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