2 HII Config Access protocol implementation of VLAN configuration module.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
5 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 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
;
81 VLAN_CONFIG_PRIVATE_DATA
*PrivateData
;
82 EFI_STRING ConfigRequestHdr
;
83 EFI_STRING ConfigRequest
;
84 BOOLEAN AllocatedRequest
;
87 if (Progress
== NULL
|| Results
== NULL
) {
88 return EFI_INVALID_PARAMETER
;
92 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &mVlanFormSetGuid
, mVlanStorageName
)) {
96 ConfigRequestHdr
= NULL
;
98 AllocatedRequest
= FALSE
;
102 // Retrieve the pointer to the UEFI HII Config Routing Protocol
104 if (mHiiConfigRouting
== NULL
) {
105 gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &mHiiConfigRouting
);
107 ASSERT (mHiiConfigRouting
!= NULL
);
110 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
112 PrivateData
= VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
113 ZeroMem (&Configuration
, sizeof (VLAN_CONFIGURATION
));
114 BufferSize
= sizeof (Configuration
);
115 ConfigRequest
= Request
;
116 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
118 // Request has no request element, construct full request string.
119 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
120 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
122 ConfigRequestHdr
= HiiConstructConfigHdr (&mVlanFormSetGuid
, mVlanStorageName
, PrivateData
->DriverHandle
);
123 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
124 ConfigRequest
= AllocateZeroPool (Size
);
125 ASSERT (ConfigRequest
!= NULL
);
126 AllocatedRequest
= TRUE
;
127 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
128 FreePool (ConfigRequestHdr
);
131 Status
= mHiiConfigRouting
->BlockToConfig (
134 (UINT8
*) &Configuration
,
140 // Free the allocated config request string.
142 if (AllocatedRequest
) {
143 FreePool (ConfigRequest
);
144 ConfigRequest
= NULL
;
147 // Set Progress string to the original request string.
149 if (Request
== NULL
) {
151 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
152 *Progress
= Request
+ StrLen (Request
);
160 This function processes the results of changes in configuration.
162 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
163 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
165 @param[out] Progress A pointer to a string filled in with the offset of
166 the most recent '&' before the first failing
167 name/value pair (or the beginning of the string if
168 the failure is in the first name/value pair) or
169 the terminating NULL if all was successful.
171 @retval EFI_SUCCESS The Results is processed successfully.
172 @retval EFI_INVALID_PARAMETER Configuration is NULL.
173 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
180 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
181 IN CONST EFI_STRING Configuration
,
182 OUT EFI_STRING
*Progress
185 if (Configuration
== NULL
|| Progress
== NULL
) {
186 return EFI_INVALID_PARAMETER
;
189 *Progress
= Configuration
;
190 if (!HiiIsConfigHdrMatch (Configuration
, &mVlanFormSetGuid
, mVlanStorageName
)) {
191 return EFI_NOT_FOUND
;
194 *Progress
= Configuration
+ StrLen (Configuration
);
199 This function processes the results of changes in configuration.
201 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
202 @param[in] Action Specifies the type of action taken by the browser.
203 @param[in] QuestionId A unique value which is sent to the original
204 exporting driver so that it can identify the type
206 @param[in] Type The type of value for the question.
207 @param[in] Value A pointer to the data being sent to the original
209 @param[out] ActionRequest On return, points to the action requested by the
212 @retval EFI_SUCCESS The callback successfully handled the action.
213 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
214 variable and its data.
215 @retval EFI_DEVICE_ERROR The variable could not be saved.
216 @retval EFI_UNSUPPORTED The specified Action is not supported by the
223 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
224 IN EFI_BROWSER_ACTION Action
,
225 IN EFI_QUESTION_ID QuestionId
,
227 IN EFI_IFR_TYPE_VALUE
*Value
,
228 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
231 VLAN_CONFIG_PRIVATE_DATA
*PrivateData
;
232 VLAN_CONFIGURATION
*Configuration
;
233 EFI_VLAN_CONFIG_PROTOCOL
*VlanConfig
;
235 EFI_HANDLE VlanHandle
;
237 PrivateData
= VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
239 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
243 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
247 Configuration
= AllocateZeroPool (sizeof (VLAN_CONFIGURATION
));
248 ASSERT (Configuration
!= NULL
);
249 HiiGetBrowserData (&mVlanFormSetGuid
, mVlanStorageName
, sizeof (VLAN_CONFIGURATION
), (UINT8
*) Configuration
);
251 VlanConfig
= PrivateData
->VlanConfig
;
253 switch (QuestionId
) {
254 case VLAN_ADD_QUESTION_ID
:
258 VlanConfig
->Set (VlanConfig
, Configuration
->VlanId
, Configuration
->Priority
);
259 VlanUpdateForm (PrivateData
);
262 // Connect the newly created VLAN device
264 VlanHandle
= NetLibGetVlanHandle (PrivateData
->ControllerHandle
, Configuration
->VlanId
);
265 if (VlanHandle
== NULL
) {
267 // There may be no child handle created for VLAN ID 0, connect the parent handle
269 VlanHandle
= PrivateData
->ControllerHandle
;
271 gBS
->ConnectController (VlanHandle
, NULL
, NULL
, TRUE
);
276 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
277 Configuration
->VlanId
= 0;
278 Configuration
->Priority
= 0;
281 case VLAN_REMOVE_QUESTION_ID
:
285 ASSERT (PrivateData
->NumberOfVlan
<= MAX_VLAN_NUMBER
);
286 for (Index
= 0; Index
< PrivateData
->NumberOfVlan
; Index
++) {
287 if (Configuration
->VlanList
[Index
] != 0) {
289 // Checkbox is selected, need remove this VLAN
291 VlanConfig
->Remove (VlanConfig
, PrivateData
->VlanId
[Index
]);
295 VlanUpdateForm (PrivateData
);
296 if (PrivateData
->NumberOfVlan
== 0) {
298 // No VLAN device now, connect the physical NIC handle.
299 // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()
301 gBS
->ConnectController (PrivateData
->ControllerHandle
, NULL
, NULL
, TRUE
);
304 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
305 ZeroMem (Configuration
->VlanList
, MAX_VLAN_NUMBER
);
308 case VLAN_UPDATE_QUESTION_ID
:
310 // Update current VLAN list into Form.
312 VlanUpdateForm (PrivateData
);
319 HiiSetBrowserData (&mVlanFormSetGuid
, mVlanStorageName
, sizeof (VLAN_CONFIGURATION
), (UINT8
*) Configuration
, NULL
);
320 FreePool (Configuration
);
325 // All other action return unsupported.
327 return EFI_UNSUPPORTED
;
332 This function update VLAN list in the VLAN configuration Form.
334 @param[in, out] PrivateData Points to VLAN configuration private data.
339 IN OUT VLAN_CONFIG_PRIVATE_DATA
*PrivateData
342 EFI_VLAN_CONFIG_PROTOCOL
*VlanConfig
;
345 EFI_VLAN_FIND_DATA
*VlanData
;
346 VOID
*StartOpCodeHandle
;
347 EFI_IFR_GUID_LABEL
*StartLabel
;
348 VOID
*EndOpCodeHandle
;
349 EFI_IFR_GUID_LABEL
*EndLabel
;
354 EFI_STRING_ID StringId
;
357 // Find current VLAN configuration
361 VlanConfig
= PrivateData
->VlanConfig
;
362 VlanConfig
->Find (VlanConfig
, NULL
, &NumberOfVlan
, &VlanData
);
365 // Update VLAN configuration in PrivateData
367 if (NumberOfVlan
> MAX_VLAN_NUMBER
) {
368 NumberOfVlan
= MAX_VLAN_NUMBER
;
370 PrivateData
->NumberOfVlan
= NumberOfVlan
;
373 // Init OpCode Handle
375 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
376 ASSERT (StartOpCodeHandle
!= NULL
);
378 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
379 ASSERT (EndOpCodeHandle
!= NULL
);
382 // Create Hii Extend Label OpCode as the start opcode
384 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
388 sizeof (EFI_IFR_GUID_LABEL
)
390 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
391 StartLabel
->Number
= LABEL_VLAN_LIST
;
394 // Create Hii Extend Label OpCode as the end opcode
396 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
400 sizeof (EFI_IFR_GUID_LABEL
)
402 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
403 EndLabel
->Number
= LABEL_END
;
405 ZeroMem (PrivateData
->VlanId
, MAX_VLAN_NUMBER
);
406 for (Index
= 0; Index
< NumberOfVlan
; Index
++) {
409 StrCpy (String
, L
" VLAN ID:");
412 // Pad VlanId string up to 4 characters with space
414 DigitalCount
= UnicodeValueToString (VlanIdStr
, 0, VlanData
[Index
].VlanId
, 5);
415 SetMem16 (String
, (4 - DigitalCount
) * sizeof (CHAR16
), L
' ');
416 StrCpy (String
+ 4 - DigitalCount
, VlanIdStr
);
419 StrCpy (String
, L
", Priority:");
421 String
+= UnicodeValueToString (String
, 0, VlanData
[Index
].Priority
, 4);
424 StringId
= HiiSetString (PrivateData
->HiiHandle
, 0, VlanStr
, NULL
);
425 ASSERT (StringId
!= 0);
427 HiiCreateCheckBoxOpCode (
429 (EFI_QUESTION_ID
) (VLAN_LIST_VAR_OFFSET
+ Index
),
430 VLAN_CONFIGURATION_VARSTORE_ID
,
431 (UINT16
) (VLAN_LIST_VAR_OFFSET
+ Index
),
433 STRING_TOKEN (STR_VLAN_VLAN_LIST_HELP
),
440 // Save VLAN id to private data
442 PrivateData
->VlanId
[Index
] = VlanData
[Index
].VlanId
;
446 PrivateData
->HiiHandle
, // HII handle
447 &mVlanFormSetGuid
, // Formset GUID
448 VLAN_CONFIGURATION_FORM_ID
, // Form ID
449 StartOpCodeHandle
, // Label for where to insert opcodes
450 EndOpCodeHandle
// Replace data
453 HiiFreeOpCodeHandle (StartOpCodeHandle
);
454 HiiFreeOpCodeHandle (EndOpCodeHandle
);
456 if (VlanData
!= NULL
) {
463 This function publish the VLAN configuration Form for a network device. The
464 HII Config Access protocol will be installed on a child handle of the network
467 @param[in, out] PrivateData Points to VLAN configuration private data.
469 @retval EFI_SUCCESS HII Form is installed for this network device.
470 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
471 @retval Others Other errors as indicated.
475 InstallVlanConfigForm (
476 IN OUT VLAN_CONFIG_PRIVATE_DATA
*PrivateData
480 EFI_HII_HANDLE HiiHandle
;
481 EFI_HANDLE DriverHandle
;
482 CHAR16 Str
[26 + sizeof (EFI_MAC_ADDRESS
) * 2 + 1];
484 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
485 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
488 // Create child handle and install HII Config Access Protocol
490 ChildDevicePath
= AppendDevicePathNode (
491 PrivateData
->ParentDevicePath
,
492 (CONST EFI_DEVICE_PATH_PROTOCOL
*) &mHiiVendorDevicePathNode
494 if (ChildDevicePath
== NULL
) {
495 return EFI_OUT_OF_RESOURCES
;
497 PrivateData
->ChildDevicePath
= ChildDevicePath
;
500 ConfigAccess
= &PrivateData
->ConfigAccess
;
501 Status
= gBS
->InstallMultipleProtocolInterfaces (
503 &gEfiDevicePathProtocolGuid
,
505 &gEfiHiiConfigAccessProtocolGuid
,
509 if (EFI_ERROR (Status
)) {
512 PrivateData
->DriverHandle
= DriverHandle
;
515 // Publish the HII package list
517 HiiHandle
= HiiAddPackages (
520 VlanConfigDxeStrings
,
524 if (HiiHandle
== NULL
) {
525 return EFI_OUT_OF_RESOURCES
;
527 PrivateData
->HiiHandle
= HiiHandle
;
530 // Update formset title help string.
533 Status
= NetLibGetMacString (PrivateData
->ControllerHandle
, PrivateData
->ImageHandle
, &MacString
);
534 if (EFI_ERROR (Status
)) {
537 PrivateData
->MacString
= MacString
;
539 StrCpy (Str
, L
"VLAN Configuration (MAC:");
540 StrnCat (Str
, MacString
, sizeof (EFI_MAC_ADDRESS
) * 2);
544 STRING_TOKEN (STR_VLAN_FORM_SET_TITLE_HELP
),
550 // Update form title help string.
554 STRING_TOKEN (STR_VLAN_FORM_HELP
),
563 This function remove the VLAN configuration Form for a network device. The
564 child handle for HII Config Access protocol will be destroyed.
566 @param[in, out] PrivateData Points to VLAN configuration private data.
570 UninstallVlanConfigForm (
571 IN OUT VLAN_CONFIG_PRIVATE_DATA
*PrivateData
577 if (PrivateData
->MacString
!= NULL
) {
578 FreePool (PrivateData
->MacString
);
579 PrivateData
->MacString
= NULL
;
583 // Uninstall HII package list
585 if (PrivateData
->HiiHandle
!= NULL
) {
586 HiiRemovePackages (PrivateData
->HiiHandle
);
587 PrivateData
->HiiHandle
= NULL
;
591 // Uninstall HII Config Access Protocol
593 if (PrivateData
->DriverHandle
!= NULL
) {
594 gBS
->UninstallMultipleProtocolInterfaces (
595 PrivateData
->DriverHandle
,
596 &gEfiDevicePathProtocolGuid
,
597 PrivateData
->ChildDevicePath
,
598 &gEfiHiiConfigAccessProtocolGuid
,
599 &PrivateData
->ConfigAccess
,
602 PrivateData
->DriverHandle
= NULL
;
604 if (PrivateData
->ChildDevicePath
!= NULL
) {
605 FreePool (PrivateData
->ChildDevicePath
);
606 PrivateData
->ChildDevicePath
= NULL
;