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