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 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
)) {
200 bSomethingFound
= TRUE
;
203 if ( EFI_OUT_OF_RESOURCES
== Status
) {
205 // Pointless to continue without memory
213 // Done with the handles
215 gBS
->FreePool ( pHandles
);
220 // Set the next network protocol
226 // Return the network connection status
228 if ( bSomethingFound
) {
229 Status
= EFI_SUCCESS
;
231 DBG_EXIT_STATUS ( Status
);
237 Disconnect from the network layer
239 Destructor for the EfiSocketLib when the library is linked
240 directly to an application. This routine walks the
241 ::cEslSocketBinding table to remove the ::ESL_SERVICE
242 structures (network connections) from the ::ESL_LAYER structure.
244 This routine is called from ::EslDestructor as a result of the
245 destructor redirection in ::mpfnEslDestructor at the end of this
248 @retval EFI_SUCCESS Successfully disconnected from the network layer
252 EslServiceNetworkDisconnect (
258 CONST ESL_SOCKET_BINDING
* pEnd
;
259 EFI_HANDLE
* pHandles
;
260 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
268 Status
= EFI_SUCCESS
;
271 // Disconnect the network devices
273 pSocketBinding
= &cEslSocketBinding
[0];
274 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
275 while ( pEnd
> pSocketBinding
) {
277 // Attempt to locate the network adapters
281 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
282 pSocketBinding
->pNetworkBinding
,
286 if (( !EFI_ERROR ( Status
))
287 && ( NULL
!= pHandles
)) {
289 // Attempt to disconnect from this network adapter
291 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
292 Status
= EslServiceDisconnect ( gImageHandle
,
294 if ( EFI_ERROR ( Status
)) {
300 // Done with the handles
302 gBS
->FreePool ( pHandles
);
306 // Set the next network protocol
309 Status
= EFI_SUCCESS
;
313 // Finish the disconnect operation
315 if ( !EFI_ERROR ( Status
)) {
316 EslServiceUnload ( );
320 // Return the network connection status
322 DBG_EXIT_STATUS ( Status
);
328 Socket layer's service binding protocol delcaration.
330 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
__attribute__((weak
)) = {
337 The following entries redirect the constructor and destructor
338 for any socket application that links against the EfiSocketLib.
339 Note that the SocketDxe driver uses different redirection.
341 PFN_ESL_xSTRUCTOR mpfnEslConstructor
__attribute__((weak
)) = EslServiceNetworkConnect
; ///< Constructor for EfiSocketLib
342 PFN_ESL_xSTRUCTOR mpfnEslDestructor
__attribute__((weak
)) = EslServiceNetworkDisconnect
; ///< Destructor for EfiSocketLib