1 /** @file
2   UEFI Component Name(2) protocol implementation for ArpDxe driver.
3 
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #include "ArpDriver.h"
10 
11 
12 //
13 // EFI Component Name Protocol
14 //
15 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gArpComponentName = {
16   ArpComponentNameGetDriverName,
17   ArpComponentNameGetControllerName,
18   "eng"
19 };
20 
21 //
22 // EFI Component Name 2 Protocol
23 //
24 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gArpComponentName2 = {
25   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) ArpComponentNameGetDriverName,
26   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) ArpComponentNameGetControllerName,
27   "en"
28 };
29 
30 
31 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mArpDriverNameTable[] = {
32   { "eng;en", L"ARP Network Service Driver" },
33   { NULL, NULL }
34 };
35 
36 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mArpControllerNameTable[] = {
37   { "eng;en", L"ARP Controller" },
38   { NULL, NULL }
39 };
40 
41 /**
42   Retrieves a Unicode string that is the user readable name of the driver.
43 
44   This function retrieves the user readable name of a driver in the form of a
45   Unicode string. If the driver specified by This has a user readable name in
46   the language specified by Language, then a pointer to the driver name is
47   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
48   by This does not support the language specified by Language,
49   then EFI_UNSUPPORTED is returned.
50 
51   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
52                                 EFI_COMPONENT_NAME_PROTOCOL instance.
53 
54   @param[in]  Language          A pointer to a Null-terminated ASCII string
55                                 array indicating the language. This is the
56                                 language of the driver name that the caller is
57                                 requesting, and it must match one of the
58                                 languages specified in SupportedLanguages. The
59                                 number of languages supported by a driver is up
60                                 to the driver writer. Language is specified
61                                 in RFC 4646 or ISO 639-2 language code format.
62 
63   @param[out]  DriverName       A pointer to the Unicode string to return.
64                                 This Unicode string is the name of the
65                                 driver specified by This in the language
66                                 specified by Language.
67 
68   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
69                                 This and the language specified by Language was
70                                 returned in DriverName.
71 
72   @retval EFI_INVALID_PARAMETER Language is NULL.
73 
74   @retval EFI_INVALID_PARAMETER DriverName is NULL.
75 
76   @retval EFI_UNSUPPORTED       The driver specified by This does not support
77                                 the language specified by Language.
78 
79 **/
80 EFI_STATUS
81 EFIAPI
ArpComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)82 ArpComponentNameGetDriverName (
83   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
84   IN  CHAR8                        *Language,
85   OUT CHAR16                       **DriverName
86   )
87 {
88   return LookupUnicodeString2 (
89            Language,
90            This->SupportedLanguages,
91            mArpDriverNameTable,
92            DriverName,
93            (BOOLEAN)(This == &gArpComponentName)
94            );
95 }
96 
97 /**
98   Retrieves a Unicode string that is the user readable name of the controller
99   that is being managed by a driver.
100 
101   This function retrieves the user readable name of the controller specified by
102   ControllerHandle and ChildHandle in the form of a Unicode string. If the
103   driver specified by This has a user readable name in the language specified by
104   Language, then a pointer to the controller name is returned in ControllerName,
105   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
106   managing the controller specified by ControllerHandle and ChildHandle,
107   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
108   support the language specified by Language, then EFI_UNSUPPORTED is returned.
109 
110   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
111                                 EFI_COMPONENT_NAME_PROTOCOL instance.
112 
113   @param[in]  ControllerHandle  The handle of a controller that the driver
114                                 specified by This is managing.  This handle
115                                 specifies the controller whose name is to be
116                                 returned.
117 
118   @param[in]  ChildHandle       The handle of the child controller to retrieve
119                                 the name of.  This is an optional parameter that
120                                 may be NULL.  It will be NULL for device
121                                 drivers.  It will also be NULL for a bus drivers
122                                 that wish to retrieve the name of the bus
123                                 controller.  It will not be NULL for a bus
124                                 driver that wishes to retrieve the name of a
125                                 child controller.
126 
127   @param[in]  Language          A pointer to a Null-terminated ASCII string
128                                 array indicating the language.  This is the
129                                 language of the driver name that the caller is
130                                 requesting, and it must match one of the
131                                 languages specified in SupportedLanguages. The
132                                 number of languages supported by a driver is up
133                                 to the driver writer. Language is specified in
134                                 RFC 4646 or ISO 639-2 language code format.
135 
136   @param[out]  ControllerName   A pointer to the Unicode string to return.
137                                 This Unicode string is the name of the
138                                 controller specified by ControllerHandle and
139                                 ChildHandle in the language specified by
140                                 Language from the point of view of the driver
141                                 specified by This.
142 
143   @retval EFI_SUCCESS           The Unicode string for the user readable name in
144                                 the language specified by Language for the
145                                 driver specified by This was returned in
146                                 DriverName.
147 
148   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
149 
150   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
151                                 EFI_HANDLE.
152 
153   @retval EFI_INVALID_PARAMETER Language is NULL.
154 
155   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
156 
157   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
158                                 managing the controller specified by
159                                 ControllerHandle and ChildHandle.
160 
161   @retval EFI_UNSUPPORTED       The driver specified by This does not support
162                                 the language specified by Language.
163 
164 **/
165 EFI_STATUS
166 EFIAPI
ArpComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)167 ArpComponentNameGetControllerName (
168   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
169   IN  EFI_HANDLE                                      ControllerHandle,
170   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
171   IN  CHAR8                                           *Language,
172   OUT CHAR16                                          **ControllerName
173   )
174 {
175   EFI_STATUS                    Status;
176   EFI_ARP_PROTOCOL              *Arp;
177 
178   //
179   // Only provide names for child handles.
180   //
181   if (ChildHandle == NULL) {
182     return EFI_UNSUPPORTED;
183   }
184 
185   //
186   // Make sure this driver produced ChildHandle
187   //
188   Status = EfiTestChildHandle (
189              ControllerHandle,
190              ChildHandle,
191              &gEfiManagedNetworkProtocolGuid
192              );
193   if (EFI_ERROR (Status)) {
194     return Status;
195   }
196 
197   //
198   // Retrieve an instance of a produced protocol from ChildHandle
199   //
200   Status = gBS->OpenProtocol (
201                   ChildHandle,
202                   &gEfiArpProtocolGuid,
203                  (VOID **)&Arp,
204                   NULL,
205                   NULL,
206                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
207                   );
208   if (EFI_ERROR (Status)) {
209     return Status;
210   }
211 
212   return LookupUnicodeString2 (
213            Language,
214            This->SupportedLanguages,
215            mArpControllerNameTable,
216            ControllerName,
217            (BOOLEAN)(This == &gArpComponentName)
218            );
219 }
220