2 Implement the connection to the EFI socket library
4 Copyright (c) 2011, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 The following GUID values are only used when an application links
14 against EfiSocketLib. An alternative set of values exists in
15 SocketDxe\EntryUnload.c which the SocketDxe driver uses to coexist
16 with socket applications.
18 Tag GUID - IPv4 in use by an application using EfiSocketLib
20 CONST EFI_GUID mEslIp4ServiceGuid
__attribute__((weak
)) = {
21 0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }
26 Tag GUID - IPv6 in use by an application using EfiSocketLib
28 CONST EFI_GUID mEslIp6ServiceGuid
__attribute__((weak
)) = {
29 0xc51b2761, 0xc476, 0x45fe, { 0xbe, 0x61, 0xba, 0x4b, 0xcc, 0x32, 0xf2, 0x34 }
34 Tag GUID - TCPv4 in use by an application using EfiSocketLib
36 CONST EFI_GUID mEslTcp4ServiceGuid
__attribute__((weak
)) = {
37 0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
42 Tag GUID - TCPv6 in use by an application using EfiSocketLib
44 CONST EFI_GUID mEslTcp6ServiceGuid
__attribute__((weak
)) = {
45 0x279858a4, 0x4e9e, 0x4e53, { 0x93, 0x22, 0xf2, 0x54, 0xe0, 0x7e, 0xef, 0xd4 }
50 Tag GUID - UDPv4 in use by an application using EfiSocketLib
52 CONST EFI_GUID mEslUdp4ServiceGuid
__attribute__((weak
)) = {
53 0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
58 Tag GUID - UDPv6 in use by an application using EfiSocketLib
60 CONST EFI_GUID mEslUdp6ServiceGuid
__attribute__((weak
)) = {
61 0xaa4af677, 0x6efe, 0x477c, { 0x96, 0x68, 0xe8, 0x13, 0x9d, 0x2, 0xfd, 0x9b }
66 Free the socket resources
68 This releases the socket resources allocated by calling
69 EslServiceGetProtocol.
71 This routine is called from the ::close routine in BsdSocketLib
72 to release the socket resources.
74 @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL
77 @return Value for ::errno, zero (0) indicates success.
81 EslServiceFreeProtocol (
82 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
88 // Release the socket resources
90 EslSocketFree ( pSocketProtocol
, &RetVal
);
93 // Return the operation status
100 Connect to the EFI socket library
102 This routine creates the ::ESL_SOCKET structure and returns
103 the API (::EFI_SOCKET_PROTOCOL address) to the socket file
104 system layer in BsdSocketLib.
106 This routine is called from the ::socket routine in BsdSocketLib
107 to create the data structure and initialize the API for a socket.
108 Note that this implementation is only used by socket applications
109 that link directly to EslSocketLib.
111 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
114 @return Value for ::errno, zero (0) indicates success.
118 EslServiceGetProtocol (
119 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
122 EFI_HANDLE ChildHandle
;
123 ESL_SOCKET
* pSocket
;
135 // Locate the socket protocol
138 Status
= EslSocketAllocate ( &ChildHandle
,
141 if ( !EFI_ERROR ( Status
)) {
142 *ppSocketProtocol
= &pSocket
->SocketProtocol
;
152 // Return the operation status
154 DBG_EXIT_DEC ( RetVal
);
160 Connect to the network layer
162 This routine is the constructor for the EfiSocketLib when the
163 library is linked directly to an application. This routine
164 walks the ::cEslSocketBinding table to create ::ESL_SERVICE
165 structures, associated with the network adapters, which this
166 routine links to the ::ESL_LAYER structure.
168 This routine is called from ::EslConstructor as a result of the
169 constructor redirection in ::mpfnEslConstructor at the end of this
172 @retval EFI_SUCCESS Successfully connected to the network layer
176 EslServiceNetworkConnect (
180 BOOLEAN bSomethingFound
;
183 CONST ESL_SOCKET_BINDING
* pEnd
;
184 EFI_HANDLE
* pHandles
;
185 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
191 // Initialize the socket layer
193 Status
= EFI_SUCCESS
;
194 bSomethingFound
= FALSE
;
195 EslServiceLoad ( gImageHandle
);
198 // Connect the network devices
200 pSocketBinding
= &cEslSocketBinding
[0];
201 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
202 while ( pEnd
> pSocketBinding
) {
204 // Attempt to locate the network adapters
208 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
209 pSocketBinding
->pNetworkBinding
,
213 if ( EFI_ERROR ( Status
)) {
214 DEBUG (( DEBUG_ERROR
,
215 "ERROR with %s layer, Status: %r\r\n",
216 pSocketBinding
->pName
,
220 if ( NULL
!= pHandles
) {
222 // Attempt to connect to this network adapter
224 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
225 Status
= EslServiceConnect ( gImageHandle
,
227 if ( !EFI_ERROR ( Status
)) {
228 bSomethingFound
= TRUE
;
231 if ( EFI_OUT_OF_RESOURCES
== Status
) {
233 // Pointless to continue without memory
241 // Done with the handles
243 gBS
->FreePool ( pHandles
);
248 // Set the next network protocol
254 // Return the network connection status
256 if ( bSomethingFound
) {
257 Status
= EFI_SUCCESS
;
259 DBG_EXIT_STATUS ( Status
);
265 Disconnect from the network layer
267 Destructor for the EfiSocketLib when the library is linked
268 directly to an application. This routine walks the
269 ::cEslSocketBinding table to remove the ::ESL_SERVICE
270 structures (network connections) from the ::ESL_LAYER structure.
272 This routine is called from ::EslDestructor as a result of the
273 destructor redirection in ::mpfnEslDestructor at the end of this
276 @retval EFI_SUCCESS Successfully disconnected from the network layer
280 EslServiceNetworkDisconnect (
286 CONST ESL_SOCKET_BINDING
* pEnd
;
287 EFI_HANDLE
* pHandles
;
288 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
296 Status
= EFI_SUCCESS
;
299 // Disconnect the network devices
301 pSocketBinding
= &cEslSocketBinding
[0];
302 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
303 while ( pEnd
> pSocketBinding
) {
305 // Attempt to locate the network adapters
309 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
310 pSocketBinding
->pNetworkBinding
,
314 if (( !EFI_ERROR ( Status
))
315 && ( NULL
!= pHandles
)) {
317 // Attempt to disconnect from this network adapter
319 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
320 Status
= EslServiceDisconnect ( gImageHandle
,
322 if ( EFI_ERROR ( Status
)) {
328 // Done with the handles
330 gBS
->FreePool ( pHandles
);
334 // Set the next network protocol
337 Status
= EFI_SUCCESS
;
341 // Finish the disconnect operation
343 if ( !EFI_ERROR ( Status
)) {
344 EslServiceUnload ( );
348 // Return the network connection status
350 DBG_EXIT_STATUS ( Status
);
356 Socket layer's service binding protocol delcaration.
358 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
__attribute__((weak
)) = {
365 The following entries redirect the constructor and destructor
366 for any socket application that links against the EfiSocketLib.
367 Note that the SocketDxe driver uses different redirection.
369 PFN_ESL_xSTRUCTOR mpfnEslConstructor
__attribute__((weak
)) = EslServiceNetworkConnect
; ///< Constructor for EfiSocketLib
370 PFN_ESL_xSTRUCTOR mpfnEslDestructor
__attribute__((weak
)) = EslServiceNetworkDisconnect
; ///< Destructor for EfiSocketLib