]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | \r | |
3 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
4 | This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | **/\r | |
13 | \r | |
14 | \r | |
15 | #include "Dhcp4Impl.h"\r | |
16 | \r | |
17 | //\r | |
18 | // EFI Component Name Functions\r | |
19 | //\r | |
20 | /**\r | |
21 | Retrieves a Unicode string that is the user readable name of the driver.\r | |
22 | \r | |
23 | This function retrieves the user readable name of a driver in the form of a\r | |
24 | Unicode string. If the driver specified by This has a user readable name in\r | |
25 | the language specified by Language, then a pointer to the driver name is\r | |
26 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
27 | by This does not support the language specified by Language,\r | |
28 | then EFI_UNSUPPORTED is returned.\r | |
29 | \r | |
30 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
31 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
32 | \r | |
33 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
34 | array indicating the language. This is the\r | |
35 | language of the driver name that the caller is\r | |
36 | requesting, and it must match one of the\r | |
37 | languages specified in SupportedLanguages. The\r | |
38 | number of languages supported by a driver is up\r | |
39 | to the driver writer. Language is specified\r | |
40 | in RFC 4646 or ISO 639-2 language code format.\r | |
41 | \r | |
42 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
43 | This Unicode string is the name of the\r | |
44 | driver specified by This in the language\r | |
45 | specified by Language.\r | |
46 | \r | |
47 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
48 | This and the language specified by Language was\r | |
49 | returned in DriverName.\r | |
50 | \r | |
51 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
52 | \r | |
53 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
54 | \r | |
55 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
56 | the language specified by Language.\r | |
57 | \r | |
58 | **/\r | |
59 | EFI_STATUS\r | |
60 | EFIAPI\r | |
61 | DhcpComponentNameGetDriverName (\r | |
62 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
63 | IN CHAR8 *Language,\r | |
64 | OUT CHAR16 **DriverName\r | |
65 | );\r | |
66 | \r | |
67 | \r | |
68 | /**\r | |
69 | Retrieves a Unicode string that is the user readable name of the controller\r | |
70 | that is being managed by a driver.\r | |
71 | \r | |
72 | This function retrieves the user readable name of the controller specified by\r | |
73 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
74 | driver specified by This has a user readable name in the language specified by\r | |
75 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
76 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
77 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
78 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
79 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
80 | \r | |
81 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
82 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
83 | \r | |
84 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
85 | specified by This is managing. This handle\r | |
86 | specifies the controller whose name is to be\r | |
87 | returned.\r | |
88 | \r | |
89 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
90 | the name of. This is an optional parameter that\r | |
91 | may be NULL. It will be NULL for device\r | |
92 | drivers. It will also be NULL for a bus drivers\r | |
93 | that wish to retrieve the name of the bus\r | |
94 | controller. It will not be NULL for a bus\r | |
95 | driver that wishes to retrieve the name of a\r | |
96 | child controller.\r | |
97 | \r | |
98 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
99 | array indicating the language. This is the\r | |
100 | language of the driver name that the caller is\r | |
101 | requesting, and it must match one of the\r | |
102 | languages specified in SupportedLanguages. The\r | |
103 | number of languages supported by a driver is up\r | |
104 | to the driver writer. Language is specified in\r | |
105 | RFC 4646 or ISO 639-2 language code format.\r | |
106 | \r | |
107 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
108 | This Unicode string is the name of the\r | |
109 | controller specified by ControllerHandle and\r | |
110 | ChildHandle in the language specified by\r | |
111 | Language from the point of view of the driver\r | |
112 | specified by This.\r | |
113 | \r | |
114 | @retval EFI_SUCCESS The Unicode string for the user readable name in\r | |
115 | the language specified by Language for the\r | |
116 | driver specified by This was returned in\r | |
117 | DriverName.\r | |
118 | \r | |
119 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r | |
120 | \r | |
121 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
122 | EFI_HANDLE.\r | |
123 | \r | |
124 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
125 | \r | |
126 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
127 | \r | |
128 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
129 | managing the controller specified by\r | |
130 | ControllerHandle and ChildHandle.\r | |
131 | \r | |
132 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
133 | the language specified by Language.\r | |
134 | \r | |
135 | **/\r | |
136 | EFI_STATUS\r | |
137 | EFIAPI\r | |
138 | DhcpComponentNameGetControllerName (\r | |
139 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
140 | IN EFI_HANDLE ControllerHandle,\r | |
141 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
142 | IN CHAR8 *Language,\r | |
143 | OUT CHAR16 **ControllerName\r | |
144 | );\r | |
145 | \r | |
146 | \r | |
147 | //\r | |
148 | // EFI Component Name Protocol\r | |
149 | //\r | |
150 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDhcp4ComponentName = {\r | |
151 | DhcpComponentNameGetDriverName,\r | |
152 | DhcpComponentNameGetControllerName,\r | |
153 | "eng"\r | |
154 | };\r | |
155 | \r | |
156 | //\r | |
157 | // EFI Component Name 2 Protocol\r | |
158 | //\r | |
159 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDhcp4ComponentName2 = {\r | |
160 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) DhcpComponentNameGetDriverName,\r | |
161 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) DhcpComponentNameGetControllerName,\r | |
162 | "en"\r | |
163 | };\r | |
164 | \r | |
165 | \r | |
166 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDhcpDriverNameTable[] = {\r | |
167 | {\r | |
168 | "eng;en",\r | |
169 | L"DHCP Protocol Driver"\r | |
170 | },\r | |
171 | {\r | |
172 | NULL,\r | |
173 | NULL\r | |
174 | }\r | |
175 | };\r | |
176 | \r | |
177 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDhcpControllerNameTable = NULL;\r | |
178 | \r | |
179 | CHAR16 *mDhcp4ControllerName[] = {\r | |
180 | L"DHCPv4 (State=0, Stopped)",\r | |
181 | L"DHCPv4 (State=1, Init)",\r | |
182 | L"DHCPv4 (State=2, Selecting)",\r | |
183 | L"DHCPv4 (State=3, Requesting)",\r | |
184 | L"DHCPv4 (State=4, Bound)",\r | |
185 | L"DHCPv4 (State=5, Renewing)",\r | |
186 | L"DHCPv4 (State=6, Rebinding)",\r | |
187 | L"DHCPv4 (State=7, InitReboot)",\r | |
188 | L"DHCPv4 (State=8, Rebooting)"\r | |
189 | };\r | |
190 | \r | |
191 | /**\r | |
192 | Retrieves a Unicode string that is the user readable name of the driver.\r | |
193 | \r | |
194 | This function retrieves the user readable name of a driver in the form of a\r | |
195 | Unicode string. If the driver specified by This has a user readable name in\r | |
196 | the language specified by Language, then a pointer to the driver name is\r | |
197 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
198 | by This does not support the language specified by Language,\r | |
199 | then EFI_UNSUPPORTED is returned.\r | |
200 | \r | |
201 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
202 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
203 | \r | |
204 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
205 | array indicating the language. This is the\r | |
206 | language of the driver name that the caller is\r | |
207 | requesting, and it must match one of the\r | |
208 | languages specified in SupportedLanguages. The\r | |
209 | number of languages supported by a driver is up\r | |
210 | to the driver writer. Language is specified\r | |
211 | in RFC 4646 or ISO 639-2 language code format.\r | |
212 | \r | |
213 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
214 | This Unicode string is the name of the\r | |
215 | driver specified by This in the language\r | |
216 | specified by Language.\r | |
217 | \r | |
218 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
219 | This and the language specified by Language was\r | |
220 | returned in DriverName.\r | |
221 | \r | |
222 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
223 | \r | |
224 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
225 | \r | |
226 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
227 | the language specified by Language.\r | |
228 | \r | |
229 | **/\r | |
230 | EFI_STATUS\r | |
231 | EFIAPI\r | |
232 | DhcpComponentNameGetDriverName (\r | |
233 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
234 | IN CHAR8 *Language,\r | |
235 | OUT CHAR16 **DriverName\r | |
236 | )\r | |
237 | {\r | |
238 | return LookupUnicodeString2 (\r | |
239 | Language,\r | |
240 | This->SupportedLanguages,\r | |
241 | mDhcpDriverNameTable,\r | |
242 | DriverName,\r | |
243 | (BOOLEAN)(This == &gDhcp4ComponentName)\r | |
244 | );\r | |
245 | }\r | |
246 | \r | |
247 | /**\r | |
248 | Update the component name for the Dhcp4 child handle.\r | |
249 | \r | |
250 | @param Dhcp4[in] A pointer to the EFI_DHCP4_PROTOCOL.\r | |
251 | \r | |
252 | \r | |
253 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r | |
254 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
255 | @retval EFI_DEVICE_ERROR DHCP is in unknown state.\r | |
256 | \r | |
257 | **/\r | |
258 | EFI_STATUS\r | |
259 | UpdateName (\r | |
260 | IN EFI_DHCP4_PROTOCOL *Dhcp4\r | |
261 | )\r | |
262 | {\r | |
263 | EFI_STATUS Status;\r | |
264 | EFI_DHCP4_MODE_DATA Dhcp4ModeData;\r | |
265 | \r | |
266 | if (Dhcp4 == NULL) {\r | |
267 | return EFI_INVALID_PARAMETER;\r | |
268 | }\r | |
269 | \r | |
270 | //\r | |
271 | // Format the child name into the string buffer.\r | |
272 | //\r | |
273 | Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4ModeData);\r | |
274 | if (EFI_ERROR (Status)) {\r | |
275 | return Status;\r | |
276 | }\r | |
277 | \r | |
278 | if (gDhcpControllerNameTable != NULL) {\r | |
279 | FreeUnicodeStringTable (gDhcpControllerNameTable);\r | |
280 | gDhcpControllerNameTable = NULL;\r | |
281 | }\r | |
282 | \r | |
283 | if (Dhcp4ModeData.State > Dhcp4Rebooting) {\r | |
284 | return EFI_DEVICE_ERROR;\r | |
285 | }\r | |
286 | \r | |
287 | Status = AddUnicodeString2 (\r | |
288 | "eng",\r | |
289 | gDhcp4ComponentName.SupportedLanguages,\r | |
290 | &gDhcpControllerNameTable,\r | |
291 | mDhcp4ControllerName[Dhcp4ModeData.State],\r | |
292 | TRUE\r | |
293 | );\r | |
294 | if (EFI_ERROR (Status)) {\r | |
295 | return Status;\r | |
296 | }\r | |
297 | \r | |
298 | return AddUnicodeString2 (\r | |
299 | "en",\r | |
300 | gDhcp4ComponentName2.SupportedLanguages,\r | |
301 | &gDhcpControllerNameTable,\r | |
302 | mDhcp4ControllerName[Dhcp4ModeData.State],\r | |
303 | FALSE\r | |
304 | );\r | |
305 | }\r | |
306 | \r | |
307 | /**\r | |
308 | Retrieves a Unicode string that is the user readable name of the controller\r | |
309 | that is being managed by a driver.\r | |
310 | \r | |
311 | This function retrieves the user readable name of the controller specified by\r | |
312 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
313 | driver specified by This has a user readable name in the language specified by\r | |
314 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
315 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
316 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
317 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
318 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
319 | \r | |
320 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
321 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
322 | \r | |
323 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
324 | specified by This is managing. This handle\r | |
325 | specifies the controller whose name is to be\r | |
326 | returned.\r | |
327 | \r | |
328 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
329 | the name of. This is an optional parameter that\r | |
330 | may be NULL. It will be NULL for device\r | |
331 | drivers. It will also be NULL for a bus drivers\r | |
332 | that wish to retrieve the name of the bus\r | |
333 | controller. It will not be NULL for a bus\r | |
334 | driver that wishes to retrieve the name of a\r | |
335 | child controller.\r | |
336 | \r | |
337 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
338 | array indicating the language. This is the\r | |
339 | language of the driver name that the caller is\r | |
340 | requesting, and it must match one of the\r | |
341 | languages specified in SupportedLanguages. The\r | |
342 | number of languages supported by a driver is up\r | |
343 | to the driver writer. Language is specified in\r | |
344 | RFC 4646 or ISO 639-2 language code format.\r | |
345 | \r | |
346 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
347 | This Unicode string is the name of the\r | |
348 | controller specified by ControllerHandle and\r | |
349 | ChildHandle in the language specified by\r | |
350 | Language from the point of view of the driver\r | |
351 | specified by This.\r | |
352 | \r | |
353 | @retval EFI_SUCCESS The Unicode string for the user readable name in\r | |
354 | the language specified by Language for the\r | |
355 | driver specified by This was returned in\r | |
356 | DriverName.\r | |
357 | \r | |
358 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r | |
359 | \r | |
360 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
361 | EFI_HANDLE.\r | |
362 | \r | |
363 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
364 | \r | |
365 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
366 | \r | |
367 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
368 | managing the controller specified by\r | |
369 | ControllerHandle and ChildHandle.\r | |
370 | \r | |
371 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
372 | the language specified by Language.\r | |
373 | \r | |
374 | **/\r | |
375 | EFI_STATUS\r | |
376 | EFIAPI\r | |
377 | DhcpComponentNameGetControllerName (\r | |
378 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
379 | IN EFI_HANDLE ControllerHandle,\r | |
380 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
381 | IN CHAR8 *Language,\r | |
382 | OUT CHAR16 **ControllerName\r | |
383 | )\r | |
384 | {\r | |
385 | EFI_STATUS Status;\r | |
386 | EFI_DHCP4_PROTOCOL *Dhcp4;\r | |
387 | \r | |
388 | //\r | |
389 | // Only provide names for child handles.\r | |
390 | //\r | |
391 | if (ChildHandle == NULL) {\r | |
392 | return EFI_UNSUPPORTED;\r | |
393 | }\r | |
394 | \r | |
395 | //\r | |
396 | // Make sure this driver produced ChildHandle\r | |
397 | //\r | |
398 | Status = EfiTestChildHandle (\r | |
399 | ControllerHandle,\r | |
400 | ChildHandle,\r | |
401 | &gEfiUdp4ProtocolGuid\r | |
402 | );\r | |
403 | if (EFI_ERROR (Status)) {\r | |
404 | return Status;\r | |
405 | }\r | |
406 | \r | |
407 | //\r | |
408 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
409 | //\r | |
410 | Status = gBS->OpenProtocol (\r | |
411 | ChildHandle,\r | |
412 | &gEfiDhcp4ProtocolGuid,\r | |
413 | (VOID **)&Dhcp4,\r | |
414 | NULL,\r | |
415 | NULL,\r | |
416 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
417 | );\r | |
418 | if (EFI_ERROR (Status)) {\r | |
419 | return Status;\r | |
420 | }\r | |
421 | \r | |
422 | //\r | |
423 | // Update the component name for this child handle.\r | |
424 | //\r | |
425 | Status = UpdateName (Dhcp4);\r | |
426 | if (EFI_ERROR (Status)) {\r | |
427 | return Status;\r | |
428 | }\r | |
429 | \r | |
430 | return LookupUnicodeString2 (\r | |
431 | Language,\r | |
432 | This->SupportedLanguages,\r | |
433 | gDhcpControllerNameTable,\r | |
434 | ControllerName,\r | |
435 | (BOOLEAN)(This == &gDhcp4ComponentName)\r | |
436 | );\r | |
437 | }\r |