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