4 Copyright (c) 2005 - 2009, 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 Locate the handles that support SNP, then open one of them
116 to send the syslog packets. The caller isn't required to close
117 the SNP after use because the SNP is opened by HandleProtocol.
119 @return The point to SNP if one is properly openned. Otherwise NULL
122 EFI_SIMPLE_NETWORK_PROTOCOL
*
127 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
134 // Locate the handles which has SNP installed.
137 Status
= gBS
->LocateHandleBuffer (
139 &gEfiSimpleNetworkProtocolGuid
,
145 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
150 // Try to open one of the ethernet SNP protocol to send packet
154 for (Index
= 0; Index
< HandleCount
; Index
++) {
155 Status
= gBS
->HandleProtocol (
157 &gEfiSimpleNetworkProtocolGuid
,
161 if ((Status
== EFI_SUCCESS
) && (Snp
!= NULL
) &&
162 (Snp
->Mode
->IfType
== NET_IFTYPE_ETHERNET
) &&
163 (Snp
->Mode
->MaxPacketSize
>= NET_SYSLOG_PACKET_LEN
)) {
176 Transmit a syslog packet synchronously through SNP. The Packet
177 already has the ethernet header prepended. This function should
178 fill in the source MAC because it will try to locate a SNP each
179 time it is called to avoid the problem if SNP is unloaded.
180 This code snip is copied from MNP.
182 @param[in] Packet The Syslog packet
183 @param[in] Length The length of the packet
185 @retval EFI_DEVICE_ERROR Failed to locate a usable SNP protocol
186 @retval EFI_TIMEOUT Timeout happened to send the packet.
187 @retval EFI_SUCCESS Packet is sent.
196 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
199 EFI_EVENT TimeoutEvent
;
202 Snp
= SyslogLocateSnp ();
205 return EFI_DEVICE_ERROR
;
208 Ether
= (ETHER_HEAD
*) Packet
;
209 CopyMem (Ether
->SrcMac
, Snp
->Mode
->CurrentAddress
.Addr
, NET_ETHER_ADDR_LEN
);
212 // Start the timeout event.
214 Status
= gBS
->CreateEvent (
222 if (EFI_ERROR (Status
)) {
226 Status
= gBS
->SetTimer (TimeoutEvent
, TimerRelative
, NET_SYSLOG_TX_TIMEOUT
);
228 if (EFI_ERROR (Status
)) {
234 // Transmit the packet through SNP.
236 Status
= Snp
->Transmit (Snp
, 0, Length
, Packet
, NULL
, NULL
, NULL
);
238 if ((Status
!= EFI_SUCCESS
) && (Status
!= EFI_NOT_READY
)) {
239 Status
= EFI_DEVICE_ERROR
;
244 // If Status is EFI_SUCCESS, the packet is put in the transmit queue.
245 // if Status is EFI_NOT_READY, the transmit engine of the network
246 // interface is busy. Both need to sync SNP.
252 // Get the recycled transmit buffer status.
254 Snp
->GetStatus (Snp
, NULL
, (VOID
**) &TxBuf
);
256 if (!EFI_ERROR (gBS
->CheckEvent (TimeoutEvent
))) {
257 Status
= EFI_TIMEOUT
;
261 } while (TxBuf
== NULL
);
263 if ((Status
== EFI_SUCCESS
) || (Status
== EFI_TIMEOUT
)) {
268 // Status is EFI_NOT_READY. Restart the timer event and
269 // call Snp->Transmit again.
271 gBS
->SetTimer (TimeoutEvent
, TimerRelative
, NET_SYSLOG_TX_TIMEOUT
);
274 gBS
->SetTimer (TimeoutEvent
, TimerCancel
, 0);
277 gBS
->CloseEvent (TimeoutEvent
);
282 Build a syslog packet, including the Ethernet/Ip/Udp headers
285 @param[in] Level Syslog servity level
286 @param[in] Module The module that generates the log
287 @param[in] File The file that contains the current log
288 @param[in] Line The line of code in the File that contains the current log
289 @param[in] Message The log message
290 @param[in] BufLen The lenght of the Buf
291 @param[out] Buf The buffer to put the packet data
293 @return The length of the syslog packet built.
309 EFI_UDP_HEADER
*Udp4
;
315 // Fill in the Ethernet header. Leave alone the source MAC.
316 // SyslogSendPacket will fill in the address for us.
318 Ether
= (ETHER_HEAD
*) Buf
;
319 CopyMem (Ether
->DstMac
, mSyslogDstMac
, NET_ETHER_ADDR_LEN
);
320 ZeroMem (Ether
->SrcMac
, NET_ETHER_ADDR_LEN
);
322 Ether
->EtherType
= HTONS (0x0800); // IPv4 protocol
324 Buf
+= sizeof (ETHER_HEAD
);
325 BufLen
-= sizeof (ETHER_HEAD
);
328 // Fill in the IP header
330 Ip4
= (IP4_HEAD
*) Buf
;
335 Ip4
->Id
= (UINT16
) mSyslogPacketSeq
;
338 Ip4
->Protocol
= 0x11;
340 Ip4
->Src
= mSyslogSrcIp
;
341 Ip4
->Dst
= mSyslogDstIp
;
343 Buf
+= sizeof (IP4_HEAD
);
344 BufLen
-= sizeof (IP4_HEAD
);
347 // Fill in the UDP header, Udp checksum is optional. Leave it zero.
349 Udp4
= (EFI_UDP_HEADER
*) Buf
;
350 Udp4
->SrcPort
= HTONS (514);
351 Udp4
->DstPort
= HTONS (514);
355 Buf
+= sizeof (EFI_UDP_HEADER
);
356 BufLen
-= sizeof (EFI_UDP_HEADER
);
359 // Build the syslog message body with <PRI> Timestamp machine module Message
361 Pri
= ((NET_SYSLOG_FACILITY
& 31) << 3) | (Level
& 7);
362 gRT
->GetTime (&Time
, NULL
);
365 // Use %a to format the ASCII strings, %s to format UNICODE strings
368 Len
+= (UINT32
) AsciiSPrint (
371 "<%d> %a %d %d:%d:%d ",
373 mMonthName
[Time
.Month
-1],
381 Len
+= (UINT32
) AsciiSPrint (
384 "Tiano %a: %a (Line: %d File: %a)",
393 // OK, patch the IP length/checksum and UDP length fields.
395 Len
+= sizeof (EFI_UDP_HEADER
);
396 Udp4
->Length
= HTONS ((UINT16
) Len
);
398 Len
+= sizeof (IP4_HEAD
);
399 Ip4
->TotalLen
= HTONS ((UINT16
) Len
);
400 Ip4
->Checksum
= (UINT16
) (~NetblockChecksum ((UINT8
*) Ip4
, sizeof (IP4_HEAD
)));
402 return Len
+ sizeof (ETHER_HEAD
);
406 Allocate a buffer, then format the message to it. This is a
407 help function for the NET_DEBUG_XXX macros. The PrintArg of
408 these macros treats the variable length print parameters as a
409 single parameter, and pass it to the NetDebugASPrint. For
410 example, NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name))
414 NETDEBUG_LEVEL_TRACE,
418 NetDebugASPrint ("State transit to %a\n", Name)
421 @param Format The ASCII format string.
422 @param ... The variable length parameter whose format is determined
423 by the Format string.
425 @return The buffer containing the formatted message,
426 or NULL if failed to allocate memory.
438 Buf
= (CHAR8
*) AllocatePool (NET_DEBUG_MSG_LEN
);
444 VA_START (Marker
, Format
);
445 AsciiVSPrint (Buf
, NET_DEBUG_MSG_LEN
, Format
, Marker
);
452 Builds an UDP4 syslog packet and send it using SNP.
454 This function will locate a instance of SNP then send the message through it.
455 Because it isn't open the SNP BY_DRIVER, apply caution when using it.
457 @param Level The servity level of the message.
458 @param Module The Moudle that generates the log.
459 @param File The file that contains the log.
460 @param Line The exact line that contains the log.
461 @param Message The user message to log.
463 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
464 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet
465 @retval EFI_SUCCESS The log is discard because that it is more verbose
466 than the mNetDebugLevelMax. Or, it has been sent out.
482 // Check whether the message should be sent out
484 if (Message
== NULL
) {
485 return EFI_INVALID_PARAMETER
;
488 if (Level
> mNetDebugLevelMax
) {
489 Status
= EFI_SUCCESS
;
494 // Allocate a maxium of 1024 bytes, the caller should ensure
495 // that the message plus the ethernet/ip/udp header is shorter
498 Packet
= (CHAR8
*) AllocatePool (NET_SYSLOG_PACKET_LEN
);
500 if (Packet
== NULL
) {
501 Status
= EFI_OUT_OF_RESOURCES
;
506 // Build the message: Ethernet header + IP header + Udp Header + user data
508 Len
= SyslogBuildPacket (
514 NET_SYSLOG_PACKET_LEN
,
519 Status
= SyslogSendPacket (Packet
, Len
);
527 Return the length of the mask.
529 Return the length of the mask, the correct value is from 0 to 32.
530 If the mask is invalid, return the invalid length 33, which is IP4_MASK_NUM.
531 NetMask is in the host byte order.
533 @param[in] NetMask The netmask to get the length from.
535 @return The length of the netmask, IP4_MASK_NUM if the mask is invalid.
546 for (Index
= 0; Index
< IP4_MASK_NUM
; Index
++) {
547 if (NetMask
== gIp4AllMasks
[Index
]) {
558 Return the class of the IP address, such as class A, B, C.
559 Addr is in host byte order.
561 The address of class A starts with 0.
562 If the address belong to class A, return IP4_ADDR_CLASSA.
563 The address of class B starts with 10.
564 If the address belong to class B, return IP4_ADDR_CLASSB.
565 The address of class C starts with 110.
566 If the address belong to class C, return IP4_ADDR_CLASSC.
567 The address of class D starts with 1110.
568 If the address belong to class D, return IP4_ADDR_CLASSD.
569 The address of class E starts with 1111.
570 If the address belong to class E, return IP4_ADDR_CLASSE.
573 @param[in] Addr The address to get the class from.
575 @return IP address class, such as IP4_ADDR_CLASSA.
586 ByteOne
= (UINT8
) (Addr
>> 24);
588 if ((ByteOne
& 0x80) == 0) {
589 return IP4_ADDR_CLASSA
;
591 } else if ((ByteOne
& 0xC0) == 0x80) {
592 return IP4_ADDR_CLASSB
;
594 } else if ((ByteOne
& 0xE0) == 0xC0) {
595 return IP4_ADDR_CLASSC
;
597 } else if ((ByteOne
& 0xF0) == 0xE0) {
598 return IP4_ADDR_CLASSD
;
601 return IP4_ADDR_CLASSE
;
608 Check whether the IP is a valid unicast address according to
609 the netmask. If NetMask is zero, use the IP address's class to get the default mask.
611 If Ip is 0, IP is not a valid unicast address.
612 Class D address is used for multicasting and class E address is reserved for future. If Ip
613 belongs to class D or class E, IP is not a valid unicast address.
614 If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.
616 @param[in] Ip The IP to check against.
617 @param[in] NetMask The mask of the IP.
619 @return TRUE if IP is a valid unicast address on the network, otherwise FALSE.
631 Class
= NetGetIpClass (Ip
);
633 if ((Ip
== 0) || (Class
>= IP4_ADDR_CLASSD
)) {
638 NetMask
= gIp4AllMasks
[Class
<< 3];
641 if (((Ip
&~NetMask
) == ~NetMask
) || ((Ip
&~NetMask
) == 0)) {
649 Check whether the incoming IPv6 address is a valid unicast address.
651 If the address is a multicast address has binary 0xFF at the start, it is not
652 a valid unicast address. If the address is unspecified ::, it is not a valid
653 unicast address to be assigned to any node. If the address is loopback address
654 ::1, it is also not a valid unicast address to be assigned to any physical
657 @param[in] Ip6 The IPv6 address to check against.
659 @return TRUE if Ip6 is a valid unicast address on the network, otherwise FALSE.
663 NetIp6IsValidUnicast (
664 IN EFI_IPv6_ADDRESS
*Ip6
670 if (Ip6
->Addr
[0] == 0xFF) {
674 for (Index
= 0; Index
< 15; Index
++) {
675 if (Ip6
->Addr
[Index
] != 0) {
680 Byte
= Ip6
->Addr
[Index
];
682 if (Byte
== 0x0 || Byte
== 0x1) {
690 Check whether the incoming Ipv6 address is the unspecified address or not.
692 @param[in] Ip6 - Ip6 address, in network order.
694 @retval TRUE - Yes, unspecified
699 NetIp6IsUnspecifiedAddr (
700 IN EFI_IPv6_ADDRESS
*Ip6
705 for (Index
= 0; Index
< 16; Index
++) {
706 if (Ip6
->Addr
[Index
] != 0) {
715 Check whether the incoming Ipv6 address is a link-local address.
717 @param[in] Ip6 - Ip6 address, in network order.
719 @retval TRUE - Yes, link-local address
724 NetIp6IsLinkLocalAddr (
725 IN EFI_IPv6_ADDRESS
*Ip6
730 ASSERT (Ip6
!= NULL
);
732 if (Ip6
->Addr
[0] != 0xFE) {
736 if (Ip6
->Addr
[1] != 0x80) {
740 for (Index
= 2; Index
< 8; Index
++) {
741 if (Ip6
->Addr
[Index
] != 0) {
750 Check whether the Ipv6 address1 and address2 are on the connected network.
752 @param[in] Ip1 - Ip6 address1, in network order.
753 @param[in] Ip2 - Ip6 address2, in network order.
754 @param[in] PrefixLength - The prefix length of the checking net.
756 @retval TRUE - Yes, connected.
762 EFI_IPv6_ADDRESS
*Ip1
,
763 EFI_IPv6_ADDRESS
*Ip2
,
771 ASSERT (Ip1
!= NULL
&& Ip2
!= NULL
);
773 if (PrefixLength
== 0) {
777 Byte
= (UINT8
) (PrefixLength
/ 8);
778 Bit
= (UINT8
) (PrefixLength
% 8);
780 if (CompareMem (Ip1
, Ip2
, Byte
) != 0) {
785 Mask
= (UINT8
) (0xFF << (8 - Bit
));
787 if ((Ip1
->Addr
[Byte
] & Mask
) != (Ip2
->Addr
[Byte
] & Mask
)) {
797 Switches the endianess of an IPv6 address
799 This function swaps the bytes in a 128-bit IPv6 address to switch the value
800 from little endian to big endian or vice versa. The byte swapped value is
803 @param Ip6 Points to an IPv6 address
805 @return The byte swapped IPv6 address.
810 EFI_IPv6_ADDRESS
*Ip6
816 CopyMem (&High
, Ip6
, sizeof (UINT64
));
817 CopyMem (&Low
, &Ip6
->Addr
[8], sizeof (UINT64
));
819 High
= SwapBytes64 (High
);
820 Low
= SwapBytes64 (Low
);
822 CopyMem (Ip6
, &Low
, sizeof (UINT64
));
823 CopyMem (&Ip6
->Addr
[8], &High
, sizeof (UINT64
));
829 Initialize a random seed using current time.
831 Get current time first. Then initialize a random seed based on some basic
832 mathematics operation on the hour, day, minute, second, nanosecond and year
835 @return The random seed initialized with current time.
847 gRT
->GetTime (&Time
, NULL
);
848 Seed
= (~Time
.Hour
<< 24 | Time
.Day
<< 16 | Time
.Minute
<< 8 | Time
.Second
);
849 Seed
^= Time
.Nanosecond
;
850 Seed
^= Time
.Year
<< 7;
857 Extract a UINT32 from a byte stream.
859 Copy a UINT32 from a byte stream, then converts it from Network
860 byte order to host byte order. Use this function to avoid alignment error.
862 @param[in] Buf The buffer to extract the UINT32.
864 @return The UINT32 extracted.
875 CopyMem (&Value
, Buf
, sizeof (UINT32
));
876 return NTOHL (Value
);
881 Put a UINT32 to the byte stream in network byte order.
883 Converts a UINT32 from host byte order to network byte order. Then copy it to the
886 @param[in, out] Buf The buffer to put the UINT32.
887 @param[in] Data The data to put.
898 CopyMem (Buf
, &Data
, sizeof (UINT32
));
903 Remove the first node entry on the list, and return the removed node entry.
905 Removes the first node Entry from a doubly linked list. It is up to the caller of
906 this function to release the memory used by the first node if that is required. On
907 exit, the removed node is returned.
909 If Head is NULL, then ASSERT().
910 If Head was not initialized, then ASSERT().
911 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
912 linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,
915 @param[in, out] Head The list header.
917 @return The first node entry that is removed from the list, NULL if the list is empty.
923 IN OUT LIST_ENTRY
*Head
928 ASSERT (Head
!= NULL
);
930 if (IsListEmpty (Head
)) {
934 First
= Head
->ForwardLink
;
935 Head
->ForwardLink
= First
->ForwardLink
;
936 First
->ForwardLink
->BackLink
= Head
;
939 First
->ForwardLink
= (LIST_ENTRY
*) NULL
;
940 First
->BackLink
= (LIST_ENTRY
*) NULL
;
948 Remove the last node entry on the list and and return the removed node entry.
950 Removes the last node entry from a doubly linked list. It is up to the caller of
951 this function to release the memory used by the first node if that is required. On
952 exit, the removed node is returned.
954 If Head is NULL, then ASSERT().
955 If Head was not initialized, then ASSERT().
956 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
957 linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,
960 @param[in, out] Head The list head.
962 @return The last node entry that is removed from the list, NULL if the list is empty.
968 IN OUT LIST_ENTRY
*Head
973 ASSERT (Head
!= NULL
);
975 if (IsListEmpty (Head
)) {
979 Last
= Head
->BackLink
;
980 Head
->BackLink
= Last
->BackLink
;
981 Last
->BackLink
->ForwardLink
= Head
;
984 Last
->ForwardLink
= (LIST_ENTRY
*) NULL
;
985 Last
->BackLink
= (LIST_ENTRY
*) NULL
;
993 Insert a new node entry after a designated node entry of a doubly linked list.
995 Inserts a new node entry donated by NewEntry after the node entry donated by PrevEntry
996 of the doubly linked list.
998 @param[in, out] PrevEntry The previous entry to insert after.
999 @param[in, out] NewEntry The new entry to insert.
1004 NetListInsertAfter (
1005 IN OUT LIST_ENTRY
*PrevEntry
,
1006 IN OUT LIST_ENTRY
*NewEntry
1009 NewEntry
->BackLink
= PrevEntry
;
1010 NewEntry
->ForwardLink
= PrevEntry
->ForwardLink
;
1011 PrevEntry
->ForwardLink
->BackLink
= NewEntry
;
1012 PrevEntry
->ForwardLink
= NewEntry
;
1017 Insert a new node entry before a designated node entry of a doubly linked list.
1019 Inserts a new node entry donated by NewEntry after the node entry donated by PostEntry
1020 of the doubly linked list.
1022 @param[in, out] PostEntry The entry to insert before.
1023 @param[in, out] NewEntry The new entry to insert.
1028 NetListInsertBefore (
1029 IN OUT LIST_ENTRY
*PostEntry
,
1030 IN OUT LIST_ENTRY
*NewEntry
1033 NewEntry
->ForwardLink
= PostEntry
;
1034 NewEntry
->BackLink
= PostEntry
->BackLink
;
1035 PostEntry
->BackLink
->ForwardLink
= NewEntry
;
1036 PostEntry
->BackLink
= NewEntry
;
1041 Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.
1043 Initialize the forward and backward links of two head nodes donated by Map->Used
1044 and Map->Recycled of two doubly linked lists.
1045 Initializes the count of the <Key, Value> pairs in the netmap to zero.
1047 If Map is NULL, then ASSERT().
1048 If the address of Map->Used is NULL, then ASSERT().
1049 If the address of Map->Recycled is NULl, then ASSERT().
1051 @param[in, out] Map The netmap to initialize.
1060 ASSERT (Map
!= NULL
);
1062 InitializeListHead (&Map
->Used
);
1063 InitializeListHead (&Map
->Recycled
);
1069 To clean up the netmap, that is, release allocated memories.
1071 Removes all nodes of the Used doubly linked list and free memory of all related netmap items.
1072 Removes all nodes of the Recycled doubly linked list and free memory of all related netmap items.
1073 The number of the <Key, Value> pairs in the netmap is set to be zero.
1075 If Map is NULL, then ASSERT().
1077 @param[in, out] Map The netmap to clean up.
1090 ASSERT (Map
!= NULL
);
1092 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Used
) {
1093 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1095 RemoveEntryList (&Item
->Link
);
1098 gBS
->FreePool (Item
);
1101 ASSERT ((Map
->Count
== 0) && IsListEmpty (&Map
->Used
));
1103 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Recycled
) {
1104 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1106 RemoveEntryList (&Item
->Link
);
1107 gBS
->FreePool (Item
);
1110 ASSERT (IsListEmpty (&Map
->Recycled
));
1115 Test whether the netmap is empty and return true if it is.
1117 If the number of the <Key, Value> pairs in the netmap is zero, return TRUE.
1119 If Map is NULL, then ASSERT().
1122 @param[in] Map The net map to test.
1124 @return TRUE if the netmap is empty, otherwise FALSE.
1133 ASSERT (Map
!= NULL
);
1134 return (BOOLEAN
) (Map
->Count
== 0);
1139 Return the number of the <Key, Value> pairs in the netmap.
1141 @param[in] Map The netmap to get the entry number.
1143 @return The entry number in the netmap.
1157 Return one allocated item.
1159 If the Recycled doubly linked list of the netmap is empty, it will try to allocate
1160 a batch of items if there are enough resources and add corresponding nodes to the begining
1161 of the Recycled doubly linked list of the netmap. Otherwise, it will directly remove
1162 the fist node entry of the Recycled doubly linked list and return the corresponding item.
1164 If Map is NULL, then ASSERT().
1166 @param[in, out] Map The netmap to allocate item for.
1168 @return The allocated item. If NULL, the
1169 allocation failed due to resource limit.
1181 ASSERT (Map
!= NULL
);
1183 Head
= &Map
->Recycled
;
1185 if (IsListEmpty (Head
)) {
1186 for (Index
= 0; Index
< NET_MAP_INCREAMENT
; Index
++) {
1187 Item
= AllocatePool (sizeof (NET_MAP_ITEM
));
1197 InsertHeadList (Head
, &Item
->Link
);
1201 Item
= NET_LIST_HEAD (Head
, NET_MAP_ITEM
, Link
);
1202 NetListRemoveHead (Head
);
1209 Allocate an item to save the <Key, Value> pair to the head of the netmap.
1211 Allocate an item to save the <Key, Value> pair and add corresponding node entry
1212 to the beginning of the Used doubly linked list. The number of the <Key, Value>
1213 pairs in the netmap increase by 1.
1215 If Map is NULL, then ASSERT().
1217 @param[in, out] Map The netmap to insert into.
1218 @param[in] Key The user's key.
1219 @param[in] Value The user's value for the key.
1221 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.
1222 @retval EFI_SUCCESS The item is inserted to the head.
1228 IN OUT NET_MAP
*Map
,
1230 IN VOID
*Value OPTIONAL
1235 ASSERT (Map
!= NULL
);
1237 Item
= NetMapAllocItem (Map
);
1240 return EFI_OUT_OF_RESOURCES
;
1244 Item
->Value
= Value
;
1245 InsertHeadList (&Map
->Used
, &Item
->Link
);
1253 Allocate an item to save the <Key, Value> pair to the tail of the netmap.
1255 Allocate an item to save the <Key, Value> pair and add corresponding node entry
1256 to the tail of the Used doubly linked list. The number of the <Key, Value>
1257 pairs in the netmap increase by 1.
1259 If Map is NULL, then ASSERT().
1261 @param[in, out] Map The netmap to insert into.
1262 @param[in] Key The user's key.
1263 @param[in] Value The user's value for the key.
1265 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.
1266 @retval EFI_SUCCESS The item is inserted to the tail.
1272 IN OUT NET_MAP
*Map
,
1274 IN VOID
*Value OPTIONAL
1279 ASSERT (Map
!= NULL
);
1281 Item
= NetMapAllocItem (Map
);
1284 return EFI_OUT_OF_RESOURCES
;
1288 Item
->Value
= Value
;
1289 InsertTailList (&Map
->Used
, &Item
->Link
);
1298 Check whether the item is in the Map and return TRUE if it is.
1300 @param[in] Map The netmap to search within.
1301 @param[in] Item The item to search.
1303 @return TRUE if the item is in the netmap, otherwise FALSE.
1309 IN NET_MAP_ITEM
*Item
1312 LIST_ENTRY
*ListEntry
;
1314 NET_LIST_FOR_EACH (ListEntry
, &Map
->Used
) {
1315 if (ListEntry
== &Item
->Link
) {
1325 Find the key in the netmap and returns the point to the item contains the Key.
1327 Iterate the Used doubly linked list of the netmap to get every item. Compare the key of every
1328 item with the key to search. It returns the point to the item contains the Key if found.
1330 If Map is NULL, then ASSERT().
1332 @param[in] Map The netmap to search within.
1333 @param[in] Key The key to search.
1335 @return The point to the item contains the Key, or NULL if Key isn't in the map.
1348 ASSERT (Map
!= NULL
);
1350 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
1351 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1353 if (Item
->Key
== Key
) {
1363 Remove the node entry of the item from the netmap and return the key of the removed item.
1365 Remove the node entry of the item from the Used doubly linked list of the netmap.
1366 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node
1367 entry of the item to the Recycled doubly linked list of the netmap. If Value is not NULL,
1368 Value will point to the value of the item. It returns the key of the removed item.
1370 If Map is NULL, then ASSERT().
1371 If Item is NULL, then ASSERT().
1372 if item in not in the netmap, then ASSERT().
1374 @param[in, out] Map The netmap to remove the item from.
1375 @param[in, out] Item The item to remove.
1376 @param[out] Value The variable to receive the value if not NULL.
1378 @return The key of the removed item.
1384 IN OUT NET_MAP
*Map
,
1385 IN OUT NET_MAP_ITEM
*Item
,
1386 OUT VOID
**Value OPTIONAL
1389 ASSERT ((Map
!= NULL
) && (Item
!= NULL
));
1390 ASSERT (NetItemInMap (Map
, Item
));
1392 RemoveEntryList (&Item
->Link
);
1394 InsertHeadList (&Map
->Recycled
, &Item
->Link
);
1396 if (Value
!= NULL
) {
1397 *Value
= Item
->Value
;
1405 Remove the first node entry on the netmap and return the key of the removed item.
1407 Remove the first node entry from the Used doubly linked list of the netmap.
1408 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node
1409 entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,
1410 parameter Value will point to the value of the item. It returns the key of the removed item.
1412 If Map is NULL, then ASSERT().
1413 If the Used doubly linked list is empty, then ASSERT().
1415 @param[in, out] Map The netmap to remove the head from.
1416 @param[out] Value The variable to receive the value if not NULL.
1418 @return The key of the item removed.
1424 IN OUT NET_MAP
*Map
,
1425 OUT VOID
**Value OPTIONAL
1431 // Often, it indicates a programming error to remove
1432 // the first entry in an empty list
1434 ASSERT (Map
&& !IsListEmpty (&Map
->Used
));
1436 Item
= NET_LIST_HEAD (&Map
->Used
, NET_MAP_ITEM
, Link
);
1437 RemoveEntryList (&Item
->Link
);
1439 InsertHeadList (&Map
->Recycled
, &Item
->Link
);
1441 if (Value
!= NULL
) {
1442 *Value
= Item
->Value
;
1450 Remove the last node entry on the netmap and return the key of the removed item.
1452 Remove the last node entry from the Used doubly linked list of the netmap.
1453 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node
1454 entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,
1455 parameter Value will point to the value of the item. It returns the key of the removed item.
1457 If Map is NULL, then ASSERT().
1458 If the Used doubly linked list is empty, then ASSERT().
1460 @param[in, out] Map The netmap to remove the tail from.
1461 @param[out] Value The variable to receive the value if not NULL.
1463 @return The key of the item removed.
1469 IN OUT NET_MAP
*Map
,
1470 OUT VOID
**Value OPTIONAL
1476 // Often, it indicates a programming error to remove
1477 // the last entry in an empty list
1479 ASSERT (Map
&& !IsListEmpty (&Map
->Used
));
1481 Item
= NET_LIST_TAIL (&Map
->Used
, NET_MAP_ITEM
, Link
);
1482 RemoveEntryList (&Item
->Link
);
1484 InsertHeadList (&Map
->Recycled
, &Item
->Link
);
1486 if (Value
!= NULL
) {
1487 *Value
= Item
->Value
;
1495 Iterate through the netmap and call CallBack for each item.
1497 It will contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break
1498 from the loop. It returns the CallBack's last return value. This function is
1499 delete safe for the current item.
1501 If Map is NULL, then ASSERT().
1502 If CallBack is NULL, then ASSERT().
1504 @param[in] Map The Map to iterate through.
1505 @param[in] CallBack The callback function to call for each item.
1506 @param[in] Arg The opaque parameter to the callback.
1508 @retval EFI_SUCCESS There is no item in the netmap or CallBack for each item
1510 @retval Others It returns the CallBack's last return value.
1517 IN NET_MAP_CALLBACK CallBack
,
1528 ASSERT ((Map
!= NULL
) && (CallBack
!= NULL
));
1532 if (IsListEmpty (Head
)) {
1536 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, Head
) {
1537 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1538 Result
= CallBack (Map
, Item
, Arg
);
1540 if (EFI_ERROR (Result
)) {
1550 This is the default unload handle for all the network drivers.
1552 Disconnect the driver specified by ImageHandle from all the devices in the handle database.
1553 Uninstall all the protocols installed in the driver entry point.
1555 @param[in] ImageHandle The drivers' driver image.
1557 @retval EFI_SUCCESS The image is unloaded.
1558 @retval Others Failed to unload the image.
1563 NetLibDefaultUnload (
1564 IN EFI_HANDLE ImageHandle
1568 EFI_HANDLE
*DeviceHandleBuffer
;
1569 UINTN DeviceHandleCount
;
1571 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
1572 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1573 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
1576 // Get the list of all the handles in the handle database.
1577 // If there is an error getting the list, then the unload
1580 Status
= gBS
->LocateHandleBuffer (
1588 if (EFI_ERROR (Status
)) {
1593 // Disconnect the driver specified by ImageHandle from all
1594 // the devices in the handle database.
1596 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1597 Status
= gBS
->DisconnectController (
1598 DeviceHandleBuffer
[Index
],
1605 // Uninstall all the protocols installed in the driver entry point
1607 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1608 Status
= gBS
->HandleProtocol (
1609 DeviceHandleBuffer
[Index
],
1610 &gEfiDriverBindingProtocolGuid
,
1611 (VOID
**) &DriverBinding
1614 if (EFI_ERROR (Status
)) {
1618 if (DriverBinding
->ImageHandle
!= ImageHandle
) {
1622 gBS
->UninstallProtocolInterface (
1624 &gEfiDriverBindingProtocolGuid
,
1627 Status
= gBS
->HandleProtocol (
1628 DeviceHandleBuffer
[Index
],
1629 &gEfiComponentNameProtocolGuid
,
1630 (VOID
**) &ComponentName
1632 if (!EFI_ERROR (Status
)) {
1633 gBS
->UninstallProtocolInterface (
1635 &gEfiComponentNameProtocolGuid
,
1640 Status
= gBS
->HandleProtocol (
1641 DeviceHandleBuffer
[Index
],
1642 &gEfiComponentName2ProtocolGuid
,
1643 (VOID
**) &ComponentName2
1645 if (!EFI_ERROR (Status
)) {
1646 gBS
->UninstallProtocolInterface (
1648 &gEfiComponentName2ProtocolGuid
,
1655 // Free the buffer containing the list of handles from the handle database
1657 if (DeviceHandleBuffer
!= NULL
) {
1658 gBS
->FreePool (DeviceHandleBuffer
);
1667 Create a child of the service that is identified by ServiceBindingGuid.
1669 Get the ServiceBinding Protocol first, then use it to create a child.
1671 If ServiceBindingGuid is NULL, then ASSERT().
1672 If ChildHandle is NULL, then ASSERT().
1674 @param[in] Controller The controller which has the service installed.
1675 @param[in] Image The image handle used to open service.
1676 @param[in] ServiceBindingGuid The service's Guid.
1677 @param[in, out] ChildHandle The handle to receive the create child.
1679 @retval EFI_SUCCESS The child is successfully created.
1680 @retval Others Failed to create the child.
1685 NetLibCreateServiceChild (
1686 IN EFI_HANDLE Controller
,
1687 IN EFI_HANDLE Image
,
1688 IN EFI_GUID
*ServiceBindingGuid
,
1689 IN OUT EFI_HANDLE
*ChildHandle
1693 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
1696 ASSERT ((ServiceBindingGuid
!= NULL
) && (ChildHandle
!= NULL
));
1699 // Get the ServiceBinding Protocol
1701 Status
= gBS
->OpenProtocol (
1707 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1710 if (EFI_ERROR (Status
)) {
1717 Status
= Service
->CreateChild (Service
, ChildHandle
);
1723 Destory a child of the service that is identified by ServiceBindingGuid.
1725 Get the ServiceBinding Protocol first, then use it to destroy a child.
1727 If ServiceBindingGuid is NULL, then ASSERT().
1729 @param[in] Controller The controller which has the service installed.
1730 @param[in] Image The image handle used to open service.
1731 @param[in] ServiceBindingGuid The service's Guid.
1732 @param[in] ChildHandle The child to destory.
1734 @retval EFI_SUCCESS The child is successfully destoried.
1735 @retval Others Failed to destory the child.
1740 NetLibDestroyServiceChild (
1741 IN EFI_HANDLE Controller
,
1742 IN EFI_HANDLE Image
,
1743 IN EFI_GUID
*ServiceBindingGuid
,
1744 IN EFI_HANDLE ChildHandle
1748 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
1750 ASSERT (ServiceBindingGuid
!= NULL
);
1753 // Get the ServiceBinding Protocol
1755 Status
= gBS
->OpenProtocol (
1761 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1764 if (EFI_ERROR (Status
)) {
1769 // destory the child
1771 Status
= Service
->DestroyChild (Service
, ChildHandle
);
1777 Convert the mac address of the simple network protocol installed on
1778 SnpHandle to a unicode string. Callers are responsible for freeing the
1781 Get the mac address of the Simple Network protocol from the SnpHandle. Then convert
1782 the mac address into a unicode string. It takes 2 unicode characters to represent
1783 a 1 byte binary buffer. Plus one unicode character for the null-terminator.
1786 @param[in] SnpHandle The handle where the simple network protocol is
1788 @param[in] ImageHandle The image handle used to act as the agent handle to
1789 get the simple network protocol.
1790 @param[out] MacString The pointer to store the address of the string
1791 representation of the mac address.
1793 @retval EFI_SUCCESS Convert the mac address a unicode string successfully.
1794 @retval EFI_OUT_OF_RESOURCES There are not enough memory resource.
1795 @retval Others Failed to open the simple network protocol.
1800 NetLibGetMacString (
1801 IN EFI_HANDLE SnpHandle
,
1802 IN EFI_HANDLE ImageHandle
,
1803 OUT CHAR16
**MacString
1807 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
1808 EFI_SIMPLE_NETWORK_MODE
*Mode
;
1816 // Get the Simple Network protocol from the SnpHandle.
1818 Status
= gBS
->OpenProtocol (
1820 &gEfiSimpleNetworkProtocolGuid
,
1824 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1826 if (EFI_ERROR (Status
)) {
1833 // It takes 2 unicode characters to represent a 1 byte binary buffer.
1834 // Plus one unicode character for the null-terminator.
1836 MacAddress
= AllocatePool ((2 * Mode
->HwAddressSize
+ 1) * sizeof (CHAR16
));
1837 if (MacAddress
== NULL
) {
1838 return EFI_OUT_OF_RESOURCES
;
1840 *MacString
= MacAddress
;
1843 // Convert the mac address into a unicode string.
1845 HwAddress
= Mode
->CurrentAddress
.Addr
;
1846 for (Index
= 0; Index
< Mode
->HwAddressSize
; Index
++) {
1847 MacAddress
+= UnicodeValueToString (MacAddress
, PREFIX_ZERO
| RADIX_HEX
, *(HwAddress
++), 2);
1850 MacAddress
[Mode
->HwAddressSize
* 2] = L
'\0';
1857 Check the default address used by the IPv4 driver is static or dynamic (acquired
1860 If the controller handle does not have the NIC Ip4 Config Protocol installed, the
1861 default address is static. If the EFI variable to save the configuration is not found,
1862 the default address is static. Otherwise, get the result from the EFI variable which
1863 saving the configuration.
1865 @param[in] Controller The controller handle which has the NIC Ip4 Config Protocol
1866 relative with the default address to judge.
1868 @retval TRUE If the default address is static.
1869 @retval FALSE If the default address is acquired from DHCP.
1873 NetLibDefaultAddressIsStatic (
1874 IN EFI_HANDLE Controller
1878 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1880 NIC_IP4_CONFIG_INFO
*ConfigInfo
;
1882 EFI_STRING ConfigHdr
;
1883 EFI_STRING ConfigResp
;
1884 EFI_STRING AccessProgress
;
1885 EFI_STRING AccessResults
;
1891 AccessProgress
= NULL
;
1892 AccessResults
= NULL
;
1895 Status
= gBS
->LocateProtocol (
1896 &gEfiHiiConfigRoutingProtocolGuid
,
1898 (VOID
**) &HiiConfigRouting
1900 if (EFI_ERROR (Status
)) {
1905 // Construct config request string header
1907 ConfigHdr
= HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, Controller
);
1908 if (ConfigHdr
== NULL
) {
1912 Len
= StrLen (ConfigHdr
);
1913 ConfigResp
= AllocateZeroPool ((Len
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
));
1914 if (ConfigResp
== NULL
) {
1917 StrCpy (ConfigResp
, ConfigHdr
);
1919 String
= ConfigResp
+ Len
;
1922 (8 + 4 + 7 + 4 + 1) * sizeof (CHAR16
),
1923 L
"&OFFSET=%04X&WIDTH=%04X",
1924 OFFSET_OF (NIC_IP4_CONFIG_INFO
, Source
),
1928 Status
= HiiConfigRouting
->ExtractConfig (
1934 if (EFI_ERROR (Status
)) {
1938 ConfigInfo
= AllocateZeroPool (sizeof (NIC_ITEM_CONFIG_SIZE
));
1939 if (ConfigInfo
== NULL
) {
1943 ConfigInfo
->Source
= IP4_CONFIG_SOURCE_STATIC
;
1944 Len
= NIC_ITEM_CONFIG_SIZE
;
1945 Status
= HiiConfigRouting
->ConfigToBlock (
1948 (UINT8
*) ConfigInfo
,
1952 if (EFI_ERROR (Status
)) {
1956 IsStatic
= (BOOLEAN
) (ConfigInfo
->Source
== IP4_CONFIG_SOURCE_STATIC
);
1960 if (AccessResults
!= NULL
) {
1961 FreePool (AccessResults
);
1963 if (ConfigInfo
!= NULL
) {
1964 FreePool (ConfigInfo
);
1966 if (ConfigResp
!= NULL
) {
1967 FreePool (ConfigResp
);
1969 if (ConfigHdr
!= NULL
) {
1970 FreePool (ConfigHdr
);
1977 Create an IPv4 device path node.
1979 The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.
1980 The header subtype of IPv4 device path node is MSG_IPv4_DP.
1981 The length of the IPv4 device path node in bytes is 19.
1982 Get other info from parameters to make up the whole IPv4 device path node.
1984 @param[in, out] Node Pointer to the IPv4 device path node.
1985 @param[in] Controller The controller handle.
1986 @param[in] LocalIp The local IPv4 address.
1987 @param[in] LocalPort The local port.
1988 @param[in] RemoteIp The remote IPv4 address.
1989 @param[in] RemotePort The remote port.
1990 @param[in] Protocol The protocol type in the IP header.
1991 @param[in] UseDefaultAddress Whether this instance is using default address or not.
1996 NetLibCreateIPv4DPathNode (
1997 IN OUT IPv4_DEVICE_PATH
*Node
,
1998 IN EFI_HANDLE Controller
,
1999 IN IP4_ADDR LocalIp
,
2000 IN UINT16 LocalPort
,
2001 IN IP4_ADDR RemoteIp
,
2002 IN UINT16 RemotePort
,
2004 IN BOOLEAN UseDefaultAddress
2007 Node
->Header
.Type
= MESSAGING_DEVICE_PATH
;
2008 Node
->Header
.SubType
= MSG_IPv4_DP
;
2009 SetDevicePathNodeLength (&Node
->Header
, 19);
2011 CopyMem (&Node
->LocalIpAddress
, &LocalIp
, sizeof (EFI_IPv4_ADDRESS
));
2012 CopyMem (&Node
->RemoteIpAddress
, &RemoteIp
, sizeof (EFI_IPv4_ADDRESS
));
2014 Node
->LocalPort
= LocalPort
;
2015 Node
->RemotePort
= RemotePort
;
2017 Node
->Protocol
= Protocol
;
2019 if (!UseDefaultAddress
) {
2020 Node
->StaticIpAddress
= TRUE
;
2022 Node
->StaticIpAddress
= NetLibDefaultAddressIsStatic (Controller
);
2027 Create an IPv6 device path node.
2029 The header type of IPv6 device path node is MESSAGING_DEVICE_PATH.
2030 The header subtype of IPv6 device path node is MSG_IPv6_DP.
2031 Get other info from parameters to make up the whole IPv6 device path node.
2033 @param[in, out] Node Pointer to the IPv6 device path node.
2034 @param[in] Controller The controller handle.
2035 @param[in] LocalIp The local IPv6 address.
2036 @param[in] LocalPort The local port.
2037 @param[in] RemoteIp The remote IPv6 address.
2038 @param[in] RemotePort The remote port.
2039 @param[in] Protocol The protocol type in the IP header.
2044 NetLibCreateIPv6DPathNode (
2045 IN OUT IPv6_DEVICE_PATH
*Node
,
2046 IN EFI_HANDLE Controller
,
2047 IN EFI_IPv6_ADDRESS
*LocalIp
,
2048 IN UINT16 LocalPort
,
2049 IN EFI_IPv6_ADDRESS
*RemoteIp
,
2050 IN UINT16 RemotePort
,
2054 Node
->Header
.Type
= MESSAGING_DEVICE_PATH
;
2055 Node
->Header
.SubType
= MSG_IPv6_DP
;
2056 SetDevicePathNodeLength (&Node
->Header
, sizeof (IPv6_DEVICE_PATH
));
2058 CopyMem (&Node
->LocalIpAddress
, LocalIp
, sizeof (EFI_IPv6_ADDRESS
));
2059 CopyMem (&Node
->RemoteIpAddress
, RemoteIp
, sizeof (EFI_IPv6_ADDRESS
));
2061 Node
->LocalPort
= LocalPort
;
2062 Node
->RemotePort
= RemotePort
;
2064 Node
->Protocol
= Protocol
;
2065 Node
->StaticIpAddress
= FALSE
;
2069 Find the UNDI/SNP handle from controller and protocol GUID.
2071 For example, IP will open a MNP child to transmit/receive
2072 packets, when MNP is stopped, IP should also be stopped. IP
2073 needs to find its own private data which is related the IP's
2074 service binding instance that is install on UNDI/SNP handle.
2075 Now, the controller is either a MNP or ARP child handle. But
2076 IP opens these handle BY_DRIVER, use that info, we can get the
2079 @param[in] Controller Then protocol handle to check.
2080 @param[in] ProtocolGuid The protocol that is related with the handle.
2082 @return The UNDI/SNP handle or NULL for errors.
2087 NetLibGetNicHandle (
2088 IN EFI_HANDLE Controller
,
2089 IN EFI_GUID
*ProtocolGuid
2092 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenBuffer
;
2098 Status
= gBS
->OpenProtocolInformation (
2105 if (EFI_ERROR (Status
)) {
2111 for (Index
= 0; Index
< OpenCount
; Index
++) {
2112 if (OpenBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) {
2113 Handle
= OpenBuffer
[Index
].ControllerHandle
;
2118 gBS
->FreePool (OpenBuffer
);