2 HII Config Access protocol implementation of VLAN configuration module.
4 Copyright (c) 2009, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The full
8 text of the license may be found at<BR>
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "VlanConfigImpl.h"
18 EFI_GUID mVlanFormSetGuid
= VLAN_CONFIG_PRIVATE_GUID
;
19 CHAR16 mVlanStorageName
[] = L
"VlanNvData";
20 EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
= NULL
;
22 VLAN_CONFIG_PRIVATE_DATA mVlanConfigPrivateDateTemplate
= {
23 VLAN_CONFIG_PRIVATE_DATA_SIGNATURE
,
31 VENDOR_DEVICE_PATH mHiiVendorDevicePathNode
= {
36 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
37 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
40 VLAN_CONFIG_PRIVATE_GUID
44 This function allows a caller to extract the current configuration for one
45 or more named elements from the target driver.
47 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
48 @param[in] Request A null-terminated Unicode string in
49 <ConfigRequest> format.
50 @param[out] Progress On return, points to a character in the Request
51 string. Points to the string's null terminator if
52 request was successful. Points to the most recent
53 '&' before the first failing name/value pair (or
54 the beginning of the string if the failure is in
55 the first name/value pair) if the request was not
57 @param[out] Results A null-terminated Unicode string in
58 <ConfigAltResp> format which has all values filled
59 in for the names in the Request string. String to
60 be allocated by the called function.
62 @retval EFI_SUCCESS The Results is filled with the requested values.
63 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
64 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
65 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
72 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
73 IN CONST EFI_STRING Request
,
74 OUT EFI_STRING
*Progress
,
75 OUT EFI_STRING
*Results
80 VLAN_CONFIGURATION Configuration
;
82 if (Request
== NULL
) {
83 return EFI_INVALID_PARAMETER
;
87 // Retrieve the pointer to the UEFI HII Config Routing Protocol
89 if (mHiiConfigRouting
== NULL
) {
90 gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &mHiiConfigRouting
);
92 ASSERT (mHiiConfigRouting
!= NULL
);
95 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
97 ZeroMem (&Configuration
, sizeof (VLAN_CONFIGURATION
));
98 BufferSize
= sizeof (VLAN_CONFIG_PRIVATE_DATA
);
99 Status
= mHiiConfigRouting
->BlockToConfig (
102 (UINT8
*) &Configuration
,
112 This function processes the results of changes in configuration.
114 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
115 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
117 @param[out] Progress A pointer to a string filled in with the offset of
118 the most recent '&' before the first failing
119 name/value pair (or the beginning of the string if
120 the failure is in the first name/value pair) or
121 the terminating NULL if all was successful.
123 @retval EFI_SUCCESS The Results is processed successfully.
124 @retval EFI_INVALID_PARAMETER Configuration is NULL.
125 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
132 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
133 IN CONST EFI_STRING Configuration
,
134 OUT EFI_STRING
*Progress
137 if (Configuration
== NULL
|| Progress
== NULL
) {
138 return EFI_INVALID_PARAMETER
;
141 *Progress
= Configuration
;
142 if (!HiiIsConfigHdrMatch (Configuration
, &mVlanFormSetGuid
, mVlanStorageName
)) {
143 return EFI_NOT_FOUND
;
146 *Progress
= Configuration
+ StrLen (Configuration
);
151 This function processes the results of changes in configuration.
153 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
154 @param[in] Action Specifies the type of action taken by the browser.
155 @param[in] QuestionId A unique value which is sent to the original
156 exporting driver so that it can identify the type
158 @param[in] Type The type of value for the question.
159 @param[in] Value A pointer to the data being sent to the original
161 @param[out] ActionRequest On return, points to the action requested by the
164 @retval EFI_SUCCESS The callback successfully handled the action.
165 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
166 variable and its data.
167 @retval EFI_DEVICE_ERROR The variable could not be saved.
168 @retval EFI_UNSUPPORTED The specified Action is not supported by the
175 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
176 IN EFI_BROWSER_ACTION Action
,
177 IN EFI_QUESTION_ID QuestionId
,
179 IN EFI_IFR_TYPE_VALUE
*Value
,
180 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
183 VLAN_CONFIG_PRIVATE_DATA
*PrivateData
;
184 VLAN_CONFIGURATION
*Configuration
;
185 EFI_VLAN_CONFIG_PROTOCOL
*VlanConfig
;
187 EFI_HANDLE VlanHandle
;
189 PrivateData
= VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
191 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
193 // On FORM_OPEN event, update current VLAN list
195 VlanUpdateForm (PrivateData
);
203 Configuration
= AllocateZeroPool (sizeof (VLAN_CONFIGURATION
));
204 ASSERT (Configuration
!= NULL
);
205 HiiGetBrowserData (&mVlanFormSetGuid
, mVlanStorageName
, sizeof (VLAN_CONFIGURATION
), (UINT8
*) Configuration
);
207 VlanConfig
= PrivateData
->VlanConfig
;
209 switch (QuestionId
) {
210 case VLAN_ADD_QUESTION_ID
:
214 VlanConfig
->Set (VlanConfig
, Configuration
->VlanId
, Configuration
->Priority
);
215 VlanUpdateForm (PrivateData
);
218 // Connect the newly created VLAN device
220 VlanHandle
= NetLibGetVlanHandle (PrivateData
->ControllerHandle
, Configuration
->VlanId
);
221 if (VlanHandle
== NULL
) {
223 // There may be no child handle created for VLAN ID 0, connect the parent handle
225 VlanHandle
= PrivateData
->ControllerHandle
;
227 gBS
->ConnectController (VlanHandle
, NULL
, NULL
, TRUE
);
232 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
233 Configuration
->VlanId
= 0;
234 Configuration
->Priority
= 0;
237 case VLAN_REMOVE_QUESTION_ID
:
241 for (Index
= 0; Index
< PrivateData
->NumberOfVlan
; Index
++) {
242 if (Configuration
->VlanList
[Index
] != 0) {
244 // Checkbox is selected, need remove this VLAN
246 VlanConfig
->Remove (VlanConfig
, PrivateData
->VlanId
[Index
]);
250 VlanUpdateForm (PrivateData
);
251 if (PrivateData
->NumberOfVlan
== 0) {
253 // No VLAN device now, connect the physical NIC handle.
254 // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()
256 gBS
->ConnectController (PrivateData
->ControllerHandle
, NULL
, NULL
, TRUE
);
259 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
260 ZeroMem (Configuration
->VlanList
, MAX_VLAN_NUMBER
);
267 HiiSetBrowserData (&mVlanFormSetGuid
, mVlanStorageName
, sizeof (VLAN_CONFIGURATION
), (UINT8
*) Configuration
, NULL
);
268 FreePool (Configuration
);
274 This function update VLAN list in the VLAN configuration Form.
276 @param[in, out] PrivateData Points to VLAN configuration private data.
281 IN OUT VLAN_CONFIG_PRIVATE_DATA
*PrivateData
284 EFI_VLAN_CONFIG_PROTOCOL
*VlanConfig
;
287 EFI_VLAN_FIND_DATA
*VlanData
;
288 VOID
*StartOpCodeHandle
;
289 EFI_IFR_GUID_LABEL
*StartLabel
;
290 VOID
*EndOpCodeHandle
;
291 EFI_IFR_GUID_LABEL
*EndLabel
;
296 EFI_STRING_ID StringId
;
299 // Find current VLAN configuration
303 VlanConfig
= PrivateData
->VlanConfig
;
304 VlanConfig
->Find (VlanConfig
, NULL
, &NumberOfVlan
, &VlanData
);
307 // Update VLAN configuration in PrivateData
309 if (NumberOfVlan
> MAX_VLAN_NUMBER
) {
310 NumberOfVlan
= MAX_VLAN_NUMBER
;
312 PrivateData
->NumberOfVlan
= NumberOfVlan
;
315 // Init OpCode Handle
317 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
318 ASSERT (StartOpCodeHandle
!= NULL
);
320 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
321 ASSERT (EndOpCodeHandle
!= NULL
);
324 // Create Hii Extend Label OpCode as the start opcode
326 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
330 sizeof (EFI_IFR_GUID_LABEL
)
332 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
333 StartLabel
->Number
= LABEL_VLAN_LIST
;
336 // Create Hii Extend Label OpCode as the end opcode
338 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
342 sizeof (EFI_IFR_GUID_LABEL
)
344 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
345 EndLabel
->Number
= LABEL_END
;
347 ZeroMem (PrivateData
->VlanId
, MAX_VLAN_NUMBER
);
348 for (Index
= 0; Index
< NumberOfVlan
; Index
++) {
351 StrCpy (String
, L
" VLAN ID:");
354 // Pad VlanId string up to 4 characters with space
356 DigitalCount
= UnicodeValueToString (VlanIdStr
, 0, VlanData
[Index
].VlanId
, 5);
357 SetMem16 (String
, (4 - DigitalCount
) * sizeof (CHAR16
), L
' ');
358 StrCpy (String
+ 4 - DigitalCount
, VlanIdStr
);
361 StrCpy (String
, L
", Priority:");
363 String
+= UnicodeValueToString (String
, 0, VlanData
[Index
].Priority
, 4);
366 StringId
= HiiSetString (PrivateData
->HiiHandle
, 0, VlanStr
, NULL
);
367 ASSERT (StringId
!= 0);
369 HiiCreateCheckBoxOpCode (
371 (EFI_QUESTION_ID
) (VLAN_LIST_VAR_OFFSET
+ Index
),
372 VLAN_CONFIGURATION_VARSTORE_ID
,
373 (UINT16
) (VLAN_LIST_VAR_OFFSET
+ Index
),
375 STRING_TOKEN (STR_VLAN_VLAN_LIST_HELP
),
382 // Save VLAN id to private data
384 PrivateData
->VlanId
[Index
] = VlanData
[Index
].VlanId
;
388 PrivateData
->HiiHandle
, // HII handle
389 &mVlanFormSetGuid
, // Formset GUID
390 VLAN_CONFIGURATION_FORM_ID
, // Form ID
391 StartOpCodeHandle
, // Label for where to insert opcodes
392 EndOpCodeHandle
// Replace data
395 HiiFreeOpCodeHandle (StartOpCodeHandle
);
396 HiiFreeOpCodeHandle (EndOpCodeHandle
);
398 if (VlanData
!= NULL
) {
405 This function publish the VLAN configuration Form for a network device. The
406 HII Config Access protocol will be installed on a child handle of the network
409 @param[in, out] PrivateData Points to VLAN configuration private data.
411 @retval EFI_SUCCESS HII Form is installed for this network device.
412 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
413 @retval Others Other errors as indicated.
417 InstallVlanConfigForm (
418 IN OUT VLAN_CONFIG_PRIVATE_DATA
*PrivateData
422 EFI_HII_HANDLE HiiHandle
;
423 EFI_HANDLE DriverHandle
;
426 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
427 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
430 // Create child handle and install HII Config Access Protocol
432 ChildDevicePath
= AppendDevicePathNode (
433 PrivateData
->ParentDevicePath
,
434 (CONST EFI_DEVICE_PATH_PROTOCOL
*) &mHiiVendorDevicePathNode
436 if (ChildDevicePath
== NULL
) {
437 return EFI_OUT_OF_RESOURCES
;
439 PrivateData
->ChildDevicePath
= ChildDevicePath
;
442 ConfigAccess
= &PrivateData
->ConfigAccess
;
443 Status
= gBS
->InstallMultipleProtocolInterfaces (
445 &gEfiDevicePathProtocolGuid
,
447 &gEfiHiiConfigAccessProtocolGuid
,
451 if (EFI_ERROR (Status
)) {
454 PrivateData
->DriverHandle
= DriverHandle
;
457 // Publish the HII package list
459 HiiHandle
= HiiAddPackages (
462 VlanConfigDxeStrings
,
466 if (HiiHandle
== NULL
) {
467 return EFI_OUT_OF_RESOURCES
;
469 PrivateData
->HiiHandle
= HiiHandle
;
472 // Update formset title
475 Status
= NetLibGetMacString (PrivateData
->ControllerHandle
, PrivateData
->ImageHandle
, &MacString
);
476 if (EFI_ERROR (Status
)) {
479 PrivateData
->MacString
= MacString
;
481 StrCpy (Str
, L
"VLAN Configuration (MAC:");
482 StrCat (Str
, MacString
);
486 STRING_TOKEN (STR_VLAN_FORM_SET_TITLE
),
496 STRING_TOKEN (STR_VLAN_FORM_TITLE
),
505 This function remove the VLAN configuration Form for a network device. The
506 child handle for HII Config Access protocol will be destroyed.
508 @param[in, out] PrivateData Points to VLAN configuration private data.
512 UninstallVlanConfigForm (
513 IN OUT VLAN_CONFIG_PRIVATE_DATA
*PrivateData
519 if (PrivateData
->MacString
!= NULL
) {
520 FreePool (PrivateData
->MacString
);
521 PrivateData
->MacString
= NULL
;
525 // Uninstall HII package list
527 if (PrivateData
->HiiHandle
!= NULL
) {
528 HiiRemovePackages (PrivateData
->HiiHandle
);
529 PrivateData
->HiiHandle
= NULL
;
533 // Uninstall HII Config Access Protocol
535 if (PrivateData
->DriverHandle
!= NULL
) {
536 gBS
->UninstallMultipleProtocolInterfaces (
537 PrivateData
->DriverHandle
,
538 &gEfiDevicePathProtocolGuid
,
539 PrivateData
->ChildDevicePath
,
540 &gEfiHiiConfigAccessProtocolGuid
,
541 &PrivateData
->ConfigAccess
,
544 PrivateData
->DriverHandle
= NULL
;
546 if (PrivateData
->ChildDevicePath
!= NULL
) {
547 FreePool (PrivateData
->ChildDevicePath
);
548 PrivateData
->ChildDevicePath
= NULL
;