]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Network/PxeDhcp4/Dxe/PxeDhcp4.c
Make EdkModulePkg pass Intel IPF compiler with /W4 /WX switches, solving warning...
[mirror_edk2.git] / EdkModulePkg / Universal / Network / PxeDhcp4 / Dxe / PxeDhcp4.c
1 /*++
2
3 Copyright (c) 2006, 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 #include "PxeDhcp4.h"
21
22 //
23 // PXE DHCP Protocol Interface
24 //
25 EFI_DRIVER_BINDING_PROTOCOL gPxeDhcp4DriverBinding = {
26 PxeDhcp4DriverBindingSupported,
27 PxeDhcp4DriverBindingStart,
28 PxeDhcp4DriverBindingStop,
29 0xa,
30 NULL,
31 NULL
32 };
33
34 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
35 EFI_STATUS
36 EFIAPI
37 PxeDhcp4DriverBindingSupported (
38 IN EFI_DRIVER_BINDING_PROTOCOL * This,
39 IN EFI_HANDLE ControllerHandle,
40 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
41 )
42 /*++
43
44 Routine Description:
45 Test to see if this driver supports ControllerHandle. Any
46 ControllerHandle that contains a PxeBaseCode protocol can be
47 supported.
48
49 Arguments:
50 This - Protocol instance pointer.
51 ControllerHandle - Handle of device to test.
52 RemainingDevicePath - Not used.
53
54 Returns:
55 EFI_SUCCESS - This driver supports this device.
56 EFI_ALREADY_STARTED - This driver is already running on this
57 device.
58 other - This driver does not support this device.
59
60 --*/
61 {
62 EFI_STATUS Status;
63 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
64
65 //
66 // Open the IO Abstraction(s) needed to perform the supported test.
67 //
68 Status = gBS->OpenProtocol (
69 ControllerHandle,
70 &gEfiPxeBaseCodeProtocolGuid,
71 (VOID **) &PxeBc,
72 This->DriverBindingHandle,
73 ControllerHandle,
74 EFI_OPEN_PROTOCOL_BY_DRIVER
75 );
76
77 if (EFI_ERROR (Status)) {
78 return Status;
79 }
80 //
81 // Close the I/O Abstraction(s) used to perform the supported test.
82 //
83 return gBS->CloseProtocol (
84 ControllerHandle,
85 &gEfiPxeBaseCodeProtocolGuid,
86 This->DriverBindingHandle,
87 ControllerHandle
88 );
89 }
90
91 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
92 EFI_STATUS
93 EFIAPI
94 PxeDhcp4DriverBindingStart (
95 IN EFI_DRIVER_BINDING_PROTOCOL * This,
96 IN EFI_HANDLE ControllerHandle,
97 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
98 )
99 /*++
100
101 Routine Description:
102 Start this driver on ControllerHandle by opening a PxeBaseCode
103 protocol and installing a PxeDhcp4 protocol on ControllerHandle.
104
105 Arguments:
106 This - Protocol instance pointer.
107 ControllerHandle - Handle of device to bind driver to.
108 RemainingDevicePath - Not used, always produce all possible
109 children.
110
111 Returns:
112 EFI_SUCCESS - This driver is added to ControllerHandle.
113 EFI_ALREADY_STARTED - This driver is already running on
114 ControllerHandle.
115 other - This driver does not support this device.
116
117 --*/
118 {
119 EFI_STATUS Status;
120 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
121 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
122 PXE_DHCP4_PRIVATE_DATA *Private;
123
124 //
125 // Connect to the PxeBaseCode interface on ControllerHandle.
126 //
127 Status = gBS->OpenProtocol (
128 ControllerHandle,
129 &gEfiPxeBaseCodeProtocolGuid,
130 (VOID **) &PxeBc,
131 This->DriverBindingHandle,
132 ControllerHandle,
133 EFI_OPEN_PROTOCOL_BY_DRIVER
134 );
135
136 if (EFI_ERROR (Status)) {
137 return Status;
138 }
139 //
140 // BaseCode has already grabbed the SimpleNetwork interface
141 // so just do a HandleProtocol() to get it.
142 //
143 Status = gBS->HandleProtocol (
144 ControllerHandle,
145 &gEfiSimpleNetworkProtocolGuid,
146 (VOID **) &Snp
147 );
148
149 if (EFI_ERROR (Status)) {
150 goto error_exit;
151 }
152
153 ASSERT (Snp);
154
155 //
156 // Initialize the PXE DHCP device instance.
157 //
158 Status = gBS->AllocatePool (
159 EfiBootServicesData,
160 sizeof (PXE_DHCP4_PRIVATE_DATA),
161 (VOID **) &Private
162 );
163
164 if (EFI_ERROR (Status)) {
165 goto error_exit;
166 }
167 //
168 //
169 //
170 ZeroMem (Private, sizeof (PXE_DHCP4_PRIVATE_DATA));
171
172 Private->Signature = PXE_DHCP4_PRIVATE_DATA_SIGNATURE;
173 Private->PxeBc = PxeBc;
174 Private->Snp = Snp;
175 Private->Handle = ControllerHandle;
176 Private->PxeDhcp4.Revision = EFI_PXE_DHCP4_PROTOCOL_REVISION;
177 Private->PxeDhcp4.Run = PxeDhcp4Run;
178 Private->PxeDhcp4.Setup = PxeDhcp4Setup;
179 Private->PxeDhcp4.Init = PxeDhcp4Init;
180 Private->PxeDhcp4.Select = PxeDhcp4Select;
181 Private->PxeDhcp4.Renew = PxeDhcp4Renew;
182 Private->PxeDhcp4.Rebind = PxeDhcp4Rebind;
183 Private->PxeDhcp4.Release = PxeDhcp4Release;
184 Private->PxeDhcp4.Data = NULL;
185
186 //
187 // Install protocol interfaces for the PXE DHCP device.
188 //
189 Status = gBS->InstallProtocolInterface (
190 &ControllerHandle,
191 &gEfiPxeDhcp4ProtocolGuid,
192 EFI_NATIVE_INTERFACE,
193 &Private->PxeDhcp4
194 );
195
196 if (!EFI_ERROR (Status)) {
197 return Status;
198 }
199
200 error_exit: ;
201 gBS->CloseProtocol (
202 ControllerHandle,
203 &gEfiPxeBaseCodeProtocolGuid,
204 This->DriverBindingHandle,
205 ControllerHandle
206 );
207
208 return Status;
209 }
210
211 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
212 EFI_STATUS
213 EFIAPI
214 PxeDhcp4DriverBindingStop (
215 IN EFI_DRIVER_BINDING_PROTOCOL *This,
216 IN EFI_HANDLE ControllerHandle,
217 IN UINTN NumberOfChildren,
218 IN EFI_HANDLE *ChildHandleBuffer
219 )
220 /*++
221
222 Routine Description:
223 Stop this driver on ControllerHandle by removing PXE DHCP
224 protocol and closing the PXE Base Code protocol on
225 ControllerHandle.
226
227 Arguments:
228 This - Protocol instance pointer.
229 ControllerHandle - Handle of device to stop driver on.
230 NumberOfChildren - Not used.
231 ChildHandleBuffer - Not used.
232
233 Returns:
234 EFI_SUCCESS - This driver is removed ControllerHandle.
235 other - This driver was not removed from this
236 device.
237
238 --*/
239 {
240 EFI_STATUS Status;
241 EFI_PXE_DHCP4_PROTOCOL *PxeDhcp4;
242 PXE_DHCP4_PRIVATE_DATA *Private;
243
244 //
245 // Get our context back.
246 //
247 Status = gBS->OpenProtocol (
248 ControllerHandle,
249 &gEfiPxeDhcp4ProtocolGuid,
250 (VOID **) &PxeDhcp4,
251 This->DriverBindingHandle,
252 ControllerHandle,
253 EFI_OPEN_PROTOCOL_GET_PROTOCOL
254 );
255
256 if (EFI_ERROR (Status)) {
257 return EFI_UNSUPPORTED;
258 }
259
260 Private = PXE_DHCP4_PRIVATE_DATA_FROM_THIS (PxeDhcp4);
261
262 //
263 // Release allocated resources
264 //
265 if (Private->PxeDhcp4.Data) {
266 gBS->FreePool (Private->PxeDhcp4.Data);
267 Private->PxeDhcp4.Data = NULL;
268 }
269 //
270 // Uninstall our protocol
271 //
272 Status = gBS->UninstallProtocolInterface (
273 ControllerHandle,
274 &gEfiPxeDhcp4ProtocolGuid,
275 &Private->PxeDhcp4
276 );
277
278 if (EFI_ERROR (Status)) {
279 return Status;
280 }
281 //
282 // Close any consumed protocols
283 //
284 Status = gBS->CloseProtocol (
285 ControllerHandle,
286 &gEfiPxeBaseCodeProtocolGuid,
287 This->DriverBindingHandle,
288 ControllerHandle
289 );
290
291 if (EFI_ERROR (Status)) {
292 return Status;
293 }
294 //
295 // Release our private data
296 //
297 gBS->FreePool (Private);
298
299 return Status;
300 }
301
302 /* EOF - PxeDhcp4.c */