]>
Commit | Line | Data |
---|---|---|
772db4bb | 1 | /** @file\r |
d1102dba LG |
2 | \r |
3 | Copyright (c) 2005 - 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 | |
8 | #include "Ip4Impl.h"\r | |
9 | \r | |
10 | //\r | |
11 | // EFI Component Name Functions\r | |
12 | //\r | |
83cbd279 | 13 | /**\r |
14 | Retrieves a Unicode string that is the user readable name of the driver.\r | |
15 | \r | |
16 | This function retrieves the user readable name of a driver in the form of a\r | |
17 | Unicode string. If the driver specified by This has a user readable name in\r | |
18 | the language specified by Language, then a pointer to the driver name is\r | |
19 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
20 | by This does not support the language specified by Language,\r | |
21 | then EFI_UNSUPPORTED is returned.\r | |
22 | \r | |
3e8c18da | 23 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r |
83cbd279 | 24 | EFI_COMPONENT_NAME_PROTOCOL instance.\r |
25 | \r | |
3e8c18da | 26 | @param[in] Language A pointer to a Null-terminated ASCII string\r |
83cbd279 | 27 | array indicating the language. This is the\r |
28 | language of the driver name that the caller is\r | |
29 | requesting, and it must match one of the\r | |
30 | languages specified in SupportedLanguages. The\r | |
31 | number of languages supported by a driver is up\r | |
32 | to the driver writer. Language is specified\r | |
0254efc0 | 33 | in RFC 4646 or ISO 639-2 language code format.\r |
83cbd279 | 34 | \r |
3e8c18da | 35 | @param[out] DriverName A pointer to the Unicode string to return.\r |
83cbd279 | 36 | This Unicode string is the name of the\r |
37 | driver specified by This in the language\r | |
38 | specified by Language.\r | |
39 | \r | |
40 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
41 | This and the language specified by Language was\r | |
42 | returned in DriverName.\r | |
43 | \r | |
44 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
45 | \r | |
46 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
47 | \r | |
48 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
49 | the language specified by Language.\r | |
50 | \r | |
51 | **/\r | |
772db4bb | 52 | EFI_STATUS\r |
53 | EFIAPI\r | |
54 | Ip4ComponentNameGetDriverName (\r | |
55 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
56 | IN CHAR8 *Language,\r | |
57 | OUT CHAR16 **DriverName\r | |
58 | );\r | |
59 | \r | |
83cbd279 | 60 | \r |
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 | Ip4ComponentNameGetControllerName (\r | |
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 | |
137 | );\r | |
138 | \r | |
83cbd279 | 139 | \r |
772db4bb | 140 | //\r |
141 | // EFI Component Name Protocol\r | |
142 | //\r | |
1307dcd7 | 143 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIp4ComponentName = {\r |
772db4bb | 144 | Ip4ComponentNameGetDriverName,\r |
145 | Ip4ComponentNameGetControllerName,\r | |
146 | "eng"\r | |
1307dcd7 | 147 | };\r |
83cbd279 | 148 | \r |
149 | //\r | |
150 | // EFI Component Name 2 Protocol\r | |
151 | //\r | |
1307dcd7 | 152 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIp4ComponentName2 = {\r |
83cbd279 | 153 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Ip4ComponentNameGetDriverName,\r |
154 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Ip4ComponentNameGetControllerName,\r | |
155 | "en"\r | |
1307dcd7 | 156 | };\r |
83cbd279 | 157 | \r |
772db4bb | 158 | \r |
d1aeb0bd | 159 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIp4DriverNameTable[] = {\r |
772db4bb | 160 | {\r |
83cbd279 | 161 | "eng;en",\r |
772db4bb | 162 | L"IP4 Network Service Driver"\r |
163 | },\r | |
164 | {\r | |
165 | NULL,\r | |
166 | NULL\r | |
167 | }\r | |
168 | };\r | |
169 | \r | |
216f7970 | 170 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIp4ControllerNameTable = NULL;\r |
171 | \r | |
83cbd279 | 172 | /**\r |
173 | Retrieves a Unicode string that is the user readable name of the driver.\r | |
174 | \r | |
175 | This function retrieves the user readable name of a driver in the form of a\r | |
176 | Unicode string. If the driver specified by This has a user readable name in\r | |
177 | the language specified by Language, then a pointer to the driver name is\r | |
178 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
179 | by This does not support the language specified by Language,\r | |
180 | then EFI_UNSUPPORTED is returned.\r | |
181 | \r | |
3e8c18da | 182 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r |
83cbd279 | 183 | EFI_COMPONENT_NAME_PROTOCOL instance.\r |
184 | \r | |
3e8c18da | 185 | @param[in] Language A pointer to a Null-terminated ASCII string\r |
83cbd279 | 186 | array indicating the language. This is the\r |
187 | language of the driver name that the caller is\r | |
188 | requesting, and it must match one of the\r | |
189 | languages specified in SupportedLanguages. The\r | |
190 | number of languages supported by a driver is up\r | |
191 | to the driver writer. Language is specified\r | |
0254efc0 | 192 | in RFC 4646 or ISO 639-2 language code format.\r |
83cbd279 | 193 | \r |
3e8c18da | 194 | @param[out] DriverName A pointer to the Unicode string to return.\r |
83cbd279 | 195 | This Unicode string is the name of the\r |
196 | driver specified by This in the language\r | |
197 | specified by Language.\r | |
198 | \r | |
199 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
200 | This and the language specified by Language was\r | |
201 | returned in DriverName.\r | |
202 | \r | |
203 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
204 | \r | |
205 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
206 | \r | |
207 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
208 | the language specified by Language.\r | |
209 | \r | |
210 | **/\r | |
772db4bb | 211 | EFI_STATUS\r |
212 | EFIAPI\r | |
213 | Ip4ComponentNameGetDriverName (\r | |
214 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
215 | IN CHAR8 *Language,\r | |
216 | OUT CHAR16 **DriverName\r | |
217 | )\r | |
772db4bb | 218 | {\r |
83cbd279 | 219 | return LookupUnicodeString2 (\r |
220 | Language,\r | |
221 | This->SupportedLanguages,\r | |
222 | mIp4DriverNameTable,\r | |
223 | DriverName,\r | |
224 | (BOOLEAN)(This == &gIp4ComponentName)\r | |
225 | );\r | |
772db4bb | 226 | \r |
227 | }\r | |
228 | \r | |
216f7970 | 229 | /**\r |
230 | Update the component name for the IP4 child handle.\r | |
231 | \r | |
232 | @param Ip4[in] A pointer to the EFI_IP4_PROTOCOL.\r | |
233 | \r | |
d1102dba | 234 | \r |
216f7970 | 235 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r |
236 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
d1102dba | 237 | \r |
216f7970 | 238 | **/\r |
239 | EFI_STATUS\r | |
240 | UpdateName (\r | |
241 | IN EFI_IP4_PROTOCOL *Ip4\r | |
242 | )\r | |
243 | {\r | |
244 | EFI_STATUS Status;\r | |
245 | CHAR16 HandleName[80];\r | |
246 | EFI_IP4_MODE_DATA Ip4ModeData;\r | |
247 | \r | |
248 | if (Ip4 == NULL) {\r | |
249 | return EFI_INVALID_PARAMETER;\r | |
250 | }\r | |
251 | \r | |
252 | //\r | |
253 | // Format the child name into the string buffer as:\r | |
254 | // IPv4 (SrcIP=127.0.0.1, DestIP=127.0.0.1)\r | |
255 | //\r | |
256 | Status = Ip4->GetModeData (Ip4, &Ip4ModeData, NULL, NULL);\r | |
257 | if (EFI_ERROR (Status)) {\r | |
258 | return Status;\r | |
259 | }\r | |
260 | \r | |
261 | if (!Ip4ModeData.IsStarted || !Ip4ModeData.IsConfigured) {\r | |
262 | UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv4 (Not started)");\r | |
263 | } else {\r | |
264 | UnicodeSPrint (HandleName, sizeof (HandleName),\r | |
265 | L"IPv4 (SrcIP=%d.%d.%d.%d)",\r | |
266 | Ip4ModeData.ConfigData.StationAddress.Addr[0],\r | |
267 | Ip4ModeData.ConfigData.StationAddress.Addr[1],\r | |
268 | Ip4ModeData.ConfigData.StationAddress.Addr[2],\r | |
269 | Ip4ModeData.ConfigData.StationAddress.Addr[3]\r | |
270 | );\r | |
271 | }\r | |
272 | \r | |
273 | if (gIp4ControllerNameTable != NULL) {\r | |
274 | FreeUnicodeStringTable (gIp4ControllerNameTable);\r | |
275 | gIp4ControllerNameTable = NULL;\r | |
276 | }\r | |
277 | Status = AddUnicodeString2 (\r | |
278 | "eng",\r | |
279 | gIp4ComponentName.SupportedLanguages,\r | |
280 | &gIp4ControllerNameTable,\r | |
281 | HandleName,\r | |
282 | TRUE\r | |
283 | );\r | |
284 | if (EFI_ERROR (Status)) {\r | |
285 | return Status;\r | |
286 | }\r | |
d1102dba | 287 | \r |
216f7970 | 288 | return AddUnicodeString2 (\r |
289 | "en",\r | |
290 | gIp4ComponentName2.SupportedLanguages,\r | |
291 | &gIp4ControllerNameTable,\r | |
292 | HandleName,\r | |
293 | FALSE\r | |
294 | );\r | |
295 | }\r | |
296 | \r | |
83cbd279 | 297 | /**\r |
298 | Retrieves a Unicode string that is the user readable name of the controller\r | |
299 | that is being managed by a driver.\r | |
300 | \r | |
301 | This function retrieves the user readable name of the controller specified by\r | |
302 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
303 | driver specified by This has a user readable name in the language specified by\r | |
304 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
305 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
306 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
307 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
308 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
309 | \r | |
3e8c18da | 310 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r |
83cbd279 | 311 | EFI_COMPONENT_NAME_PROTOCOL instance.\r |
312 | \r | |
3e8c18da | 313 | @param[in] ControllerHandle The handle of a controller that the driver\r |
83cbd279 | 314 | specified by This is managing. This handle\r |
315 | specifies the controller whose name is to be\r | |
316 | returned.\r | |
317 | \r | |
3e8c18da | 318 | @param[in] ChildHandle The handle of the child controller to retrieve\r |
83cbd279 | 319 | the name of. This is an optional parameter that\r |
320 | may be NULL. It will be NULL for device\r | |
321 | drivers. It will also be NULL for a bus drivers\r | |
322 | that wish to retrieve the name of the bus\r | |
323 | controller. It will not be NULL for a bus\r | |
324 | driver that wishes to retrieve the name of a\r | |
325 | child controller.\r | |
326 | \r | |
3e8c18da | 327 | @param[in] Language A pointer to a Null-terminated ASCII string\r |
83cbd279 | 328 | array indicating the language. This is the\r |
329 | language of the driver name that the caller is\r | |
330 | requesting, and it must match one of the\r | |
331 | languages specified in SupportedLanguages. The\r | |
332 | number of languages supported by a driver is up\r | |
333 | to the driver writer. Language is specified in\r | |
0254efc0 | 334 | RFC 4646 or ISO 639-2 language code format.\r |
83cbd279 | 335 | \r |
3e8c18da | 336 | @param[out] ControllerName A pointer to the Unicode string to return.\r |
83cbd279 | 337 | This Unicode string is the name of the\r |
338 | controller specified by ControllerHandle and\r | |
339 | ChildHandle in the language specified by\r | |
340 | Language from the point of view of the driver\r | |
341 | specified by This.\r | |
342 | \r | |
343 | @retval EFI_SUCCESS The Unicode string for the user readable name in\r | |
344 | the language specified by Language for the\r | |
345 | driver specified by This was returned in\r | |
346 | DriverName.\r | |
347 | \r | |
284ee2e8 | 348 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
83cbd279 | 349 | \r |
350 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
351 | EFI_HANDLE.\r | |
352 | \r | |
353 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
354 | \r | |
355 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
356 | \r | |
357 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
358 | managing the controller specified by\r | |
359 | ControllerHandle and ChildHandle.\r | |
360 | \r | |
361 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
362 | the language specified by Language.\r | |
363 | \r | |
364 | **/\r | |
772db4bb | 365 | EFI_STATUS\r |
366 | EFIAPI\r | |
367 | Ip4ComponentNameGetControllerName (\r | |
368 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
369 | IN EFI_HANDLE ControllerHandle,\r | |
370 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
371 | IN CHAR8 *Language,\r | |
372 | OUT CHAR16 **ControllerName\r | |
373 | )\r | |
772db4bb | 374 | {\r |
d1102dba | 375 | EFI_STATUS Status;\r |
216f7970 | 376 | EFI_IP4_PROTOCOL *Ip4;\r |
d1102dba | 377 | \r |
216f7970 | 378 | //\r |
379 | // Only provide names for child handles.\r | |
380 | //\r | |
381 | if (ChildHandle == NULL) {\r | |
382 | return EFI_UNSUPPORTED;\r | |
383 | }\r | |
384 | \r | |
d1102dba LG |
385 | //\r |
386 | // Make sure this driver produced ChildHandle\r | |
387 | //\r | |
216f7970 | 388 | Status = EfiTestChildHandle (\r |
389 | ControllerHandle,\r | |
390 | ChildHandle,\r | |
391 | &gEfiManagedNetworkProtocolGuid\r | |
392 | );\r | |
393 | if (EFI_ERROR (Status)) {\r | |
394 | return Status;\r | |
395 | }\r | |
396 | \r | |
d1102dba LG |
397 | //\r |
398 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
399 | //\r | |
216f7970 | 400 | Status = gBS->OpenProtocol (\r |
401 | ChildHandle,\r | |
402 | &gEfiIp4ProtocolGuid,\r | |
403 | (VOID **)&Ip4,\r | |
404 | NULL,\r | |
405 | NULL,\r | |
406 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
407 | );\r | |
408 | if (EFI_ERROR (Status)) {\r | |
409 | return Status;\r | |
410 | }\r | |
411 | \r | |
412 | //\r | |
413 | // Update the component name for this child handle.\r | |
414 | //\r | |
415 | Status = UpdateName (Ip4);\r | |
416 | if (EFI_ERROR (Status)) {\r | |
417 | return Status;\r | |
418 | }\r | |
419 | \r | |
420 | return LookupUnicodeString2 (\r | |
421 | Language,\r | |
422 | This->SupportedLanguages,\r | |
423 | gIp4ControllerNameTable,\r | |
424 | ControllerName,\r | |
425 | (BOOLEAN)(This == &gIp4ComponentName)\r | |
426 | );\r | |
772db4bb | 427 | }\r |
216f7970 | 428 | \r |