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