2 The Hii functions for WiFi Connection Manager.
4 Copyright (c) 2019 - 2022, 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
[] = {
58 CHAR16
*mSignalStrengthBar
[] = {
67 #define RSSI_TO_SIGNAL_STRENGTH_BAR(Rssi) mSignalStrengthBar[((Rssi + 19)/20)]
69 #define NET_LIST_FOR_EACH_FROM_NODE(Entry, Node, ListHead) \
70 for(Entry = Node->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
72 extern EFI_GUID gWifiConfigFormSetGuid
;
75 Create Hii Extend Label OpCode as the start opcode and end opcode.
76 The caller is responsible for freeing the OpCode with HiiFreeOpCodeHandle().
78 @param[in] StartLabelNumber The number of start label.
79 @param[out] StartOpCodeHandle Points to the start opcode handle.
80 @param[out] EndOpCodeHandle Points to the end opcode handle.
82 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
84 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
85 @retval EFI_SUCCESS The operation is completed successfully.
86 @retval Other Errors Returned errors when updating the HII form.
91 IN UINT16 StartLabelNumber
,
92 OUT VOID
**StartOpCodeHandle
,
93 OUT VOID
**EndOpCodeHandle
97 EFI_IFR_GUID_LABEL
*InternalStartLabel
;
98 EFI_IFR_GUID_LABEL
*InternalEndLabel
;
100 if ((StartOpCodeHandle
== NULL
) || (EndOpCodeHandle
== NULL
)) {
101 return EFI_INVALID_PARAMETER
;
104 Status
= EFI_OUT_OF_RESOURCES
;
105 *StartOpCodeHandle
= NULL
;
106 *EndOpCodeHandle
= NULL
;
109 // Initialize the container for dynamic opcodes.
111 *StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
112 if (*StartOpCodeHandle
== NULL
) {
116 *EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
117 if (*EndOpCodeHandle
== NULL
) {
122 // Create Hii Extend Label OpCode as the start opcode.
124 InternalStartLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (
128 sizeof (EFI_IFR_GUID_LABEL
)
130 if (InternalStartLabel
== NULL
) {
134 InternalStartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
135 InternalStartLabel
->Number
= StartLabelNumber
;
138 // Create Hii Extend Label OpCode as the end opcode.
140 InternalEndLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (
144 sizeof (EFI_IFR_GUID_LABEL
)
146 if (InternalEndLabel
== NULL
) {
150 InternalEndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
151 InternalEndLabel
->Number
= LABEL_END
;
157 if (*StartOpCodeHandle
!= NULL
) {
158 HiiFreeOpCodeHandle (*StartOpCodeHandle
);
161 if (*EndOpCodeHandle
!= NULL
) {
162 HiiFreeOpCodeHandle (*EndOpCodeHandle
);
169 Display the Nic list contains all available Nics.
171 @param[in] Private The pointer to the global private data structure.
173 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
174 @retval EFI_SUCCESS The operation is completed successfully.
179 IN WIFI_MGR_PRIVATE_DATA
*Private
183 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
184 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
185 EFI_STRING_ID PortTitleToken
;
186 EFI_STRING_ID PortTitleHelpToken
;
187 WIFI_MGR_DEVICE_DATA
*Nic
;
189 VOID
*StartOpCodeHandle
;
190 VOID
*EndOpCodeHandle
;
192 if (Private
== NULL
) {
193 return EFI_INVALID_PARAMETER
;
196 Status
= WifiMgrCreateOpCode (
201 if (EFI_ERROR (Status
)) {
205 NET_LIST_FOR_EACH (Entry
, &Private
->NicList
) {
206 Nic
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_MGR_DEVICE_DATA
, Link
, WIFI_MGR_DEVICE_DATA_SIGNATURE
);
207 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
208 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC %s", MacString
);
209 PortTitleToken
= HiiSetString (
210 Private
->RegisteredHandle
,
215 if (PortTitleToken
== 0) {
216 Status
= EFI_INVALID_PARAMETER
;
220 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC Address");
221 PortTitleHelpToken
= HiiSetString (
222 Private
->RegisteredHandle
,
227 if (PortTitleHelpToken
== 0) {
228 Status
= EFI_INVALID_PARAMETER
;
232 HiiCreateGotoOpCode (
234 FORMID_WIFI_MAINPAGE
,
237 EFI_IFR_FLAG_CALLBACK
,
238 (UINT16
)(KEY_MAC_ENTRY_BASE
+ Nic
->NicIndex
)
242 Status
= HiiUpdateForm (
243 Private
->RegisteredHandle
, // HII handle
244 &gWifiConfigFormSetGuid
, // Formset GUID
245 FORMID_MAC_SELECTION
, // Form ID
246 StartOpCodeHandle
, // Label for where to insert opcodes
247 EndOpCodeHandle
// Replace data
252 HiiFreeOpCodeHandle (StartOpCodeHandle
);
253 HiiFreeOpCodeHandle (EndOpCodeHandle
);
258 Retreive the unicode string of the AKM Suite list of a profile.
259 The caller is responsible for freeing the string with FreePool().
261 @param[in] Profile The network profile contains a AKM suite list.
263 @return the unicode string of AKM suite list or "None".
267 WifiMgrGetStrAKMList (
268 IN WIFI_MGR_NETWORK_PROFILE
*Profile
272 UINT16 AKMSuiteCount
;
273 CHAR16
*AKMListDisplay
;
276 AKMListDisplay
= NULL
;
277 if ((Profile
== NULL
) || (Profile
->Network
.AKMSuite
== NULL
)) {
281 AKMSuiteCount
= Profile
->Network
.AKMSuite
->AKMSuiteCount
;
282 if (AKMSuiteCount
!= 0) {
284 // Current AKM Suite is between 1-18
286 AKMListDisplay
= (CHAR16
*)AllocateZeroPool (sizeof (CHAR16
) * (AKMSuiteCount
* 3 + 1));
288 if (AKMListDisplay
!= NULL
) {
289 for (Index
= 0; Index
< AKMSuiteCount
; Index
++) {
291 // The size of buffer should be 4 CHAR16 for Null-terminated Unicode string.
294 AKMListDisplay
+ Length
,
297 Profile
->Network
.AKMSuite
->AKMSuiteList
[Index
].SuiteType
299 Length
= StrLen (AKMListDisplay
+ Length
) + Length
;
300 if (Index
== AKMSuiteCount
- 1) {
301 *(AKMListDisplay
+ (Length
- 1)) = L
'\0';
309 if (AKMListDisplay
== NULL
) {
310 AKMListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
313 return AKMListDisplay
;
317 Retreive the unicode string of the Cipher Suite list of a profile.
318 The caller is responsible for freeing the string with FreePool().
320 @param[in] Profile The network profile contains a Cipher suite list.
322 @return the unicode string of Cipher suite list or "None".
326 WifiMgrGetStrCipherList (
327 IN WIFI_MGR_NETWORK_PROFILE
*Profile
331 UINT16 CipherSuiteCount
;
332 CHAR16
*CipherListDisplay
;
334 CipherListDisplay
= NULL
;
335 if ((Profile
== NULL
) || (Profile
->Network
.CipherSuite
== NULL
)) {
339 CipherSuiteCount
= Profile
->Network
.CipherSuite
->CipherSuiteCount
;
340 if (CipherSuiteCount
!= 0) {
342 // Current Cipher Suite is between 1-9
344 CipherListDisplay
= (CHAR16
*)AllocateZeroPool (sizeof (CHAR16
) * (CipherSuiteCount
* 2 + 1));
345 if (CipherListDisplay
!= NULL
) {
346 for (Index
= 0; Index
< CipherSuiteCount
; Index
++) {
348 // The size of buffer should be 3 CHAR16 for Null-terminated Unicode string.
349 // The first char is the Cipher Suite number, the second char is ' ', the third char is '\0'.
352 CipherListDisplay
+ (Index
* 2),
355 Profile
->Network
.CipherSuite
->CipherSuiteList
[Index
].SuiteType
357 if (Index
== CipherSuiteCount
- 1) {
358 *(CipherListDisplay
+ (Index
* 2 + 1)) = L
'\0';
366 if (CipherListDisplay
== NULL
) {
367 CipherListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
370 return CipherListDisplay
;
374 Refresh the network list display of the current Nic.
376 @param[in] Private The pointer to the global private data structure.
377 @param[out] IfrNvData The IFR NV data.
379 @retval EFI_SUCCESS The operation is completed successfully.
380 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
381 @retval Other Errors Returned errors when creating Opcodes or updating the
386 WifiMgrRefreshNetworkList (
387 IN WIFI_MGR_PRIVATE_DATA
*Private
,
388 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
393 UINT32 AvailableCount
;
394 EFI_STRING_ID PortPromptToken
;
395 EFI_STRING_ID PortTextToken
;
396 EFI_STRING_ID PortHelpToken
;
397 WIFI_MGR_NETWORK_PROFILE
*Profile
;
399 VOID
*StartOpCodeHandle
;
400 VOID
*EndOpCodeHandle
;
401 CHAR16
*AKMListDisplay
;
402 CHAR16
*CipherListDisplay
;
403 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
404 UINTN PortStringSize
;
405 WIFI_MGR_NETWORK_PROFILE
*ConnectedProfile
;
407 if (Private
->CurrentNic
== NULL
) {
411 Status
= WifiMgrCreateOpCode (
412 LABEL_NETWORK_LIST_ENTRY
,
416 if (EFI_ERROR (Status
)) {
420 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
422 PortStringSize
= sizeof (PortString
);
423 ConnectedProfile
= NULL
;
424 AKMListDisplay
= NULL
;
425 CipherListDisplay
= NULL
;
427 if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
429 // Display the current connected network.
430 // Find the current operate network under connected status.
432 if ((Private
->CurrentNic
->CurrentOperateNetwork
!= NULL
) &&
433 Private
->CurrentNic
->CurrentOperateNetwork
->IsAvailable
)
435 Profile
= Private
->CurrentNic
->CurrentOperateNetwork
;
438 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
439 if (AKMListDisplay
== NULL
) {
440 Status
= EFI_OUT_OF_RESOURCES
;
444 CipherListDisplay
= WifiMgrGetStrCipherList (Profile
);
445 if (CipherListDisplay
== NULL
) {
446 Status
= EFI_OUT_OF_RESOURCES
;
450 UnicodeSPrint (PortString
, PortStringSize
, L
"%s (Connected)", Profile
->SSId
);
451 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
453 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
456 UnicodeSPrint (PortString
, PortStringSize
, L
"AKMSuite: %s CipherSuite: %s", AKMListDisplay
, CipherListDisplay
);
457 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
460 FreePool (AKMListDisplay
);
461 FreePool (CipherListDisplay
);
462 AKMListDisplay
= NULL
;
463 CipherListDisplay
= NULL
;
465 HiiCreateGotoOpCode (
467 FORMID_CONNECT_NETWORK
,
470 EFI_IFR_FLAG_CALLBACK
,
471 (UINT16
)(KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
478 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
479 mSecurityType
[Profile
->SecurityType
],
480 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile
->NetworkQuality
)
482 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
484 HiiCreateTextOpCode (
491 ConnectedProfile
= Profile
;
493 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
498 // Display all supported available networks.
500 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
501 Profile
= NET_LIST_USER_STRUCT_S (
503 WIFI_MGR_NETWORK_PROFILE
,
505 WIFI_MGR_PROFILE_SIGNATURE
507 if (ConnectedProfile
== Profile
) {
511 if (Profile
->IsAvailable
&& Profile
->CipherSuiteSupported
) {
514 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
515 if (AKMListDisplay
== NULL
) {
516 Status
= EFI_OUT_OF_RESOURCES
;
520 CipherListDisplay
= WifiMgrGetStrCipherList (Profile
);
521 if (CipherListDisplay
== NULL
) {
522 Status
= EFI_OUT_OF_RESOURCES
;
526 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
527 if (PortPromptToken
== 0) {
528 Status
= EFI_OUT_OF_RESOURCES
;
532 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
538 L
"AKMSuite: %s CipherSuite: %s",
542 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
543 if (PortHelpToken
== 0) {
544 Status
= EFI_OUT_OF_RESOURCES
;
549 FreePool (AKMListDisplay
);
550 FreePool (CipherListDisplay
);
551 AKMListDisplay
= NULL
;
552 CipherListDisplay
= NULL
;
554 HiiCreateGotoOpCode (
556 FORMID_CONNECT_NETWORK
,
559 EFI_IFR_FLAG_CALLBACK
,
560 (UINT16
)(KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
567 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
568 mSecurityType
[Profile
->SecurityType
],
569 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile
->NetworkQuality
)
571 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
572 if (PortTextToken
== 0) {
573 Status
= EFI_OUT_OF_RESOURCES
;
577 HiiCreateTextOpCode (
587 // Display all Unsupported available networks.
589 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
590 Profile
= NET_LIST_USER_STRUCT_S (
592 WIFI_MGR_NETWORK_PROFILE
,
594 WIFI_MGR_PROFILE_SIGNATURE
596 if (ConnectedProfile
== Profile
) {
600 if (Profile
->IsAvailable
&& !Profile
->CipherSuiteSupported
) {
603 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
604 if (AKMListDisplay
== NULL
) {
605 Status
= EFI_OUT_OF_RESOURCES
;
609 CipherListDisplay
= WifiMgrGetStrCipherList (Profile
);
610 if (CipherListDisplay
== NULL
) {
611 Status
= EFI_OUT_OF_RESOURCES
;
615 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
617 if (Profile
->AKMSuiteSupported
) {
621 L
"AKMSuite: %s CipherSuite(UnSupported): %s",
629 L
"AKMSuite(UnSupported): %s CipherSuite(UnSupported): %s",
635 FreePool (AKMListDisplay
);
636 FreePool (CipherListDisplay
);
637 AKMListDisplay
= NULL
;
638 CipherListDisplay
= NULL
;
640 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
642 HiiCreateGotoOpCode (
644 FORMID_CONNECT_NETWORK
,
647 EFI_IFR_FLAG_CALLBACK
,
648 (UINT16
)(KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
656 mSecurityType
[Profile
->SecurityType
],
657 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile
->NetworkQuality
)
659 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
661 HiiCreateTextOpCode (
670 Status
= HiiUpdateForm (
671 Private
->RegisteredHandle
, // HII handle
672 &gWifiConfigFormSetGuid
, // Formset GUID
673 FORMID_NETWORK_LIST
, // Form ID
674 StartOpCodeHandle
, // Label for where to insert opcodes
675 EndOpCodeHandle
// Replace data
680 gBS
->RestoreTPL (OldTpl
);
682 if (AKMListDisplay
!= NULL
) {
683 FreePool (AKMListDisplay
);
686 if (CipherListDisplay
!= NULL
) {
687 FreePool (CipherListDisplay
);
690 HiiFreeOpCodeHandle (StartOpCodeHandle
);
691 HiiFreeOpCodeHandle (EndOpCodeHandle
);
693 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Network List is Refreshed!\n"));
698 Refresh the hidden network list configured by user.
700 @param[in] Private The pointer to the global private data structure.
702 @retval EFI_SUCCESS The operation is completed successfully.
703 @retval Other Errors Returned errors when creating Opcodes or updating the
707 WifiMgrRefreshHiddenList (
708 IN WIFI_MGR_PRIVATE_DATA
*Private
714 EFI_STRING_ID StringId
;
715 VOID
*StartOpCodeHandle
;
716 VOID
*EndOpCodeHandle
;
717 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
720 if (Private
== NULL
) {
724 Status
= WifiMgrCreateOpCode (
725 LABEL_HIDDEN_NETWORK_ENTRY
,
729 if (EFI_ERROR (Status
)) {
733 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
736 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
737 HiddenNetwork
= NET_LIST_USER_STRUCT_S (
739 WIFI_HIDDEN_NETWORK_DATA
,
741 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
743 StringId
= HiiSetString (Private
->RegisteredHandle
, 0, HiddenNetwork
->SSId
, NULL
);
745 HiiCreateCheckBoxOpCode (
747 (EFI_QUESTION_ID
)(KEY_HIDDEN_NETWORK_ENTRY_BASE
+ Index
),
749 (UINT16
)(HIDDEN_NETWORK_LIST_VAR_OFFSET
+ Index
),
759 Status
= HiiUpdateForm (
760 Private
->RegisteredHandle
, // HII handle
761 &gWifiConfigFormSetGuid
, // Formset GUID
762 FORMID_HIDDEN_NETWORK_LIST
, // Form ID
763 StartOpCodeHandle
, // Label for where to insert opcodes
764 EndOpCodeHandle
// Replace data
767 gBS
->RestoreTPL (OldTpl
);
768 HiiFreeOpCodeHandle (StartOpCodeHandle
);
769 HiiFreeOpCodeHandle (EndOpCodeHandle
);
774 Callback function for user to select a Nic.
776 @param[in] Private The pointer to the global private data structure.
777 @param[in] KeyValue The key value received from HII input.
779 @retval EFI_NOT_FOUND The corresponding Nic is not found.
780 @retval EFI_SUCCESS The operation is completed successfully.
785 IN WIFI_MGR_PRIVATE_DATA
*Private
,
786 IN EFI_QUESTION_ID KeyValue
789 WIFI_MGR_DEVICE_DATA
*Nic
;
791 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
793 NicIndex
= KeyValue
- KEY_MAC_ENTRY_BASE
;
794 Nic
= WifiMgrGetNicByIndex (Private
, NicIndex
);
796 return EFI_NOT_FOUND
;
799 Private
->CurrentNic
= Nic
;
801 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
802 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_MAC_ADDRESS
), MacString
, NULL
);
807 Restore the NV data to be default.
809 @param[in] Private The pointer to the global private data structure.
810 @param[out] IfrNvData The IFR NV data.
814 WifiMgrCleanUserInput (
815 IN WIFI_MGR_PRIVATE_DATA
*Private
818 Private
->SecurityType
= SECURITY_TYPE_NONE
;
819 Private
->EapAuthMethod
= EAP_AUTH_METHOD_TTLS
;
820 Private
->EapSecondAuthMethod
= EAP_SEAUTH_METHOD_MSCHAPV2
;
821 Private
->FileType
= FileTypeMax
;
825 UI handle function when user select a network to connect.
827 @param[in] Private The pointer to the global private data structure.
828 @param[in] ProfileIndex The profile index user selected to connect.
830 @retval EFI_INVALID_PARAMETER Nic is null.
831 @retval EFI_NOT_FOUND Profile could not be found.
832 @retval EFI_SUCCESS The operation is completed successfully.
836 WifiMgrUserSelectProfileToConnect (
837 IN WIFI_MGR_PRIVATE_DATA
*Private
,
838 IN UINT32 ProfileIndex
841 WIFI_MGR_NETWORK_PROFILE
*Profile
;
842 WIFI_MGR_DEVICE_DATA
*Nic
;
844 Nic
= Private
->CurrentNic
;
846 return EFI_INVALID_PARAMETER
;
850 // Initialize the connection page
852 WifiMgrCleanUserInput (Private
);
854 Profile
= WifiMgrGetProfileByProfileIndex (ProfileIndex
, &Nic
->ProfileList
);
855 if (Profile
== NULL
) {
856 return EFI_NOT_FOUND
;
859 Private
->CurrentNic
->UserSelectedProfile
= Profile
;
865 Record password from a HII input string.
867 @param[in] Private The pointer to the global private data structure.
868 @param[in] StringId The QuestionId received from HII input.
869 @param[in] StringBuffer The unicode string buffer to store password.
870 @param[in] StringBufferLen The len of unicode string buffer.
872 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
873 @retval EFI_NOT_FOUND The password string is not found or invalid.
874 @retval EFI_SUCCESS The operation is completed successfully.
878 WifiMgrRecordPassword (
879 IN WIFI_MGR_PRIVATE_DATA
*Private
,
880 IN EFI_STRING_ID StringId
,
881 IN CHAR16
*StringBuffer
,
882 IN UINTN StringBufferLen
887 if ((StringId
== 0) || (StringBuffer
== NULL
) || (StringBufferLen
<= 0)) {
888 return EFI_INVALID_PARAMETER
;
891 Password
= HiiGetString (Private
->RegisteredHandle
, StringId
, NULL
);
892 if (Password
== NULL
) {
893 return EFI_NOT_FOUND
;
896 if (StrLen (Password
) > StringBufferLen
) {
898 return EFI_NOT_FOUND
;
901 StrnCpyS (StringBuffer
, StringBufferLen
, Password
, StrLen (Password
));
902 ZeroMem (Password
, (StrLen (Password
) + 1) * sizeof (CHAR16
));
906 // Clean password in string package
908 HiiSetString (Private
->RegisteredHandle
, StringId
, L
"", NULL
);
913 Update connection message on connect configuration page, and trigger related form refresh.
915 @param[in] Nic The related Nic for updating message.
916 @param[in] ConnectStateChanged The tag to tell if the connection state has been changed, only
917 when the connection changes from "Connected" or "Disconnecting"
918 to "Disconnected", or from "Disconnected" or "Connecting" to
919 "Connected", this tag can be set as TRUE.
920 @param[in] ConnectStatusMessage The message to show on connected status bar, if NULL, will
925 WifiMgrUpdateConnectMessage (
926 IN WIFI_MGR_DEVICE_DATA
*Nic
,
927 IN BOOLEAN ConnectStateChanged
,
928 IN EFI_STRING ConnectStatusMessage
931 CHAR16 ConnectStatusStr
[WIFI_STR_MAX_SIZE
];
932 WIFI_MGR_PRIVATE_DATA
*Private
;
934 Private
= Nic
->Private
;
935 if ((Private
== NULL
) || (Private
->CurrentNic
!= Nic
)) {
940 // Update Connection Status Bar
942 if (ConnectStatusMessage
!= NULL
) {
943 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusMessage
, NULL
);
945 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
948 sizeof (ConnectStatusStr
),
950 Nic
->CurrentOperateNetwork
->SSId
952 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
953 } else if (Nic
->ConnectState
== WifiMgrDisconnected
) {
954 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), L
"Disconnected", NULL
);
955 } else if (Nic
->ConnectState
== WifiMgrConnectingToAp
) {
958 sizeof (ConnectStatusStr
),
959 L
"Connecting to %s ...",
960 Nic
->CurrentOperateNetwork
->SSId
962 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
963 } else if (Nic
->ConnectState
== WifiMgrDisconnectingToAp
) {
966 sizeof (ConnectStatusStr
),
967 L
"Disconnecting from %s ...",
968 Nic
->CurrentOperateNetwork
->SSId
970 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
977 // Update Connect Button
979 if ((Nic
->ConnectState
== WifiMgrConnectedToAp
) && (Nic
->UserSelectedProfile
== Nic
->CurrentOperateNetwork
)) {
981 Private
->RegisteredHandle
,
982 STRING_TOKEN (STR_CONNECT_NOW
),
983 L
"Disconnect from this Network",
987 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_NOW
), L
"Connect to this Network", NULL
);
990 gBS
->SignalEvent (Private
->ConnectFormRefreshEvent
);
993 // Update Main Page and Network List
995 if (ConnectStateChanged
) {
996 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
997 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Connected to", NULL
);
999 Private
->RegisteredHandle
,
1000 STRING_TOKEN (STR_CONNECTED_SSID
),
1001 Nic
->CurrentOperateNetwork
->SSId
,
1005 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Disconnected", NULL
);
1006 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTED_SSID
), L
"", NULL
);
1009 gBS
->SignalEvent (Private
->NetworkListRefreshEvent
);
1010 gBS
->SignalEvent (Private
->MainPageRefreshEvent
);
1015 Convert the driver configuration data into the IFR data.
1017 @param[in] Private The pointer to the global private data structure.
1018 @param[out] IfrNvData The IFR NV data.
1020 @retval EFI_SUCCESS The operation is completed successfully.
1024 WifiMgrConvertConfigDataToIfrNvData (
1025 IN WIFI_MGR_PRIVATE_DATA
*Private
,
1026 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
1030 // Private shouldn't be NULL here, assert if Private is NULL.
1032 ASSERT (Private
!= NULL
);
1034 if (Private
->CurrentNic
!= NULL
) {
1035 IfrNvData
->ProfileCount
= Private
->CurrentNic
->AvailableCount
;
1037 IfrNvData
->ProfileCount
= 0;
1044 Convert the IFR data into the driver configuration data.
1046 @param[in] Private The pointer to the global private data structure.
1047 @param[in, out] IfrNvData The IFR NV data.
1049 @retval EFI_SUCCESS The operation is completed successfully.
1053 WifiMgrConvertIfrNvDataToConfigData (
1054 IN WIFI_MGR_PRIVATE_DATA
*Private
,
1055 IN OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
1062 This function allows the caller to request the current
1063 configuration for one or more named elements. The resulting
1064 string is in <ConfigAltResp> format. Any and all alternative
1065 configuration strings shall also be appended to the end of the
1066 current configuration string. If they are, they must appear
1067 after the current configuration. They must contain the same
1068 routing (GUID, NAME, PATH) as the current configuration string.
1069 They must have an additional description indicating the type of
1070 alternative configuration the string represents,
1071 "ALTCFG=<StringToken>". That <StringToken> (when
1072 converted from Hex UNICODE to binary) is a reference to a
1073 string in the associated string pack.
1075 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1077 @param Request A null-terminated Unicode string in
1078 <ConfigRequest> format. Note that this
1079 includes the routing information as well as
1080 the configurable name / value pairs. It is
1081 invalid for this string to be in
1082 <MultiConfigRequest> format.
1083 If a NULL is passed in for the Request field,
1084 all of the settings being abstracted by this function
1085 will be returned in the Results field. In addition,
1086 if a ConfigHdr is passed in with no request elements,
1087 all of the settings being abstracted for that particular
1088 ConfigHdr reference will be returned in the Results Field.
1090 @param Progress On return, points to a character in the
1091 Request string. Points to the string's null
1092 terminator if request was successful. Points
1093 to the most recent "&" before the first
1094 failing name / value pair (or the beginning
1095 of the string if the failure is in the first
1096 name / value pair) if the request was not
1099 @param Results A null-terminated Unicode string in
1100 <MultiConfigAltResp> format which has all values
1101 filled in for the names in the Request string.
1102 String to be allocated by the called function.
1104 @retval EFI_SUCCESS The Results string is filled with the
1105 values corresponding to all requested
1108 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1109 parts of the results that must be
1110 stored awaiting possible future
1113 @retval EFI_NOT_FOUND Routing data doesn't match any
1114 known driver. Progress set to the
1115 first character in the routing header.
1116 Note: There is no requirement that the
1117 driver validate the routing data. It
1118 must skip the <ConfigHdr> in order to
1121 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
1122 to most recent "&" before the
1123 error or the beginning of the
1126 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
1127 to the & before the name in
1133 WifiMgrDxeHiiConfigAccessExtractConfig (
1134 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1135 IN CONST EFI_STRING Request
,
1136 OUT EFI_STRING
*Progress
,
1137 OUT EFI_STRING
*Results
1140 WIFI_MGR_PRIVATE_DATA
*Private
;
1141 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1142 EFI_STRING ConfigRequestHdr
;
1143 EFI_STRING ConfigRequest
;
1145 BOOLEAN AllocatedRequest
;
1149 if ((This
== NULL
) || (Progress
== NULL
) || (Results
== NULL
)) {
1150 return EFI_INVALID_PARAMETER
;
1153 *Progress
= Request
;
1154 if ((Request
!= NULL
) &&
1155 !HiiIsConfigHdrMatch (Request
, &gWifiConfigFormSetGuid
, mVendorStorageName
))
1157 return EFI_NOT_FOUND
;
1160 ConfigRequestHdr
= NULL
;
1161 ConfigRequest
= NULL
;
1162 AllocatedRequest
= FALSE
;
1165 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1167 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1168 IfrNvData
= AllocateZeroPool (BufferSize
);
1169 if (IfrNvData
== NULL
) {
1170 return EFI_OUT_OF_RESOURCES
;
1173 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1175 ConfigRequest
= Request
;
1176 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1178 // Request has no request element, construct full request string.
1179 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1180 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
1182 ConfigRequestHdr
= HiiConstructConfigHdr (
1183 &gWifiConfigFormSetGuid
,
1185 Private
->DriverHandle
1187 if (ConfigRequestHdr
== NULL
) {
1188 FreePool (IfrNvData
);
1189 return EFI_OUT_OF_RESOURCES
;
1192 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1193 ConfigRequest
= AllocateZeroPool (Size
);
1194 if (ConfigRequest
== NULL
) {
1195 FreePool (IfrNvData
);
1196 FreePool (ConfigRequestHdr
);
1197 return EFI_OUT_OF_RESOURCES
;
1200 AllocatedRequest
= TRUE
;
1204 L
"%s&OFFSET=0&WIDTH=%016LX",
1208 FreePool (ConfigRequestHdr
);
1212 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1214 Status
= gHiiConfigRouting
->BlockToConfig (
1223 FreePool (IfrNvData
);
1225 // Free the allocated config request string.
1227 if (AllocatedRequest
) {
1228 FreePool (ConfigRequest
);
1229 ConfigRequest
= NULL
;
1233 // Set Progress string to the original request string.
1235 if (Request
== NULL
) {
1237 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1238 *Progress
= Request
+ StrLen (Request
);
1245 This function applies changes in a driver's configuration.
1246 Input is a Configuration, which has the routing data for this
1247 driver followed by name / value configuration pairs. The driver
1248 must apply those pairs to its configurable storage. If the
1249 driver's configuration is stored in a linear block of data
1250 and the driver's name / value pairs are in <BlockConfig>
1251 format, it may use the ConfigToBlock helper function (above) to
1254 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1256 @param Configuration A null-terminated Unicode string in
1257 <ConfigString> format.
1259 @param Progress A pointer to a string filled in with the
1260 offset of the most recent '&' before the
1261 first failing name / value pair (or the
1262 beginn ing of the string if the failure
1263 is in the first name / value pair) or
1264 the terminating NULL if all was
1267 @retval EFI_SUCCESS The results have been distributed or are
1268 awaiting distribution.
1270 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1271 parts of the results that must be
1272 stored awaiting possible future
1275 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
1276 Results parameter would result
1277 in this type of error.
1279 @retval EFI_NOT_FOUND Target for the specified routing data
1285 WifiMgrDxeHiiConfigAccessRouteConfig (
1286 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1287 IN CONST EFI_STRING Configuration
,
1288 OUT EFI_STRING
*Progress
1293 WIFI_MGR_PRIVATE_DATA
*Private
;
1294 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1296 if ((Configuration
== NULL
) || (Progress
== NULL
)) {
1297 return EFI_INVALID_PARAMETER
;
1301 *Progress
= Configuration
;
1302 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1303 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1305 if (!HiiIsConfigHdrMatch (Configuration
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1306 return EFI_NOT_FOUND
;
1309 IfrNvData
= AllocateZeroPool (BufferSize
);
1310 if (IfrNvData
== NULL
) {
1311 return EFI_OUT_OF_RESOURCES
;
1314 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1316 Status
= gHiiConfigRouting
->ConfigToBlock (
1323 if (EFI_ERROR (Status
)) {
1327 Status
= WifiMgrConvertIfrNvDataToConfigData (Private
, IfrNvData
);
1328 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1329 FreePool (IfrNvData
);
1335 This function is called to provide results data to the driver.
1336 This data consists of a unique key that is used to identify
1337 which data is either being passed back or being asked for.
1339 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1340 @param Action Specifies the type of action taken by the browser.
1341 @param QuestionId A unique value which is sent to the original
1342 exporting driver so that it can identify the type
1343 of data to expect. The format of the data tends to
1344 vary based on the opcode that generated the callback.
1345 @param Type The type of value for the question.
1346 @param Value A pointer to the data being sent to the original
1348 @param ActionRequest On return, points to the action requested by the
1351 @retval EFI_SUCCESS The callback successfully handled the action.
1352 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1353 variable and its data.
1354 @retval EFI_DEVICE_ERROR The variable could not be saved.
1355 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1361 WifiMgrDxeHiiConfigAccessCallback (
1362 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1363 IN EFI_BROWSER_ACTION Action
,
1364 IN EFI_QUESTION_ID QuestionId
,
1366 IN OUT EFI_IFR_TYPE_VALUE
*Value
,
1367 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1373 WIFI_MGR_PRIVATE_DATA
*Private
;
1374 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1375 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
1376 WIFI_MGR_NETWORK_PROFILE
*Profile
;
1377 WIFI_MGR_NETWORK_PROFILE
*ProfileToConnect
;
1378 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
1384 CHAR16
*TempPassword
;
1385 CHAR16
*ErrorMessage
;
1387 if ((Action
!= EFI_BROWSER_ACTION_FORM_OPEN
) &&
1388 (Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
) &&
1389 (Action
!= EFI_BROWSER_ACTION_CHANGING
) &&
1390 (Action
!= EFI_BROWSER_ACTION_CHANGED
) &&
1391 (Action
!= EFI_BROWSER_ACTION_RETRIEVE
))
1393 return EFI_UNSUPPORTED
;
1396 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
1397 return EFI_INVALID_PARAMETER
;
1400 Status
= EFI_SUCCESS
;
1401 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1402 if (Private
->CurrentNic
== NULL
) {
1403 return EFI_DEVICE_ERROR
;
1407 // Retrieve uncommitted data from Browser
1409 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1410 IfrNvData
= AllocateZeroPool (BufferSize
);
1411 if (IfrNvData
== NULL
) {
1412 return EFI_OUT_OF_RESOURCES
;
1415 HiiGetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*)IfrNvData
);
1417 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
1418 switch (QuestionId
) {
1421 Status
= WifiMgrShowNicList (Private
);
1424 case KEY_REFRESH_NETWORK_LIST
:
1426 if (Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1427 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1430 // Erase secrets since user has left Connection Page
1431 // Connection Page may direct to Network List Page or Eap Configuration Page,
1432 // secrets only need to be erased when head to Network List Page
1434 WifiMgrCleanProfileSecrets (Profile
);
1436 Private
->CurrentNic
->UserSelectedProfile
= NULL
;
1441 case KEY_CONNECT_ACTION
:
1443 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1447 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1450 // Enter the network connection configuration page
1451 // Recovery from restored data
1453 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SSID
), Profile
->SSId
, NULL
) == 0) {
1454 return EFI_OUT_OF_RESOURCES
;
1457 IfrNvData
->SecurityType
= Profile
->SecurityType
;
1459 Private
->RegisteredHandle
,
1460 STRING_TOKEN (STR_SECURITY_TYPE
),
1461 mSecurityType
[IfrNvData
->SecurityType
],
1465 return EFI_OUT_OF_RESOURCES
;
1468 if ((IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) ||
1469 (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA3_ENTERPRISE
))
1471 IfrNvData
->EapAuthMethod
= Profile
->EapAuthMethod
;
1472 IfrNvData
->EapSecondAuthMethod
= Profile
->EapSecondAuthMethod
;
1473 StrCpyS (IfrNvData
->EapIdentity
, EAP_IDENTITY_SIZE
, Profile
->EapIdentity
);
1478 case KEY_ENROLLED_CERT_NAME
:
1480 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1484 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1487 // Enter the key enrollment page
1488 // For TTLS and PEAP, only CA cert needs to be cared
1490 if (Private
->FileType
== FileTypeCACert
) {
1491 if (Profile
->CACertData
!= NULL
) {
1492 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->CACertName
, NULL
);
1494 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1496 } else if (Private
->FileType
== FileTypeClientCert
) {
1497 if (Profile
->ClientCertData
!= NULL
) {
1498 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->ClientCertName
, NULL
);
1500 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1506 case KEY_ENROLLED_PRIVATE_KEY_NAME
:
1508 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1512 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1514 if (Profile
->PrivateKeyData
!= NULL
) {
1515 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), Profile
->PrivateKeyName
, NULL
);
1517 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), L
"", NULL
);
1525 } else if (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
) {
1526 switch (QuestionId
) {
1527 case KEY_CONNECT_ACTION
:
1529 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1533 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1536 // Restore User Config Data for Page recovery
1538 if ((IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) ||
1539 (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA3_ENTERPRISE
))
1541 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1542 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1543 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1551 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1552 switch (QuestionId
) {
1553 case KEY_NETWORK_LIST
:
1556 // User triggered a scan process.
1558 Private
->CurrentNic
->OneTimeScanRequest
= TRUE
;
1561 case KEY_PASSWORD_CONNECT_NETWORK
:
1562 case KEY_EAP_PASSWORD_CONNECT_NETWORK
:
1563 case KEY_PRIVATE_KEY_PASSWORD
:
1565 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1569 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1571 if (QuestionId
== KEY_PASSWORD_CONNECT_NETWORK
) {
1572 TempPassword
= Profile
->Password
;
1573 } else if (QuestionId
== KEY_EAP_PASSWORD_CONNECT_NETWORK
) {
1574 TempPassword
= Profile
->EapPassword
;
1576 TempPassword
= Profile
->PrivateKeyPassword
;
1579 Status
= WifiMgrRecordPassword (Private
, Value
->string
, TempPassword
, PASSWORD_STORAGE_SIZE
);
1580 if (EFI_ERROR (Status
)) {
1581 DEBUG ((DEBUG_ERROR
, "[WiFi Connection Manager] Error: Failed to input password!"));
1586 // This password is not a new created password, so no need to confirm.
1588 Status
= EFI_NOT_FOUND
;
1591 case KEY_CONNECT_ACTION
:
1593 ErrorMessage
= NULL
;
1594 ProfileToConnect
= NULL
;
1596 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1600 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1602 if ((Private
->CurrentNic
->ConnectState
== WifiMgrDisconnected
) ||
1603 (Profile
!= Private
->CurrentNic
->CurrentOperateNetwork
))
1606 // When this network is not currently connected, pend it to connect.
1608 if (Profile
->AKMSuiteSupported
&& Profile
->CipherSuiteSupported
) {
1609 if ((Profile
->SecurityType
== SECURITY_TYPE_NONE
) ||
1610 (Profile
->SecurityType
== SECURITY_TYPE_WPA2_PERSONAL
) ||
1611 (Profile
->SecurityType
== SECURITY_TYPE_WPA3_PERSONAL
))
1614 // For Open network, connect directly.
1616 ProfileToConnect
= Profile
;
1617 } else if ((Profile
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) ||
1618 (Profile
->SecurityType
== SECURITY_TYPE_WPA3_ENTERPRISE
))
1621 // For WPA/WPA2-Enterprise network, conduct eap configuration first.
1622 // Only EAP-TLS, TTLS and PEAP is supported now!
1624 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1625 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1627 if ((IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TTLS
) || (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_PEAP
)) {
1628 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1629 ProfileToConnect
= Profile
;
1630 } else if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TLS
) {
1631 ProfileToConnect
= Profile
;
1633 ErrorMessage
= L
"ERROR: Only EAP-TLS, TTLS or PEAP is supported now!";
1636 ErrorMessage
= L
"ERROR: Can't connect to this network!";
1639 ErrorMessage
= L
"ERROR: This network is not supported!";
1642 if (ErrorMessage
!= NULL
) {
1644 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1651 if (ProfileToConnect
!= NULL
) {
1652 Private
->CurrentNic
->OneTimeConnectRequest
= TRUE
;
1653 Private
->CurrentNic
->ConnectPendingNetwork
= ProfileToConnect
;
1655 } else if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
1657 // This network is currently connected, just disconnect from it.
1659 Private
->CurrentNic
->OneTimeDisconnectRequest
= TRUE
;
1660 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
1665 case KEY_ENROLL_CA_CERT_CONNECT_NETWORK
:
1667 Private
->FileType
= FileTypeCACert
;
1670 case KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK
:
1672 Private
->FileType
= FileTypeClientCert
;
1675 case KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE
:
1678 ChooseFile (NULL
, NULL
, NULL
, &FilePath
);
1680 if (FilePath
!= NULL
) {
1681 UpdatePrivateKeyFromFile (Private
, FilePath
);
1682 FreePool (FilePath
);
1687 case KEY_EAP_ENROLL_CERT_FROM_FILE
:
1690 // User will select a cert file from File Explore
1693 ChooseFile (NULL
, NULL
, NULL
, &FilePath
);
1695 if (FilePath
!= NULL
) {
1696 UpdateCAFromFile (Private
, FilePath
);
1697 FreePool (FilePath
);
1702 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1704 if ((Private
->FileContext
!= NULL
) && (Private
->FileContext
->FHandle
!= NULL
) &&
1705 (Private
->CurrentNic
->UserSelectedProfile
!= NULL
))
1708 // Read Private Key file to Buffer
1710 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1711 if (Profile
->PrivateKeyData
!= NULL
) {
1712 ZeroMem (Profile
->PrivateKeyData
, Profile
->PrivateKeyDataSize
);
1713 FreePool (Profile
->PrivateKeyData
);
1714 Profile
->PrivateKeyData
= 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 private key file!",
1730 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1732 Profile
->PrivateKeyData
= TempData
;
1733 Profile
->PrivateKeyDataSize
= TempDataSize
;
1734 StrCpyS (Profile
->PrivateKeyName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1738 "[WiFi Connection Manager] Private Key: %s has been enrolled! Size: %d\n",
1739 Profile
->PrivateKeyName
,
1740 Profile
->PrivateKeyDataSize
1747 case KEY_SAVE_CERT_TO_MEM
:
1749 if ((Private
->FileContext
!= NULL
) && (Private
->FileContext
->FHandle
!= NULL
) &&
1750 (Private
->CurrentNic
->UserSelectedProfile
!= NULL
))
1753 // Read Cert file to Buffer
1755 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1757 if (Private
->FileType
== FileTypeCACert
) {
1758 if (Profile
->CACertData
!= NULL
) {
1759 ZeroMem (Profile
->CACertData
, Profile
->CACertSize
);
1760 FreePool (Profile
->CACertData
);
1761 Profile
->CACertData
= NULL
;
1763 } else if (Private
->FileType
== FileTypeClientCert
) {
1764 if (Profile
->ClientCertData
!= NULL
) {
1765 ZeroMem (Profile
->ClientCertData
, Profile
->ClientCertSize
);
1766 FreePool (Profile
->ClientCertData
);
1767 Profile
->ClientCertData
= NULL
;
1773 Status
= WifiMgrReadFileToBuffer (
1774 Private
->FileContext
,
1778 if (EFI_ERROR (Status
)) {
1780 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1782 L
"ERROR: Can't read this certificate file!",
1786 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1787 if (Private
->FileType
== FileTypeCACert
) {
1788 Profile
->CACertData
= TempData
;
1789 Profile
->CACertSize
= TempDataSize
;
1790 StrCpyS (Profile
->CACertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1793 "[WiFi Connection Manager] CA Cert: %s has been enrolled! Size: %d\n",
1794 Profile
->CACertName
,
1798 Profile
->ClientCertData
= TempData
;
1799 Profile
->ClientCertSize
= TempDataSize
;
1800 StrCpyS (Profile
->ClientCertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1803 "[WiFi Connection Manager] Client Cert: %s has been enrolled! Size: %d\n",
1804 Profile
->ClientCertName
,
1805 Profile
->ClientCertSize
1813 case KEY_ADD_HIDDEN_NETWORK
:
1816 // Add a Hidden Network
1818 if ((StrLen (IfrNvData
->SSId
) < SSID_MIN_LEN
) ||
1819 (Private
->HiddenNetworkCount
>= HIDDEN_NETWORK_LIST_COUNT_MAX
))
1821 Status
= EFI_ABORTED
;
1825 // Check if this SSId is already in Hidden Network List
1827 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
1828 HiddenNetwork
= NET_LIST_USER_STRUCT_S (
1830 WIFI_HIDDEN_NETWORK_DATA
,
1832 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
1834 if (StrCmp (HiddenNetwork
->SSId
, IfrNvData
->SSId
) == 0) {
1835 Status
= EFI_ABORTED
;
1841 HiddenNetwork
= (WIFI_HIDDEN_NETWORK_DATA
*)AllocateZeroPool (sizeof (WIFI_HIDDEN_NETWORK_DATA
));
1842 if (HiddenNetwork
== NULL
) {
1843 Status
= EFI_OUT_OF_RESOURCES
;
1847 HiddenNetwork
->Signature
= WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
;
1848 StrCpyS (HiddenNetwork
->SSId
, SSID_STORAGE_SIZE
, IfrNvData
->SSId
);
1850 InsertTailList (&Private
->HiddenNetworkList
, &HiddenNetwork
->Link
);
1851 Private
->HiddenNetworkCount
++;
1853 WifiMgrRefreshHiddenList (Private
);
1856 case KEY_REMOVE_HIDDEN_NETWORK
:
1859 // Remove Hidden Networks
1861 Entry
= GetFirstNode (&Private
->HiddenNetworkList
);
1863 for (Index
= 0; Index
< Private
->HiddenNetworkCount
; Index
++) {
1864 if (IfrNvData
->HiddenNetworkList
[Index
] != 0) {
1865 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
, Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1866 Entry
= RemoveEntryList (Entry
);
1869 FreePool (HiddenNetwork
);
1871 Entry
= GetNextNode (&Private
->HiddenNetworkList
, Entry
);
1875 Private
->HiddenNetworkCount
-= RemoveCount
;
1876 WifiMgrRefreshHiddenList (Private
);
1881 if ((QuestionId
>= KEY_MAC_ENTRY_BASE
) && (QuestionId
< KEY_MAC_ENTRY_BASE
+ Private
->NicCount
)) {
1883 // User selects a wireless NIC.
1885 Status
= WifiMgrSelectNic (Private
, QuestionId
);
1886 if (EFI_ERROR (Status
)) {
1888 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1890 L
"ERROR: Fail to operate the wireless NIC!",
1894 } else if (Private
->CurrentNic
!= NULL
) {
1895 if ((QuestionId
>= KEY_AVAILABLE_NETWORK_ENTRY_BASE
) &&
1896 (QuestionId
<= KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Private
->CurrentNic
->MaxProfileIndex
))
1898 Status
= WifiMgrUserSelectProfileToConnect (Private
, QuestionId
- KEY_AVAILABLE_NETWORK_ENTRY_BASE
);
1899 if (!EFI_ERROR (Status
)) {
1900 WifiMgrUpdateConnectMessage (Private
->CurrentNic
, FALSE
, NULL
);
1904 if (EFI_ERROR (Status
)) {
1906 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1908 L
"ERROR: Fail to operate this profile!",
1916 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1917 switch (QuestionId
) {
1918 case KEY_SAVE_CERT_TO_MEM
:
1919 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1921 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1924 case KEY_NO_SAVE_CERT_TO_MEM
:
1925 case KEY_NO_SAVE_PRIVATE_KEY_TO_MEM
:
1927 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1932 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1935 } else if (Action
== EFI_BROWSER_ACTION_RETRIEVE
) {
1936 switch (QuestionId
) {
1937 case KEY_REFRESH_NETWORK_LIST
:
1939 WifiMgrRefreshNetworkList (Private
, IfrNvData
);
1947 if (!EFI_ERROR (Status
)) {
1949 // Pass changed uncommitted data back to Form Browser.
1951 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1952 HiiSetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*)IfrNvData
, NULL
);
1955 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1956 FreePool (IfrNvData
);
1961 Initialize the WiFi configuration form.
1963 @param[in] Private The pointer to the global private data structure.
1965 @retval EFI_SUCCESS The configuration form is initialized.
1966 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1967 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1968 @retval Other Erros Returned Errors when installing protocols.
1972 WifiMgrDxeConfigFormInit (
1973 WIFI_MGR_PRIVATE_DATA
*Private
1978 if (Private
== NULL
) {
1979 return EFI_INVALID_PARAMETER
;
1982 Private
->ConfigAccess
.ExtractConfig
= WifiMgrDxeHiiConfigAccessExtractConfig
;
1983 Private
->ConfigAccess
.RouteConfig
= WifiMgrDxeHiiConfigAccessRouteConfig
;
1984 Private
->ConfigAccess
.Callback
= WifiMgrDxeHiiConfigAccessCallback
;
1987 // Install Device Path Protocol and Config Access protocol to driver handle.
1989 Status
= gBS
->InstallMultipleProtocolInterfaces (
1990 &Private
->DriverHandle
,
1991 &gEfiDevicePathProtocolGuid
,
1992 &mWifiMgrDxeHiiVendorDevicePath
,
1993 &gEfiHiiConfigAccessProtocolGuid
,
1994 &Private
->ConfigAccess
,
1997 if (EFI_ERROR (Status
)) {
2002 // Publish our HII data.
2004 Private
->RegisteredHandle
= HiiAddPackages (
2005 &gWifiConfigFormSetGuid
,
2006 Private
->DriverHandle
,
2007 WifiConnectionManagerDxeStrings
,
2008 WifiConnectionManagerDxeBin
,
2011 if (Private
->RegisteredHandle
== NULL
) {
2012 gBS
->UninstallMultipleProtocolInterfaces (
2013 Private
->DriverHandle
,
2014 &gEfiDevicePathProtocolGuid
,
2015 &mWifiMgrDxeHiiVendorDevicePath
,
2016 &gEfiHiiConfigAccessProtocolGuid
,
2017 &Private
->ConfigAccess
,
2020 return EFI_OUT_OF_RESOURCES
;
2023 Private
->FileContext
= AllocateZeroPool (sizeof (WIFI_MGR_FILE_CONTEXT
));
2024 if (Private
->FileContext
== NULL
) {
2025 return EFI_OUT_OF_RESOURCES
;
2032 Unload the WiFi configuration form.
2034 @param[in] Private The pointer to the global private data structure.
2036 @retval EFI_SUCCESS The configuration form is unloaded successfully.
2037 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
2038 @retval Other Errors Returned Erros when uninstalling protocols.
2042 WifiMgrDxeConfigFormUnload (
2043 WIFI_MGR_PRIVATE_DATA
*Private
2048 if (Private
== NULL
) {
2049 return EFI_INVALID_PARAMETER
;
2052 if (Private
->FileContext
!= NULL
) {
2053 if (Private
->FileContext
->FHandle
!= NULL
) {
2054 Private
->FileContext
->FHandle
->Close (Private
->FileContext
->FHandle
);
2057 if (Private
->FileContext
->FileName
!= NULL
) {
2058 FreePool (Private
->FileContext
->FileName
);
2061 FreePool (Private
->FileContext
);
2064 HiiRemovePackages (Private
->RegisteredHandle
);
2066 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2067 Private
->DriverHandle
,
2068 &gEfiDevicePathProtocolGuid
,
2069 &mWifiMgrDxeHiiVendorDevicePath
,
2070 &gEfiHiiConfigAccessProtocolGuid
,
2071 &Private
->ConfigAccess
,