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
);
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
) {
490 Profile
= NET_LIST_USER_STRUCT_S (
492 WIFI_MGR_NETWORK_PROFILE
,
494 WIFI_MGR_PROFILE_SIGNATURE
496 if (ConnectedProfile
== Profile
) {
499 if (Profile
->IsAvailable
&& Profile
->CipherSuiteSupported
) {
503 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
504 if (AKMListDisplay
== NULL
) {
505 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",
527 AKMListDisplay
, CipherListDisplay
529 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
530 if (PortHelpToken
== 0) {
531 Status
= EFI_OUT_OF_RESOURCES
;
535 FreePool (AKMListDisplay
);
536 FreePool (CipherListDisplay
);
537 AKMListDisplay
= NULL
;
538 CipherListDisplay
= NULL
;
540 HiiCreateGotoOpCode (
542 FORMID_CONNECT_NETWORK
,
545 EFI_IFR_FLAG_CALLBACK
,
546 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
553 (Profile
->SecurityType
!= SECURITY_TYPE_NONE
? L
"Secured" : L
"Open "),
554 mSecurityType
[Profile
->SecurityType
],
555 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
557 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
558 if (PortTextToken
== 0) {
559 Status
= EFI_OUT_OF_RESOURCES
;
562 HiiCreateTextOpCode (
572 // Display all Unsupported available networks.
574 NET_LIST_FOR_EACH (Entry
, &Private
->CurrentNic
->ProfileList
) {
576 Profile
= NET_LIST_USER_STRUCT_S (
578 WIFI_MGR_NETWORK_PROFILE
,
580 WIFI_MGR_PROFILE_SIGNATURE
582 if (ConnectedProfile
== Profile
) {
585 if (Profile
->IsAvailable
&& !Profile
->CipherSuiteSupported
) {
589 AKMListDisplay
= WifiMgrGetStrAKMList (Profile
);
590 if (AKMListDisplay
== NULL
) {
591 Status
= EFI_OUT_OF_RESOURCES
;
594 CipherListDisplay
= WifiMgrGetStrCipherList(Profile
);
595 if (CipherListDisplay
== NULL
) {
596 Status
= EFI_OUT_OF_RESOURCES
;
600 PortPromptToken
= HiiSetString (Private
->RegisteredHandle
, 0, Profile
->SSId
, NULL
);
602 if (Profile
->AKMSuiteSupported
) {
606 L
"AKMSuite: %s CipherSuite(UnSupported): %s",
607 AKMListDisplay
, CipherListDisplay
613 L
"AKMSuite(UnSupported): %s CipherSuite(UnSupported): %s",
614 AKMListDisplay
, CipherListDisplay
617 FreePool (AKMListDisplay
);
618 FreePool (CipherListDisplay
);
619 AKMListDisplay
= NULL
;
620 CipherListDisplay
= NULL
;
622 PortHelpToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
624 HiiCreateGotoOpCode (
626 FORMID_CONNECT_NETWORK
,
629 EFI_IFR_FLAG_CALLBACK
,
630 (UINT16
) (KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Profile
->ProfileIndex
)
638 mSecurityType
[Profile
->SecurityType
],
639 RSSI_TO_SIGNAL_STRENGTH_BAR(Profile
->NetworkQuality
)
641 PortTextToken
= HiiSetString (Private
->RegisteredHandle
, 0, PortString
, NULL
);
643 HiiCreateTextOpCode (
652 Status
= HiiUpdateForm (
653 Private
->RegisteredHandle
, // HII handle
654 &gWifiConfigFormSetGuid
, // Formset GUID
655 FORMID_NETWORK_LIST
, // Form ID
656 StartOpCodeHandle
, // Label for where to insert opcodes
657 EndOpCodeHandle
// Replace data
662 gBS
->RestoreTPL (OldTpl
);
664 if (AKMListDisplay
!= NULL
) {
665 FreePool (AKMListDisplay
);
667 if (CipherListDisplay
!= NULL
) {
668 FreePool (CipherListDisplay
);
671 HiiFreeOpCodeHandle (StartOpCodeHandle
);
672 HiiFreeOpCodeHandle (EndOpCodeHandle
);
674 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Network List is Refreshed!\n"));
679 Refresh the hidden network list configured by user.
681 @param[in] Private The pointer to the global private data structure.
683 @retval EFI_SUCCESS The operation is completed successfully.
684 @retval Other Errors Returned errors when creating Opcodes or updating the
688 WifiMgrRefreshHiddenList (
689 IN WIFI_MGR_PRIVATE_DATA
*Private
695 EFI_STRING_ID StringId
;
696 VOID
*StartOpCodeHandle
;
697 VOID
*EndOpCodeHandle
;
698 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
701 if (Private
== NULL
) {
705 Status
= WifiMgrCreateOpCode (
706 LABEL_HIDDEN_NETWORK_ENTRY
,
710 if (EFI_ERROR (Status
)) {
714 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
717 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
719 HiddenNetwork
= NET_LIST_USER_STRUCT_S (
721 WIFI_HIDDEN_NETWORK_DATA
,
723 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
725 StringId
= HiiSetString (Private
->RegisteredHandle
, 0, HiddenNetwork
->SSId
, NULL
);
727 HiiCreateCheckBoxOpCode (
729 (EFI_QUESTION_ID
) (KEY_HIDDEN_NETWORK_ENTRY_BASE
+ Index
),
731 (UINT16
) (HIDDEN_NETWORK_LIST_VAR_OFFSET
+ Index
),
741 Status
= HiiUpdateForm (
742 Private
->RegisteredHandle
, // HII handle
743 &gWifiConfigFormSetGuid
, // Formset GUID
744 FORMID_HIDDEN_NETWORK_LIST
, // Form ID
745 StartOpCodeHandle
, // Label for where to insert opcodes
746 EndOpCodeHandle
// Replace data
749 gBS
->RestoreTPL (OldTpl
);
750 HiiFreeOpCodeHandle (StartOpCodeHandle
);
751 HiiFreeOpCodeHandle (EndOpCodeHandle
);
757 Callback function for user to select a Nic.
759 @param[in] Private The pointer to the global private data structure.
760 @param[in] KeyValue The key value received from HII input.
762 @retval EFI_NOT_FOUND The corresponding Nic is not found.
763 @retval EFI_SUCCESS The operation is completed successfully.
768 IN WIFI_MGR_PRIVATE_DATA
*Private
,
769 IN EFI_QUESTION_ID KeyValue
772 WIFI_MGR_DEVICE_DATA
*Nic
;
774 CHAR16 MacString
[WIFI_MGR_MAX_MAC_STRING_LEN
];
776 NicIndex
= KeyValue
- KEY_MAC_ENTRY_BASE
;
777 Nic
= WifiMgrGetNicByIndex (Private
, NicIndex
);
779 return EFI_NOT_FOUND
;
781 Private
->CurrentNic
= Nic
;
783 WifiMgrMacAddrToStr (&Nic
->MacAddress
, sizeof (MacString
), MacString
);
784 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN(STR_MAC_ADDRESS
), MacString
, NULL
);
789 Restore the NV data to be default.
791 @param[in] Private The pointer to the global private data structure.
792 @param[out] IfrNvData The IFR NV data.
796 WifiMgrCleanUserInput (
797 IN WIFI_MGR_PRIVATE_DATA
*Private
800 Private
->SecurityType
= SECURITY_TYPE_NONE
;
801 Private
->EapAuthMethod
= EAP_AUTH_METHOD_TTLS
;
802 Private
->EapSecondAuthMethod
= EAP_SEAUTH_METHOD_MSCHAPV2
;
803 Private
->FileType
= FileTypeMax
;
807 UI handle function when user select a network to connect.
809 @param[in] Private The pointer to the global private data structure.
810 @param[in] ProfileIndex The profile index user selected to connect.
812 @retval EFI_INVALID_PARAMETER Nic is null.
813 @retval EFI_NOT_FOUND Profile could not be found.
814 @retval EFI_SUCCESS The operation is completed successfully.
818 WifiMgrUserSelectProfileToConnect(
819 IN WIFI_MGR_PRIVATE_DATA
*Private
,
820 IN UINT32 ProfileIndex
823 WIFI_MGR_NETWORK_PROFILE
*Profile
;
824 WIFI_MGR_DEVICE_DATA
*Nic
;
826 Nic
= Private
->CurrentNic
;
828 return EFI_INVALID_PARAMETER
;
832 //Initialize the connection page
834 WifiMgrCleanUserInput(Private
);
836 Profile
= WifiMgrGetProfileByProfileIndex (ProfileIndex
, &Nic
->ProfileList
);
837 if (Profile
== NULL
) {
838 return EFI_NOT_FOUND
;
840 Private
->CurrentNic
->UserSelectedProfile
= Profile
;
846 Record password from a HII input string.
848 @param[in] Private The pointer to the global private data structure.
849 @param[in] StringId The QuestionId received from HII input.
850 @param[in] StringBuffer The unicode string buffer to store password.
851 @param[in] StringBufferLen The len of unicode string buffer.
853 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
854 @retval EFI_NOT_FOUND The password string is not found or invalid.
855 @retval EFI_SUCCESS The operation is completed successfully.
859 WifiMgrRecordPassword (
860 IN WIFI_MGR_PRIVATE_DATA
*Private
,
861 IN EFI_STRING_ID StringId
,
862 IN CHAR16
*StringBuffer
,
863 IN UINTN StringBufferLen
868 if (StringId
== 0 || StringBuffer
== NULL
|| StringBufferLen
<= 0) {
869 return EFI_INVALID_PARAMETER
;
872 Password
= HiiGetString (Private
->RegisteredHandle
, StringId
, NULL
);
873 if (Password
== NULL
) {
874 return EFI_NOT_FOUND
;
876 if (StrLen (Password
) > StringBufferLen
) {
878 return EFI_NOT_FOUND
;
880 StrnCpyS (StringBuffer
, StringBufferLen
, Password
, StrLen (Password
));
881 ZeroMem (Password
, (StrLen (Password
) + 1) * sizeof (CHAR16
));
885 // Clean password in string package
887 HiiSetString (Private
->RegisteredHandle
, StringId
, L
"", NULL
);
892 Update connection message on connect configuration page, and trigger related form refresh.
894 @param[in] Nic The related Nic for updating message.
895 @param[in] ConnectStateChanged The tag to tell if the connection state has been changed, only
896 when the connection changes from "Connected" or "Disconnecting"
897 to "Disconnected", or from "Disconnected" or "Connecting" to
898 "Connected", this tag can be set as TRUE.
899 @param[in] ConnectStatusMessage The message to show on connected status bar, if NULL, will
904 WifiMgrUpdateConnectMessage (
905 IN WIFI_MGR_DEVICE_DATA
*Nic
,
906 IN BOOLEAN ConnectStateChanged
,
907 IN EFI_STRING ConnectStatusMessage
910 CHAR16 ConnectStatusStr
[WIFI_STR_MAX_SIZE
];
911 WIFI_MGR_PRIVATE_DATA
*Private
;
913 Private
= Nic
->Private
;
914 if (Private
== NULL
|| Private
->CurrentNic
!= Nic
) {
919 // Update Connection Status Bar
921 if (ConnectStatusMessage
!= NULL
) {
922 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusMessage
, NULL
);
924 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
926 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Connected to %s",
927 Nic
->CurrentOperateNetwork
->SSId
);
928 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
929 } else if (Nic
->ConnectState
== WifiMgrDisconnected
) {
931 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), L
"Disconnected", NULL
);
932 } else if (Nic
->ConnectState
== WifiMgrConnectingToAp
) {
934 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Connecting to %s ...",
935 Nic
->CurrentOperateNetwork
->SSId
);
936 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
937 } else if (Nic
->ConnectState
== WifiMgrDisconnectingToAp
) {
939 UnicodeSPrint (ConnectStatusStr
, sizeof (ConnectStatusStr
), L
"Disconnecting from %s ...",
940 Nic
->CurrentOperateNetwork
->SSId
);
941 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_STATUS
), ConnectStatusStr
, NULL
);
948 // Update Connect Button
950 if (Nic
->ConnectState
== WifiMgrConnectedToAp
&& Nic
->UserSelectedProfile
== Nic
->CurrentOperateNetwork
) {
952 HiiSetString (Private
->RegisteredHandle
,
953 STRING_TOKEN (STR_CONNECT_NOW
), L
"Disconnect from this Network", NULL
);
955 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECT_NOW
), L
"Connect to this Network", NULL
);
957 gBS
->SignalEvent (Private
->ConnectFormRefreshEvent
);
960 // Update Main Page and Network List
962 if (ConnectStateChanged
) {
964 if (Nic
->ConnectState
== WifiMgrConnectedToAp
) {
966 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Connected to", NULL
);
967 HiiSetString (Private
->RegisteredHandle
,
968 STRING_TOKEN (STR_CONNECTED_SSID
), Nic
->CurrentOperateNetwork
->SSId
, NULL
);
970 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTION_INFO
), L
"Disconnected", NULL
);
971 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_CONNECTED_SSID
), L
"", NULL
);
974 gBS
->SignalEvent (Private
->NetworkListRefreshEvent
);
975 gBS
->SignalEvent (Private
->MainPageRefreshEvent
);
980 Convert the driver configuration data into the IFR data.
982 @param[in] Private The pointer to the global private data structure.
983 @param[out] IfrNvData The IFR NV data.
985 @retval EFI_SUCCESS The operation is completed successfully.
989 WifiMgrConvertConfigDataToIfrNvData (
990 IN WIFI_MGR_PRIVATE_DATA
*Private
,
991 OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
995 // Private shouldn't be NULL here, assert if Private is NULL.
997 ASSERT (Private
!= NULL
);
999 if (Private
->CurrentNic
!= NULL
) {
1000 IfrNvData
->ProfileCount
= Private
->CurrentNic
->AvailableCount
;
1002 IfrNvData
->ProfileCount
= 0;
1009 Convert the IFR data into the driver configuration data.
1011 @param[in] Private The pointer to the global private data structure.
1012 @param[in, out] IfrNvData The IFR NV data.
1014 @retval EFI_SUCCESS The operation is completed successfully.
1018 WifiMgrConvertIfrNvDataToConfigData (
1019 IN WIFI_MGR_PRIVATE_DATA
*Private
,
1020 IN OUT WIFI_MANAGER_IFR_NVDATA
*IfrNvData
1027 This function allows the caller to request the current
1028 configuration for one or more named elements. The resulting
1029 string is in <ConfigAltResp> format. Any and all alternative
1030 configuration strings shall also be appended to the end of the
1031 current configuration string. If they are, they must appear
1032 after the current configuration. They must contain the same
1033 routing (GUID, NAME, PATH) as the current configuration string.
1034 They must have an additional description indicating the type of
1035 alternative configuration the string represents,
1036 "ALTCFG=<StringToken>". That <StringToken> (when
1037 converted from Hex UNICODE to binary) is a reference to a
1038 string in the associated string pack.
1040 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1042 @param Request A null-terminated Unicode string in
1043 <ConfigRequest> format. Note that this
1044 includes the routing information as well as
1045 the configurable name / value pairs. It is
1046 invalid for this string to be in
1047 <MultiConfigRequest> format.
1048 If a NULL is passed in for the Request field,
1049 all of the settings being abstracted by this function
1050 will be returned in the Results field. In addition,
1051 if a ConfigHdr is passed in with no request elements,
1052 all of the settings being abstracted for that particular
1053 ConfigHdr reference will be returned in the Results Field.
1055 @param Progress On return, points to a character in the
1056 Request string. Points to the string's null
1057 terminator if request was successful. Points
1058 to the most recent "&" before the first
1059 failing name / value pair (or the beginning
1060 of the string if the failure is in the first
1061 name / value pair) if the request was not
1064 @param Results A null-terminated Unicode string in
1065 <MultiConfigAltResp> format which has all values
1066 filled in for the names in the Request string.
1067 String to be allocated by the called function.
1069 @retval EFI_SUCCESS The Results string is filled with the
1070 values corresponding to all requested
1073 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1074 parts of the results that must be
1075 stored awaiting possible future
1078 @retval EFI_NOT_FOUND Routing data doesn't match any
1079 known driver. Progress set to the
1080 first character in the routing header.
1081 Note: There is no requirement that the
1082 driver validate the routing data. It
1083 must skip the <ConfigHdr> in order to
1086 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
1087 to most recent "&" before the
1088 error or the beginning of the
1091 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
1092 to the & before the name in
1098 WifiMgrDxeHiiConfigAccessExtractConfig (
1099 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1100 IN CONST EFI_STRING Request
,
1101 OUT EFI_STRING
*Progress
,
1102 OUT EFI_STRING
*Results
1105 WIFI_MGR_PRIVATE_DATA
*Private
;
1106 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1107 EFI_STRING ConfigRequestHdr
;
1108 EFI_STRING ConfigRequest
;
1110 BOOLEAN AllocatedRequest
;
1114 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
1115 return EFI_INVALID_PARAMETER
;
1118 *Progress
= Request
;
1119 if ((Request
!= NULL
) &&
1120 !HiiIsConfigHdrMatch (Request
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1121 return EFI_NOT_FOUND
;
1124 ConfigRequestHdr
= NULL
;
1125 ConfigRequest
= NULL
;
1126 AllocatedRequest
= FALSE
;
1129 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1131 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1132 IfrNvData
= AllocateZeroPool (BufferSize
);
1133 if (IfrNvData
== NULL
) {
1134 return EFI_OUT_OF_RESOURCES
;
1137 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1139 ConfigRequest
= Request
;
1140 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1142 // Request has no request element, construct full request string.
1143 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1144 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
1146 ConfigRequestHdr
= HiiConstructConfigHdr (
1147 &gWifiConfigFormSetGuid
,
1149 Private
->DriverHandle
);
1150 if (ConfigRequestHdr
== NULL
) {
1151 FreePool (IfrNvData
);
1152 return EFI_OUT_OF_RESOURCES
;
1155 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1156 ConfigRequest
= AllocateZeroPool (Size
);
1157 if (ConfigRequest
== NULL
) {
1159 FreePool (IfrNvData
);
1160 FreePool (ConfigRequestHdr
);
1161 return EFI_OUT_OF_RESOURCES
;
1164 AllocatedRequest
= TRUE
;
1168 L
"%s&OFFSET=0&WIDTH=%016LX",
1172 FreePool (ConfigRequestHdr
);
1176 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1178 Status
= gHiiConfigRouting
->BlockToConfig (
1181 (UINT8
*) IfrNvData
,
1187 FreePool (IfrNvData
);
1189 // Free the allocated config request string.
1191 if (AllocatedRequest
) {
1192 FreePool (ConfigRequest
);
1193 ConfigRequest
= NULL
;
1196 // Set Progress string to the original request string.
1198 if (Request
== NULL
) {
1200 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1201 *Progress
= Request
+ StrLen (Request
);
1208 This function applies changes in a driver's configuration.
1209 Input is a Configuration, which has the routing data for this
1210 driver followed by name / value configuration pairs. The driver
1211 must apply those pairs to its configurable storage. If the
1212 driver's configuration is stored in a linear block of data
1213 and the driver's name / value pairs are in <BlockConfig>
1214 format, it may use the ConfigToBlock helper function (above) to
1217 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1219 @param Configuration A null-terminated Unicode string in
1220 <ConfigString> format.
1222 @param Progress A pointer to a string filled in with the
1223 offset of the most recent '&' before the
1224 first failing name / value pair (or the
1225 beginn ing of the string if the failure
1226 is in the first name / value pair) or
1227 the terminating NULL if all was
1230 @retval EFI_SUCCESS The results have been distributed or are
1231 awaiting distribution.
1233 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1234 parts of the results that must be
1235 stored awaiting possible future
1238 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
1239 Results parameter would result
1240 in this type of error.
1242 @retval EFI_NOT_FOUND Target for the specified routing data
1248 WifiMgrDxeHiiConfigAccessRouteConfig (
1249 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1250 IN CONST EFI_STRING Configuration
,
1251 OUT EFI_STRING
*Progress
1256 WIFI_MGR_PRIVATE_DATA
*Private
;
1257 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1259 if (Configuration
== NULL
|| Progress
== NULL
) {
1260 return EFI_INVALID_PARAMETER
;
1264 *Progress
= Configuration
;
1265 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1266 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1268 if (!HiiIsConfigHdrMatch (Configuration
, &gWifiConfigFormSetGuid
, mVendorStorageName
)) {
1269 return EFI_NOT_FOUND
;
1272 IfrNvData
= AllocateZeroPool (BufferSize
);
1273 if (IfrNvData
== NULL
) {
1274 return EFI_OUT_OF_RESOURCES
;
1277 WifiMgrConvertConfigDataToIfrNvData (Private
, IfrNvData
);
1279 Status
= gHiiConfigRouting
->ConfigToBlock (
1286 if (EFI_ERROR (Status
)) {
1290 Status
= WifiMgrConvertIfrNvDataToConfigData (Private
, IfrNvData
);
1291 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1292 FreePool (IfrNvData
);
1298 This function is called to provide results data to the driver.
1299 This data consists of a unique key that is used to identify
1300 which data is either being passed back or being asked for.
1302 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1303 @param Action Specifies the type of action taken by the browser.
1304 @param QuestionId A unique value which is sent to the original
1305 exporting driver so that it can identify the type
1306 of data to expect. The format of the data tends to
1307 vary based on the opcode that generated the callback.
1308 @param Type The type of value for the question.
1309 @param Value A pointer to the data being sent to the original
1311 @param ActionRequest On return, points to the action requested by the
1314 @retval EFI_SUCCESS The callback successfully handled the action.
1315 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1316 variable and its data.
1317 @retval EFI_DEVICE_ERROR The variable could not be saved.
1318 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1324 WifiMgrDxeHiiConfigAccessCallback (
1325 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1326 IN EFI_BROWSER_ACTION Action
,
1327 IN EFI_QUESTION_ID QuestionId
,
1329 IN OUT EFI_IFR_TYPE_VALUE
*Value
,
1330 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1336 WIFI_MGR_PRIVATE_DATA
*Private
;
1337 WIFI_MANAGER_IFR_NVDATA
*IfrNvData
;
1338 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
1339 WIFI_MGR_NETWORK_PROFILE
*Profile
;
1340 WIFI_MGR_NETWORK_PROFILE
*ProfileToConnect
;
1341 WIFI_HIDDEN_NETWORK_DATA
*HiddenNetwork
;
1347 CHAR16
*TempPassword
;
1348 CHAR16
*ErrorMessage
;
1350 if (Action
!= EFI_BROWSER_ACTION_FORM_OPEN
&&
1351 Action
!= EFI_BROWSER_ACTION_FORM_CLOSE
&&
1352 Action
!= EFI_BROWSER_ACTION_CHANGING
&&
1353 Action
!= EFI_BROWSER_ACTION_CHANGED
&&
1354 Action
!= EFI_BROWSER_ACTION_RETRIEVE
) {
1356 return EFI_UNSUPPORTED
;
1358 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
1359 return EFI_INVALID_PARAMETER
;
1362 Status
= EFI_SUCCESS
;
1363 Private
= WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This
);
1364 if (Private
->CurrentNic
== NULL
) {
1365 return EFI_DEVICE_ERROR
;
1369 // Retrieve uncommitted data from Browser
1371 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1372 IfrNvData
= AllocateZeroPool (BufferSize
);
1373 if (IfrNvData
== NULL
) {
1374 return EFI_OUT_OF_RESOURCES
;
1376 HiiGetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*) IfrNvData
);
1378 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
1379 switch (QuestionId
) {
1383 Status
= WifiMgrShowNicList (Private
);
1386 case KEY_REFRESH_NETWORK_LIST
:
1388 if (Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1390 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1393 // Erase secrets since user has left Connection Page
1394 // Connection Page may direct to Network List Page or Eap Configuration Page,
1395 // secrets only need to be erased when head to Network List Page
1397 WifiMgrCleanProfileSecrets (Profile
);
1399 Private
->CurrentNic
->UserSelectedProfile
= NULL
;
1404 case KEY_CONNECT_ACTION
:
1406 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1409 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1412 //Enter the network connection configuration page
1413 //Recovery from restored data
1415 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SSID
), Profile
->SSId
, NULL
) == 0) {
1416 return EFI_OUT_OF_RESOURCES
;
1418 IfrNvData
->SecurityType
= Profile
->SecurityType
;
1419 if (HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_SECURITY_TYPE
),
1420 mSecurityType
[IfrNvData
->SecurityType
], NULL
) == 0) {
1421 return EFI_OUT_OF_RESOURCES
;
1424 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1426 IfrNvData
->EapAuthMethod
= Profile
->EapAuthMethod
;
1427 IfrNvData
->EapSecondAuthMethod
= Profile
->EapSecondAuthMethod
;
1428 StrCpyS (IfrNvData
->EapIdentity
, EAP_IDENTITY_SIZE
, Profile
->EapIdentity
);
1433 case KEY_ENROLLED_CERT_NAME
:
1435 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1438 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1441 //Enter the key enrollment page
1442 //For TTLS and PEAP, only CA cert needs to be cared
1444 if (Private
->FileType
== FileTypeCACert
) {
1446 if (Profile
->CACertData
!= NULL
) {
1447 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->CACertName
, NULL
);
1449 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1451 } else if (Private
->FileType
== FileTypeClientCert
) {
1453 if (Profile
->ClientCertData
!= NULL
) {
1454 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), Profile
->ClientCertName
, NULL
);
1456 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME
), L
"", NULL
);
1461 case KEY_ENROLLED_PRIVATE_KEY_NAME
:
1463 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1466 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1468 if (Profile
->PrivateKeyData
!= NULL
) {
1469 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), Profile
->PrivateKeyName
, NULL
);
1471 HiiSetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME
), L
"", NULL
);
1478 } else if (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
) {
1479 switch (QuestionId
) {
1481 case KEY_CONNECT_ACTION
:
1483 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1486 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1489 //Restore User Config Data for Page recovery
1491 if (IfrNvData
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1493 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1494 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1495 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1502 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1503 switch (QuestionId
) {
1505 case KEY_NETWORK_LIST
:
1508 //User triggered a scan process.
1510 Private
->CurrentNic
->OneTimeScanRequest
= TRUE
;
1513 case KEY_PASSWORD_CONNECT_NETWORK
:
1514 case KEY_EAP_PASSWORD_CONNECT_NETWORK
:
1515 case KEY_PRIVATE_KEY_PASSWORD
:
1517 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1520 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1522 if (QuestionId
== KEY_PASSWORD_CONNECT_NETWORK
) {
1523 TempPassword
= Profile
->Password
;
1524 } else if (QuestionId
== KEY_EAP_PASSWORD_CONNECT_NETWORK
) {
1525 TempPassword
= Profile
->EapPassword
;
1527 TempPassword
= Profile
->PrivateKeyPassword
;
1530 Status
= WifiMgrRecordPassword (Private
, Value
->string
, TempPassword
, PASSWORD_STORAGE_SIZE
);
1531 if (EFI_ERROR (Status
)) {
1532 DEBUG ((DEBUG_ERROR
, "[WiFi Connection Manager] Error: Failed to input password!"));
1537 // This password is not a new created password, so no need to confirm.
1539 Status
= EFI_NOT_FOUND
;
1542 case KEY_CONNECT_ACTION
:
1544 ErrorMessage
= NULL
;
1545 ProfileToConnect
= NULL
;
1547 if (Private
->CurrentNic
->UserSelectedProfile
== NULL
) {
1550 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1552 if (Private
->CurrentNic
->ConnectState
== WifiMgrDisconnected
||
1553 Profile
!= Private
->CurrentNic
->CurrentOperateNetwork
) {
1556 // When this network is not currently connected, pend it to connect.
1558 if (Profile
->AKMSuiteSupported
&& Profile
->CipherSuiteSupported
) {
1560 if (Profile
->SecurityType
== SECURITY_TYPE_NONE
|| Profile
->SecurityType
== SECURITY_TYPE_WPA2_PERSONAL
) {
1563 // For Open network, connect directly.
1565 ProfileToConnect
= Profile
;
1567 } else if (Profile
->SecurityType
== SECURITY_TYPE_WPA2_ENTERPRISE
) {
1570 // For WPA/WPA2-Enterprise network, conduct eap configuration first.
1571 // Only EAP-TLS, TTLS and PEAP is supported now!
1573 Profile
->EapAuthMethod
= IfrNvData
->EapAuthMethod
;
1574 StrCpyS (Profile
->EapIdentity
, EAP_IDENTITY_SIZE
, IfrNvData
->EapIdentity
);
1576 if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TTLS
|| IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_PEAP
) {
1578 Profile
->EapSecondAuthMethod
= IfrNvData
->EapSecondAuthMethod
;
1579 ProfileToConnect
= Profile
;
1580 } else if (IfrNvData
->EapAuthMethod
== EAP_AUTH_METHOD_TLS
) {
1581 ProfileToConnect
= Profile
;
1583 ErrorMessage
= L
"ERROR: Only EAP-TLS, TTLS or PEAP is supported now!";
1586 ErrorMessage
= L
"ERROR: Can't connect to this network!";
1589 ErrorMessage
= L
"ERROR: This network is not supported!";
1592 if (ErrorMessage
!= NULL
) {
1594 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1601 if (ProfileToConnect
!= NULL
) {
1603 Private
->CurrentNic
->OneTimeConnectRequest
= TRUE
;
1604 Private
->CurrentNic
->ConnectPendingNetwork
= ProfileToConnect
;
1606 } else if (Private
->CurrentNic
->ConnectState
== WifiMgrConnectedToAp
) {
1609 // This network is currently connected, just disconnect from it.
1611 Private
->CurrentNic
->OneTimeDisconnectRequest
= TRUE
;
1612 Private
->CurrentNic
->HasDisconnectPendingNetwork
= TRUE
;
1616 case KEY_ENROLL_CA_CERT_CONNECT_NETWORK
:
1618 Private
->FileType
= FileTypeCACert
;
1621 case KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK
:
1623 Private
->FileType
= FileTypeClientCert
;
1626 case KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE
:
1629 ChooseFile (NULL
, NULL
, NULL
, &FilePath
);
1631 if (FilePath
!= NULL
) {
1633 UpdatePrivateKeyFromFile(Private
, FilePath
);
1634 FreePool (FilePath
);
1638 case KEY_EAP_ENROLL_CERT_FROM_FILE
:
1641 //User will select a cert file from File Explore
1644 ChooseFile( NULL
, NULL
, NULL
, &FilePath
);
1646 if (FilePath
!= NULL
) {
1648 UpdateCAFromFile(Private
, FilePath
);
1649 FreePool (FilePath
);
1653 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1655 if (Private
->FileContext
!= NULL
&& Private
->FileContext
->FHandle
!= NULL
&&
1656 Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1659 // Read Private Key file to Buffer
1661 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1662 if (Profile
->PrivateKeyData
!= NULL
) {
1664 ZeroMem (Profile
->PrivateKeyData
, Profile
->PrivateKeyDataSize
);
1665 FreePool (Profile
->PrivateKeyData
);
1666 Profile
->PrivateKeyData
= NULL
;
1669 Status
= WifiMgrReadFileToBuffer (
1670 Private
->FileContext
,
1674 if (EFI_ERROR (Status
)) {
1676 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1678 L
"ERROR: Can't read this private key file!",
1683 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1685 Profile
->PrivateKeyData
= TempData
;
1686 Profile
->PrivateKeyDataSize
= TempDataSize
;
1687 StrCpyS(Profile
->PrivateKeyName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1689 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Private Key: %s has been enrolled! Size: %d\n",
1690 Profile
->PrivateKeyName
, Profile
->PrivateKeyDataSize
));
1695 case KEY_SAVE_CERT_TO_MEM
:
1697 if (Private
->FileContext
!= NULL
&& Private
->FileContext
->FHandle
!= NULL
&&
1698 Private
->CurrentNic
->UserSelectedProfile
!= NULL
) {
1701 // Read Cert file to Buffer
1703 Profile
= Private
->CurrentNic
->UserSelectedProfile
;
1705 if (Private
->FileType
== FileTypeCACert
) {
1706 if (Profile
->CACertData
!= NULL
) {
1708 ZeroMem (Profile
->CACertData
, Profile
->CACertSize
);
1709 FreePool (Profile
->CACertData
);
1710 Profile
->CACertData
= NULL
;
1712 } else if (Private
->FileType
== FileTypeClientCert
) {
1713 if (Profile
->ClientCertData
!= NULL
) {
1715 ZeroMem (Profile
->ClientCertData
, Profile
->ClientCertSize
);
1716 FreePool (Profile
->ClientCertData
);
1717 Profile
->ClientCertData
= NULL
;
1723 Status
= WifiMgrReadFileToBuffer (
1724 Private
->FileContext
,
1728 if (EFI_ERROR (Status
)) {
1730 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1732 L
"ERROR: Can't read this certificate file!",
1737 ASSERT (Private
->FileContext
->FileName
!= NULL
);
1738 if (Private
->FileType
== FileTypeCACert
) {
1740 Profile
->CACertData
= TempData
;
1741 Profile
->CACertSize
= TempDataSize
;
1742 StrCpyS(Profile
->CACertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1743 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] CA Cert: %s has been enrolled! Size: %d\n",
1744 Profile
->CACertName
, Profile
->CACertSize
));
1747 Profile
->ClientCertData
= TempData
;
1748 Profile
->ClientCertSize
= TempDataSize
;
1749 StrCpyS(Profile
->ClientCertName
, WIFI_FILENAME_STR_MAX_SIZE
, Private
->FileContext
->FileName
);
1750 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Client Cert: %s has been enrolled! Size: %d\n",
1751 Profile
->ClientCertName
, Profile
->ClientCertSize
));
1757 case KEY_ADD_HIDDEN_NETWORK
:
1760 // Add a Hidden Network
1762 if (StrLen (IfrNvData
->SSId
) < SSID_MIN_LEN
||
1763 Private
->HiddenNetworkCount
>= HIDDEN_NETWORK_LIST_COUNT_MAX
) {
1765 Status
= EFI_ABORTED
;
1770 // Check if this SSId is already in Hidden Network List
1772 NET_LIST_FOR_EACH (Entry
, &Private
->HiddenNetworkList
) {
1774 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
,
1775 Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1776 if (StrCmp (HiddenNetwork
->SSId
, IfrNvData
->SSId
) == 0) {
1778 Status
= EFI_ABORTED
;
1784 HiddenNetwork
= (WIFI_HIDDEN_NETWORK_DATA
*) AllocateZeroPool (sizeof (WIFI_HIDDEN_NETWORK_DATA
));
1785 if (HiddenNetwork
== NULL
) {
1787 Status
= EFI_OUT_OF_RESOURCES
;
1790 HiddenNetwork
->Signature
= WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
;
1791 StrCpyS (HiddenNetwork
->SSId
, SSID_STORAGE_SIZE
, IfrNvData
->SSId
);
1793 InsertTailList (&Private
->HiddenNetworkList
, &HiddenNetwork
->Link
);
1794 Private
->HiddenNetworkCount
++;
1796 WifiMgrRefreshHiddenList (Private
);
1799 case KEY_REMOVE_HIDDEN_NETWORK
:
1802 // Remove Hidden Networks
1804 Entry
= GetFirstNode (&Private
->HiddenNetworkList
);
1806 for (Index
= 0; Index
< Private
->HiddenNetworkCount
; Index
++) {
1807 if (IfrNvData
->HiddenNetworkList
[Index
] != 0) {
1809 HiddenNetwork
= NET_LIST_USER_STRUCT_S (Entry
, WIFI_HIDDEN_NETWORK_DATA
, Link
, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
);
1810 Entry
= RemoveEntryList (Entry
);
1813 FreePool (HiddenNetwork
);
1815 Entry
= GetNextNode (&Private
->HiddenNetworkList
, Entry
);
1819 Private
->HiddenNetworkCount
-= RemoveCount
;
1820 WifiMgrRefreshHiddenList (Private
);
1825 if (QuestionId
>= KEY_MAC_ENTRY_BASE
&& QuestionId
< KEY_MAC_ENTRY_BASE
+ Private
->NicCount
) {
1827 // User selects a wireless NIC.
1829 Status
= WifiMgrSelectNic (Private
, QuestionId
);
1830 if (EFI_ERROR (Status
)) {
1832 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1834 L
"ERROR: Fail to operate the wireless NIC!",
1838 } else if (Private
->CurrentNic
!= NULL
) {
1839 if (QuestionId
>= KEY_AVAILABLE_NETWORK_ENTRY_BASE
&&
1840 QuestionId
<= KEY_AVAILABLE_NETWORK_ENTRY_BASE
+ Private
->CurrentNic
->MaxProfileIndex
) {
1842 Status
= WifiMgrUserSelectProfileToConnect (Private
, QuestionId
- KEY_AVAILABLE_NETWORK_ENTRY_BASE
);
1843 if (!EFI_ERROR (Status
)) {
1844 WifiMgrUpdateConnectMessage(Private
->CurrentNic
, FALSE
, NULL
);
1848 if (EFI_ERROR (Status
)) {
1850 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1852 L
"ERROR: Fail to operate this profile!",
1860 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1861 switch (QuestionId
) {
1863 case KEY_SAVE_CERT_TO_MEM
:
1864 case KEY_SAVE_PRIVATE_KEY_TO_MEM
:
1866 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
1869 case KEY_NO_SAVE_CERT_TO_MEM
:
1870 case KEY_NO_SAVE_PRIVATE_KEY_TO_MEM
:
1872 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT
;
1877 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
1880 } else if (Action
== EFI_BROWSER_ACTION_RETRIEVE
) {
1882 switch (QuestionId
) {
1884 case KEY_REFRESH_NETWORK_LIST
:
1886 WifiMgrRefreshNetworkList (Private
, IfrNvData
);
1894 if (!EFI_ERROR (Status
)) {
1896 // Pass changed uncommitted data back to Form Browser.
1898 BufferSize
= sizeof (WIFI_MANAGER_IFR_NVDATA
);
1899 HiiSetBrowserData (&gWifiConfigFormSetGuid
, mVendorStorageName
, BufferSize
, (UINT8
*) IfrNvData
, NULL
);
1902 ZeroMem (IfrNvData
, sizeof (WIFI_MANAGER_IFR_NVDATA
));
1903 FreePool (IfrNvData
);
1908 Initialize the WiFi configuration form.
1910 @param[in] Private The pointer to the global private data structure.
1912 @retval EFI_SUCCESS The configuration form is initialized.
1913 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1914 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1915 @retval Other Erros Returned Errors when installing protocols.
1919 WifiMgrDxeConfigFormInit (
1920 WIFI_MGR_PRIVATE_DATA
*Private
1925 if (Private
== NULL
) {
1926 return EFI_INVALID_PARAMETER
;
1929 Private
->ConfigAccess
.ExtractConfig
= WifiMgrDxeHiiConfigAccessExtractConfig
;
1930 Private
->ConfigAccess
.RouteConfig
= WifiMgrDxeHiiConfigAccessRouteConfig
;
1931 Private
->ConfigAccess
.Callback
= WifiMgrDxeHiiConfigAccessCallback
;
1934 // Install Device Path Protocol and Config Access protocol to driver handle.
1936 Status
= gBS
->InstallMultipleProtocolInterfaces (
1937 &Private
->DriverHandle
,
1938 &gEfiDevicePathProtocolGuid
,
1939 &mWifiMgrDxeHiiVendorDevicePath
,
1940 &gEfiHiiConfigAccessProtocolGuid
,
1941 &Private
->ConfigAccess
,
1944 if (EFI_ERROR (Status
)) {
1949 // Publish our HII data.
1951 Private
->RegisteredHandle
= HiiAddPackages (
1952 &gWifiConfigFormSetGuid
,
1953 Private
->DriverHandle
,
1954 WifiConnectionManagerDxeStrings
,
1955 WifiConnectionManagerDxeBin
,
1958 if (Private
->RegisteredHandle
== NULL
) {
1959 gBS
->UninstallMultipleProtocolInterfaces (
1960 Private
->DriverHandle
,
1961 &gEfiDevicePathProtocolGuid
,
1962 &mWifiMgrDxeHiiVendorDevicePath
,
1963 &gEfiHiiConfigAccessProtocolGuid
,
1964 &Private
->ConfigAccess
,
1967 return EFI_OUT_OF_RESOURCES
;
1970 Private
->FileContext
= AllocateZeroPool (sizeof (WIFI_MGR_FILE_CONTEXT
));
1971 if (Private
->FileContext
== NULL
) {
1972 return EFI_OUT_OF_RESOURCES
;
1979 Unload the WiFi configuration form.
1981 @param[in] Private The pointer to the global private data structure.
1983 @retval EFI_SUCCESS The configuration form is unloaded successfully.
1984 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1985 @retval Other Errors Returned Erros when uninstalling protocols.
1989 WifiMgrDxeConfigFormUnload (
1990 WIFI_MGR_PRIVATE_DATA
*Private
1995 if (Private
== NULL
) {
1996 return EFI_INVALID_PARAMETER
;
1999 if (Private
->FileContext
!= NULL
) {
2001 if (Private
->FileContext
->FHandle
!= NULL
) {
2002 Private
->FileContext
->FHandle
->Close (Private
->FileContext
->FHandle
);
2005 if (Private
->FileContext
->FileName
!= NULL
) {
2006 FreePool (Private
->FileContext
->FileName
);
2008 FreePool (Private
->FileContext
);
2011 HiiRemovePackages(Private
->RegisteredHandle
);
2013 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2014 Private
->DriverHandle
,
2015 &gEfiDevicePathProtocolGuid
,
2016 &mWifiMgrDxeHiiVendorDevicePath
,
2017 &gEfiHiiConfigAccessProtocolGuid
,
2018 &Private
->ConfigAccess
,