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