Ip6Impl.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  1. /** @file
  2. Implementation of EFI_IP6_PROTOCOL protocol interfaces.
  3. (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
  4. Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "Ip6Impl.h"
  8. EFI_IPSEC2_PROTOCOL *mIpSec = NULL;
  9. EFI_IP6_PROTOCOL mEfiIp6ProtocolTemplete = {
  10. EfiIp6GetModeData,
  11. EfiIp6Configure,
  12. EfiIp6Groups,
  13. EfiIp6Routes,
  14. EfiIp6Neighbors,
  15. EfiIp6Transmit,
  16. EfiIp6Receive,
  17. EfiIp6Cancel,
  18. EfiIp6Poll
  19. };
  20. /**
  21. Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
  22. The GetModeData() function returns the current operational mode data for this driver instance.
  23. The data fields in EFI_IP6_MODE_DATA are read only. This function is used optionally to
  24. retrieve the operational mode data of underlying networks or drivers.
  25. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  26. @param[out] Ip6ModeData Pointer to the EFI IPv6 Protocol mode data structure.
  27. @param[out] MnpConfigData Pointer to the managed network configuration data structure.
  28. @param[out] SnpModeData Pointer to the simple network mode data structure.
  29. @retval EFI_SUCCESS The operation completed successfully.
  30. @retval EFI_INVALID_PARAMETER This is NULL.
  31. @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
  32. **/
  33. EFI_STATUS
  34. EFIAPI
  35. EfiIp6GetModeData (
  36. IN EFI_IP6_PROTOCOL *This,
  37. OUT EFI_IP6_MODE_DATA *Ip6ModeData OPTIONAL,
  38. OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
  39. OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
  40. )
  41. {
  42. IP6_PROTOCOL *IpInstance;
  43. IP6_SERVICE *IpSb;
  44. IP6_INTERFACE *IpIf;
  45. EFI_IP6_CONFIG_DATA *Config;
  46. EFI_STATUS Status;
  47. EFI_TPL OldTpl;
  48. if (This == NULL) {
  49. return EFI_INVALID_PARAMETER;
  50. }
  51. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  52. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  53. IpSb = IpInstance->Service;
  54. IpIf = IpInstance->Interface;
  55. if (IpSb->LinkLocalDadFail) {
  56. return EFI_INVALID_PARAMETER;
  57. }
  58. if (Ip6ModeData != NULL) {
  59. //
  60. // IsStarted is "whether the EfiIp6Configure has been called".
  61. // IsConfigured is "whether the station address has been configured"
  62. //
  63. Ip6ModeData->IsStarted = (BOOLEAN)(IpInstance->State == IP6_STATE_CONFIGED);
  64. Ip6ModeData->MaxPacketSize = IpSb->MaxPacketSize;
  65. CopyMem (&Ip6ModeData->ConfigData, &IpInstance->ConfigData, sizeof (EFI_IP6_CONFIG_DATA));
  66. Ip6ModeData->IsConfigured = FALSE;
  67. Ip6ModeData->AddressCount = 0;
  68. Ip6ModeData->AddressList = NULL;
  69. Ip6ModeData->GroupCount = IpInstance->GroupCount;
  70. Ip6ModeData->GroupTable = NULL;
  71. Ip6ModeData->RouteCount = 0;
  72. Ip6ModeData->RouteTable = NULL;
  73. Ip6ModeData->NeighborCount = 0;
  74. Ip6ModeData->NeighborCache = NULL;
  75. Ip6ModeData->PrefixCount = 0;
  76. Ip6ModeData->PrefixTable = NULL;
  77. Ip6ModeData->IcmpTypeCount = 23;
  78. Ip6ModeData->IcmpTypeList = AllocateCopyPool (
  79. Ip6ModeData->IcmpTypeCount * sizeof (EFI_IP6_ICMP_TYPE),
  80. mIp6SupportedIcmp
  81. );
  82. if (Ip6ModeData->IcmpTypeList == NULL) {
  83. Status = EFI_OUT_OF_RESOURCES;
  84. goto Error;
  85. }
  86. //
  87. // Return the currently configured IPv6 addresses and corresponding prefix lengths.
  88. //
  89. Status = Ip6BuildEfiAddressList (
  90. IpSb,
  91. &Ip6ModeData->AddressCount,
  92. &Ip6ModeData->AddressList
  93. );
  94. if (EFI_ERROR (Status)) {
  95. goto Error;
  96. }
  97. //
  98. // Return the current station address for this IP child.
  99. // If UseAnyStationAddress is set to TRUE, IP6 driver will
  100. // select a source address from its address list. Otherwise use the
  101. // StationAddress in config data.
  102. //
  103. if (Ip6ModeData->IsStarted) {
  104. Config = &Ip6ModeData->ConfigData;
  105. if (IpIf->Configured || NetIp6IsUnspecifiedAddr (&Config->DestinationAddress)) {
  106. Ip6ModeData->IsConfigured = TRUE;
  107. } else {
  108. Ip6ModeData->IsConfigured = FALSE;
  109. }
  110. //
  111. // Build a EFI route table for user from the internal route table.
  112. //
  113. Status = Ip6BuildEfiRouteTable (
  114. IpSb->RouteTable,
  115. &Ip6ModeData->RouteCount,
  116. &Ip6ModeData->RouteTable
  117. );
  118. if (EFI_ERROR (Status)) {
  119. goto Error;
  120. }
  121. }
  122. if (Ip6ModeData->IsConfigured) {
  123. //
  124. // Return the joined multicast group addresses.
  125. //
  126. if (IpInstance->GroupCount != 0) {
  127. Ip6ModeData->GroupTable = AllocateCopyPool (
  128. IpInstance->GroupCount * sizeof (EFI_IPv6_ADDRESS),
  129. IpInstance->GroupList
  130. );
  131. if (Ip6ModeData->GroupTable == NULL) {
  132. Status = EFI_OUT_OF_RESOURCES;
  133. goto Error;
  134. }
  135. }
  136. //
  137. // Return the neighbor cache entries
  138. //
  139. Status = Ip6BuildEfiNeighborCache (
  140. IpInstance,
  141. &Ip6ModeData->NeighborCount,
  142. &Ip6ModeData->NeighborCache
  143. );
  144. if (EFI_ERROR (Status)) {
  145. goto Error;
  146. }
  147. //
  148. // Return the prefix table entries
  149. //
  150. Status = Ip6BuildPrefixTable (
  151. IpInstance,
  152. &Ip6ModeData->PrefixCount,
  153. &Ip6ModeData->PrefixTable
  154. );
  155. if (EFI_ERROR (Status)) {
  156. goto Error;
  157. }
  158. }
  159. }
  160. //
  161. // Get fresh mode data from MNP, since underlying media status may change
  162. //
  163. Status = IpSb->Mnp->GetModeData (IpSb->Mnp, MnpConfigData, SnpModeData);
  164. goto Exit;
  165. Error:
  166. if (Ip6ModeData != NULL) {
  167. if (Ip6ModeData->AddressList != NULL) {
  168. FreePool (Ip6ModeData->AddressList);
  169. }
  170. if (Ip6ModeData->GroupTable != NULL) {
  171. FreePool (Ip6ModeData->GroupTable);
  172. }
  173. if (Ip6ModeData->RouteTable != NULL) {
  174. FreePool (Ip6ModeData->RouteTable);
  175. }
  176. if (Ip6ModeData->NeighborCache != NULL) {
  177. FreePool (Ip6ModeData->NeighborCache);
  178. }
  179. if (Ip6ModeData->PrefixTable != NULL) {
  180. FreePool (Ip6ModeData->PrefixTable);
  181. }
  182. if (Ip6ModeData->IcmpTypeList != NULL) {
  183. FreePool (Ip6ModeData->IcmpTypeList);
  184. }
  185. }
  186. Exit:
  187. gBS->RestoreTPL (OldTpl);
  188. return Status;
  189. }
  190. /**
  191. Validate that Ipv6 address is OK to be used as station address or next hop address/ neighbor.
  192. @param[in] IpSb The IP6 service instance.
  193. @param[in] Ip The IPv6 address to validate.
  194. @param[in] Flag If TRUE, validate if the address is OK to be used
  195. as station address. If FALSE, validate if the
  196. address is OK to be used as the next hop address/
  197. neighbor.
  198. @retval TRUE The Ip address is valid and could be used.
  199. @retval FALSE Invalid Ip address.
  200. **/
  201. BOOLEAN
  202. Ip6IsValidAddress (
  203. IN IP6_SERVICE *IpSb,
  204. IN EFI_IPv6_ADDRESS *Ip,
  205. IN BOOLEAN Flag
  206. )
  207. {
  208. if (!NetIp6IsUnspecifiedAddr (Ip)) {
  209. if (!NetIp6IsValidUnicast (Ip)) {
  210. return FALSE;
  211. }
  212. if (Ip6IsOneOfSetAddress (IpSb, Ip, NULL, NULL)) {
  213. return Flag;
  214. }
  215. } else {
  216. return Flag;
  217. }
  218. return (BOOLEAN) !Flag;
  219. }
  220. /**
  221. Validate whether the value of protocol is illegal or not. Protocol is the 'Next Header' field
  222. in the last IPv6 extension header, or basic IPv6 header is there's no extension header.
  223. @param[in] Protocol Default value of 'Next Header'
  224. @retval TRUE The protocol is illegal.
  225. @retval FALSE The protocol is legal.
  226. **/
  227. BOOLEAN
  228. Ip6IsIllegalProtocol (
  229. IN UINT8 Protocol
  230. )
  231. {
  232. if ((Protocol == IP6_HOP_BY_HOP) || (Protocol == EFI_IP_PROTO_ICMP) || (Protocol == IP4_PROTO_IGMP)) {
  233. return TRUE;
  234. }
  235. if ((Protocol == 41) || (Protocol == 43) || (Protocol == 44) || (Protocol == 59) || (Protocol == 60) || (Protocol == 124)) {
  236. return TRUE;
  237. }
  238. return FALSE;
  239. }
  240. /**
  241. Initialize the IP6_PROTOCOL structure to the unconfigured states.
  242. @param[in] IpSb The IP6 service instance.
  243. @param[in, out] IpInstance The IP6 child instance.
  244. **/
  245. VOID
  246. Ip6InitProtocol (
  247. IN IP6_SERVICE *IpSb,
  248. IN OUT IP6_PROTOCOL *IpInstance
  249. )
  250. {
  251. ASSERT ((IpSb != NULL) && (IpInstance != NULL));
  252. ZeroMem (IpInstance, sizeof (IP6_PROTOCOL));
  253. IpInstance->Signature = IP6_PROTOCOL_SIGNATURE;
  254. IpInstance->State = IP6_STATE_UNCONFIGED;
  255. IpInstance->Service = IpSb;
  256. IpInstance->GroupList = NULL;
  257. CopyMem (&IpInstance->Ip6Proto, &mEfiIp6ProtocolTemplete, sizeof (EFI_IP6_PROTOCOL));
  258. NetMapInit (&IpInstance->RxTokens);
  259. NetMapInit (&IpInstance->TxTokens);
  260. InitializeListHead (&IpInstance->Received);
  261. InitializeListHead (&IpInstance->Delivered);
  262. EfiInitializeLock (&IpInstance->RecycleLock, TPL_NOTIFY);
  263. }
  264. /**
  265. Configure the IP6 child. If the child is already configured,
  266. change the configuration parameter. Otherwise, configure it
  267. for the first time. The caller should validate the configuration
  268. before deliver them to it. It also don't do configure NULL.
  269. @param[in, out] IpInstance The IP6 child to configure.
  270. @param[in] Config The configure data.
  271. @retval EFI_SUCCESS The IP6 child is successfully configured.
  272. @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
  273. configure underlying MNP, or other errors.
  274. @retval EFI_NO_MAPPING The IP6 child is configured to use the default
  275. address, but the default address hasn't been
  276. configured. The IP6 child doesn't need to be
  277. reconfigured when the default address is configured.
  278. @retval EFI_OUT_OF_RESOURCES No more memory space is available.
  279. @retval other Other error occurs.
  280. **/
  281. EFI_STATUS
  282. Ip6ConfigProtocol (
  283. IN OUT IP6_PROTOCOL *IpInstance,
  284. IN EFI_IP6_CONFIG_DATA *Config
  285. )
  286. {
  287. IP6_SERVICE *IpSb;
  288. IP6_INTERFACE *IpIf;
  289. EFI_STATUS Status;
  290. EFI_IP6_CONFIG_DATA *Current;
  291. IP6_ADDRESS_INFO *AddressInfo;
  292. BOOLEAN StationZero;
  293. BOOLEAN DestZero;
  294. EFI_IPv6_ADDRESS Source;
  295. BOOLEAN AddrOk;
  296. IpSb = IpInstance->Service;
  297. Current = &IpInstance->ConfigData;
  298. //
  299. // User is changing packet filters. It must be stopped
  300. // before the station address can be changed.
  301. //
  302. if (IpInstance->State == IP6_STATE_CONFIGED) {
  303. //
  304. // Cancel all the pending transmit/receive from upper layer
  305. //
  306. Status = Ip6Cancel (IpInstance, NULL);
  307. if (EFI_ERROR (Status)) {
  308. return EFI_DEVICE_ERROR;
  309. }
  310. CopyMem (Current, Config, sizeof (EFI_IP6_CONFIG_DATA));
  311. return EFI_SUCCESS;
  312. }
  313. //
  314. // Set up the interface.
  315. //
  316. StationZero = NetIp6IsUnspecifiedAddr (&Config->StationAddress);
  317. DestZero = NetIp6IsUnspecifiedAddr (&Config->DestinationAddress);
  318. if (StationZero && DestZero) {
  319. //
  320. // StationAddress is still zero.
  321. //
  322. NET_GET_REF (IpSb->DefaultInterface);
  323. IpInstance->Interface = IpSb->DefaultInterface;
  324. InsertTailList (&IpSb->DefaultInterface->IpInstances, &IpInstance->AddrLink);
  325. CopyMem (Current, Config, sizeof (EFI_IP6_CONFIG_DATA));
  326. IpInstance->State = IP6_STATE_CONFIGED;
  327. return EFI_SUCCESS;
  328. }
  329. if (StationZero && !DestZero) {
  330. Status = Ip6SelectSourceAddress (IpSb, &Config->DestinationAddress, &Source);
  331. if (EFI_ERROR (Status)) {
  332. return Status;
  333. }
  334. } else {
  335. IP6_COPY_ADDRESS (&Source, &Config->StationAddress);
  336. }
  337. AddrOk = Ip6IsOneOfSetAddress (IpSb, &Source, &IpIf, &AddressInfo);
  338. if (AddrOk) {
  339. if (AddressInfo != NULL) {
  340. IpInstance->PrefixLength = AddressInfo->PrefixLength;
  341. } else {
  342. IpInstance->PrefixLength = IP6_LINK_LOCAL_PREFIX_LENGTH;
  343. }
  344. } else {
  345. //
  346. // The specified source address is not one of the addresses IPv6 maintains.
  347. //
  348. return EFI_INVALID_PARAMETER;
  349. }
  350. NET_GET_REF (IpIf);
  351. IpInstance->Interface = IpIf;
  352. InsertTailList (&IpIf->IpInstances, &IpInstance->AddrLink);
  353. CopyMem (Current, Config, sizeof (EFI_IP6_CONFIG_DATA));
  354. IP6_COPY_ADDRESS (&Current->StationAddress, &Source);
  355. IpInstance->State = IP6_STATE_CONFIGED;
  356. return EFI_SUCCESS;
  357. }
  358. /**
  359. Clean up the IP6 child, and release all the resources used by it.
  360. @param[in, out] IpInstance The IP6 child to clean up.
  361. @retval EFI_SUCCESS The IP6 child is cleaned up.
  362. @retval EFI_DEVICE_ERROR Some resources failed to be released.
  363. **/
  364. EFI_STATUS
  365. Ip6CleanProtocol (
  366. IN OUT IP6_PROTOCOL *IpInstance
  367. )
  368. {
  369. if (EFI_ERROR (Ip6Cancel (IpInstance, NULL))) {
  370. return EFI_DEVICE_ERROR;
  371. }
  372. if (EFI_ERROR (Ip6Groups (IpInstance, FALSE, NULL))) {
  373. return EFI_DEVICE_ERROR;
  374. }
  375. //
  376. // Some packets haven't been recycled. It is because either the
  377. // user forgets to recycle the packets, or because the callback
  378. // hasn't been called. Just leave it alone.
  379. //
  380. if (!IsListEmpty (&IpInstance->Delivered)) {
  381. }
  382. if (IpInstance->Interface != NULL) {
  383. RemoveEntryList (&IpInstance->AddrLink);
  384. Ip6CleanInterface (IpInstance->Interface, IpInstance);
  385. IpInstance->Interface = NULL;
  386. }
  387. if (IpInstance->GroupList != NULL) {
  388. FreePool (IpInstance->GroupList);
  389. IpInstance->GroupList = NULL;
  390. IpInstance->GroupCount = 0;
  391. }
  392. NetMapClean (&IpInstance->TxTokens);
  393. NetMapClean (&IpInstance->RxTokens);
  394. return EFI_SUCCESS;
  395. }
  396. /**
  397. Configure the MNP parameter used by IP. The IP driver uses one MNP
  398. child to transmit/receive frames. By default, it configures MNP
  399. to receive unicast/multicast/broadcast. Also, it will enable/disable
  400. the promiscuous receive according to whether there is IP child
  401. enable that or not. If Force is FALSE, it will iterate through
  402. all the IP children to check whether the promiscuous receive
  403. setting has been changed. If it hasn't been changed, it won't
  404. reconfigure the MNP. If Force is TRUE, the MNP is configured
  405. whether that is changed or not.
  406. @param[in] IpSb The IP6 service instance that is to be changed.
  407. @param[in] Force Force the configuration or not.
  408. @retval EFI_SUCCESS The MNP successfully configured/reconfigured.
  409. @retval Others Configuration failed.
  410. **/
  411. EFI_STATUS
  412. Ip6ServiceConfigMnp (
  413. IN IP6_SERVICE *IpSb,
  414. IN BOOLEAN Force
  415. )
  416. {
  417. LIST_ENTRY *Entry;
  418. LIST_ENTRY *ProtoEntry;
  419. IP6_INTERFACE *IpIf;
  420. IP6_PROTOCOL *IpInstance;
  421. BOOLEAN Reconfig;
  422. BOOLEAN PromiscReceive;
  423. EFI_STATUS Status;
  424. Reconfig = FALSE;
  425. PromiscReceive = FALSE;
  426. if (!Force) {
  427. //
  428. // Iterate through the IP children to check whether promiscuous
  429. // receive setting has been changed. Update the interface's receive
  430. // filter also.
  431. //
  432. NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
  433. IpIf = NET_LIST_USER_STRUCT (Entry, IP6_INTERFACE, Link);
  434. IpIf->PromiscRecv = FALSE;
  435. NET_LIST_FOR_EACH (ProtoEntry, &IpIf->IpInstances) {
  436. IpInstance = NET_LIST_USER_STRUCT (ProtoEntry, IP6_PROTOCOL, AddrLink);
  437. if (IpInstance->ConfigData.AcceptPromiscuous) {
  438. IpIf->PromiscRecv = TRUE;
  439. PromiscReceive = TRUE;
  440. }
  441. }
  442. }
  443. //
  444. // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
  445. //
  446. if (PromiscReceive == IpSb->MnpConfigData.EnablePromiscuousReceive) {
  447. return EFI_SUCCESS;
  448. }
  449. Reconfig = TRUE;
  450. IpSb->MnpConfigData.EnablePromiscuousReceive = PromiscReceive;
  451. }
  452. Status = IpSb->Mnp->Configure (IpSb->Mnp, &IpSb->MnpConfigData);
  453. //
  454. // recover the original configuration if failed to set the configure.
  455. //
  456. if (EFI_ERROR (Status) && Reconfig) {
  457. IpSb->MnpConfigData.EnablePromiscuousReceive = (BOOLEAN) !PromiscReceive;
  458. }
  459. return Status;
  460. }
  461. /**
  462. Assigns an IPv6 address and subnet mask to this EFI IPv6 Protocol driver instance.
  463. The Configure() function is used to set, change, or reset the operational parameters and filter
  464. settings for this EFI IPv6 Protocol instance. Until these parameters have been set, no network traffic
  465. can be sent or received by this instance. Once the parameters have been reset (by calling this
  466. function with Ip6ConfigData set to NULL), no more traffic can be sent or received until these
  467. parameters have been set again. Each EFI IPv6 Protocol instance can be started and stopped
  468. independently of each other by enabling or disabling their receive filter settings with the
  469. Configure() function.
  470. If Ip6ConfigData.StationAddress is a valid non-zero IPv6 unicast address, it is required
  471. to be one of the currently configured IPv6 addresses listed in the EFI IPv6 drivers, or else
  472. EFI_INVALID_PARAMETER will be returned. If Ip6ConfigData.StationAddress is
  473. unspecified, the IPv6 driver will bind a source address according to the source address selection
  474. algorithm. Clients could frequently call GetModeData() to check get currently configured IPv6
  475. address list in the EFI IPv6 driver. If both Ip6ConfigData.StationAddress and
  476. Ip6ConfigData.Destination are unspecified, when transmitting the packet afterwards, the
  477. source address filled in each outgoing IPv6 packet is decided based on the destination of this packet.
  478. If operational parameters are reset or changed, any pending transmit and receive requests will be
  479. cancelled. Their completion token status will be set to EFI_ABORTED and their events will be
  480. signaled.
  481. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  482. @param[in] Ip6ConfigData Pointer to the EFI IPv6 Protocol configuration data structure.
  483. If NULL, reset the configuration data.
  484. @retval EFI_SUCCESS The driver instance was successfully opened.
  485. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  486. - This is NULL.
  487. - Ip6ConfigData.StationAddress is neither zero nor
  488. a unicast IPv6 address.
  489. - Ip6ConfigData.StationAddress is neither zero nor
  490. one of the configured IP addresses in the EFI IPv6 driver.
  491. - Ip6ConfigData.DefaultProtocol is illegal.
  492. @retval EFI_OUT_OF_RESOURCES The EFI IPv6 Protocol driver instance data could not be allocated.
  493. @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing a source address for
  494. this instance, but no source address was available for use.
  495. @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the IPv6
  496. address or prefix length can be changed.
  497. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv6
  498. Protocol driver instance was not opened.
  499. @retval EFI_UNSUPPORTED Default protocol specified through
  500. Ip6ConfigData.DefaultProtocol isn't supported.
  501. **/
  502. EFI_STATUS
  503. EFIAPI
  504. EfiIp6Configure (
  505. IN EFI_IP6_PROTOCOL *This,
  506. IN EFI_IP6_CONFIG_DATA *Ip6ConfigData OPTIONAL
  507. )
  508. {
  509. IP6_PROTOCOL *IpInstance;
  510. EFI_IP6_CONFIG_DATA *Current;
  511. EFI_TPL OldTpl;
  512. EFI_STATUS Status;
  513. IP6_SERVICE *IpSb;
  514. //
  515. // First, validate the parameters
  516. //
  517. if (This == NULL) {
  518. return EFI_INVALID_PARAMETER;
  519. }
  520. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  521. IpSb = IpInstance->Service;
  522. if (IpSb->LinkLocalDadFail && (Ip6ConfigData != NULL)) {
  523. return EFI_DEVICE_ERROR;
  524. }
  525. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  526. Status = EFI_INVALID_PARAMETER;
  527. //
  528. // Validate the configuration first.
  529. //
  530. if (Ip6ConfigData != NULL) {
  531. //
  532. // Check whether the station address is valid.
  533. //
  534. if (!Ip6IsValidAddress (IpSb, &Ip6ConfigData->StationAddress, TRUE)) {
  535. goto Exit;
  536. }
  537. //
  538. // Check whether the default protocol is valid.
  539. //
  540. if (Ip6IsIllegalProtocol (Ip6ConfigData->DefaultProtocol)) {
  541. goto Exit;
  542. }
  543. //
  544. // User can only update packet filters when already configured.
  545. // If it wants to change the station address, it must configure(NULL)
  546. // the instance firstly.
  547. //
  548. if (IpInstance->State == IP6_STATE_CONFIGED) {
  549. Current = &IpInstance->ConfigData;
  550. if (!EFI_IP6_EQUAL (&Current->StationAddress, &Ip6ConfigData->StationAddress)) {
  551. Status = EFI_ALREADY_STARTED;
  552. goto Exit;
  553. }
  554. if (NetIp6IsUnspecifiedAddr (&Current->StationAddress) && IP6_NO_MAPPING (IpInstance)) {
  555. Status = EFI_NO_MAPPING;
  556. goto Exit;
  557. }
  558. }
  559. }
  560. //
  561. // Configure the instance or clean it up.
  562. //
  563. if (Ip6ConfigData != NULL) {
  564. Status = Ip6ConfigProtocol (IpInstance, Ip6ConfigData);
  565. } else {
  566. Status = Ip6CleanProtocol (IpInstance);
  567. //
  568. // Don't change the state if it is DESTROY, consider the following
  569. // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
  570. // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
  571. // the unload fails miserably.
  572. //
  573. if (IpInstance->State == IP6_STATE_CONFIGED) {
  574. IpInstance->State = IP6_STATE_UNCONFIGED;
  575. }
  576. }
  577. //
  578. // Update the MNP's configure data. Ip6ServiceConfigMnp will check
  579. // whether it is necessary to reconfigure the MNP.
  580. //
  581. Ip6ServiceConfigMnp (IpInstance->Service, FALSE);
  582. Exit:
  583. gBS->RestoreTPL (OldTpl);
  584. return Status;
  585. }
  586. /**
  587. Joins and leaves multicast groups.
  588. The Groups() function is used to join and leave multicast group sessions. Joining a group will
  589. enable reception of matching multicast packets. Leaving a group will disable reception of matching
  590. multicast packets. Source-Specific Multicast isn't required to be supported.
  591. If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
  592. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  593. @param[in] JoinFlag Set to TRUE to join the multicast group session, and FALSE to leave.
  594. @param[in] GroupAddress Pointer to the IPv6 multicast address.
  595. This is an optional parameter that may be NULL.
  596. @retval EFI_SUCCESS The operation completed successfully.
  597. @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
  598. - This is NULL.
  599. - JoinFlag is TRUE and GroupAddress is NULL.
  600. - GroupAddress is not NULL and *GroupAddress is
  601. not a multicast IPv6 address.
  602. - GroupAddress is not NULL and *GroupAddress is in the
  603. range of SSM destination address.
  604. @retval EFI_NOT_STARTED This instance has not been started.
  605. @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
  606. @retval EFI_UNSUPPORTED This EFI IPv6 Protocol implementation does not support multicast groups.
  607. @retval EFI_ALREADY_STARTED The group address is already in the group table (when
  608. JoinFlag is TRUE).
  609. @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
  610. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  611. **/
  612. EFI_STATUS
  613. EFIAPI
  614. EfiIp6Groups (
  615. IN EFI_IP6_PROTOCOL *This,
  616. IN BOOLEAN JoinFlag,
  617. IN EFI_IPv6_ADDRESS *GroupAddress OPTIONAL
  618. )
  619. {
  620. EFI_TPL OldTpl;
  621. EFI_STATUS Status;
  622. IP6_PROTOCOL *IpInstance;
  623. IP6_SERVICE *IpSb;
  624. if ((This == NULL) || (JoinFlag && (GroupAddress == NULL))) {
  625. return EFI_INVALID_PARAMETER;
  626. }
  627. if ((GroupAddress != NULL) && !IP6_IS_MULTICAST (GroupAddress)) {
  628. return EFI_INVALID_PARAMETER;
  629. }
  630. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  631. IpSb = IpInstance->Service;
  632. if (IpSb->LinkLocalDadFail) {
  633. return EFI_DEVICE_ERROR;
  634. }
  635. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  636. if (IpInstance->State != IP6_STATE_CONFIGED) {
  637. Status = EFI_NOT_STARTED;
  638. goto ON_EXIT;
  639. }
  640. Status = Ip6Groups (IpInstance, JoinFlag, GroupAddress);
  641. ON_EXIT:
  642. gBS->RestoreTPL (OldTpl);
  643. return Status;
  644. }
  645. /**
  646. Adds and deletes routing table entries.
  647. The Routes() function adds a route to, or deletes a route from, the routing table.
  648. Routes are determined by comparing the leftmost PrefixLength bits of Destination with
  649. the destination IPv6 address arithmetically. The gateway address must be on the same subnet as the
  650. configured station address.
  651. The default route is added with Destination and PrefixLength both set to all zeros. The
  652. default route matches all destination IPv6 addresses that do not match any other routes.
  653. All EFI IPv6 Protocol instances share a routing table.
  654. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  655. @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
  656. FALSE to add this route to the routing table. Destination,
  657. PrefixLength and Gateway are used as the key to each
  658. route entry.
  659. @param[in] Destination The address prefix of the subnet that needs to be routed.
  660. This is an optional parameter that may be NULL.
  661. @param[in] PrefixLength The prefix length of Destination. Ignored if Destination
  662. is NULL.
  663. @param[in] GatewayAddress The unicast gateway IPv6 address for this route.
  664. This is an optional parameter that may be NULL.
  665. @retval EFI_SUCCESS The operation completed successfully.
  666. @retval EFI_NOT_STARTED The driver instance has not been started.
  667. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  668. - This is NULL.
  669. - When DeleteRoute is TRUE, both Destination and
  670. GatewayAddress are NULL.
  671. - When DeleteRoute is FALSE, either Destination or
  672. GatewayAddress is NULL.
  673. - *GatewayAddress is not a valid unicast IPv6 address.
  674. - *GatewayAddress is one of the local configured IPv6
  675. addresses.
  676. @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
  677. @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
  678. @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
  679. DeleteRoute is FALSE).
  680. **/
  681. EFI_STATUS
  682. EFIAPI
  683. EfiIp6Routes (
  684. IN EFI_IP6_PROTOCOL *This,
  685. IN BOOLEAN DeleteRoute,
  686. IN EFI_IPv6_ADDRESS *Destination OPTIONAL,
  687. IN UINT8 PrefixLength,
  688. IN EFI_IPv6_ADDRESS *GatewayAddress OPTIONAL
  689. )
  690. {
  691. IP6_PROTOCOL *IpInstance;
  692. EFI_STATUS Status;
  693. EFI_TPL OldTpl;
  694. IP6_SERVICE *IpSb;
  695. if ((This == NULL) || (PrefixLength > IP6_PREFIX_MAX)) {
  696. return EFI_INVALID_PARAMETER;
  697. }
  698. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  699. IpSb = IpInstance->Service;
  700. if (IpSb->LinkLocalDadFail) {
  701. return EFI_DEVICE_ERROR;
  702. }
  703. if (IpInstance->State != IP6_STATE_CONFIGED) {
  704. return EFI_NOT_STARTED;
  705. }
  706. if (DeleteRoute && (Destination == NULL) && (GatewayAddress == NULL)) {
  707. return EFI_INVALID_PARAMETER;
  708. }
  709. if (!DeleteRoute && ((Destination == NULL) || (GatewayAddress == NULL))) {
  710. return EFI_INVALID_PARAMETER;
  711. }
  712. if (GatewayAddress != NULL) {
  713. if (!Ip6IsValidAddress (IpSb, GatewayAddress, FALSE)) {
  714. return EFI_INVALID_PARAMETER;
  715. }
  716. if (!NetIp6IsUnspecifiedAddr (GatewayAddress) &&
  717. !NetIp6IsNetEqual (GatewayAddress, &IpInstance->ConfigData.StationAddress, PrefixLength)
  718. )
  719. {
  720. return EFI_INVALID_PARAMETER;
  721. }
  722. }
  723. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  724. //
  725. // Update the route table
  726. //
  727. if (DeleteRoute) {
  728. Status = Ip6DelRoute (IpSb->RouteTable, Destination, PrefixLength, GatewayAddress);
  729. } else {
  730. Status = Ip6AddRoute (IpSb->RouteTable, Destination, PrefixLength, GatewayAddress);
  731. }
  732. gBS->RestoreTPL (OldTpl);
  733. return Status;
  734. }
  735. /**
  736. Add or delete Neighbor cache entries.
  737. The Neighbors() function is used to add, update, or delete an entry from neighbor cache.
  738. IPv6 neighbor cache entries are typically inserted and updated by the network protocol driver as
  739. network traffic is processed. Most neighbor cache entries will timeout and be deleted if the network
  740. traffic stops. Neighbor cache entries that were inserted by Neighbors() may be static (will not
  741. timeout) or dynamic (will timeout).
  742. The implementation should follow the neighbor cache timeout mechanism which is defined in
  743. RFC4861. The default neighbor cache timeout value should be tuned for the expected network
  744. environment
  745. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  746. @param[in] DeleteFlag Set to TRUE to delete the specified cache entry, set to FALSE to
  747. add (or update, if it already exists and Override is TRUE) the
  748. specified cache entry. TargetIp6Address is used as the key
  749. to find the requested cache entry.
  750. @param[in] TargetIp6Address Pointer to the Target IPv6 address.
  751. @param[in] TargetLinkAddress Pointer to the link-layer address of the target. Ignored if NULL.
  752. @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
  753. cache, it will be deleted after Timeout. A value of zero means that
  754. the entry is permanent. A non-zero value means that the entry is
  755. dynamic.
  756. @param[in] Override If TRUE, the cached link-layer address of the matching entry will
  757. be overridden and updated; if FALSE, EFI_ACCESS_DENIED
  758. will be returned if a corresponding cache entry already existed.
  759. @retval EFI_SUCCESS The data has been queued for transmission.
  760. @retval EFI_NOT_STARTED This instance has not been started.
  761. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  762. - This is NULL.
  763. - TargetIpAddress is NULL.
  764. - *TargetLinkAddress is invalid when not NULL.
  765. - *TargetIpAddress is not a valid unicast IPv6 address.
  766. - *TargetIpAddress is one of the local configured IPv6
  767. addresses.
  768. @retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache.
  769. @retval EFI_NOT_FOUND This entry is not in the neighbor cache (when DeleteFlag is
  770. TRUE or when DeleteFlag is FALSE while
  771. TargetLinkAddress is NULL.).
  772. @retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,
  773. and that entry is tagged as un-overridden (when Override
  774. is FALSE).
  775. **/
  776. EFI_STATUS
  777. EFIAPI
  778. EfiIp6Neighbors (
  779. IN EFI_IP6_PROTOCOL *This,
  780. IN BOOLEAN DeleteFlag,
  781. IN EFI_IPv6_ADDRESS *TargetIp6Address,
  782. IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL,
  783. IN UINT32 Timeout,
  784. IN BOOLEAN Override
  785. )
  786. {
  787. EFI_TPL OldTpl;
  788. EFI_STATUS Status;
  789. IP6_PROTOCOL *IpInstance;
  790. IP6_SERVICE *IpSb;
  791. if ((This == NULL) || (TargetIp6Address == NULL)) {
  792. return EFI_INVALID_PARAMETER;
  793. }
  794. if (NetIp6IsUnspecifiedAddr (TargetIp6Address)) {
  795. return EFI_INVALID_PARAMETER;
  796. }
  797. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  798. IpSb = IpInstance->Service;
  799. if (IpSb->LinkLocalDadFail) {
  800. return EFI_DEVICE_ERROR;
  801. }
  802. if (!Ip6IsValidAddress (IpSb, TargetIp6Address, FALSE)) {
  803. return EFI_INVALID_PARAMETER;
  804. }
  805. if (TargetLinkAddress != NULL) {
  806. if (!Ip6IsValidLinkAddress (IpSb, TargetLinkAddress)) {
  807. return EFI_INVALID_PARAMETER;
  808. }
  809. }
  810. if (Ip6IsOneOfSetAddress (IpSb, TargetIp6Address, NULL, NULL)) {
  811. return EFI_INVALID_PARAMETER;
  812. }
  813. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  814. if (IpInstance->State != IP6_STATE_CONFIGED) {
  815. Status = EFI_NOT_STARTED;
  816. goto Exit;
  817. }
  818. if (DeleteFlag) {
  819. Status = Ip6DelNeighbor (IpInstance->Service, TargetIp6Address, TargetLinkAddress, Timeout, Override);
  820. } else {
  821. Status = Ip6AddNeighbor (IpInstance->Service, TargetIp6Address, TargetLinkAddress, Timeout, Override);
  822. }
  823. Exit:
  824. gBS->RestoreTPL (OldTpl);
  825. return Status;
  826. }
  827. /**
  828. Check whether the user's token or event has already
  829. been enqueue on IP6's list.
  830. @param[in] Map The container of either user's transmit or receive
  831. token.
  832. @param[in] Item Current item to check against.
  833. @param[in] Context The Token to check against.
  834. @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
  835. @retval EFI_SUCCESS The current item isn't the same token/event as the
  836. context.
  837. **/
  838. EFI_STATUS
  839. EFIAPI
  840. Ip6TokenExist (
  841. IN NET_MAP *Map,
  842. IN NET_MAP_ITEM *Item,
  843. IN VOID *Context
  844. )
  845. {
  846. EFI_IP6_COMPLETION_TOKEN *Token;
  847. EFI_IP6_COMPLETION_TOKEN *TokenInItem;
  848. Token = (EFI_IP6_COMPLETION_TOKEN *)Context;
  849. TokenInItem = (EFI_IP6_COMPLETION_TOKEN *)Item->Key;
  850. if ((Token == TokenInItem) || (Token->Event == TokenInItem->Event)) {
  851. return EFI_ACCESS_DENIED;
  852. }
  853. return EFI_SUCCESS;
  854. }
  855. /**
  856. Validate the user's token against the current station address.
  857. @param[in] Token User's token to validate.
  858. @retval EFI_INVALID_PARAMETER Some parameters are invalid.
  859. @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
  860. @retval EFI_SUCCESS The token is OK.
  861. **/
  862. EFI_STATUS
  863. Ip6TxTokenValid (
  864. IN EFI_IP6_COMPLETION_TOKEN *Token
  865. )
  866. {
  867. EFI_IP6_TRANSMIT_DATA *TxData;
  868. UINT32 Index;
  869. UINT32 DataLength;
  870. if ((Token == NULL) || (Token->Event == NULL)) {
  871. return EFI_INVALID_PARAMETER;
  872. }
  873. TxData = Token->Packet.TxData;
  874. if ((TxData == NULL) || ((TxData->ExtHdrsLength != 0) && (TxData->ExtHdrs == NULL))) {
  875. return EFI_INVALID_PARAMETER;
  876. }
  877. if ((TxData->FragmentCount == 0) || (TxData->DataLength == 0)) {
  878. return EFI_INVALID_PARAMETER;
  879. }
  880. for (DataLength = 0, Index = 0; Index < TxData->FragmentCount; Index++) {
  881. if ((TxData->FragmentTable[Index].FragmentLength == 0) || (TxData->FragmentTable[Index].FragmentBuffer == NULL)) {
  882. return EFI_INVALID_PARAMETER;
  883. }
  884. DataLength += TxData->FragmentTable[Index].FragmentLength;
  885. }
  886. if (TxData->DataLength != DataLength) {
  887. return EFI_INVALID_PARAMETER;
  888. }
  889. //
  890. // TODO: Token.Packet.TxData.DataLength is too short to transmit.
  891. // return EFI_BUFFER_TOO_SMALL;
  892. //
  893. //
  894. // If Token.Packet.TxData.DataLength is beyond the maximum that which can be
  895. // described through the Fragment Offset field in Fragment header when performing
  896. // fragmentation.
  897. //
  898. if (TxData->DataLength > 64 * 1024) {
  899. return EFI_BAD_BUFFER_SIZE;
  900. }
  901. return EFI_SUCCESS;
  902. }
  903. /**
  904. The callback function for the net buffer which wraps the user's
  905. transmit token. Although this function seems simple, there
  906. are some subtle aspects.
  907. When user requests the IP to transmit a packet by passing it a
  908. token, the token is wrapped in an IP6_TXTOKEN_WRAP and the data
  909. is wrapped in an net buffer. The net buffer's Free function is
  910. set to Ip6FreeTxToken. The Token and token wrap are added to the
  911. IP child's TxToken map. Then the buffer is passed to Ip6Output for
  912. transmission. If an error happened before that, the buffer
  913. is freed, which in turn frees the token wrap. The wrap may
  914. have been added to the TxToken map or not, and the user's event
  915. shouldn't be fired because we are still in the EfiIp6Transmit. If
  916. the buffer has been sent by Ip6Output, it should be removed from
  917. the TxToken map and user's event signaled. The token wrap and buffer
  918. are bound together. Check the comments in Ip6Output for information
  919. about IP fragmentation.
  920. @param[in] Context The token's wrap.
  921. **/
  922. VOID
  923. EFIAPI
  924. Ip6FreeTxToken (
  925. IN VOID *Context
  926. )
  927. {
  928. IP6_TXTOKEN_WRAP *Wrap;
  929. NET_MAP_ITEM *Item;
  930. Wrap = (IP6_TXTOKEN_WRAP *)Context;
  931. //
  932. // Signal IpSecRecycleEvent to inform IPsec free the memory
  933. //
  934. if (Wrap->IpSecRecycleSignal != NULL) {
  935. gBS->SignalEvent (Wrap->IpSecRecycleSignal);
  936. }
  937. //
  938. // Find the token in the instance's map. EfiIp6Transmit put the
  939. // token to the map. If that failed, NetMapFindKey will return NULL.
  940. //
  941. Item = NetMapFindKey (&Wrap->IpInstance->TxTokens, Wrap->Token);
  942. if (Item != NULL) {
  943. NetMapRemoveItem (&Wrap->IpInstance->TxTokens, Item, NULL);
  944. }
  945. if (Wrap->Sent) {
  946. gBS->SignalEvent (Wrap->Token->Event);
  947. //
  948. // Dispatch the DPC queued by the NotifyFunction of Token->Event.
  949. //
  950. DispatchDpc ();
  951. }
  952. FreePool (Wrap);
  953. }
  954. /**
  955. The callback function to Ip6Output to update the transmit status.
  956. @param[in] Packet The user's transmit packet.
  957. @param[in] IoStatus The result of the transmission.
  958. @param[in] Flag Not used during transmission.
  959. @param[in] Context The token's wrap.
  960. **/
  961. VOID
  962. Ip6OnPacketSent (
  963. IN NET_BUF *Packet,
  964. IN EFI_STATUS IoStatus,
  965. IN UINT32 Flag,
  966. IN VOID *Context
  967. )
  968. {
  969. IP6_TXTOKEN_WRAP *Wrap;
  970. //
  971. // This is the transmission request from upper layer,
  972. // not the IP6 driver itself.
  973. //
  974. Wrap = (IP6_TXTOKEN_WRAP *)Context;
  975. Wrap->Token->Status = IoStatus;
  976. NetbufFree (Wrap->Packet);
  977. }
  978. /**
  979. Places outgoing data packets into the transmit queue.
  980. The Transmit() function places a sending request in the transmit queue of this
  981. EFI IPv6 Protocol instance. Whenever the packet in the token is sent out or some
  982. errors occur, the event in the token will be signaled, and the status is updated.
  983. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  984. @param[in] Token Pointer to the transmit token.
  985. @retval EFI_SUCCESS The data has been queued for transmission.
  986. @retval EFI_NOT_STARTED This instance has not been started.
  987. @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing
  988. a source address for this transmission,
  989. but no source address was available for use.
  990. @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
  991. - This is NULL.
  992. - Token is NULL.
  993. - Token.Event is NULL.
  994. - Token.Packet.TxData is NULL.
  995. - Token.Packet.ExtHdrsLength is not zero and
  996. Token.Packet.ExtHdrs is NULL.
  997. - Token.Packet.FragmentCount is zero.
  998. - One or more of the Token.Packet.TxData.
  999. FragmentTable[].FragmentLength fields is zero.
  1000. - One or more of the Token.Packet.TxData.
  1001. FragmentTable[].FragmentBuffer fields is NULL.
  1002. - Token.Packet.TxData.DataLength is zero or not
  1003. equal to the sum of fragment lengths.
  1004. - Token.Packet.TxData.DestinationAddress is non
  1005. zero when DestinationAddress is configured as
  1006. non-zero when doing Configure() for this
  1007. EFI IPv6 protocol instance.
  1008. - Token.Packet.TxData.DestinationAddress is
  1009. unspecified when DestinationAddress is unspecified
  1010. when doing Configure() for this EFI IPv6 protocol
  1011. instance.
  1012. @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.
  1013. Event was already in the transmit queue.
  1014. @retval EFI_NOT_READY The completion token could not be queued because
  1015. the transmit queue is full.
  1016. @retval EFI_NOT_FOUND Not route is found to destination address.
  1017. @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
  1018. @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
  1019. short to transmit.
  1020. @retval EFI_BAD_BUFFER_SIZE If Token.Packet.TxData.DataLength is beyond the
  1021. maximum that which can be described through the
  1022. Fragment Offset field in Fragment header when
  1023. performing fragmentation.
  1024. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  1025. **/
  1026. EFI_STATUS
  1027. EFIAPI
  1028. EfiIp6Transmit (
  1029. IN EFI_IP6_PROTOCOL *This,
  1030. IN EFI_IP6_COMPLETION_TOKEN *Token
  1031. )
  1032. {
  1033. IP6_SERVICE *IpSb;
  1034. IP6_PROTOCOL *IpInstance;
  1035. EFI_IP6_CONFIG_DATA *Config;
  1036. EFI_STATUS Status;
  1037. EFI_TPL OldTpl;
  1038. EFI_IP6_HEADER Head;
  1039. EFI_IP6_TRANSMIT_DATA *TxData;
  1040. EFI_IP6_OVERRIDE_DATA *Override;
  1041. IP6_TXTOKEN_WRAP *Wrap;
  1042. UINT8 *ExtHdrs;
  1043. //
  1044. // Check input parameters.
  1045. //
  1046. if (This == NULL) {
  1047. return EFI_INVALID_PARAMETER;
  1048. }
  1049. ExtHdrs = NULL;
  1050. Status = Ip6TxTokenValid (Token);
  1051. if (EFI_ERROR (Status)) {
  1052. return Status;
  1053. }
  1054. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  1055. IpSb = IpInstance->Service;
  1056. if (IpSb->LinkLocalDadFail) {
  1057. return EFI_DEVICE_ERROR;
  1058. }
  1059. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  1060. if (IpInstance->State != IP6_STATE_CONFIGED) {
  1061. Status = EFI_NOT_STARTED;
  1062. goto Exit;
  1063. }
  1064. Config = &IpInstance->ConfigData;
  1065. //
  1066. // Check whether the token or signal already existed.
  1067. //
  1068. if (EFI_ERROR (NetMapIterate (&IpInstance->TxTokens, Ip6TokenExist, Token))) {
  1069. Status = EFI_ACCESS_DENIED;
  1070. goto Exit;
  1071. }
  1072. //
  1073. // Build the IP header, fill in the information from ConfigData or OverrideData
  1074. //
  1075. ZeroMem (&Head, sizeof (EFI_IP6_HEADER));
  1076. TxData = Token->Packet.TxData;
  1077. IP6_COPY_ADDRESS (&Head.SourceAddress, &Config->StationAddress);
  1078. IP6_COPY_ADDRESS (&Head.DestinationAddress, &Config->DestinationAddress);
  1079. Status = EFI_INVALID_PARAMETER;
  1080. if (NetIp6IsUnspecifiedAddr (&TxData->DestinationAddress)) {
  1081. if (NetIp6IsUnspecifiedAddr (&Config->DestinationAddress)) {
  1082. goto Exit;
  1083. }
  1084. ASSERT (!NetIp6IsUnspecifiedAddr (&Config->StationAddress));
  1085. } else {
  1086. //
  1087. // StationAddress is unspecified only when ConfigData.Dest is unspecified.
  1088. // Use TxData.Dest to override the DestinationAddress.
  1089. //
  1090. if (!NetIp6IsUnspecifiedAddr (&Config->DestinationAddress)) {
  1091. goto Exit;
  1092. }
  1093. if (NetIp6IsUnspecifiedAddr (&Config->StationAddress)) {
  1094. Status = Ip6SelectSourceAddress (
  1095. IpSb,
  1096. &TxData->DestinationAddress,
  1097. &Head.SourceAddress
  1098. );
  1099. if (EFI_ERROR (Status)) {
  1100. goto Exit;
  1101. }
  1102. }
  1103. IP6_COPY_ADDRESS (&Head.DestinationAddress, &TxData->DestinationAddress);
  1104. }
  1105. //
  1106. // Fill in Head infos.
  1107. //
  1108. Head.NextHeader = Config->DefaultProtocol;
  1109. if (TxData->ExtHdrsLength != 0) {
  1110. Head.NextHeader = TxData->NextHeader;
  1111. }
  1112. if (TxData->OverrideData != NULL) {
  1113. Override = TxData->OverrideData;
  1114. Head.NextHeader = Override->Protocol;
  1115. Head.HopLimit = Override->HopLimit;
  1116. Head.FlowLabelL = HTONS ((UINT16)Override->FlowLabel);
  1117. Head.FlowLabelH = (UINT8)((Override->FlowLabel >> 16) & 0x0F);
  1118. } else {
  1119. Head.HopLimit = Config->HopLimit;
  1120. Head.FlowLabelL = HTONS ((UINT16)Config->FlowLabel);
  1121. Head.FlowLabelH = (UINT8)((Config->FlowLabel >> 16) & 0x0F);
  1122. }
  1123. Head.PayloadLength = HTONS ((UINT16)(TxData->ExtHdrsLength + TxData->DataLength));
  1124. //
  1125. // OK, it survives all the validation check. Wrap the token in
  1126. // a IP6_TXTOKEN_WRAP and the data in a netbuf
  1127. //
  1128. Status = EFI_OUT_OF_RESOURCES;
  1129. Wrap = AllocateZeroPool (sizeof (IP6_TXTOKEN_WRAP));
  1130. if (Wrap == NULL) {
  1131. goto Exit;
  1132. }
  1133. Wrap->IpInstance = IpInstance;
  1134. Wrap->Token = Token;
  1135. Wrap->Sent = FALSE;
  1136. Wrap->Life = IP6_US_TO_SEC (Config->TransmitTimeout);
  1137. Wrap->Packet = NetbufFromExt (
  1138. (NET_FRAGMENT *)TxData->FragmentTable,
  1139. TxData->FragmentCount,
  1140. IP6_MAX_HEADLEN,
  1141. 0,
  1142. Ip6FreeTxToken,
  1143. Wrap
  1144. );
  1145. if (Wrap->Packet == NULL) {
  1146. FreePool (Wrap);
  1147. goto Exit;
  1148. }
  1149. Token->Status = EFI_NOT_READY;
  1150. Status = NetMapInsertTail (&IpInstance->TxTokens, Token, Wrap);
  1151. if (EFI_ERROR (Status)) {
  1152. //
  1153. // NetbufFree will call Ip6FreeTxToken, which in turn will
  1154. // free the IP6_TXTOKEN_WRAP. Now, the token wrap hasn't been
  1155. // enqueued.
  1156. //
  1157. NetbufFree (Wrap->Packet);
  1158. goto Exit;
  1159. }
  1160. //
  1161. // Allocate a new buffer to store IPv6 extension headers to avoid updating
  1162. // the original data in EFI_IP6_COMPLETION_TOKEN.
  1163. //
  1164. if ((TxData->ExtHdrsLength != 0) && (TxData->ExtHdrs != NULL)) {
  1165. ExtHdrs = (UINT8 *)AllocateCopyPool (TxData->ExtHdrsLength, TxData->ExtHdrs);
  1166. if (ExtHdrs == NULL) {
  1167. Status = EFI_OUT_OF_RESOURCES;
  1168. goto Exit;
  1169. }
  1170. }
  1171. //
  1172. // Mark the packet sent before output it. Mark it not sent again if the
  1173. // returned status is not EFI_SUCCESS;
  1174. //
  1175. Wrap->Sent = TRUE;
  1176. Status = Ip6Output (
  1177. IpSb,
  1178. NULL,
  1179. IpInstance,
  1180. Wrap->Packet,
  1181. &Head,
  1182. ExtHdrs,
  1183. TxData->ExtHdrsLength,
  1184. Ip6OnPacketSent,
  1185. Wrap
  1186. );
  1187. if (EFI_ERROR (Status)) {
  1188. Wrap->Sent = FALSE;
  1189. NetbufFree (Wrap->Packet);
  1190. }
  1191. Exit:
  1192. gBS->RestoreTPL (OldTpl);
  1193. if (ExtHdrs != NULL) {
  1194. FreePool (ExtHdrs);
  1195. }
  1196. return Status;
  1197. }
  1198. /**
  1199. Places a receiving request into the receiving queue.
  1200. The Receive() function places a completion token into the receive packet queue.
  1201. This function is always asynchronous.
  1202. The Token.Event field in the completion token must be filled in by the caller
  1203. and cannot be NULL. When the receive operation completes, the EFI IPv6 Protocol
  1204. driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
  1205. is signaled.
  1206. Current Udp implementation creates an IP child for each Udp child.
  1207. It initiates a asynchronous receive immediately no matter whether
  1208. there is no mapping or not. Therefore, disable the returning EFI_NO_MAPPING for now.
  1209. To enable it, the following check must be performed:
  1210. if (NetIp6IsUnspecifiedAddr (&Config->StationAddress) && IP6_NO_MAPPING (IpInstance)) {
  1211. Status = EFI_NO_MAPPING;
  1212. goto Exit;
  1213. }
  1214. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  1215. @param[in] Token Pointer to a token that is associated with the receive data descriptor.
  1216. @retval EFI_SUCCESS The receive completion token was cached.
  1217. @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
  1218. @retval EFI_NO_MAPPING When IP6 driver responsible for binding source address to this instance,
  1219. while no source address is available for use.
  1220. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  1221. - This is NULL.
  1222. - Token is NULL.
  1223. - Token.Event is NULL.
  1224. @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
  1225. resources (usually memory).
  1226. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  1227. The EFI IPv6 Protocol instance has been reset to startup defaults.
  1228. @retval EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
  1229. in the receive queue.
  1230. @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
  1231. **/
  1232. EFI_STATUS
  1233. EFIAPI
  1234. EfiIp6Receive (
  1235. IN EFI_IP6_PROTOCOL *This,
  1236. IN EFI_IP6_COMPLETION_TOKEN *Token
  1237. )
  1238. {
  1239. IP6_PROTOCOL *IpInstance;
  1240. EFI_STATUS Status;
  1241. EFI_TPL OldTpl;
  1242. IP6_SERVICE *IpSb;
  1243. if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {
  1244. return EFI_INVALID_PARAMETER;
  1245. }
  1246. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  1247. IpSb = IpInstance->Service;
  1248. if (IpSb->LinkLocalDadFail) {
  1249. return EFI_DEVICE_ERROR;
  1250. }
  1251. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  1252. if (IpInstance->State != IP6_STATE_CONFIGED) {
  1253. Status = EFI_NOT_STARTED;
  1254. goto Exit;
  1255. }
  1256. //
  1257. // Check whether the toke is already on the receive queue.
  1258. //
  1259. Status = NetMapIterate (&IpInstance->RxTokens, Ip6TokenExist, Token);
  1260. if (EFI_ERROR (Status)) {
  1261. Status = EFI_ACCESS_DENIED;
  1262. goto Exit;
  1263. }
  1264. //
  1265. // Queue the token then check whether there is pending received packet.
  1266. //
  1267. Status = NetMapInsertTail (&IpInstance->RxTokens, Token, NULL);
  1268. if (EFI_ERROR (Status)) {
  1269. goto Exit;
  1270. }
  1271. Status = Ip6InstanceDeliverPacket (IpInstance);
  1272. //
  1273. // Dispatch the DPC queued by the NotifyFunction of this instane's receive
  1274. // event.
  1275. //
  1276. DispatchDpc ();
  1277. Exit:
  1278. gBS->RestoreTPL (OldTpl);
  1279. return Status;
  1280. }
  1281. /**
  1282. Cancel the transmitted but not recycled packet. If a matching
  1283. token is found, it will call Ip6CancelPacket to cancel the
  1284. packet. Ip6CancelPacket cancels all the fragments of the
  1285. packet. When all the fragments are freed, the IP6_TXTOKEN_WRAP
  1286. is deleted from the Map, and user's event is signalled.
  1287. Because Ip6CancelPacket and other functions are all called in
  1288. line, after Ip6CancelPacket returns, the Item has been freed.
  1289. @param[in] Map The IP6 child's transmit queue.
  1290. @param[in] Item The current transmitted packet to test.
  1291. @param[in] Context The user's token to cancel.
  1292. @retval EFI_SUCCESS Continue to check the next Item.
  1293. @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
  1294. **/
  1295. EFI_STATUS
  1296. EFIAPI
  1297. Ip6CancelTxTokens (
  1298. IN NET_MAP *Map,
  1299. IN NET_MAP_ITEM *Item,
  1300. IN VOID *Context
  1301. )
  1302. {
  1303. EFI_IP6_COMPLETION_TOKEN *Token;
  1304. IP6_TXTOKEN_WRAP *Wrap;
  1305. Token = (EFI_IP6_COMPLETION_TOKEN *)Context;
  1306. //
  1307. // Return EFI_SUCCESS to check the next item in the map if
  1308. // this one doesn't match.
  1309. //
  1310. if ((Token != NULL) && (Token != Item->Key)) {
  1311. return EFI_SUCCESS;
  1312. }
  1313. Wrap = (IP6_TXTOKEN_WRAP *)Item->Value;
  1314. ASSERT (Wrap != NULL);
  1315. //
  1316. // Don't access the Item, Wrap and Token's members after this point.
  1317. // Item and wrap has been freed. And we no longer own the Token.
  1318. //
  1319. Ip6CancelPacket (Wrap->IpInstance->Interface, Wrap->Packet, EFI_ABORTED);
  1320. //
  1321. // If only one item is to be cancel, return EFI_ABORTED to stop
  1322. // iterating the map any more.
  1323. //
  1324. if (Token != NULL) {
  1325. return EFI_ABORTED;
  1326. }
  1327. return EFI_SUCCESS;
  1328. }
  1329. /**
  1330. Cancel the receive request. This is simple, because
  1331. it is only enqueued in our local receive map.
  1332. @param[in] Map The IP6 child's receive queue.
  1333. @param[in] Item Current receive request to cancel.
  1334. @param[in] Context The user's token to cancel.
  1335. @retval EFI_SUCCESS Continue to check the next receive request on the
  1336. queue.
  1337. @retval EFI_ABORTED The user's token (token != NULL) has been
  1338. cancelled.
  1339. **/
  1340. EFI_STATUS
  1341. EFIAPI
  1342. Ip6CancelRxTokens (
  1343. IN NET_MAP *Map,
  1344. IN NET_MAP_ITEM *Item,
  1345. IN VOID *Context
  1346. )
  1347. {
  1348. EFI_IP6_COMPLETION_TOKEN *Token;
  1349. EFI_IP6_COMPLETION_TOKEN *This;
  1350. Token = (EFI_IP6_COMPLETION_TOKEN *)Context;
  1351. This = Item->Key;
  1352. if ((Token != NULL) && (Token != This)) {
  1353. return EFI_SUCCESS;
  1354. }
  1355. NetMapRemoveItem (Map, Item, NULL);
  1356. This->Status = EFI_ABORTED;
  1357. This->Packet.RxData = NULL;
  1358. gBS->SignalEvent (This->Event);
  1359. if (Token != NULL) {
  1360. return EFI_ABORTED;
  1361. }
  1362. return EFI_SUCCESS;
  1363. }
  1364. /**
  1365. Cancel the user's receive/transmit request. It is the worker function of
  1366. EfiIp6Cancel API.
  1367. @param[in] IpInstance The IP6 child.
  1368. @param[in] Token The token to cancel. If NULL, all token will be
  1369. cancelled.
  1370. @retval EFI_SUCCESS The token is cancelled.
  1371. @retval EFI_NOT_FOUND The token isn't found on either the
  1372. transmit/receive queue.
  1373. @retval EFI_DEVICE_ERROR Not all tokens are cancelled when Token is NULL.
  1374. **/
  1375. EFI_STATUS
  1376. Ip6Cancel (
  1377. IN IP6_PROTOCOL *IpInstance,
  1378. IN EFI_IP6_COMPLETION_TOKEN *Token OPTIONAL
  1379. )
  1380. {
  1381. EFI_STATUS Status;
  1382. //
  1383. // First check the transmitted packet. Ip6CancelTxTokens returns
  1384. // EFI_ABORTED to mean that the token has been cancelled when
  1385. // token != NULL. So, return EFI_SUCCESS for this condition.
  1386. //
  1387. Status = NetMapIterate (&IpInstance->TxTokens, Ip6CancelTxTokens, Token);
  1388. if (EFI_ERROR (Status)) {
  1389. if ((Token != NULL) && (Status == EFI_ABORTED)) {
  1390. return EFI_SUCCESS;
  1391. }
  1392. return Status;
  1393. }
  1394. //
  1395. // Check the receive queue. Ip6CancelRxTokens also returns EFI_ABORT
  1396. // for Token!=NULL and it is cancelled.
  1397. //
  1398. Status = NetMapIterate (&IpInstance->RxTokens, Ip6CancelRxTokens, Token);
  1399. //
  1400. // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
  1401. // events.
  1402. //
  1403. DispatchDpc ();
  1404. if (EFI_ERROR (Status)) {
  1405. if ((Token != NULL) && (Status == EFI_ABORTED)) {
  1406. return EFI_SUCCESS;
  1407. }
  1408. return Status;
  1409. }
  1410. //
  1411. // OK, if the Token is found when Token != NULL, the NetMapIterate
  1412. // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
  1413. //
  1414. if (Token != NULL) {
  1415. return EFI_NOT_FOUND;
  1416. }
  1417. //
  1418. // If Token == NULL, cancel all the tokens. return error if not
  1419. // all of them are cancelled.
  1420. //
  1421. if (!NetMapIsEmpty (&IpInstance->TxTokens) || !NetMapIsEmpty (&IpInstance->RxTokens)) {
  1422. return EFI_DEVICE_ERROR;
  1423. }
  1424. return EFI_SUCCESS;
  1425. }
  1426. /**
  1427. Abort an asynchronous transmit or receive request.
  1428. The Cancel() function is used to abort a pending transmit or receive request.
  1429. If the token is in the transmit or receive request queues, after calling this
  1430. function, Token->Status will be set to EFI_ABORTED, and then Token->Event will
  1431. be signaled. If the token is not in one of the queues, which usually means the
  1432. asynchronous operation has completed, this function will not signal the token,
  1433. and EFI_NOT_FOUND is returned.
  1434. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  1435. @param[in] Token Pointer to a token that has been issued by
  1436. EFI_IP6_PROTOCOL.Transmit() or
  1437. EFI_IP6_PROTOCOL.Receive(). If NULL, all pending
  1438. tokens are aborted. Type EFI_IP6_COMPLETION_TOKEN is
  1439. defined in EFI_IP6_PROTOCOL.Transmit().
  1440. @retval EFI_SUCCESS The asynchronous I/O request was aborted and
  1441. Token->Event was signaled. When Token is NULL, all
  1442. pending requests were aborted, and their events were signaled.
  1443. @retval EFI_INVALID_PARAMETER This is NULL.
  1444. @retval EFI_NOT_STARTED This instance has not been started.
  1445. @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
  1446. not found in the transmit or receive queue. It has either completed
  1447. or was not issued by Transmit() and Receive().
  1448. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  1449. **/
  1450. EFI_STATUS
  1451. EFIAPI
  1452. EfiIp6Cancel (
  1453. IN EFI_IP6_PROTOCOL *This,
  1454. IN EFI_IP6_COMPLETION_TOKEN *Token OPTIONAL
  1455. )
  1456. {
  1457. IP6_PROTOCOL *IpInstance;
  1458. EFI_STATUS Status;
  1459. EFI_TPL OldTpl;
  1460. if (This == NULL) {
  1461. return EFI_INVALID_PARAMETER;
  1462. }
  1463. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  1464. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  1465. if (IpInstance->State != IP6_STATE_CONFIGED) {
  1466. Status = EFI_NOT_STARTED;
  1467. goto Exit;
  1468. }
  1469. Status = Ip6Cancel (IpInstance, Token);
  1470. Exit:
  1471. gBS->RestoreTPL (OldTpl);
  1472. return Status;
  1473. }
  1474. /**
  1475. Polls for incoming data packets, and processes outgoing data packets.
  1476. The Poll() function polls for incoming data packets and processes outgoing data
  1477. packets. Network drivers and applications can call the EFI_IP6_PROTOCOL.Poll()
  1478. function to increase the rate that data packets are moved between the communications
  1479. device and the transmit and receive queues.
  1480. In some systems the periodic timer event may not poll the underlying communications
  1481. device fast enough to transmit and/or receive all data packets without missing
  1482. incoming packets or dropping outgoing packets. Drivers and applications that are
  1483. experiencing packet loss should try calling the EFI_IP6_PROTOCOL.Poll() function
  1484. more often.
  1485. @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
  1486. @retval EFI_SUCCESS Incoming or outgoing data was processed.
  1487. @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
  1488. @retval EFI_INVALID_PARAMETER This is NULL.
  1489. @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
  1490. @retval EFI_NOT_READY No incoming or outgoing data was processed.
  1491. @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
  1492. Consider increasing the polling rate.
  1493. **/
  1494. EFI_STATUS
  1495. EFIAPI
  1496. EfiIp6Poll (
  1497. IN EFI_IP6_PROTOCOL *This
  1498. )
  1499. {
  1500. IP6_PROTOCOL *IpInstance;
  1501. IP6_SERVICE *IpSb;
  1502. EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
  1503. if (This == NULL) {
  1504. return EFI_INVALID_PARAMETER;
  1505. }
  1506. IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);
  1507. IpSb = IpInstance->Service;
  1508. if (IpSb->LinkLocalDadFail) {
  1509. return EFI_DEVICE_ERROR;
  1510. }
  1511. if (IpInstance->State == IP6_STATE_UNCONFIGED) {
  1512. return EFI_NOT_STARTED;
  1513. }
  1514. Mnp = IpInstance->Service->Mnp;
  1515. //
  1516. // Don't lock the Poll function to enable the deliver of
  1517. // the packet polled up.
  1518. //
  1519. return Mnp->Poll (Mnp);
  1520. }