2 The Hii functions for WiFi Connection Manager.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "WifiConnectionMgrDxe.h"
18 CHAR16 mVendorStorageName
[] = L
"WIFI_MANAGER_IFR_NVDATA";
20 HII_VENDOR_DEVICE_PATH mWifiMgrDxeHiiVendorDevicePath
= {
26 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
27 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
30 WIFI_CONNECTION_MANAGER_CONFIG_GUID
34 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
36 (UINT8
) (END_DEVICE_PATH_LENGTH
),
37 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
43 // HII Config Access Protocol instance
45 GLOBAL_REMOVE_IF_UNREFERENCED
46 EFI_HII_CONFIG_ACCESS_PROTOCOL gWifiMgrDxeHiiConfigAccess
= {
47 WifiMgrDxeHiiConfigAccessExtractConfig
,
48 WifiMgrDxeHiiConfigAccessRouteConfig
,
49 WifiMgrDxeHiiConfigAccessCallback
52 CHAR16
* mSecurityType
[] = {
62 CHAR16
* mSignalStrengthBar
[] = {
71 #define RSSI_TO_SIGNAL_STRENGTH_BAR(Rssi) mSignalStrengthBar[((Rssi + 19)/20)]
73 #define NET_LIST_FOR_EACH_FROM_NODE(Entry, Node, ListHead) \
74 for(Entry = Node->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
76 extern EFI_GUID gWifiConfigFormSetGuid
;
79 Create Hii Extend Label OpCode as the start opcode and end opcode.
80 The caller is responsible for freeing the OpCode with HiiFreeOpCodeHandle().
82 @param[in] StartLabelNumber The number of start label.
83 @param[out] StartOpCodeHandle Points to the start opcode handle.
84 @param[out] EndOpCodeHandle Points to the end opcode handle.
86 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
88 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
89 @retval EFI_SUCCESS The operation is completed successfully.
90 @retval Other Errors Returned errors when updating the HII form.
95 IN UINT16 StartLabelNumber
,
96 OUT VOID
**StartOpCodeHandle
,
97 OUT VOID
**EndOpCodeHandle
101 EFI_IFR_GUID_LABEL
*InternalStartLabel
;
102 EFI_IFR_GUID_LABEL
*InternalEndLabel
;
104 if (StartOpCodeHandle
== NULL
|| EndOpCodeHandle
== NULL
) {
105 return EFI_INVALID_PARAMETER
;
108 Status
= EFI_OUT_OF_RESOURCES
;
109 *StartOpCodeHandle
= NULL
;
110 *EndOpCodeHandle
= NULL
;
113 // Initialize the container for dynamic opcodes.
115 *StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
116 if (*StartOpCodeHandle
== NULL
) {
119 *EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
120 if (*EndOpCodeHandle
== NULL
) {
125 // Create Hii Extend Label OpCode as the start opcode.
127 InternalStartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
131 sizeof (EFI_IFR_GUID_LABEL
)
133 if (InternalStartLabel
== NULL
) {
136 InternalStartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
137 InternalStartLabel
->Number
= StartLabelNumber
;
140 // Create Hii Extend Label OpCode as the end opcode.
142 InternalEndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
146 sizeof (EFI_IFR_GUID_LABEL
)
148 if (InternalEndLabel
== NULL
) {
151 InternalEndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
152 InternalEndLabel
->Number
= LABEL_END
;
158 if (*StartOpCodeHandle
!= NULL
) {
159 HiiFreeOpCodeHandle (*StartOpCodeHandle
);
161 if (*EndOpCodeHandle
!= NULL
) {
162 HiiFreeOpCodeHandle (*EndOpCodeHandle
);
168 Display the Nic list contains all available Nics.
170 @param[in] Private The pointer to the global private data structure.
172 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
173 @retval EFI_SUCCESS The operation is completed successfully.
178 IN WIFI_MGR_PRIVATE_DATA
*Private
182 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
183 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
184 EFI_STRING_ID PortTitleToken
;
185 EFI_STRING_ID PortTitleHelpToken
;
186 WIFI_MGR_DEVICE_DATA
*Nic
;
188 VOID
*StartOpCodeHandle
;
189 VOID
*EndOpCodeHandle
;
191 if (Private
== NULL
) {
192 return EFI_INVALID_PARAMETER
;
195 Status
= WifiMgrCreateOpCode (
200 if (EFI_ERROR (Status
)) {
204 NET_LIST_FOR_EACH (Entry
, &Private
->NicList
) {
205 Nic
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_MGR_DEVICE_DATA
, Link
, WIFI_MGR_DEVICE_DATA_SIGNATURE
);
206 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
207 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC %s", MacString
);
208 PortTitleToken
= HiiSetString (
209 Private
->RegisteredHandle
,
214 if (PortTitleToken
== 0) {
215 Status
= EFI_INVALID_PARAMETER
;
219 UnicodeSPrint (PortString
, sizeof (PortString
), L
"MAC Address");
220 PortTitleHelpToken
= HiiSetString (
221 Private
->RegisteredHandle
,
226 if (PortTitleHelpToken
== 0) {
227 Status
= EFI_INVALID_PARAMETER
;
231 HiiCreateGotoOpCode (
233 FORMID_WIFI_MAINPAGE
,
236 EFI_IFR_FLAG_CALLBACK
,
237 (UINT16
) (KEY_MAC_ENTRY_BASE
+ Nic
->NicIndex
)
241 Status
= HiiUpdateForm (
242 Private
->RegisteredHandle
, // HII handle
243 &gWifiConfigFormSetGuid
, // Formset GUID
244 FORMID_MAC_SELECTION
, // Form ID
245 StartOpCodeHandle
, // Label for where to insert opcodes
246 EndOpCodeHandle
// Replace data
251 HiiFreeOpCodeHandle (StartOpCodeHandle
);
252 HiiFreeOpCodeHandle (EndOpCodeHandle
);
257 Retreive the unicode string of the AKM Suite list of a profile.
258 The caller is responsible for freeing the string with FreePool().
260 @param[in] Profile The network profile contains a AKM suite list.
262 @return the unicode string of AKM suite list or "None".
266 WifiMgrGetStrAKMList (
267 IN WIFI_MGR_NETWORK_PROFILE
*Profile
271 UINT16 AKMSuiteCount
;
272 CHAR16
*AKMListDisplay
;
274 AKMListDisplay
= NULL
;
275 if (Profile
== NULL
|| Profile
->Network
.AKMSuite
== NULL
) {
279 AKMSuiteCount
= Profile
->Network
.AKMSuite
->AKMSuiteCount
;
280 if (AKMSuiteCount
!= 0) {
283 // Current AKM Suite is between 1-9
285 AKMListDisplay
= (CHAR16
*) AllocateZeroPool(sizeof (CHAR16
) * AKMSuiteCount
* 2);
286 if (AKMListDisplay
!= NULL
) {
287 for (Index
= 0; Index
< AKMSuiteCount
; Index
++) {
289 AKMListDisplay
+ (Index
* 2),
292 Profile
->Network
.AKMSuite
->AKMSuiteList
[Index
].SuiteType
294 if (Index
== AKMSuiteCount
- 1) {
295 *(AKMListDisplay
+ (Index
* 2 + 1)) = L
'\0';
303 if (AKMListDisplay
== NULL
) {
304 AKMListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
306 return AKMListDisplay
;
310 Retreive the unicode string of the Cipher Suite list of a profile.
311 The caller is responsible for freeing the string with FreePool().
313 @param[in] Profile The network profile contains a Cipher suite list.
315 @return the unicode string of Cipher suite list or "None".
319 WifiMgrGetStrCipherList (
320 IN WIFI_MGR_NETWORK_PROFILE
*Profile
324 UINT16 CipherSuiteCount
;
325 CHAR16
*CipherListDisplay
;
327 CipherListDisplay
= NULL
;
328 if (Profile
== NULL
|| Profile
->Network
.CipherSuite
== NULL
) {
332 CipherSuiteCount
= Profile
->Network
.CipherSuite
->CipherSuiteCount
;
333 if (CipherSuiteCount
!= 0) {
336 // Current Cipher Suite is between 1-9
338 CipherListDisplay
= (CHAR16
*) AllocateZeroPool(sizeof (CHAR16
) * CipherSuiteCount
* 2);
339 if (CipherListDisplay
!= NULL
) {
340 for (Index
= 0; Index
< CipherSuiteCount
; Index
++) {
342 CipherListDisplay
+ (Index
* 2),
345 Profile
->Network
.CipherSuite
->CipherSuiteList
[Index
].SuiteType
347 if (Index
== CipherSuiteCount
- 1) {
348 *(CipherListDisplay
+ (Index
* 2 + 1)) = L
'\0';
356 if (CipherListDisplay
== NULL
) {
357 CipherListDisplay
= AllocateCopyPool (sizeof (L
"None"), L
"None");
359 return CipherListDisplay
;
363 Refresh the network list display of the current Nic.
365 @param[in] Private The pointer to the global private data structure.
366 @param[out] IfrNvData The IFR NV data.
368 @retval EFI_SUCCESS The operation is completed successfully.
369 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
370 @retval Other Errors Returned errors when creating Opcodes or updating the
375 WifiMgrRefreshNetworkList (
376 IN WIFI_MGR_PRIVATE_DATA
*Private
,
377 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
382 UINT32 AvailableCount
;
383 EFI_STRING_ID PortPromptToken
;
384 EFI_STRING_ID PortTextToken
;
385 EFI_STRING_ID PortHelpToken
;
386 WIFI_MGR_NETWORK_PROFILE
*Profile
;
388 VOID
*StartOpCodeHandle
;
389 VOID
*EndOpCodeHandle
;
390 CHAR16
*AKMListDisplay
;
391 CHAR16
*CipherListDisplay
;
392 CHAR16 PortString
[WIFI_STR_MAX_SIZE
];
393 UINTN PortStringSize
;
394 WIFI_MGR_NETWORK_PROFILE
*ConnectedProfile
;
396 if (Private
->CurrentNic
== NULL
) {
400 Status
= WifiMgrCreateOpCode (
401 LABEL_NETWORK_LIST_ENTRY
,
405 if (EFI_ERROR (Status
)) {
409 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
411 PortStringSize
= sizeof (PortString
);
412 ConnectedProfile
= NULL
;
413 AKMListDisplay
= NULL
;
414 CipherListDisplay
= NULL
;
416 if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
419 // Display the current connected network.
420 // Find the current operate network under connected status.
422 if (Private
->CurrentNic
->CurrentOperateNetwork
!= NULL
&&
423 Private
->CurrentNic
->CurrentOperateNetwork
->IsAvailable
) {
425 Profile
= Private
->CurrentNic
->CurrentOperateNetwork
;
428 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
429 if (AKMListDisplay
== NULL
) {
430 Status
= EFI_OUT_OF_RESOURCES
;
433 CipherListDisplay
= WifiMgrGetStrCipherList(Profile
);
434 if (CipherListDisplay
== NULL
) {
435 Status
= EFI_OUT_OF_RESOURCES
;
439 UnicodeSPrint (PortString
, PortStringSize
, L
"%s (Connected)", Profile
->SSId
);
440 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
442 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
445 UnicodeSPrint (PortString
, PortStringSize
, L
"AKMSuite: %s CipherSuite: %s", AKMListDisplay
, CipherListDisplay
);
446 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
448 FreePool (AKMListDisplay
);
449 FreePool (CipherListDisplay
);
451 HiiCreateGotoOpCode (
453 FORMID_CONNECT_NETWORK
,
456 EFI_IFR_FLAG_CALLBACK
,
457 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
464 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
465 mSecurityType
[Profile
->SecurityType
],
466 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
468 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
470 HiiCreateTextOpCode (
477 ConnectedProfile
= Profile
;
479 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
484 // Display all supported available networks.
486 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
488 Profile
= NET_LIST_USER_STRUCT_S (
490 WIFI_MGR_NETWORK_PROFILE
,
492 WIFI_MGR_PROFILE_SIGNATURE
494 if (ConnectedProfile
== Profile
) {
497 if (Profile
->IsAvailable
&& Profile
->CipherSuiteSupported
) {
501 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
502 if (AKMListDisplay
== NULL
) {
503 Status
= EFI_OUT_OF_RESOURCES
;
506 CipherListDisplay
= WifiMgrGetStrCipherList(Profile
);
507 if (CipherListDisplay
== NULL
) {
508 Status
= EFI_OUT_OF_RESOURCES
;
512 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
513 if (PortPromptToken
== 0) {
514 Status
= EFI_OUT_OF_RESOURCES
;
518 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
) {
524 L
"AKMSuite: %s CipherSuite: %s",
525 AKMListDisplay
, CipherListDisplay
527 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
528 if (PortHelpToken
== 0) {
529 Status
= EFI_OUT_OF_RESOURCES
;
533 FreePool (AKMListDisplay
);
534 FreePool (CipherListDisplay
);
536 HiiCreateGotoOpCode (
538 FORMID_CONNECT_NETWORK
,
541 EFI_IFR_FLAG_CALLBACK
,
542 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
549 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
550 mSecurityType
[Profile
->SecurityType
],
551 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
553 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
554 if (PortTextToken
== 0) {
555 Status
= EFI_OUT_OF_RESOURCES
;
558 HiiCreateTextOpCode (
568 // Display all Unsupported available networks.
570 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
572 Profile
= NET_LIST_USER_STRUCT_S (
574 WIFI_MGR_NETWORK_PROFILE
,
576 WIFI_MGR_PROFILE_SIGNATURE
578 if (ConnectedProfile
== Profile
) {
581 if (Profile
->IsAvailable
&& !Profile
->CipherSuiteSupported
) {
585 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
586 if (AKMListDisplay
== NULL
) {
587 Status
= EFI_OUT_OF_RESOURCES
;
590 CipherListDisplay
= WifiMgrGetStrCipherList(Profile
);
591 if (CipherListDisplay
== NULL
) {
592 Status
= EFI_OUT_OF_RESOURCES
;
596 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
598 if (Profile
->AKMSuiteSupported
) {
602 L
"AKMSuite: %s CipherSuite(UnSupported): %s",
603 AKMListDisplay
, CipherListDisplay
609 L
"AKMSuite(UnSupported): %s CipherSuite(UnSupported): %s",
610 AKMListDisplay
, CipherListDisplay
613 FreePool (AKMListDisplay
);
614 FreePool (CipherListDisplay
);
616 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
618 HiiCreateGotoOpCode (
620 FORMID_CONNECT_NETWORK
,
623 EFI_IFR_FLAG_CALLBACK
,
624 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
632 mSecurityType
[Profile
->SecurityType
],
633 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
635 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
637 HiiCreateTextOpCode (
646 Status
= HiiUpdateForm (
647 Private
->RegisteredHandle
, // HII handle
648 &gWifiConfigFormSetGuid
, // Formset GUID
649 FORMID_NETWORK_LIST
, // Form ID
650 StartOpCodeHandle
, // Label for where to insert opcodes
651 EndOpCodeHandle
// Replace data
656 gBS
->RestoreTPL (OldTpl
);
658 if (AKMListDisplay
!= NULL
) {
659 FreePool (AKMListDisplay
);
661 if (CipherListDisplay
!= NULL
) {
662 FreePool (CipherListDisplay
);
665 HiiFreeOpCodeHandle (StartOpCodeHandle
);
666 HiiFreeOpCodeHandle (EndOpCodeHandle
);
668 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Network List is Refreshed!\n"));
673 Refresh the hidden network list configured by user.
675 @param[in] Private The pointer to the global private data structure.
677 @retval EFI_SUCCESS The operation is completed successfully.
678 @retval Other Errors Returned errors when creating Opcodes or updating the
682 WifiMgrRefreshHiddenList (
683 IN WIFI_MGR_PRIVATE_DATA
*Private
689 EFI_STRING_ID StringId
;
690 VOID
*StartOpCodeHandle
;
691 VOID
*EndOpCodeHandle
;
692 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
695 if (Private
== NULL
) {
699 Status
= WifiMgrCreateOpCode (
700 LABEL_HIDDEN_NETWORK_ENTRY
,
704 if (EFI_ERROR (Status
)) {
708 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
711 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
713 HiddenNetwork
= NET_LIST_USER_STRUCT_S (
715 WIFI_HIDDEN_NETWORK_DATA
,
717 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
719 StringId
= HiiSetString (Private
->RegisteredHandle
, 0, HiddenNetwork
->SSId
, NULL
);
721 HiiCreateCheckBoxOpCode (
723 (EFI_QUESTION_ID
) (KEY_HIDDEN_NETWORK_ENTRY_BASE
+ Index
),
725 (UINT16
) (HIDDEN_NETWORK_LIST_VAR_OFFSET
+ Index
),
735 Status
= HiiUpdateForm (
736 Private
->RegisteredHandle
, // HII handle
737 &gWifiConfigFormSetGuid
, // Formset GUID
738 FORMID_HIDDEN_NETWORK_LIST
, // Form ID
739 StartOpCodeHandle
, // Label for where to insert opcodes
740 EndOpCodeHandle
// Replace data
743 gBS
->RestoreTPL (OldTpl
);
744 HiiFreeOpCodeHandle (StartOpCodeHandle
);
745 HiiFreeOpCodeHandle (EndOpCodeHandle
);
751 Callback function for user to select a Nic.
753 @param[in] Private The pointer to the global private data structure.
754 @param[in] KeyValue The key value received from HII input.
756 @retval EFI_NOT_FOUND The corresponding Nic is not found.
757 @retval EFI_SUCCESS The operation is completed successfully.
762 IN WIFI_MGR_PRIVATE_DATA
*Private
,
763 IN EFI_QUESTION_ID KeyValue
766 WIFI_MGR_DEVICE_DATA
*Nic
;
768 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
770 NicIndex
= KeyValue
- KEY_MAC_ENTRY_BASE
;
771 Nic
= WifiMgrGetNicByIndex (Private
, NicIndex
);
773 return EFI_NOT_FOUND
;
775 Private
->CurrentNic
= Nic
;
777 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
778 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN(STR_MAC_ADDRESS
), MacString
, NULL
);
783 Restore the NV data to be default.
785 @param[in] Private The pointer to the global private data structure.
786 @param[out] IfrNvData The IFR NV data.
790 WifiMgrCleanUserInput (
791 IN WIFI_MGR_PRIVATE_DATA
*Private
794 Private
->SecurityType
= SECURITY_TYPE_NONE
;
795 Private
->EapAuthMethod
= EAP_AUTH_METHOD_TTLS
;
796 Private
->EapSecondAuthMethod
= EAP_SEAUTH_METHOD_MSCHAPV2
;
797 Private
->FileType
= FileTypeMax
;
801 UI handle function when user select a network to connect.
803 @param[in] Private The pointer to the global private data structure.
804 @param[in] ProfileIndex The profile index user selected to connect.
806 @retval EFI_INVALID_PARAMETER Nic is null.
807 @retval EFI_NOT_FOUND Profile could not be found.
808 @retval EFI_SUCCESS The operation is completed successfully.
812 WifiMgrUserSelectProfileToConnect(
813 IN WIFI_MGR_PRIVATE_DATA
*Private
,
814 IN UINT32 ProfileIndex
817 WIFI_MGR_NETWORK_PROFILE
*Profile
;
818 WIFI_MGR_DEVICE_DATA
*Nic
;
820 Nic
= Private
->CurrentNic
;
822 return EFI_INVALID_PARAMETER
;
826 //Initialize the connection page
828 WifiMgrCleanUserInput(Private
);
830 Profile
= WifiMgrGetProfileByProfileIndex (ProfileIndex
, &Nic
->ProfileList
);
831 if (Profile
== NULL
) {
832 return EFI_NOT_FOUND
;
834 Private
->CurrentNic
->UserSelectedProfile
= Profile
;
840 Record password from a HII input string.
842 @param[in] Private The pointer to the global private data structure.
843 @param[in] StringId The QuestionId received from HII input.
844 @param[in] StringBuffer The unicode string buffer to store password.
845 @param[in] StringBufferLen The len of unicode string buffer.
847 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
848 @retval EFI_NOT_FOUND The password string is not found or invalid.
849 @retval EFI_SUCCESS The operation is completed successfully.
853 WifiMgrRecordPassword (
854 IN WIFI_MGR_PRIVATE_DATA
*Private
,
855 IN EFI_STRING_ID StringId
,
856 IN CHAR16
*StringBuffer
,
857 IN UINTN StringBufferLen
862 if (StringId
== 0 || StringBuffer
== NULL
|| StringBufferLen
<= 0) {
863 return EFI_INVALID_PARAMETER
;
866 Password
= HiiGetString (Private
->RegisteredHandle
, StringId
, NULL
);
867 if (Password
== NULL
) {
868 return EFI_NOT_FOUND
;
870 if (StrLen (Password
) > StringBufferLen
) {
872 return EFI_NOT_FOUND
;
874 StrnCpyS (StringBuffer
, StringBufferLen
, Password
, StrLen (Password
));
875 ZeroMem (Password
, (StrLen (Password
) + 1) * sizeof (CHAR16
));
879 // Clean password in string package
881 HiiSetString (Private
->RegisteredHandle
, StringId
, L
"", NULL
);
886 Update connection message on connect configuration page, and trigger related form refresh.
888 @param[in] Nic The related Nic for updating message.
889 @param[in] ConnectStateChanged The tag to tell if the connection state has been changed, only
890 when the connection changes from "Connected" or "Disconnecting"
891 to "Disconnected", or from "Disconnected" or "Connecting" to
892 "Connected", this tag can be set as TRUE.
893 @param[in] ConnectStatusMessage The message to show on connected status bar, if NULL, will
898 WifiMgrUpdateConnectMessage (
899 IN WIFI_MGR_DEVICE_DATA
*Nic
,
900 IN BOOLEAN ConnectStateChanged
,
901 IN EFI_STRING ConnectStatusMessage
904 CHAR16 ConnectStatusStr
[WIFI_STR_MAX_SIZE
];
905 WIFI_MGR_PRIVATE_DATA
*Private
;
907 Private
= Nic
->Private
;
908 if (Private
== NULL
|| Private
->CurrentNic
!= Nic
) {
913 // Update Connection Status Bar
915 if (ConnectStatusMessage
!= NULL
) {
916 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusMessage
, NULL
);
918 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
920 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Connected to %s",
921 Nic
->CurrentOperateNetwork
->SSId
);
922 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
923 } else if (Nic
->ConnectState
== WifiMgrDisconnected
) {
925 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), L
"Disconnected", NULL
);
926 } else if (Nic
->ConnectState
== WifiMgrConnectingToAp
) {
928 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Connecting to %s ...",
929 Nic
->CurrentOperateNetwork
->SSId
);
930 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
931 } else if (Nic
->ConnectState
== WifiMgrDisconnectingToAp
) {
933 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Disconnecting from %s ...",
934 Nic
->CurrentOperateNetwork
->SSId
);
935 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
942 // Update Connect Button
944 if (Nic
->ConnectState
== WifiMgrConnectedToAp
&& Nic
->UserSelectedProfile
== Nic
->CurrentOperateNetwork
) {
946 HiiSetString (Private
->RegisteredHandle
,
947 STRING_TOKEN (STR_CONNECT_NOW
), L
"Disconnect from this Network", NULL
);
949 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_NOW
), L
"Connect to this Network", NULL
);
951 gBS
->SignalEvent (Private
->ConnectFormRefreshEvent
);
954 // Update Main Page and Network List
956 if (ConnectStateChanged
) {
958 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
960 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Connected to", NULL
);
961 HiiSetString (Private
->RegisteredHandle
,
962 STRING_TOKEN (STR_CONNECTED_SSID
), Nic
->CurrentOperateNetwork
->SSId
, NULL
);
964 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Disconnected", NULL
);
965 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTED_SSID
), L
"", NULL
);
968 gBS
->SignalEvent (Private
->NetworkListRefreshEvent
);
969 gBS
->SignalEvent (Private
->MainPageRefreshEvent
);
974 Convert the driver configuration data into the IFR data.
976 @param[in] Private The pointer to the global private data structure.
977 @param[out] IfrNvData The IFR NV data.
979 @retval EFI_SUCCESS The operation is completed successfully.
983 WifiMgrConvertConfigDataToIfrNvData (
984 IN WIFI_MGR_PRIVATE_DATA
*Private
,
985 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
989 // Private shouldn't be NULL here, assert if Private is NULL.
991 ASSERT (Private
!= NULL
);
993 if (Private
->CurrentNic
!= NULL
) {
994 IfrNvData
->ProfileCount
= Private
->CurrentNic
->AvailableCount
;
996 IfrNvData
->ProfileCount
= 0;
1003 Convert the IFR data into the driver configuration data.
1005 @param[in] Private The pointer to the global private data structure.
1006 @param[in, out] IfrNvData The IFR NV data.
1008 @retval EFI_SUCCESS The operation is completed successfully.
1012 WifiMgrConvertIfrNvDataToConfigData (
1013 IN WIFI_MGR_PRIVATE_DATA
*Private
,
1014 IN OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
1021 This function allows the caller to request the current
1022 configuration for one or more named elements. The resulting
1023 string is in <ConfigAltResp> format. Any and all alternative
1024 configuration strings shall also be appended to the end of the
1025 current configuration string. If they are, they must appear
1026 after the current configuration. They must contain the same
1027 routing (GUID, NAME, PATH) as the current configuration string.
1028 They must have an additional description indicating the type of
1029 alternative configuration the string represents,
1030 "ALTCFG=<StringToken>". That <StringToken> (when
1031 converted from Hex UNICODE to binary) is a reference to a
1032 string in the associated string pack.
1034 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1036 @param Request A null-terminated Unicode string in
1037 <ConfigRequest> format. Note that this
1038 includes the routing information as well as
1039 the configurable name / value pairs. It is
1040 invalid for this string to be in
1041 <MultiConfigRequest> format.
1042 If a NULL is passed in for the Request field,
1043 all of the settings being abstracted by this function
1044 will be returned in the Results field. In addition,
1045 if a ConfigHdr is passed in with no request elements,
1046 all of the settings being abstracted for that particular
1047 ConfigHdr reference will be returned in the Results Field.
1049 @param Progress On return, points to a character in the
1050 Request string. Points to the string's null
1051 terminator if request was successful. Points
1052 to the most recent "&" before the first
1053 failing name / value pair (or the beginning
1054 of the string if the failure is in the first
1055 name / value pair) if the request was not
1058 @param Results A null-terminated Unicode string in
1059 <MultiConfigAltResp> format which has all values
1060 filled in for the names in the Request string.
1061 String to be allocated by the called function.
1063 @retval EFI_SUCCESS The Results string is filled with the
1064 values corresponding to all requested
1067 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1068 parts of the results that must be
1069 stored awaiting possible future
1072 @retval EFI_NOT_FOUND Routing data doesn't match any
1073 known driver. Progress set to the
1074 first character in the routing header.
1075 Note: There is no requirement that the
1076 driver validate the routing data. It
1077 must skip the <ConfigHdr> in order to
1080 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
1081 to most recent "&" before the
1082 error or the beginning of the
1085 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
1086 to the & before the name in
1092 WifiMgrDxeHiiConfigAccessExtractConfig (
1093 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1094 IN CONST EFI_STRING Request
,
1095 OUT EFI_STRING
*Progress
,
1096 OUT EFI_STRING
*Results
1099 WIFI_MGR_PRIVATE_DATA
*Private
;
1100 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1101 EFI_STRING ConfigRequestHdr
;
1102 EFI_STRING ConfigRequest
;
1104 BOOLEAN AllocatedRequest
;
1108 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
1109 return EFI_INVALID_PARAMETER
;
1112 *Progress
= Request
;
1113 if ((Request
!= NULL
) &&
1114 !HiiIsConfigHdrMatch (Request
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1115 return EFI_NOT_FOUND
;
1118 ConfigRequestHdr
= NULL
;
1119 ConfigRequest
= NULL
;
1120 AllocatedRequest
= FALSE
;
1123 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1125 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1126 IfrNvData
= AllocateZeroPool (BufferSize
);
1127 if (IfrNvData
== NULL
) {
1128 return EFI_OUT_OF_RESOURCES
;
1131 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1133 ConfigRequest
= Request
;
1134 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1136 // Request has no request element, construct full request string.
1137 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1138 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
1140 ConfigRequestHdr
= HiiConstructConfigHdr (
1141 &gWifiConfigFormSetGuid
,
1143 Private
->DriverHandle
);
1144 if (ConfigRequestHdr
== NULL
) {
1145 FreePool (IfrNvData
);
1146 return EFI_OUT_OF_RESOURCES
;
1149 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1150 ConfigRequest
= AllocateZeroPool (Size
);
1151 if (ConfigRequest
== NULL
) {
1153 FreePool (IfrNvData
);
1154 FreePool (ConfigRequestHdr
);
1155 return EFI_OUT_OF_RESOURCES
;
1158 AllocatedRequest
= TRUE
;
1162 L
"%s&OFFSET=0&WIDTH=%016LX",
1166 FreePool (ConfigRequestHdr
);
1170 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1172 Status
= gHiiConfigRouting
->BlockToConfig (
1175 (UINT8
*) IfrNvData
,
1181 FreePool (IfrNvData
);
1183 // Free the allocated config request string.
1185 if (AllocatedRequest
) {
1186 FreePool (ConfigRequest
);
1187 ConfigRequest
= NULL
;
1190 // Set Progress string to the original request string.
1192 if (Request
== NULL
) {
1194 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1195 *Progress
= Request
+ StrLen (Request
);
1202 This function applies changes in a driver's configuration.
1203 Input is a Configuration, which has the routing data for this
1204 driver followed by name / value configuration pairs. The driver
1205 must apply those pairs to its configurable storage. If the
1206 driver's configuration is stored in a linear block of data
1207 and the driver's name / value pairs are in <BlockConfig>
1208 format, it may use the ConfigToBlock helper function (above) to
1211 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1213 @param Configuration A null-terminated Unicode string in
1214 <ConfigString> format.
1216 @param Progress A pointer to a string filled in with the
1217 offset of the most recent '&' before the
1218 first failing name / value pair (or the
1219 beginn ing of the string if the failure
1220 is in the first name / value pair) or
1221 the terminating NULL if all was
1224 @retval EFI_SUCCESS The results have been distributed or are
1225 awaiting distribution.
1227 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1228 parts of the results that must be
1229 stored awaiting possible future
1232 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
1233 Results parameter would result
1234 in this type of error.
1236 @retval EFI_NOT_FOUND Target for the specified routing data
1242 WifiMgrDxeHiiConfigAccessRouteConfig (
1243 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1244 IN CONST EFI_STRING Configuration
,
1245 OUT EFI_STRING
*Progress
1250 WIFI_MGR_PRIVATE_DATA
*Private
;
1251 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1253 if (Configuration
== NULL
|| Progress
== NULL
) {
1254 return EFI_INVALID_PARAMETER
;
1258 *Progress
= Configuration
;
1259 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1260 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1262 if (!HiiIsConfigHdrMatch (Configuration
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1263 return EFI_NOT_FOUND
;
1266 IfrNvData
= AllocateZeroPool (BufferSize
);
1267 if (IfrNvData
== NULL
) {
1268 return EFI_OUT_OF_RESOURCES
;
1271 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1273 Status
= gHiiConfigRouting
->ConfigToBlock (
1280 if (EFI_ERROR (Status
)) {
1284 Status
= WifiMgrConvertIfrNvDataToConfigData (Private
, IfrNvData
);
1285 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1286 FreePool (IfrNvData
);
1292 This function is called to provide results data to the driver.
1293 This data consists of a unique key that is used to identify
1294 which data is either being passed back or being asked for.
1296 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1297 @param Action Specifies the type of action taken by the browser.
1298 @param QuestionId A unique value which is sent to the original
1299 exporting driver so that it can identify the type
1300 of data to expect. The format of the data tends to
1301 vary based on the opcode that generated the callback.
1302 @param Type The type of value for the question.
1303 @param Value A pointer to the data being sent to the original
1305 @param ActionRequest On return, points to the action requested by the
1308 @retval EFI_SUCCESS The callback successfully handled the action.
1309 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1310 variable and its data.
1311 @retval EFI_DEVICE_ERROR The variable could not be saved.
1312 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1318 WifiMgrDxeHiiConfigAccessCallback (
1319 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1320 IN EFI_BROWSER_ACTION Action
,
1321 IN EFI_QUESTION_ID QuestionId
,
1323 IN OUT EFI_IFR_TYPE_VALUE
*Value
,
1324 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1330 WIFI_MGR_PRIVATE_DATA
*Private
;
1331 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1332 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
1333 WIFI_MGR_NETWORK_PROFILE
*Profile
;
1334 WIFI_MGR_NETWORK_PROFILE
*ProfileToConnect
;
1335 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
1341 CHAR16
*TempPassword
;
1342 CHAR16
*ErrorMessage
;
1344 if (Action
!= EFI_BROWSER_ACTION_FORM_OPEN
&&
1345 Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
&&
1346 Action
!= EFI_BROWSER_ACTION_CHANGING
&&
1347 Action
!= EFI_BROWSER_ACTION_CHANGED
&&
1348 Action
!= EFI_BROWSER_ACTION_RETRIEVE
) {
1350 return EFI_UNSUPPORTED
;
1352 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
1353 return EFI_INVALID_PARAMETER
;
1356 Status
= EFI_SUCCESS
;
1357 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1358 if (Private
->CurrentNic
== NULL
) {
1359 return EFI_DEVICE_ERROR
;
1363 // Retrieve uncommitted data from Browser
1365 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1366 IfrNvData
= AllocateZeroPool (BufferSize
);
1367 if (IfrNvData
== NULL
) {
1368 return EFI_OUT_OF_RESOURCES
;
1370 HiiGetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*) IfrNvData
);
1372 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
1373 switch (QuestionId
) {
1377 Status
= WifiMgrShowNicList (Private
);
1380 case KEY_REFRESH_NETWORK_LIST
:
1382 if (Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1384 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1387 // Erase secrets since user has left Connection Page
1388 // Connection Page may direct to Network List Page or Eap Configuration Page,
1389 // secrets only need to be erased when head to Network List Page
1391 WifiMgrCleanProfileSecrets (Profile
);
1393 Private
->CurrentNic
->UserSelectedProfile
= NULL
;
1398 case KEY_CONNECT_ACTION
:
1400 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1403 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1406 //Enter the network connection configuration page
1407 //Recovery from restored data
1409 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SSID
), Profile
->SSId
, NULL
) == 0) {
1410 return EFI_OUT_OF_RESOURCES
;
1412 IfrNvData
->SecurityType
= Profile
->SecurityType
;
1413 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SECURITY_TYPE
),
1414 mSecurityType
[IfrNvData
->SecurityType
], NULL
) == 0) {
1415 return EFI_OUT_OF_RESOURCES
;
1418 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1420 IfrNvData
->EapAuthMethod
= Profile
->EapAuthMethod
;
1421 IfrNvData
->EapSecondAuthMethod
= Profile
->EapSecondAuthMethod
;
1422 StrCpyS (IfrNvData
->EapIdentity
, EAP_IDENTITY_SIZE
, Profile
->EapIdentity
);
1427 case KEY_ENROLLED_CERT_NAME
:
1429 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1432 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1435 //Enter the key enrollment page
1436 //For TTLS and PEAP, only CA cert needs to be cared
1438 if (Private
->FileType
== FileTypeCACert
) {
1440 if (Profile
->CACertData
!= NULL
) {
1441 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->CACertName
, NULL
);
1443 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1445 } else if (Private
->FileType
== FileTypeClientCert
) {
1447 if (Profile
->ClientCertData
!= NULL
) {
1448 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->ClientCertName
, NULL
);
1450 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1455 case KEY_ENROLLED_PRIVATE_KEY_NAME
:
1457 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1460 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1462 if (Profile
->PrivateKeyData
!= NULL
) {
1463 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), Profile
->PrivateKeyName
, NULL
);
1465 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), L
"", NULL
);
1472 } else if (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
) {
1473 switch (QuestionId
) {
1475 case KEY_CONNECT_ACTION
:
1477 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1480 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1483 //Restore User Config Data for Page recovery
1485 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1487 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1488 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1489 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1496 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1497 switch (QuestionId
) {
1499 case KEY_NETWORK_LIST
:
1502 //User triggered a scan process.
1504 Private
->CurrentNic
->OneTimeScanRequest
= TRUE
;
1507 case KEY_PASSWORD_CONNECT_NETWORK
:
1508 case KEY_EAP_PASSWORD_CONNECT_NETWORK
:
1509 case KEY_PRIVATE_KEY_PASSWORD
:
1511 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1514 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1516 if (QuestionId
== KEY_PASSWORD_CONNECT_NETWORK
) {
1517 TempPassword
= Profile
->Password
;
1518 } else if (QuestionId
== KEY_EAP_PASSWORD_CONNECT_NETWORK
) {
1519 TempPassword
= Profile
->EapPassword
;
1521 TempPassword
= Profile
->PrivateKeyPassword
;
1524 Status
= WifiMgrRecordPassword (Private
, Value
->string
, TempPassword
, PASSWORD_STORAGE_SIZE
);
1525 if (EFI_ERROR (Status
)) {
1526 DEBUG ((DEBUG_ERROR
, "[WiFi Connection Manager] Error: Failed to input password!"));
1531 // This password is not a new created password, so no need to confirm.
1533 Status
= EFI_NOT_FOUND
;
1536 case KEY_CONNECT_ACTION
:
1538 ErrorMessage
= NULL
;
1539 ProfileToConnect
= NULL
;
1541 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1544 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1546 if (Private
->CurrentNic
->ConnectState
== WifiMgrDisconnected
||
1547 Profile
!= Private
->CurrentNic
->CurrentOperateNetwork
) {
1550 // When this network is not currently connected, pend it to connect.
1552 if (Profile
->AKMSuiteSupported
&& Profile
->CipherSuiteSupported
) {
1554 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
|| Profile
->SecurityType
== SECURITY_TYPE_WPA2_PERSONAL
) {
1557 // For Open network, connect directly.
1559 ProfileToConnect
= Profile
;
1561 } else if (Profile
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1564 // For WPA/WPA2-Enterprise network, conduct eap configuration first.
1565 // Only EAP-TLS, TTLS and PEAP is supported now!
1567 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1568 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1570 if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TTLS
|| IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_PEAP
) {
1572 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1573 ProfileToConnect
= Profile
;
1574 } else if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TLS
) {
1575 ProfileToConnect
= Profile
;
1577 ErrorMessage
= L
"ERROR: Only EAP-TLS, TTLS or PEAP is supported now!";
1580 ErrorMessage
= L
"ERROR: Can't connect to this network!";
1583 ErrorMessage
= L
"ERROR: This network is not supported!";
1586 if (ErrorMessage
!= NULL
) {
1588 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1595 if (ProfileToConnect
!= NULL
) {
1597 Private
->CurrentNic
->OneTimeConnectRequest
= TRUE
;
1598 Private
->CurrentNic
->ConnectPendingNetwork
= ProfileToConnect
;
1600 } else if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
1603 // This network is currently connected, just disconnect from it.
1605 Private
->CurrentNic
->OneTimeDisconnectRequest
= TRUE
;
1606 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
1610 case KEY_ENROLL_CA_CERT_CONNECT_NETWORK
:
1612 Private
->FileType
= FileTypeCACert
;
1615 case KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK
:
1617 Private
->FileType
= FileTypeClientCert
;
1620 case KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE
:
1623 ChooseFile (NULL
, NULL
, NULL
, &FilePath
);
1625 if (FilePath
!= NULL
) {
1627 UpdatePrivateKeyFromFile(Private
, FilePath
);
1628 FreePool (FilePath
);
1632 case KEY_EAP_ENROLL_CERT_FROM_FILE
:
1635 //User will select a cert file from File Explore
1638 ChooseFile( NULL
, NULL
, NULL
, &FilePath
);
1640 if (FilePath
!= NULL
) {
1642 UpdateCAFromFile(Private
, FilePath
);
1643 FreePool (FilePath
);
1647 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1649 if (Private
->FileContext
!= NULL
&& Private
->FileContext
->FHandle
!= NULL
&&
1650 Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1653 // Read Private Key file to Buffer
1655 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1656 if (Profile
->PrivateKeyData
!= NULL
) {
1658 ZeroMem (Profile
->PrivateKeyData
, Profile
->PrivateKeyDataSize
);
1659 FreePool (Profile
->PrivateKeyData
);
1662 Status
= WifiMgrReadFileToBuffer (
1663 Private
->FileContext
,
1667 if (EFI_ERROR (Status
)) {
1669 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1671 L
"ERROR: Can't read this private key file!",
1676 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1678 Profile
->PrivateKeyData
= TempData
;
1679 Profile
->PrivateKeyDataSize
= TempDataSize
;
1680 StrCpyS(Profile
->PrivateKeyName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1682 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Private Key: %s has been enrolled! Size: %d\n",
1683 Profile
->PrivateKeyName
, Profile
->PrivateKeyDataSize
));
1688 case KEY_SAVE_CERT_TO_MEM
:
1690 if (Private
->FileContext
!= NULL
&& Private
->FileContext
->FHandle
!= NULL
&&
1691 Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1694 // Read Cert file to Buffer
1696 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1698 if (Private
->FileType
== FileTypeCACert
) {
1699 if (Profile
->CACertData
!= NULL
) {
1701 ZeroMem (Profile
->CACertData
, Profile
->CACertSize
);
1702 FreePool (Profile
->CACertData
);
1704 } else if (Private
->FileType
== FileTypeClientCert
) {
1705 if (Profile
->ClientCertData
!= NULL
) {
1707 ZeroMem (Profile
->ClientCertData
, Profile
->ClientCertSize
);
1708 FreePool (Profile
->ClientCertData
);
1714 Status
= WifiMgrReadFileToBuffer (
1715 Private
->FileContext
,
1719 if (EFI_ERROR (Status
)) {
1721 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1723 L
"ERROR: Can't read this certificate file!",
1728 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1729 if (Private
->FileType
== FileTypeCACert
) {
1731 Profile
->CACertData
= TempData
;
1732 Profile
->CACertSize
= TempDataSize
;
1733 StrCpyS(Profile
->CACertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1734 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] CA Cert: %s has been enrolled! Size: %d\n",
1735 Profile
->CACertName
, Profile
->CACertSize
));
1738 Profile
->ClientCertData
= TempData
;
1739 Profile
->ClientCertSize
= TempDataSize
;
1740 StrCpyS(Profile
->ClientCertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1741 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Client Cert: %s has been enrolled! Size: %d\n",
1742 Profile
->ClientCertName
, Profile
->ClientCertSize
));
1748 case KEY_ADD_HIDDEN_NETWORK
:
1751 // Add a Hidden Network
1753 if (StrLen (IfrNvData
->SSId
) < SSID_MIN_LEN
||
1754 Private
->HiddenNetworkCount
>= HIDDEN_NETWORK_LIST_COUNT_MAX
) {
1756 Status
= EFI_ABORTED
;
1761 // Check if this SSId is already in Hidden Network List
1763 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
1765 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
,
1766 Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1767 if (StrCmp (HiddenNetwork
->SSId
, IfrNvData
->SSId
) == 0) {
1769 Status
= EFI_ABORTED
;
1775 HiddenNetwork
= (WIFI_HIDDEN_NETWORK_DATA
*) AllocateZeroPool (sizeof (WIFI_HIDDEN_NETWORK_DATA
));
1776 if (HiddenNetwork
== NULL
) {
1778 Status
= EFI_OUT_OF_RESOURCES
;
1781 HiddenNetwork
->Signature
= WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
;
1782 StrCpyS (HiddenNetwork
->SSId
, SSID_STORAGE_SIZE
, IfrNvData
->SSId
);
1784 InsertTailList (&Private
->HiddenNetworkList
, &HiddenNetwork
->Link
);
1785 Private
->HiddenNetworkCount
++;
1787 WifiMgrRefreshHiddenList (Private
);
1790 case KEY_REMOVE_HIDDEN_NETWORK
:
1793 // Remove Hidden Networks
1795 Entry
= GetFirstNode (&Private
->HiddenNetworkList
);
1797 for (Index
= 0; Index
< Private
->HiddenNetworkCount
; Index
++) {
1798 if (IfrNvData
->HiddenNetworkList
[Index
] != 0) {
1800 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
, Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1801 Entry
= RemoveEntryList (Entry
);
1804 FreePool (HiddenNetwork
);
1806 Entry
= GetNextNode (&Private
->HiddenNetworkList
, Entry
);
1810 Private
->HiddenNetworkCount
-= RemoveCount
;
1811 WifiMgrRefreshHiddenList (Private
);
1816 if (QuestionId
>= KEY_MAC_ENTRY_BASE
&& QuestionId
< KEY_MAC_ENTRY_BASE
+ Private
->NicCount
) {
1818 // User selects a wireless NIC.
1820 Status
= WifiMgrSelectNic (Private
, QuestionId
);
1821 if (EFI_ERROR (Status
)) {
1823 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1825 L
"ERROR: Fail to operate the wireless NIC!",
1829 } else if (Private
->CurrentNic
!= NULL
) {
1830 if (QuestionId
>= KEY_AVAILABLE_NETWORK_ENTRY_BASE
&&
1831 QuestionId
<= KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Private
->CurrentNic
->MaxProfileIndex
) {
1833 Status
= WifiMgrUserSelectProfileToConnect (Private
, QuestionId
- KEY_AVAILABLE_NETWORK_ENTRY_BASE
);
1834 if (!EFI_ERROR (Status
)) {
1835 WifiMgrUpdateConnectMessage(Private
->CurrentNic
, FALSE
, NULL
);
1839 if (EFI_ERROR (Status
)) {
1841 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1843 L
"ERROR: Fail to operate this profile!",
1851 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1852 switch (QuestionId
) {
1854 case KEY_SAVE_CERT_TO_MEM
:
1855 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1857 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1860 case KEY_NO_SAVE_CERT_TO_MEM
:
1861 case KEY_NO_SAVE_PRIVATE_KEY_TO_MEM
:
1863 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1868 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1871 } else if (Action
== EFI_BROWSER_ACTION_RETRIEVE
) {
1873 switch (QuestionId
) {
1875 case KEY_REFRESH_NETWORK_LIST
:
1877 WifiMgrRefreshNetworkList (Private
, IfrNvData
);
1885 if (!EFI_ERROR (Status
)) {
1887 // Pass changed uncommitted data back to Form Browser.
1889 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1890 HiiSetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*) IfrNvData
, NULL
);
1893 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1894 FreePool (IfrNvData
);
1899 Initialize the WiFi configuration form.
1901 @param[in] Private The pointer to the global private data structure.
1903 @retval EFI_SUCCESS The configuration form is initialized.
1904 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1905 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1906 @retval Other Erros Returned Errors when installing protocols.
1910 WifiMgrDxeConfigFormInit (
1911 WIFI_MGR_PRIVATE_DATA
*Private
1916 if (Private
== NULL
) {
1917 return EFI_INVALID_PARAMETER
;
1920 Private
->ConfigAccess
.ExtractConfig
= WifiMgrDxeHiiConfigAccessExtractConfig
;
1921 Private
->ConfigAccess
.RouteConfig
= WifiMgrDxeHiiConfigAccessRouteConfig
;
1922 Private
->ConfigAccess
.Callback
= WifiMgrDxeHiiConfigAccessCallback
;
1925 // Install Device Path Protocol and Config Access protocol to driver handle.
1927 Status
= gBS
->InstallMultipleProtocolInterfaces (
1928 &Private
->DriverHandle
,
1929 &gEfiDevicePathProtocolGuid
,
1930 &mWifiMgrDxeHiiVendorDevicePath
,
1931 &gEfiHiiConfigAccessProtocolGuid
,
1932 &Private
->ConfigAccess
,
1935 if (EFI_ERROR (Status
)) {
1940 // Publish our HII data.
1942 Private
->RegisteredHandle
= HiiAddPackages (
1943 &gWifiConfigFormSetGuid
,
1944 Private
->DriverHandle
,
1945 WifiConnectionManagerDxeStrings
,
1946 WifiConnectionManagerDxeBin
,
1949 if (Private
->RegisteredHandle
== NULL
) {
1950 gBS
->UninstallMultipleProtocolInterfaces (
1951 Private
->DriverHandle
,
1952 &gEfiDevicePathProtocolGuid
,
1953 &mWifiMgrDxeHiiVendorDevicePath
,
1954 &gEfiHiiConfigAccessProtocolGuid
,
1955 &Private
->ConfigAccess
,
1958 return EFI_OUT_OF_RESOURCES
;
1961 Private
->FileContext
= AllocateZeroPool (sizeof (WIFI_MGR_FILE_CONTEXT
));
1962 if (Private
->FileContext
== NULL
) {
1963 return EFI_OUT_OF_RESOURCES
;
1970 Unload the WiFi configuration form.
1972 @param[in] Private The pointer to the global private data structure.
1974 @retval EFI_SUCCESS The configuration form is unloaded successfully.
1975 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1976 @retval Other Errors Returned Erros when uninstalling protocols.
1980 WifiMgrDxeConfigFormUnload (
1981 WIFI_MGR_PRIVATE_DATA
*Private
1986 if (Private
== NULL
) {
1987 return EFI_INVALID_PARAMETER
;
1990 if (Private
->FileContext
!= NULL
) {
1992 if (Private
->FileContext
->FHandle
!= NULL
) {
1993 Private
->FileContext
->FHandle
->Close (Private
->FileContext
->FHandle
);
1996 if (Private
->FileContext
->FileName
!= NULL
) {
1997 FreePool (Private
->FileContext
->FileName
);
1999 FreePool (Private
->FileContext
);
2002 HiiRemovePackages(Private
->RegisteredHandle
);
2004 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2005 Private
->DriverHandle
,
2006 &gEfiDevicePathProtocolGuid
,
2007 &mWifiMgrDxeHiiVendorDevicePath
,
2008 &gEfiHiiConfigAccessProtocolGuid
,
2009 &Private
->ConfigAccess
,