]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - StdLib/EfiSocketLib/UseEfiSocketLib.c
Fix issues detected by python web-server.
[mirror_edk2.git] / StdLib / EfiSocketLib / UseEfiSocketLib.c
... / ...
CommitLineData
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
15#include "Socket.h"\r
16\r
17\r
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
26CONST EFI_GUID mEslIp4ServiceGuid = {\r
27 0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }\r
28};\r
29\r
30\r
31/**\r
32 Tag GUID - IPv6 in use by an application using EfiSocketLib\r
33**/\r
34CONST EFI_GUID mEslIp6ServiceGuid = {\r
35 0xc51b2761, 0xc476, 0x45fe, { 0xbe, 0x61, 0xba, 0x4b, 0xcc, 0x32, 0xf2, 0x34 }\r
36};\r
37\r
38\r
39/**\r
40 Tag GUID - TCPv4 in use by an application using EfiSocketLib\r
41**/\r
42CONST EFI_GUID mEslTcp4ServiceGuid = {\r
43 0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }\r
44};\r
45\r
46\r
47/**\r
48 Tag GUID - TCPv6 in use by an application using EfiSocketLib\r
49**/\r
50CONST EFI_GUID mEslTcp6ServiceGuid = {\r
51 0x279858a4, 0x4e9e, 0x4e53, { 0x93, 0x22, 0xf2, 0x54, 0xe0, 0x7e, 0xef, 0xd4 }\r
52};\r
53\r
54\r
55/**\r
56 Tag GUID - UDPv4 in use by an application using EfiSocketLib\r
57**/\r
58CONST EFI_GUID mEslUdp4ServiceGuid = {\r
59 0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }\r
60};\r
61\r
62\r
63/**\r
64 Tag GUID - UDPv6 in use by an application using EfiSocketLib\r
65**/\r
66CONST EFI_GUID mEslUdp6ServiceGuid = {\r
67 0xaa4af677, 0x6efe, 0x477c, { 0x96, 0x68, 0xe8, 0x13, 0x9d, 0x2, 0xfd, 0x9b }\r
68};\r
69\r
70\r
71/**\r
72 Connect to the EFI socket library\r
73\r
74 This routine creates the ::ESL_SOCKET structure and returns\r
75 the API (::EFI_SOCKET_PROTOCOL address) to the socket file\r
76 system layer in BsdSocketLib.\r
77\r
78 This routine is called from the ::socket routine in BsdSocketLib\r
79 to create the data structure and initialize the API for a socket.\r
80 Note that this implementation is only used by socket applications\r
81 that link directly to EslSocketLib.\r
82\r
83 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL\r
84 structure address\r
85\r
86 @return Value for ::errno, zero (0) indicates success.\r
87\r
88 **/\r
89int\r
90EslServiceGetProtocol (\r
91 IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol\r
92 )\r
93{\r
94 EFI_HANDLE ChildHandle;\r
95 ESL_SOCKET * pSocket;\r
96 int RetVal;\r
97 EFI_STATUS Status;\r
98\r
99 DBG_ENTER ( );\r
100\r
101 //\r
102 // Assume success\r
103 //\r
104 RetVal = 0;\r
105\r
106 //\r
107 // Locate the socket protocol\r
108 //\r
109 ChildHandle = NULL;\r
110 Status = EslSocketAllocate ( &ChildHandle,\r
111 DEBUG_SOCKET,\r
112 &pSocket );\r
113 if ( !EFI_ERROR ( Status )) {\r
114 *ppSocketProtocol = &pSocket->SocketProtocol;\r
115 }\r
116 else {\r
117 //\r
118 // No resources\r
119 //\r
120 RetVal = ENOMEM;\r
121 }\r
122\r
123 //\r
124 // Return the operation status\r
125 //\r
126 DBG_EXIT_DEC ( RetVal );\r
127 return RetVal;\r
128}\r
129\r
130\r
131/**\r
132 Connect to the network layer\r
133\r
134 This routine is the constructor for the EfiSocketLib when the\r
135 library is linked directly to an application. This routine\r
136 walks the ::cEslSocketBinding table to create ::ESL_SERVICE\r
137 structures, associated with the network adapters, which this\r
138 routine links to the ::ESL_LAYER structure.\r
139\r
140 This routine is called from ::EslConstructor as a result of the\r
141 constructor redirection in ::mpfnEslConstructor at the end of this\r
142 file.\r
143\r
144 @retval EFI_SUCCESS Successfully connected to the network layer\r
145\r
146 **/\r
147EFI_STATUS\r
148EslServiceNetworkConnect (\r
149 VOID\r
150 )\r
151{\r
152 BOOLEAN bSomethingFound;\r
153 UINTN HandleCount;\r
154 UINTN Index;\r
155 CONST ESL_SOCKET_BINDING * pEnd;\r
156 EFI_HANDLE * pHandles;\r
157 CONST ESL_SOCKET_BINDING * pSocketBinding;\r
158 EFI_STATUS Status;\r
159\r
160 DBG_ENTER ( );\r
161\r
162 //\r
163 // Initialize the socket layer\r
164 //\r
165 Status = EFI_SUCCESS;\r
166 bSomethingFound = FALSE;\r
167 EslServiceLoad ( gImageHandle );\r
168\r
169 //\r
170 // Connect the network devices\r
171 //\r
172 pSocketBinding = &cEslSocketBinding[0];\r
173 pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r
174 while ( pEnd > pSocketBinding ) {\r
175 //\r
176 // Attempt to locate the network adapters\r
177 //\r
178 HandleCount = 0;\r
179 pHandles = NULL;\r
180 Status = gBS->LocateHandleBuffer ( ByProtocol,\r
181 pSocketBinding->pNetworkBinding,\r
182 NULL,\r
183 &HandleCount,\r
184 &pHandles );\r
185 if ( EFI_ERROR ( Status )) {\r
186 DEBUG (( DEBUG_ERROR,\r
187 "ERROR with %s layer, Status: %r\r\n",\r
188 pSocketBinding->pName,\r
189 Status ));\r
190 }\r
191 else {\r
192 if ( NULL != pHandles ) {\r
193 //\r
194 // Attempt to connect to this network adapter\r
195 //\r
196 for ( Index = 0; HandleCount > Index; Index++ ) {\r
197 Status = EslServiceConnect ( gImageHandle,\r
198 pHandles[ Index ]);\r
199 if ( EFI_ERROR ( Status )) {\r
200 break;\r
201 }\r
202 bSomethingFound = TRUE;\r
203 }\r
204\r
205 //\r
206 // Done with the handles\r
207 //\r
208 gBS->FreePool ( pHandles );\r
209 }\r
210 }\r
211\r
212 //\r
213 // Set the next network protocol\r
214 //\r
215 pSocketBinding += 1;\r
216 }\r
217\r
218 //\r
219 // Return the network connection status\r
220 //\r
221 if ( bSomethingFound ) {\r
222 Status = EFI_SUCCESS;\r
223 }\r
224 DBG_EXIT_STATUS ( Status );\r
225 return Status;\r
226}\r
227\r
228\r
229/**\r
230 Disconnect from the network layer\r
231\r
232 Destructor for the EfiSocketLib when the library is linked\r
233 directly to an application. This routine walks the\r
234 ::cEslSocketBinding table to remove the ::ESL_SERVICE\r
235 structures (network connections) from the ::ESL_LAYER structure.\r
236\r
237 This routine is called from ::EslDestructor as a result of the\r
238 destructor redirection in ::mpfnEslDestructor at the end of this\r
239 file.\r
240\r
241 @retval EFI_SUCCESS Successfully disconnected from the network layer\r
242\r
243 **/\r
244EFI_STATUS\r
245EslServiceNetworkDisconnect (\r
246 VOID\r
247 )\r
248{\r
249 UINTN HandleCount;\r
250 UINTN Index;\r
251 CONST ESL_SOCKET_BINDING * pEnd;\r
252 EFI_HANDLE * pHandles;\r
253 CONST ESL_SOCKET_BINDING * pSocketBinding;\r
254 EFI_STATUS Status;\r
255\r
256 DBG_ENTER ( );\r
257\r
258 //\r
259 // Assume success\r
260 //\r
261 Status = EFI_SUCCESS;\r
262\r
263 //\r
264 // Disconnect the network devices\r
265 //\r
266 pSocketBinding = &cEslSocketBinding[0];\r
267 pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r
268 while ( pEnd > pSocketBinding ) {\r
269 //\r
270 // Attempt to locate the network adapters\r
271 //\r
272 HandleCount = 0;\r
273 pHandles = NULL;\r
274 Status = gBS->LocateHandleBuffer ( ByProtocol,\r
275 pSocketBinding->pNetworkBinding,\r
276 NULL,\r
277 &HandleCount,\r
278 &pHandles );\r
279 if (( !EFI_ERROR ( Status ))\r
280 && ( NULL != pHandles )) {\r
281 //\r
282 // Attempt to disconnect from this network adapter\r
283 //\r
284 for ( Index = 0; HandleCount > Index; Index++ ) {\r
285 Status = EslServiceDisconnect ( gImageHandle,\r
286 pHandles[ Index ]);\r
287 if ( EFI_ERROR ( Status )) {\r
288 break;\r
289 }\r
290 }\r
291\r
292 //\r
293 // Done with the handles\r
294 //\r
295 gBS->FreePool ( pHandles );\r
296 }\r
297\r
298 //\r
299 // Set the next network protocol\r
300 //\r
301 pSocketBinding += 1;\r
302 Status = EFI_SUCCESS;\r
303 }\r
304\r
305 //\r
306 // Finish the disconnect operation\r
307 //\r
308 if ( !EFI_ERROR ( Status )) {\r
309 EslServiceUnload ( );\r
310 }\r
311\r
312 //\r
313 // Return the network connection status\r
314 //\r
315 DBG_EXIT_STATUS ( Status );\r
316 return Status;\r
317}\r
318\r
319\r
320/**\r
321 Socket layer's service binding protocol delcaration.\r
322**/\r
323CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {\r
324 NULL,\r
325 NULL\r
326};\r
327\r
328\r
329/**\r
330 The following entries redirect the constructor and destructor\r
331 for any socket application that links against the EfiSocketLib.\r
332 Note that the SocketDxe driver uses different redirection.\r
333**/\r
334PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect; ///< Constructor for EfiSocketLib\r
335PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect; ///< Destructor for EfiSocketLib\r