]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Network/PxeDhcp4/Dxe/PxeDhcp4.c
Clean up the following module msa files, they are three networt and two PCD modules.
[mirror_edk2.git] / EdkModulePkg / Universal / Network / PxeDhcp4 / Dxe / PxeDhcp4.c
1 /*++
2
3 Copyright (c) 2006 - 2007, 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 Private = AllocateZeroPool (sizeof (PXE_DHCP4_PRIVATE_DATA));
159 if (Private == NULL) {
160 Status = EFI_OUT_OF_RESOURCES;
161 goto error_exit;
162 }
163
164 Private->Signature = PXE_DHCP4_PRIVATE_DATA_SIGNATURE;
165 Private->PxeBc = PxeBc;
166 Private->Snp = Snp;
167 Private->Handle = ControllerHandle;
168 Private->PxeDhcp4.Revision = EFI_PXE_DHCP4_PROTOCOL_REVISION;
169 Private->PxeDhcp4.Run = PxeDhcp4Run;
170 Private->PxeDhcp4.Setup = PxeDhcp4Setup;
171 Private->PxeDhcp4.Init = PxeDhcp4Init;
172 Private->PxeDhcp4.Select = PxeDhcp4Select;
173 Private->PxeDhcp4.Renew = PxeDhcp4Renew;
174 Private->PxeDhcp4.Rebind = PxeDhcp4Rebind;
175 Private->PxeDhcp4.Release = PxeDhcp4Release;
176 Private->PxeDhcp4.Data = NULL;
177
178 //
179 // Install protocol interfaces for the PXE DHCP device.
180 //
181 Status = gBS->InstallProtocolInterface (
182 &ControllerHandle,
183 &gEfiPxeDhcp4ProtocolGuid,
184 EFI_NATIVE_INTERFACE,
185 &Private->PxeDhcp4
186 );
187
188 if (!EFI_ERROR (Status)) {
189 return Status;
190 }
191
192 error_exit: ;
193 gBS->CloseProtocol (
194 ControllerHandle,
195 &gEfiPxeBaseCodeProtocolGuid,
196 This->DriverBindingHandle,
197 ControllerHandle
198 );
199
200 return Status;
201 }
202
203 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
204 EFI_STATUS
205 EFIAPI
206 PxeDhcp4DriverBindingStop (
207 IN EFI_DRIVER_BINDING_PROTOCOL *This,
208 IN EFI_HANDLE ControllerHandle,
209 IN UINTN NumberOfChildren,
210 IN EFI_HANDLE *ChildHandleBuffer
211 )
212 /*++
213
214 Routine Description:
215 Stop this driver on ControllerHandle by removing PXE DHCP
216 protocol and closing the PXE Base Code protocol on
217 ControllerHandle.
218
219 Arguments:
220 This - Protocol instance pointer.
221 ControllerHandle - Handle of device to stop driver on.
222 NumberOfChildren - Not used.
223 ChildHandleBuffer - Not used.
224
225 Returns:
226 EFI_SUCCESS - This driver is removed ControllerHandle.
227 other - This driver was not removed from this
228 device.
229
230 --*/
231 {
232 EFI_STATUS Status;
233 EFI_PXE_DHCP4_PROTOCOL *PxeDhcp4;
234 PXE_DHCP4_PRIVATE_DATA *Private;
235
236 //
237 // Get our context back.
238 //
239 Status = gBS->OpenProtocol (
240 ControllerHandle,
241 &gEfiPxeDhcp4ProtocolGuid,
242 (VOID **) &PxeDhcp4,
243 This->DriverBindingHandle,
244 ControllerHandle,
245 EFI_OPEN_PROTOCOL_GET_PROTOCOL
246 );
247
248 if (EFI_ERROR (Status)) {
249 return EFI_UNSUPPORTED;
250 }
251
252 Private = PXE_DHCP4_PRIVATE_DATA_FROM_THIS (PxeDhcp4);
253
254 //
255 // Release allocated resources
256 //
257 if (Private->PxeDhcp4.Data) {
258 FreePool (Private->PxeDhcp4.Data);
259 Private->PxeDhcp4.Data = NULL;
260 }
261 //
262 // Uninstall our protocol
263 //
264 Status = gBS->UninstallProtocolInterface (
265 ControllerHandle,
266 &gEfiPxeDhcp4ProtocolGuid,
267 &Private->PxeDhcp4
268 );
269
270 if (EFI_ERROR (Status)) {
271 return Status;
272 }
273 //
274 // Close any consumed protocols
275 //
276 Status = gBS->CloseProtocol (
277 ControllerHandle,
278 &gEfiPxeBaseCodeProtocolGuid,
279 This->DriverBindingHandle,
280 ControllerHandle
281 );
282
283 if (EFI_ERROR (Status)) {
284 return Status;
285 }
286 //
287 // Release our private data
288 //
289 FreePool (Private);
290
291 return Status;
292 }
293
294 /* EOF - PxeDhcp4.c */