]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/SocketDxe/DriverBinding.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / SocketDxe / DriverBinding.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the driver binding protocol for the socket layer.\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
a88c3163 13\r
14 \section NetworkAdapterManagement Network Adapter Management\r
15 Network adapters may come and go over the life if a system running\r
16 UEFI. The SocketDxe driver uses the driver binding API to manage\r
17 the connections to network adapters.\r
18\r
19 The ::DriverSupported routine selects network adapters that the\r
20 socket layer is not using. This determination by the lack of the\r
21 tag GUID associated with the network protocol in the\r
22 ::cEslSocketBinding array. The selected network adapters are \r
23 passed to the ::DriverStart routine.\r
24\r
25 The ::DriverStart routine calls the ::EslServiceConnect routine\r
26 to create an ::ESL_SERVICE structure to manage the network adapter\r
27 for the socket layer. EslServiceConnect also installs the tag\r
28 GUID on the network adapter to prevent future calls from\r
29 ::DriverSupported. EslService also calls the network specific\r
30 initialization routine listed in ESL_SOCKET_BINDING::pfnInitialize\r
31 field of the ::cEslSocketBinding entry.\r
32\r
33 The ::DriverStop routine calls the ::EslServiceDisconnect routine\r
34 to undo the work done by ::DriverStart. The socket layer must break\r
35 the active network connections, then remove the tag GUIDs from the\r
36 controller handle and free ::ESL_SERVICE structure.\r
37\r
d7ce7006 38**/\r
39\r
40#include "Socket.h"\r
41\r
42/**\r
43 Verify the controller type\r
44\r
a88c3163 45 This routine walks the cEslSocketBinding array to determines if\r
46 the controller is a network adapter by supporting any of the\r
47 network protocols required by the sockets layer. If so, the\r
48 routine verifies that the socket layer is not already using the\r
49 support by looking for the tag GUID listed in the corresponding\r
50 array entry. The controller handle is passed to the ::DriverStart\r
51 routine if sockets can use the network adapter.\r
52 See the \ref NetworkAdapterManagement section.\r
53\r
54 This routine is called by the UEFI driver framework during connect\r
55 processing.\r
d7ce7006 56\r
57 @param [in] pThis Protocol instance pointer.\r
58 @param [in] Controller Handle of device to test.\r
59 @param [in] pRemainingDevicePath Not used.\r
60\r
61 @retval EFI_SUCCESS This driver supports this device.\r
62 @retval other This driver does not support this device.\r
63\r
64**/\r
65EFI_STATUS\r
66EFIAPI\r
67DriverSupported (\r
68 IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r
69 IN EFI_HANDLE Controller,\r
70 IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath\r
71 )\r
72{\r
a88c3163 73 CONST ESL_SOCKET_BINDING * pEnd;\r
d7ce7006 74 VOID * pInterface;\r
a88c3163 75 CONST ESL_SOCKET_BINDING * pSocketBinding;\r
d7ce7006 76 EFI_STATUS Status;\r
77\r
78 //\r
79 // Assume the list is empty\r
80 //\r
81 Status = EFI_UNSUPPORTED;\r
82\r
83 //\r
84 // Walk the list of network connection points\r
85 //\r
86 pSocketBinding = &cEslSocketBinding[0];\r
87 pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r
88 while ( pEnd > pSocketBinding ) {\r
89 //\r
90 // Determine if the controller supports the network protocol\r
91 //\r
92 Status = gBS->OpenProtocol (\r
93 Controller,\r
94 pSocketBinding->pNetworkBinding,\r
95 &pInterface,\r
96 pThis->DriverBindingHandle,\r
97 Controller,\r
98 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
99 );\r
100 if ( !EFI_ERROR ( Status )) {\r
101 //\r
102 // Determine if the driver is already connected\r
103 //\r
104 Status = gBS->OpenProtocol (\r
105 Controller,\r
106 (EFI_GUID *)pSocketBinding->pTagGuid,\r
107 &pInterface,\r
108 pThis->DriverBindingHandle,\r
109 Controller,\r
110 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
111 );\r
112 if ( !EFI_ERROR ( Status )) {\r
113 Status = EFI_ALREADY_STARTED;\r
114 }\r
115 else {\r
116 if ( EFI_UNSUPPORTED == Status ) {\r
117 //\r
118 // Connect the driver since the tag is not present\r
119 //\r
120 Status = EFI_SUCCESS;\r
121 }\r
122 }\r
123 }\r
124\r
125 //\r
126 // Set the next network protocol\r
127 //\r
128 pSocketBinding += 1;\r
129 }\r
130\r
131 //\r
132 // Return the device supported status\r
133 //\r
134 return Status;\r
135}\r
136\r
137\r
138/**\r
a88c3163 139 Connect to a network adapter\r
d7ce7006 140\r
a88c3163 141 This routine calls ::EslServiceConnect to connect the socket\r
142 layer to the network adapters. See the \ref NetworkAdapterManagement\r
143 section.\r
144\r
145 This routine is called by the UEFI driver framework during connect\r
146 processing if the controller passes the tests in ::DriverSupported.\r
d7ce7006 147\r
148 @param [in] pThis Protocol instance pointer.\r
149 @param [in] Controller Handle of device to work with.\r
150 @param [in] pRemainingDevicePath Not used, always produce all possible children.\r
151\r
152 @retval EFI_SUCCESS This driver is added to Controller.\r
153 @retval other This driver does not support this device.\r
154\r
155**/\r
156EFI_STATUS\r
157EFIAPI\r
158DriverStart (\r
159 IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r
160 IN EFI_HANDLE Controller,\r
161 IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath\r
162 )\r
163{\r
164 EFI_STATUS Status;\r
165\r
166 DBG_ENTER ( );\r
167\r
168 //\r
169 // Connect to this network adapter\r
170 //\r
171 Status = EslServiceConnect ( pThis->DriverBindingHandle,\r
172 Controller );\r
173\r
174 //\r
175 // Display the driver start status\r
176 //\r
177 DBG_EXIT_STATUS ( Status );\r
178 return Status;\r
179}\r
180\r
181\r
182/**\r
a88c3163 183 Disconnect from a network adapter\r
184\r
185 This routine calls ::EslServiceDisconnect to disconnect the socket\r
186 layer from the network adapters. See the \ref NetworkAdapterManagement\r
187 section.\r
d7ce7006 188\r
a88c3163 189 This routine is called by ::DriverUnload when the socket layer\r
190 is being unloaded. This routine should also called by the UEFI\r
191 driver framework when a network adapter is being unloaded from\r
192 the system.\r
193 \r
d7ce7006 194 @param [in] pThis Protocol instance pointer.\r
195 @param [in] Controller Handle of device to stop driver on.\r
196 @param [in] NumberOfChildren How many children need to be stopped.\r
197 @param [in] pChildHandleBuffer Not used.\r
198\r
199 @retval EFI_SUCCESS This driver is removed Controller.\r
200 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
201 @retval other This driver was not removed from this device.\r
202\r
203**/\r
204EFI_STATUS\r
205EFIAPI\r
206DriverStop (\r
207 IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r
208 IN EFI_HANDLE Controller,\r
209 IN UINTN NumberOfChildren,\r
210 IN EFI_HANDLE * pChildHandleBuffer\r
211 )\r
212{\r
213 EFI_STATUS Status;\r
214 \r
215 DBG_ENTER ( );\r
216\r
217 //\r
218 // Disconnect the network adapters\r
219 //\r
220 Status = EslServiceDisconnect ( pThis->DriverBindingHandle,\r
221 Controller );\r
222\r
223 //\r
224 // Display the driver start status\r
225 //\r
226 DBG_EXIT_STATUS ( Status );\r
227 return Status;\r
228}\r
229\r
230\r
231/**\r
a88c3163 232 Driver binding protocol for the SocketDxe driver.\r
d7ce7006 233**/\r
a88c3163 234EFI_DRIVER_BINDING_PROTOCOL mDriverBinding = {\r
d7ce7006 235 DriverSupported,\r
236 DriverStart,\r
237 DriverStop,\r
238 0xa,\r
239 NULL,\r
240 NULL\r
241};\r