]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | Implementation of EFI_IP6_PROTOCOL protocol interfaces.\r | |
3 | \r | |
d551cc64 | 4 | Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r |
a3bcde70 HT |
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 | 18 | EFI_IPSEC2_PROTOCOL *mIpSec = NULL;\r |
a3bcde70 HT |
19 | \r |
20 | EFI_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 | |
49 | EFI_STATUS\r | |
50 | EFIAPI\r | |
51 | EfiIp6GetModeData (\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 | |
202 | Error:\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 | |
229 | Exit:\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 | |
248 | BOOLEAN\r | |
249 | Ip6IsValidAddress (\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 | |
279 | BOOLEAN\r | |
280 | Ip6IsIllegalProtocol (\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 | |
302 | VOID\r | |
303 | Ip6InitProtocol (\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 | |
346 | EFI_STATUS\r | |
347 | Ip6ConfigProtocol (\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 | |
448 | EFI_STATUS\r | |
449 | Ip6CleanProtocol (\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 | |
507 | EFI_STATUS\r | |
508 | Ip6ServiceConfigMnp (\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 | |
615 | EFI_STATUS\r | |
616 | EFIAPI\r | |
617 | EfiIp6Configure (\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 | |
216f7970 | 638 | if (IpSb->LinkLocalDadFail && Ip6ConfigData != NULL) {\r |
a3bcde70 HT |
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 | |
75dce340 | 692 | // Don't change the state if it is DESTROY, consider the following\r |
a3bcde70 HT |
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 | |
a3bcde70 HT |
708 | Exit:\r |
709 | gBS->RestoreTPL (OldTpl);\r | |
710 | return Status;\r | |
711 | }\r | |
712 | \r | |
713 | /**\r | |
714 | Joins and leaves multicast groups.\r | |
715 | \r | |
716 | The Groups() function is used to join and leave multicast group sessions. Joining a group will\r | |
717 | enable reception of matching multicast packets. Leaving a group will disable reception of matching\r | |
718 | multicast packets. Source-Specific Multicast isn't required to be supported.\r | |
719 | \r | |
720 | If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.\r | |
721 | \r | |
722 | @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.\r | |
723 | @param[in] JoinFlag Set to TRUE to join the multicast group session, and FALSE to leave.\r | |
724 | @param[in] GroupAddress Pointer to the IPv6 multicast address.\r | |
725 | This is an optional parameter that may be NULL.\r | |
726 | \r | |
727 | @retval EFI_SUCCESS The operation completed successfully.\r | |
728 | @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:\r | |
729 | - This is NULL.\r | |
730 | - JoinFlag is TRUE and GroupAddress is NULL.\r | |
731 | - GroupAddress is not NULL and *GroupAddress is\r | |
732 | not a multicast IPv6 address.\r | |
733 | - GroupAddress is not NULL and *GroupAddress is in the\r | |
734 | range of SSM destination address.\r | |
735 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
736 | @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.\r | |
737 | @retval EFI_UNSUPPORTED This EFI IPv6 Protocol implementation does not support multicast groups.\r | |
738 | @retval EFI_ALREADY_STARTED The group address is already in the group table (when\r | |
739 | JoinFlag is TRUE).\r | |
740 | @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).\r | |
741 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
742 | \r | |
743 | **/\r | |
744 | EFI_STATUS\r | |
745 | EFIAPI\r | |
746 | EfiIp6Groups (\r | |
747 | IN EFI_IP6_PROTOCOL *This,\r | |
748 | IN BOOLEAN JoinFlag,\r | |
749 | IN EFI_IPv6_ADDRESS *GroupAddress OPTIONAL\r | |
750 | )\r | |
751 | {\r | |
752 | EFI_TPL OldTpl;\r | |
753 | EFI_STATUS Status;\r | |
754 | IP6_PROTOCOL *IpInstance;\r | |
755 | IP6_SERVICE *IpSb;\r | |
756 | \r | |
757 | if ((This == NULL) || (JoinFlag && GroupAddress == NULL)) {\r | |
758 | return EFI_INVALID_PARAMETER;\r | |
759 | }\r | |
760 | \r | |
761 | if (GroupAddress != NULL && !IP6_IS_MULTICAST (GroupAddress)) {\r | |
762 | return EFI_INVALID_PARAMETER;\r | |
763 | }\r | |
764 | \r | |
765 | IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);\r | |
766 | IpSb = IpInstance->Service;\r | |
767 | \r | |
768 | if (IpSb->LinkLocalDadFail) {\r | |
769 | return EFI_DEVICE_ERROR;\r | |
770 | }\r | |
771 | \r | |
772 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
773 | \r | |
774 | if (IpInstance->State != IP6_STATE_CONFIGED) {\r | |
775 | Status = EFI_NOT_STARTED;\r | |
776 | goto ON_EXIT;\r | |
777 | }\r | |
778 | \r | |
779 | Status = Ip6Groups (IpInstance, JoinFlag, GroupAddress);\r | |
780 | \r | |
781 | ON_EXIT:\r | |
782 | gBS->RestoreTPL (OldTpl);\r | |
783 | return Status;\r | |
784 | }\r | |
785 | \r | |
786 | /**\r | |
787 | Adds and deletes routing table entries.\r | |
788 | \r | |
789 | The Routes() function adds a route to, or deletes a route from, the routing table.\r | |
790 | \r | |
791 | Routes are determined by comparing the leftmost PrefixLength bits of Destination with\r | |
792 | the destination IPv6 address arithmetically. The gateway address must be on the same subnet as the\r | |
793 | configured station address.\r | |
794 | \r | |
795 | The default route is added with Destination and PrefixLegth both set to all zeros. The\r | |
796 | default route matches all destination IPv6 addresses that do not match any other routes.\r | |
797 | \r | |
798 | All EFI IPv6 Protocol instances share a routing table.\r | |
799 | \r | |
800 | @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.\r | |
801 | @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to\r | |
802 | FALSE to add this route to the routing table. Destination,\r | |
803 | PrefixLength and Gateway are used as the key to each\r | |
804 | route entry.\r | |
805 | @param[in] Destination The address prefix of the subnet that needs to be routed.\r | |
806 | This is an optional parameter that may be NULL.\r | |
807 | @param[in] PrefixLength The prefix length of Destination. Ignored if Destination\r | |
808 | is NULL.\r | |
809 | @param[in] GatewayAddress The unicast gateway IPv6 address for this route.\r | |
810 | This is an optional parameter that may be NULL.\r | |
811 | \r | |
812 | @retval EFI_SUCCESS The operation completed successfully.\r | |
813 | @retval EFI_NOT_STARTED The driver instance has not been started.\r | |
814 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
815 | - This is NULL.\r | |
816 | - When DeleteRoute is TRUE, both Destination and\r | |
817 | GatewayAddress are NULL.\r | |
818 | - When DeleteRoute is FALSE, either Destination or\r | |
819 | GatewayAddress is NULL.\r | |
820 | - *GatewayAddress is not a valid unicast IPv6 address.\r | |
821 | - *GatewayAddress is one of the local configured IPv6\r | |
822 | addresses.\r | |
823 | @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.\r | |
824 | @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).\r | |
825 | @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when\r | |
826 | DeleteRoute is FALSE).\r | |
827 | \r | |
828 | **/\r | |
829 | EFI_STATUS\r | |
830 | EFIAPI\r | |
831 | EfiIp6Routes (\r | |
832 | IN EFI_IP6_PROTOCOL *This,\r | |
833 | IN BOOLEAN DeleteRoute,\r | |
834 | IN EFI_IPv6_ADDRESS *Destination OPTIONAL,\r | |
835 | IN UINT8 PrefixLength,\r | |
836 | IN EFI_IPv6_ADDRESS *GatewayAddress OPTIONAL\r | |
837 | )\r | |
838 | {\r | |
839 | IP6_PROTOCOL *IpInstance;\r | |
840 | EFI_STATUS Status;\r | |
841 | EFI_TPL OldTpl;\r | |
842 | IP6_SERVICE *IpSb;\r | |
843 | \r | |
844 | if ((This == NULL) || (PrefixLength >= IP6_PREFIX_NUM)) {\r | |
845 | return EFI_INVALID_PARAMETER;\r | |
846 | }\r | |
847 | \r | |
848 | IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);\r | |
849 | IpSb = IpInstance->Service;\r | |
850 | \r | |
851 | if (IpSb->LinkLocalDadFail) {\r | |
852 | return EFI_DEVICE_ERROR;\r | |
853 | }\r | |
854 | \r | |
855 | if (IpInstance->State != IP6_STATE_CONFIGED) {\r | |
856 | return EFI_NOT_STARTED;\r | |
857 | }\r | |
858 | \r | |
859 | if (DeleteRoute && (Destination == NULL) && (GatewayAddress == NULL)) {\r | |
860 | return EFI_INVALID_PARAMETER;\r | |
861 | }\r | |
862 | \r | |
863 | if (!DeleteRoute && (Destination == NULL || GatewayAddress == NULL)) {\r | |
864 | return EFI_INVALID_PARAMETER;\r | |
865 | }\r | |
866 | \r | |
867 | if (GatewayAddress != NULL) {\r | |
868 | if (!Ip6IsValidAddress (IpSb, GatewayAddress, FALSE)) {\r | |
869 | return EFI_INVALID_PARAMETER;\r | |
870 | }\r | |
871 | \r | |
872 | if (!NetIp6IsUnspecifiedAddr (GatewayAddress) &&\r | |
873 | !NetIp6IsNetEqual (GatewayAddress, &IpInstance->ConfigData.StationAddress, PrefixLength)\r | |
874 | ) {\r | |
875 | return EFI_INVALID_PARAMETER;\r | |
876 | }\r | |
877 | }\r | |
878 | \r | |
879 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
880 | \r | |
881 | //\r | |
882 | // Update the route table\r | |
883 | //\r | |
884 | if (DeleteRoute) {\r | |
885 | Status = Ip6DelRoute (IpSb->RouteTable, Destination, PrefixLength, GatewayAddress);\r | |
886 | } else {\r | |
887 | Status = Ip6AddRoute (IpSb->RouteTable, Destination, PrefixLength, GatewayAddress);\r | |
888 | }\r | |
889 | \r | |
890 | gBS->RestoreTPL (OldTpl);\r | |
891 | return Status;\r | |
892 | }\r | |
893 | \r | |
894 | /**\r | |
895 | Add or delete Neighbor cache entries.\r | |
896 | \r | |
897 | The Neighbors() function is used to add, update, or delete an entry from neighbor cache.\r | |
898 | IPv6 neighbor cache entries are typically inserted and updated by the network protocol driver as\r | |
899 | network traffic is processed. Most neighbor cache entries will timeout and be deleted if the network\r | |
900 | traffic stops. Neighbor cache entries that were inserted by Neighbors() may be static (will not\r | |
901 | timeout) or dynamic (will timeout).\r | |
902 | \r | |
903 | The implementation should follow the neighbor cache timeout mechanism which is defined in\r | |
904 | RFC4861. The default neighbor cache timeout value should be tuned for the expected network\r | |
905 | environment\r | |
906 | \r | |
907 | @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.\r | |
908 | @param[in] DeleteFlag Set to TRUE to delete the specified cache entry, set to FALSE to\r | |
909 | add (or update, if it already exists and Override is TRUE) the\r | |
910 | specified cache entry. TargetIp6Address is used as the key\r | |
911 | to find the requested cache entry.\r | |
912 | @param[in] TargetIp6Address Pointer to the Target IPv6 address.\r | |
913 | @param[in] TargetLinkAddress Pointer to the link-layer address of the target. Ignored if NULL.\r | |
914 | @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor\r | |
915 | cache, it will be deleted after Timeout. A value of zero means that\r | |
916 | the entry is permanent. A non-zero value means that the entry is\r | |
917 | dynamic.\r | |
918 | @param[in] Override If TRUE, the cached link-layer address of the matching entry will\r | |
919 | be overridden and updated; if FALSE, EFI_ACCESS_DENIED\r | |
920 | will be returned if a corresponding cache entry already existed.\r | |
921 | \r | |
922 | @retval EFI_SUCCESS The data has been queued for transmission.\r | |
923 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
924 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
925 | - This is NULL.\r | |
926 | - TargetIpAddress is NULL.\r | |
927 | - *TargetLinkAddress is invalid when not NULL.\r | |
928 | - *TargetIpAddress is not a valid unicast IPv6 address.\r | |
929 | - *TargetIpAddress is one of the local configured IPv6\r | |
930 | addresses.\r | |
931 | @retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache.\r | |
932 | @retval EFI_NOT_FOUND This entry is not in the neighbor cache (when DeleteFlag is\r | |
933 | TRUE or when DeleteFlag is FALSE while\r | |
934 | TargetLinkAddress is NULL.).\r | |
935 | @retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,\r | |
936 | and that entry is tagged as un-overridden (when Override\r | |
937 | is FALSE).\r | |
938 | \r | |
939 | **/\r | |
940 | EFI_STATUS\r | |
941 | EFIAPI\r | |
942 | EfiIp6Neighbors (\r | |
943 | IN EFI_IP6_PROTOCOL *This,\r | |
944 | IN BOOLEAN DeleteFlag,\r | |
945 | IN EFI_IPv6_ADDRESS *TargetIp6Address,\r | |
946 | IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL,\r | |
947 | IN UINT32 Timeout,\r | |
948 | IN BOOLEAN Override\r | |
949 | )\r | |
950 | {\r | |
951 | EFI_TPL OldTpl;\r | |
952 | EFI_STATUS Status;\r | |
953 | IP6_PROTOCOL *IpInstance;\r | |
954 | IP6_SERVICE *IpSb;\r | |
955 | \r | |
956 | if (This == NULL || TargetIp6Address == NULL) {\r | |
957 | return EFI_INVALID_PARAMETER;\r | |
958 | }\r | |
959 | \r | |
960 | if (NetIp6IsUnspecifiedAddr (TargetIp6Address)) {\r | |
961 | return EFI_INVALID_PARAMETER;\r | |
962 | }\r | |
963 | \r | |
964 | IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);\r | |
965 | IpSb = IpInstance->Service;\r | |
966 | \r | |
967 | if (IpSb->LinkLocalDadFail) {\r | |
968 | return EFI_DEVICE_ERROR;\r | |
969 | }\r | |
970 | \r | |
971 | if (!Ip6IsValidAddress (IpSb, TargetIp6Address, FALSE)) {\r | |
972 | return EFI_INVALID_PARAMETER;\r | |
973 | }\r | |
974 | \r | |
975 | if (TargetLinkAddress != NULL) {\r | |
976 | if (!Ip6IsValidLinkAddress (IpSb, TargetLinkAddress)) {\r | |
977 | return EFI_INVALID_PARAMETER;\r | |
978 | }\r | |
979 | }\r | |
980 | \r | |
981 | if (Ip6IsOneOfSetAddress (IpSb, TargetIp6Address, NULL, NULL)) {\r | |
982 | return EFI_INVALID_PARAMETER;\r | |
983 | }\r | |
984 | \r | |
985 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
986 | if (IpInstance->State != IP6_STATE_CONFIGED) {\r | |
987 | Status = EFI_NOT_STARTED;\r | |
988 | goto Exit;\r | |
989 | }\r | |
990 | \r | |
991 | if (DeleteFlag) {\r | |
992 | Status = Ip6DelNeighbor (IpInstance->Service, TargetIp6Address, TargetLinkAddress, Timeout, Override);\r | |
993 | } else {\r | |
994 | Status = Ip6AddNeighbor (IpInstance->Service, TargetIp6Address, TargetLinkAddress, Timeout, Override);\r | |
995 | }\r | |
996 | \r | |
997 | Exit:\r | |
998 | gBS->RestoreTPL (OldTpl);\r | |
999 | return Status;\r | |
1000 | }\r | |
1001 | \r | |
1002 | /**\r | |
1003 | Check whether the user's token or event has already\r | |
1004 | been enqueue on IP6's list.\r | |
1005 | \r | |
1006 | @param[in] Map The container of either user's transmit or receive\r | |
1007 | token.\r | |
1008 | @param[in] Item Current item to check against.\r | |
1009 | @param[in] Context The Token to check againist.\r | |
1010 | \r | |
1011 | @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP\r | |
1012 | @retval EFI_SUCCESS The current item isn't the same token/event as the\r | |
1013 | context.\r | |
1014 | \r | |
1015 | **/\r | |
1016 | EFI_STATUS\r | |
1017 | EFIAPI\r | |
1018 | Ip6TokenExist (\r | |
1019 | IN NET_MAP *Map,\r | |
1020 | IN NET_MAP_ITEM *Item,\r | |
1021 | IN VOID *Context\r | |
1022 | )\r | |
1023 | {\r | |
1024 | EFI_IP6_COMPLETION_TOKEN *Token;\r | |
1025 | EFI_IP6_COMPLETION_TOKEN *TokenInItem;\r | |
1026 | \r | |
1027 | Token = (EFI_IP6_COMPLETION_TOKEN *) Context;\r | |
1028 | TokenInItem = (EFI_IP6_COMPLETION_TOKEN *) Item->Key;\r | |
1029 | \r | |
1030 | if (Token == TokenInItem || Token->Event == TokenInItem->Event) {\r | |
1031 | return EFI_ACCESS_DENIED;\r | |
1032 | }\r | |
1033 | \r | |
1034 | return EFI_SUCCESS;\r | |
1035 | }\r | |
1036 | \r | |
1037 | /**\r | |
1038 | Validate the user's token against the current station address.\r | |
1039 | \r | |
1040 | @param[in] Token User's token to validate.\r | |
1041 | \r | |
1042 | @retval EFI_INVALID_PARAMETER Some parameters are invalid.\r | |
1043 | @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.\r | |
1044 | @retval EFI_SUCCESS The token is OK.\r | |
1045 | \r | |
1046 | **/\r | |
1047 | EFI_STATUS\r | |
1048 | Ip6TxTokenValid (\r | |
1049 | IN EFI_IP6_COMPLETION_TOKEN *Token\r | |
1050 | )\r | |
1051 | {\r | |
1052 | EFI_IP6_TRANSMIT_DATA *TxData;\r | |
1053 | UINT32 Index;\r | |
1054 | UINT32 DataLength;\r | |
1055 | \r | |
1056 | if (Token == NULL || Token->Event == NULL) {\r | |
1057 | return EFI_INVALID_PARAMETER;\r | |
1058 | }\r | |
1059 | \r | |
1060 | TxData = Token->Packet.TxData;\r | |
1061 | \r | |
1062 | if (TxData == NULL || (TxData->ExtHdrsLength != 0 && TxData->ExtHdrs == NULL)) {\r | |
1063 | return EFI_INVALID_PARAMETER;\r | |
1064 | }\r | |
1065 | \r | |
1066 | if (TxData->FragmentCount == 0 || TxData->DataLength == 0) {\r | |
1067 | return EFI_INVALID_PARAMETER;\r | |
1068 | }\r | |
1069 | \r | |
1070 | for (DataLength = 0, Index = 0; Index < TxData->FragmentCount; Index++) {\r | |
1071 | if (TxData->FragmentTable[Index].FragmentLength == 0 || TxData->FragmentTable[Index].FragmentBuffer == NULL) {\r | |
1072 | return EFI_INVALID_PARAMETER;\r | |
1073 | }\r | |
1074 | \r | |
1075 | DataLength += TxData->FragmentTable[Index].FragmentLength;\r | |
1076 | }\r | |
1077 | \r | |
1078 | if (TxData->DataLength != DataLength) {\r | |
1079 | return EFI_INVALID_PARAMETER;\r | |
1080 | }\r | |
1081 | \r | |
1082 | //\r | |
1083 | // TODO: Token.Packet.TxData.DataLength is too short to transmit.\r | |
1084 | // return EFI_BUFFER_TOO_SMALL;\r | |
1085 | //\r | |
1086 | \r | |
1087 | //\r | |
1088 | // If Token.Packet.TxData.DataLength is beyond the maximum that which can be\r | |
1089 | // described through the Fragment Offset field in Fragment header when performing\r | |
1090 | // fragmentation.\r | |
1091 | //\r | |
1092 | if (TxData->DataLength > 64 * 1024) {\r | |
1093 | return EFI_BAD_BUFFER_SIZE;\r | |
1094 | }\r | |
1095 | \r | |
1096 | return EFI_SUCCESS;\r | |
1097 | }\r | |
1098 | \r | |
1099 | /**\r | |
1100 | The callback function for the net buffer which wraps the user's\r | |
1101 | transmit token. Although this function seems simple, there\r | |
1102 | are some subtle aspects.\r | |
1103 | When user requests the IP to transmit a packet by passing it a\r | |
1104 | token, the token is wrapped in an IP6_TXTOKEN_WRAP and the data\r | |
1105 | is wrapped in an net buffer. The net buffer's Free function is\r | |
1106 | set to Ip6FreeTxToken. The Token and token wrap are added to the\r | |
1107 | IP child's TxToken map. Then the buffer is passed to Ip6Output for\r | |
1108 | transmission. If an error happened before that, the buffer\r | |
1109 | is freed, which in turn frees the token wrap. The wrap may\r | |
1110 | have been added to the TxToken map or not, and the user's event\r | |
1111 | shouldn't be fired because we are still in the EfiIp6Transmit. If\r | |
1112 | the buffer has been sent by Ip6Output, it should be removed from\r | |
1113 | the TxToken map and user's event signaled. The token wrap and buffer\r | |
1114 | are bound together. Check the comments in Ip6Output for information\r | |
1115 | about IP fragmentation.\r | |
1116 | \r | |
1117 | @param[in] Context The token's wrap.\r | |
1118 | \r | |
1119 | **/\r | |
1120 | VOID\r | |
1121 | EFIAPI\r | |
1122 | Ip6FreeTxToken (\r | |
1123 | IN VOID *Context\r | |
1124 | )\r | |
1125 | {\r | |
1126 | IP6_TXTOKEN_WRAP *Wrap;\r | |
1127 | NET_MAP_ITEM *Item;\r | |
1128 | \r | |
1129 | Wrap = (IP6_TXTOKEN_WRAP *) Context;\r | |
1130 | \r | |
1131 | //\r | |
1132 | // Signal IpSecRecycleEvent to inform IPsec free the memory\r | |
1133 | //\r | |
1134 | if (Wrap->IpSecRecycleSignal != NULL) {\r | |
1135 | gBS->SignalEvent (Wrap->IpSecRecycleSignal);\r | |
1136 | }\r | |
1137 | \r | |
1138 | //\r | |
1139 | // Find the token in the instance's map. EfiIp6Transmit put the\r | |
1140 | // token to the map. If that failed, NetMapFindKey will return NULL.\r | |
1141 | //\r | |
1142 | Item = NetMapFindKey (&Wrap->IpInstance->TxTokens, Wrap->Token);\r | |
1143 | \r | |
1144 | if (Item != NULL) {\r | |
1145 | NetMapRemoveItem (&Wrap->IpInstance->TxTokens, Item, NULL);\r | |
1146 | }\r | |
1147 | \r | |
1148 | if (Wrap->Sent) {\r | |
1149 | gBS->SignalEvent (Wrap->Token->Event);\r | |
1150 | \r | |
1151 | //\r | |
1152 | // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r | |
1153 | //\r | |
1154 | DispatchDpc ();\r | |
1155 | }\r | |
1156 | \r | |
1157 | FreePool (Wrap);\r | |
1158 | }\r | |
1159 | \r | |
1160 | \r | |
1161 | /**\r | |
1162 | The callback function to Ip6Output to update the transmit status.\r | |
1163 | \r | |
1164 | @param[in] Packet The user's transmit packet.\r | |
1165 | @param[in] IoStatus The result of the transmission.\r | |
1166 | @param[in] Flag Not used during transmission.\r | |
1167 | @param[in] Context The token's wrap.\r | |
1168 | \r | |
1169 | **/\r | |
1170 | VOID\r | |
1171 | Ip6OnPacketSent (\r | |
1172 | IN NET_BUF *Packet,\r | |
1173 | IN EFI_STATUS IoStatus,\r | |
1174 | IN UINT32 Flag,\r | |
1175 | IN VOID *Context\r | |
1176 | )\r | |
1177 | {\r | |
1178 | IP6_TXTOKEN_WRAP *Wrap;\r | |
1179 | \r | |
1180 | //\r | |
1181 | // This is the transmission request from upper layer,\r | |
1182 | // not the IP6 driver itself.\r | |
1183 | //\r | |
1184 | Wrap = (IP6_TXTOKEN_WRAP *) Context;\r | |
1185 | Wrap->Token->Status = IoStatus;\r | |
1186 | \r | |
1187 | NetbufFree (Wrap->Packet);\r | |
1188 | }\r | |
1189 | \r | |
1190 | /**\r | |
1191 | Places outgoing data packets into the transmit queue.\r | |
1192 | \r | |
1193 | The Transmit() function places a sending request in the transmit queue of this\r | |
1194 | EFI IPv6 Protocol instance. Whenever the packet in the token is sent out or some\r | |
1195 | errors occur, the event in the token will be signaled, and the status is updated.\r | |
1196 | \r | |
1197 | @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.\r | |
1198 | @param[in] Token Pointer to the transmit token.\r | |
1199 | \r | |
1200 | @retval EFI_SUCCESS The data has been queued for transmission.\r | |
1201 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
1202 | @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing\r | |
1203 | a source address for this transmission,\r | |
1204 | but no source address was available for use.\r | |
1205 | @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:\r | |
1206 | - This is NULL.\r | |
1207 | - Token is NULL.\r | |
1208 | - Token.Event is NULL.\r | |
1209 | - Token.Packet.TxData is NULL.\r | |
1210 | - Token.Packet.ExtHdrsLength is not zero and\r | |
1211 | Token.Packet.ExtHdrs is NULL.\r | |
1212 | - Token.Packet.FragmentCount is zero.\r | |
1213 | - One or more of the Token.Packet.TxData.\r | |
1214 | FragmentTable[].FragmentLength fields is zero.\r | |
1215 | - One or more of the Token.Packet.TxData.\r | |
1216 | FragmentTable[].FragmentBuffer fields is NULL.\r | |
1217 | - Token.Packet.TxData.DataLength is zero or not\r | |
1218 | equal to the sum of fragment lengths.\r | |
1219 | - Token.Packet.TxData.DestinationAddress is non\r | |
1220 | zero when DestinationAddress is configured as\r | |
1221 | non-zero when doing Configure() for this\r | |
1222 | EFI IPv6 protocol instance.\r | |
1223 | - Token.Packet.TxData.DestinationAddress is\r | |
1224 | unspecified when DestinationAddress is unspecified\r | |
1225 | when doing Configure() for this EFI IPv6 protocol\r | |
1226 | instance.\r | |
1227 | @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.\r | |
1228 | Event was already in the transmit queue.\r | |
1229 | @retval EFI_NOT_READY The completion token could not be queued because\r | |
1230 | the transmit queue is full.\r | |
1231 | @retval EFI_NOT_FOUND Not route is found to destination address.\r | |
1232 | @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.\r | |
1233 | @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too\r | |
1234 | short to transmit.\r | |
1235 | @retval EFI_BAD_BUFFER_SIZE If Token.Packet.TxData.DataLength is beyond the\r | |
1236 | maximum that which can be described through the\r | |
1237 | Fragment Offset field in Fragment header when\r | |
1238 | performing fragmentation.\r | |
1239 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
1240 | \r | |
1241 | **/\r | |
1242 | EFI_STATUS\r | |
1243 | EFIAPI\r | |
1244 | EfiIp6Transmit (\r | |
1245 | IN EFI_IP6_PROTOCOL *This,\r | |
1246 | IN EFI_IP6_COMPLETION_TOKEN *Token\r | |
1247 | )\r | |
1248 | {\r | |
1249 | IP6_SERVICE *IpSb;\r | |
1250 | IP6_PROTOCOL *IpInstance;\r | |
1251 | EFI_IP6_CONFIG_DATA *Config;\r | |
1252 | EFI_STATUS Status;\r | |
1253 | EFI_TPL OldTpl;\r | |
1254 | EFI_IP6_HEADER Head;\r | |
1255 | EFI_IP6_TRANSMIT_DATA *TxData;\r | |
1256 | EFI_IP6_OVERRIDE_DATA *Override;\r | |
1257 | IP6_TXTOKEN_WRAP *Wrap;\r | |
1258 | UINT8 *ExtHdrs;\r | |
1259 | \r | |
1260 | //\r | |
1261 | // Check input parameters.\r | |
1262 | //\r | |
1263 | if (This == NULL) {\r | |
1264 | return EFI_INVALID_PARAMETER;\r | |
1265 | }\r | |
1266 | \r | |
1267 | ExtHdrs = NULL;\r | |
1268 | \r | |
1269 | Status = Ip6TxTokenValid (Token);\r | |
1270 | if (EFI_ERROR (Status)) {\r | |
1271 | return Status;\r | |
1272 | }\r | |
1273 | \r | |
1274 | IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);\r | |
1275 | IpSb = IpInstance->Service;\r | |
1276 | \r | |
1277 | if (IpSb->LinkLocalDadFail) {\r | |
1278 | return EFI_DEVICE_ERROR;\r | |
1279 | }\r | |
1280 | \r | |
1281 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1282 | \r | |
1283 | if (IpInstance->State != IP6_STATE_CONFIGED) {\r | |
1284 | Status = EFI_NOT_STARTED;\r | |
1285 | goto Exit;\r | |
1286 | }\r | |
1287 | \r | |
1288 | Config = &IpInstance->ConfigData;\r | |
1289 | \r | |
1290 | //\r | |
1291 | // Check whether the token or signal already existed.\r | |
1292 | //\r | |
1293 | if (EFI_ERROR (NetMapIterate (&IpInstance->TxTokens, Ip6TokenExist, Token))) {\r | |
1294 | Status = EFI_ACCESS_DENIED;\r | |
1295 | goto Exit;\r | |
1296 | }\r | |
1297 | \r | |
1298 | //\r | |
1299 | // Build the IP header, fill in the information from ConfigData or OverrideData\r | |
1300 | //\r | |
1301 | ZeroMem (&Head, sizeof(EFI_IP6_HEADER));\r | |
1302 | TxData = Token->Packet.TxData;\r | |
1303 | IP6_COPY_ADDRESS (&Head.SourceAddress, &Config->StationAddress);\r | |
1304 | IP6_COPY_ADDRESS (&Head.DestinationAddress, &Config->DestinationAddress);\r | |
1305 | \r | |
1306 | Status = EFI_INVALID_PARAMETER;\r | |
1307 | \r | |
1308 | if (NetIp6IsUnspecifiedAddr (&TxData->DestinationAddress)) {\r | |
1309 | if (NetIp6IsUnspecifiedAddr (&Config->DestinationAddress)) {\r | |
1310 | goto Exit;\r | |
1311 | }\r | |
1312 | \r | |
1313 | ASSERT (!NetIp6IsUnspecifiedAddr (&Config->StationAddress));\r | |
1314 | \r | |
1315 | } else {\r | |
1316 | //\r | |
1317 | // StationAddress is unspecified only when ConfigData.Dest is unspecified.\r | |
1318 | // Use TxData.Dest to override the DestinationAddress.\r | |
1319 | //\r | |
1320 | if (!NetIp6IsUnspecifiedAddr (&Config->DestinationAddress)) {\r | |
1321 | goto Exit;\r | |
1322 | }\r | |
1323 | \r | |
1324 | if (NetIp6IsUnspecifiedAddr (&Config->StationAddress)) {\r | |
1325 | Status = Ip6SelectSourceAddress (\r | |
1326 | IpSb,\r | |
1327 | &TxData->DestinationAddress,\r | |
1328 | &Head.SourceAddress\r | |
1329 | );\r | |
1330 | if (EFI_ERROR (Status)) {\r | |
1331 | goto Exit;\r | |
1332 | }\r | |
1333 | }\r | |
1334 | \r | |
1335 | IP6_COPY_ADDRESS (&Head.DestinationAddress, &TxData->DestinationAddress);\r | |
1336 | }\r | |
1337 | \r | |
1338 | //\r | |
1339 | // Fill in Head infos.\r | |
1340 | //\r | |
1341 | Head.NextHeader = Config->DefaultProtocol;\r | |
1342 | if (TxData->ExtHdrsLength != 0) {\r | |
1343 | Head.NextHeader = TxData->NextHeader;\r | |
1344 | }\r | |
1345 | \r | |
1346 | if (TxData->OverrideData != NULL) {\r | |
1347 | Override = TxData->OverrideData;\r | |
1348 | Head.NextHeader = Override->Protocol;\r | |
1349 | Head.HopLimit = Override->HopLimit;\r | |
1350 | Head.FlowLabelL = HTONS ((UINT16) Override->FlowLabel);\r | |
1351 | Head.FlowLabelH = (UINT8) ((Override->FlowLabel >> 16) & 0x0F);\r | |
1352 | } else {\r | |
1353 | Head.HopLimit = Config->HopLimit;\r | |
1354 | Head.FlowLabelL = HTONS ((UINT16) Config->FlowLabel);\r | |
1355 | Head.FlowLabelH = (UINT8) ((Config->FlowLabel >> 16) & 0x0F);\r | |
1356 | }\r | |
1357 | \r | |
1358 | Head.PayloadLength = HTONS ((UINT16) (TxData->ExtHdrsLength + TxData->DataLength));\r | |
1359 | \r | |
1360 | //\r | |
1361 | // OK, it survives all the validation check. Wrap the token in\r | |
1362 | // a IP6_TXTOKEN_WRAP and the data in a netbuf\r | |
1363 | //\r | |
1364 | Status = EFI_OUT_OF_RESOURCES;\r | |
1365 | Wrap = AllocateZeroPool (sizeof (IP6_TXTOKEN_WRAP));\r | |
1366 | if (Wrap == NULL) {\r | |
1367 | goto Exit;\r | |
1368 | }\r | |
1369 | \r | |
1370 | Wrap->IpInstance = IpInstance;\r | |
1371 | Wrap->Token = Token;\r | |
1372 | Wrap->Sent = FALSE;\r | |
1373 | Wrap->Life = IP6_US_TO_SEC (Config->TransmitTimeout);\r | |
1374 | Wrap->Packet = NetbufFromExt (\r | |
1375 | (NET_FRAGMENT *) TxData->FragmentTable,\r | |
1376 | TxData->FragmentCount,\r | |
1377 | IP6_MAX_HEADLEN,\r | |
1378 | 0,\r | |
1379 | Ip6FreeTxToken,\r | |
1380 | Wrap\r | |
1381 | );\r | |
1382 | \r | |
1383 | if (Wrap->Packet == NULL) {\r | |
1384 | FreePool (Wrap);\r | |
1385 | goto Exit;\r | |
1386 | }\r | |
1387 | \r | |
1388 | Token->Status = EFI_NOT_READY;\r | |
1389 | \r | |
1390 | Status = NetMapInsertTail (&IpInstance->TxTokens, Token, Wrap);\r | |
1391 | if (EFI_ERROR (Status)) {\r | |
1392 | //\r | |
1393 | // NetbufFree will call Ip6FreeTxToken, which in turn will\r | |
1394 | // free the IP6_TXTOKEN_WRAP. Now, the token wrap hasn't been\r | |
1395 | // enqueued.\r | |
1396 | //\r | |
1397 | NetbufFree (Wrap->Packet);\r | |
1398 | goto Exit;\r | |
1399 | }\r | |
1400 | \r | |
1401 | //\r | |
1402 | // Allocate a new buffer to store IPv6 extension headers to avoid updating\r | |
1403 | // the original data in EFI_IP6_COMPLETION_TOKEN.\r | |
1404 | //\r | |
1405 | if (TxData->ExtHdrsLength != 0 && TxData->ExtHdrs != NULL) {\r | |
1406 | ExtHdrs = (UINT8 *) AllocateCopyPool (TxData->ExtHdrsLength, TxData->ExtHdrs);\r | |
1407 | if (ExtHdrs == NULL) {\r | |
1408 | Status = EFI_OUT_OF_RESOURCES;\r | |
1409 | goto Exit;\r | |
1410 | }\r | |
1411 | }\r | |
1412 | \r | |
1413 | //\r | |
1414 | // Mark the packet sent before output it. Mark it not sent again if the\r | |
1415 | // returned status is not EFI_SUCCESS;\r | |
1416 | //\r | |
1417 | Wrap->Sent = TRUE;\r | |
1418 | \r | |
1419 | Status = Ip6Output (\r | |
1420 | IpSb,\r | |
1421 | NULL,\r | |
1422 | IpInstance,\r | |
1423 | Wrap->Packet,\r | |
1424 | &Head,\r | |
1425 | ExtHdrs,\r | |
1426 | TxData->ExtHdrsLength,\r | |
1427 | Ip6OnPacketSent,\r | |
1428 | Wrap\r | |
1429 | );\r | |
1430 | if (EFI_ERROR (Status)) {\r | |
1431 | Wrap->Sent = FALSE;\r | |
1432 | NetbufFree (Wrap->Packet);\r | |
1433 | }\r | |
1434 | \r | |
1435 | Exit:\r | |
1436 | gBS->RestoreTPL (OldTpl);\r | |
1437 | \r | |
1438 | if (ExtHdrs != NULL) {\r | |
1439 | FreePool (ExtHdrs);\r | |
1440 | }\r | |
1441 | \r | |
1442 | return Status;\r | |
1443 | }\r | |
1444 | \r | |
1445 | /**\r | |
1446 | Places a receiving request into the receiving queue.\r | |
1447 | \r | |
1448 | The Receive() function places a completion token into the receive packet queue.\r | |
1449 | This function is always asynchronous.\r | |
1450 | \r | |
1451 | The Token.Event field in the completion token must be filled in by the caller\r | |
1452 | and cannot be NULL. When the receive operation completes, the EFI IPv6 Protocol\r | |
1453 | driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event\r | |
1454 | is signaled.\r | |
1455 | \r | |
1456 | Current Udp implementation creates an IP child for each Udp child.\r | |
1457 | It initates a asynchronous receive immediately no matter whether\r | |
1458 | there is no mapping or not. Therefore, disable the returning EFI_NO_MAPPING for now.\r | |
1459 | To enable it, the following check must be performed:\r | |
1460 | \r | |
1461 | if (NetIp6IsUnspecifiedAddr (&Config->StationAddress) && IP6_NO_MAPPING (IpInstance)) {\r | |
1462 | Status = EFI_NO_MAPPING;\r | |
1463 | goto Exit;\r | |
1464 | }\r | |
1465 | \r | |
1466 | @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.\r | |
1467 | @param[in] Token Pointer to a token that is associated with the receive data descriptor.\r | |
1468 | \r | |
1469 | @retval EFI_SUCCESS The receive completion token was cached.\r | |
1470 | @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.\r | |
1471 | @retval EFI_NO_MAPPING When IP6 driver responsible for binding source address to this instance,\r | |
1472 | while no source address is available for use.\r | |
1473 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
1474 | - This is NULL.\r | |
1475 | - Token is NULL.\r | |
1476 | - Token.Event is NULL.\r | |
1477 | @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system\r | |
1478 | resources (usually memory).\r | |
1479 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
1480 | The EFI IPv6 Protocol instance has been reset to startup defaults.\r | |
1481 | @retval EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already\r | |
1482 | in the receive queue.\r | |
1483 | @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.\r | |
1484 | \r | |
1485 | **/\r | |
1486 | EFI_STATUS\r | |
1487 | EFIAPI\r | |
1488 | EfiIp6Receive (\r | |
1489 | IN EFI_IP6_PROTOCOL *This,\r | |
1490 | IN EFI_IP6_COMPLETION_TOKEN *Token\r | |
1491 | )\r | |
1492 | {\r | |
1493 | IP6_PROTOCOL *IpInstance;\r | |
1494 | EFI_STATUS Status;\r | |
1495 | EFI_TPL OldTpl;\r | |
1496 | IP6_SERVICE *IpSb;\r | |
1497 | \r | |
1498 | if (This == NULL || Token == NULL || Token->Event == NULL) {\r | |
1499 | return EFI_INVALID_PARAMETER;\r | |
1500 | }\r | |
1501 | \r | |
1502 | IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);\r | |
1503 | IpSb = IpInstance->Service;\r | |
1504 | \r | |
1505 | if (IpSb->LinkLocalDadFail) {\r | |
1506 | return EFI_DEVICE_ERROR;\r | |
1507 | }\r | |
1508 | \r | |
1509 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1510 | \r | |
1511 | if (IpInstance->State != IP6_STATE_CONFIGED) {\r | |
1512 | Status = EFI_NOT_STARTED;\r | |
1513 | goto Exit;\r | |
1514 | }\r | |
1515 | \r | |
1516 | //\r | |
1517 | // Check whether the toke is already on the receive queue.\r | |
1518 | //\r | |
1519 | Status = NetMapIterate (&IpInstance->RxTokens, Ip6TokenExist, Token);\r | |
1520 | \r | |
1521 | if (EFI_ERROR (Status)) {\r | |
1522 | Status = EFI_ACCESS_DENIED;\r | |
1523 | goto Exit;\r | |
1524 | }\r | |
1525 | \r | |
1526 | //\r | |
1527 | // Queue the token then check whether there is pending received packet.\r | |
1528 | //\r | |
1529 | Status = NetMapInsertTail (&IpInstance->RxTokens, Token, NULL);\r | |
1530 | \r | |
1531 | if (EFI_ERROR (Status)) {\r | |
1532 | goto Exit;\r | |
1533 | }\r | |
1534 | \r | |
1535 | Status = Ip6InstanceDeliverPacket (IpInstance);\r | |
1536 | \r | |
1537 | //\r | |
1538 | // Dispatch the DPC queued by the NotifyFunction of this instane's receive\r | |
1539 | // event.\r | |
1540 | //\r | |
1541 | DispatchDpc ();\r | |
1542 | \r | |
1543 | Exit:\r | |
1544 | gBS->RestoreTPL (OldTpl);\r | |
1545 | return Status;\r | |
1546 | }\r | |
1547 | \r | |
1548 | \r | |
1549 | /**\r | |
1550 | Cancel the transmitted but not recycled packet. If a matching\r | |
1551 | token is found, it will call Ip6CancelPacket to cancel the\r | |
1552 | packet. Ip6CancelPacket cancels all the fragments of the\r | |
1553 | packet. When all the fragments are freed, the IP6_TXTOKEN_WRAP\r | |
1554 | is deleted from the Map, and user's event is signalled.\r | |
1555 | Because Ip6CancelPacket and other functions are all called in\r | |
1556 | line, after Ip6CancelPacket returns, the Item has been freed.\r | |
1557 | \r | |
1558 | @param[in] Map The IP6 child's transmit queue.\r | |
1559 | @param[in] Item The current transmitted packet to test.\r | |
1560 | @param[in] Context The user's token to cancel.\r | |
1561 | \r | |
1562 | @retval EFI_SUCCESS Continue to check the next Item.\r | |
1563 | @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.\r | |
1564 | \r | |
1565 | **/\r | |
1566 | EFI_STATUS\r | |
1567 | EFIAPI\r | |
1568 | Ip6CancelTxTokens (\r | |
1569 | IN NET_MAP *Map,\r | |
1570 | IN NET_MAP_ITEM *Item,\r | |
1571 | IN VOID *Context\r | |
1572 | )\r | |
1573 | {\r | |
1574 | EFI_IP6_COMPLETION_TOKEN *Token;\r | |
1575 | IP6_TXTOKEN_WRAP *Wrap;\r | |
1576 | \r | |
1577 | Token = (EFI_IP6_COMPLETION_TOKEN *) Context;\r | |
1578 | \r | |
1579 | //\r | |
1580 | // Return EFI_SUCCESS to check the next item in the map if\r | |
1581 | // this one doesn't match.\r | |
1582 | //\r | |
1583 | if ((Token != NULL) && (Token != Item->Key)) {\r | |
1584 | return EFI_SUCCESS;\r | |
1585 | }\r | |
1586 | \r | |
1587 | Wrap = (IP6_TXTOKEN_WRAP *) Item->Value;\r | |
1588 | ASSERT (Wrap != NULL);\r | |
1589 | \r | |
1590 | //\r | |
1591 | // Don't access the Item, Wrap and Token's members after this point.\r | |
1592 | // Item and wrap has been freed. And we no longer own the Token.\r | |
1593 | //\r | |
1594 | Ip6CancelPacket (Wrap->IpInstance->Interface, Wrap->Packet, EFI_ABORTED);\r | |
1595 | \r | |
1596 | //\r | |
1597 | // If only one item is to be cancel, return EFI_ABORTED to stop\r | |
1598 | // iterating the map any more.\r | |
1599 | //\r | |
1600 | if (Token != NULL) {\r | |
1601 | return EFI_ABORTED;\r | |
1602 | }\r | |
1603 | \r | |
1604 | return EFI_SUCCESS;\r | |
1605 | }\r | |
1606 | \r | |
1607 | \r | |
1608 | /**\r | |
1609 | Cancel the receive request. This is simple, because\r | |
1610 | it is only enqueued in our local receive map.\r | |
1611 | \r | |
1612 | @param[in] Map The IP6 child's receive queue.\r | |
1613 | @param[in] Item Current receive request to cancel.\r | |
1614 | @param[in] Context The user's token to cancel.\r | |
1615 | \r | |
1616 | \r | |
1617 | @retval EFI_SUCCESS Continue to check the next receive request on the\r | |
1618 | queue.\r | |
1619 | @retval EFI_ABORTED The user's token (token != NULL) has been\r | |
1620 | cancelled.\r | |
1621 | \r | |
1622 | **/\r | |
1623 | EFI_STATUS\r | |
1624 | EFIAPI\r | |
1625 | Ip6CancelRxTokens (\r | |
1626 | IN NET_MAP *Map,\r | |
1627 | IN NET_MAP_ITEM *Item,\r | |
1628 | IN VOID *Context\r | |
1629 | )\r | |
1630 | {\r | |
1631 | EFI_IP6_COMPLETION_TOKEN *Token;\r | |
1632 | EFI_IP6_COMPLETION_TOKEN *This;\r | |
1633 | \r | |
1634 | Token = (EFI_IP6_COMPLETION_TOKEN *) Context;\r | |
1635 | This = Item->Key;\r | |
1636 | \r | |
1637 | if ((Token != NULL) && (Token != This)) {\r | |
1638 | return EFI_SUCCESS;\r | |
1639 | }\r | |
1640 | \r | |
1641 | NetMapRemoveItem (Map, Item, NULL);\r | |
1642 | \r | |
1643 | This->Status = EFI_ABORTED;\r | |
1644 | This->Packet.RxData = NULL;\r | |
1645 | gBS->SignalEvent (This->Event);\r | |
1646 | \r | |
1647 | if (Token != NULL) {\r | |
1648 | return EFI_ABORTED;\r | |
1649 | }\r | |
1650 | \r | |
1651 | return EFI_SUCCESS;\r | |
1652 | }\r | |
1653 | \r | |
1654 | /**\r | |
1655 | Cancel the user's receive/transmit request. It is the worker function of\r | |
1656 | EfiIp6Cancel API.\r | |
1657 | \r | |
1658 | @param[in] IpInstance The IP6 child.\r | |
1659 | @param[in] Token The token to cancel. If NULL, all token will be\r | |
1660 | cancelled.\r | |
1661 | \r | |
1662 | @retval EFI_SUCCESS The token is cancelled.\r | |
1663 | @retval EFI_NOT_FOUND The token isn't found on either the\r | |
1664 | transmit/receive queue.\r | |
1665 | @retval EFI_DEVICE_ERROR Not all tokens are cancelled when Token is NULL.\r | |
1666 | \r | |
1667 | **/\r | |
1668 | EFI_STATUS\r | |
1669 | Ip6Cancel (\r | |
1670 | IN IP6_PROTOCOL *IpInstance,\r | |
1671 | IN EFI_IP6_COMPLETION_TOKEN *Token OPTIONAL\r | |
1672 | )\r | |
1673 | {\r | |
1674 | EFI_STATUS Status;\r | |
1675 | \r | |
1676 | //\r | |
1677 | // First check the transmitted packet. Ip6CancelTxTokens returns\r | |
1678 | // EFI_ABORTED to mean that the token has been cancelled when\r | |
1679 | // token != NULL. So, return EFI_SUCCESS for this condition.\r | |
1680 | //\r | |
1681 | Status = NetMapIterate (&IpInstance->TxTokens, Ip6CancelTxTokens, Token);\r | |
1682 | if (EFI_ERROR (Status)) {\r | |
1683 | if ((Token != NULL) && (Status == EFI_ABORTED)) {\r | |
1684 | return EFI_SUCCESS;\r | |
1685 | }\r | |
1686 | \r | |
1687 | return Status;\r | |
1688 | }\r | |
1689 | \r | |
1690 | //\r | |
1691 | // Check the receive queue. Ip6CancelRxTokens also returns EFI_ABORT\r | |
1692 | // for Token!=NULL and it is cancelled.\r | |
1693 | //\r | |
1694 | Status = NetMapIterate (&IpInstance->RxTokens, Ip6CancelRxTokens, Token);\r | |
1695 | //\r | |
1696 | // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's\r | |
1697 | // events.\r | |
1698 | //\r | |
1699 | DispatchDpc ();\r | |
1700 | if (EFI_ERROR (Status)) {\r | |
1701 | if ((Token != NULL) && (Status == EFI_ABORTED)) {\r | |
1702 | return EFI_SUCCESS;\r | |
1703 | }\r | |
1704 | \r | |
1705 | return Status;\r | |
1706 | }\r | |
1707 | \r | |
1708 | //\r | |
1709 | // OK, if the Token is found when Token != NULL, the NetMapIterate\r | |
1710 | // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.\r | |
1711 | //\r | |
1712 | if (Token != NULL) {\r | |
1713 | return EFI_NOT_FOUND;\r | |
1714 | }\r | |
1715 | \r | |
1716 | //\r | |
1717 | // If Token == NULL, cancel all the tokens. return error if not\r | |
1718 | // all of them are cancelled.\r | |
1719 | //\r | |
1720 | if (!NetMapIsEmpty (&IpInstance->TxTokens) || !NetMapIsEmpty (&IpInstance->RxTokens)) {\r | |
1721 | \r | |
1722 | return EFI_DEVICE_ERROR;\r | |
1723 | }\r | |
1724 | \r | |
1725 | return EFI_SUCCESS;\r | |
1726 | }\r | |
1727 | \r | |
1728 | /**\r | |
1729 | Abort an asynchronous transmit or receive request.\r | |
1730 | \r | |
1731 | The Cancel() function is used to abort a pending transmit or receive request.\r | |
1732 | If the token is in the transmit or receive request queues, after calling this\r | |
1733 | function, Token->Status will be set to EFI_ABORTED, and then Token->Event will\r | |
1734 | be signaled. If the token is not in one of the queues, which usually means the\r | |
1735 | asynchronous operation has completed, this function will not signal the token,\r | |
1736 | and EFI_NOT_FOUND is returned.\r | |
1737 | \r | |
1738 | @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.\r | |
1739 | @param[in] Token Pointer to a token that has been issued by\r | |
1740 | EFI_IP6_PROTOCOL.Transmit() or\r | |
1741 | EFI_IP6_PROTOCOL.Receive(). If NULL, all pending\r | |
1742 | tokens are aborted. Type EFI_IP6_COMPLETION_TOKEN is\r | |
1743 | defined in EFI_IP6_PROTOCOL.Transmit().\r | |
1744 | \r | |
1745 | @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r | |
1746 | Token->Event was signaled. When Token is NULL, all\r | |
1747 | pending requests were aborted, and their events were signaled.\r | |
1748 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
1749 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
1750 | @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was\r | |
1751 | not found in the transmit or receive queue. It has either completed\r | |
1752 | or was not issued by Transmit() and Receive().\r | |
1753 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
1754 | \r | |
1755 | **/\r | |
1756 | EFI_STATUS\r | |
1757 | EFIAPI\r | |
1758 | EfiIp6Cancel (\r | |
1759 | IN EFI_IP6_PROTOCOL *This,\r | |
1760 | IN EFI_IP6_COMPLETION_TOKEN *Token OPTIONAL\r | |
1761 | )\r | |
1762 | {\r | |
1763 | IP6_PROTOCOL *IpInstance;\r | |
1764 | IP6_SERVICE *IpSb;\r | |
1765 | EFI_STATUS Status;\r | |
1766 | EFI_TPL OldTpl;\r | |
1767 | \r | |
1768 | if (This == NULL) {\r | |
1769 | return EFI_INVALID_PARAMETER;\r | |
1770 | }\r | |
1771 | \r | |
1772 | IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);\r | |
1773 | IpSb = IpInstance->Service;\r | |
1774 | \r | |
a3bcde70 HT |
1775 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
1776 | \r | |
1777 | if (IpInstance->State != IP6_STATE_CONFIGED) {\r | |
1778 | Status = EFI_NOT_STARTED;\r | |
1779 | goto Exit;\r | |
1780 | }\r | |
1781 | \r | |
1782 | Status = Ip6Cancel (IpInstance, Token);\r | |
1783 | \r | |
1784 | Exit:\r | |
1785 | gBS->RestoreTPL (OldTpl);\r | |
1786 | return Status;\r | |
1787 | }\r | |
1788 | \r | |
1789 | /**\r | |
1790 | Polls for incoming data packets, and processes outgoing data packets.\r | |
1791 | \r | |
1792 | The Poll() function polls for incoming data packets and processes outgoing data\r | |
1793 | packets. Network drivers and applications can call the EFI_IP6_PROTOCOL.Poll()\r | |
1794 | function to increase the rate that data packets are moved between the communications\r | |
1795 | device and the transmit and receive queues.\r | |
1796 | \r | |
1797 | In some systems the periodic timer event may not poll the underlying communications\r | |
1798 | device fast enough to transmit and/or receive all data packets without missing\r | |
1799 | incoming packets or dropping outgoing packets. Drivers and applications that are\r | |
1800 | experiencing packet loss should try calling the EFI_IP6_PROTOCOL.Poll() function\r | |
1801 | more often.\r | |
1802 | \r | |
1803 | @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.\r | |
1804 | \r | |
1805 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
1806 | @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.\r | |
1807 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
1808 | @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.\r | |
1809 | @retval EFI_NOT_READY No incoming or outgoing data was processed.\r | |
1810 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.\r | |
1811 | Consider increasing the polling rate.\r | |
1812 | \r | |
1813 | **/\r | |
1814 | EFI_STATUS\r | |
1815 | EFIAPI\r | |
1816 | EfiIp6Poll (\r | |
1817 | IN EFI_IP6_PROTOCOL *This\r | |
1818 | )\r | |
1819 | {\r | |
1820 | IP6_PROTOCOL *IpInstance;\r | |
1821 | IP6_SERVICE *IpSb;\r | |
1822 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
1823 | \r | |
1824 | if (This == NULL) {\r | |
1825 | return EFI_INVALID_PARAMETER;\r | |
1826 | }\r | |
1827 | \r | |
1828 | IpInstance = IP6_INSTANCE_FROM_PROTOCOL (This);\r | |
1829 | IpSb = IpInstance->Service;\r | |
1830 | \r | |
1831 | if (IpSb->LinkLocalDadFail) {\r | |
1832 | return EFI_DEVICE_ERROR;\r | |
1833 | }\r | |
1834 | \r | |
1835 | if (IpInstance->State == IP6_STATE_UNCONFIGED) {\r | |
1836 | return EFI_NOT_STARTED;\r | |
1837 | }\r | |
1838 | \r | |
1839 | Mnp = IpInstance->Service->Mnp;\r | |
1840 | \r | |
1841 | //\r | |
1842 | // Don't lock the Poll function to enable the deliver of\r | |
1843 | // the packet polled up.\r | |
1844 | //\r | |
1845 | return Mnp->Poll (Mnp);\r | |
1846 | \r | |
1847 | }\r | |
1848 | \r |