]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/MnpDxe/ComponentName.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / MnpDxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for MnpDxe driver.
3
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "MnpImpl.h"
10
11 //
12 // EFI Component Name Protocol
13 //
14 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName = {
15 MnpComponentNameGetDriverName,
16 MnpComponentNameGetControllerName,
17 "eng"
18 };
19
20 //
21 // EFI Component Name 2 Protocol
22 //
23 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2 = {
24 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)MnpComponentNameGetDriverName,
25 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)MnpComponentNameGetControllerName,
26 "en"
27 };
28
29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
30 {
31 "eng;en",
32 L"MNP Network Service Driver"
33 },
34 {
35 NULL,
36 NULL
37 }
38 };
39
40 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMnpControllerNameTable = NULL;
41
42 /**
43 Retrieves a Unicode string that is the user readable name of the driver.
44
45 This function retrieves the user readable name of a driver in the form of a
46 Unicode string. If the driver specified by This has a user readable name in
47 the language specified by Language, then a pointer to the driver name is
48 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
49 by This does not support the language specified by Language,
50 then EFI_UNSUPPORTED is returned.
51
52 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
53 EFI_COMPONENT_NAME_PROTOCOL instance.
54
55 @param[in] Language A pointer to a Null-terminated ASCII string
56 array indicating the language. This is the
57 language of the driver name that the caller is
58 requesting, and it must match one of the
59 languages specified in SupportedLanguages. The
60 number of languages supported by a driver is up
61 to the driver writer. Language is specified
62 in RFC 4646 or ISO 639-2 language code format.
63
64 @param[out] DriverName A pointer to the Unicode string to return.
65 This Unicode string is the name of the
66 driver specified by This in the language
67 specified by Language.
68
69 @retval EFI_SUCCESS The Unicode string for the Driver specified by
70 This and the language specified by Language was
71 returned in DriverName.
72
73 @retval EFI_INVALID_PARAMETER Language is NULL.
74
75 @retval EFI_INVALID_PARAMETER DriverName is NULL.
76
77 @retval EFI_UNSUPPORTED The driver specified by This does not support
78 the language specified by Language.
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 MnpComponentNameGetDriverName (
84 IN EFI_COMPONENT_NAME_PROTOCOL *This,
85 IN CHAR8 *Language,
86 OUT CHAR16 **DriverName
87 )
88 {
89 return LookupUnicodeString2 (
90 Language,
91 This->SupportedLanguages,
92 mMnpDriverNameTable,
93 DriverName,
94 (BOOLEAN)(This == &gMnpComponentName)
95 );
96 }
97
98 /**
99 Update the component name for the MNP child handle.
100
101 @param Mnp[in] A pointer to the EFI_MANAGED_NETWORK_PROTOCOL.
102
103
104 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
105 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
106
107 **/
108 EFI_STATUS
109 UpdateName (
110 IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp
111 )
112 {
113 EFI_STATUS Status;
114 MNP_INSTANCE_DATA *Instance;
115 CHAR16 HandleName[80];
116 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;
117 EFI_SIMPLE_NETWORK_MODE SnpModeData;
118 UINTN OffSet;
119 UINTN Index;
120
121 if (Mnp == NULL) {
122 return EFI_INVALID_PARAMETER;
123 }
124
125 Instance = MNP_INSTANCE_DATA_FROM_THIS (Mnp);
126 //
127 // Format the child name into the string buffer as:
128 // MNP (MAC=FF-FF-FF-FF-FF-FF, ProtocolType=0x0800, VlanId=0)
129 //
130 Status = Mnp->GetModeData (Mnp, &MnpConfigData, &SnpModeData);
131 if (!EFI_ERROR (Status)) {
132 OffSet = 0;
133 //
134 // Print the MAC address.
135 //
136 OffSet += UnicodeSPrint (
137 HandleName,
138 sizeof (HandleName),
139 L"MNP (MAC="
140 );
141 for (Index = 0; Index < SnpModeData.HwAddressSize; Index++) {
142 OffSet += UnicodeSPrint (
143 HandleName + OffSet,
144 sizeof (HandleName) - OffSet * sizeof (CHAR16),
145 L"%02X-",
146 SnpModeData.CurrentAddress.Addr[Index]
147 );
148 }
149
150 ASSERT (OffSet > 0);
151 //
152 // Remove the last '-'
153 //
154 OffSet--;
155 //
156 // Print the ProtocolType and VLAN ID for this instance.
157 //
158 OffSet += UnicodeSPrint (
159 HandleName + OffSet,
160 sizeof (HandleName) - OffSet * sizeof (CHAR16),
161 L", ProtocolType=0x%X, VlanId=%d)",
162 MnpConfigData.ProtocolTypeFilter,
163 Instance->MnpServiceData->VlanId
164 );
165 } else if (Status == EFI_NOT_STARTED) {
166 UnicodeSPrint (
167 HandleName,
168 sizeof (HandleName),
169 L"MNP (Not started)"
170 );
171 } else {
172 return Status;
173 }
174
175 if (gMnpControllerNameTable != NULL) {
176 FreeUnicodeStringTable (gMnpControllerNameTable);
177 gMnpControllerNameTable = NULL;
178 }
179
180 Status = AddUnicodeString2 (
181 "eng",
182 gMnpComponentName.SupportedLanguages,
183 &gMnpControllerNameTable,
184 HandleName,
185 TRUE
186 );
187 if (EFI_ERROR (Status)) {
188 return Status;
189 }
190
191 return AddUnicodeString2 (
192 "en",
193 gMnpComponentName2.SupportedLanguages,
194 &gMnpControllerNameTable,
195 HandleName,
196 FALSE
197 );
198 }
199
200 /**
201 Retrieves a Unicode string that is the user readable name of the controller
202 that is being managed by a driver.
203
204 This function retrieves the user readable name of the controller specified by
205 ControllerHandle and ChildHandle in the form of a Unicode string. If the
206 driver specified by This has a user readable name in the language specified by
207 Language, then a pointer to the controller name is returned in ControllerName,
208 and EFI_SUCCESS is returned. If the driver specified by This is not currently
209 managing the controller specified by ControllerHandle and ChildHandle,
210 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
211 support the language specified by Language, then EFI_UNSUPPORTED is returned.
212 Currently not implemented.
213
214 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
215 EFI_COMPONENT_NAME_PROTOCOL instance.
216
217 @param[in] ControllerHandle The handle of a controller that the driver
218 specified by This is managing. This handle
219 specifies the controller whose name is to be
220 returned.
221
222 @param[in] ChildHandle The handle of the child controller to retrieve
223 the name of. This is an optional parameter that
224 may be NULL. It will be NULL for device
225 drivers. It will also be NULL for a bus drivers
226 that wish to retrieve the name of the bus
227 controller. It will not be NULL for a bus
228 driver that wishes to retrieve the name of a
229 child controller.
230
231 @param[in] Language A pointer to a Null-terminated ASCII string
232 array indicating the language. This is the
233 language of the driver name that the caller is
234 requesting, and it must match one of the
235 languages specified in SupportedLanguages. The
236 number of languages supported by a driver is up
237 to the driver writer. Language is specified in
238 RFC 4646 or ISO 639-2 language code format.
239
240 @param[out] ControllerName A pointer to the Unicode string to return.
241 This Unicode string is the name of the
242 controller specified by ControllerHandle and
243 ChildHandle in the language specified by
244 Language from the point of view of the driver
245 specified by This.
246
247 @retval EFI_SUCCESS The Unicode string for the user readable name
248 specified by This, ControllerHandle, ChildHandle,
249 and Language was returned in ControllerName.
250
251 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
252
253 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
254 EFI_HANDLE.
255
256 @retval EFI_INVALID_PARAMETER Language is NULL.
257
258 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
259
260 @retval EFI_UNSUPPORTED The driver specified by This is not currently
261 managing the controller specified by
262 ControllerHandle and ChildHandle.
263
264 @retval EFI_UNSUPPORTED The driver specified by This does not support
265 the language specified by Language.
266
267 **/
268 EFI_STATUS
269 EFIAPI
270 MnpComponentNameGetControllerName (
271 IN EFI_COMPONENT_NAME_PROTOCOL *This,
272 IN EFI_HANDLE ControllerHandle,
273 IN EFI_HANDLE ChildHandle OPTIONAL,
274 IN CHAR8 *Language,
275 OUT CHAR16 **ControllerName
276 )
277 {
278 EFI_STATUS Status;
279 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
280
281 //
282 // Only provide names for MNP child handles.
283 //
284 if (ChildHandle == NULL) {
285 return EFI_UNSUPPORTED;
286 }
287
288 //
289 // Make sure this driver is currently managing ControllerHandle
290 //
291 Status = EfiTestManagedDevice (
292 ControllerHandle,
293 gMnpDriverBinding.DriverBindingHandle,
294 &gEfiSimpleNetworkProtocolGuid
295 );
296 if (EFI_ERROR (Status)) {
297 return Status;
298 }
299
300 //
301 // Make sure this driver produced ChildHandle
302 //
303 Status = EfiTestChildHandle (
304 ControllerHandle,
305 ChildHandle,
306 &gEfiManagedNetworkServiceBindingProtocolGuid
307 );
308 if (EFI_ERROR (Status)) {
309 return Status;
310 }
311
312 //
313 // Retrieve an instance of a produced protocol from ChildHandle
314 //
315 Status = gBS->OpenProtocol (
316 ChildHandle,
317 &gEfiManagedNetworkProtocolGuid,
318 (VOID **)&Mnp,
319 NULL,
320 NULL,
321 EFI_OPEN_PROTOCOL_GET_PROTOCOL
322 );
323 if (EFI_ERROR (Status)) {
324 return Status;
325 }
326
327 //
328 // Update the component name for this child handle.
329 //
330 Status = UpdateName (Mnp);
331 if (EFI_ERROR (Status)) {
332 return Status;
333 }
334
335 return LookupUnicodeString2 (
336 Language,
337 This->SupportedLanguages,
338 gMnpControllerNameTable,
339 ControllerName,
340 (BOOLEAN)(This == &gMnpComponentName)
341 );
342 }