]>
Commit | Line | Data |
---|---|---|
8a67d61d | 1 | /** @file\r |
6e4bac4d | 2 | UEFI Component Name(2) protocol implementation for MnpDxe driver.\r |
8a67d61d | 3 | \r |
44833d44 | 4 | Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
779ae357 | 6 | are licensed and made available under the terms and conditions\r |
7 | of the BSD License which accompanies this distribution. The full\r | |
8 | text of the license may be found at<BR>\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
8a67d61d | 10 | \r |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT 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 | 21 | GLOBAL_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 | 30 | GLOBAL_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 | 36 | GLOBAL_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 | 47 | GLOBAL_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 | 88 | EFI_STATUS\r |
89 | EFIAPI\r | |
90 | MnpComponentNameGetDriverName (\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 | |
115 | EFI_STATUS\r | |
116 | UpdateName (\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 | |
f8c075d1 | 151 | sizeof (HandleName) - OffSet * sizeof (CHAR16),\r |
216f7970 | 152 | L"%02X-",\r |
153 | SnpModeData.CurrentAddress.Addr[Index]\r | |
154 | );\r | |
155 | }\r | |
44833d44 | 156 | ASSERT (OffSet > 0);\r |
216f7970 | 157 | //\r |
158 | // Remove the last '-'\r | |
159 | //\r | |
160 | OffSet--; \r | |
161 | //\r | |
162 | // Print the ProtocolType and VLAN ID for this instance.\r | |
163 | //\r | |
164 | OffSet += UnicodeSPrint (\r | |
165 | HandleName + OffSet,\r | |
f8c075d1 | 166 | sizeof (HandleName) - OffSet * sizeof (CHAR16),\r |
216f7970 | 167 | L", ProtocolType=0x%X, VlanId=%d)",\r |
168 | MnpConfigData.ProtocolTypeFilter,\r | |
169 | Instance->MnpServiceData->VlanId\r | |
170 | );\r | |
171 | } else if (Status == EFI_NOT_STARTED) {\r | |
172 | UnicodeSPrint (\r | |
173 | HandleName,\r | |
174 | sizeof (HandleName),\r | |
175 | L"MNP (Not started)"\r | |
176 | );\r | |
177 | } else {\r | |
178 | return Status;\r | |
179 | }\r | |
180 | \r | |
181 | if (gMnpControllerNameTable != NULL) {\r | |
182 | FreeUnicodeStringTable (gMnpControllerNameTable);\r | |
183 | gMnpControllerNameTable = NULL;\r | |
184 | }\r | |
185 | \r | |
186 | Status = AddUnicodeString2 (\r | |
187 | "eng",\r | |
188 | gMnpComponentName.SupportedLanguages,\r | |
189 | &gMnpControllerNameTable,\r | |
190 | HandleName,\r | |
191 | TRUE\r | |
192 | );\r | |
193 | if (EFI_ERROR (Status)) {\r | |
194 | return Status;\r | |
195 | }\r | |
196 | \r | |
197 | return AddUnicodeString2 (\r | |
198 | "en",\r | |
199 | gMnpComponentName2.SupportedLanguages,\r | |
200 | &gMnpControllerNameTable,\r | |
201 | HandleName,\r | |
202 | FALSE\r | |
203 | );\r | |
204 | }\r | |
205 | \r | |
83cbd279 | 206 | /**\r |
207 | Retrieves a Unicode string that is the user readable name of the controller\r | |
208 | that is being managed by a driver.\r | |
209 | \r | |
210 | This function retrieves the user readable name of the controller specified by\r | |
211 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
212 | driver specified by This has a user readable name in the language specified by\r | |
213 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
214 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
215 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
216 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
217 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
6e4bac4d | 218 | Currently not implemented.\r |
83cbd279 | 219 | \r |
6e4bac4d | 220 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r |
83cbd279 | 221 | EFI_COMPONENT_NAME_PROTOCOL instance.\r |
222 | \r | |
6e4bac4d | 223 | @param[in] ControllerHandle The handle of a controller that the driver\r |
83cbd279 | 224 | specified by This is managing. This handle\r |
225 | specifies the controller whose name is to be\r | |
226 | returned.\r | |
227 | \r | |
6e4bac4d | 228 | @param[in] ChildHandle The handle of the child controller to retrieve\r |
83cbd279 | 229 | the name of. This is an optional parameter that\r |
230 | may be NULL. It will be NULL for device\r | |
231 | drivers. It will also be NULL for a bus drivers\r | |
232 | that wish to retrieve the name of the bus\r | |
233 | controller. It will not be NULL for a bus\r | |
234 | driver that wishes to retrieve the name of a\r | |
235 | child controller.\r | |
236 | \r | |
6e4bac4d | 237 | @param[in] Language A pointer to a Null-terminated ASCII string\r |
83cbd279 | 238 | array indicating the language. This is the\r |
239 | language of the driver name that the caller is\r | |
240 | requesting, and it must match one of the\r | |
241 | languages specified in SupportedLanguages. The\r | |
242 | number of languages supported by a driver is up\r | |
243 | to the driver writer. Language is specified in\r | |
0254efc0 | 244 | RFC 4646 or ISO 639-2 language code format.\r |
83cbd279 | 245 | \r |
3e8c18da | 246 | @param[out] ControllerName A pointer to the Unicode string to return.\r |
83cbd279 | 247 | This Unicode string is the name of the\r |
248 | controller specified by ControllerHandle and\r | |
249 | ChildHandle in the language specified by\r | |
250 | Language from the point of view of the driver\r | |
251 | specified by This.\r | |
252 | \r | |
779ae357 | 253 | @retval EFI_SUCCESS The Unicode string for the user readable name\r |
6e4bac4d | 254 | specified by This, ControllerHandle, ChildHandle,\r |
779ae357 | 255 | and Language was returned in ControllerName.\r |
83cbd279 | 256 | \r |
284ee2e8 | 257 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
83cbd279 | 258 | \r |
259 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
260 | EFI_HANDLE.\r | |
261 | \r | |
262 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
263 | \r | |
264 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
265 | \r | |
266 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
267 | managing the controller specified by\r | |
268 | ControllerHandle and ChildHandle.\r | |
269 | \r | |
270 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
271 | the language specified by Language.\r | |
272 | \r | |
273 | **/\r | |
8a67d61d | 274 | EFI_STATUS\r |
275 | EFIAPI\r | |
276 | MnpComponentNameGetControllerName (\r | |
779ae357 | 277 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
278 | IN EFI_HANDLE ControllerHandle,\r | |
279 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
280 | IN CHAR8 *Language,\r | |
281 | OUT CHAR16 **ControllerName\r | |
8a67d61d | 282 | )\r |
8a67d61d | 283 | {\r |
216f7970 | 284 | EFI_STATUS Status;\r |
285 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
286 | \r | |
287 | //\r | |
288 | // Only provide names for MNP child handles.\r | |
289 | //\r | |
290 | if (ChildHandle == NULL) {\r | |
291 | return EFI_UNSUPPORTED;\r | |
292 | }\r | |
293 | \r | |
294 | // \r | |
295 | // Make sure this driver is currently managing ControllerHandle \r | |
296 | // \r | |
297 | Status = EfiTestManagedDevice (\r | |
298 | ControllerHandle,\r | |
299 | gMnpDriverBinding.DriverBindingHandle,\r | |
300 | &gEfiSimpleNetworkProtocolGuid\r | |
301 | );\r | |
302 | if (EFI_ERROR (Status)) { \r | |
303 | return Status;\r | |
304 | }\r | |
305 | \r | |
306 | // \r | |
307 | // Make sure this driver produced ChildHandle \r | |
308 | // \r | |
309 | Status = EfiTestChildHandle (\r | |
310 | ControllerHandle,\r | |
311 | ChildHandle,\r | |
312 | &gEfiManagedNetworkServiceBindingProtocolGuid\r | |
313 | );\r | |
314 | if (EFI_ERROR (Status)) {\r | |
315 | return Status;\r | |
316 | }\r | |
317 | \r | |
318 | // \r | |
319 | // Retrieve an instance of a produced protocol from ChildHandle \r | |
320 | // \r | |
321 | Status = gBS->OpenProtocol (\r | |
322 | ChildHandle,\r | |
323 | &gEfiManagedNetworkProtocolGuid,\r | |
324 | (VOID **)&Mnp,\r | |
325 | NULL,\r | |
326 | NULL,\r | |
327 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
328 | );\r | |
329 | if (EFI_ERROR (Status)) {\r | |
330 | return Status;\r | |
331 | }\r | |
332 | \r | |
333 | //\r | |
334 | // Update the component name for this child handle.\r | |
335 | //\r | |
336 | Status = UpdateName (Mnp);\r | |
337 | if (EFI_ERROR (Status)) {\r | |
338 | return Status;\r | |
339 | }\r | |
340 | \r | |
341 | return LookupUnicodeString2 (\r | |
342 | Language,\r | |
343 | This->SupportedLanguages,\r | |
344 | gMnpControllerNameTable,\r | |
345 | ControllerName,\r | |
346 | (BOOLEAN)(This == &gMnpComponentName)\r | |
347 | );\r | |
8a67d61d | 348 | }\r |