3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 #include <Protocol/ServiceBinding.h>
25 #include <Protocol/SimpleNetwork.h>
26 #include <Protocol/LoadedImage.h>
27 #include <Protocol/NicIp4Config.h>
29 #include <Library/NetLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiRuntimeServicesTableLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/MemoryAllocationLib.h>
40 // All the supported IP4 maskes in host byte order.
42 IP4_ADDR mIp4AllMasks
[IP4_MASK_NUM
] = {
81 EFI_IPv4_ADDRESS mZeroIp4Addr
= {{0, 0, 0, 0}};
84 Converts the low nibble of a byte to hex unicode character.
86 @param Nibble lower nibble of a byte.
88 @return Hex unicode character.
98 // This library interface is simply obsolete.
99 // Include the source code to user code.
104 return (CHAR16
)(Nibble
+ L
'0');
107 return (CHAR16
)(Nibble
- 0xA + L
'A');
111 Return the length of the mask. If the mask is invalid,
112 return the invalid length 33, which is IP4_MASK_NUM.
113 NetMask is in the host byte order.
115 @param NetMask The netmask to get the length from
117 @return The length of the netmask, IP4_MASK_NUM if the mask isn't
128 for (Index
= 0; Index
< IP4_MASK_NUM
; Index
++) {
129 if (NetMask
== mIp4AllMasks
[Index
]) {
140 Return the class of the address, such as class a, b, c.
141 Addr is in host byte order.
143 @param Addr The address to get the class from
145 @return IP address class, such as IP4_ADDR_CLASSA
155 ByteOne
= (UINT8
) (Addr
>> 24);
157 if ((ByteOne
& 0x80) == 0) {
158 return IP4_ADDR_CLASSA
;
160 } else if ((ByteOne
& 0xC0) == 0x80) {
161 return IP4_ADDR_CLASSB
;
163 } else if ((ByteOne
& 0xE0) == 0xC0) {
164 return IP4_ADDR_CLASSC
;
166 } else if ((ByteOne
& 0xF0) == 0xE0) {
167 return IP4_ADDR_CLASSD
;
170 return IP4_ADDR_CLASSE
;
177 Check whether the IP is a valid unicast address according to
178 the netmask. If NetMask is zero, use the IP address's class to
179 get the default mask.
181 @param Ip The IP to check againist
182 @param NetMask The mask of the IP
184 @return TRUE if IP is a valid unicast address on the network, otherwise FALSE
195 Class
= NetGetIpClass (Ip
);
197 if ((Ip
== 0) || (Class
>= IP4_ADDR_CLASSD
)) {
202 NetMask
= mIp4AllMasks
[Class
<< 3];
205 if (((Ip
&~NetMask
) == ~NetMask
) || ((Ip
&~NetMask
) == 0)) {
214 Initialize a random seed using current time.
218 @return The random seed initialized with current time.
229 gRT
->GetTime (&Time
, NULL
);
230 Seed
= (~Time
.Hour
<< 24 | Time
.Second
<< 16 | Time
.Minute
<< 8 | Time
.Day
);
231 Seed
^= Time
.Nanosecond
;
232 Seed
^= Time
.Year
<< 7;
239 Extract a UINT32 from a byte stream, then convert it to host
240 byte order. Use this function to avoid alignment error.
242 @param Buf The buffer to extract the UINT32.
244 @return The UINT32 extracted.
254 NetCopyMem (&Value
, Buf
, sizeof (UINT32
));
255 return NTOHL (Value
);
260 Put a UINT32 to the byte stream. Convert it from host byte order
261 to network byte order before putting.
263 @param Buf The buffer to put the UINT32
264 @param Data The data to put
276 NetCopyMem (Buf
, &Data
, sizeof (UINT32
));
281 Remove the first entry on the list
283 @param Head The list header
285 @return The entry that is removed from the list, NULL if the list is empty.
293 NET_LIST_ENTRY
*First
;
295 ASSERT (Head
!= NULL
);
297 if (NetListIsEmpty (Head
)) {
301 First
= Head
->ForwardLink
;
302 Head
->ForwardLink
= First
->ForwardLink
;
303 First
->ForwardLink
->BackLink
= Head
;
306 First
->ForwardLink
= (LIST_ENTRY
*) NULL
;
307 First
->BackLink
= (LIST_ENTRY
*) NULL
;
315 Remove the last entry on the list
317 @param Head The list head
319 @return The entry that is removed from the list, NULL if the list is empty.
327 NET_LIST_ENTRY
*Last
;
329 ASSERT (Head
!= NULL
);
331 if (NetListIsEmpty (Head
)) {
335 Last
= Head
->BackLink
;
336 Head
->BackLink
= Last
->BackLink
;
337 Last
->BackLink
->ForwardLink
= Head
;
340 Last
->ForwardLink
= (LIST_ENTRY
*) NULL
;
341 Last
->BackLink
= (LIST_ENTRY
*) NULL
;
349 Insert the NewEntry after the PrevEntry
351 @param PrevEntry The previous entry to insert after
352 @param NewEntry The new entry to insert
359 IN NET_LIST_ENTRY
*PrevEntry
,
360 IN NET_LIST_ENTRY
*NewEntry
363 NewEntry
->BackLink
= PrevEntry
;
364 NewEntry
->ForwardLink
= PrevEntry
->ForwardLink
;
365 PrevEntry
->ForwardLink
->BackLink
= NewEntry
;
366 PrevEntry
->ForwardLink
= NewEntry
;
371 Insert the NewEntry before the PostEntry
373 @param PostEntry The entry to insert before
374 @param NewEntry The new entry to insert
380 NetListInsertBefore (
381 IN NET_LIST_ENTRY
*PostEntry
,
382 IN NET_LIST_ENTRY
*NewEntry
385 NewEntry
->ForwardLink
= PostEntry
;
386 NewEntry
->BackLink
= PostEntry
->BackLink
;
387 PostEntry
->BackLink
->ForwardLink
= NewEntry
;
388 PostEntry
->BackLink
= NewEntry
;
393 Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.
395 @param Map The netmap to initialize
405 ASSERT (Map
!= NULL
);
407 NetListInit (&Map
->Used
);
408 NetListInit (&Map
->Recycled
);
414 To clean up the netmap, that is, release allocated memories.
416 @param Map The netmap to clean up.
427 NET_LIST_ENTRY
*Entry
;
428 NET_LIST_ENTRY
*Next
;
430 ASSERT (Map
!= NULL
);
432 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Used
) {
433 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
435 NetListRemoveEntry (&Item
->Link
);
441 ASSERT ((Map
->Count
== 0) && NetListIsEmpty (&Map
->Used
));
443 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Recycled
) {
444 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
446 NetListRemoveEntry (&Item
->Link
);
450 ASSERT (NetListIsEmpty (&Map
->Recycled
));
455 Test whether the netmap is empty
457 @param Map The net map to test
459 @return TRUE if the netmap is empty, otherwise FALSE.
467 ASSERT (Map
!= NULL
);
468 return (BOOLEAN
) (Map
->Count
== 0);
473 Return the number of the <Key, Value> pairs in the netmap.
475 @param Map The netmap to get the entry number
477 @return The entry number in the netmap.
490 Allocate an item for the netmap. It will try to allocate
491 a batch of items and return one.
493 @param Map The netmap to allocate item for
495 @return The allocated item or NULL
505 NET_LIST_ENTRY
*Head
;
508 ASSERT (Map
!= NULL
);
510 Head
= &Map
->Recycled
;
512 if (NetListIsEmpty (Head
)) {
513 for (Index
= 0; Index
< NET_MAP_INCREAMENT
; Index
++) {
514 Item
= NetAllocatePool (sizeof (NET_MAP_ITEM
));
524 NetListInsertHead (Head
, &Item
->Link
);
528 Item
= NET_LIST_HEAD (Head
, NET_MAP_ITEM
, Link
);
529 NetListRemoveHead (Head
);
536 Allocate an item to save the <Key, Value> pair to the head of the netmap.
538 @param Map The netmap to insert into
539 @param Key The user's key
540 @param Value The user's value for the key
542 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
543 @retval EFI_SUCCESS The item is inserted to the head
550 IN VOID
*Value OPTIONAL
555 ASSERT (Map
!= NULL
);
557 Item
= NetMapAllocItem (Map
);
560 return EFI_OUT_OF_RESOURCES
;
565 NetListInsertHead (&Map
->Used
, &Item
->Link
);
573 Allocate an item to save the <Key, Value> pair to the tail of the netmap.
575 @param Map The netmap to insert into
576 @param Key The user's key
577 @param Value The user's value for the key
579 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
580 @retval EFI_SUCCESS The item is inserted to the tail
587 IN VOID
*Value OPTIONAL
592 ASSERT (Map
!= NULL
);
594 Item
= NetMapAllocItem (Map
);
597 return EFI_OUT_OF_RESOURCES
;
602 NetListInsertTail (&Map
->Used
, &Item
->Link
);
611 Check whther the item is in the Map
613 @param Map The netmap to search within
614 @param Item The item to search
616 @return TRUE if the item is in the netmap, otherwise FALSE.
623 IN NET_MAP_ITEM
*Item
626 NET_LIST_ENTRY
*ListEntry
;
628 NET_LIST_FOR_EACH (ListEntry
, &Map
->Used
) {
629 if (ListEntry
== &Item
->Link
) {
639 Find the key in the netmap
641 @param Map The netmap to search within
642 @param Key The key to search
644 @return The point to the item contains the Key, or NULL if Key isn't in the map.
653 NET_LIST_ENTRY
*Entry
;
656 ASSERT (Map
!= NULL
);
658 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
659 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
661 if (Item
->Key
== Key
) {
671 Remove the item from the netmap
673 @param Map The netmap to remove the item from
674 @param Item The item to remove
675 @param Value The variable to receive the value if not NULL
677 @return The key of the removed item.
683 IN NET_MAP_ITEM
*Item
,
684 OUT VOID
**Value OPTIONAL
687 ASSERT ((Map
!= NULL
) && (Item
!= NULL
));
688 ASSERT (NetItemInMap (Map
, Item
));
690 NetListRemoveEntry (&Item
->Link
);
692 NetListInsertHead (&Map
->Recycled
, &Item
->Link
);
695 *Value
= Item
->Value
;
703 Remove the first entry on the netmap
705 @param Map The netmap to remove the head from
706 @param Value The variable to receive the value if not NULL
708 @return The key of the item removed
714 OUT VOID
**Value OPTIONAL
720 // Often, it indicates a programming error to remove
721 // the first entry in an empty list
723 ASSERT (Map
&& !NetListIsEmpty (&Map
->Used
));
725 Item
= NET_LIST_HEAD (&Map
->Used
, NET_MAP_ITEM
, Link
);
726 NetListRemoveEntry (&Item
->Link
);
728 NetListInsertHead (&Map
->Recycled
, &Item
->Link
);
731 *Value
= Item
->Value
;
739 Remove the last entry on the netmap
741 @param Map The netmap to remove the tail from
742 @param Value The variable to receive the value if not NULL
744 @return The key of the item removed
750 OUT VOID
**Value OPTIONAL
756 // Often, it indicates a programming error to remove
757 // the last entry in an empty list
759 ASSERT (Map
&& !NetListIsEmpty (&Map
->Used
));
761 Item
= NET_LIST_TAIL (&Map
->Used
, NET_MAP_ITEM
, Link
);
762 NetListRemoveEntry (&Item
->Link
);
764 NetListInsertHead (&Map
->Recycled
, &Item
->Link
);
767 *Value
= Item
->Value
;
775 Iterate through the netmap and call CallBack for each item. It will
776 contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break
777 from the loop. It returns the CallBack's last return value. This
778 function is delete safe for the current item.
780 @param Map The Map to iterate through
781 @param CallBack The callback function to call for each item.
782 @param Arg The opaque parameter to the callback
784 @return It returns the CallBack's last return value.
790 IN NET_MAP_CALLBACK CallBack
,
795 NET_LIST_ENTRY
*Entry
;
796 NET_LIST_ENTRY
*Next
;
797 NET_LIST_ENTRY
*Head
;
801 ASSERT ((Map
!= NULL
) && (CallBack
!= NULL
));
805 if (NetListIsEmpty (Head
)) {
809 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, Head
) {
810 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
811 Result
= CallBack (Map
, Item
, Arg
);
813 if (EFI_ERROR (Result
)) {
823 This is the default unload handle for all the network drivers.
825 @param ImageHandle The drivers' driver image.
827 @retval EFI_SUCCESS The image is unloaded.
828 @retval Others Failed to unload the image.
833 NetLibDefaultUnload (
834 IN EFI_HANDLE ImageHandle
838 EFI_HANDLE
*DeviceHandleBuffer
;
839 UINTN DeviceHandleCount
;
841 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
842 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
843 EFI_DRIVER_CONFIGURATION_PROTOCOL
*DriverConfiguration
;
844 EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics
;
847 // Get the list of all the handles in the handle database.
848 // If there is an error getting the list, then the unload
851 Status
= gBS
->LocateHandleBuffer (
859 if (EFI_ERROR (Status
)) {
864 // Disconnect the driver specified by ImageHandle from all
865 // the devices in the handle database.
867 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
868 Status
= gBS
->DisconnectController (
869 DeviceHandleBuffer
[Index
],
876 // Uninstall all the protocols installed in the driver entry point
878 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
879 Status
= gBS
->HandleProtocol (
880 DeviceHandleBuffer
[Index
],
881 &gEfiDriverBindingProtocolGuid
,
882 (VOID
**) &DriverBinding
885 if (EFI_ERROR (Status
)) {
889 if (DriverBinding
->ImageHandle
!= ImageHandle
) {
893 gBS
->UninstallProtocolInterface (
895 &gEfiDriverBindingProtocolGuid
,
898 Status
= gBS
->HandleProtocol (
899 DeviceHandleBuffer
[Index
],
900 &gEfiComponentNameProtocolGuid
,
901 (VOID
**) &ComponentName
903 if (!EFI_ERROR (Status
)) {
904 gBS
->UninstallProtocolInterface (
906 &gEfiComponentNameProtocolGuid
,
911 Status
= gBS
->HandleProtocol (
912 DeviceHandleBuffer
[Index
],
913 &gEfiDriverConfigurationProtocolGuid
,
914 (VOID
**) &DriverConfiguration
917 if (!EFI_ERROR (Status
)) {
918 gBS
->UninstallProtocolInterface (
920 &gEfiDriverConfigurationProtocolGuid
,
925 Status
= gBS
->HandleProtocol (
926 DeviceHandleBuffer
[Index
],
927 &gEfiDriverDiagnosticsProtocolGuid
,
928 (VOID
**) &DriverDiagnostics
931 if (!EFI_ERROR (Status
)) {
932 gBS
->UninstallProtocolInterface (
934 &gEfiDriverDiagnosticsProtocolGuid
,
941 // Free the buffer containing the list of handles from the handle database
943 if (DeviceHandleBuffer
!= NULL
) {
944 gBS
->FreePool (DeviceHandleBuffer
);
953 Create a child of the service that is identified by ServiceBindingGuid.
955 @param Controller The controller which has the service installed.
956 @param Image The image handle used to open service.
957 @param ServiceBindingGuid The service's Guid.
958 @param ChildHandle The handle to receive the create child
960 @retval EFI_SUCCESS The child is successfully created.
961 @retval Others Failed to create the child.
965 NetLibCreateServiceChild (
966 IN EFI_HANDLE Controller
,
968 IN EFI_GUID
*ServiceBindingGuid
,
969 OUT EFI_HANDLE
*ChildHandle
973 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
976 ASSERT ((ServiceBindingGuid
!= NULL
) && (ChildHandle
!= NULL
));
979 // Get the ServiceBinding Protocol
981 Status
= gBS
->OpenProtocol (
987 EFI_OPEN_PROTOCOL_GET_PROTOCOL
990 if (EFI_ERROR (Status
)) {
997 Status
= Service
->CreateChild (Service
, ChildHandle
);
1003 Destory a child of the service that is identified by ServiceBindingGuid.
1005 @param Controller The controller which has the service installed.
1006 @param Image The image handle used to open service.
1007 @param ServiceBindingGuid The service's Guid.
1008 @param ChildHandle The child to destory
1010 @retval EFI_SUCCESS The child is successfully destoried.
1011 @retval Others Failed to destory the child.
1015 NetLibDestroyServiceChild (
1016 IN EFI_HANDLE Controller
,
1017 IN EFI_HANDLE Image
,
1018 IN EFI_GUID
*ServiceBindingGuid
,
1019 IN EFI_HANDLE ChildHandle
1023 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
1025 ASSERT (ServiceBindingGuid
!= NULL
);
1028 // Get the ServiceBinding Protocol
1030 Status
= gBS
->OpenProtocol (
1036 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1039 if (EFI_ERROR (Status
)) {
1044 // destory the child
1046 Status
= Service
->DestroyChild (Service
, ChildHandle
);
1052 Convert the mac address of the simple network protocol installed on
1053 SnpHandle to a unicode string. Callers are responsible for freeing the
1056 @param SnpHandle The handle where the simple network protocol is
1058 @param ImageHandle The image handle used to act as the agent handle to
1059 get the simple network protocol.
1060 @param MacString The pointer to store the address of the string
1061 representation of the mac address.
1063 @retval EFI_OUT_OF_RESOURCES There are not enough memory resource.
1064 @retval other Failed to open the simple network protocol.
1068 NetLibGetMacString (
1069 IN EFI_HANDLE SnpHandle
,
1070 IN EFI_HANDLE ImageHandle
,
1071 IN OUT CHAR16
**MacString
1075 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
1076 EFI_SIMPLE_NETWORK_MODE
*Mode
;
1083 // Get the Simple Network protocol from the SnpHandle.
1085 Status
= gBS
->OpenProtocol (
1087 &gEfiSimpleNetworkProtocolGuid
,
1091 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1093 if (EFI_ERROR (Status
)) {
1100 // It takes 2 unicode characters to represent a 1 byte binary buffer.
1101 // Plus one unicode character for the null-terminator.
1103 MacAddress
= NetAllocatePool ((2 * Mode
->HwAddressSize
+ 1) * sizeof (CHAR16
));
1104 if (MacAddress
== NULL
) {
1105 return EFI_OUT_OF_RESOURCES
;
1109 // Convert the mac address into a unicode string.
1111 for (Index
= 0; Index
< Mode
->HwAddressSize
; Index
++) {
1112 MacAddress
[Index
* 2] = NibbleToHexChar ((UINT8
) (Mode
->CurrentAddress
.Addr
[Index
] >> 4));
1113 MacAddress
[Index
* 2 + 1] = NibbleToHexChar (Mode
->CurrentAddress
.Addr
[Index
]);
1116 MacAddress
[Mode
->HwAddressSize
* 2] = L
'\0';
1118 *MacString
= MacAddress
;
1124 Check the default address used by the IPv4 driver is static or dynamic (acquired
1127 @param Controller The controller handle which has the NIC Ip4 Config Protocol
1128 relative with the default address to judge.
1130 @retval TRUE If the default address is static.
1131 @retval FALSE If the default address is acquired from DHCP.
1136 NetLibDefaultAddressIsStatic (
1137 IN EFI_HANDLE Controller
1141 EFI_NIC_IP4_CONFIG_PROTOCOL
*NicIp4
;
1143 NIC_IP4_CONFIG_INFO
*ConfigInfo
;
1146 Status
= gBS
->HandleProtocol (
1148 &gEfiNicIp4ConfigProtocolGuid
,
1151 if (EFI_ERROR (Status
)) {
1156 Status
= NicIp4
->GetInfo (NicIp4
, &Len
, NULL
);
1157 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1161 ConfigInfo
= NetAllocatePool (Len
);
1162 if (ConfigInfo
== NULL
) {
1167 Status
= NicIp4
->GetInfo (NicIp4
, &Len
, ConfigInfo
);
1168 if (EFI_ERROR (Status
)) {
1172 IsStatic
= (BOOLEAN
) (ConfigInfo
->Source
== IP4_CONFIG_SOURCE_STATIC
);
1176 NetFreePool (ConfigInfo
);
1182 Create an IPv4 device path node.
1184 @param Node Pointer to the IPv4 device path node.
1185 @param Controller The handle where the NIC IP4 config protocol resides.
1186 @param LocalIp The local IPv4 address.
1187 @param LocalPort The local port.
1188 @param RemoteIp The remote IPv4 address.
1189 @param RemotePort The remote port.
1190 @param Protocol The protocol type in the IP header.
1191 @param UseDefaultAddress Whether this instance is using default address or not.
1196 NetLibCreateIPv4DPathNode (
1197 IN OUT IPv4_DEVICE_PATH
*Node
,
1198 IN EFI_HANDLE Controller
,
1199 IN IP4_ADDR LocalIp
,
1200 IN UINT16 LocalPort
,
1201 IN IP4_ADDR RemoteIp
,
1202 IN UINT16 RemotePort
,
1204 IN BOOLEAN UseDefaultAddress
1207 Node
->Header
.Type
= MESSAGING_DEVICE_PATH
;
1208 Node
->Header
.SubType
= MSG_IPv4_DP
;
1209 SetDevicePathNodeLength (&Node
->Header
, 19);
1211 NetCopyMem (&Node
->LocalIpAddress
, &LocalIp
, sizeof (EFI_IPv4_ADDRESS
));
1212 NetCopyMem (&Node
->RemoteIpAddress
, &RemoteIp
, sizeof (EFI_IPv4_ADDRESS
));
1214 Node
->LocalPort
= LocalPort
;
1215 Node
->RemotePort
= RemotePort
;
1217 Node
->Protocol
= Protocol
;
1219 if (!UseDefaultAddress
) {
1220 Node
->StaticIpAddress
= TRUE
;
1222 Node
->StaticIpAddress
= NetLibDefaultAddressIsStatic (Controller
);
1228 Find the UNDI/SNP handle from controller and protocol GUID.
1229 For example, IP will open a MNP child to transmit/receive
1230 packets, when MNP is stopped, IP should also be stopped. IP
1231 needs to find its own private data which is related the IP's
1232 service binding instance that is install on UNDI/SNP handle.
1233 Now, the controller is either a MNP or ARP child handle. But
1234 IP opens these handle BY_DRIVER, use that info, we can get the
1237 @param Controller Then protocol handle to check
1238 @param ProtocolGuid The protocol that is related with the handle.
1240 @return The UNDI/SNP handle or NULL.
1244 NetLibGetNicHandle (
1245 IN EFI_HANDLE Controller
,
1246 IN EFI_GUID
*ProtocolGuid
1249 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenBuffer
;
1255 Status
= gBS
->OpenProtocolInformation (
1262 if (EFI_ERROR (Status
)) {
1268 for (Index
= 0; Index
< OpenCount
; Index
++) {
1269 if (OpenBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) {
1270 Handle
= OpenBuffer
[Index
].ControllerHandle
;
1275 gBS
->FreePool (OpenBuffer
);
1280 NetLibInstallAllDriverProtocols (
1281 IN EFI_HANDLE ImageHandle
,
1282 IN EFI_SYSTEM_TABLE
*SystemTable
,
1283 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
1284 IN EFI_HANDLE DriverBindingHandle
,
1285 IN EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
, OPTIONAL
1286 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*DriverConfiguration
, OPTIONAL
1287 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics OPTIONAL
1291 Routine Description:
1293 Intialize a driver by installing the Driver Binding Protocol onto the
1294 driver's DriverBindingHandle. This is typically the same as the driver's
1295 ImageHandle, but it can be different if the driver produces multiple
1296 DriverBinding Protocols. This function also initializes the EFI Driver
1297 Library that initializes the global variables gST, gBS, gRT.
1301 ImageHandle - The image handle of the driver
1302 SystemTable - The EFI System Table that was passed to the driver's
1304 DriverBinding - A Driver Binding Protocol instance that this driver
1306 DriverBindingHandle - The handle that DriverBinding is to be installe onto.
1307 If this parameter is NULL, then a new handle is created.
1308 ComponentName - A Component Name Protocol instance that this driver is
1310 DriverConfiguration - A Driver Configuration Protocol instance that this
1311 driver is producing.
1312 DriverDiagnostics - A Driver Diagnostics Protocol instance that this
1313 driver is producing.
1317 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
1318 Otherwise, then return status from gBS->InstallProtocolInterface()
1322 return NetLibInstallAllDriverProtocolsWithUnload (
1326 DriverBindingHandle
,
1328 DriverConfiguration
,
1335 NetLibInstallAllDriverProtocolsWithUnload (
1336 IN EFI_HANDLE ImageHandle
,
1337 IN EFI_SYSTEM_TABLE
*SystemTable
,
1338 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
1339 IN EFI_HANDLE DriverBindingHandle
,
1340 IN EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
, OPTIONAL
1341 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*DriverConfiguration
, OPTIONAL
1342 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics
, OPTIONAL
1343 IN NET_LIB_DRIVER_UNLOAD Unload
1347 Routine Description:
1349 Intialize a driver by installing the Driver Binding Protocol onto the
1350 driver's DriverBindingHandle. This is typically the same as the driver's
1351 ImageHandle, but it can be different if the driver produces multiple
1352 DriverBinding Protocols. This function also initializes the EFI Driver
1353 Library that initializes the global variables gST, gBS, gRT.
1357 ImageHandle - The image handle of the driver
1358 SystemTable - The EFI System Table that was passed to the driver's
1360 DriverBinding - A Driver Binding Protocol instance that this driver
1362 DriverBindingHandle - The handle that DriverBinding is to be installe onto.
1363 If this parameter is NULL, then a new handle is created.
1364 ComponentName - A Component Name Protocol instance that this driver is
1366 DriverConfiguration - A Driver Configuration Protocol instance that this
1367 driver is producing.
1368 DriverDiagnostics - A Driver Diagnostics Protocol instance that this
1369 driver is producing.
1370 Unload - The customized unload to install.
1374 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
1375 Otherwise, then return status from gBS->InstallProtocolInterface()
1380 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
1382 Status
= EfiLibInstallAllDriverProtocols (
1386 DriverBindingHandle
,
1388 DriverConfiguration
,
1392 if (EFI_ERROR (Status
)) {
1397 // Retrieve the Loaded Image Protocol from Image Handle
1399 Status
= gBS
->OpenProtocol (
1401 &gEfiLoadedImageProtocolGuid
,
1402 (VOID
**) &LoadedImage
,
1405 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1408 if (EFI_ERROR (Status
)) {
1413 // Fill in the Unload() service of the Loaded Image Protocol
1415 LoadedImage
->Unload
= (Unload
== NULL
) ? NetLibDefaultUnload
: Unload
;