VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/Ip6Dxe/Ip6Impl.c@ 80721

Last change on this file since 80721 was 80721, checked in by vboxsync, 5 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette