2 The Hii functions for WiFi Connection Manager.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "WifiConnectionMgrDxe.h"
12 CHAR16 mVendorStorageName
[] = L
"WIFI_MANAGER_IFR_NVDATA";
14 HII_VENDOR_DEVICE_PATH mWifiMgrDxeHiiVendorDevicePath
= {
20 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
21 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
24 WIFI_CONNECTION_MANAGER_CONFIG_GUID
28 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
30 (UINT8
) (END_DEVICE_PATH_LENGTH
),
31 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
37 // HII Config Access Protocol instance
39 GLOBAL_REMOVE_IF_UNREFERENCED
40 EFI_HII_CONFIG_ACCESS_PROTOCOL gWifiMgrDxeHiiConfigAccess
= {
41 WifiMgrDxeHiiConfigAccessExtractConfig
,
42 WifiMgrDxeHiiConfigAccessRouteConfig
,
43 WifiMgrDxeHiiConfigAccessCallback
46 CHAR16
* mSecurityType
[] = {
56 CHAR16
* mSignalStrengthBar
[] = {
65 #define RSSI_TO_SIGNAL_STRENGTH_BAR(Rssi) mSignalStrengthBar[((Rssi + 19)/20)]
67 #define NET_LIST_FOR_EACH_FROM_NODE(Entry, Node, ListHead) \
68 for(Entry = Node->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
70 extern EFI_GUID gWifiConfigFormSetGuid
;
73 Create Hii Extend Label OpCode as the start opcode and end opcode.
74 The caller is responsible for freeing the OpCode with HiiFreeOpCodeHandle().
76 @param[in] StartLabelNumber The number of start label.
77 @param[out] StartOpCodeHandle Points to the start opcode handle.
78 @param[out] EndOpCodeHandle Points to the end opcode handle.
80 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
82 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
83 @retval EFI_SUCCESS The operation is completed successfully.
84 @retval Other Errors Returned errors when updating the HII form.
89 IN UINT16 StartLabelNumber
,
90 OUT VOID
**StartOpCodeHandle
,
91 OUT VOID
**EndOpCodeHandle
95 EFI_IFR_GUID_LABEL
*InternalStartLabel
;
96 EFI_IFR_GUID_LABEL
*InternalEndLabel
;
98 if (StartOpCodeHandle
== NULL
|| EndOpCodeHandle
== NULL
) {
99 return EFI_INVALID_PARAMETER
;
102 Status
= EFI_OUT_OF_RESOURCES
;
103 *StartOpCodeHandle
= NULL
;
104 *EndOpCodeHandle
= NULL
;
107 // Initialize the container for dynamic opcodes.
109 *StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
110 if (*StartOpCodeHandle
== NULL
) {
113 *EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
114 if (*EndOpCodeHandle
== NULL
) {
119 // Create Hii Extend Label OpCode as the start opcode.
121 InternalStartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
125 sizeof (EFI_IFR_GUID_LABEL
)
127 if (InternalStartLabel
== NULL
) {
130 InternalStartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
131 InternalStartLabel
->Number
= StartLabelNumber
;
134 // Create Hii Extend Label OpCode as the end opcode.
136 InternalEndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
140 sizeof (EFI_IFR_GUID_LABEL
)
142 if (InternalEndLabel
== NULL
) {
145 InternalEndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
146 InternalEndLabel
->Number
= LABEL_END
;
152 if (*StartOpCodeHandle
!= NULL
) {
153 HiiFreeOpCodeHandle (*StartOpCodeHandle
);
155 if (*EndOpCodeHandle
!= NULL
) {
156 HiiFreeOpCodeHandle (*EndOpCodeHandle
);
162 Display the Nic list contains all available Nics.
164 @param[in] Private The pointer to the global private data structure.
166 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
167 @retval EFI_SUCCESS The operation is completed successfully.
172 IN WIFI_MGR_PRIVATE_DATA
*Private
176 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
177 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
178 EFI_STRING_ID PortTitleToken
;
179 EFI_STRING_ID PortTitleHelpToken
;
180 WIFI_MGR_DEVICE_DATA
*Nic
;
182 VOID
*StartOpCodeHandle
;
183 VOID
*EndOpCodeHandle
;
185 if (Private
== NULL
) {
186 return EFI_INVALID_PARAMETER
;
189 Status
= WifiMgrCreateOpCode (
194 if (EFI_ERROR (Status
)) {
198 NET_LIST_FOR_EACH (Entry
, &Private
->NicList
) {
199 Nic
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_MGR_DEVICE_DATA
, Link
, WIFI_MGR_DEVICE_DATA_SIGNATURE
);
200 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
201 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC %s", MacString
);
202 PortTitleToken
= HiiSetString (
203 Private
->RegisteredHandle
,
208 if (PortTitleToken
== 0) {
209 Status
= EFI_INVALID_PARAMETER
;
213 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC Address");
214 PortTitleHelpToken
= HiiSetString (
215 Private
->RegisteredHandle
,
220 if (PortTitleHelpToken
== 0) {
221 Status
= EFI_INVALID_PARAMETER
;
225 HiiCreateGotoOpCode (
227 FORMID_WIFI_MAINPAGE
,
230 EFI_IFR_FLAG_CALLBACK
,
231 (UINT16
) (KEY_MAC_ENTRY_BASE
+ Nic
->NicIndex
)
235 Status
= HiiUpdateForm (
236 Private
->RegisteredHandle
, // HII handle
237 &gWifiConfigFormSetGuid
, // Formset GUID
238 FORMID_MAC_SELECTION
, // Form ID
239 StartOpCodeHandle
, // Label for where to insert opcodes
240 EndOpCodeHandle
// Replace data
245 HiiFreeOpCodeHandle (StartOpCodeHandle
);
246 HiiFreeOpCodeHandle (EndOpCodeHandle
);
251 Retreive the unicode string of the AKM Suite list of a profile.
252 The caller is responsible for freeing the string with FreePool().
254 @param[in] Profile The network profile contains a AKM suite list.
256 @return the unicode string of AKM suite list or "None".
260 WifiMgrGetStrAKMList (
261 IN WIFI_MGR_NETWORK_PROFILE
*Profile
265 UINT16 AKMSuiteCount
;
266 CHAR16
*AKMListDisplay
;
268 AKMListDisplay
= NULL
;
269 if (Profile
== NULL
|| Profile
->Network
.AKMSuite
== NULL
) {
273 AKMSuiteCount
= Profile
->Network
.AKMSuite
->AKMSuiteCount
;
274 if (AKMSuiteCount
!= 0) {
277 // Current AKM Suite is between 1-9
279 AKMListDisplay
= (CHAR16
*) AllocateZeroPool(sizeof (CHAR16
) * AKMSuiteCount
* 2);
280 if (AKMListDisplay
!= NULL
) {
281 for (Index
= 0; Index
< AKMSuiteCount
; Index
++) {
283 AKMListDisplay
+ (Index
* 2),
286 Profile
->Network
.AKMSuite
->AKMSuiteList
[Index
].SuiteType
288 if (Index
== AKMSuiteCount
- 1) {
289 *(AKMListDisplay
+ (Index
* 2 + 1)) = L
'\0';
297 if (AKMListDisplay
== NULL
) {
298 AKMListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
300 return AKMListDisplay
;
304 Retreive the unicode string of the Cipher Suite list of a profile.
305 The caller is responsible for freeing the string with FreePool().
307 @param[in] Profile The network profile contains a Cipher suite list.
309 @return the unicode string of Cipher suite list or "None".
313 WifiMgrGetStrCipherList (
314 IN WIFI_MGR_NETWORK_PROFILE
*Profile
318 UINT16 CipherSuiteCount
;
319 CHAR16
*CipherListDisplay
;
321 CipherListDisplay
= NULL
;
322 if (Profile
== NULL
|| Profile
->Network
.CipherSuite
== NULL
) {
326 CipherSuiteCount
= Profile
->Network
.CipherSuite
->CipherSuiteCount
;
327 if (CipherSuiteCount
!= 0) {
330 // Current Cipher Suite is between 1-9
332 CipherListDisplay
= (CHAR16
*) AllocateZeroPool(sizeof (CHAR16
) * CipherSuiteCount
* 2);
333 if (CipherListDisplay
!= NULL
) {
334 for (Index
= 0; Index
< CipherSuiteCount
; Index
++) {
336 CipherListDisplay
+ (Index
* 2),
339 Profile
->Network
.CipherSuite
->CipherSuiteList
[Index
].SuiteType
341 if (Index
== CipherSuiteCount
- 1) {
342 *(CipherListDisplay
+ (Index
* 2 + 1)) = L
'\0';
350 if (CipherListDisplay
== NULL
) {
351 CipherListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
353 return CipherListDisplay
;
357 Refresh the network list display of the current Nic.
359 @param[in] Private The pointer to the global private data structure.
360 @param[out] IfrNvData The IFR NV data.
362 @retval EFI_SUCCESS The operation is completed successfully.
363 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
364 @retval Other Errors Returned errors when creating Opcodes or updating the
369 WifiMgrRefreshNetworkList (
370 IN WIFI_MGR_PRIVATE_DATA
*Private
,
371 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
376 UINT32 AvailableCount
;
377 EFI_STRING_ID PortPromptToken
;
378 EFI_STRING_ID PortTextToken
;
379 EFI_STRING_ID PortHelpToken
;
380 WIFI_MGR_NETWORK_PROFILE
*Profile
;
382 VOID
*StartOpCodeHandle
;
383 VOID
*EndOpCodeHandle
;
384 CHAR16
*AKMListDisplay
;
385 CHAR16
*CipherListDisplay
;
386 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
387 UINTN PortStringSize
;
388 WIFI_MGR_NETWORK_PROFILE
*ConnectedProfile
;
390 if (Private
->CurrentNic
== NULL
) {
394 Status
= WifiMgrCreateOpCode (
395 LABEL_NETWORK_LIST_ENTRY
,
399 if (EFI_ERROR (Status
)) {
403 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
405 PortStringSize
= sizeof (PortString
);
406 ConnectedProfile
= NULL
;
407 AKMListDisplay
= NULL
;
408 CipherListDisplay
= NULL
;
410 if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
413 // Display the current connected network.
414 // Find the current operate network under connected status.
416 if (Private
->CurrentNic
->CurrentOperateNetwork
!= NULL
&&
417 Private
->CurrentNic
->CurrentOperateNetwork
->IsAvailable
) {
419 Profile
= Private
->CurrentNic
->CurrentOperateNetwork
;
422 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
423 if (AKMListDisplay
== NULL
) {
424 Status
= EFI_OUT_OF_RESOURCES
;
427 CipherListDisplay
= WifiMgrGetStrCipherList(Profile
);
428 if (CipherListDisplay
== NULL
) {
429 Status
= EFI_OUT_OF_RESOURCES
;
433 UnicodeSPrint (PortString
, PortStringSize
, L
"%s (Connected)", Profile
->SSId
);
434 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
436 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
439 UnicodeSPrint (PortString
, PortStringSize
, L
"AKMSuite: %s CipherSuite: %s", AKMListDisplay
, CipherListDisplay
);
440 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
442 FreePool (AKMListDisplay
);
443 FreePool (CipherListDisplay
);
444 AKMListDisplay
= NULL
;
445 CipherListDisplay
= NULL
;
447 HiiCreateGotoOpCode (
449 FORMID_CONNECT_NETWORK
,
452 EFI_IFR_FLAG_CALLBACK
,
453 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
460 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
461 mSecurityType
[Profile
->SecurityType
],
462 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
464 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
466 HiiCreateTextOpCode (
473 ConnectedProfile
= Profile
;
475 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
480 // Display all supported available networks.
482 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
484 Profile
= NET_LIST_USER_STRUCT_S (
486 WIFI_MGR_NETWORK_PROFILE
,
488 WIFI_MGR_PROFILE_SIGNATURE
490 if (ConnectedProfile
== Profile
) {
493 if (Profile
->IsAvailable
&& Profile
->CipherSuiteSupported
) {
497 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
498 if (AKMListDisplay
== NULL
) {
499 Status
= EFI_OUT_OF_RESOURCES
;
502 CipherListDisplay
= WifiMgrGetStrCipherList(Profile
);
503 if (CipherListDisplay
== NULL
) {
504 Status
= EFI_OUT_OF_RESOURCES
;
508 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
509 if (PortPromptToken
== 0) {
510 Status
= EFI_OUT_OF_RESOURCES
;
514 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
520 L
"AKMSuite: %s CipherSuite: %s",
521 AKMListDisplay
, CipherListDisplay
523 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
524 if (PortHelpToken
== 0) {
525 Status
= EFI_OUT_OF_RESOURCES
;
529 FreePool (AKMListDisplay
);
530 FreePool (CipherListDisplay
);
531 AKMListDisplay
= NULL
;
532 CipherListDisplay
= NULL
;
534 HiiCreateGotoOpCode (
536 FORMID_CONNECT_NETWORK
,
539 EFI_IFR_FLAG_CALLBACK
,
540 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
547 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
548 mSecurityType
[Profile
->SecurityType
],
549 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
551 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
552 if (PortTextToken
== 0) {
553 Status
= EFI_OUT_OF_RESOURCES
;
556 HiiCreateTextOpCode (
566 // Display all Unsupported available networks.
568 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
570 Profile
= NET_LIST_USER_STRUCT_S (
572 WIFI_MGR_NETWORK_PROFILE
,
574 WIFI_MGR_PROFILE_SIGNATURE
576 if (ConnectedProfile
== Profile
) {
579 if (Profile
->IsAvailable
&& !Profile
->CipherSuiteSupported
) {
583 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
584 if (AKMListDisplay
== NULL
) {
585 Status
= EFI_OUT_OF_RESOURCES
;
588 CipherListDisplay
= WifiMgrGetStrCipherList(Profile
);
589 if (CipherListDisplay
== NULL
) {
590 Status
= EFI_OUT_OF_RESOURCES
;
594 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
596 if (Profile
->AKMSuiteSupported
) {
600 L
"AKMSuite: %s CipherSuite(UnSupported): %s",
601 AKMListDisplay
, CipherListDisplay
607 L
"AKMSuite(UnSupported): %s CipherSuite(UnSupported): %s",
608 AKMListDisplay
, CipherListDisplay
611 FreePool (AKMListDisplay
);
612 FreePool (CipherListDisplay
);
613 AKMListDisplay
= NULL
;
614 CipherListDisplay
= NULL
;
616 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
618 HiiCreateGotoOpCode (
620 FORMID_CONNECT_NETWORK
,
623 EFI_IFR_FLAG_CALLBACK
,
624 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
632 mSecurityType
[Profile
->SecurityType
],
633 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
635 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
637 HiiCreateTextOpCode (
646 Status
= HiiUpdateForm (
647 Private
->RegisteredHandle
, // HII handle
648 &gWifiConfigFormSetGuid
, // Formset GUID
649 FORMID_NETWORK_LIST
, // Form ID
650 StartOpCodeHandle
, // Label for where to insert opcodes
651 EndOpCodeHandle
// Replace data
656 gBS
->RestoreTPL (OldTpl
);
658 if (AKMListDisplay
!= NULL
) {
659 FreePool (AKMListDisplay
);
661 if (CipherListDisplay
!= NULL
) {
662 FreePool (CipherListDisplay
);
665 HiiFreeOpCodeHandle (StartOpCodeHandle
);
666 HiiFreeOpCodeHandle (EndOpCodeHandle
);
668 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Network List is Refreshed!\n"));
673 Refresh the hidden network list configured by user.
675 @param[in] Private The pointer to the global private data structure.
677 @retval EFI_SUCCESS The operation is completed successfully.
678 @retval Other Errors Returned errors when creating Opcodes or updating the
682 WifiMgrRefreshHiddenList (
683 IN WIFI_MGR_PRIVATE_DATA
*Private
689 EFI_STRING_ID StringId
;
690 VOID
*StartOpCodeHandle
;
691 VOID
*EndOpCodeHandle
;
692 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
695 if (Private
== NULL
) {
699 Status
= WifiMgrCreateOpCode (
700 LABEL_HIDDEN_NETWORK_ENTRY
,
704 if (EFI_ERROR (Status
)) {
708 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
711 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
713 HiddenNetwork
= NET_LIST_USER_STRUCT_S (
715 WIFI_HIDDEN_NETWORK_DATA
,
717 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
719 StringId
= HiiSetString (Private
->RegisteredHandle
, 0, HiddenNetwork
->SSId
, NULL
);
721 HiiCreateCheckBoxOpCode (
723 (EFI_QUESTION_ID
) (KEY_HIDDEN_NETWORK_ENTRY_BASE
+ Index
),
725 (UINT16
) (HIDDEN_NETWORK_LIST_VAR_OFFSET
+ Index
),
735 Status
= HiiUpdateForm (
736 Private
->RegisteredHandle
, // HII handle
737 &gWifiConfigFormSetGuid
, // Formset GUID
738 FORMID_HIDDEN_NETWORK_LIST
, // Form ID
739 StartOpCodeHandle
, // Label for where to insert opcodes
740 EndOpCodeHandle
// Replace data
743 gBS
->RestoreTPL (OldTpl
);
744 HiiFreeOpCodeHandle (StartOpCodeHandle
);
745 HiiFreeOpCodeHandle (EndOpCodeHandle
);
751 Callback function for user to select a Nic.
753 @param[in] Private The pointer to the global private data structure.
754 @param[in] KeyValue The key value received from HII input.
756 @retval EFI_NOT_FOUND The corresponding Nic is not found.
757 @retval EFI_SUCCESS The operation is completed successfully.
762 IN WIFI_MGR_PRIVATE_DATA
*Private
,
763 IN EFI_QUESTION_ID KeyValue
766 WIFI_MGR_DEVICE_DATA
*Nic
;
768 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
770 NicIndex
= KeyValue
- KEY_MAC_ENTRY_BASE
;
771 Nic
= WifiMgrGetNicByIndex (Private
, NicIndex
);
773 return EFI_NOT_FOUND
;
775 Private
->CurrentNic
= Nic
;
777 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
778 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN(STR_MAC_ADDRESS
), MacString
, NULL
);
783 Restore the NV data to be default.
785 @param[in] Private The pointer to the global private data structure.
786 @param[out] IfrNvData The IFR NV data.
790 WifiMgrCleanUserInput (
791 IN WIFI_MGR_PRIVATE_DATA
*Private
794 Private
->SecurityType
= SECURITY_TYPE_NONE
;
795 Private
->EapAuthMethod
= EAP_AUTH_METHOD_TTLS
;
796 Private
->EapSecondAuthMethod
= EAP_SEAUTH_METHOD_MSCHAPV2
;
797 Private
->FileType
= FileTypeMax
;
801 UI handle function when user select a network to connect.
803 @param[in] Private The pointer to the global private data structure.
804 @param[in] ProfileIndex The profile index user selected to connect.
806 @retval EFI_INVALID_PARAMETER Nic is null.
807 @retval EFI_NOT_FOUND Profile could not be found.
808 @retval EFI_SUCCESS The operation is completed successfully.
812 WifiMgrUserSelectProfileToConnect(
813 IN WIFI_MGR_PRIVATE_DATA
*Private
,
814 IN UINT32 ProfileIndex
817 WIFI_MGR_NETWORK_PROFILE
*Profile
;
818 WIFI_MGR_DEVICE_DATA
*Nic
;
820 Nic
= Private
->CurrentNic
;
822 return EFI_INVALID_PARAMETER
;
826 //Initialize the connection page
828 WifiMgrCleanUserInput(Private
);
830 Profile
= WifiMgrGetProfileByProfileIndex (ProfileIndex
, &Nic
->ProfileList
);
831 if (Profile
== NULL
) {
832 return EFI_NOT_FOUND
;
834 Private
->CurrentNic
->UserSelectedProfile
= Profile
;
840 Record password from a HII input string.
842 @param[in] Private The pointer to the global private data structure.
843 @param[in] StringId The QuestionId received from HII input.
844 @param[in] StringBuffer The unicode string buffer to store password.
845 @param[in] StringBufferLen The len of unicode string buffer.
847 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
848 @retval EFI_NOT_FOUND The password string is not found or invalid.
849 @retval EFI_SUCCESS The operation is completed successfully.
853 WifiMgrRecordPassword (
854 IN WIFI_MGR_PRIVATE_DATA
*Private
,
855 IN EFI_STRING_ID StringId
,
856 IN CHAR16
*StringBuffer
,
857 IN UINTN StringBufferLen
862 if (StringId
== 0 || StringBuffer
== NULL
|| StringBufferLen
<= 0) {
863 return EFI_INVALID_PARAMETER
;
866 Password
= HiiGetString (Private
->RegisteredHandle
, StringId
, NULL
);
867 if (Password
== NULL
) {
868 return EFI_NOT_FOUND
;
870 if (StrLen (Password
) > StringBufferLen
) {
872 return EFI_NOT_FOUND
;
874 StrnCpyS (StringBuffer
, StringBufferLen
, Password
, StrLen (Password
));
875 ZeroMem (Password
, (StrLen (Password
) + 1) * sizeof (CHAR16
));
879 // Clean password in string package
881 HiiSetString (Private
->RegisteredHandle
, StringId
, L
"", NULL
);
886 Update connection message on connect configuration page, and trigger related form refresh.
888 @param[in] Nic The related Nic for updating message.
889 @param[in] ConnectStateChanged The tag to tell if the connection state has been changed, only
890 when the connection changes from "Connected" or "Disconnecting"
891 to "Disconnected", or from "Disconnected" or "Connecting" to
892 "Connected", this tag can be set as TRUE.
893 @param[in] ConnectStatusMessage The message to show on connected status bar, if NULL, will
898 WifiMgrUpdateConnectMessage (
899 IN WIFI_MGR_DEVICE_DATA
*Nic
,
900 IN BOOLEAN ConnectStateChanged
,
901 IN EFI_STRING ConnectStatusMessage
904 CHAR16 ConnectStatusStr
[WIFI_STR_MAX_SIZE
];
905 WIFI_MGR_PRIVATE_DATA
*Private
;
907 Private
= Nic
->Private
;
908 if (Private
== NULL
|| Private
->CurrentNic
!= Nic
) {
913 // Update Connection Status Bar
915 if (ConnectStatusMessage
!= NULL
) {
916 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusMessage
, NULL
);
918 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
920 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Connected to %s",
921 Nic
->CurrentOperateNetwork
->SSId
);
922 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
923 } else if (Nic
->ConnectState
== WifiMgrDisconnected
) {
925 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), L
"Disconnected", NULL
);
926 } else if (Nic
->ConnectState
== WifiMgrConnectingToAp
) {
928 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Connecting to %s ...",
929 Nic
->CurrentOperateNetwork
->SSId
);
930 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
931 } else if (Nic
->ConnectState
== WifiMgrDisconnectingToAp
) {
933 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Disconnecting from %s ...",
934 Nic
->CurrentOperateNetwork
->SSId
);
935 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
942 // Update Connect Button
944 if (Nic
->ConnectState
== WifiMgrConnectedToAp
&& Nic
->UserSelectedProfile
== Nic
->CurrentOperateNetwork
) {
946 HiiSetString (Private
->RegisteredHandle
,
947 STRING_TOKEN (STR_CONNECT_NOW
), L
"Disconnect from this Network", NULL
);
949 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_NOW
), L
"Connect to this Network", NULL
);
951 gBS
->SignalEvent (Private
->ConnectFormRefreshEvent
);
954 // Update Main Page and Network List
956 if (ConnectStateChanged
) {
958 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
960 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Connected to", NULL
);
961 HiiSetString (Private
->RegisteredHandle
,
962 STRING_TOKEN (STR_CONNECTED_SSID
), Nic
->CurrentOperateNetwork
->SSId
, NULL
);
964 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Disconnected", NULL
);
965 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTED_SSID
), L
"", NULL
);
968 gBS
->SignalEvent (Private
->NetworkListRefreshEvent
);
969 gBS
->SignalEvent (Private
->MainPageRefreshEvent
);
974 Convert the driver configuration data into the IFR data.
976 @param[in] Private The pointer to the global private data structure.
977 @param[out] IfrNvData The IFR NV data.
979 @retval EFI_SUCCESS The operation is completed successfully.
983 WifiMgrConvertConfigDataToIfrNvData (
984 IN WIFI_MGR_PRIVATE_DATA
*Private
,
985 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
989 // Private shouldn't be NULL here, assert if Private is NULL.
991 ASSERT (Private
!= NULL
);
993 if (Private
->CurrentNic
!= NULL
) {
994 IfrNvData
->ProfileCount
= Private
->CurrentNic
->AvailableCount
;
996 IfrNvData
->ProfileCount
= 0;
1003 Convert the IFR data into the driver configuration data.
1005 @param[in] Private The pointer to the global private data structure.
1006 @param[in, out] IfrNvData The IFR NV data.
1008 @retval EFI_SUCCESS The operation is completed successfully.
1012 WifiMgrConvertIfrNvDataToConfigData (
1013 IN WIFI_MGR_PRIVATE_DATA
*Private
,
1014 IN OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
1021 This function allows the caller to request the current
1022 configuration for one or more named elements. The resulting
1023 string is in <ConfigAltResp> format. Any and all alternative
1024 configuration strings shall also be appended to the end of the
1025 current configuration string. If they are, they must appear
1026 after the current configuration. They must contain the same
1027 routing (GUID, NAME, PATH) as the current configuration string.
1028 They must have an additional description indicating the type of
1029 alternative configuration the string represents,
1030 "ALTCFG=<StringToken>". That <StringToken> (when
1031 converted from Hex UNICODE to binary) is a reference to a
1032 string in the associated string pack.
1034 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1036 @param Request A null-terminated Unicode string in
1037 <ConfigRequest> format. Note that this
1038 includes the routing information as well as
1039 the configurable name / value pairs. It is
1040 invalid for this string to be in
1041 <MultiConfigRequest> format.
1042 If a NULL is passed in for the Request field,
1043 all of the settings being abstracted by this function
1044 will be returned in the Results field. In addition,
1045 if a ConfigHdr is passed in with no request elements,
1046 all of the settings being abstracted for that particular
1047 ConfigHdr reference will be returned in the Results Field.
1049 @param Progress On return, points to a character in the
1050 Request string. Points to the string's null
1051 terminator if request was successful. Points
1052 to the most recent "&" before the first
1053 failing name / value pair (or the beginning
1054 of the string if the failure is in the first
1055 name / value pair) if the request was not
1058 @param Results A null-terminated Unicode string in
1059 <MultiConfigAltResp> format which has all values
1060 filled in for the names in the Request string.
1061 String to be allocated by the called function.
1063 @retval EFI_SUCCESS The Results string is filled with the
1064 values corresponding to all requested
1067 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1068 parts of the results that must be
1069 stored awaiting possible future
1072 @retval EFI_NOT_FOUND Routing data doesn't match any
1073 known driver. Progress set to the
1074 first character in the routing header.
1075 Note: There is no requirement that the
1076 driver validate the routing data. It
1077 must skip the <ConfigHdr> in order to
1080 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
1081 to most recent "&" before the
1082 error or the beginning of the
1085 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
1086 to the & before the name in
1092 WifiMgrDxeHiiConfigAccessExtractConfig (
1093 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1094 IN CONST EFI_STRING Request
,
1095 OUT EFI_STRING
*Progress
,
1096 OUT EFI_STRING
*Results
1099 WIFI_MGR_PRIVATE_DATA
*Private
;
1100 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1101 EFI_STRING ConfigRequestHdr
;
1102 EFI_STRING ConfigRequest
;
1104 BOOLEAN AllocatedRequest
;
1108 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
1109 return EFI_INVALID_PARAMETER
;
1112 *Progress
= Request
;
1113 if ((Request
!= NULL
) &&
1114 !HiiIsConfigHdrMatch (Request
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1115 return EFI_NOT_FOUND
;
1118 ConfigRequestHdr
= NULL
;
1119 ConfigRequest
= NULL
;
1120 AllocatedRequest
= FALSE
;
1123 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1125 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1126 IfrNvData
= AllocateZeroPool (BufferSize
);
1127 if (IfrNvData
== NULL
) {
1128 return EFI_OUT_OF_RESOURCES
;
1131 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1133 ConfigRequest
= Request
;
1134 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1136 // Request has no request element, construct full request string.
1137 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1138 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
1140 ConfigRequestHdr
= HiiConstructConfigHdr (
1141 &gWifiConfigFormSetGuid
,
1143 Private
->DriverHandle
);
1144 if (ConfigRequestHdr
== NULL
) {
1145 FreePool (IfrNvData
);
1146 return EFI_OUT_OF_RESOURCES
;
1149 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1150 ConfigRequest
= AllocateZeroPool (Size
);
1151 if (ConfigRequest
== NULL
) {
1153 FreePool (IfrNvData
);
1154 FreePool (ConfigRequestHdr
);
1155 return EFI_OUT_OF_RESOURCES
;
1158 AllocatedRequest
= TRUE
;
1162 L
"%s&OFFSET=0&WIDTH=%016LX",
1166 FreePool (ConfigRequestHdr
);
1170 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1172 Status
= gHiiConfigRouting
->BlockToConfig (
1175 (UINT8
*) IfrNvData
,
1181 FreePool (IfrNvData
);
1183 // Free the allocated config request string.
1185 if (AllocatedRequest
) {
1186 FreePool (ConfigRequest
);
1187 ConfigRequest
= NULL
;
1190 // Set Progress string to the original request string.
1192 if (Request
== NULL
) {
1194 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1195 *Progress
= Request
+ StrLen (Request
);
1202 This function applies changes in a driver's configuration.
1203 Input is a Configuration, which has the routing data for this
1204 driver followed by name / value configuration pairs. The driver
1205 must apply those pairs to its configurable storage. If the
1206 driver's configuration is stored in a linear block of data
1207 and the driver's name / value pairs are in <BlockConfig>
1208 format, it may use the ConfigToBlock helper function (above) to
1211 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1213 @param Configuration A null-terminated Unicode string in
1214 <ConfigString> format.
1216 @param Progress A pointer to a string filled in with the
1217 offset of the most recent '&' before the
1218 first failing name / value pair (or the
1219 beginn ing of the string if the failure
1220 is in the first name / value pair) or
1221 the terminating NULL if all was
1224 @retval EFI_SUCCESS The results have been distributed or are
1225 awaiting distribution.
1227 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1228 parts of the results that must be
1229 stored awaiting possible future
1232 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
1233 Results parameter would result
1234 in this type of error.
1236 @retval EFI_NOT_FOUND Target for the specified routing data
1242 WifiMgrDxeHiiConfigAccessRouteConfig (
1243 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1244 IN CONST EFI_STRING Configuration
,
1245 OUT EFI_STRING
*Progress
1250 WIFI_MGR_PRIVATE_DATA
*Private
;
1251 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1253 if (Configuration
== NULL
|| Progress
== NULL
) {
1254 return EFI_INVALID_PARAMETER
;
1258 *Progress
= Configuration
;
1259 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1260 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1262 if (!HiiIsConfigHdrMatch (Configuration
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1263 return EFI_NOT_FOUND
;
1266 IfrNvData
= AllocateZeroPool (BufferSize
);
1267 if (IfrNvData
== NULL
) {
1268 return EFI_OUT_OF_RESOURCES
;
1271 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1273 Status
= gHiiConfigRouting
->ConfigToBlock (
1280 if (EFI_ERROR (Status
)) {
1284 Status
= WifiMgrConvertIfrNvDataToConfigData (Private
, IfrNvData
);
1285 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1286 FreePool (IfrNvData
);
1292 This function is called to provide results data to the driver.
1293 This data consists of a unique key that is used to identify
1294 which data is either being passed back or being asked for.
1296 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1297 @param Action Specifies the type of action taken by the browser.
1298 @param QuestionId A unique value which is sent to the original
1299 exporting driver so that it can identify the type
1300 of data to expect. The format of the data tends to
1301 vary based on the opcode that generated the callback.
1302 @param Type The type of value for the question.
1303 @param Value A pointer to the data being sent to the original
1305 @param ActionRequest On return, points to the action requested by the
1308 @retval EFI_SUCCESS The callback successfully handled the action.
1309 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1310 variable and its data.
1311 @retval EFI_DEVICE_ERROR The variable could not be saved.
1312 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1318 WifiMgrDxeHiiConfigAccessCallback (
1319 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1320 IN EFI_BROWSER_ACTION Action
,
1321 IN EFI_QUESTION_ID QuestionId
,
1323 IN OUT EFI_IFR_TYPE_VALUE
*Value
,
1324 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1330 WIFI_MGR_PRIVATE_DATA
*Private
;
1331 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1332 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
1333 WIFI_MGR_NETWORK_PROFILE
*Profile
;
1334 WIFI_MGR_NETWORK_PROFILE
*ProfileToConnect
;
1335 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
1341 CHAR16
*TempPassword
;
1342 CHAR16
*ErrorMessage
;
1344 if (Action
!= EFI_BROWSER_ACTION_FORM_OPEN
&&
1345 Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
&&
1346 Action
!= EFI_BROWSER_ACTION_CHANGING
&&
1347 Action
!= EFI_BROWSER_ACTION_CHANGED
&&
1348 Action
!= EFI_BROWSER_ACTION_RETRIEVE
) {
1350 return EFI_UNSUPPORTED
;
1352 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
1353 return EFI_INVALID_PARAMETER
;
1356 Status
= EFI_SUCCESS
;
1357 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1358 if (Private
->CurrentNic
== NULL
) {
1359 return EFI_DEVICE_ERROR
;
1363 // Retrieve uncommitted data from Browser
1365 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1366 IfrNvData
= AllocateZeroPool (BufferSize
);
1367 if (IfrNvData
== NULL
) {
1368 return EFI_OUT_OF_RESOURCES
;
1370 HiiGetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*) IfrNvData
);
1372 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
1373 switch (QuestionId
) {
1377 Status
= WifiMgrShowNicList (Private
);
1380 case KEY_REFRESH_NETWORK_LIST
:
1382 if (Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1384 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1387 // Erase secrets since user has left Connection Page
1388 // Connection Page may direct to Network List Page or Eap Configuration Page,
1389 // secrets only need to be erased when head to Network List Page
1391 WifiMgrCleanProfileSecrets (Profile
);
1393 Private
->CurrentNic
->UserSelectedProfile
= NULL
;
1398 case KEY_CONNECT_ACTION
:
1400 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1403 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1406 //Enter the network connection configuration page
1407 //Recovery from restored data
1409 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SSID
), Profile
->SSId
, NULL
) == 0) {
1410 return EFI_OUT_OF_RESOURCES
;
1412 IfrNvData
->SecurityType
= Profile
->SecurityType
;
1413 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SECURITY_TYPE
),
1414 mSecurityType
[IfrNvData
->SecurityType
], NULL
) == 0) {
1415 return EFI_OUT_OF_RESOURCES
;
1418 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1420 IfrNvData
->EapAuthMethod
= Profile
->EapAuthMethod
;
1421 IfrNvData
->EapSecondAuthMethod
= Profile
->EapSecondAuthMethod
;
1422 StrCpyS (IfrNvData
->EapIdentity
, EAP_IDENTITY_SIZE
, Profile
->EapIdentity
);
1427 case KEY_ENROLLED_CERT_NAME
:
1429 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1432 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1435 //Enter the key enrollment page
1436 //For TTLS and PEAP, only CA cert needs to be cared
1438 if (Private
->FileType
== FileTypeCACert
) {
1440 if (Profile
->CACertData
!= NULL
) {
1441 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->CACertName
, NULL
);
1443 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1445 } else if (Private
->FileType
== FileTypeClientCert
) {
1447 if (Profile
->ClientCertData
!= NULL
) {
1448 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->ClientCertName
, NULL
);
1450 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1455 case KEY_ENROLLED_PRIVATE_KEY_NAME
:
1457 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1460 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1462 if (Profile
->PrivateKeyData
!= NULL
) {
1463 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), Profile
->PrivateKeyName
, NULL
);
1465 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), L
"", NULL
);
1472 } else if (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
) {
1473 switch (QuestionId
) {
1475 case KEY_CONNECT_ACTION
:
1477 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1480 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1483 //Restore User Config Data for Page recovery
1485 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1487 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1488 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1489 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1496 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1497 switch (QuestionId
) {
1499 case KEY_NETWORK_LIST
:
1502 //User triggered a scan process.
1504 Private
->CurrentNic
->OneTimeScanRequest
= TRUE
;
1507 case KEY_PASSWORD_CONNECT_NETWORK
:
1508 case KEY_EAP_PASSWORD_CONNECT_NETWORK
:
1509 case KEY_PRIVATE_KEY_PASSWORD
:
1511 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1514 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1516 if (QuestionId
== KEY_PASSWORD_CONNECT_NETWORK
) {
1517 TempPassword
= Profile
->Password
;
1518 } else if (QuestionId
== KEY_EAP_PASSWORD_CONNECT_NETWORK
) {
1519 TempPassword
= Profile
->EapPassword
;
1521 TempPassword
= Profile
->PrivateKeyPassword
;
1524 Status
= WifiMgrRecordPassword (Private
, Value
->string
, TempPassword
, PASSWORD_STORAGE_SIZE
);
1525 if (EFI_ERROR (Status
)) {
1526 DEBUG ((DEBUG_ERROR
, "[WiFi Connection Manager] Error: Failed to input password!"));
1531 // This password is not a new created password, so no need to confirm.
1533 Status
= EFI_NOT_FOUND
;
1536 case KEY_CONNECT_ACTION
:
1538 ErrorMessage
= NULL
;
1539 ProfileToConnect
= NULL
;
1541 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1544 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1546 if (Private
->CurrentNic
->ConnectState
== WifiMgrDisconnected
||
1547 Profile
!= Private
->CurrentNic
->CurrentOperateNetwork
) {
1550 // When this network is not currently connected, pend it to connect.
1552 if (Profile
->AKMSuiteSupported
&& Profile
->CipherSuiteSupported
) {
1554 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
|| Profile
->SecurityType
== SECURITY_TYPE_WPA2_PERSONAL
) {
1557 // For Open network, connect directly.
1559 ProfileToConnect
= Profile
;
1561 } else if (Profile
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1564 // For WPA/WPA2-Enterprise network, conduct eap configuration first.
1565 // Only EAP-TLS, TTLS and PEAP is supported now!
1567 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1568 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1570 if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TTLS
|| IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_PEAP
) {
1572 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1573 ProfileToConnect
= Profile
;
1574 } else if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TLS
) {
1575 ProfileToConnect
= Profile
;
1577 ErrorMessage
= L
"ERROR: Only EAP-TLS, TTLS or PEAP is supported now!";
1580 ErrorMessage
= L
"ERROR: Can't connect to this network!";
1583 ErrorMessage
= L
"ERROR: This network is not supported!";
1586 if (ErrorMessage
!= NULL
) {
1588 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1595 if (ProfileToConnect
!= NULL
) {
1597 Private
->CurrentNic
->OneTimeConnectRequest
= TRUE
;
1598 Private
->CurrentNic
->ConnectPendingNetwork
= ProfileToConnect
;
1600 } else if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
1603 // This network is currently connected, just disconnect from it.
1605 Private
->CurrentNic
->OneTimeDisconnectRequest
= TRUE
;
1606 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
1610 case KEY_ENROLL_CA_CERT_CONNECT_NETWORK
:
1612 Private
->FileType
= FileTypeCACert
;
1615 case KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK
:
1617 Private
->FileType
= FileTypeClientCert
;
1620 case KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE
:
1623 ChooseFile (NULL
, NULL
, NULL
, &FilePath
);
1625 if (FilePath
!= NULL
) {
1627 UpdatePrivateKeyFromFile(Private
, FilePath
);
1628 FreePool (FilePath
);
1632 case KEY_EAP_ENROLL_CERT_FROM_FILE
:
1635 //User will select a cert file from File Explore
1638 ChooseFile( NULL
, NULL
, NULL
, &FilePath
);
1640 if (FilePath
!= NULL
) {
1642 UpdateCAFromFile(Private
, FilePath
);
1643 FreePool (FilePath
);
1647 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1649 if (Private
->FileContext
!= NULL
&& Private
->FileContext
->FHandle
!= NULL
&&
1650 Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1653 // Read Private Key file to Buffer
1655 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1656 if (Profile
->PrivateKeyData
!= NULL
) {
1658 ZeroMem (Profile
->PrivateKeyData
, Profile
->PrivateKeyDataSize
);
1659 FreePool (Profile
->PrivateKeyData
);
1660 Profile
->PrivateKeyData
= NULL
;
1663 Status
= WifiMgrReadFileToBuffer (
1664 Private
->FileContext
,
1668 if (EFI_ERROR (Status
)) {
1670 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1672 L
"ERROR: Can't read this private key file!",
1677 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1679 Profile
->PrivateKeyData
= TempData
;
1680 Profile
->PrivateKeyDataSize
= TempDataSize
;
1681 StrCpyS(Profile
->PrivateKeyName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1683 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Private Key: %s has been enrolled! Size: %d\n",
1684 Profile
->PrivateKeyName
, Profile
->PrivateKeyDataSize
));
1689 case KEY_SAVE_CERT_TO_MEM
:
1691 if (Private
->FileContext
!= NULL
&& Private
->FileContext
->FHandle
!= NULL
&&
1692 Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1695 // Read Cert file to Buffer
1697 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1699 if (Private
->FileType
== FileTypeCACert
) {
1700 if (Profile
->CACertData
!= NULL
) {
1702 ZeroMem (Profile
->CACertData
, Profile
->CACertSize
);
1703 FreePool (Profile
->CACertData
);
1704 Profile
->CACertData
= NULL
;
1706 } else if (Private
->FileType
== FileTypeClientCert
) {
1707 if (Profile
->ClientCertData
!= NULL
) {
1709 ZeroMem (Profile
->ClientCertData
, Profile
->ClientCertSize
);
1710 FreePool (Profile
->ClientCertData
);
1711 Profile
->ClientCertData
= NULL
;
1717 Status
= WifiMgrReadFileToBuffer (
1718 Private
->FileContext
,
1722 if (EFI_ERROR (Status
)) {
1724 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1726 L
"ERROR: Can't read this certificate file!",
1731 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1732 if (Private
->FileType
== FileTypeCACert
) {
1734 Profile
->CACertData
= TempData
;
1735 Profile
->CACertSize
= TempDataSize
;
1736 StrCpyS(Profile
->CACertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1737 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] CA Cert: %s has been enrolled! Size: %d\n",
1738 Profile
->CACertName
, Profile
->CACertSize
));
1741 Profile
->ClientCertData
= TempData
;
1742 Profile
->ClientCertSize
= TempDataSize
;
1743 StrCpyS(Profile
->ClientCertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1744 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Client Cert: %s has been enrolled! Size: %d\n",
1745 Profile
->ClientCertName
, Profile
->ClientCertSize
));
1751 case KEY_ADD_HIDDEN_NETWORK
:
1754 // Add a Hidden Network
1756 if (StrLen (IfrNvData
->SSId
) < SSID_MIN_LEN
||
1757 Private
->HiddenNetworkCount
>= HIDDEN_NETWORK_LIST_COUNT_MAX
) {
1759 Status
= EFI_ABORTED
;
1764 // Check if this SSId is already in Hidden Network List
1766 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
1768 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
,
1769 Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1770 if (StrCmp (HiddenNetwork
->SSId
, IfrNvData
->SSId
) == 0) {
1772 Status
= EFI_ABORTED
;
1778 HiddenNetwork
= (WIFI_HIDDEN_NETWORK_DATA
*) AllocateZeroPool (sizeof (WIFI_HIDDEN_NETWORK_DATA
));
1779 if (HiddenNetwork
== NULL
) {
1781 Status
= EFI_OUT_OF_RESOURCES
;
1784 HiddenNetwork
->Signature
= WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
;
1785 StrCpyS (HiddenNetwork
->SSId
, SSID_STORAGE_SIZE
, IfrNvData
->SSId
);
1787 InsertTailList (&Private
->HiddenNetworkList
, &HiddenNetwork
->Link
);
1788 Private
->HiddenNetworkCount
++;
1790 WifiMgrRefreshHiddenList (Private
);
1793 case KEY_REMOVE_HIDDEN_NETWORK
:
1796 // Remove Hidden Networks
1798 Entry
= GetFirstNode (&Private
->HiddenNetworkList
);
1800 for (Index
= 0; Index
< Private
->HiddenNetworkCount
; Index
++) {
1801 if (IfrNvData
->HiddenNetworkList
[Index
] != 0) {
1803 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
, Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1804 Entry
= RemoveEntryList (Entry
);
1807 FreePool (HiddenNetwork
);
1809 Entry
= GetNextNode (&Private
->HiddenNetworkList
, Entry
);
1813 Private
->HiddenNetworkCount
-= RemoveCount
;
1814 WifiMgrRefreshHiddenList (Private
);
1819 if (QuestionId
>= KEY_MAC_ENTRY_BASE
&& QuestionId
< KEY_MAC_ENTRY_BASE
+ Private
->NicCount
) {
1821 // User selects a wireless NIC.
1823 Status
= WifiMgrSelectNic (Private
, QuestionId
);
1824 if (EFI_ERROR (Status
)) {
1826 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1828 L
"ERROR: Fail to operate the wireless NIC!",
1832 } else if (Private
->CurrentNic
!= NULL
) {
1833 if (QuestionId
>= KEY_AVAILABLE_NETWORK_ENTRY_BASE
&&
1834 QuestionId
<= KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Private
->CurrentNic
->MaxProfileIndex
) {
1836 Status
= WifiMgrUserSelectProfileToConnect (Private
, QuestionId
- KEY_AVAILABLE_NETWORK_ENTRY_BASE
);
1837 if (!EFI_ERROR (Status
)) {
1838 WifiMgrUpdateConnectMessage(Private
->CurrentNic
, FALSE
, NULL
);
1842 if (EFI_ERROR (Status
)) {
1844 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1846 L
"ERROR: Fail to operate this profile!",
1854 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1855 switch (QuestionId
) {
1857 case KEY_SAVE_CERT_TO_MEM
:
1858 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1860 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1863 case KEY_NO_SAVE_CERT_TO_MEM
:
1864 case KEY_NO_SAVE_PRIVATE_KEY_TO_MEM
:
1866 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1871 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1874 } else if (Action
== EFI_BROWSER_ACTION_RETRIEVE
) {
1876 switch (QuestionId
) {
1878 case KEY_REFRESH_NETWORK_LIST
:
1880 WifiMgrRefreshNetworkList (Private
, IfrNvData
);
1888 if (!EFI_ERROR (Status
)) {
1890 // Pass changed uncommitted data back to Form Browser.
1892 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1893 HiiSetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*) IfrNvData
, NULL
);
1896 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1897 FreePool (IfrNvData
);
1902 Initialize the WiFi configuration form.
1904 @param[in] Private The pointer to the global private data structure.
1906 @retval EFI_SUCCESS The configuration form is initialized.
1907 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1908 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1909 @retval Other Erros Returned Errors when installing protocols.
1913 WifiMgrDxeConfigFormInit (
1914 WIFI_MGR_PRIVATE_DATA
*Private
1919 if (Private
== NULL
) {
1920 return EFI_INVALID_PARAMETER
;
1923 Private
->ConfigAccess
.ExtractConfig
= WifiMgrDxeHiiConfigAccessExtractConfig
;
1924 Private
->ConfigAccess
.RouteConfig
= WifiMgrDxeHiiConfigAccessRouteConfig
;
1925 Private
->ConfigAccess
.Callback
= WifiMgrDxeHiiConfigAccessCallback
;
1928 // Install Device Path Protocol and Config Access protocol to driver handle.
1930 Status
= gBS
->InstallMultipleProtocolInterfaces (
1931 &Private
->DriverHandle
,
1932 &gEfiDevicePathProtocolGuid
,
1933 &mWifiMgrDxeHiiVendorDevicePath
,
1934 &gEfiHiiConfigAccessProtocolGuid
,
1935 &Private
->ConfigAccess
,
1938 if (EFI_ERROR (Status
)) {
1943 // Publish our HII data.
1945 Private
->RegisteredHandle
= HiiAddPackages (
1946 &gWifiConfigFormSetGuid
,
1947 Private
->DriverHandle
,
1948 WifiConnectionManagerDxeStrings
,
1949 WifiConnectionManagerDxeBin
,
1952 if (Private
->RegisteredHandle
== NULL
) {
1953 gBS
->UninstallMultipleProtocolInterfaces (
1954 Private
->DriverHandle
,
1955 &gEfiDevicePathProtocolGuid
,
1956 &mWifiMgrDxeHiiVendorDevicePath
,
1957 &gEfiHiiConfigAccessProtocolGuid
,
1958 &Private
->ConfigAccess
,
1961 return EFI_OUT_OF_RESOURCES
;
1964 Private
->FileContext
= AllocateZeroPool (sizeof (WIFI_MGR_FILE_CONTEXT
));
1965 if (Private
->FileContext
== NULL
) {
1966 return EFI_OUT_OF_RESOURCES
;
1973 Unload the WiFi configuration form.
1975 @param[in] Private The pointer to the global private data structure.
1977 @retval EFI_SUCCESS The configuration form is unloaded successfully.
1978 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1979 @retval Other Errors Returned Erros when uninstalling protocols.
1983 WifiMgrDxeConfigFormUnload (
1984 WIFI_MGR_PRIVATE_DATA
*Private
1989 if (Private
== NULL
) {
1990 return EFI_INVALID_PARAMETER
;
1993 if (Private
->FileContext
!= NULL
) {
1995 if (Private
->FileContext
->FHandle
!= NULL
) {
1996 Private
->FileContext
->FHandle
->Close (Private
->FileContext
->FHandle
);
1999 if (Private
->FileContext
->FileName
!= NULL
) {
2000 FreePool (Private
->FileContext
->FileName
);
2002 FreePool (Private
->FileContext
);
2005 HiiRemovePackages(Private
->RegisteredHandle
);
2007 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2008 Private
->DriverHandle
,
2009 &gEfiDevicePathProtocolGuid
,
2010 &mWifiMgrDxeHiiVendorDevicePath
,
2011 &gEfiHiiConfigAccessProtocolGuid
,
2012 &Private
->ConfigAccess
,