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
) {
114 *EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
115 if (*EndOpCodeHandle
== NULL
) {
120 // Create Hii Extend Label OpCode as the start opcode.
122 InternalStartLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (
126 sizeof (EFI_IFR_GUID_LABEL
)
128 if (InternalStartLabel
== NULL
) {
132 InternalStartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
133 InternalStartLabel
->Number
= StartLabelNumber
;
136 // Create Hii Extend Label OpCode as the end opcode.
138 InternalEndLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (
142 sizeof (EFI_IFR_GUID_LABEL
)
144 if (InternalEndLabel
== NULL
) {
148 InternalEndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
149 InternalEndLabel
->Number
= LABEL_END
;
155 if (*StartOpCodeHandle
!= NULL
) {
156 HiiFreeOpCodeHandle (*StartOpCodeHandle
);
159 if (*EndOpCodeHandle
!= NULL
) {
160 HiiFreeOpCodeHandle (*EndOpCodeHandle
);
167 Display the Nic list contains all available Nics.
169 @param[in] Private The pointer to the global private data structure.
171 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
172 @retval EFI_SUCCESS The operation is completed successfully.
177 IN WIFI_MGR_PRIVATE_DATA
*Private
181 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
182 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
183 EFI_STRING_ID PortTitleToken
;
184 EFI_STRING_ID PortTitleHelpToken
;
185 WIFI_MGR_DEVICE_DATA
*Nic
;
187 VOID
*StartOpCodeHandle
;
188 VOID
*EndOpCodeHandle
;
190 if (Private
== NULL
) {
191 return EFI_INVALID_PARAMETER
;
194 Status
= WifiMgrCreateOpCode (
199 if (EFI_ERROR (Status
)) {
203 NET_LIST_FOR_EACH (Entry
, &Private
->NicList
) {
204 Nic
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_MGR_DEVICE_DATA
, Link
, WIFI_MGR_DEVICE_DATA_SIGNATURE
);
205 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
206 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC %s", MacString
);
207 PortTitleToken
= HiiSetString (
208 Private
->RegisteredHandle
,
213 if (PortTitleToken
== 0) {
214 Status
= EFI_INVALID_PARAMETER
;
218 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC Address");
219 PortTitleHelpToken
= HiiSetString (
220 Private
->RegisteredHandle
,
225 if (PortTitleHelpToken
== 0) {
226 Status
= EFI_INVALID_PARAMETER
;
230 HiiCreateGotoOpCode (
232 FORMID_WIFI_MAINPAGE
,
235 EFI_IFR_FLAG_CALLBACK
,
236 (UINT16
)(KEY_MAC_ENTRY_BASE
+ Nic
->NicIndex
)
240 Status
= HiiUpdateForm (
241 Private
->RegisteredHandle
, // HII handle
242 &gWifiConfigFormSetGuid
, // Formset GUID
243 FORMID_MAC_SELECTION
, // Form ID
244 StartOpCodeHandle
, // Label for where to insert opcodes
245 EndOpCodeHandle
// Replace data
250 HiiFreeOpCodeHandle (StartOpCodeHandle
);
251 HiiFreeOpCodeHandle (EndOpCodeHandle
);
256 Retreive the unicode string of the AKM Suite list of a profile.
257 The caller is responsible for freeing the string with FreePool().
259 @param[in] Profile The network profile contains a AKM suite list.
261 @return the unicode string of AKM suite list or "None".
265 WifiMgrGetStrAKMList (
266 IN WIFI_MGR_NETWORK_PROFILE
*Profile
270 UINT16 AKMSuiteCount
;
271 CHAR16
*AKMListDisplay
;
273 AKMListDisplay
= NULL
;
274 if ((Profile
== NULL
) || (Profile
->Network
.AKMSuite
== NULL
)) {
278 AKMSuiteCount
= Profile
->Network
.AKMSuite
->AKMSuiteCount
;
279 if (AKMSuiteCount
!= 0) {
281 // Current AKM Suite is between 1-9
283 AKMListDisplay
= (CHAR16
*)AllocateZeroPool (sizeof (CHAR16
) * AKMSuiteCount
* 2);
284 if (AKMListDisplay
!= NULL
) {
285 for (Index
= 0; Index
< AKMSuiteCount
; Index
++) {
287 AKMListDisplay
+ (Index
* 2),
290 Profile
->Network
.AKMSuite
->AKMSuiteList
[Index
].SuiteType
292 if (Index
== AKMSuiteCount
- 1) {
293 *(AKMListDisplay
+ (Index
* 2 + 1)) = L
'\0';
301 if (AKMListDisplay
== NULL
) {
302 AKMListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
305 return AKMListDisplay
;
309 Retreive the unicode string of the Cipher Suite list of a profile.
310 The caller is responsible for freeing the string with FreePool().
312 @param[in] Profile The network profile contains a Cipher suite list.
314 @return the unicode string of Cipher suite list or "None".
318 WifiMgrGetStrCipherList (
319 IN WIFI_MGR_NETWORK_PROFILE
*Profile
323 UINT16 CipherSuiteCount
;
324 CHAR16
*CipherListDisplay
;
326 CipherListDisplay
= NULL
;
327 if ((Profile
== NULL
) || (Profile
->Network
.CipherSuite
== NULL
)) {
331 CipherSuiteCount
= Profile
->Network
.CipherSuite
->CipherSuiteCount
;
332 if (CipherSuiteCount
!= 0) {
334 // Current Cipher Suite is between 1-9
336 CipherListDisplay
= (CHAR16
*)AllocateZeroPool (sizeof (CHAR16
) * CipherSuiteCount
* 2);
337 if (CipherListDisplay
!= NULL
) {
338 for (Index
= 0; Index
< CipherSuiteCount
; Index
++) {
340 CipherListDisplay
+ (Index
* 2),
343 Profile
->Network
.CipherSuite
->CipherSuiteList
[Index
].SuiteType
345 if (Index
== CipherSuiteCount
- 1) {
346 *(CipherListDisplay
+ (Index
* 2 + 1)) = L
'\0';
354 if (CipherListDisplay
== NULL
) {
355 CipherListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
358 return CipherListDisplay
;
362 Refresh the network list display of the current Nic.
364 @param[in] Private The pointer to the global private data structure.
365 @param[out] IfrNvData The IFR NV data.
367 @retval EFI_SUCCESS The operation is completed successfully.
368 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
369 @retval Other Errors Returned errors when creating Opcodes or updating the
374 WifiMgrRefreshNetworkList (
375 IN WIFI_MGR_PRIVATE_DATA
*Private
,
376 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
381 UINT32 AvailableCount
;
382 EFI_STRING_ID PortPromptToken
;
383 EFI_STRING_ID PortTextToken
;
384 EFI_STRING_ID PortHelpToken
;
385 WIFI_MGR_NETWORK_PROFILE
*Profile
;
387 VOID
*StartOpCodeHandle
;
388 VOID
*EndOpCodeHandle
;
389 CHAR16
*AKMListDisplay
;
390 CHAR16
*CipherListDisplay
;
391 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
392 UINTN PortStringSize
;
393 WIFI_MGR_NETWORK_PROFILE
*ConnectedProfile
;
395 if (Private
->CurrentNic
== NULL
) {
399 Status
= WifiMgrCreateOpCode (
400 LABEL_NETWORK_LIST_ENTRY
,
404 if (EFI_ERROR (Status
)) {
408 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
410 PortStringSize
= sizeof (PortString
);
411 ConnectedProfile
= NULL
;
412 AKMListDisplay
= NULL
;
413 CipherListDisplay
= NULL
;
415 if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
417 // Display the current connected network.
418 // Find the current operate network under connected status.
420 if ((Private
->CurrentNic
->CurrentOperateNetwork
!= NULL
) &&
421 Private
->CurrentNic
->CurrentOperateNetwork
->IsAvailable
)
423 Profile
= Private
->CurrentNic
->CurrentOperateNetwork
;
426 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
427 if (AKMListDisplay
== NULL
) {
428 Status
= EFI_OUT_OF_RESOURCES
;
432 CipherListDisplay
= WifiMgrGetStrCipherList (Profile
);
433 if (CipherListDisplay
== NULL
) {
434 Status
= EFI_OUT_OF_RESOURCES
;
438 UnicodeSPrint (PortString
, PortStringSize
, L
"%s (Connected)", Profile
->SSId
);
439 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
441 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
444 UnicodeSPrint (PortString
, PortStringSize
, L
"AKMSuite: %s CipherSuite: %s", AKMListDisplay
, CipherListDisplay
);
445 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
448 FreePool (AKMListDisplay
);
449 FreePool (CipherListDisplay
);
450 AKMListDisplay
= NULL
;
451 CipherListDisplay
= NULL
;
453 HiiCreateGotoOpCode (
455 FORMID_CONNECT_NETWORK
,
458 EFI_IFR_FLAG_CALLBACK
,
459 (UINT16
)(KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
466 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
467 mSecurityType
[Profile
->SecurityType
],
468 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile
->NetworkQuality
)
470 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
472 HiiCreateTextOpCode (
479 ConnectedProfile
= Profile
;
481 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
486 // Display all supported available networks.
488 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
489 Profile
= NET_LIST_USER_STRUCT_S (
491 WIFI_MGR_NETWORK_PROFILE
,
493 WIFI_MGR_PROFILE_SIGNATURE
495 if (ConnectedProfile
== Profile
) {
499 if (Profile
->IsAvailable
&& Profile
->CipherSuiteSupported
) {
502 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
503 if (AKMListDisplay
== NULL
) {
504 Status
= EFI_OUT_OF_RESOURCES
;
508 CipherListDisplay
= WifiMgrGetStrCipherList (Profile
);
509 if (CipherListDisplay
== NULL
) {
510 Status
= EFI_OUT_OF_RESOURCES
;
514 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
515 if (PortPromptToken
== 0) {
516 Status
= EFI_OUT_OF_RESOURCES
;
520 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
526 L
"AKMSuite: %s CipherSuite: %s",
530 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
531 if (PortHelpToken
== 0) {
532 Status
= EFI_OUT_OF_RESOURCES
;
537 FreePool (AKMListDisplay
);
538 FreePool (CipherListDisplay
);
539 AKMListDisplay
= NULL
;
540 CipherListDisplay
= NULL
;
542 HiiCreateGotoOpCode (
544 FORMID_CONNECT_NETWORK
,
547 EFI_IFR_FLAG_CALLBACK
,
548 (UINT16
)(KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
555 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
556 mSecurityType
[Profile
->SecurityType
],
557 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile
->NetworkQuality
)
559 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
560 if (PortTextToken
== 0) {
561 Status
= EFI_OUT_OF_RESOURCES
;
565 HiiCreateTextOpCode (
575 // Display all Unsupported available networks.
577 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
578 Profile
= NET_LIST_USER_STRUCT_S (
580 WIFI_MGR_NETWORK_PROFILE
,
582 WIFI_MGR_PROFILE_SIGNATURE
584 if (ConnectedProfile
== Profile
) {
588 if (Profile
->IsAvailable
&& !Profile
->CipherSuiteSupported
) {
591 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
592 if (AKMListDisplay
== NULL
) {
593 Status
= EFI_OUT_OF_RESOURCES
;
597 CipherListDisplay
= WifiMgrGetStrCipherList (Profile
);
598 if (CipherListDisplay
== NULL
) {
599 Status
= EFI_OUT_OF_RESOURCES
;
603 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
605 if (Profile
->AKMSuiteSupported
) {
609 L
"AKMSuite: %s CipherSuite(UnSupported): %s",
617 L
"AKMSuite(UnSupported): %s CipherSuite(UnSupported): %s",
623 FreePool (AKMListDisplay
);
624 FreePool (CipherListDisplay
);
625 AKMListDisplay
= NULL
;
626 CipherListDisplay
= NULL
;
628 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
630 HiiCreateGotoOpCode (
632 FORMID_CONNECT_NETWORK
,
635 EFI_IFR_FLAG_CALLBACK
,
636 (UINT16
)(KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
644 mSecurityType
[Profile
->SecurityType
],
645 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile
->NetworkQuality
)
647 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
649 HiiCreateTextOpCode (
658 Status
= HiiUpdateForm (
659 Private
->RegisteredHandle
, // HII handle
660 &gWifiConfigFormSetGuid
, // Formset GUID
661 FORMID_NETWORK_LIST
, // Form ID
662 StartOpCodeHandle
, // Label for where to insert opcodes
663 EndOpCodeHandle
// Replace data
668 gBS
->RestoreTPL (OldTpl
);
670 if (AKMListDisplay
!= NULL
) {
671 FreePool (AKMListDisplay
);
674 if (CipherListDisplay
!= NULL
) {
675 FreePool (CipherListDisplay
);
678 HiiFreeOpCodeHandle (StartOpCodeHandle
);
679 HiiFreeOpCodeHandle (EndOpCodeHandle
);
681 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Network List is Refreshed!\n"));
686 Refresh the hidden network list configured by user.
688 @param[in] Private The pointer to the global private data structure.
690 @retval EFI_SUCCESS The operation is completed successfully.
691 @retval Other Errors Returned errors when creating Opcodes or updating the
695 WifiMgrRefreshHiddenList (
696 IN WIFI_MGR_PRIVATE_DATA
*Private
702 EFI_STRING_ID StringId
;
703 VOID
*StartOpCodeHandle
;
704 VOID
*EndOpCodeHandle
;
705 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
708 if (Private
== NULL
) {
712 Status
= WifiMgrCreateOpCode (
713 LABEL_HIDDEN_NETWORK_ENTRY
,
717 if (EFI_ERROR (Status
)) {
721 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
724 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
725 HiddenNetwork
= NET_LIST_USER_STRUCT_S (
727 WIFI_HIDDEN_NETWORK_DATA
,
729 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
731 StringId
= HiiSetString (Private
->RegisteredHandle
, 0, HiddenNetwork
->SSId
, NULL
);
733 HiiCreateCheckBoxOpCode (
735 (EFI_QUESTION_ID
)(KEY_HIDDEN_NETWORK_ENTRY_BASE
+ Index
),
737 (UINT16
)(HIDDEN_NETWORK_LIST_VAR_OFFSET
+ Index
),
747 Status
= HiiUpdateForm (
748 Private
->RegisteredHandle
, // HII handle
749 &gWifiConfigFormSetGuid
, // Formset GUID
750 FORMID_HIDDEN_NETWORK_LIST
, // Form ID
751 StartOpCodeHandle
, // Label for where to insert opcodes
752 EndOpCodeHandle
// Replace data
755 gBS
->RestoreTPL (OldTpl
);
756 HiiFreeOpCodeHandle (StartOpCodeHandle
);
757 HiiFreeOpCodeHandle (EndOpCodeHandle
);
762 Callback function for user to select a Nic.
764 @param[in] Private The pointer to the global private data structure.
765 @param[in] KeyValue The key value received from HII input.
767 @retval EFI_NOT_FOUND The corresponding Nic is not found.
768 @retval EFI_SUCCESS The operation is completed successfully.
773 IN WIFI_MGR_PRIVATE_DATA
*Private
,
774 IN EFI_QUESTION_ID KeyValue
777 WIFI_MGR_DEVICE_DATA
*Nic
;
779 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
781 NicIndex
= KeyValue
- KEY_MAC_ENTRY_BASE
;
782 Nic
= WifiMgrGetNicByIndex (Private
, NicIndex
);
784 return EFI_NOT_FOUND
;
787 Private
->CurrentNic
= Nic
;
789 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
790 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_MAC_ADDRESS
), MacString
, NULL
);
795 Restore the NV data to be default.
797 @param[in] Private The pointer to the global private data structure.
798 @param[out] IfrNvData The IFR NV data.
802 WifiMgrCleanUserInput (
803 IN WIFI_MGR_PRIVATE_DATA
*Private
806 Private
->SecurityType
= SECURITY_TYPE_NONE
;
807 Private
->EapAuthMethod
= EAP_AUTH_METHOD_TTLS
;
808 Private
->EapSecondAuthMethod
= EAP_SEAUTH_METHOD_MSCHAPV2
;
809 Private
->FileType
= FileTypeMax
;
813 UI handle function when user select a network to connect.
815 @param[in] Private The pointer to the global private data structure.
816 @param[in] ProfileIndex The profile index user selected to connect.
818 @retval EFI_INVALID_PARAMETER Nic is null.
819 @retval EFI_NOT_FOUND Profile could not be found.
820 @retval EFI_SUCCESS The operation is completed successfully.
824 WifiMgrUserSelectProfileToConnect (
825 IN WIFI_MGR_PRIVATE_DATA
*Private
,
826 IN UINT32 ProfileIndex
829 WIFI_MGR_NETWORK_PROFILE
*Profile
;
830 WIFI_MGR_DEVICE_DATA
*Nic
;
832 Nic
= Private
->CurrentNic
;
834 return EFI_INVALID_PARAMETER
;
838 // Initialize the connection page
840 WifiMgrCleanUserInput (Private
);
842 Profile
= WifiMgrGetProfileByProfileIndex (ProfileIndex
, &Nic
->ProfileList
);
843 if (Profile
== NULL
) {
844 return EFI_NOT_FOUND
;
847 Private
->CurrentNic
->UserSelectedProfile
= Profile
;
853 Record password from a HII input string.
855 @param[in] Private The pointer to the global private data structure.
856 @param[in] StringId The QuestionId received from HII input.
857 @param[in] StringBuffer The unicode string buffer to store password.
858 @param[in] StringBufferLen The len of unicode string buffer.
860 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
861 @retval EFI_NOT_FOUND The password string is not found or invalid.
862 @retval EFI_SUCCESS The operation is completed successfully.
866 WifiMgrRecordPassword (
867 IN WIFI_MGR_PRIVATE_DATA
*Private
,
868 IN EFI_STRING_ID StringId
,
869 IN CHAR16
*StringBuffer
,
870 IN UINTN StringBufferLen
875 if ((StringId
== 0) || (StringBuffer
== NULL
) || (StringBufferLen
<= 0)) {
876 return EFI_INVALID_PARAMETER
;
879 Password
= HiiGetString (Private
->RegisteredHandle
, StringId
, NULL
);
880 if (Password
== NULL
) {
881 return EFI_NOT_FOUND
;
884 if (StrLen (Password
) > StringBufferLen
) {
886 return EFI_NOT_FOUND
;
889 StrnCpyS (StringBuffer
, StringBufferLen
, Password
, StrLen (Password
));
890 ZeroMem (Password
, (StrLen (Password
) + 1) * sizeof (CHAR16
));
894 // Clean password in string package
896 HiiSetString (Private
->RegisteredHandle
, StringId
, L
"", NULL
);
901 Update connection message on connect configuration page, and trigger related form refresh.
903 @param[in] Nic The related Nic for updating message.
904 @param[in] ConnectStateChanged The tag to tell if the connection state has been changed, only
905 when the connection changes from "Connected" or "Disconnecting"
906 to "Disconnected", or from "Disconnected" or "Connecting" to
907 "Connected", this tag can be set as TRUE.
908 @param[in] ConnectStatusMessage The message to show on connected status bar, if NULL, will
913 WifiMgrUpdateConnectMessage (
914 IN WIFI_MGR_DEVICE_DATA
*Nic
,
915 IN BOOLEAN ConnectStateChanged
,
916 IN EFI_STRING ConnectStatusMessage
919 CHAR16 ConnectStatusStr
[WIFI_STR_MAX_SIZE
];
920 WIFI_MGR_PRIVATE_DATA
*Private
;
922 Private
= Nic
->Private
;
923 if ((Private
== NULL
) || (Private
->CurrentNic
!= Nic
)) {
928 // Update Connection Status Bar
930 if (ConnectStatusMessage
!= NULL
) {
931 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusMessage
, NULL
);
933 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
936 sizeof (ConnectStatusStr
),
938 Nic
->CurrentOperateNetwork
->SSId
940 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
941 } else if (Nic
->ConnectState
== WifiMgrDisconnected
) {
942 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), L
"Disconnected", NULL
);
943 } else if (Nic
->ConnectState
== WifiMgrConnectingToAp
) {
946 sizeof (ConnectStatusStr
),
947 L
"Connecting to %s ...",
948 Nic
->CurrentOperateNetwork
->SSId
950 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
951 } else if (Nic
->ConnectState
== WifiMgrDisconnectingToAp
) {
954 sizeof (ConnectStatusStr
),
955 L
"Disconnecting from %s ...",
956 Nic
->CurrentOperateNetwork
->SSId
958 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
965 // Update Connect Button
967 if ((Nic
->ConnectState
== WifiMgrConnectedToAp
) && (Nic
->UserSelectedProfile
== Nic
->CurrentOperateNetwork
)) {
969 Private
->RegisteredHandle
,
970 STRING_TOKEN (STR_CONNECT_NOW
),
971 L
"Disconnect from this Network",
975 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_NOW
), L
"Connect to this Network", NULL
);
978 gBS
->SignalEvent (Private
->ConnectFormRefreshEvent
);
981 // Update Main Page and Network List
983 if (ConnectStateChanged
) {
984 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
985 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Connected to", NULL
);
987 Private
->RegisteredHandle
,
988 STRING_TOKEN (STR_CONNECTED_SSID
),
989 Nic
->CurrentOperateNetwork
->SSId
,
993 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Disconnected", NULL
);
994 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTED_SSID
), L
"", NULL
);
997 gBS
->SignalEvent (Private
->NetworkListRefreshEvent
);
998 gBS
->SignalEvent (Private
->MainPageRefreshEvent
);
1003 Convert the driver configuration data into the IFR data.
1005 @param[in] Private The pointer to the global private data structure.
1006 @param[out] IfrNvData The IFR NV data.
1008 @retval EFI_SUCCESS The operation is completed successfully.
1012 WifiMgrConvertConfigDataToIfrNvData (
1013 IN WIFI_MGR_PRIVATE_DATA
*Private
,
1014 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
1018 // Private shouldn't be NULL here, assert if Private is NULL.
1020 ASSERT (Private
!= NULL
);
1022 if (Private
->CurrentNic
!= NULL
) {
1023 IfrNvData
->ProfileCount
= Private
->CurrentNic
->AvailableCount
;
1025 IfrNvData
->ProfileCount
= 0;
1032 Convert the IFR data into the driver configuration data.
1034 @param[in] Private The pointer to the global private data structure.
1035 @param[in, out] IfrNvData The IFR NV data.
1037 @retval EFI_SUCCESS The operation is completed successfully.
1041 WifiMgrConvertIfrNvDataToConfigData (
1042 IN WIFI_MGR_PRIVATE_DATA
*Private
,
1043 IN OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
1050 This function allows the caller to request the current
1051 configuration for one or more named elements. The resulting
1052 string is in <ConfigAltResp> format. Any and all alternative
1053 configuration strings shall also be appended to the end of the
1054 current configuration string. If they are, they must appear
1055 after the current configuration. They must contain the same
1056 routing (GUID, NAME, PATH) as the current configuration string.
1057 They must have an additional description indicating the type of
1058 alternative configuration the string represents,
1059 "ALTCFG=<StringToken>". That <StringToken> (when
1060 converted from Hex UNICODE to binary) is a reference to a
1061 string in the associated string pack.
1063 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1065 @param Request A null-terminated Unicode string in
1066 <ConfigRequest> format. Note that this
1067 includes the routing information as well as
1068 the configurable name / value pairs. It is
1069 invalid for this string to be in
1070 <MultiConfigRequest> format.
1071 If a NULL is passed in for the Request field,
1072 all of the settings being abstracted by this function
1073 will be returned in the Results field. In addition,
1074 if a ConfigHdr is passed in with no request elements,
1075 all of the settings being abstracted for that particular
1076 ConfigHdr reference will be returned in the Results Field.
1078 @param Progress On return, points to a character in the
1079 Request string. Points to the string's null
1080 terminator if request was successful. Points
1081 to the most recent "&" before the first
1082 failing name / value pair (or the beginning
1083 of the string if the failure is in the first
1084 name / value pair) if the request was not
1087 @param Results A null-terminated Unicode string in
1088 <MultiConfigAltResp> format which has all values
1089 filled in for the names in the Request string.
1090 String to be allocated by the called function.
1092 @retval EFI_SUCCESS The Results string is filled with the
1093 values corresponding to all requested
1096 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1097 parts of the results that must be
1098 stored awaiting possible future
1101 @retval EFI_NOT_FOUND Routing data doesn't match any
1102 known driver. Progress set to the
1103 first character in the routing header.
1104 Note: There is no requirement that the
1105 driver validate the routing data. It
1106 must skip the <ConfigHdr> in order to
1109 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
1110 to most recent "&" before the
1111 error or the beginning of the
1114 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
1115 to the & before the name in
1121 WifiMgrDxeHiiConfigAccessExtractConfig (
1122 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1123 IN CONST EFI_STRING Request
,
1124 OUT EFI_STRING
*Progress
,
1125 OUT EFI_STRING
*Results
1128 WIFI_MGR_PRIVATE_DATA
*Private
;
1129 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1130 EFI_STRING ConfigRequestHdr
;
1131 EFI_STRING ConfigRequest
;
1133 BOOLEAN AllocatedRequest
;
1137 if ((This
== NULL
) || (Progress
== NULL
) || (Results
== NULL
)) {
1138 return EFI_INVALID_PARAMETER
;
1141 *Progress
= Request
;
1142 if ((Request
!= NULL
) &&
1143 !HiiIsConfigHdrMatch (Request
, &gWifiConfigFormSetGuid
, mVendorStorageName
))
1145 return EFI_NOT_FOUND
;
1148 ConfigRequestHdr
= NULL
;
1149 ConfigRequest
= NULL
;
1150 AllocatedRequest
= FALSE
;
1153 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1155 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1156 IfrNvData
= AllocateZeroPool (BufferSize
);
1157 if (IfrNvData
== NULL
) {
1158 return EFI_OUT_OF_RESOURCES
;
1161 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1163 ConfigRequest
= Request
;
1164 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1166 // Request has no request element, construct full request string.
1167 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1168 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
1170 ConfigRequestHdr
= HiiConstructConfigHdr (
1171 &gWifiConfigFormSetGuid
,
1173 Private
->DriverHandle
1175 if (ConfigRequestHdr
== NULL
) {
1176 FreePool (IfrNvData
);
1177 return EFI_OUT_OF_RESOURCES
;
1180 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1181 ConfigRequest
= AllocateZeroPool (Size
);
1182 if (ConfigRequest
== NULL
) {
1183 FreePool (IfrNvData
);
1184 FreePool (ConfigRequestHdr
);
1185 return EFI_OUT_OF_RESOURCES
;
1188 AllocatedRequest
= TRUE
;
1192 L
"%s&OFFSET=0&WIDTH=%016LX",
1196 FreePool (ConfigRequestHdr
);
1200 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1202 Status
= gHiiConfigRouting
->BlockToConfig (
1211 FreePool (IfrNvData
);
1213 // Free the allocated config request string.
1215 if (AllocatedRequest
) {
1216 FreePool (ConfigRequest
);
1217 ConfigRequest
= NULL
;
1221 // Set Progress string to the original request string.
1223 if (Request
== NULL
) {
1225 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1226 *Progress
= Request
+ StrLen (Request
);
1233 This function applies changes in a driver's configuration.
1234 Input is a Configuration, which has the routing data for this
1235 driver followed by name / value configuration pairs. The driver
1236 must apply those pairs to its configurable storage. If the
1237 driver's configuration is stored in a linear block of data
1238 and the driver's name / value pairs are in <BlockConfig>
1239 format, it may use the ConfigToBlock helper function (above) to
1242 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1244 @param Configuration A null-terminated Unicode string in
1245 <ConfigString> format.
1247 @param Progress A pointer to a string filled in with the
1248 offset of the most recent '&' before the
1249 first failing name / value pair (or the
1250 beginn ing of the string if the failure
1251 is in the first name / value pair) or
1252 the terminating NULL if all was
1255 @retval EFI_SUCCESS The results have been distributed or are
1256 awaiting distribution.
1258 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1259 parts of the results that must be
1260 stored awaiting possible future
1263 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
1264 Results parameter would result
1265 in this type of error.
1267 @retval EFI_NOT_FOUND Target for the specified routing data
1273 WifiMgrDxeHiiConfigAccessRouteConfig (
1274 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1275 IN CONST EFI_STRING Configuration
,
1276 OUT EFI_STRING
*Progress
1281 WIFI_MGR_PRIVATE_DATA
*Private
;
1282 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1284 if ((Configuration
== NULL
) || (Progress
== NULL
)) {
1285 return EFI_INVALID_PARAMETER
;
1289 *Progress
= Configuration
;
1290 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1291 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1293 if (!HiiIsConfigHdrMatch (Configuration
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1294 return EFI_NOT_FOUND
;
1297 IfrNvData
= AllocateZeroPool (BufferSize
);
1298 if (IfrNvData
== NULL
) {
1299 return EFI_OUT_OF_RESOURCES
;
1302 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1304 Status
= gHiiConfigRouting
->ConfigToBlock (
1311 if (EFI_ERROR (Status
)) {
1315 Status
= WifiMgrConvertIfrNvDataToConfigData (Private
, IfrNvData
);
1316 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1317 FreePool (IfrNvData
);
1323 This function is called to provide results data to the driver.
1324 This data consists of a unique key that is used to identify
1325 which data is either being passed back or being asked for.
1327 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1328 @param Action Specifies the type of action taken by the browser.
1329 @param QuestionId A unique value which is sent to the original
1330 exporting driver so that it can identify the type
1331 of data to expect. The format of the data tends to
1332 vary based on the opcode that generated the callback.
1333 @param Type The type of value for the question.
1334 @param Value A pointer to the data being sent to the original
1336 @param ActionRequest On return, points to the action requested by the
1339 @retval EFI_SUCCESS The callback successfully handled the action.
1340 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1341 variable and its data.
1342 @retval EFI_DEVICE_ERROR The variable could not be saved.
1343 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1349 WifiMgrDxeHiiConfigAccessCallback (
1350 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1351 IN EFI_BROWSER_ACTION Action
,
1352 IN EFI_QUESTION_ID QuestionId
,
1354 IN OUT EFI_IFR_TYPE_VALUE
*Value
,
1355 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1361 WIFI_MGR_PRIVATE_DATA
*Private
;
1362 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1363 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
1364 WIFI_MGR_NETWORK_PROFILE
*Profile
;
1365 WIFI_MGR_NETWORK_PROFILE
*ProfileToConnect
;
1366 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
1372 CHAR16
*TempPassword
;
1373 CHAR16
*ErrorMessage
;
1375 if ((Action
!= EFI_BROWSER_ACTION_FORM_OPEN
) &&
1376 (Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
) &&
1377 (Action
!= EFI_BROWSER_ACTION_CHANGING
) &&
1378 (Action
!= EFI_BROWSER_ACTION_CHANGED
) &&
1379 (Action
!= EFI_BROWSER_ACTION_RETRIEVE
))
1381 return EFI_UNSUPPORTED
;
1384 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
1385 return EFI_INVALID_PARAMETER
;
1388 Status
= EFI_SUCCESS
;
1389 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1390 if (Private
->CurrentNic
== NULL
) {
1391 return EFI_DEVICE_ERROR
;
1395 // Retrieve uncommitted data from Browser
1397 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1398 IfrNvData
= AllocateZeroPool (BufferSize
);
1399 if (IfrNvData
== NULL
) {
1400 return EFI_OUT_OF_RESOURCES
;
1403 HiiGetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*)IfrNvData
);
1405 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
1406 switch (QuestionId
) {
1409 Status
= WifiMgrShowNicList (Private
);
1412 case KEY_REFRESH_NETWORK_LIST
:
1414 if (Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1415 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1418 // Erase secrets since user has left Connection Page
1419 // Connection Page may direct to Network List Page or Eap Configuration Page,
1420 // secrets only need to be erased when head to Network List Page
1422 WifiMgrCleanProfileSecrets (Profile
);
1424 Private
->CurrentNic
->UserSelectedProfile
= NULL
;
1429 case KEY_CONNECT_ACTION
:
1431 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1435 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1438 // Enter the network connection configuration page
1439 // Recovery from restored data
1441 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SSID
), Profile
->SSId
, NULL
) == 0) {
1442 return EFI_OUT_OF_RESOURCES
;
1445 IfrNvData
->SecurityType
= Profile
->SecurityType
;
1447 Private
->RegisteredHandle
,
1448 STRING_TOKEN (STR_SECURITY_TYPE
),
1449 mSecurityType
[IfrNvData
->SecurityType
],
1453 return EFI_OUT_OF_RESOURCES
;
1456 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1457 IfrNvData
->EapAuthMethod
= Profile
->EapAuthMethod
;
1458 IfrNvData
->EapSecondAuthMethod
= Profile
->EapSecondAuthMethod
;
1459 StrCpyS (IfrNvData
->EapIdentity
, EAP_IDENTITY_SIZE
, Profile
->EapIdentity
);
1464 case KEY_ENROLLED_CERT_NAME
:
1466 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1470 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1473 // Enter the key enrollment page
1474 // For TTLS and PEAP, only CA cert needs to be cared
1476 if (Private
->FileType
== FileTypeCACert
) {
1477 if (Profile
->CACertData
!= NULL
) {
1478 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->CACertName
, NULL
);
1480 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1482 } else if (Private
->FileType
== FileTypeClientCert
) {
1483 if (Profile
->ClientCertData
!= NULL
) {
1484 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->ClientCertName
, NULL
);
1486 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1492 case KEY_ENROLLED_PRIVATE_KEY_NAME
:
1494 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1498 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1500 if (Profile
->PrivateKeyData
!= NULL
) {
1501 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), Profile
->PrivateKeyName
, NULL
);
1503 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), L
"", NULL
);
1511 } else if (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
) {
1512 switch (QuestionId
) {
1513 case KEY_CONNECT_ACTION
:
1515 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1519 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1522 // Restore User Config Data for Page recovery
1524 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1525 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1526 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1527 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1535 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1536 switch (QuestionId
) {
1537 case KEY_NETWORK_LIST
:
1540 // User triggered a scan process.
1542 Private
->CurrentNic
->OneTimeScanRequest
= TRUE
;
1545 case KEY_PASSWORD_CONNECT_NETWORK
:
1546 case KEY_EAP_PASSWORD_CONNECT_NETWORK
:
1547 case KEY_PRIVATE_KEY_PASSWORD
:
1549 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1553 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1555 if (QuestionId
== KEY_PASSWORD_CONNECT_NETWORK
) {
1556 TempPassword
= Profile
->Password
;
1557 } else if (QuestionId
== KEY_EAP_PASSWORD_CONNECT_NETWORK
) {
1558 TempPassword
= Profile
->EapPassword
;
1560 TempPassword
= Profile
->PrivateKeyPassword
;
1563 Status
= WifiMgrRecordPassword (Private
, Value
->string
, TempPassword
, PASSWORD_STORAGE_SIZE
);
1564 if (EFI_ERROR (Status
)) {
1565 DEBUG ((DEBUG_ERROR
, "[WiFi Connection Manager] Error: Failed to input password!"));
1570 // This password is not a new created password, so no need to confirm.
1572 Status
= EFI_NOT_FOUND
;
1575 case KEY_CONNECT_ACTION
:
1577 ErrorMessage
= NULL
;
1578 ProfileToConnect
= NULL
;
1580 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1584 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1586 if ((Private
->CurrentNic
->ConnectState
== WifiMgrDisconnected
) ||
1587 (Profile
!= Private
->CurrentNic
->CurrentOperateNetwork
))
1590 // When this network is not currently connected, pend it to connect.
1592 if (Profile
->AKMSuiteSupported
&& Profile
->CipherSuiteSupported
) {
1593 if ((Profile
->SecurityType
== SECURITY_TYPE_NONE
) || (Profile
->SecurityType
== SECURITY_TYPE_WPA2_PERSONAL
)) {
1595 // For Open network, connect directly.
1597 ProfileToConnect
= Profile
;
1598 } else if (Profile
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1600 // For WPA/WPA2-Enterprise network, conduct eap configuration first.
1601 // Only EAP-TLS, TTLS and PEAP is supported now!
1603 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1604 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1606 if ((IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TTLS
) || (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_PEAP
)) {
1607 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1608 ProfileToConnect
= Profile
;
1609 } else if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TLS
) {
1610 ProfileToConnect
= Profile
;
1612 ErrorMessage
= L
"ERROR: Only EAP-TLS, TTLS or PEAP is supported now!";
1615 ErrorMessage
= L
"ERROR: Can't connect to this network!";
1618 ErrorMessage
= L
"ERROR: This network is not supported!";
1621 if (ErrorMessage
!= NULL
) {
1623 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1630 if (ProfileToConnect
!= NULL
) {
1631 Private
->CurrentNic
->OneTimeConnectRequest
= TRUE
;
1632 Private
->CurrentNic
->ConnectPendingNetwork
= ProfileToConnect
;
1634 } else if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
1636 // This network is currently connected, just disconnect from it.
1638 Private
->CurrentNic
->OneTimeDisconnectRequest
= TRUE
;
1639 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
1644 case KEY_ENROLL_CA_CERT_CONNECT_NETWORK
:
1646 Private
->FileType
= FileTypeCACert
;
1649 case KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK
:
1651 Private
->FileType
= FileTypeClientCert
;
1654 case KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE
:
1657 ChooseFile (NULL
, NULL
, NULL
, &FilePath
);
1659 if (FilePath
!= NULL
) {
1660 UpdatePrivateKeyFromFile (Private
, FilePath
);
1661 FreePool (FilePath
);
1666 case KEY_EAP_ENROLL_CERT_FROM_FILE
:
1669 // User will select a cert file from File Explore
1672 ChooseFile (NULL
, NULL
, NULL
, &FilePath
);
1674 if (FilePath
!= NULL
) {
1675 UpdateCAFromFile (Private
, FilePath
);
1676 FreePool (FilePath
);
1681 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1683 if ((Private
->FileContext
!= NULL
) && (Private
->FileContext
->FHandle
!= NULL
) &&
1684 (Private
->CurrentNic
->UserSelectedProfile
!= NULL
))
1687 // Read Private Key file to Buffer
1689 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1690 if (Profile
->PrivateKeyData
!= NULL
) {
1691 ZeroMem (Profile
->PrivateKeyData
, Profile
->PrivateKeyDataSize
);
1692 FreePool (Profile
->PrivateKeyData
);
1693 Profile
->PrivateKeyData
= NULL
;
1696 Status
= WifiMgrReadFileToBuffer (
1697 Private
->FileContext
,
1701 if (EFI_ERROR (Status
)) {
1703 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1705 L
"ERROR: Can't read this private key file!",
1709 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1711 Profile
->PrivateKeyData
= TempData
;
1712 Profile
->PrivateKeyDataSize
= TempDataSize
;
1713 StrCpyS (Profile
->PrivateKeyName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1717 "[WiFi Connection Manager] Private Key: %s has been enrolled! Size: %d\n",
1718 Profile
->PrivateKeyName
,
1719 Profile
->PrivateKeyDataSize
1726 case KEY_SAVE_CERT_TO_MEM
:
1728 if ((Private
->FileContext
!= NULL
) && (Private
->FileContext
->FHandle
!= NULL
) &&
1729 (Private
->CurrentNic
->UserSelectedProfile
!= NULL
))
1732 // Read Cert file to Buffer
1734 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1736 if (Private
->FileType
== FileTypeCACert
) {
1737 if (Profile
->CACertData
!= NULL
) {
1738 ZeroMem (Profile
->CACertData
, Profile
->CACertSize
);
1739 FreePool (Profile
->CACertData
);
1740 Profile
->CACertData
= NULL
;
1742 } else if (Private
->FileType
== FileTypeClientCert
) {
1743 if (Profile
->ClientCertData
!= NULL
) {
1744 ZeroMem (Profile
->ClientCertData
, Profile
->ClientCertSize
);
1745 FreePool (Profile
->ClientCertData
);
1746 Profile
->ClientCertData
= NULL
;
1752 Status
= WifiMgrReadFileToBuffer (
1753 Private
->FileContext
,
1757 if (EFI_ERROR (Status
)) {
1759 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1761 L
"ERROR: Can't read this certificate file!",
1765 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1766 if (Private
->FileType
== FileTypeCACert
) {
1767 Profile
->CACertData
= TempData
;
1768 Profile
->CACertSize
= TempDataSize
;
1769 StrCpyS (Profile
->CACertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1772 "[WiFi Connection Manager] CA Cert: %s has been enrolled! Size: %d\n",
1773 Profile
->CACertName
,
1777 Profile
->ClientCertData
= TempData
;
1778 Profile
->ClientCertSize
= TempDataSize
;
1779 StrCpyS (Profile
->ClientCertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1782 "[WiFi Connection Manager] Client Cert: %s has been enrolled! Size: %d\n",
1783 Profile
->ClientCertName
,
1784 Profile
->ClientCertSize
1792 case KEY_ADD_HIDDEN_NETWORK
:
1795 // Add a Hidden Network
1797 if ((StrLen (IfrNvData
->SSId
) < SSID_MIN_LEN
) ||
1798 (Private
->HiddenNetworkCount
>= HIDDEN_NETWORK_LIST_COUNT_MAX
))
1800 Status
= EFI_ABORTED
;
1804 // Check if this SSId is already in Hidden Network List
1806 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
1807 HiddenNetwork
= NET_LIST_USER_STRUCT_S (
1809 WIFI_HIDDEN_NETWORK_DATA
,
1811 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
1813 if (StrCmp (HiddenNetwork
->SSId
, IfrNvData
->SSId
) == 0) {
1814 Status
= EFI_ABORTED
;
1820 HiddenNetwork
= (WIFI_HIDDEN_NETWORK_DATA
*)AllocateZeroPool (sizeof (WIFI_HIDDEN_NETWORK_DATA
));
1821 if (HiddenNetwork
== NULL
) {
1822 Status
= EFI_OUT_OF_RESOURCES
;
1826 HiddenNetwork
->Signature
= WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
;
1827 StrCpyS (HiddenNetwork
->SSId
, SSID_STORAGE_SIZE
, IfrNvData
->SSId
);
1829 InsertTailList (&Private
->HiddenNetworkList
, &HiddenNetwork
->Link
);
1830 Private
->HiddenNetworkCount
++;
1832 WifiMgrRefreshHiddenList (Private
);
1835 case KEY_REMOVE_HIDDEN_NETWORK
:
1838 // Remove Hidden Networks
1840 Entry
= GetFirstNode (&Private
->HiddenNetworkList
);
1842 for (Index
= 0; Index
< Private
->HiddenNetworkCount
; Index
++) {
1843 if (IfrNvData
->HiddenNetworkList
[Index
] != 0) {
1844 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
, Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1845 Entry
= RemoveEntryList (Entry
);
1848 FreePool (HiddenNetwork
);
1850 Entry
= GetNextNode (&Private
->HiddenNetworkList
, Entry
);
1854 Private
->HiddenNetworkCount
-= RemoveCount
;
1855 WifiMgrRefreshHiddenList (Private
);
1860 if ((QuestionId
>= KEY_MAC_ENTRY_BASE
) && (QuestionId
< KEY_MAC_ENTRY_BASE
+ Private
->NicCount
)) {
1862 // User selects a wireless NIC.
1864 Status
= WifiMgrSelectNic (Private
, QuestionId
);
1865 if (EFI_ERROR (Status
)) {
1867 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1869 L
"ERROR: Fail to operate the wireless NIC!",
1873 } else if (Private
->CurrentNic
!= NULL
) {
1874 if ((QuestionId
>= KEY_AVAILABLE_NETWORK_ENTRY_BASE
) &&
1875 (QuestionId
<= KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Private
->CurrentNic
->MaxProfileIndex
))
1877 Status
= WifiMgrUserSelectProfileToConnect (Private
, QuestionId
- KEY_AVAILABLE_NETWORK_ENTRY_BASE
);
1878 if (!EFI_ERROR (Status
)) {
1879 WifiMgrUpdateConnectMessage (Private
->CurrentNic
, FALSE
, NULL
);
1883 if (EFI_ERROR (Status
)) {
1885 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1887 L
"ERROR: Fail to operate this profile!",
1895 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1896 switch (QuestionId
) {
1897 case KEY_SAVE_CERT_TO_MEM
:
1898 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1900 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1903 case KEY_NO_SAVE_CERT_TO_MEM
:
1904 case KEY_NO_SAVE_PRIVATE_KEY_TO_MEM
:
1906 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1911 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1914 } else if (Action
== EFI_BROWSER_ACTION_RETRIEVE
) {
1915 switch (QuestionId
) {
1916 case KEY_REFRESH_NETWORK_LIST
:
1918 WifiMgrRefreshNetworkList (Private
, IfrNvData
);
1926 if (!EFI_ERROR (Status
)) {
1928 // Pass changed uncommitted data back to Form Browser.
1930 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1931 HiiSetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*)IfrNvData
, NULL
);
1934 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1935 FreePool (IfrNvData
);
1940 Initialize the WiFi configuration form.
1942 @param[in] Private The pointer to the global private data structure.
1944 @retval EFI_SUCCESS The configuration form is initialized.
1945 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1946 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1947 @retval Other Erros Returned Errors when installing protocols.
1951 WifiMgrDxeConfigFormInit (
1952 WIFI_MGR_PRIVATE_DATA
*Private
1957 if (Private
== NULL
) {
1958 return EFI_INVALID_PARAMETER
;
1961 Private
->ConfigAccess
.ExtractConfig
= WifiMgrDxeHiiConfigAccessExtractConfig
;
1962 Private
->ConfigAccess
.RouteConfig
= WifiMgrDxeHiiConfigAccessRouteConfig
;
1963 Private
->ConfigAccess
.Callback
= WifiMgrDxeHiiConfigAccessCallback
;
1966 // Install Device Path Protocol and Config Access protocol to driver handle.
1968 Status
= gBS
->InstallMultipleProtocolInterfaces (
1969 &Private
->DriverHandle
,
1970 &gEfiDevicePathProtocolGuid
,
1971 &mWifiMgrDxeHiiVendorDevicePath
,
1972 &gEfiHiiConfigAccessProtocolGuid
,
1973 &Private
->ConfigAccess
,
1976 if (EFI_ERROR (Status
)) {
1981 // Publish our HII data.
1983 Private
->RegisteredHandle
= HiiAddPackages (
1984 &gWifiConfigFormSetGuid
,
1985 Private
->DriverHandle
,
1986 WifiConnectionManagerDxeStrings
,
1987 WifiConnectionManagerDxeBin
,
1990 if (Private
->RegisteredHandle
== NULL
) {
1991 gBS
->UninstallMultipleProtocolInterfaces (
1992 Private
->DriverHandle
,
1993 &gEfiDevicePathProtocolGuid
,
1994 &mWifiMgrDxeHiiVendorDevicePath
,
1995 &gEfiHiiConfigAccessProtocolGuid
,
1996 &Private
->ConfigAccess
,
1999 return EFI_OUT_OF_RESOURCES
;
2002 Private
->FileContext
= AllocateZeroPool (sizeof (WIFI_MGR_FILE_CONTEXT
));
2003 if (Private
->FileContext
== NULL
) {
2004 return EFI_OUT_OF_RESOURCES
;
2011 Unload the WiFi configuration form.
2013 @param[in] Private The pointer to the global private data structure.
2015 @retval EFI_SUCCESS The configuration form is unloaded successfully.
2016 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
2017 @retval Other Errors Returned Erros when uninstalling protocols.
2021 WifiMgrDxeConfigFormUnload (
2022 WIFI_MGR_PRIVATE_DATA
*Private
2027 if (Private
== NULL
) {
2028 return EFI_INVALID_PARAMETER
;
2031 if (Private
->FileContext
!= NULL
) {
2032 if (Private
->FileContext
->FHandle
!= NULL
) {
2033 Private
->FileContext
->FHandle
->Close (Private
->FileContext
->FHandle
);
2036 if (Private
->FileContext
->FileName
!= NULL
) {
2037 FreePool (Private
->FileContext
->FileName
);
2040 FreePool (Private
->FileContext
);
2043 HiiRemovePackages (Private
->RegisteredHandle
);
2045 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2046 Private
->DriverHandle
,
2047 &gEfiDevicePathProtocolGuid
,
2048 &mWifiMgrDxeHiiVendorDevicePath
,
2049 &gEfiHiiConfigAccessProtocolGuid
,
2050 &Private
->ConfigAccess
,