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