]>
Commit | Line | Data |
---|---|---|
779ae357 | 1 | /** @file\r |
2 | HII Config Access protocol implementation of VLAN configuration module.\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
779ae357 | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "VlanConfigImpl.h"\r | |
10 | \r | |
779ae357 | 11 | CHAR16 mVlanStorageName[] = L"VlanNvData";\r |
12 | EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r | |
13 | \r | |
14 | VLAN_CONFIG_PRIVATE_DATA mVlanConfigPrivateDateTemplate = {\r | |
15 | VLAN_CONFIG_PRIVATE_DATA_SIGNATURE,\r | |
16 | {\r | |
17 | VlanExtractConfig,\r | |
18 | VlanRouteConfig,\r | |
19 | VlanCallback\r | |
20 | }\r | |
21 | };\r | |
22 | \r | |
23 | VENDOR_DEVICE_PATH mHiiVendorDevicePathNode = {\r | |
24 | {\r | |
25 | HARDWARE_DEVICE_PATH,\r | |
26 | HW_VENDOR_DP,\r | |
27 | {\r | |
28 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
29 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
30 | }\r | |
31 | },\r | |
c8ad2d7a | 32 | VLAN_CONFIG_FORM_SET_GUID\r |
779ae357 | 33 | };\r |
34 | \r | |
35 | /**\r | |
36 | This function allows a caller to extract the current configuration for one\r | |
37 | or more named elements from the target driver.\r | |
38 | \r | |
39 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
40 | @param[in] Request A null-terminated Unicode string in\r | |
41 | <ConfigRequest> format.\r | |
42 | @param[out] Progress On return, points to a character in the Request\r | |
43 | string. Points to the string's null terminator if\r | |
44 | request was successful. Points to the most recent\r | |
45 | '&' before the first failing name/value pair (or\r | |
46 | the beginning of the string if the failure is in\r | |
47 | the first name/value pair) if the request was not\r | |
48 | successful.\r | |
49 | @param[out] Results A null-terminated Unicode string in\r | |
50 | <ConfigAltResp> format which has all values filled\r | |
51 | in for the names in the Request string. String to\r | |
52 | be allocated by the called function.\r | |
53 | \r | |
54 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
55 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
5a157365 | 56 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r |
779ae357 | 57 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r |
58 | driver.\r | |
59 | \r | |
60 | **/\r | |
61 | EFI_STATUS\r | |
62 | EFIAPI\r | |
63 | VlanExtractConfig (\r | |
64 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
65 | IN CONST EFI_STRING Request,\r | |
66 | OUT EFI_STRING *Progress,\r | |
67 | OUT EFI_STRING *Results\r | |
68 | )\r | |
69 | {\r | |
59aefb7e LG |
70 | EFI_STATUS Status;\r |
71 | UINTN BufferSize;\r | |
72 | VLAN_CONFIGURATION Configuration;\r | |
73 | VLAN_CONFIG_PRIVATE_DATA *PrivateData;\r | |
74 | EFI_STRING ConfigRequestHdr;\r | |
75 | EFI_STRING ConfigRequest;\r | |
76 | BOOLEAN AllocatedRequest;\r | |
77 | UINTN Size;\r | |
78 | \r | |
79 | if (Progress == NULL || Results == NULL) {\r | |
779ae357 | 80 | return EFI_INVALID_PARAMETER;\r |
81 | }\r | |
82 | \r | |
59aefb7e | 83 | *Progress = Request;\r |
c8ad2d7a | 84 | if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r |
59aefb7e LG |
85 | return EFI_NOT_FOUND;\r |
86 | }\r | |
87 | \r | |
88 | ConfigRequestHdr = NULL;\r | |
89 | ConfigRequest = NULL;\r | |
90 | AllocatedRequest = FALSE;\r | |
91 | Size = 0;\r | |
92 | \r | |
779ae357 | 93 | //\r |
94 | // Retrieve the pointer to the UEFI HII Config Routing Protocol\r | |
95 | //\r | |
96 | if (mHiiConfigRouting == NULL) {\r | |
97 | gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mHiiConfigRouting);\r | |
98 | }\r | |
99 | ASSERT (mHiiConfigRouting != NULL);\r | |
100 | \r | |
101 | //\r | |
102 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r | |
103 | //\r | |
59aefb7e | 104 | PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r |
779ae357 | 105 | ZeroMem (&Configuration, sizeof (VLAN_CONFIGURATION));\r |
5a157365 | 106 | BufferSize = sizeof (Configuration);\r |
59aefb7e LG |
107 | ConfigRequest = Request;\r |
108 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r | |
109 | //\r | |
110 | // Request has no request element, construct full request string.\r | |
111 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r | |
112 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
113 | //\r | |
c8ad2d7a | 114 | ConfigRequestHdr = HiiConstructConfigHdr (&gVlanConfigFormSetGuid, mVlanStorageName, PrivateData->DriverHandle);\r |
59aefb7e LG |
115 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r |
116 | ConfigRequest = AllocateZeroPool (Size);\r | |
117 | ASSERT (ConfigRequest != NULL);\r | |
118 | AllocatedRequest = TRUE;\r | |
119 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r | |
120 | FreePool (ConfigRequestHdr);\r | |
121 | }\r | |
122 | \r | |
779ae357 | 123 | Status = mHiiConfigRouting->BlockToConfig (\r |
124 | mHiiConfigRouting,\r | |
59aefb7e | 125 | ConfigRequest,\r |
779ae357 | 126 | (UINT8 *) &Configuration,\r |
127 | BufferSize,\r | |
128 | Results,\r | |
129 | Progress\r | |
130 | );\r | |
59aefb7e LG |
131 | //\r |
132 | // Free the allocated config request string.\r | |
133 | //\r | |
134 | if (AllocatedRequest) {\r | |
135 | FreePool (ConfigRequest);\r | |
136 | ConfigRequest = NULL;\r | |
137 | }\r | |
138 | //\r | |
139 | // Set Progress string to the original request string.\r | |
140 | //\r | |
141 | if (Request == NULL) {\r | |
142 | *Progress = NULL;\r | |
143 | } else if (StrStr (Request, L"OFFSET") == NULL) {\r | |
144 | *Progress = Request + StrLen (Request);\r | |
145 | }\r | |
146 | \r | |
779ae357 | 147 | return Status;\r |
148 | }\r | |
149 | \r | |
150 | \r | |
151 | /**\r | |
152 | This function processes the results of changes in configuration.\r | |
153 | \r | |
154 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
155 | @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r | |
156 | format.\r | |
157 | @param[out] Progress A pointer to a string filled in with the offset of\r | |
158 | the most recent '&' before the first failing\r | |
159 | name/value pair (or the beginning of the string if\r | |
160 | the failure is in the first name/value pair) or\r | |
161 | the terminating NULL if all was successful.\r | |
162 | \r | |
163 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
164 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
165 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r | |
166 | driver.\r | |
167 | \r | |
168 | **/\r | |
169 | EFI_STATUS\r | |
170 | EFIAPI\r | |
171 | VlanRouteConfig (\r | |
172 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
173 | IN CONST EFI_STRING Configuration,\r | |
174 | OUT EFI_STRING *Progress\r | |
175 | )\r | |
176 | {\r | |
177 | if (Configuration == NULL || Progress == NULL) {\r | |
178 | return EFI_INVALID_PARAMETER;\r | |
179 | }\r | |
180 | \r | |
181 | *Progress = Configuration;\r | |
c8ad2d7a | 182 | if (!HiiIsConfigHdrMatch (Configuration, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r |
779ae357 | 183 | return EFI_NOT_FOUND;\r |
184 | }\r | |
185 | \r | |
186 | *Progress = Configuration + StrLen (Configuration);\r | |
187 | return EFI_SUCCESS;\r | |
188 | }\r | |
189 | \r | |
190 | /**\r | |
191 | This function processes the results of changes in configuration.\r | |
192 | \r | |
193 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
194 | @param[in] Action Specifies the type of action taken by the browser.\r | |
195 | @param[in] QuestionId A unique value which is sent to the original\r | |
196 | exporting driver so that it can identify the type\r | |
197 | of data to expect.\r | |
198 | @param[in] Type The type of value for the question.\r | |
199 | @param[in] Value A pointer to the data being sent to the original\r | |
200 | exporting driver.\r | |
201 | @param[out] ActionRequest On return, points to the action requested by the\r | |
202 | callback function.\r | |
203 | \r | |
204 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
205 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r | |
206 | variable and its data.\r | |
207 | @retval EFI_DEVICE_ERROR The variable could not be saved.\r | |
208 | @retval EFI_UNSUPPORTED The specified Action is not supported by the\r | |
209 | callback.\r | |
210 | \r | |
211 | **/\r | |
212 | EFI_STATUS\r | |
213 | EFIAPI\r | |
214 | VlanCallback (\r | |
215 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
216 | IN EFI_BROWSER_ACTION Action,\r | |
217 | IN EFI_QUESTION_ID QuestionId,\r | |
218 | IN UINT8 Type,\r | |
219 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
220 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
221 | )\r | |
222 | {\r | |
223 | VLAN_CONFIG_PRIVATE_DATA *PrivateData;\r | |
224 | VLAN_CONFIGURATION *Configuration;\r | |
225 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r | |
226 | UINTN Index;\r | |
227 | EFI_HANDLE VlanHandle;\r | |
228 | \r | |
229 | PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r | |
230 | \r | |
9ea13d79 | 231 | if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r |
779ae357 | 232 | return EFI_SUCCESS;\r |
233 | }\r | |
234 | \r | |
3a4e7a3e | 235 | if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) {\r |
779ae357 | 236 | //\r |
3a4e7a3e | 237 | // All other action return unsupported.\r |
779ae357 | 238 | //\r |
3a4e7a3e ED |
239 | return EFI_UNSUPPORTED;\r |
240 | }\r | |
241 | \r | |
242 | //\r | |
243 | // Get Browser data\r | |
244 | //\r | |
245 | Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r | |
246 | ASSERT (Configuration != NULL);\r | |
247 | HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r | |
779ae357 | 248 | \r |
3a4e7a3e | 249 | VlanConfig = PrivateData->VlanConfig;\r |
083f7c69 | 250 | \r |
3a4e7a3e | 251 | if (Action == EFI_BROWSER_ACTION_CHANGED) {\r |
083f7c69 ED |
252 | switch (QuestionId) {\r |
253 | case VLAN_ADD_QUESTION_ID:\r | |
779ae357 | 254 | //\r |
083f7c69 | 255 | // Add a VLAN\r |
779ae357 | 256 | //\r |
083f7c69 ED |
257 | VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r |
258 | VlanUpdateForm (PrivateData);\r | |
779ae357 | 259 | \r |
083f7c69 ED |
260 | //\r |
261 | // Connect the newly created VLAN device\r | |
262 | //\r | |
263 | VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r | |
264 | if (VlanHandle == NULL) {\r | |
779ae357 | 265 | //\r |
083f7c69 | 266 | // There may be no child handle created for VLAN ID 0, connect the parent handle\r |
779ae357 | 267 | //\r |
083f7c69 | 268 | VlanHandle = PrivateData->ControllerHandle;\r |
779ae357 | 269 | }\r |
083f7c69 | 270 | gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r |
779ae357 | 271 | \r |
779ae357 | 272 | //\r |
083f7c69 | 273 | // Clear UI data\r |
779ae357 | 274 | //\r |
cd3d9a85 | 275 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r |
083f7c69 ED |
276 | Configuration->VlanId = 0;\r |
277 | Configuration->Priority = 0;\r | |
278 | break;\r | |
779ae357 | 279 | \r |
083f7c69 ED |
280 | case VLAN_REMOVE_QUESTION_ID:\r |
281 | //\r | |
282 | // Remove VLAN\r | |
283 | //\r | |
284 | ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER);\r | |
285 | for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r | |
286 | if (Configuration->VlanList[Index] != 0) {\r | |
287 | //\r | |
288 | // Checkbox is selected, need remove this VLAN\r | |
289 | //\r | |
290 | VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r | |
291 | }\r | |
292 | }\r | |
779ae357 | 293 | \r |
083f7c69 ED |
294 | VlanUpdateForm (PrivateData);\r |
295 | if (PrivateData->NumberOfVlan == 0) {\r | |
296 | //\r | |
297 | // No VLAN device now, connect the physical NIC handle.\r | |
298 | // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r | |
299 | //\r | |
300 | gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r | |
301 | }\r | |
302 | \r | |
cd3d9a85 | 303 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r |
083f7c69 ED |
304 | ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r |
305 | break;\r | |
306 | \r | |
3a4e7a3e ED |
307 | default:\r |
308 | break;\r | |
309 | }\r | |
310 | } else if (Action == EFI_BROWSER_ACTION_CHANGING) {\r | |
311 | switch (QuestionId) {\r | |
9ea13d79 | 312 | case VLAN_UPDATE_QUESTION_ID:\r |
313 | //\r | |
314 | // Update current VLAN list into Form.\r | |
315 | //\r | |
316 | VlanUpdateForm (PrivateData);\r | |
317 | break;\r | |
318 | \r | |
083f7c69 ED |
319 | default:\r |
320 | break;\r | |
321 | }\r | |
779ae357 | 322 | }\r |
d1102dba | 323 | \r |
3a4e7a3e ED |
324 | HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r |
325 | FreePool (Configuration);\r | |
326 | return EFI_SUCCESS;\r | |
779ae357 | 327 | }\r |
328 | \r | |
329 | \r | |
330 | /**\r | |
331 | This function update VLAN list in the VLAN configuration Form.\r | |
332 | \r | |
333 | @param[in, out] PrivateData Points to VLAN configuration private data.\r | |
334 | \r | |
335 | **/\r | |
336 | VOID\r | |
337 | VlanUpdateForm (\r | |
338 | IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r | |
339 | )\r | |
340 | {\r | |
341 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r | |
342 | UINT16 NumberOfVlan;\r | |
343 | UINTN Index;\r | |
344 | EFI_VLAN_FIND_DATA *VlanData;\r | |
345 | VOID *StartOpCodeHandle;\r | |
346 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
347 | VOID *EndOpCodeHandle;\r | |
348 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
349 | CHAR16 *String;\r | |
350 | CHAR16 VlanStr[30];\r | |
351 | CHAR16 VlanIdStr[6];\r | |
352 | UINTN DigitalCount;\r | |
353 | EFI_STRING_ID StringId;\r | |
354 | \r | |
355 | //\r | |
356 | // Find current VLAN configuration\r | |
357 | //\r | |
358 | VlanData = NULL;\r | |
359 | NumberOfVlan = 0;\r | |
360 | VlanConfig = PrivateData->VlanConfig;\r | |
361 | VlanConfig->Find (VlanConfig, NULL, &NumberOfVlan, &VlanData);\r | |
362 | \r | |
363 | //\r | |
364 | // Update VLAN configuration in PrivateData\r | |
365 | //\r | |
366 | if (NumberOfVlan > MAX_VLAN_NUMBER) {\r | |
367 | NumberOfVlan = MAX_VLAN_NUMBER;\r | |
368 | }\r | |
369 | PrivateData->NumberOfVlan = NumberOfVlan;\r | |
370 | \r | |
371 | //\r | |
372 | // Init OpCode Handle\r | |
373 | //\r | |
374 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
375 | ASSERT (StartOpCodeHandle != NULL);\r | |
376 | \r | |
377 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
378 | ASSERT (EndOpCodeHandle != NULL);\r | |
379 | \r | |
380 | //\r | |
381 | // Create Hii Extend Label OpCode as the start opcode\r | |
382 | //\r | |
383 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r | |
384 | StartOpCodeHandle,\r | |
385 | &gEfiIfrTianoGuid,\r | |
386 | NULL,\r | |
387 | sizeof (EFI_IFR_GUID_LABEL)\r | |
388 | );\r | |
389 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
390 | StartLabel->Number = LABEL_VLAN_LIST;\r | |
391 | \r | |
392 | //\r | |
393 | // Create Hii Extend Label OpCode as the end opcode\r | |
394 | //\r | |
395 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r | |
396 | EndOpCodeHandle,\r | |
397 | &gEfiIfrTianoGuid,\r | |
398 | NULL,\r | |
399 | sizeof (EFI_IFR_GUID_LABEL)\r | |
400 | );\r | |
401 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
402 | EndLabel->Number = LABEL_END;\r | |
403 | \r | |
404 | ZeroMem (PrivateData->VlanId, MAX_VLAN_NUMBER);\r | |
405 | for (Index = 0; Index < NumberOfVlan; Index++) {\r | |
406 | String = VlanStr;\r | |
407 | \r | |
206b5f51 | 408 | StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)), L" VLAN ID:");\r |
779ae357 | 409 | String += 10;\r |
410 | //\r | |
411 | // Pad VlanId string up to 4 characters with space\r | |
412 | //\r | |
9f4048f7 HW |
413 | UnicodeValueToStringS (VlanIdStr, sizeof (VlanIdStr), 0, VlanData[Index].VlanId, 5);\r |
414 | DigitalCount = StrnLenS (VlanIdStr, ARRAY_SIZE (VlanIdStr));\r | |
779ae357 | 415 | SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' ');\r |
206b5f51 | 416 | StrCpyS (String + 4 - DigitalCount, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount), VlanIdStr);\r |
779ae357 | 417 | String += 4;\r |
418 | \r | |
206b5f51 | 419 | StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount) - 4, L", Priority:");\r |
779ae357 | 420 | String += 11;\r |
9f4048f7 HW |
421 | UnicodeValueToStringS (\r |
422 | String,\r | |
423 | sizeof (VlanStr) - ((UINTN)String - (UINTN)VlanStr),\r | |
424 | 0,\r | |
425 | VlanData[Index].Priority,\r | |
426 | 4\r | |
427 | );\r | |
428 | String += StrnLenS (String, ARRAY_SIZE (VlanStr) - ((UINTN)String - (UINTN)VlanStr) / sizeof (CHAR16));\r | |
779ae357 | 429 | *String = 0;\r |
430 | \r | |
431 | StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL);\r | |
432 | ASSERT (StringId != 0);\r | |
433 | \r | |
434 | HiiCreateCheckBoxOpCode (\r | |
435 | StartOpCodeHandle,\r | |
436 | (EFI_QUESTION_ID) (VLAN_LIST_VAR_OFFSET + Index),\r | |
437 | VLAN_CONFIGURATION_VARSTORE_ID,\r | |
438 | (UINT16) (VLAN_LIST_VAR_OFFSET + Index),\r | |
439 | StringId,\r | |
440 | STRING_TOKEN (STR_VLAN_VLAN_LIST_HELP),\r | |
441 | 0,\r | |
442 | 0,\r | |
443 | NULL\r | |
444 | );\r | |
445 | \r | |
446 | //\r | |
447 | // Save VLAN id to private data\r | |
448 | //\r | |
449 | PrivateData->VlanId[Index] = VlanData[Index].VlanId;\r | |
450 | }\r | |
451 | \r | |
452 | HiiUpdateForm (\r | |
453 | PrivateData->HiiHandle, // HII handle\r | |
c8ad2d7a | 454 | &gVlanConfigFormSetGuid, // Formset GUID\r |
779ae357 | 455 | VLAN_CONFIGURATION_FORM_ID, // Form ID\r |
456 | StartOpCodeHandle, // Label for where to insert opcodes\r | |
457 | EndOpCodeHandle // Replace data\r | |
458 | );\r | |
459 | \r | |
460 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r | |
461 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
462 | \r | |
463 | if (VlanData != NULL) {\r | |
464 | FreePool (VlanData);\r | |
465 | }\r | |
466 | }\r | |
467 | \r | |
468 | \r | |
469 | /**\r | |
470 | This function publish the VLAN configuration Form for a network device. The\r | |
471 | HII Config Access protocol will be installed on a child handle of the network\r | |
472 | device.\r | |
473 | \r | |
474 | @param[in, out] PrivateData Points to VLAN configuration private data.\r | |
475 | \r | |
476 | @retval EFI_SUCCESS HII Form is installed for this network device.\r | |
477 | @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r | |
478 | @retval Others Other errors as indicated.\r | |
479 | \r | |
480 | **/\r | |
481 | EFI_STATUS\r | |
482 | InstallVlanConfigForm (\r | |
483 | IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r | |
484 | )\r | |
485 | {\r | |
486 | EFI_STATUS Status;\r | |
487 | EFI_HII_HANDLE HiiHandle;\r | |
488 | EFI_HANDLE DriverHandle;\r | |
e2851998 | 489 | CHAR16 Str[26 + sizeof (EFI_MAC_ADDRESS) * 2 + 1];\r |
779ae357 | 490 | CHAR16 *MacString;\r |
491 | EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r | |
492 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
216f7970 | 493 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r |
779ae357 | 494 | \r |
495 | //\r | |
496 | // Create child handle and install HII Config Access Protocol\r | |
497 | //\r | |
498 | ChildDevicePath = AppendDevicePathNode (\r | |
499 | PrivateData->ParentDevicePath,\r | |
500 | (CONST EFI_DEVICE_PATH_PROTOCOL *) &mHiiVendorDevicePathNode\r | |
501 | );\r | |
502 | if (ChildDevicePath == NULL) {\r | |
503 | return EFI_OUT_OF_RESOURCES;\r | |
504 | }\r | |
505 | PrivateData->ChildDevicePath = ChildDevicePath;\r | |
506 | \r | |
507 | DriverHandle = NULL;\r | |
508 | ConfigAccess = &PrivateData->ConfigAccess;\r | |
509 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
510 | &DriverHandle,\r | |
511 | &gEfiDevicePathProtocolGuid,\r | |
512 | ChildDevicePath,\r | |
513 | &gEfiHiiConfigAccessProtocolGuid,\r | |
514 | ConfigAccess,\r | |
515 | NULL\r | |
516 | );\r | |
517 | if (EFI_ERROR (Status)) {\r | |
518 | return Status;\r | |
519 | }\r | |
520 | PrivateData->DriverHandle = DriverHandle;\r | |
521 | \r | |
216f7970 | 522 | //\r |
523 | // Establish the parent-child relationship between the new created\r | |
524 | // child handle and the ControllerHandle.\r | |
525 | //\r | |
526 | Status = gBS->OpenProtocol (\r | |
527 | PrivateData->ControllerHandle,\r | |
528 | &gEfiVlanConfigProtocolGuid,\r | |
529 | (VOID **)&VlanConfig,\r | |
530 | PrivateData->ImageHandle,\r | |
531 | PrivateData->DriverHandle,\r | |
532 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
533 | );\r | |
534 | if (EFI_ERROR (Status)) {\r | |
535 | return Status;\r | |
536 | }\r | |
537 | \r | |
779ae357 | 538 | //\r |
539 | // Publish the HII package list\r | |
540 | //\r | |
541 | HiiHandle = HiiAddPackages (\r | |
c8ad2d7a | 542 | &gVlanConfigFormSetGuid,\r |
779ae357 | 543 | DriverHandle,\r |
544 | VlanConfigDxeStrings,\r | |
545 | VlanConfigBin,\r | |
546 | NULL\r | |
547 | );\r | |
548 | if (HiiHandle == NULL) {\r | |
549 | return EFI_OUT_OF_RESOURCES;\r | |
550 | }\r | |
551 | PrivateData->HiiHandle = HiiHandle;\r | |
552 | \r | |
553 | //\r | |
3ddc4cf2 | 554 | // Update formset title help string.\r |
779ae357 | 555 | //\r |
556 | MacString = NULL;\r | |
557 | Status = NetLibGetMacString (PrivateData->ControllerHandle, PrivateData->ImageHandle, &MacString);\r | |
558 | if (EFI_ERROR (Status)) {\r | |
559 | return Status;\r | |
560 | }\r | |
561 | PrivateData->MacString = MacString;\r | |
562 | \r | |
206b5f51 ZL |
563 | StrCpyS (Str, sizeof (Str) / sizeof (CHAR16), L"VLAN Configuration (MAC:");\r |
564 | StrCatS (Str, sizeof (Str) / sizeof (CHAR16), MacString);\r | |
565 | StrCatS (Str, sizeof (Str) / sizeof (CHAR16), L")");\r | |
779ae357 | 566 | HiiSetString (\r |
567 | HiiHandle,\r | |
c7f204db | 568 | STRING_TOKEN (STR_VLAN_FORM_SET_TITLE_HELP),\r |
779ae357 | 569 | Str,\r |
570 | NULL\r | |
571 | );\r | |
572 | \r | |
573 | //\r | |
3ddc4cf2 | 574 | // Update form title help string.\r |
779ae357 | 575 | //\r |
576 | HiiSetString (\r | |
577 | HiiHandle,\r | |
c7f204db | 578 | STRING_TOKEN (STR_VLAN_FORM_HELP),\r |
779ae357 | 579 | Str,\r |
580 | NULL\r | |
581 | );\r | |
582 | \r | |
583 | return EFI_SUCCESS;\r | |
584 | }\r | |
585 | \r | |
586 | /**\r | |
587 | This function remove the VLAN configuration Form for a network device. The\r | |
588 | child handle for HII Config Access protocol will be destroyed.\r | |
589 | \r | |
590 | @param[in, out] PrivateData Points to VLAN configuration private data.\r | |
591 | \r | |
ca4e58d8 FS |
592 | @retval EFI_SUCCESS HII Form has been uninstalled successfully.\r |
593 | @retval Others Other errors as indicated.\r | |
594 | \r | |
779ae357 | 595 | **/\r |
ca4e58d8 | 596 | EFI_STATUS\r |
779ae357 | 597 | UninstallVlanConfigForm (\r |
598 | IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r | |
599 | )\r | |
600 | {\r | |
ca4e58d8 FS |
601 | EFI_STATUS Status;\r |
602 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r | |
d1102dba | 603 | \r |
216f7970 | 604 | //\r |
605 | // End the parent-child relationship.\r | |
606 | //\r | |
ca4e58d8 FS |
607 | Status = gBS->CloseProtocol (\r |
608 | PrivateData->ControllerHandle,\r | |
609 | &gEfiVlanConfigProtocolGuid,\r | |
610 | PrivateData->ImageHandle,\r | |
611 | PrivateData->DriverHandle\r | |
612 | );\r | |
613 | if (EFI_ERROR (Status)) {\r | |
614 | return Status;\r | |
615 | }\r | |
216f7970 | 616 | \r |
779ae357 | 617 | //\r |
618 | // Uninstall HII Config Access Protocol\r | |
619 | //\r | |
620 | if (PrivateData->DriverHandle != NULL) {\r | |
ca4e58d8 FS |
621 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
622 | PrivateData->DriverHandle,\r | |
623 | &gEfiDevicePathProtocolGuid,\r | |
624 | PrivateData->ChildDevicePath,\r | |
625 | &gEfiHiiConfigAccessProtocolGuid,\r | |
626 | &PrivateData->ConfigAccess,\r | |
627 | NULL\r | |
628 | );\r | |
629 | if (EFI_ERROR (Status)) {\r | |
630 | gBS->OpenProtocol (\r | |
631 | PrivateData->ControllerHandle,\r | |
632 | &gEfiVlanConfigProtocolGuid,\r | |
633 | (VOID **)&VlanConfig,\r | |
634 | PrivateData->ImageHandle,\r | |
635 | PrivateData->DriverHandle,\r | |
636 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
637 | );\r | |
638 | return Status;\r | |
639 | }\r | |
779ae357 | 640 | PrivateData->DriverHandle = NULL;\r |
641 | \r | |
642 | if (PrivateData->ChildDevicePath != NULL) {\r | |
643 | FreePool (PrivateData->ChildDevicePath);\r | |
644 | PrivateData->ChildDevicePath = NULL;\r | |
645 | }\r | |
646 | }\r | |
ca4e58d8 FS |
647 | \r |
648 | //\r | |
649 | // Free MAC string\r | |
650 | //\r | |
651 | if (PrivateData->MacString != NULL) {\r | |
652 | FreePool (PrivateData->MacString);\r | |
653 | PrivateData->MacString = NULL;\r | |
654 | }\r | |
655 | \r | |
656 | //\r | |
657 | // Uninstall HII package list\r | |
658 | //\r | |
659 | if (PrivateData->HiiHandle != NULL) {\r | |
660 | HiiRemovePackages (PrivateData->HiiHandle);\r | |
661 | PrivateData->HiiHandle = NULL;\r | |
662 | }\r | |
663 | return EFI_SUCCESS;\r | |
779ae357 | 664 | }\r |