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