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 - TCPv4 in use by an application using EfiSocketLib
34 CONST EFI_GUID mEslTcp4ServiceGuid
= {
35 0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
40 Tag GUID - UDPv4 in use by an application using EfiSocketLib
42 CONST EFI_GUID mEslUdp4ServiceGuid
= {
43 0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
48 Connect to the EFI socket library
50 This routine creates the ::ESL_SOCKET structure and returns
51 the API (::EFI_SOCKET_PROTOCOL address) to the socket file
52 system layer in BsdSocketLib.
54 This routine is called from the ::socket routine in BsdSocketLib
55 to create the data structure and initialize the API for a socket.
56 Note that this implementation is only used by socket applications
57 that link directly to EslSocketLib.
59 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
62 @return Value for ::errno, zero (0) indicates success.
66 EslServiceGetProtocol (
67 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
70 EFI_HANDLE ChildHandle
;
83 // Locate the socket protocol
86 Status
= EslSocketAllocate ( &ChildHandle
,
89 if ( !EFI_ERROR ( Status
)) {
90 *ppSocketProtocol
= &pSocket
->SocketProtocol
;
100 // Return the operation status
102 DBG_EXIT_DEC ( RetVal
);
108 Connect to the network layer
110 This routine is the constructor for the EfiSocketLib when the
111 library is linked directly to an application. This routine
112 walks the ::cEslSocketBinding table to create ::ESL_SERVICE
113 structures, associated with the network adapters, which this
114 routine links to the ::ESL_LAYER structure.
116 This routine is called from ::EslConstructor as a result of the
117 constructor redirection in ::mpfnEslConstructor at the end of this
120 @retval EFI_SUCCESS Successfully connected to the network layer
124 EslServiceNetworkConnect (
128 BOOLEAN bSomethingFound
;
131 CONST ESL_SOCKET_BINDING
* pEnd
;
132 EFI_HANDLE
* pHandles
;
133 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
139 // Initialize the socket layer
141 Status
= EFI_SUCCESS
;
142 bSomethingFound
= FALSE
;
143 EslServiceLoad ( gImageHandle
);
146 // Connect the network devices
148 pSocketBinding
= &cEslSocketBinding
[0];
149 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
150 while ( pEnd
> pSocketBinding
) {
152 // Attempt to locate the network adapters
156 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
157 pSocketBinding
->pNetworkBinding
,
161 if ( EFI_ERROR ( Status
)) {
162 DEBUG (( DEBUG_ERROR
,
163 "ERROR with %s layer, Status: %r\r\n",
164 pSocketBinding
->pName
,
168 if ( NULL
!= pHandles
) {
170 // Attempt to connect to this network adapter
172 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
173 Status
= EslServiceConnect ( gImageHandle
,
175 if ( EFI_ERROR ( Status
)) {
178 bSomethingFound
= TRUE
;
182 // Done with the handles
184 gBS
->FreePool ( pHandles
);
189 // Set the next network protocol
195 // Return the network connection status
197 if ( bSomethingFound
) {
198 Status
= EFI_SUCCESS
;
200 DBG_EXIT_STATUS ( Status
);
206 Disconnect from the network layer
208 Destructor for the EfiSocketLib when the library is linked
209 directly to an application. This routine walks the
210 ::cEslSocketBinding table to remove the ::ESL_SERVICE
211 structures (network connections) from the ::ESL_LAYER structure.
213 This routine is called from ::EslDestructor as a result of the
214 destructor redirection in ::mpfnEslDestructor at the end of this
217 @retval EFI_SUCCESS Successfully disconnected from the network layer
221 EslServiceNetworkDisconnect (
227 CONST ESL_SOCKET_BINDING
* pEnd
;
228 EFI_HANDLE
* pHandles
;
229 CONST ESL_SOCKET_BINDING
* pSocketBinding
;
237 Status
= EFI_SUCCESS
;
240 // Disconnect the network devices
242 pSocketBinding
= &cEslSocketBinding
[0];
243 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
244 while ( pEnd
> pSocketBinding
) {
246 // Attempt to locate the network adapters
250 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
251 pSocketBinding
->pNetworkBinding
,
255 if ( EFI_ERROR ( Status
)) {
258 if ( NULL
!= pHandles
) {
260 // Attempt to disconnect from this network adapter
262 for ( Index
= 0; HandleCount
> Index
; Index
++ ) {
263 Status
= EslServiceDisconnect ( gImageHandle
,
265 if ( EFI_ERROR ( Status
)) {
271 // Done with the handles
273 gBS
->FreePool ( pHandles
);
277 // Set the next network protocol
283 // Finish the disconnect operation
285 if ( !EFI_ERROR ( Status
)) {
286 EslServiceUnload ( );
290 // Return the network connection status
292 DBG_EXIT_STATUS ( Status
);
298 Socket layer's service binding protocol delcaration.
300 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
= {
307 The following entries redirect the constructor and destructor
308 for any socket application that links against the EfiSocketLib.
309 Note that the SocketDxe driver uses different redirection.
311 PFN_ESL_xSTRUCTOR mpfnEslConstructor
= EslServiceNetworkConnect
; ///< Constructor for EfiSocketLib
312 PFN_ESL_xSTRUCTOR mpfnEslDestructor
= EslServiceNetworkDisconnect
; ///< Destructor for EfiSocketLib