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
= {
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
= {
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
= {
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
= {
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
= {
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
= {
67 0xaa4af677, 0x6efe, 0x477c, { 0x96, 0x68, 0xe8, 0x13, 0x9d, 0x2, 0xfd, 0x9b }
72 Connect to the EFI socket library
74 This routine creates the ::ESL_SOCKET structure and returns
75 the API (::EFI_SOCKET_PROTOCOL address) to the socket file
76 system layer in BsdSocketLib.
78 This routine is called from the ::socket routine in BsdSocketLib
79 to create the data structure and initialize the API for a socket.
80 Note that this implementation is only used by socket applications
81 that link directly to EslSocketLib.
83 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
86 @return Value for ::errno, zero (0) indicates success.
90 EslServiceGetProtocol (
91 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
94 EFI_HANDLE ChildHandle
;
107 // Locate the socket protocol
110 Status
= EslSocketAllocate ( &ChildHandle
,
113 if ( !EFI_ERROR ( Status
)) {
114 *ppSocketProtocol
= &pSocket
->SocketProtocol
;
124 // Return the operation status
126 DBG_EXIT_DEC ( RetVal
);
132 Connect to the network layer
134 This routine is the constructor for the EfiSocketLib when the
135 library is linked directly to an application. This routine
136 walks the ::cEslSocketBinding table to create ::ESL_SERVICE
137 structures, associated with the network adapters, which this
138 routine links to the ::ESL_LAYER structure.
140 This routine is called from ::EslConstructor as a result of the
141 constructor redirection in ::mpfnEslConstructor at the end of this
144 @retval EFI_SUCCESS Successfully connected to the network layer
148 EslServiceNetworkConnect (
152 BOOLEAN bSomethingFound
;
155 CONST ESL_SOCKET_BINDING
* pEnd
;
156 EFI_HANDLE
* pHandles
;
157 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
163 // Initialize the socket layer
165 Status
= EFI_SUCCESS
;
166 bSomethingFound
= FALSE
;
167 EslServiceLoad ( gImageHandle
);
170 // Connect the network devices
172 pSocketBinding
= &cEslSocketBinding
[0];
173 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
174 while ( pEnd
> pSocketBinding
) {
176 // Attempt to locate the network adapters
180 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
181 pSocketBinding
->pNetworkBinding
,
185 if ( EFI_ERROR ( Status
)) {
186 DEBUG (( DEBUG_ERROR
,
187 "ERROR with %s layer, Status: %r\r\n",
188 pSocketBinding
->pName
,
192 if ( NULL
!= pHandles
) {
194 // Attempt to connect to this network adapter
196 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
197 Status
= EslServiceConnect ( gImageHandle
,
199 if ( EFI_ERROR ( Status
)) {
202 bSomethingFound
= TRUE
;
206 // Done with the handles
208 gBS
->FreePool ( pHandles
);
213 // Set the next network protocol
219 // Return the network connection status
221 if ( bSomethingFound
) {
222 Status
= EFI_SUCCESS
;
224 DBG_EXIT_STATUS ( Status
);
230 Disconnect from the network layer
232 Destructor for the EfiSocketLib when the library is linked
233 directly to an application. This routine walks the
234 ::cEslSocketBinding table to remove the ::ESL_SERVICE
235 structures (network connections) from the ::ESL_LAYER structure.
237 This routine is called from ::EslDestructor as a result of the
238 destructor redirection in ::mpfnEslDestructor at the end of this
241 @retval EFI_SUCCESS Successfully disconnected from the network layer
245 EslServiceNetworkDisconnect (
251 CONST ESL_SOCKET_BINDING
* pEnd
;
252 EFI_HANDLE
* pHandles
;
253 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
261 Status
= EFI_SUCCESS
;
264 // Disconnect the network devices
266 pSocketBinding
= &cEslSocketBinding
[0];
267 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
268 while ( pEnd
> pSocketBinding
) {
270 // Attempt to locate the network adapters
274 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
275 pSocketBinding
->pNetworkBinding
,
279 if (( !EFI_ERROR ( Status
))
280 && ( NULL
!= pHandles
)) {
282 // Attempt to disconnect from this network adapter
284 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
285 Status
= EslServiceDisconnect ( gImageHandle
,
287 if ( EFI_ERROR ( Status
)) {
293 // Done with the handles
295 gBS
->FreePool ( pHandles
);
299 // Set the next network protocol
302 Status
= EFI_SUCCESS
;
306 // Finish the disconnect operation
308 if ( !EFI_ERROR ( Status
)) {
309 EslServiceUnload ( );
313 // Return the network connection status
315 DBG_EXIT_STATUS ( Status
);
321 Socket layer's service binding protocol delcaration.
323 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
= {
330 The following entries redirect the constructor and destructor
331 for any socket application that links against the EfiSocketLib.
332 Note that the SocketDxe driver uses different redirection.
334 PFN_ESL_xSTRUCTOR mpfnEslConstructor
= EslServiceNetworkConnect
; ///< Constructor for EfiSocketLib
335 PFN_ESL_xSTRUCTOR mpfnEslDestructor
= EslServiceNetworkDisconnect
; ///< Destructor for EfiSocketLib