2 Implement the connection to the EFI socket library
4 Copyright (c) 2011, Intel Corporation
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.
19 The following GUID values are only used when an application links
20 against EfiSocketLib. An alternative set of values exists in
21 SocketDxe\EntryUnload.c which the SocketDxe driver uses to coexist
22 with socket applications.
24 Tag GUID - IPv4 in use by an application using EfiSocketLib
26 CONST EFI_GUID mEslIp4ServiceGuid
__attribute__((weak
)) = {
27 0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }
32 Tag GUID - IPv6 in use by an application using EfiSocketLib
34 CONST EFI_GUID mEslIp6ServiceGuid
__attribute__((weak
)) = {
35 0xc51b2761, 0xc476, 0x45fe, { 0xbe, 0x61, 0xba, 0x4b, 0xcc, 0x32, 0xf2, 0x34 }
40 Tag GUID - TCPv4 in use by an application using EfiSocketLib
42 CONST EFI_GUID mEslTcp4ServiceGuid
__attribute__((weak
)) = {
43 0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
48 Tag GUID - TCPv6 in use by an application using EfiSocketLib
50 CONST EFI_GUID mEslTcp6ServiceGuid
__attribute__((weak
)) = {
51 0x279858a4, 0x4e9e, 0x4e53, { 0x93, 0x22, 0xf2, 0x54, 0xe0, 0x7e, 0xef, 0xd4 }
56 Tag GUID - UDPv4 in use by an application using EfiSocketLib
58 CONST EFI_GUID mEslUdp4ServiceGuid
__attribute__((weak
)) = {
59 0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
64 Tag GUID - UDPv6 in use by an application using EfiSocketLib
66 CONST EFI_GUID mEslUdp6ServiceGuid
__attribute__((weak
)) = {
67 0xaa4af677, 0x6efe, 0x477c, { 0x96, 0x68, 0xe8, 0x13, 0x9d, 0x2, 0xfd, 0x9b }
72 Free the socket resources
74 This releases the socket resources allocated by calling
75 EslServiceGetProtocol.
77 This routine is called from the ::close routine in BsdSocketLib
78 to release the socket resources.
80 @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL
83 @return Value for ::errno, zero (0) indicates success.
87 EslServiceFreeProtocol (
88 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
94 // Release the socket resources
96 EslSocketFree ( pSocketProtocol
, &RetVal
);
99 // Return the operation status
106 Connect to the EFI socket library
108 This routine creates the ::ESL_SOCKET structure and returns
109 the API (::EFI_SOCKET_PROTOCOL address) to the socket file
110 system layer in BsdSocketLib.
112 This routine is called from the ::socket routine in BsdSocketLib
113 to create the data structure and initialize the API for a socket.
114 Note that this implementation is only used by socket applications
115 that link directly to EslSocketLib.
117 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
120 @return Value for ::errno, zero (0) indicates success.
124 EslServiceGetProtocol (
125 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
128 EFI_HANDLE ChildHandle
;
129 ESL_SOCKET
* pSocket
;
141 // Locate the socket protocol
144 Status
= EslSocketAllocate ( &ChildHandle
,
147 if ( !EFI_ERROR ( Status
)) {
148 *ppSocketProtocol
= &pSocket
->SocketProtocol
;
158 // Return the operation status
160 DBG_EXIT_DEC ( RetVal
);
166 Connect to the network layer
168 This routine is the constructor for the EfiSocketLib when the
169 library is linked directly to an application. This routine
170 walks the ::cEslSocketBinding table to create ::ESL_SERVICE
171 structures, associated with the network adapters, which this
172 routine links to the ::ESL_LAYER structure.
174 This routine is called from ::EslConstructor as a result of the
175 constructor redirection in ::mpfnEslConstructor at the end of this
178 @retval EFI_SUCCESS Successfully connected to the network layer
182 EslServiceNetworkConnect (
186 BOOLEAN bSomethingFound
;
189 CONST ESL_SOCKET_BINDING
* pEnd
;
190 EFI_HANDLE
* pHandles
;
191 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
197 // Initialize the socket layer
199 Status
= EFI_SUCCESS
;
200 bSomethingFound
= FALSE
;
201 EslServiceLoad ( gImageHandle
);
204 // Connect the network devices
206 pSocketBinding
= &cEslSocketBinding
[0];
207 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
208 while ( pEnd
> pSocketBinding
) {
210 // Attempt to locate the network adapters
214 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
215 pSocketBinding
->pNetworkBinding
,
219 if ( EFI_ERROR ( Status
)) {
220 DEBUG (( DEBUG_ERROR
,
221 "ERROR with %s layer, Status: %r\r\n",
222 pSocketBinding
->pName
,
226 if ( NULL
!= pHandles
) {
228 // Attempt to connect to this network adapter
230 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
231 Status
= EslServiceConnect ( gImageHandle
,
233 if ( !EFI_ERROR ( Status
)) {
234 bSomethingFound
= TRUE
;
237 if ( EFI_OUT_OF_RESOURCES
== Status
) {
239 // Pointless to continue without memory
247 // Done with the handles
249 gBS
->FreePool ( pHandles
);
254 // Set the next network protocol
260 // Return the network connection status
262 if ( bSomethingFound
) {
263 Status
= EFI_SUCCESS
;
265 DBG_EXIT_STATUS ( Status
);
271 Disconnect from the network layer
273 Destructor for the EfiSocketLib when the library is linked
274 directly to an application. This routine walks the
275 ::cEslSocketBinding table to remove the ::ESL_SERVICE
276 structures (network connections) from the ::ESL_LAYER structure.
278 This routine is called from ::EslDestructor as a result of the
279 destructor redirection in ::mpfnEslDestructor at the end of this
282 @retval EFI_SUCCESS Successfully disconnected from the network layer
286 EslServiceNetworkDisconnect (
292 CONST ESL_SOCKET_BINDING
* pEnd
;
293 EFI_HANDLE
* pHandles
;
294 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
302 Status
= EFI_SUCCESS
;
305 // Disconnect the network devices
307 pSocketBinding
= &cEslSocketBinding
[0];
308 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
309 while ( pEnd
> pSocketBinding
) {
311 // Attempt to locate the network adapters
315 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
316 pSocketBinding
->pNetworkBinding
,
320 if (( !EFI_ERROR ( Status
))
321 && ( NULL
!= pHandles
)) {
323 // Attempt to disconnect from this network adapter
325 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
326 Status
= EslServiceDisconnect ( gImageHandle
,
328 if ( EFI_ERROR ( Status
)) {
334 // Done with the handles
336 gBS
->FreePool ( pHandles
);
340 // Set the next network protocol
343 Status
= EFI_SUCCESS
;
347 // Finish the disconnect operation
349 if ( !EFI_ERROR ( Status
)) {
350 EslServiceUnload ( );
354 // Return the network connection status
356 DBG_EXIT_STATUS ( Status
);
362 Socket layer's service binding protocol delcaration.
364 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
__attribute__((weak
)) = {
371 The following entries redirect the constructor and destructor
372 for any socket application that links against the EfiSocketLib.
373 Note that the SocketDxe driver uses different redirection.
375 PFN_ESL_xSTRUCTOR mpfnEslConstructor
__attribute__((weak
)) = EslServiceNetworkConnect
; ///< Constructor for EfiSocketLib
376 PFN_ESL_xSTRUCTOR mpfnEslDestructor
__attribute__((weak
)) = EslServiceNetworkDisconnect
; ///< Destructor for EfiSocketLib