4 Copyright (c) 2005 - 2010, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Protocol/DriverBinding.h>
17 #include <Protocol/ServiceBinding.h>
18 #include <Protocol/SimpleNetwork.h>
19 #include <Protocol/ManagedNetwork.h>
20 #include <Protocol/HiiConfigRouting.h>
21 #include <Protocol/ComponentName.h>
22 #include <Protocol/ComponentName2.h>
24 #include <Guid/NicIp4ConfigNvData.h>
26 #include <Library/NetLib.h>
27 #include <Library/BaseLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiRuntimeServicesTableLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/DevicePathLib.h>
34 #include <Library/HiiLib.h>
35 #include <Library/PrintLib.h>
37 #define NIC_ITEM_CONFIG_SIZE sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE
40 // All the supported IP4 maskes in host byte order.
42 GLOBAL_REMOVE_IF_UNREFERENCED IP4_ADDR gIp4AllMasks
[IP4_MASK_NUM
] = {
81 GLOBAL_REMOVE_IF_UNREFERENCED EFI_IPv4_ADDRESS mZeroIp4Addr
= {{0, 0, 0, 0}};
84 // Any error level digitally larger than mNetDebugLevelMax
85 // will be silently discarded.
87 GLOBAL_REMOVE_IF_UNREFERENCED UINTN mNetDebugLevelMax
= NETDEBUG_LEVEL_ERROR
;
88 GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogPacketSeq
= 0xDEADBEEF;
91 // You can change mSyslogDstMac mSyslogDstIp and mSyslogSrcIp
92 // here to direct the syslog packets to the syslog deamon. The
93 // default is broadcast to both the ethernet and IP.
95 GLOBAL_REMOVE_IF_UNREFERENCED UINT8 mSyslogDstMac
[NET_ETHER_ADDR_LEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
96 GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogDstIp
= 0xffffffff;
97 GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mSyslogSrcIp
= 0;
99 GLOBAL_REMOVE_IF_UNREFERENCED CHAR8
*mMonthName
[] = {
115 // VLAN device path node template
117 GLOBAL_REMOVE_IF_UNREFERENCED VLAN_DEVICE_PATH mNetVlanDevicePathTemplate
= {
119 MESSAGING_DEVICE_PATH
,
122 (UINT8
) (sizeof (VLAN_DEVICE_PATH
)),
123 (UINT8
) ((sizeof (VLAN_DEVICE_PATH
)) >> 8)
130 Locate the handles that support SNP, then open one of them
131 to send the syslog packets. The caller isn't required to close
132 the SNP after use because the SNP is opened by HandleProtocol.
134 @return The point to SNP if one is properly openned. Otherwise NULL
137 EFI_SIMPLE_NETWORK_PROTOCOL
*
142 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
149 // Locate the handles which has SNP installed.
152 Status
= gBS
->LocateHandleBuffer (
154 &gEfiSimpleNetworkProtocolGuid
,
160 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
165 // Try to open one of the ethernet SNP protocol to send packet
169 for (Index
= 0; Index
< HandleCount
; Index
++) {
170 Status
= gBS
->HandleProtocol (
172 &gEfiSimpleNetworkProtocolGuid
,
176 if ((Status
== EFI_SUCCESS
) && (Snp
!= NULL
) &&
177 (Snp
->Mode
->IfType
== NET_IFTYPE_ETHERNET
) &&
178 (Snp
->Mode
->MaxPacketSize
>= NET_SYSLOG_PACKET_LEN
)) {
191 Transmit a syslog packet synchronously through SNP. The Packet
192 already has the ethernet header prepended. This function should
193 fill in the source MAC because it will try to locate a SNP each
194 time it is called to avoid the problem if SNP is unloaded.
195 This code snip is copied from MNP.
197 @param[in] Packet The Syslog packet
198 @param[in] Length The length of the packet
200 @retval EFI_DEVICE_ERROR Failed to locate a usable SNP protocol
201 @retval EFI_TIMEOUT Timeout happened to send the packet.
202 @retval EFI_SUCCESS Packet is sent.
211 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
214 EFI_EVENT TimeoutEvent
;
217 Snp
= SyslogLocateSnp ();
220 return EFI_DEVICE_ERROR
;
223 Ether
= (ETHER_HEAD
*) Packet
;
224 CopyMem (Ether
->SrcMac
, Snp
->Mode
->CurrentAddress
.Addr
, NET_ETHER_ADDR_LEN
);
227 // Start the timeout event.
229 Status
= gBS
->CreateEvent (
237 if (EFI_ERROR (Status
)) {
241 Status
= gBS
->SetTimer (TimeoutEvent
, TimerRelative
, NET_SYSLOG_TX_TIMEOUT
);
243 if (EFI_ERROR (Status
)) {
249 // Transmit the packet through SNP.
251 Status
= Snp
->Transmit (Snp
, 0, Length
, Packet
, NULL
, NULL
, NULL
);
253 if ((Status
!= EFI_SUCCESS
) && (Status
!= EFI_NOT_READY
)) {
254 Status
= EFI_DEVICE_ERROR
;
259 // If Status is EFI_SUCCESS, the packet is put in the transmit queue.
260 // if Status is EFI_NOT_READY, the transmit engine of the network
261 // interface is busy. Both need to sync SNP.
267 // Get the recycled transmit buffer status.
269 Snp
->GetStatus (Snp
, NULL
, (VOID
**) &TxBuf
);
271 if (!EFI_ERROR (gBS
->CheckEvent (TimeoutEvent
))) {
272 Status
= EFI_TIMEOUT
;
276 } while (TxBuf
== NULL
);
278 if ((Status
== EFI_SUCCESS
) || (Status
== EFI_TIMEOUT
)) {
283 // Status is EFI_NOT_READY. Restart the timer event and
284 // call Snp->Transmit again.
286 gBS
->SetTimer (TimeoutEvent
, TimerRelative
, NET_SYSLOG_TX_TIMEOUT
);
289 gBS
->SetTimer (TimeoutEvent
, TimerCancel
, 0);
292 gBS
->CloseEvent (TimeoutEvent
);
297 Build a syslog packet, including the Ethernet/Ip/Udp headers
300 @param[in] Level Syslog servity level
301 @param[in] Module The module that generates the log
302 @param[in] File The file that contains the current log
303 @param[in] Line The line of code in the File that contains the current log
304 @param[in] Message The log message
305 @param[in] BufLen The lenght of the Buf
306 @param[out] Buf The buffer to put the packet data
308 @return The length of the syslog packet built.
324 EFI_UDP_HEADER
*Udp4
;
330 // Fill in the Ethernet header. Leave alone the source MAC.
331 // SyslogSendPacket will fill in the address for us.
333 Ether
= (ETHER_HEAD
*) Buf
;
334 CopyMem (Ether
->DstMac
, mSyslogDstMac
, NET_ETHER_ADDR_LEN
);
335 ZeroMem (Ether
->SrcMac
, NET_ETHER_ADDR_LEN
);
337 Ether
->EtherType
= HTONS (0x0800); // IPv4 protocol
339 Buf
+= sizeof (ETHER_HEAD
);
340 BufLen
-= sizeof (ETHER_HEAD
);
343 // Fill in the IP header
345 Ip4
= (IP4_HEAD
*) Buf
;
350 Ip4
->Id
= (UINT16
) mSyslogPacketSeq
;
353 Ip4
->Protocol
= 0x11;
355 Ip4
->Src
= mSyslogSrcIp
;
356 Ip4
->Dst
= mSyslogDstIp
;
358 Buf
+= sizeof (IP4_HEAD
);
359 BufLen
-= sizeof (IP4_HEAD
);
362 // Fill in the UDP header, Udp checksum is optional. Leave it zero.
364 Udp4
= (EFI_UDP_HEADER
*) Buf
;
365 Udp4
->SrcPort
= HTONS (514);
366 Udp4
->DstPort
= HTONS (514);
370 Buf
+= sizeof (EFI_UDP_HEADER
);
371 BufLen
-= sizeof (EFI_UDP_HEADER
);
374 // Build the syslog message body with <PRI> Timestamp machine module Message
376 Pri
= ((NET_SYSLOG_FACILITY
& 31) << 3) | (Level
& 7);
377 gRT
->GetTime (&Time
, NULL
);
378 ASSERT ((Time
.Month
<= 12) && (Time
.Month
>= 1));
381 // Use %a to format the ASCII strings, %s to format UNICODE strings
384 Len
+= (UINT32
) AsciiSPrint (
387 "<%d> %a %d %d:%d:%d ",
389 mMonthName
[Time
.Month
-1],
397 Len
+= (UINT32
) AsciiSPrint (
400 "Tiano %a: %a (Line: %d File: %a)",
409 // OK, patch the IP length/checksum and UDP length fields.
411 Len
+= sizeof (EFI_UDP_HEADER
);
412 Udp4
->Length
= HTONS ((UINT16
) Len
);
414 Len
+= sizeof (IP4_HEAD
);
415 Ip4
->TotalLen
= HTONS ((UINT16
) Len
);
416 Ip4
->Checksum
= (UINT16
) (~NetblockChecksum ((UINT8
*) Ip4
, sizeof (IP4_HEAD
)));
418 return Len
+ sizeof (ETHER_HEAD
);
422 Allocate a buffer, then format the message to it. This is a
423 help function for the NET_DEBUG_XXX macros. The PrintArg of
424 these macros treats the variable length print parameters as a
425 single parameter, and pass it to the NetDebugASPrint. For
426 example, NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name))
430 NETDEBUG_LEVEL_TRACE,
434 NetDebugASPrint ("State transit to %a\n", Name)
437 @param Format The ASCII format string.
438 @param ... The variable length parameter whose format is determined
439 by the Format string.
441 @return The buffer containing the formatted message,
442 or NULL if failed to allocate memory.
455 Buf
= (CHAR8
*) AllocatePool (NET_DEBUG_MSG_LEN
);
461 VA_START (Marker
, Format
);
462 AsciiVSPrint (Buf
, NET_DEBUG_MSG_LEN
, Format
, Marker
);
469 Builds an UDP4 syslog packet and send it using SNP.
471 This function will locate a instance of SNP then send the message through it.
472 Because it isn't open the SNP BY_DRIVER, apply caution when using it.
474 @param Level The servity level of the message.
475 @param Module The Moudle that generates the log.
476 @param File The file that contains the log.
477 @param Line The exact line that contains the log.
478 @param Message The user message to log.
480 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
481 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet
482 @retval EFI_SUCCESS The log is discard because that it is more verbose
483 than the mNetDebugLevelMax. Or, it has been sent out.
500 // Check whether the message should be sent out
502 if (Message
== NULL
) {
503 return EFI_INVALID_PARAMETER
;
506 if (Level
> mNetDebugLevelMax
) {
507 Status
= EFI_SUCCESS
;
512 // Allocate a maxium of 1024 bytes, the caller should ensure
513 // that the message plus the ethernet/ip/udp header is shorter
516 Packet
= (CHAR8
*) AllocatePool (NET_SYSLOG_PACKET_LEN
);
518 if (Packet
== NULL
) {
519 Status
= EFI_OUT_OF_RESOURCES
;
524 // Build the message: Ethernet header + IP header + Udp Header + user data
526 Len
= SyslogBuildPacket (
532 NET_SYSLOG_PACKET_LEN
,
537 Status
= SyslogSendPacket (Packet
, Len
);
545 Return the length of the mask.
547 Return the length of the mask, the correct value is from 0 to 32.
548 If the mask is invalid, return the invalid length 33, which is IP4_MASK_NUM.
549 NetMask is in the host byte order.
551 @param[in] NetMask The netmask to get the length from.
553 @return The length of the netmask, IP4_MASK_NUM if the mask is invalid.
564 for (Index
= 0; Index
< IP4_MASK_NUM
; Index
++) {
565 if (NetMask
== gIp4AllMasks
[Index
]) {
576 Return the class of the IP address, such as class A, B, C.
577 Addr is in host byte order.
579 The address of class A starts with 0.
580 If the address belong to class A, return IP4_ADDR_CLASSA.
581 The address of class B starts with 10.
582 If the address belong to class B, return IP4_ADDR_CLASSB.
583 The address of class C starts with 110.
584 If the address belong to class C, return IP4_ADDR_CLASSC.
585 The address of class D starts with 1110.
586 If the address belong to class D, return IP4_ADDR_CLASSD.
587 The address of class E starts with 1111.
588 If the address belong to class E, return IP4_ADDR_CLASSE.
591 @param[in] Addr The address to get the class from.
593 @return IP address class, such as IP4_ADDR_CLASSA.
604 ByteOne
= (UINT8
) (Addr
>> 24);
606 if ((ByteOne
& 0x80) == 0) {
607 return IP4_ADDR_CLASSA
;
609 } else if ((ByteOne
& 0xC0) == 0x80) {
610 return IP4_ADDR_CLASSB
;
612 } else if ((ByteOne
& 0xE0) == 0xC0) {
613 return IP4_ADDR_CLASSC
;
615 } else if ((ByteOne
& 0xF0) == 0xE0) {
616 return IP4_ADDR_CLASSD
;
619 return IP4_ADDR_CLASSE
;
626 Check whether the IP is a valid unicast address according to
627 the netmask. If NetMask is zero, use the IP address's class to get the default mask.
629 If Ip is 0, IP is not a valid unicast address.
630 Class D address is used for multicasting and class E address is reserved for future. If Ip
631 belongs to class D or class E, IP is not a valid unicast address.
632 If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.
634 @param[in] Ip The IP to check against.
635 @param[in] NetMask The mask of the IP.
637 @return TRUE if IP is a valid unicast address on the network, otherwise FALSE.
649 Class
= NetGetIpClass (Ip
);
651 if ((Ip
== 0) || (Class
>= IP4_ADDR_CLASSD
)) {
656 NetMask
= gIp4AllMasks
[Class
<< 3];
659 if (((Ip
&~NetMask
) == ~NetMask
) || ((Ip
&~NetMask
) == 0)) {
667 Check whether the incoming IPv6 address is a valid unicast address.
669 If the address is a multicast address has binary 0xFF at the start, it is not
670 a valid unicast address. If the address is unspecified ::, it is not a valid
671 unicast address to be assigned to any node. If the address is loopback address
672 ::1, it is also not a valid unicast address to be assigned to any physical
675 @param[in] Ip6 The IPv6 address to check against.
677 @return TRUE if Ip6 is a valid unicast address on the network, otherwise FALSE.
682 NetIp6IsValidUnicast (
683 IN EFI_IPv6_ADDRESS
*Ip6
689 if (Ip6
->Addr
[0] == 0xFF) {
693 for (Index
= 0; Index
< 15; Index
++) {
694 if (Ip6
->Addr
[Index
] != 0) {
699 Byte
= Ip6
->Addr
[Index
];
701 if (Byte
== 0x0 || Byte
== 0x1) {
709 Check whether the incoming Ipv6 address is the unspecified address or not.
711 @param[in] Ip6 - Ip6 address, in network order.
713 @retval TRUE - Yes, unspecified
719 NetIp6IsUnspecifiedAddr (
720 IN EFI_IPv6_ADDRESS
*Ip6
725 for (Index
= 0; Index
< 16; Index
++) {
726 if (Ip6
->Addr
[Index
] != 0) {
735 Check whether the incoming Ipv6 address is a link-local address.
737 @param[in] Ip6 - Ip6 address, in network order.
739 @retval TRUE - Yes, link-local address
745 NetIp6IsLinkLocalAddr (
746 IN EFI_IPv6_ADDRESS
*Ip6
751 ASSERT (Ip6
!= NULL
);
753 if (Ip6
->Addr
[0] != 0xFE) {
757 if (Ip6
->Addr
[1] != 0x80) {
761 for (Index
= 2; Index
< 8; Index
++) {
762 if (Ip6
->Addr
[Index
] != 0) {
771 Check whether the Ipv6 address1 and address2 are on the connected network.
773 @param[in] Ip1 - Ip6 address1, in network order.
774 @param[in] Ip2 - Ip6 address2, in network order.
775 @param[in] PrefixLength - The prefix length of the checking net.
777 @retval TRUE - Yes, connected.
784 EFI_IPv6_ADDRESS
*Ip1
,
785 EFI_IPv6_ADDRESS
*Ip2
,
793 ASSERT ((Ip1
!= NULL
) && (Ip2
!= NULL
) && (PrefixLength
< IP6_PREFIX_NUM
));
795 if (PrefixLength
== 0) {
799 Byte
= (UINT8
) (PrefixLength
/ 8);
800 Bit
= (UINT8
) (PrefixLength
% 8);
802 if (CompareMem (Ip1
, Ip2
, Byte
) != 0) {
807 Mask
= (UINT8
) (0xFF << (8 - Bit
));
810 if ((Ip1
->Addr
[Byte
] & Mask
) != (Ip2
->Addr
[Byte
] & Mask
)) {
820 Switches the endianess of an IPv6 address
822 This function swaps the bytes in a 128-bit IPv6 address to switch the value
823 from little endian to big endian or vice versa. The byte swapped value is
826 @param Ip6 Points to an IPv6 address
828 @return The byte swapped IPv6 address.
834 EFI_IPv6_ADDRESS
*Ip6
840 CopyMem (&High
, Ip6
, sizeof (UINT64
));
841 CopyMem (&Low
, &Ip6
->Addr
[8], sizeof (UINT64
));
843 High
= SwapBytes64 (High
);
844 Low
= SwapBytes64 (Low
);
846 CopyMem (Ip6
, &Low
, sizeof (UINT64
));
847 CopyMem (&Ip6
->Addr
[8], &High
, sizeof (UINT64
));
853 Initialize a random seed using current time.
855 Get current time first. Then initialize a random seed based on some basic
856 mathematics operation on the hour, day, minute, second, nanosecond and year
859 @return The random seed initialized with current time.
871 gRT
->GetTime (&Time
, NULL
);
872 Seed
= (~Time
.Hour
<< 24 | Time
.Day
<< 16 | Time
.Minute
<< 8 | Time
.Second
);
873 Seed
^= Time
.Nanosecond
;
874 Seed
^= Time
.Year
<< 7;
881 Extract a UINT32 from a byte stream.
883 Copy a UINT32 from a byte stream, then converts it from Network
884 byte order to host byte order. Use this function to avoid alignment error.
886 @param[in] Buf The buffer to extract the UINT32.
888 @return The UINT32 extracted.
899 CopyMem (&Value
, Buf
, sizeof (UINT32
));
900 return NTOHL (Value
);
905 Put a UINT32 to the byte stream in network byte order.
907 Converts a UINT32 from host byte order to network byte order. Then copy it to the
910 @param[in, out] Buf The buffer to put the UINT32.
911 @param[in] Data The data to be converted and put into the byte stream.
922 CopyMem (Buf
, &Data
, sizeof (UINT32
));
927 Remove the first node entry on the list, and return the removed node entry.
929 Removes the first node Entry from a doubly linked list. It is up to the caller of
930 this function to release the memory used by the first node if that is required. On
931 exit, the removed node is returned.
933 If Head is NULL, then ASSERT().
934 If Head was not initialized, then ASSERT().
935 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
936 linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,
939 @param[in, out] Head The list header.
941 @return The first node entry that is removed from the list, NULL if the list is empty.
947 IN OUT LIST_ENTRY
*Head
952 ASSERT (Head
!= NULL
);
954 if (IsListEmpty (Head
)) {
958 First
= Head
->ForwardLink
;
959 Head
->ForwardLink
= First
->ForwardLink
;
960 First
->ForwardLink
->BackLink
= Head
;
963 First
->ForwardLink
= (LIST_ENTRY
*) NULL
;
964 First
->BackLink
= (LIST_ENTRY
*) NULL
;
972 Remove the last node entry on the list and and return the removed node entry.
974 Removes the last node entry from a doubly linked list. It is up to the caller of
975 this function to release the memory used by the first node if that is required. On
976 exit, the removed node is returned.
978 If Head is NULL, then ASSERT().
979 If Head was not initialized, then ASSERT().
980 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
981 linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,
984 @param[in, out] Head The list head.
986 @return The last node entry that is removed from the list, NULL if the list is empty.
992 IN OUT LIST_ENTRY
*Head
997 ASSERT (Head
!= NULL
);
999 if (IsListEmpty (Head
)) {
1003 Last
= Head
->BackLink
;
1004 Head
->BackLink
= Last
->BackLink
;
1005 Last
->BackLink
->ForwardLink
= Head
;
1008 Last
->ForwardLink
= (LIST_ENTRY
*) NULL
;
1009 Last
->BackLink
= (LIST_ENTRY
*) NULL
;
1017 Insert a new node entry after a designated node entry of a doubly linked list.
1019 Inserts a new node entry donated by NewEntry after the node entry donated by PrevEntry
1020 of the doubly linked list.
1022 @param[in, out] PrevEntry The previous entry to insert after.
1023 @param[in, out] NewEntry The new entry to insert.
1028 NetListInsertAfter (
1029 IN OUT LIST_ENTRY
*PrevEntry
,
1030 IN OUT LIST_ENTRY
*NewEntry
1033 NewEntry
->BackLink
= PrevEntry
;
1034 NewEntry
->ForwardLink
= PrevEntry
->ForwardLink
;
1035 PrevEntry
->ForwardLink
->BackLink
= NewEntry
;
1036 PrevEntry
->ForwardLink
= NewEntry
;
1041 Insert a new node entry before a designated node entry of a doubly linked list.
1043 Inserts a new node entry donated by NewEntry after the node entry donated by PostEntry
1044 of the doubly linked list.
1046 @param[in, out] PostEntry The entry to insert before.
1047 @param[in, out] NewEntry The new entry to insert.
1052 NetListInsertBefore (
1053 IN OUT LIST_ENTRY
*PostEntry
,
1054 IN OUT LIST_ENTRY
*NewEntry
1057 NewEntry
->ForwardLink
= PostEntry
;
1058 NewEntry
->BackLink
= PostEntry
->BackLink
;
1059 PostEntry
->BackLink
->ForwardLink
= NewEntry
;
1060 PostEntry
->BackLink
= NewEntry
;
1065 Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.
1067 Initialize the forward and backward links of two head nodes donated by Map->Used
1068 and Map->Recycled of two doubly linked lists.
1069 Initializes the count of the <Key, Value> pairs in the netmap to zero.
1071 If Map is NULL, then ASSERT().
1072 If the address of Map->Used is NULL, then ASSERT().
1073 If the address of Map->Recycled is NULl, then ASSERT().
1075 @param[in, out] Map The netmap to initialize.
1084 ASSERT (Map
!= NULL
);
1086 InitializeListHead (&Map
->Used
);
1087 InitializeListHead (&Map
->Recycled
);
1093 To clean up the netmap, that is, release allocated memories.
1095 Removes all nodes of the Used doubly linked list and free memory of all related netmap items.
1096 Removes all nodes of the Recycled doubly linked list and free memory of all related netmap items.
1097 The number of the <Key, Value> pairs in the netmap is set to be zero.
1099 If Map is NULL, then ASSERT().
1101 @param[in, out] Map The netmap to clean up.
1114 ASSERT (Map
!= NULL
);
1116 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Used
) {
1117 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1119 RemoveEntryList (&Item
->Link
);
1122 gBS
->FreePool (Item
);
1125 ASSERT ((Map
->Count
== 0) && IsListEmpty (&Map
->Used
));
1127 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Recycled
) {
1128 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1130 RemoveEntryList (&Item
->Link
);
1131 gBS
->FreePool (Item
);
1134 ASSERT (IsListEmpty (&Map
->Recycled
));
1139 Test whether the netmap is empty and return true if it is.
1141 If the number of the <Key, Value> pairs in the netmap is zero, return TRUE.
1143 If Map is NULL, then ASSERT().
1146 @param[in] Map The net map to test.
1148 @return TRUE if the netmap is empty, otherwise FALSE.
1157 ASSERT (Map
!= NULL
);
1158 return (BOOLEAN
) (Map
->Count
== 0);
1163 Return the number of the <Key, Value> pairs in the netmap.
1165 @param[in] Map The netmap to get the entry number.
1167 @return The entry number in the netmap.
1181 Return one allocated item.
1183 If the Recycled doubly linked list of the netmap is empty, it will try to allocate
1184 a batch of items if there are enough resources and add corresponding nodes to the begining
1185 of the Recycled doubly linked list of the netmap. Otherwise, it will directly remove
1186 the fist node entry of the Recycled doubly linked list and return the corresponding item.
1188 If Map is NULL, then ASSERT().
1190 @param[in, out] Map The netmap to allocate item for.
1192 @return The allocated item. If NULL, the
1193 allocation failed due to resource limit.
1205 ASSERT (Map
!= NULL
);
1207 Head
= &Map
->Recycled
;
1209 if (IsListEmpty (Head
)) {
1210 for (Index
= 0; Index
< NET_MAP_INCREAMENT
; Index
++) {
1211 Item
= AllocatePool (sizeof (NET_MAP_ITEM
));
1221 InsertHeadList (Head
, &Item
->Link
);
1225 Item
= NET_LIST_HEAD (Head
, NET_MAP_ITEM
, Link
);
1226 NetListRemoveHead (Head
);
1233 Allocate an item to save the <Key, Value> pair to the head of the netmap.
1235 Allocate an item to save the <Key, Value> pair and add corresponding node entry
1236 to the beginning of the Used doubly linked list. The number of the <Key, Value>
1237 pairs in the netmap increase by 1.
1239 If Map is NULL, then ASSERT().
1241 @param[in, out] Map The netmap to insert into.
1242 @param[in] Key The user's key.
1243 @param[in] Value The user's value for the key.
1245 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.
1246 @retval EFI_SUCCESS The item is inserted to the head.
1252 IN OUT NET_MAP
*Map
,
1254 IN VOID
*Value OPTIONAL
1259 ASSERT (Map
!= NULL
);
1261 Item
= NetMapAllocItem (Map
);
1264 return EFI_OUT_OF_RESOURCES
;
1268 Item
->Value
= Value
;
1269 InsertHeadList (&Map
->Used
, &Item
->Link
);
1277 Allocate an item to save the <Key, Value> pair to the tail of the netmap.
1279 Allocate an item to save the <Key, Value> pair and add corresponding node entry
1280 to the tail of the Used doubly linked list. The number of the <Key, Value>
1281 pairs in the netmap increase by 1.
1283 If Map is NULL, then ASSERT().
1285 @param[in, out] Map The netmap to insert into.
1286 @param[in] Key The user's key.
1287 @param[in] Value The user's value for the key.
1289 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.
1290 @retval EFI_SUCCESS The item is inserted to the tail.
1296 IN OUT NET_MAP
*Map
,
1298 IN VOID
*Value OPTIONAL
1303 ASSERT (Map
!= NULL
);
1305 Item
= NetMapAllocItem (Map
);
1308 return EFI_OUT_OF_RESOURCES
;
1312 Item
->Value
= Value
;
1313 InsertTailList (&Map
->Used
, &Item
->Link
);
1322 Check whether the item is in the Map and return TRUE if it is.
1324 @param[in] Map The netmap to search within.
1325 @param[in] Item The item to search.
1327 @return TRUE if the item is in the netmap, otherwise FALSE.
1333 IN NET_MAP_ITEM
*Item
1336 LIST_ENTRY
*ListEntry
;
1338 NET_LIST_FOR_EACH (ListEntry
, &Map
->Used
) {
1339 if (ListEntry
== &Item
->Link
) {
1349 Find the key in the netmap and returns the point to the item contains the Key.
1351 Iterate the Used doubly linked list of the netmap to get every item. Compare the key of every
1352 item with the key to search. It returns the point to the item contains the Key if found.
1354 If Map is NULL, then ASSERT().
1356 @param[in] Map The netmap to search within.
1357 @param[in] Key The key to search.
1359 @return The point to the item contains the Key, or NULL if Key isn't in the map.
1372 ASSERT (Map
!= NULL
);
1374 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
1375 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1377 if (Item
->Key
== Key
) {
1387 Remove the node entry of the item from the netmap and return the key of the removed item.
1389 Remove the node entry of the item from the Used doubly linked list of the netmap.
1390 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node
1391 entry of the item to the Recycled doubly linked list of the netmap. If Value is not NULL,
1392 Value will point to the value of the item. It returns the key of the removed item.
1394 If Map is NULL, then ASSERT().
1395 If Item is NULL, then ASSERT().
1396 if item in not in the netmap, then ASSERT().
1398 @param[in, out] Map The netmap to remove the item from.
1399 @param[in, out] Item The item to remove.
1400 @param[out] Value The variable to receive the value if not NULL.
1402 @return The key of the removed item.
1408 IN OUT NET_MAP
*Map
,
1409 IN OUT NET_MAP_ITEM
*Item
,
1410 OUT VOID
**Value OPTIONAL
1413 ASSERT ((Map
!= NULL
) && (Item
!= NULL
));
1414 ASSERT (NetItemInMap (Map
, Item
));
1416 RemoveEntryList (&Item
->Link
);
1418 InsertHeadList (&Map
->Recycled
, &Item
->Link
);
1420 if (Value
!= NULL
) {
1421 *Value
= Item
->Value
;
1429 Remove the first node entry on the netmap and return the key of the removed item.
1431 Remove the first node entry from the Used doubly linked list of the netmap.
1432 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node
1433 entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,
1434 parameter Value will point to the value of the item. It returns the key of the removed item.
1436 If Map is NULL, then ASSERT().
1437 If the Used doubly linked list is empty, then ASSERT().
1439 @param[in, out] Map The netmap to remove the head from.
1440 @param[out] Value The variable to receive the value if not NULL.
1442 @return The key of the item removed.
1448 IN OUT NET_MAP
*Map
,
1449 OUT VOID
**Value OPTIONAL
1455 // Often, it indicates a programming error to remove
1456 // the first entry in an empty list
1458 ASSERT (Map
&& !IsListEmpty (&Map
->Used
));
1460 Item
= NET_LIST_HEAD (&Map
->Used
, NET_MAP_ITEM
, Link
);
1461 RemoveEntryList (&Item
->Link
);
1463 InsertHeadList (&Map
->Recycled
, &Item
->Link
);
1465 if (Value
!= NULL
) {
1466 *Value
= Item
->Value
;
1474 Remove the last node entry on the netmap and return the key of the removed item.
1476 Remove the last node entry from the Used doubly linked list of the netmap.
1477 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node
1478 entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,
1479 parameter Value will point to the value of the item. It returns the key of the removed item.
1481 If Map is NULL, then ASSERT().
1482 If the Used doubly linked list is empty, then ASSERT().
1484 @param[in, out] Map The netmap to remove the tail from.
1485 @param[out] Value The variable to receive the value if not NULL.
1487 @return The key of the item removed.
1493 IN OUT NET_MAP
*Map
,
1494 OUT VOID
**Value OPTIONAL
1500 // Often, it indicates a programming error to remove
1501 // the last entry in an empty list
1503 ASSERT (Map
&& !IsListEmpty (&Map
->Used
));
1505 Item
= NET_LIST_TAIL (&Map
->Used
, NET_MAP_ITEM
, Link
);
1506 RemoveEntryList (&Item
->Link
);
1508 InsertHeadList (&Map
->Recycled
, &Item
->Link
);
1510 if (Value
!= NULL
) {
1511 *Value
= Item
->Value
;
1519 Iterate through the netmap and call CallBack for each item.
1521 It will contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break
1522 from the loop. It returns the CallBack's last return value. This function is
1523 delete safe for the current item.
1525 If Map is NULL, then ASSERT().
1526 If CallBack is NULL, then ASSERT().
1528 @param[in] Map The Map to iterate through.
1529 @param[in] CallBack The callback function to call for each item.
1530 @param[in] Arg The opaque parameter to the callback.
1532 @retval EFI_SUCCESS There is no item in the netmap or CallBack for each item
1534 @retval Others It returns the CallBack's last return value.
1541 IN NET_MAP_CALLBACK CallBack
,
1542 IN VOID
*Arg OPTIONAL
1552 ASSERT ((Map
!= NULL
) && (CallBack
!= NULL
));
1556 if (IsListEmpty (Head
)) {
1560 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, Head
) {
1561 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1562 Result
= CallBack (Map
, Item
, Arg
);
1564 if (EFI_ERROR (Result
)) {
1574 This is the default unload handle for all the network drivers.
1576 Disconnect the driver specified by ImageHandle from all the devices in the handle database.
1577 Uninstall all the protocols installed in the driver entry point.
1579 @param[in] ImageHandle The drivers' driver image.
1581 @retval EFI_SUCCESS The image is unloaded.
1582 @retval Others Failed to unload the image.
1587 NetLibDefaultUnload (
1588 IN EFI_HANDLE ImageHandle
1592 EFI_HANDLE
*DeviceHandleBuffer
;
1593 UINTN DeviceHandleCount
;
1595 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
1596 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1597 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
1600 // Get the list of all the handles in the handle database.
1601 // If there is an error getting the list, then the unload
1604 Status
= gBS
->LocateHandleBuffer (
1612 if (EFI_ERROR (Status
)) {
1617 // Disconnect the driver specified by ImageHandle from all
1618 // the devices in the handle database.
1620 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1621 Status
= gBS
->DisconnectController (
1622 DeviceHandleBuffer
[Index
],
1629 // Uninstall all the protocols installed in the driver entry point
1631 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1632 Status
= gBS
->HandleProtocol (
1633 DeviceHandleBuffer
[Index
],
1634 &gEfiDriverBindingProtocolGuid
,
1635 (VOID
**) &DriverBinding
1638 if (EFI_ERROR (Status
)) {
1642 if (DriverBinding
->ImageHandle
!= ImageHandle
) {
1646 gBS
->UninstallProtocolInterface (
1648 &gEfiDriverBindingProtocolGuid
,
1651 Status
= gBS
->HandleProtocol (
1652 DeviceHandleBuffer
[Index
],
1653 &gEfiComponentNameProtocolGuid
,
1654 (VOID
**) &ComponentName
1656 if (!EFI_ERROR (Status
)) {
1657 gBS
->UninstallProtocolInterface (
1659 &gEfiComponentNameProtocolGuid
,
1664 Status
= gBS
->HandleProtocol (
1665 DeviceHandleBuffer
[Index
],
1666 &gEfiComponentName2ProtocolGuid
,
1667 (VOID
**) &ComponentName2
1669 if (!EFI_ERROR (Status
)) {
1670 gBS
->UninstallProtocolInterface (
1672 &gEfiComponentName2ProtocolGuid
,
1679 // Free the buffer containing the list of handles from the handle database
1681 if (DeviceHandleBuffer
!= NULL
) {
1682 gBS
->FreePool (DeviceHandleBuffer
);
1691 Create a child of the service that is identified by ServiceBindingGuid.
1693 Get the ServiceBinding Protocol first, then use it to create a child.
1695 If ServiceBindingGuid is NULL, then ASSERT().
1696 If ChildHandle is NULL, then ASSERT().
1698 @param[in] Controller The controller which has the service installed.
1699 @param[in] Image The image handle used to open service.
1700 @param[in] ServiceBindingGuid The service's Guid.
1701 @param[in, out] ChildHandle The handle to receive the create child.
1703 @retval EFI_SUCCESS The child is successfully created.
1704 @retval Others Failed to create the child.
1709 NetLibCreateServiceChild (
1710 IN EFI_HANDLE Controller
,
1711 IN EFI_HANDLE Image
,
1712 IN EFI_GUID
*ServiceBindingGuid
,
1713 IN OUT EFI_HANDLE
*ChildHandle
1717 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
1720 ASSERT ((ServiceBindingGuid
!= NULL
) && (ChildHandle
!= NULL
));
1723 // Get the ServiceBinding Protocol
1725 Status
= gBS
->OpenProtocol (
1731 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1734 if (EFI_ERROR (Status
)) {
1741 Status
= Service
->CreateChild (Service
, ChildHandle
);
1747 Destory a child of the service that is identified by ServiceBindingGuid.
1749 Get the ServiceBinding Protocol first, then use it to destroy a child.
1751 If ServiceBindingGuid is NULL, then ASSERT().
1753 @param[in] Controller The controller which has the service installed.
1754 @param[in] Image The image handle used to open service.
1755 @param[in] ServiceBindingGuid The service's Guid.
1756 @param[in] ChildHandle The child to destory.
1758 @retval EFI_SUCCESS The child is successfully destoried.
1759 @retval Others Failed to destory the child.
1764 NetLibDestroyServiceChild (
1765 IN EFI_HANDLE Controller
,
1766 IN EFI_HANDLE Image
,
1767 IN EFI_GUID
*ServiceBindingGuid
,
1768 IN EFI_HANDLE ChildHandle
1772 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
1774 ASSERT (ServiceBindingGuid
!= NULL
);
1777 // Get the ServiceBinding Protocol
1779 Status
= gBS
->OpenProtocol (
1785 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1788 if (EFI_ERROR (Status
)) {
1793 // destory the child
1795 Status
= Service
->DestroyChild (Service
, ChildHandle
);
1800 Get handle with Simple Network Protocol installed on it.
1802 There should be MNP Service Binding Protocol installed on the input ServiceHandle.
1803 If Simple Network Protocol is already installed on the ServiceHandle, the
1804 ServiceHandle will be returned. If SNP is not installed on the ServiceHandle,
1805 try to find its parent handle with SNP installed.
1807 @param[in] ServiceHandle The handle where network service binding protocols are
1809 @param[out] Snp The pointer to store the address of the SNP instance.
1810 This is an optional parameter that may be NULL.
1812 @return The SNP handle, or NULL if not found.
1817 NetLibGetSnpHandle (
1818 IN EFI_HANDLE ServiceHandle
,
1819 OUT EFI_SIMPLE_NETWORK_PROTOCOL
**Snp OPTIONAL
1823 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpInstance
;
1824 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1825 EFI_HANDLE SnpHandle
;
1828 // Try to open SNP from ServiceHandle
1831 Status
= gBS
->HandleProtocol (ServiceHandle
, &gEfiSimpleNetworkProtocolGuid
, (VOID
**) &SnpInstance
);
1832 if (!EFI_ERROR (Status
)) {
1836 return ServiceHandle
;
1840 // Failed to open SNP, try to get SNP handle by LocateDevicePath()
1842 DevicePath
= DevicePathFromHandle (ServiceHandle
);
1843 if (DevicePath
== NULL
) {
1848 Status
= gBS
->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid
, &DevicePath
, &SnpHandle
);
1849 if (EFI_ERROR (Status
)) {
1851 // Failed to find SNP handle
1856 Status
= gBS
->HandleProtocol (SnpHandle
, &gEfiSimpleNetworkProtocolGuid
, (VOID
**) &SnpInstance
);
1857 if (!EFI_ERROR (Status
)) {
1868 Retrieve VLAN ID of a VLAN device handle.
1870 Search VLAN device path node in Device Path of specified ServiceHandle and
1871 return its VLAN ID. If no VLAN device path node found, then this ServiceHandle
1872 is not a VLAN device handle, and 0 will be returned.
1874 @param[in] ServiceHandle The handle where network service binding protocols are
1877 @return VLAN ID of the device handle, or 0 if not a VLAN device.
1883 IN EFI_HANDLE ServiceHandle
1886 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1887 EFI_DEVICE_PATH_PROTOCOL
*Node
;
1889 DevicePath
= DevicePathFromHandle (ServiceHandle
);
1890 if (DevicePath
== NULL
) {
1895 while (!IsDevicePathEnd (Node
)) {
1896 if (Node
->Type
== MESSAGING_DEVICE_PATH
&& Node
->SubType
== MSG_VLAN_DP
) {
1897 return ((VLAN_DEVICE_PATH
*) Node
)->VlanId
;
1899 Node
= NextDevicePathNode (Node
);
1906 Find VLAN device handle with specified VLAN ID.
1908 The VLAN child device handle is created by VLAN Config Protocol on ControllerHandle.
1909 This function will append VLAN device path node to the parent device path,
1910 and then use LocateDevicePath() to find the correct VLAN device handle.
1912 @param[in] ControllerHandle The handle where network service binding protocols are
1914 @param[in] VlanId The configured VLAN ID for the VLAN device.
1916 @return The VLAN device handle, or NULL if not found.
1921 NetLibGetVlanHandle (
1922 IN EFI_HANDLE ControllerHandle
,
1926 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
1927 EFI_DEVICE_PATH_PROTOCOL
*VlanDevicePath
;
1928 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1929 VLAN_DEVICE_PATH VlanNode
;
1932 ParentDevicePath
= DevicePathFromHandle (ControllerHandle
);
1933 if (ParentDevicePath
== NULL
) {
1938 // Construct VLAN device path
1940 CopyMem (&VlanNode
, &mNetVlanDevicePathTemplate
, sizeof (VLAN_DEVICE_PATH
));
1941 VlanNode
.VlanId
= VlanId
;
1942 VlanDevicePath
= AppendDevicePathNode (
1944 (EFI_DEVICE_PATH_PROTOCOL
*) &VlanNode
1946 if (VlanDevicePath
== NULL
) {
1951 // Find VLAN device handle
1954 DevicePath
= VlanDevicePath
;
1955 gBS
->LocateDevicePath (
1956 &gEfiDevicePathProtocolGuid
,
1960 if (!IsDevicePathEnd (DevicePath
)) {
1962 // Device path is not exactly match
1967 FreePool (VlanDevicePath
);
1972 Get MAC address associated with the network service handle.
1974 There should be MNP Service Binding Protocol installed on the input ServiceHandle.
1975 If SNP is installed on the ServiceHandle or its parent handle, MAC address will
1976 be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP.
1978 @param[in] ServiceHandle The handle where network service binding protocols are
1980 @param[out] MacAddress The pointer to store the returned MAC address.
1981 @param[out] AddressSize The length of returned MAC address.
1983 @retval EFI_SUCCESS MAC address is returned successfully.
1984 @retval Others Failed to get SNP mode data.
1989 NetLibGetMacAddress (
1990 IN EFI_HANDLE ServiceHandle
,
1991 OUT EFI_MAC_ADDRESS
*MacAddress
,
1992 OUT UINTN
*AddressSize
1996 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
1997 EFI_SIMPLE_NETWORK_MODE
*SnpMode
;
1998 EFI_SIMPLE_NETWORK_MODE SnpModeData
;
1999 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2000 EFI_SERVICE_BINDING_PROTOCOL
*MnpSb
;
2001 EFI_HANDLE
*SnpHandle
;
2002 EFI_HANDLE MnpChildHandle
;
2004 ASSERT (MacAddress
!= NULL
);
2005 ASSERT (AddressSize
!= NULL
);
2008 // Try to get SNP handle
2011 SnpHandle
= NetLibGetSnpHandle (ServiceHandle
, &Snp
);
2012 if (SnpHandle
!= NULL
) {
2014 // SNP found, use it directly
2016 SnpMode
= Snp
->Mode
;
2019 // Failed to get SNP handle, try to get MAC address from MNP
2021 MnpChildHandle
= NULL
;
2022 Status
= gBS
->HandleProtocol (
2024 &gEfiManagedNetworkServiceBindingProtocolGuid
,
2027 if (EFI_ERROR (Status
)) {
2032 // Create a MNP child
2034 Status
= MnpSb
->CreateChild (MnpSb
, &MnpChildHandle
);
2035 if (EFI_ERROR (Status
)) {
2040 // Open MNP protocol
2042 Status
= gBS
->HandleProtocol (
2044 &gEfiManagedNetworkProtocolGuid
,
2047 if (EFI_ERROR (Status
)) {
2052 // Try to get SNP mode from MNP
2054 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpModeData
);
2055 if (EFI_ERROR (Status
)) {
2058 SnpMode
= &SnpModeData
;
2061 // Destroy the MNP child
2063 MnpSb
->DestroyChild (MnpSb
, MnpChildHandle
);
2066 *AddressSize
= SnpMode
->HwAddressSize
;
2067 CopyMem (MacAddress
->Addr
, SnpMode
->CurrentAddress
.Addr
, SnpMode
->HwAddressSize
);
2073 Convert MAC address of the NIC associated with specified Service Binding Handle
2074 to a unicode string. Callers are responsible for freeing the string storage.
2076 Locate simple network protocol associated with the Service Binding Handle and
2077 get the mac address from SNP. Then convert the mac address into a unicode
2078 string. It takes 2 unicode characters to represent a 1 byte binary buffer.
2079 Plus one unicode character for the null-terminator.
2081 @param[in] ServiceHandle The handle where network service binding protocol is
2083 @param[in] ImageHandle The image handle used to act as the agent handle to
2084 get the simple network protocol.
2085 @param[out] MacString The pointer to store the address of the string
2086 representation of the mac address.
2088 @retval EFI_SUCCESS Convert the mac address a unicode string successfully.
2089 @retval EFI_OUT_OF_RESOURCES There are not enough memory resource.
2090 @retval Others Failed to open the simple network protocol.
2095 NetLibGetMacString (
2096 IN EFI_HANDLE ServiceHandle
,
2097 IN EFI_HANDLE ImageHandle
,
2098 OUT CHAR16
**MacString
2102 EFI_MAC_ADDRESS MacAddress
;
2104 UINTN HwAddressSize
;
2109 ASSERT (MacString
!= NULL
);
2112 // Get MAC address of the network device
2114 Status
= NetLibGetMacAddress (ServiceHandle
, &MacAddress
, &HwAddressSize
);
2115 if (EFI_ERROR (Status
)) {
2120 // It takes 2 unicode characters to represent a 1 byte binary buffer.
2121 // If VLAN is configured, it will need extra 5 characters like "\0005".
2122 // Plus one unicode character for the null-terminator.
2124 String
= AllocateZeroPool ((2 * HwAddressSize
+ 5 + 1) * sizeof (CHAR16
));
2125 if (String
== NULL
) {
2126 return EFI_OUT_OF_RESOURCES
;
2128 *MacString
= String
;
2131 // Convert the MAC address into a unicode string.
2133 HwAddress
= &MacAddress
.Addr
[0];
2134 for (Index
= 0; Index
< HwAddressSize
; Index
++) {
2135 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(HwAddress
++), 2);
2139 // Append VLAN ID if any
2141 VlanId
= NetLibGetVlanId (ServiceHandle
);
2144 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, VlanId
, 4);
2148 // Null terminate the Unicode string
2156 Detect media status for specified network device.
2158 The underlying UNDI driver may or may not support reporting media status from
2159 GET_STATUS command (PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED). This routine
2160 will try to invoke Snp->GetStatus() to get the media status: if media already
2161 present, it return directly; if media not present, it will stop SNP and then
2162 restart SNP to get the latest media status, this give chance to get the correct
2163 media status for old UNDI driver which doesn't support reporting media status
2164 from GET_STATUS command.
2165 Note: there will be two limitations for current algorithm:
2166 1) for UNDI with this capability, in case of cable is not attached, there will
2167 be an redundant Stop/Start() process;
2168 2) for UNDI without this capability, in case that network cable is attached when
2169 Snp->Initialize() is invoked while network cable is unattached later,
2170 NetLibDetectMedia() will report MediaPresent as TRUE, causing upper layer
2171 apps to wait for timeout time.
2173 @param[in] ServiceHandle The handle where network service binding protocols are
2175 @param[out] MediaPresent The pointer to store the media status.
2177 @retval EFI_SUCCESS Media detection success.
2178 @retval EFI_INVALID_PARAMETER ServiceHandle is not valid network device handle.
2179 @retval EFI_UNSUPPORTED Network device does not support media detection.
2180 @retval EFI_DEVICE_ERROR SNP is in unknown state.
2186 IN EFI_HANDLE ServiceHandle
,
2187 OUT BOOLEAN
*MediaPresent
2191 EFI_HANDLE SnpHandle
;
2192 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
2193 UINT32 InterruptStatus
;
2195 EFI_MAC_ADDRESS
*MCastFilter
;
2196 UINT32 MCastFilterCount
;
2197 UINT32 EnableFilterBits
;
2198 UINT32 DisableFilterBits
;
2199 BOOLEAN ResetMCastFilters
;
2201 ASSERT (MediaPresent
!= NULL
);
2207 SnpHandle
= NetLibGetSnpHandle (ServiceHandle
, &Snp
);
2208 if (SnpHandle
== NULL
) {
2209 return EFI_INVALID_PARAMETER
;
2213 // Check whether SNP support media detection
2215 if (!Snp
->Mode
->MediaPresentSupported
) {
2216 return EFI_UNSUPPORTED
;
2220 // Invoke Snp->GetStatus() to refresh MediaPresent field in SNP mode data
2222 Status
= Snp
->GetStatus (Snp
, &InterruptStatus
, NULL
);
2223 if (EFI_ERROR (Status
)) {
2227 if (Snp
->Mode
->MediaPresent
) {
2229 // Media is present, return directly
2231 *MediaPresent
= TRUE
;
2236 // Till now, GetStatus() report no media; while, in case UNDI not support
2237 // reporting media status from GetStatus(), this media status may be incorrect.
2238 // So, we will stop SNP and then restart it to get the correct media status.
2240 OldState
= Snp
->Mode
->State
;
2241 if (OldState
>= EfiSimpleNetworkMaxState
) {
2242 return EFI_DEVICE_ERROR
;
2247 if (OldState
== EfiSimpleNetworkInitialized
) {
2249 // SNP is already in use, need Shutdown/Stop and then Start/Initialize
2253 // Backup current SNP receive filter settings
2255 EnableFilterBits
= Snp
->Mode
->ReceiveFilterSetting
;
2256 DisableFilterBits
= Snp
->Mode
->ReceiveFilterMask
^ EnableFilterBits
;
2258 ResetMCastFilters
= TRUE
;
2259 MCastFilterCount
= Snp
->Mode
->MCastFilterCount
;
2260 if (MCastFilterCount
!= 0) {
2261 MCastFilter
= AllocateCopyPool (
2262 MCastFilterCount
* sizeof (EFI_MAC_ADDRESS
),
2263 Snp
->Mode
->MCastFilter
2265 ASSERT (MCastFilter
!= NULL
);
2267 ResetMCastFilters
= FALSE
;
2271 // Shutdown/Stop the simple network
2273 Status
= Snp
->Shutdown (Snp
);
2274 if (!EFI_ERROR (Status
)) {
2275 Status
= Snp
->Stop (Snp
);
2277 if (EFI_ERROR (Status
)) {
2282 // Start/Initialize the simple network
2284 Status
= Snp
->Start (Snp
);
2285 if (!EFI_ERROR (Status
)) {
2286 Status
= Snp
->Initialize (Snp
, 0, 0);
2288 if (EFI_ERROR (Status
)) {
2293 // Here we get the correct media status
2295 *MediaPresent
= Snp
->Mode
->MediaPresent
;
2298 // Restore SNP receive filter settings
2300 Status
= Snp
->ReceiveFilters (
2309 if (MCastFilter
!= NULL
) {
2310 FreePool (MCastFilter
);
2317 // SNP is not in use, it's in state of EfiSimpleNetworkStopped or EfiSimpleNetworkStarted
2319 if (OldState
== EfiSimpleNetworkStopped
) {
2321 // SNP not start yet, start it
2323 Status
= Snp
->Start (Snp
);
2324 if (EFI_ERROR (Status
)) {
2330 // Initialize the simple network
2332 Status
= Snp
->Initialize (Snp
, 0, 0);
2333 if (EFI_ERROR (Status
)) {
2334 Status
= EFI_DEVICE_ERROR
;
2339 // Here we get the correct media status
2341 *MediaPresent
= Snp
->Mode
->MediaPresent
;
2344 // Shut down the simple network
2346 Snp
->Shutdown (Snp
);
2349 if (OldState
== EfiSimpleNetworkStopped
) {
2351 // Original SNP sate is Stopped, restore to original state
2356 if (MCastFilter
!= NULL
) {
2357 FreePool (MCastFilter
);
2364 Check the default address used by the IPv4 driver is static or dynamic (acquired
2367 If the controller handle does not have the NIC Ip4 Config Protocol installed, the
2368 default address is static. If the EFI variable to save the configuration is not found,
2369 the default address is static. Otherwise, get the result from the EFI variable which
2370 saving the configuration.
2372 @param[in] Controller The controller handle which has the NIC Ip4 Config Protocol
2373 relative with the default address to judge.
2375 @retval TRUE If the default address is static.
2376 @retval FALSE If the default address is acquired from DHCP.
2380 NetLibDefaultAddressIsStatic (
2381 IN EFI_HANDLE Controller
2385 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
2387 NIC_IP4_CONFIG_INFO
*ConfigInfo
;
2389 EFI_STRING ConfigHdr
;
2390 EFI_STRING ConfigResp
;
2391 EFI_STRING AccessProgress
;
2392 EFI_STRING AccessResults
;
2398 AccessProgress
= NULL
;
2399 AccessResults
= NULL
;
2402 Status
= gBS
->LocateProtocol (
2403 &gEfiHiiConfigRoutingProtocolGuid
,
2405 (VOID
**) &HiiConfigRouting
2407 if (EFI_ERROR (Status
)) {
2412 // Construct config request string header
2414 ConfigHdr
= HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, Controller
);
2415 if (ConfigHdr
== NULL
) {
2419 Len
= StrLen (ConfigHdr
);
2420 ConfigResp
= AllocateZeroPool ((Len
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
));
2421 if (ConfigResp
== NULL
) {
2424 StrCpy (ConfigResp
, ConfigHdr
);
2426 String
= ConfigResp
+ Len
;
2429 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
2430 L
"&OFFSET=%04X&WIDTH=%04X",
2431 OFFSET_OF (NIC_IP4_CONFIG_INFO
, Source
),
2435 Status
= HiiConfigRouting
->ExtractConfig (
2441 if (EFI_ERROR (Status
)) {
2445 ConfigInfo
= AllocateZeroPool (sizeof (NIC_ITEM_CONFIG_SIZE
));
2446 if (ConfigInfo
== NULL
) {
2450 ConfigInfo
->Source
= IP4_CONFIG_SOURCE_STATIC
;
2451 Len
= NIC_ITEM_CONFIG_SIZE
;
2452 Status
= HiiConfigRouting
->ConfigToBlock (
2455 (UINT8
*) ConfigInfo
,
2459 if (EFI_ERROR (Status
)) {
2463 IsStatic
= (BOOLEAN
) (ConfigInfo
->Source
== IP4_CONFIG_SOURCE_STATIC
);
2467 if (AccessResults
!= NULL
) {
2468 FreePool (AccessResults
);
2470 if (ConfigInfo
!= NULL
) {
2471 FreePool (ConfigInfo
);
2473 if (ConfigResp
!= NULL
) {
2474 FreePool (ConfigResp
);
2476 if (ConfigHdr
!= NULL
) {
2477 FreePool (ConfigHdr
);
2484 Create an IPv4 device path node.
2486 The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.
2487 The header subtype of IPv4 device path node is MSG_IPv4_DP.
2488 The length of the IPv4 device path node in bytes is 19.
2489 Get other info from parameters to make up the whole IPv4 device path node.
2491 @param[in, out] Node Pointer to the IPv4 device path node.
2492 @param[in] Controller The controller handle.
2493 @param[in] LocalIp The local IPv4 address.
2494 @param[in] LocalPort The local port.
2495 @param[in] RemoteIp The remote IPv4 address.
2496 @param[in] RemotePort The remote port.
2497 @param[in] Protocol The protocol type in the IP header.
2498 @param[in] UseDefaultAddress Whether this instance is using default address or not.
2503 NetLibCreateIPv4DPathNode (
2504 IN OUT IPv4_DEVICE_PATH
*Node
,
2505 IN EFI_HANDLE Controller
,
2506 IN IP4_ADDR LocalIp
,
2507 IN UINT16 LocalPort
,
2508 IN IP4_ADDR RemoteIp
,
2509 IN UINT16 RemotePort
,
2511 IN BOOLEAN UseDefaultAddress
2514 Node
->Header
.Type
= MESSAGING_DEVICE_PATH
;
2515 Node
->Header
.SubType
= MSG_IPv4_DP
;
2516 SetDevicePathNodeLength (&Node
->Header
, 19);
2518 CopyMem (&Node
->LocalIpAddress
, &LocalIp
, sizeof (EFI_IPv4_ADDRESS
));
2519 CopyMem (&Node
->RemoteIpAddress
, &RemoteIp
, sizeof (EFI_IPv4_ADDRESS
));
2521 Node
->LocalPort
= LocalPort
;
2522 Node
->RemotePort
= RemotePort
;
2524 Node
->Protocol
= Protocol
;
2526 if (!UseDefaultAddress
) {
2527 Node
->StaticIpAddress
= TRUE
;
2529 Node
->StaticIpAddress
= NetLibDefaultAddressIsStatic (Controller
);
2534 Create an IPv6 device path node.
2536 The header type of IPv6 device path node is MESSAGING_DEVICE_PATH.
2537 The header subtype of IPv6 device path node is MSG_IPv6_DP.
2538 Get other info from parameters to make up the whole IPv6 device path node.
2540 @param[in, out] Node Pointer to the IPv6 device path node.
2541 @param[in] Controller The controller handle.
2542 @param[in] LocalIp The local IPv6 address.
2543 @param[in] LocalPort The local port.
2544 @param[in] RemoteIp The remote IPv6 address.
2545 @param[in] RemotePort The remote port.
2546 @param[in] Protocol The protocol type in the IP header.
2551 NetLibCreateIPv6DPathNode (
2552 IN OUT IPv6_DEVICE_PATH
*Node
,
2553 IN EFI_HANDLE Controller
,
2554 IN EFI_IPv6_ADDRESS
*LocalIp
,
2555 IN UINT16 LocalPort
,
2556 IN EFI_IPv6_ADDRESS
*RemoteIp
,
2557 IN UINT16 RemotePort
,
2561 Node
->Header
.Type
= MESSAGING_DEVICE_PATH
;
2562 Node
->Header
.SubType
= MSG_IPv6_DP
;
2563 SetDevicePathNodeLength (&Node
->Header
, sizeof (IPv6_DEVICE_PATH
));
2565 CopyMem (&Node
->LocalIpAddress
, LocalIp
, sizeof (EFI_IPv6_ADDRESS
));
2566 CopyMem (&Node
->RemoteIpAddress
, RemoteIp
, sizeof (EFI_IPv6_ADDRESS
));
2568 Node
->LocalPort
= LocalPort
;
2569 Node
->RemotePort
= RemotePort
;
2571 Node
->Protocol
= Protocol
;
2572 Node
->StaticIpAddress
= FALSE
;
2576 Find the UNDI/SNP handle from controller and protocol GUID.
2578 For example, IP will open a MNP child to transmit/receive
2579 packets, when MNP is stopped, IP should also be stopped. IP
2580 needs to find its own private data which is related the IP's
2581 service binding instance that is install on UNDI/SNP handle.
2582 Now, the controller is either a MNP or ARP child handle. But
2583 IP opens these handle BY_DRIVER, use that info, we can get the
2586 @param[in] Controller Then protocol handle to check.
2587 @param[in] ProtocolGuid The protocol that is related with the handle.
2589 @return The UNDI/SNP handle or NULL for errors.
2594 NetLibGetNicHandle (
2595 IN EFI_HANDLE Controller
,
2596 IN EFI_GUID
*ProtocolGuid
2599 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenBuffer
;
2605 Status
= gBS
->OpenProtocolInformation (
2612 if (EFI_ERROR (Status
)) {
2618 for (Index
= 0; Index
< OpenCount
; Index
++) {
2619 if ((OpenBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
2620 Handle
= OpenBuffer
[Index
].ControllerHandle
;
2625 gBS
->FreePool (OpenBuffer
);
2630 Convert one Null-terminated ASCII string (decimal dotted) to EFI_IPv4_ADDRESS.
2632 @param[in] String The pointer to the Ascii string.
2633 @param[out] Ip4Address The pointer to the converted IPv4 address.
2635 @retval EFI_SUCCESS Convert to IPv4 address successfully.
2636 @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip4Address is NULL.
2641 NetLibAsciiStrToIp4 (
2642 IN CONST CHAR8
*String
,
2643 OUT EFI_IPv4_ADDRESS
*Ip4Address
2651 if ((String
== NULL
) || (Ip4Address
== NULL
)) {
2652 return EFI_INVALID_PARAMETER
;
2655 Ip4Str
= (CHAR8
*) String
;
2657 for (Index
= 0; Index
< 4; Index
++) {
2660 while ((*Ip4Str
!= '\0') && (*Ip4Str
!= '.')) {
2665 // The IPv4 address is X.X.X.X
2667 if (*Ip4Str
== '.') {
2669 return EFI_INVALID_PARAMETER
;
2673 return EFI_INVALID_PARAMETER
;
2678 // Convert the string to IPv4 address. AsciiStrDecimalToUintn stops at the
2679 // first character that is not a valid decimal character, '.' or '\0' here.
2681 NodeVal
= AsciiStrDecimalToUintn (TempStr
);
2682 if (NodeVal
> 0xFF) {
2683 return EFI_INVALID_PARAMETER
;
2686 Ip4Address
->Addr
[Index
] = (UINT8
) NodeVal
;
2696 Convert one Null-terminated ASCII string to EFI_IPv6_ADDRESS. The format of the
2697 string is defined in RFC 4291 - Text Pepresentation of Addresses.
2699 @param[in] String The pointer to the Ascii string.
2700 @param[out] Ip6Address The pointer to the converted IPv6 address.
2702 @retval EFI_SUCCESS Convert to IPv6 address successfully.
2703 @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip6Address is NULL.
2708 NetLibAsciiStrToIp6 (
2709 IN CONST CHAR8
*String
,
2710 OUT EFI_IPv6_ADDRESS
*Ip6Address
2724 if ((String
== NULL
) || (Ip6Address
== NULL
)) {
2725 return EFI_INVALID_PARAMETER
;
2728 Ip6Str
= (CHAR8
*) String
;
2732 // An IPv6 address leading with : looks strange.
2734 if (*Ip6Str
== ':') {
2735 if (*(Ip6Str
+ 1) != ':') {
2736 return EFI_INVALID_PARAMETER
;
2742 ZeroMem (Ip6Address
, sizeof (EFI_IPv6_ADDRESS
));
2749 for (Index
= 0; Index
< 15; Index
= (UINT8
) (Index
+ 2)) {
2752 while ((*Ip6Str
!= '\0') && (*Ip6Str
!= ':')) {
2756 if ((*Ip6Str
== '\0') && (Index
!= 14)) {
2757 return EFI_INVALID_PARAMETER
;
2760 if (*Ip6Str
== ':') {
2761 if (*(Ip6Str
+ 1) == ':') {
2762 if ((*(Ip6Str
+ 2) == '0') || (NodeCnt
> 6)) {
2764 // ::0 looks strange. report error to user.
2766 return EFI_INVALID_PARAMETER
;
2770 // Skip the abbreviation part of IPv6 address.
2772 TempStr2
= Ip6Str
+ 2;
2773 while ((*TempStr2
!= '\0')) {
2774 if (*TempStr2
== ':') {
2775 if (*(TempStr2
+ 1) == ':') {
2777 // :: can only appear once in IPv6 address.
2779 return EFI_INVALID_PARAMETER
;
2783 if (TailNodeCnt
>= (AllowedCnt
- NodeCnt
)) {
2785 // :: indicates one or more groups of 16 bits of zeros.
2787 return EFI_INVALID_PARAMETER
;
2797 Ip6Str
= Ip6Str
+ 2;
2801 if ((Short
&& (NodeCnt
> 6)) || (!Short
&& (NodeCnt
> 7))) {
2803 // There are more than 8 groups of 16 bits of zeros.
2805 return EFI_INVALID_PARAMETER
;
2811 // Convert the string to IPv6 address. AsciiStrHexToUintn stops at the first
2812 // character that is not a valid hexadecimal character, ':' or '\0' here.
2814 NodeVal
= AsciiStrHexToUintn (TempStr
);
2815 if ((NodeVal
> 0xFFFF) || (Index
> 14)) {
2816 return EFI_INVALID_PARAMETER
;
2819 Ip6Address
->Addr
[Index
] = (UINT8
) (NodeVal
>> 8);
2820 Ip6Address
->Addr
[Index
+ 1] = (UINT8
) (NodeVal
& 0xFF);
2823 // Skip the groups of zeros by ::
2825 if (Short
&& Update
) {
2826 Index
= (UINT8
) (16 - (TailNodeCnt
+ 2) * 2);
2831 if ((!Short
&& Index
!= 16) || (*Ip6Str
!= '\0')) {
2832 return EFI_INVALID_PARAMETER
;
2840 Convert one Null-terminated Unicode string (decimal dotted) to EFI_IPv4_ADDRESS.
2842 @param[in] String The pointer to the Ascii string.
2843 @param[out] Ip4Address The pointer to the converted IPv4 address.
2845 @retval EFI_SUCCESS Convert to IPv4 address successfully.
2846 @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip4Address is NULL.
2847 @retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to lack of resource.
2853 IN CONST CHAR16
*String
,
2854 OUT EFI_IPv4_ADDRESS
*Ip4Address
2860 if ((String
== NULL
) || (Ip4Address
== NULL
)) {
2861 return EFI_INVALID_PARAMETER
;
2864 Ip4Str
= (CHAR8
*) AllocatePool ((StrLen (String
) + 1) * sizeof (CHAR8
));
2865 if (Ip4Str
== NULL
) {
2866 return EFI_OUT_OF_RESOURCES
;
2869 UnicodeStrToAsciiStr (String
, Ip4Str
);
2871 Status
= NetLibAsciiStrToIp4 (Ip4Str
, Ip4Address
);
2880 Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS. The format of
2881 the string is defined in RFC 4291 - Text Pepresentation of Addresses.
2883 @param[in] String The pointer to the Ascii string.
2884 @param[out] Ip6Address The pointer to the converted IPv6 address.
2886 @retval EFI_SUCCESS Convert to IPv6 address successfully.
2887 @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip6Address is NULL.
2888 @retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to lack of resource.
2894 IN CONST CHAR16
*String
,
2895 OUT EFI_IPv6_ADDRESS
*Ip6Address
2901 if ((String
== NULL
) || (Ip6Address
== NULL
)) {
2902 return EFI_INVALID_PARAMETER
;
2905 Ip6Str
= (CHAR8
*) AllocatePool ((StrLen (String
) + 1) * sizeof (CHAR8
));
2906 if (Ip6Str
== NULL
) {
2907 return EFI_OUT_OF_RESOURCES
;
2910 UnicodeStrToAsciiStr (String
, Ip6Str
);
2912 Status
= NetLibAsciiStrToIp6 (Ip6Str
, Ip6Address
);
2920 Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS and prefix length.
2921 The format of the string is defined in RFC 4291 - Text Pepresentation of Addresses
2922 Prefixes: ipv6-address/prefix-length.
2924 @param[in] String The pointer to the Ascii string.
2925 @param[out] Ip6Address The pointer to the converted IPv6 address.
2926 @param[out] PrefixLength The pointer to the converted prefix length.
2928 @retval EFI_SUCCESS Convert to IPv6 address successfully.
2929 @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip6Address is NULL.
2930 @retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to lack of resource.
2935 NetLibStrToIp6andPrefix (
2936 IN CONST CHAR16
*String
,
2937 OUT EFI_IPv6_ADDRESS
*Ip6Address
,
2938 OUT UINT8
*PrefixLength
2947 if ((String
== NULL
) || (Ip6Address
== NULL
) || (PrefixLength
== NULL
)) {
2948 return EFI_INVALID_PARAMETER
;
2951 Ip6Str
= (CHAR8
*) AllocatePool ((StrLen (String
) + 1) * sizeof (CHAR8
));
2952 if (Ip6Str
== NULL
) {
2953 return EFI_OUT_OF_RESOURCES
;
2956 UnicodeStrToAsciiStr (String
, Ip6Str
);
2959 // Get the sub string describing prefix length.
2962 while (*TempStr
!= '\0' && (*TempStr
!= '/')) {
2966 if (*TempStr
== '/') {
2967 PrefixStr
= TempStr
+ 1;
2973 // Get the sub string describing IPv6 address and convert it.
2977 Status
= NetLibAsciiStrToIp6 (Ip6Str
, Ip6Address
);
2978 if (EFI_ERROR (Status
)) {
2983 // If input string doesn't indicate the prefix length, return 0xff.
2988 // Convert the string to prefix length
2990 if (PrefixStr
!= NULL
) {
2992 Status
= EFI_INVALID_PARAMETER
;
2994 while (*PrefixStr
!= '\0') {
2995 if (NET_IS_DIGIT (*PrefixStr
)) {
2996 Length
= (UINT8
) (Length
* 10 + (*PrefixStr
- '0'));
2997 if (Length
>= IP6_PREFIX_NUM
) {
3008 *PrefixLength
= Length
;
3009 Status
= EFI_SUCCESS
;