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