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