]>
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 | |
779ae357 | 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 |
83cbd279 | 24 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) MnpComponentNameGetDriverName,\r |
25 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) MnpComponentNameGetControllerName,\r | |
26 | "en"\r | |
1307dcd7 | 27 | };\r |
83cbd279 | 28 | \r |
779ae357 | 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 | |
216f7970 | 40 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMnpControllerNameTable = NULL;\r |
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 | |
779ae357 | 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 | |
c57273b0 | 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 | |
110 | IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp\r | |
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 | |
44833d44 | 149 | ASSERT (OffSet > 0);\r |
216f7970 | 150 | //\r |
151 | // Remove the last '-'\r | |
152 | //\r | |
d1102dba | 153 | OffSet--;\r |
216f7970 | 154 | //\r |
155 | // Print the ProtocolType and VLAN ID for this instance.\r | |
156 | //\r | |
157 | OffSet += UnicodeSPrint (\r | |
158 | HandleName + OffSet,\r | |
f8c075d1 | 159 | sizeof (HandleName) - OffSet * sizeof (CHAR16),\r |
216f7970 | 160 | L", ProtocolType=0x%X, VlanId=%d)",\r |
161 | MnpConfigData.ProtocolTypeFilter,\r | |
162 | Instance->MnpServiceData->VlanId\r | |
163 | );\r | |
164 | } else if (Status == EFI_NOT_STARTED) {\r | |
165 | UnicodeSPrint (\r | |
166 | HandleName,\r | |
167 | sizeof (HandleName),\r | |
168 | L"MNP (Not started)"\r | |
169 | );\r | |
170 | } else {\r | |
171 | return Status;\r | |
172 | }\r | |
d1102dba | 173 | \r |
216f7970 | 174 | if (gMnpControllerNameTable != NULL) {\r |
175 | FreeUnicodeStringTable (gMnpControllerNameTable);\r | |
176 | gMnpControllerNameTable = NULL;\r | |
177 | }\r | |
d1102dba | 178 | \r |
216f7970 | 179 | Status = AddUnicodeString2 (\r |
180 | "eng",\r | |
181 | gMnpComponentName.SupportedLanguages,\r | |
182 | &gMnpControllerNameTable,\r | |
183 | HandleName,\r | |
184 | TRUE\r | |
185 | );\r | |
186 | if (EFI_ERROR (Status)) {\r | |
187 | return Status;\r | |
188 | }\r | |
d1102dba | 189 | \r |
216f7970 | 190 | return AddUnicodeString2 (\r |
191 | "en",\r | |
192 | gMnpComponentName2.SupportedLanguages,\r | |
193 | &gMnpControllerNameTable,\r | |
194 | HandleName,\r | |
195 | FALSE\r | |
196 | );\r | |
197 | }\r | |
198 | \r | |
83cbd279 | 199 | /**\r |
200 | Retrieves a Unicode string that is the user readable name of the controller\r | |
201 | that is being managed by a driver.\r | |
202 | \r | |
203 | This function retrieves the user readable name of the controller specified by\r | |
204 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
205 | driver specified by This has a user readable name in the language specified by\r | |
206 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
207 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
208 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
209 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
210 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
6e4bac4d | 211 | Currently not implemented.\r |
83cbd279 | 212 | \r |
6e4bac4d | 213 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r |
83cbd279 | 214 | EFI_COMPONENT_NAME_PROTOCOL instance.\r |
215 | \r | |
6e4bac4d | 216 | @param[in] ControllerHandle The handle of a controller that the driver\r |
83cbd279 | 217 | specified by This is managing. This handle\r |
218 | specifies the controller whose name is to be\r | |
219 | returned.\r | |
220 | \r | |
6e4bac4d | 221 | @param[in] ChildHandle The handle of the child controller to retrieve\r |
83cbd279 | 222 | the name of. This is an optional parameter that\r |
223 | may be NULL. It will be NULL for device\r | |
224 | drivers. It will also be NULL for a bus drivers\r | |
225 | that wish to retrieve the name of the bus\r | |
226 | controller. It will not be NULL for a bus\r | |
227 | driver that wishes to retrieve the name of a\r | |
228 | child controller.\r | |
229 | \r | |
6e4bac4d | 230 | @param[in] Language A pointer to a Null-terminated ASCII string\r |
83cbd279 | 231 | array indicating the language. This is the\r |
232 | language of the driver name that the caller is\r | |
233 | requesting, and it must match one of the\r | |
234 | languages specified in SupportedLanguages. The\r | |
235 | number of languages supported by a driver is up\r | |
236 | to the driver writer. Language is specified in\r | |
0254efc0 | 237 | RFC 4646 or ISO 639-2 language code format.\r |
83cbd279 | 238 | \r |
3e8c18da | 239 | @param[out] ControllerName A pointer to the Unicode string to return.\r |
83cbd279 | 240 | This Unicode string is the name of the\r |
241 | controller specified by ControllerHandle and\r | |
242 | ChildHandle in the language specified by\r | |
243 | Language from the point of view of the driver\r | |
244 | specified by This.\r | |
245 | \r | |
779ae357 | 246 | @retval EFI_SUCCESS The Unicode string for the user readable name\r |
6e4bac4d | 247 | specified by This, ControllerHandle, ChildHandle,\r |
779ae357 | 248 | and Language was returned in ControllerName.\r |
83cbd279 | 249 | \r |
284ee2e8 | 250 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
83cbd279 | 251 | \r |
252 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
253 | EFI_HANDLE.\r | |
254 | \r | |
255 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
256 | \r | |
257 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
258 | \r | |
259 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
260 | managing the controller specified by\r | |
261 | ControllerHandle and ChildHandle.\r | |
262 | \r | |
263 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
264 | the language specified by Language.\r | |
265 | \r | |
266 | **/\r | |
8a67d61d | 267 | EFI_STATUS\r |
268 | EFIAPI\r | |
269 | MnpComponentNameGetControllerName (\r | |
779ae357 | 270 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
271 | IN EFI_HANDLE ControllerHandle,\r | |
272 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
273 | IN CHAR8 *Language,\r | |
274 | OUT CHAR16 **ControllerName\r | |
8a67d61d | 275 | )\r |
8a67d61d | 276 | {\r |
216f7970 | 277 | EFI_STATUS Status;\r |
278 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
279 | \r | |
280 | //\r | |
281 | // Only provide names for MNP child handles.\r | |
282 | //\r | |
283 | if (ChildHandle == NULL) {\r | |
284 | return EFI_UNSUPPORTED;\r | |
285 | }\r | |
d1102dba LG |
286 | \r |
287 | //\r | |
288 | // Make sure this driver is currently managing ControllerHandle\r | |
289 | //\r | |
216f7970 | 290 | Status = EfiTestManagedDevice (\r |
291 | ControllerHandle,\r | |
292 | gMnpDriverBinding.DriverBindingHandle,\r | |
293 | &gEfiSimpleNetworkProtocolGuid\r | |
294 | );\r | |
d1102dba | 295 | if (EFI_ERROR (Status)) {\r |
216f7970 | 296 | return Status;\r |
297 | }\r | |
d1102dba LG |
298 | \r |
299 | //\r | |
300 | // Make sure this driver produced ChildHandle\r | |
301 | //\r | |
216f7970 | 302 | Status = EfiTestChildHandle (\r |
303 | ControllerHandle,\r | |
304 | ChildHandle,\r | |
305 | &gEfiManagedNetworkServiceBindingProtocolGuid\r | |
306 | );\r | |
307 | if (EFI_ERROR (Status)) {\r | |
308 | return Status;\r | |
309 | }\r | |
310 | \r | |
d1102dba LG |
311 | //\r |
312 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
313 | //\r | |
216f7970 | 314 | Status = gBS->OpenProtocol (\r |
315 | ChildHandle,\r | |
316 | &gEfiManagedNetworkProtocolGuid,\r | |
317 | (VOID **)&Mnp,\r | |
318 | NULL,\r | |
319 | NULL,\r | |
320 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
321 | );\r | |
322 | if (EFI_ERROR (Status)) {\r | |
323 | return Status;\r | |
324 | }\r | |
325 | \r | |
326 | //\r | |
327 | // Update the component name for this child handle.\r | |
328 | //\r | |
329 | Status = UpdateName (Mnp);\r | |
330 | if (EFI_ERROR (Status)) {\r | |
331 | return Status;\r | |
332 | }\r | |
333 | \r | |
334 | return LookupUnicodeString2 (\r | |
335 | Language,\r | |
336 | This->SupportedLanguages,\r | |
337 | gMnpControllerNameTable,\r | |
338 | ControllerName,\r | |
339 | (BOOLEAN)(This == &gMnpComponentName)\r | |
340 | );\r | |
8a67d61d | 341 | }\r |