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