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