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