]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /** @file\r |
2 | Implement the connection to the EFI socket library\r | |
3 | \r | |
4 | Copyright (c) 2011, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
eb222aea | 15 | #include "Socket.h"\r |
d7ce7006 | 16 | \r |
17 | \r | |
a88c3163 | 18 | /**\r |
19 | The following GUID values are only used when an application links\r | |
20 | against EfiSocketLib. An alternative set of values exists in\r | |
21 | SocketDxe\EntryUnload.c which the SocketDxe driver uses to coexist\r | |
22 | with socket applications.\r | |
23 | \r | |
24 | Tag GUID - IPv4 in use by an application using EfiSocketLib\r | |
25 | **/\r | |
26 | CONST EFI_GUID mEslIp4ServiceGuid = {\r | |
27 | 0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }\r | |
d7ce7006 | 28 | };\r |
29 | \r | |
a88c3163 | 30 | \r |
31 | /**\r | |
32 | Tag GUID - TCPv4 in use by an application using EfiSocketLib\r | |
33 | **/\r | |
d7ce7006 | 34 | CONST EFI_GUID mEslTcp4ServiceGuid = {\r |
35 | 0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }\r | |
36 | };\r | |
37 | \r | |
a88c3163 | 38 | \r |
39 | /**\r | |
40 | Tag GUID - UDPv4 in use by an application using EfiSocketLib\r | |
41 | **/\r | |
d7ce7006 | 42 | CONST EFI_GUID mEslUdp4ServiceGuid = {\r |
43 | 0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }\r | |
44 | };\r | |
45 | \r | |
46 | \r | |
47 | /**\r | |
48 | Connect to the EFI socket library\r | |
49 | \r | |
a88c3163 | 50 | This routine creates the ::ESL_SOCKET structure and returns\r |
51 | the API (::EFI_SOCKET_PROTOCOL address) to the socket file\r | |
52 | system layer in BsdSocketLib.\r | |
53 | \r | |
54 | This routine is called from the ::socket routine in BsdSocketLib\r | |
55 | to create the data structure and initialize the API for a socket.\r | |
56 | Note that this implementation is only used by socket applications\r | |
57 | that link directly to EslSocketLib.\r | |
58 | \r | |
59 | @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL\r | |
60 | structure address\r | |
61 | \r | |
62 | @return Value for ::errno, zero (0) indicates success.\r | |
d7ce7006 | 63 | \r |
d7ce7006 | 64 | **/\r |
65 | int\r | |
66 | EslServiceGetProtocol (\r | |
67 | IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol\r | |
68 | )\r | |
69 | {\r | |
70 | EFI_HANDLE ChildHandle;\r | |
a88c3163 | 71 | ESL_SOCKET * pSocket;\r |
d7ce7006 | 72 | int RetVal;\r |
73 | EFI_STATUS Status;\r | |
74 | \r | |
75 | DBG_ENTER ( );\r | |
76 | \r | |
77 | //\r | |
78 | // Assume success\r | |
79 | //\r | |
80 | RetVal = 0;\r | |
81 | \r | |
82 | //\r | |
83 | // Locate the socket protocol\r | |
84 | //\r | |
85 | ChildHandle = NULL;\r | |
86 | Status = EslSocketAllocate ( &ChildHandle,\r | |
87 | DEBUG_SOCKET,\r | |
88 | &pSocket );\r | |
89 | if ( !EFI_ERROR ( Status )) {\r | |
90 | *ppSocketProtocol = &pSocket->SocketProtocol;\r | |
91 | }\r | |
92 | else {\r | |
93 | //\r | |
94 | // No resources\r | |
95 | //\r | |
96 | RetVal = ENOMEM;\r | |
97 | }\r | |
98 | \r | |
99 | //\r | |
100 | // Return the operation status\r | |
101 | //\r | |
102 | DBG_EXIT_DEC ( RetVal );\r | |
103 | return RetVal;\r | |
104 | }\r | |
105 | \r | |
106 | \r | |
107 | /**\r | |
108 | Connect to the network layer\r | |
109 | \r | |
a88c3163 | 110 | This routine is the constructor for the EfiSocketLib when the\r |
111 | library is linked directly to an application. This routine\r | |
112 | walks the ::cEslSocketBinding table to create ::ESL_SERVICE\r | |
113 | structures, associated with the network adapters, which this\r | |
114 | routine links to the ::ESL_LAYER structure.\r | |
115 | \r | |
116 | This routine is called from ::EslConstructor as a result of the\r | |
117 | constructor redirection in ::mpfnEslConstructor at the end of this\r | |
118 | file.\r | |
119 | \r | |
d7ce7006 | 120 | @retval EFI_SUCCESS Successfully connected to the network layer\r |
121 | \r | |
122 | **/\r | |
123 | EFI_STATUS\r | |
124 | EslServiceNetworkConnect (\r | |
125 | VOID\r | |
126 | )\r | |
127 | {\r | |
a88c3163 | 128 | BOOLEAN bSomethingFound;\r |
d7ce7006 | 129 | UINTN HandleCount;\r |
d7ce7006 | 130 | UINTN Index;\r |
a88c3163 | 131 | CONST ESL_SOCKET_BINDING * pEnd;\r |
132 | EFI_HANDLE * pHandles;\r | |
133 | CONST ESL_SOCKET_BINDING * pSocketBinding;\r | |
d7ce7006 | 134 | EFI_STATUS Status;\r |
135 | \r | |
136 | DBG_ENTER ( );\r | |
137 | \r | |
138 | //\r | |
139 | // Initialize the socket layer\r | |
140 | //\r | |
141 | Status = EFI_SUCCESS;\r | |
a88c3163 | 142 | bSomethingFound = FALSE;\r |
d7ce7006 | 143 | EslServiceLoad ( gImageHandle );\r |
144 | \r | |
145 | //\r | |
146 | // Connect the network devices\r | |
147 | //\r | |
a88c3163 | 148 | pSocketBinding = &cEslSocketBinding[0];\r |
149 | pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r | |
d7ce7006 | 150 | while ( pEnd > pSocketBinding ) {\r |
151 | //\r | |
152 | // Attempt to locate the network adapters\r | |
153 | //\r | |
154 | HandleCount = 0;\r | |
155 | pHandles = NULL;\r | |
156 | Status = gBS->LocateHandleBuffer ( ByProtocol,\r | |
157 | pSocketBinding->pNetworkBinding,\r | |
158 | NULL,\r | |
159 | &HandleCount,\r | |
160 | &pHandles );\r | |
161 | if ( EFI_ERROR ( Status )) {\r | |
a88c3163 | 162 | DEBUG (( DEBUG_ERROR,\r |
163 | "ERROR with %s layer, Status: %r\r\n",\r | |
164 | pSocketBinding->pName,\r | |
165 | Status ));\r | |
d7ce7006 | 166 | }\r |
a88c3163 | 167 | else {\r |
168 | if ( NULL != pHandles ) {\r | |
169 | //\r | |
170 | // Attempt to connect to this network adapter\r | |
171 | //\r | |
172 | for ( Index = 0; HandleCount > Index; Index++ ) {\r | |
173 | Status = EslServiceConnect ( gImageHandle,\r | |
174 | pHandles[ Index ]);\r | |
175 | if ( EFI_ERROR ( Status )) {\r | |
176 | break;\r | |
177 | }\r | |
178 | bSomethingFound = TRUE;\r | |
d7ce7006 | 179 | }\r |
d7ce7006 | 180 | \r |
a88c3163 | 181 | //\r |
182 | // Done with the handles\r | |
183 | //\r | |
184 | gBS->FreePool ( pHandles );\r | |
185 | }\r | |
d7ce7006 | 186 | }\r |
187 | \r | |
188 | //\r | |
189 | // Set the next network protocol\r | |
190 | //\r | |
191 | pSocketBinding += 1;\r | |
192 | }\r | |
193 | \r | |
194 | //\r | |
195 | // Return the network connection status\r | |
196 | //\r | |
a88c3163 | 197 | if ( bSomethingFound ) {\r |
198 | Status = EFI_SUCCESS;\r | |
199 | }\r | |
d7ce7006 | 200 | DBG_EXIT_STATUS ( Status );\r |
201 | return Status;\r | |
202 | }\r | |
203 | \r | |
204 | \r | |
205 | /**\r | |
206 | Disconnect from the network layer\r | |
207 | \r | |
a88c3163 | 208 | Destructor for the EfiSocketLib when the library is linked\r |
209 | directly to an application. This routine walks the\r | |
210 | ::cEslSocketBinding table to remove the ::ESL_SERVICE\r | |
211 | structures (network connections) from the ::ESL_LAYER structure.\r | |
212 | \r | |
213 | This routine is called from ::EslDestructor as a result of the\r | |
214 | destructor redirection in ::mpfnEslDestructor at the end of this\r | |
215 | file.\r | |
216 | \r | |
d7ce7006 | 217 | @retval EFI_SUCCESS Successfully disconnected from the network layer\r |
218 | \r | |
219 | **/\r | |
220 | EFI_STATUS\r | |
221 | EslServiceNetworkDisconnect (\r | |
222 | VOID\r | |
223 | )\r | |
224 | {\r | |
225 | UINTN HandleCount;\r | |
d7ce7006 | 226 | UINTN Index;\r |
a88c3163 | 227 | CONST ESL_SOCKET_BINDING * pEnd;\r |
228 | EFI_HANDLE * pHandles;\r | |
229 | CONST ESL_SOCKET_BINDING * pSocketBinding;\r | |
d7ce7006 | 230 | EFI_STATUS Status;\r |
231 | \r | |
232 | DBG_ENTER ( );\r | |
233 | \r | |
234 | //\r | |
235 | // Assume success\r | |
236 | //\r | |
237 | Status = EFI_SUCCESS;\r | |
238 | \r | |
239 | //\r | |
240 | // Disconnect the network devices\r | |
241 | //\r | |
a88c3163 | 242 | pSocketBinding = &cEslSocketBinding[0];\r |
243 | pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r | |
d7ce7006 | 244 | while ( pEnd > pSocketBinding ) {\r |
245 | //\r | |
246 | // Attempt to locate the network adapters\r | |
247 | //\r | |
248 | HandleCount = 0;\r | |
249 | pHandles = NULL;\r | |
250 | Status = gBS->LocateHandleBuffer ( ByProtocol,\r | |
251 | pSocketBinding->pNetworkBinding,\r | |
252 | NULL,\r | |
253 | &HandleCount,\r | |
254 | &pHandles );\r | |
255 | if ( EFI_ERROR ( Status )) {\r | |
256 | break;\r | |
257 | }\r | |
258 | if ( NULL != pHandles ) {\r | |
259 | //\r | |
260 | // Attempt to disconnect from this network adapter\r | |
261 | //\r | |
262 | for ( Index = 0; HandleCount > Index; Index++ ) {\r | |
263 | Status = EslServiceDisconnect ( gImageHandle,\r | |
a88c3163 | 264 | pHandles[ Index ]);\r |
d7ce7006 | 265 | if ( EFI_ERROR ( Status )) {\r |
266 | break;\r | |
267 | }\r | |
268 | }\r | |
269 | \r | |
270 | //\r | |
271 | // Done with the handles\r | |
272 | //\r | |
273 | gBS->FreePool ( pHandles );\r | |
274 | }\r | |
275 | \r | |
276 | //\r | |
277 | // Set the next network protocol\r | |
278 | //\r | |
279 | pSocketBinding += 1;\r | |
280 | }\r | |
281 | \r | |
282 | //\r | |
283 | // Finish the disconnect operation\r | |
284 | //\r | |
285 | if ( !EFI_ERROR ( Status )) {\r | |
286 | EslServiceUnload ( );\r | |
287 | }\r | |
288 | \r | |
289 | //\r | |
290 | // Return the network connection status\r | |
291 | //\r | |
292 | DBG_EXIT_STATUS ( Status );\r | |
293 | return Status;\r | |
294 | }\r | |
295 | \r | |
296 | \r | |
a88c3163 | 297 | /**\r |
298 | Socket layer's service binding protocol delcaration.\r | |
299 | **/\r | |
300 | CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {\r | |
301 | NULL,\r | |
302 | NULL\r | |
303 | };\r | |
304 | \r | |
305 | \r | |
306 | /**\r | |
307 | The following entries redirect the constructor and destructor\r | |
308 | for any socket application that links against the EfiSocketLib.\r | |
309 | Note that the SocketDxe driver uses different redirection.\r | |
310 | **/\r | |
311 | PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect; ///< Constructor for EfiSocketLib\r | |
312 | PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect; ///< Destructor for EfiSocketLib\r |