]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/PxeDhcp4Dxe/PxeDhcp4.c
remove clean console control protocol.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / PxeDhcp4Dxe / PxeDhcp4.c
1 /** @file
2
3 Copyright (c) 2004 - 2005, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13 PxeDhcp4.c
14
15 Abstract:
16
17
18 **/
19
20
21 #include "PxeDhcp4.h"
22
23 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
24
25 //
26 // Prototypes
27 // Driver model protocol interface
28 //
29 EFI_STATUS
30 EFIAPI
31 PxeDhcp4DriverEntryPoint (
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 );
35
36 EFI_STATUS
37 EFIAPI
38 PxeDhcp4DriverBindingSupported (
39 IN EFI_DRIVER_BINDING_PROTOCOL *This,
40 IN EFI_HANDLE ControllerHandle,
41 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
42 );
43
44 EFI_STATUS
45 EFIAPI
46 PxeDhcp4DriverBindingStart (
47 IN EFI_DRIVER_BINDING_PROTOCOL *This,
48 IN EFI_HANDLE ControllerHandle,
49 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
50 );
51
52 EFI_STATUS
53 EFIAPI
54 PxeDhcp4DriverBindingStop (
55 IN EFI_DRIVER_BINDING_PROTOCOL *This,
56 IN EFI_HANDLE ControllerHandle,
57 IN UINTN NumberOfChildren,
58 IN EFI_HANDLE *ChildHandleBuffer
59 );
60
61 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
62
63 //
64 // PXE DHCP Protocol Interface
65 //
66 EFI_DRIVER_BINDING_PROTOCOL gPxeDhcp4DriverBinding = {
67 PxeDhcp4DriverBindingSupported,
68 PxeDhcp4DriverBindingStart,
69 PxeDhcp4DriverBindingStop,
70 0xa,
71 NULL,
72 NULL
73 };
74
75 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
76
77 //
78 // PxeDhcp4 Driver Entry point funtion
79 //
80
81 /**
82 Register Driver Binding protocol for this driver.
83
84 @param entry EFI_IMAGE_ENTRY_POINT)
85
86 @retval EFI_SUCCESS Driver loaded.
87 @retval other Driver not loaded.
88
89 **/
90 EFI_STATUS
91 EFIAPI
92 PxeDhcp4DriverEntryPoint (
93 IN EFI_HANDLE ImageHandle,
94 IN EFI_SYSTEM_TABLE *SystemTable
95 )
96 {
97 return EfiLibInstallDriverBindingComponentName2 (
98 ImageHandle,
99 SystemTable,
100 &gPxeDhcp4DriverBinding,
101 NULL,
102 &gPxeDhcp4ComponentName,
103 &gPxeDhcp4ComponentName2
104 );
105 }
106
107 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
108
109 /**
110 Test to see if this driver supports ControllerHandle. Any
111 ControllerHandle that contains a PxeBaseCode protocol can be
112 supported.
113
114 @param This Protocol instance pointer.
115 @param ControllerHandle Handle of device to test.
116 @param RemainingDevicePath Not used.
117
118 @retval EFI_SUCCESS This driver supports this device.
119 @retval EFI_ALREADY_STARTED This driver is already running on this device.
120 @retval other This driver does not support this device.
121
122 **/
123 EFI_STATUS
124 EFIAPI
125 PxeDhcp4DriverBindingSupported (
126 IN EFI_DRIVER_BINDING_PROTOCOL * This,
127 IN EFI_HANDLE ControllerHandle,
128 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
129 )
130 {
131 EFI_STATUS Status;
132 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
133
134 //
135 // Open the IO Abstraction(s) needed to perform the supported test.
136 //
137 Status = gBS->OpenProtocol (
138 ControllerHandle,
139 &gEfiPxeBaseCodeProtocolGuid,
140 (VOID **) &PxeBc,
141 This->DriverBindingHandle,
142 ControllerHandle,
143 EFI_OPEN_PROTOCOL_BY_DRIVER
144 );
145
146 if (EFI_ERROR (Status)) {
147 return Status;
148 }
149 //
150 // Close the I/O Abstraction(s) used to perform the supported test.
151 //
152 return gBS->CloseProtocol (
153 ControllerHandle,
154 &gEfiPxeBaseCodeProtocolGuid,
155 This->DriverBindingHandle,
156 ControllerHandle
157 );
158 }
159
160 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
161
162 /**
163 Start this driver on ControllerHandle by opening a PxeBaseCode
164 protocol and installing a PxeDhcp4 protocol on ControllerHandle.
165
166 @param This Protocol instance pointer.
167 @param ControllerHandle Handle of device to bind driver to.
168 @param RemainingDevicePath Not used, always produce all possible children.
169
170 @retval EFI_SUCCESS This driver is added to ControllerHandle.
171 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
172 @retval other This driver does not support this device.
173
174 **/
175 EFI_STATUS
176 EFIAPI
177 PxeDhcp4DriverBindingStart (
178 IN EFI_DRIVER_BINDING_PROTOCOL * This,
179 IN EFI_HANDLE ControllerHandle,
180 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
181 )
182 {
183 EFI_STATUS Status;
184 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
185 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
186 PXE_DHCP4_PRIVATE_DATA *Private;
187
188 //
189 // Connect to the PxeBaseCode interface on ControllerHandle.
190 //
191 Status = gBS->OpenProtocol (
192 ControllerHandle,
193 &gEfiPxeBaseCodeProtocolGuid,
194 (VOID **) &PxeBc,
195 This->DriverBindingHandle,
196 ControllerHandle,
197 EFI_OPEN_PROTOCOL_BY_DRIVER
198 );
199
200 if (EFI_ERROR (Status)) {
201 return Status;
202 }
203 //
204 // BaseCode has already grabbed the SimpleNetwork interface
205 // so just do a HandleProtocol() to get it.
206 //
207 Status = gBS->HandleProtocol (
208 ControllerHandle,
209 &gEfiSimpleNetworkProtocolGuid,
210 (VOID **) &Snp
211 );
212
213 if (EFI_ERROR (Status)) {
214 goto error_exit;
215 }
216
217 ASSERT (Snp);
218
219 //
220 // Initialize the PXE DHCP device instance.
221 //
222 Private = AllocateZeroPool (sizeof (PXE_DHCP4_PRIVATE_DATA));
223 if (Private == NULL) {
224 Status = EFI_OUT_OF_RESOURCES;
225 goto error_exit;
226 }
227
228 Private->Signature = PXE_DHCP4_PRIVATE_DATA_SIGNATURE;
229 Private->PxeBc = PxeBc;
230 Private->Snp = Snp;
231 Private->Handle = ControllerHandle;
232 Private->PxeDhcp4.Revision = EFI_PXE_DHCP4_PROTOCOL_REVISION;
233 Private->PxeDhcp4.Run = PxeDhcp4Run;
234 Private->PxeDhcp4.Setup = PxeDhcp4Setup;
235 Private->PxeDhcp4.Init = PxeDhcp4Init;
236 Private->PxeDhcp4.Select = PxeDhcp4Select;
237 Private->PxeDhcp4.Renew = PxeDhcp4Renew;
238 Private->PxeDhcp4.Rebind = PxeDhcp4Rebind;
239 Private->PxeDhcp4.Release = PxeDhcp4Release;
240 Private->PxeDhcp4.Data = NULL;
241
242 //
243 // Install protocol interfaces for the PXE DHCP device.
244 //
245 Status = gBS->InstallProtocolInterface (
246 &ControllerHandle,
247 &gEfiPxeDhcp4ProtocolGuid,
248 EFI_NATIVE_INTERFACE,
249 &Private->PxeDhcp4
250 );
251
252 if (!EFI_ERROR (Status)) {
253 return Status;
254 }
255
256 error_exit: ;
257 gBS->CloseProtocol (
258 ControllerHandle,
259 &gEfiPxeBaseCodeProtocolGuid,
260 This->DriverBindingHandle,
261 ControllerHandle
262 );
263
264 return Status;
265 }
266
267 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
268
269 /**
270 Stop this driver on ControllerHandle by removing PXE DHCP
271 protocol and closing the PXE Base Code protocol on
272 ControllerHandle.
273
274 @param This Protocol instance pointer.
275 @param ControllerHandle Handle of device to stop driver on.
276 @param NumberOfChildren Not used.
277 @param ChildHandleBuffer Not used.
278
279 @retval EFI_SUCCESS This driver is removed ControllerHandle.
280 @retval other This driver was not removed from this device.
281
282 **/
283 EFI_STATUS
284 EFIAPI
285 PxeDhcp4DriverBindingStop (
286 IN EFI_DRIVER_BINDING_PROTOCOL *This,
287 IN EFI_HANDLE ControllerHandle,
288 IN UINTN NumberOfChildren,
289 IN EFI_HANDLE *ChildHandleBuffer
290 )
291 {
292 EFI_STATUS Status;
293 EFI_PXE_DHCP4_PROTOCOL *PxeDhcp4;
294 PXE_DHCP4_PRIVATE_DATA *Private;
295
296 //
297 // Get our context back.
298 //
299 Status = gBS->OpenProtocol (
300 ControllerHandle,
301 &gEfiPxeDhcp4ProtocolGuid,
302 (VOID **) &PxeDhcp4,
303 This->DriverBindingHandle,
304 ControllerHandle,
305 EFI_OPEN_PROTOCOL_GET_PROTOCOL
306 );
307
308 if (EFI_ERROR (Status)) {
309 return EFI_UNSUPPORTED;
310 }
311
312 Private = PXE_DHCP4_PRIVATE_DATA_FROM_THIS (PxeDhcp4);
313
314 //
315 // Release allocated resources
316 //
317 if (Private->PxeDhcp4.Data) {
318 FreePool (Private->PxeDhcp4.Data);
319 Private->PxeDhcp4.Data = NULL;
320 }
321 //
322 // Uninstall our protocol
323 //
324 Status = gBS->UninstallProtocolInterface (
325 ControllerHandle,
326 &gEfiPxeDhcp4ProtocolGuid,
327 &Private->PxeDhcp4
328 );
329
330 if (EFI_ERROR (Status)) {
331 return Status;
332 }
333 //
334 // Close any consumed protocols
335 //
336 Status = gBS->CloseProtocol (
337 ControllerHandle,
338 &gEfiPxeBaseCodeProtocolGuid,
339 This->DriverBindingHandle,
340 ControllerHandle
341 );
342
343 if (EFI_ERROR (Status)) {
344 return Status;
345 }
346 //
347 // Release our private data
348 //
349 FreePool (Private);
350
351 return Status;
352 }
353
354 /* EOF - PxeDhcp4.c */