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