]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrHiiConfigAccess.c
NetworkPkg: Add Wi-Fi Wpa3 support in WifiConnectManager
[mirror_edk2.git] / NetworkPkg / WifiConnectionManagerDxe / WifiConnectionMgrHiiConfigAccess.c
1 /** @file
2 The Hii functions for WiFi Connection Manager.
3
4 Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "WifiConnectionMgrDxe.h"
11
12 CHAR16 mVendorStorageName[] = L"WIFI_MANAGER_IFR_NVDATA";
13
14 HII_VENDOR_DEVICE_PATH mWifiMgrDxeHiiVendorDevicePath = {
15 {
16 {
17 HARDWARE_DEVICE_PATH,
18 HW_VENDOR_DP,
19 {
20 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
21 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
22 }
23 },
24 WIFI_CONNECTION_MANAGER_CONFIG_GUID
25 },
26 {
27 END_DEVICE_PATH_TYPE,
28 END_ENTIRE_DEVICE_PATH_SUBTYPE,
29 {
30 (UINT8)(END_DEVICE_PATH_LENGTH),
31 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
32 }
33 }
34 };
35
36 //
37 // HII Config Access Protocol instance
38 //
39 GLOBAL_REMOVE_IF_UNREFERENCED
40 EFI_HII_CONFIG_ACCESS_PROTOCOL gWifiMgrDxeHiiConfigAccess = {
41 WifiMgrDxeHiiConfigAccessExtractConfig,
42 WifiMgrDxeHiiConfigAccessRouteConfig,
43 WifiMgrDxeHiiConfigAccessCallback
44 };
45
46 CHAR16 *mSecurityType[] = {
47 L"OPEN ",
48 L"WPA-Enterprise ",
49 L"WPA2-Enterprise",
50 L"WPA-Personal ",
51 L"WPA2-Personal ",
52 L"WEP ",
53 L"WPA3-Personal ",
54 L"WPA3-Enterprise",
55 L"UnKnown "
56 };
57
58 CHAR16 *mSignalStrengthBar[] = {
59 L"[-----]",
60 L"[*----]",
61 L"[**---]",
62 L"[***--]",
63 L"[****-]",
64 L"[*****]"
65 };
66
67 #define RSSI_TO_SIGNAL_STRENGTH_BAR(Rssi) mSignalStrengthBar[((Rssi + 19)/20)]
68
69 #define NET_LIST_FOR_EACH_FROM_NODE(Entry, Node, ListHead) \
70 for(Entry = Node->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
71
72 extern EFI_GUID gWifiConfigFormSetGuid;
73
74 /**
75 Create Hii Extend Label OpCode as the start opcode and end opcode.
76 The caller is responsible for freeing the OpCode with HiiFreeOpCodeHandle().
77
78 @param[in] StartLabelNumber The number of start label.
79 @param[out] StartOpCodeHandle Points to the start opcode handle.
80 @param[out] EndOpCodeHandle Points to the end opcode handle.
81
82 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
83 operation.
84 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
85 @retval EFI_SUCCESS The operation is completed successfully.
86 @retval Other Errors Returned errors when updating the HII form.
87
88 **/
89 EFI_STATUS
90 WifiMgrCreateOpCode (
91 IN UINT16 StartLabelNumber,
92 OUT VOID **StartOpCodeHandle,
93 OUT VOID **EndOpCodeHandle
94 )
95 {
96 EFI_STATUS Status;
97 EFI_IFR_GUID_LABEL *InternalStartLabel;
98 EFI_IFR_GUID_LABEL *InternalEndLabel;
99
100 if ((StartOpCodeHandle == NULL) || (EndOpCodeHandle == NULL)) {
101 return EFI_INVALID_PARAMETER;
102 }
103
104 Status = EFI_OUT_OF_RESOURCES;
105 *StartOpCodeHandle = NULL;
106 *EndOpCodeHandle = NULL;
107
108 //
109 // Initialize the container for dynamic opcodes.
110 //
111 *StartOpCodeHandle = HiiAllocateOpCodeHandle ();
112 if (*StartOpCodeHandle == NULL) {
113 goto Exit;
114 }
115
116 *EndOpCodeHandle = HiiAllocateOpCodeHandle ();
117 if (*EndOpCodeHandle == NULL) {
118 goto Exit;
119 }
120
121 //
122 // Create Hii Extend Label OpCode as the start opcode.
123 //
124 InternalStartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
125 *StartOpCodeHandle,
126 &gEfiIfrTianoGuid,
127 NULL,
128 sizeof (EFI_IFR_GUID_LABEL)
129 );
130 if (InternalStartLabel == NULL) {
131 goto Exit;
132 }
133
134 InternalStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
135 InternalStartLabel->Number = StartLabelNumber;
136
137 //
138 // Create Hii Extend Label OpCode as the end opcode.
139 //
140 InternalEndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
141 *EndOpCodeHandle,
142 &gEfiIfrTianoGuid,
143 NULL,
144 sizeof (EFI_IFR_GUID_LABEL)
145 );
146 if (InternalEndLabel == NULL) {
147 goto Exit;
148 }
149
150 InternalEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
151 InternalEndLabel->Number = LABEL_END;
152
153 return EFI_SUCCESS;
154
155 Exit:
156
157 if (*StartOpCodeHandle != NULL) {
158 HiiFreeOpCodeHandle (*StartOpCodeHandle);
159 }
160
161 if (*EndOpCodeHandle != NULL) {
162 HiiFreeOpCodeHandle (*EndOpCodeHandle);
163 }
164
165 return Status;
166 }
167
168 /**
169 Display the Nic list contains all available Nics.
170
171 @param[in] Private The pointer to the global private data structure.
172
173 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
174 @retval EFI_SUCCESS The operation is completed successfully.
175
176 **/
177 EFI_STATUS
178 WifiMgrShowNicList (
179 IN WIFI_MGR_PRIVATE_DATA *Private
180 )
181 {
182 EFI_STATUS Status;
183 CHAR16 MacString[WIFI_MGR_MAX_MAC_STRING_LEN];
184 CHAR16 PortString[WIFI_STR_MAX_SIZE];
185 EFI_STRING_ID PortTitleToken;
186 EFI_STRING_ID PortTitleHelpToken;
187 WIFI_MGR_DEVICE_DATA *Nic;
188 LIST_ENTRY *Entry;
189 VOID *StartOpCodeHandle;
190 VOID *EndOpCodeHandle;
191
192 if (Private == NULL) {
193 return EFI_INVALID_PARAMETER;
194 }
195
196 Status = WifiMgrCreateOpCode (
197 LABEL_MAC_ENTRY,
198 &StartOpCodeHandle,
199 &EndOpCodeHandle
200 );
201 if (EFI_ERROR (Status)) {
202 return Status;
203 }
204
205 NET_LIST_FOR_EACH (Entry, &Private->NicList) {
206 Nic = NET_LIST_USER_STRUCT_S (Entry, WIFI_MGR_DEVICE_DATA, Link, WIFI_MGR_DEVICE_DATA_SIGNATURE);
207 WifiMgrMacAddrToStr (&Nic->MacAddress, sizeof (MacString), MacString);
208 UnicodeSPrint (PortString, sizeof (PortString), L"MAC %s", MacString);
209 PortTitleToken = HiiSetString (
210 Private->RegisteredHandle,
211 0,
212 PortString,
213 NULL
214 );
215 if (PortTitleToken == 0) {
216 Status = EFI_INVALID_PARAMETER;
217 goto Exit;
218 }
219
220 UnicodeSPrint (PortString, sizeof (PortString), L"MAC Address");
221 PortTitleHelpToken = HiiSetString (
222 Private->RegisteredHandle,
223 0,
224 PortString,
225 NULL
226 );
227 if (PortTitleHelpToken == 0) {
228 Status = EFI_INVALID_PARAMETER;
229 goto Exit;
230 }
231
232 HiiCreateGotoOpCode (
233 StartOpCodeHandle,
234 FORMID_WIFI_MAINPAGE,
235 PortTitleToken,
236 PortTitleHelpToken,
237 EFI_IFR_FLAG_CALLBACK,
238 (UINT16)(KEY_MAC_ENTRY_BASE + Nic->NicIndex)
239 );
240 }
241
242 Status = HiiUpdateForm (
243 Private->RegisteredHandle, // HII handle
244 &gWifiConfigFormSetGuid, // Formset GUID
245 FORMID_MAC_SELECTION, // Form ID
246 StartOpCodeHandle, // Label for where to insert opcodes
247 EndOpCodeHandle // Replace data
248 );
249
250 Exit:
251
252 HiiFreeOpCodeHandle (StartOpCodeHandle);
253 HiiFreeOpCodeHandle (EndOpCodeHandle);
254 return Status;
255 }
256
257 /**
258 Retreive the unicode string of the AKM Suite list of a profile.
259 The caller is responsible for freeing the string with FreePool().
260
261 @param[in] Profile The network profile contains a AKM suite list.
262
263 @return the unicode string of AKM suite list or "None".
264
265 **/
266 CHAR16 *
267 WifiMgrGetStrAKMList (
268 IN WIFI_MGR_NETWORK_PROFILE *Profile
269 )
270 {
271 UINT8 Index;
272 UINT16 AKMSuiteCount;
273 CHAR16 *AKMListDisplay;
274 UINTN Length;
275
276 AKMListDisplay = NULL;
277 if ((Profile == NULL) || (Profile->Network.AKMSuite == NULL)) {
278 goto Exit;
279 }
280
281 AKMSuiteCount = Profile->Network.AKMSuite->AKMSuiteCount;
282 if (AKMSuiteCount != 0) {
283 //
284 // Current AKM Suite is between 1-18
285 //
286 AKMListDisplay = (CHAR16 *)AllocateZeroPool (sizeof (CHAR16) * (AKMSuiteCount * 3 + 1));
287 Length = 0;
288 if (AKMListDisplay != NULL) {
289 for (Index = 0; Index < AKMSuiteCount; Index++) {
290 //
291 // The size of buffer should be 4 CHAR16 for Null-terminated Unicode string.
292 //
293 UnicodeSPrint (
294 AKMListDisplay + Length,
295 sizeof (CHAR16) * 4,
296 L"%d ",
297 Profile->Network.AKMSuite->AKMSuiteList[Index].SuiteType
298 );
299 Length = StrLen (AKMListDisplay + Length) + Length;
300 if (Index == AKMSuiteCount - 1) {
301 *(AKMListDisplay + (Length - 1)) = L'\0';
302 }
303 }
304 }
305 }
306
307 Exit:
308
309 if (AKMListDisplay == NULL) {
310 AKMListDisplay = AllocateCopyPool (sizeof (L"None"), L"None");
311 }
312
313 return AKMListDisplay;
314 }
315
316 /**
317 Retreive the unicode string of the Cipher Suite list of a profile.
318 The caller is responsible for freeing the string with FreePool().
319
320 @param[in] Profile The network profile contains a Cipher suite list.
321
322 @return the unicode string of Cipher suite list or "None".
323
324 **/
325 CHAR16 *
326 WifiMgrGetStrCipherList (
327 IN WIFI_MGR_NETWORK_PROFILE *Profile
328 )
329 {
330 UINT8 Index;
331 UINT16 CipherSuiteCount;
332 CHAR16 *CipherListDisplay;
333
334 CipherListDisplay = NULL;
335 if ((Profile == NULL) || (Profile->Network.CipherSuite == NULL)) {
336 goto Exit;
337 }
338
339 CipherSuiteCount = Profile->Network.CipherSuite->CipherSuiteCount;
340 if (CipherSuiteCount != 0) {
341 //
342 // Current Cipher Suite is between 1-9
343 //
344 CipherListDisplay = (CHAR16 *)AllocateZeroPool (sizeof (CHAR16) * (CipherSuiteCount * 2 + 1));
345 if (CipherListDisplay != NULL) {
346 for (Index = 0; Index < CipherSuiteCount; Index++) {
347 //
348 // The size of buffer should be 3 CHAR16 for Null-terminated Unicode string.
349 // The first char is the Cipher Suite number, the second char is ' ', the third char is '\0'.
350 //
351 UnicodeSPrint (
352 CipherListDisplay + (Index * 2),
353 sizeof (CHAR16) * 3,
354 L"%d ",
355 Profile->Network.CipherSuite->CipherSuiteList[Index].SuiteType
356 );
357 if (Index == CipherSuiteCount - 1) {
358 *(CipherListDisplay + (Index * 2 + 1)) = L'\0';
359 }
360 }
361 }
362 }
363
364 Exit:
365
366 if (CipherListDisplay == NULL) {
367 CipherListDisplay = AllocateCopyPool (sizeof (L"None"), L"None");
368 }
369
370 return CipherListDisplay;
371 }
372
373 /**
374 Refresh the network list display of the current Nic.
375
376 @param[in] Private The pointer to the global private data structure.
377 @param[out] IfrNvData The IFR NV data.
378
379 @retval EFI_SUCCESS The operation is completed successfully.
380 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
381 @retval Other Errors Returned errors when creating Opcodes or updating the
382 Hii form.
383
384 **/
385 EFI_STATUS
386 WifiMgrRefreshNetworkList (
387 IN WIFI_MGR_PRIVATE_DATA *Private,
388 OUT WIFI_MANAGER_IFR_NVDATA *IfrNvData
389 )
390 {
391 EFI_STATUS Status;
392 EFI_TPL OldTpl;
393 UINT32 AvailableCount;
394 EFI_STRING_ID PortPromptToken;
395 EFI_STRING_ID PortTextToken;
396 EFI_STRING_ID PortHelpToken;
397 WIFI_MGR_NETWORK_PROFILE *Profile;
398 LIST_ENTRY *Entry;
399 VOID *StartOpCodeHandle;
400 VOID *EndOpCodeHandle;
401 CHAR16 *AKMListDisplay;
402 CHAR16 *CipherListDisplay;
403 CHAR16 PortString[WIFI_STR_MAX_SIZE];
404 UINTN PortStringSize;
405 WIFI_MGR_NETWORK_PROFILE *ConnectedProfile;
406
407 if (Private->CurrentNic == NULL) {
408 return EFI_SUCCESS;
409 }
410
411 Status = WifiMgrCreateOpCode (
412 LABEL_NETWORK_LIST_ENTRY,
413 &StartOpCodeHandle,
414 &EndOpCodeHandle
415 );
416 if (EFI_ERROR (Status)) {
417 return Status;
418 }
419
420 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
421 AvailableCount = 0;
422 PortStringSize = sizeof (PortString);
423 ConnectedProfile = NULL;
424 AKMListDisplay = NULL;
425 CipherListDisplay = NULL;
426
427 if (Private->CurrentNic->ConnectState == WifiMgrConnectedToAp) {
428 //
429 // Display the current connected network.
430 // Find the current operate network under connected status.
431 //
432 if ((Private->CurrentNic->CurrentOperateNetwork != NULL) &&
433 Private->CurrentNic->CurrentOperateNetwork->IsAvailable)
434 {
435 Profile = Private->CurrentNic->CurrentOperateNetwork;
436 AvailableCount++;
437
438 AKMListDisplay = WifiMgrGetStrAKMList (Profile);
439 if (AKMListDisplay == NULL) {
440 Status = EFI_OUT_OF_RESOURCES;
441 goto Exit;
442 }
443
444 CipherListDisplay = WifiMgrGetStrCipherList (Profile);
445 if (CipherListDisplay == NULL) {
446 Status = EFI_OUT_OF_RESOURCES;
447 goto Exit;
448 }
449
450 UnicodeSPrint (PortString, PortStringSize, L"%s (Connected)", Profile->SSId);
451 PortPromptToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);
452
453 if (Profile->SecurityType == SECURITY_TYPE_NONE) {
454 PortHelpToken = 0;
455 } else {
456 UnicodeSPrint (PortString, PortStringSize, L"AKMSuite: %s CipherSuite: %s", AKMListDisplay, CipherListDisplay);
457 PortHelpToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);
458 }
459
460 FreePool (AKMListDisplay);
461 FreePool (CipherListDisplay);
462 AKMListDisplay = NULL;
463 CipherListDisplay = NULL;
464
465 HiiCreateGotoOpCode (
466 StartOpCodeHandle,
467 FORMID_CONNECT_NETWORK,
468 PortPromptToken,
469 PortHelpToken,
470 EFI_IFR_FLAG_CALLBACK,
471 (UINT16)(KEY_AVAILABLE_NETWORK_ENTRY_BASE + Profile->ProfileIndex)
472 );
473
474 UnicodeSPrint (
475 PortString,
476 PortStringSize,
477 L"%s %s %s",
478 (Profile->SecurityType != SECURITY_TYPE_NONE ? L"Secured" : L"Open "),
479 mSecurityType[Profile->SecurityType],
480 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile->NetworkQuality)
481 );
482 PortTextToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);
483
484 HiiCreateTextOpCode (
485 StartOpCodeHandle,
486 PortTextToken,
487 0,
488 0
489 );
490
491 ConnectedProfile = Profile;
492 } else {
493 Private->CurrentNic->HasDisconnectPendingNetwork = TRUE;
494 }
495 }
496
497 //
498 // Display all supported available networks.
499 //
500 NET_LIST_FOR_EACH (Entry, &Private->CurrentNic->ProfileList) {
501 Profile = NET_LIST_USER_STRUCT_S (
502 Entry,
503 WIFI_MGR_NETWORK_PROFILE,
504 Link,
505 WIFI_MGR_PROFILE_SIGNATURE
506 );
507 if (ConnectedProfile == Profile) {
508 continue;
509 }
510
511 if (Profile->IsAvailable && Profile->CipherSuiteSupported) {
512 AvailableCount++;
513
514 AKMListDisplay = WifiMgrGetStrAKMList (Profile);
515 if (AKMListDisplay == NULL) {
516 Status = EFI_OUT_OF_RESOURCES;
517 goto Exit;
518 }
519
520 CipherListDisplay = WifiMgrGetStrCipherList (Profile);
521 if (CipherListDisplay == NULL) {
522 Status = EFI_OUT_OF_RESOURCES;
523 goto Exit;
524 }
525
526 PortPromptToken = HiiSetString (Private->RegisteredHandle, 0, Profile->SSId, NULL);
527 if (PortPromptToken == 0) {
528 Status = EFI_OUT_OF_RESOURCES;
529 goto Exit;
530 }
531
532 if (Profile->SecurityType == SECURITY_TYPE_NONE) {
533 PortHelpToken = 0;
534 } else {
535 UnicodeSPrint (
536 PortString,
537 PortStringSize,
538 L"AKMSuite: %s CipherSuite: %s",
539 AKMListDisplay,
540 CipherListDisplay
541 );
542 PortHelpToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);
543 if (PortHelpToken == 0) {
544 Status = EFI_OUT_OF_RESOURCES;
545 goto Exit;
546 }
547 }
548
549 FreePool (AKMListDisplay);
550 FreePool (CipherListDisplay);
551 AKMListDisplay = NULL;
552 CipherListDisplay = NULL;
553
554 HiiCreateGotoOpCode (
555 StartOpCodeHandle,
556 FORMID_CONNECT_NETWORK,
557 PortPromptToken,
558 PortHelpToken,
559 EFI_IFR_FLAG_CALLBACK,
560 (UINT16)(KEY_AVAILABLE_NETWORK_ENTRY_BASE + Profile->ProfileIndex)
561 );
562
563 UnicodeSPrint (
564 PortString,
565 PortStringSize,
566 L"%s %s %s",
567 (Profile->SecurityType != SECURITY_TYPE_NONE ? L"Secured" : L"Open "),
568 mSecurityType[Profile->SecurityType],
569 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile->NetworkQuality)
570 );
571 PortTextToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);
572 if (PortTextToken == 0) {
573 Status = EFI_OUT_OF_RESOURCES;
574 goto Exit;
575 }
576
577 HiiCreateTextOpCode (
578 StartOpCodeHandle,
579 PortTextToken,
580 0,
581 0
582 );
583 }
584 }
585
586 //
587 // Display all Unsupported available networks.
588 //
589 NET_LIST_FOR_EACH (Entry, &Private->CurrentNic->ProfileList) {
590 Profile = NET_LIST_USER_STRUCT_S (
591 Entry,
592 WIFI_MGR_NETWORK_PROFILE,
593 Link,
594 WIFI_MGR_PROFILE_SIGNATURE
595 );
596 if (ConnectedProfile == Profile) {
597 continue;
598 }
599
600 if (Profile->IsAvailable && !Profile->CipherSuiteSupported) {
601 AvailableCount++;
602
603 AKMListDisplay = WifiMgrGetStrAKMList (Profile);
604 if (AKMListDisplay == NULL) {
605 Status = EFI_OUT_OF_RESOURCES;
606 goto Exit;
607 }
608
609 CipherListDisplay = WifiMgrGetStrCipherList (Profile);
610 if (CipherListDisplay == NULL) {
611 Status = EFI_OUT_OF_RESOURCES;
612 goto Exit;
613 }
614
615 PortPromptToken = HiiSetString (Private->RegisteredHandle, 0, Profile->SSId, NULL);
616
617 if (Profile->AKMSuiteSupported) {
618 UnicodeSPrint (
619 PortString,
620 PortStringSize,
621 L"AKMSuite: %s CipherSuite(UnSupported): %s",
622 AKMListDisplay,
623 CipherListDisplay
624 );
625 } else {
626 UnicodeSPrint (
627 PortString,
628 PortStringSize,
629 L"AKMSuite(UnSupported): %s CipherSuite(UnSupported): %s",
630 AKMListDisplay,
631 CipherListDisplay
632 );
633 }
634
635 FreePool (AKMListDisplay);
636 FreePool (CipherListDisplay);
637 AKMListDisplay = NULL;
638 CipherListDisplay = NULL;
639
640 PortHelpToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);
641
642 HiiCreateGotoOpCode (
643 StartOpCodeHandle,
644 FORMID_CONNECT_NETWORK,
645 PortPromptToken,
646 PortHelpToken,
647 EFI_IFR_FLAG_CALLBACK,
648 (UINT16)(KEY_AVAILABLE_NETWORK_ENTRY_BASE + Profile->ProfileIndex)
649 );
650
651 UnicodeSPrint (
652 PortString,
653 PortStringSize,
654 L"%s %s %s",
655 L"UnSupported",
656 mSecurityType[Profile->SecurityType],
657 RSSI_TO_SIGNAL_STRENGTH_BAR (Profile->NetworkQuality)
658 );
659 PortTextToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);
660
661 HiiCreateTextOpCode (
662 StartOpCodeHandle,
663 PortTextToken,
664 0,
665 0
666 );
667 }
668 }
669
670 Status = HiiUpdateForm (
671 Private->RegisteredHandle, // HII handle
672 &gWifiConfigFormSetGuid, // Formset GUID
673 FORMID_NETWORK_LIST, // Form ID
674 StartOpCodeHandle, // Label for where to insert opcodes
675 EndOpCodeHandle // Replace data
676 );
677
678 Exit:
679
680 gBS->RestoreTPL (OldTpl);
681
682 if (AKMListDisplay != NULL) {
683 FreePool (AKMListDisplay);
684 }
685
686 if (CipherListDisplay != NULL) {
687 FreePool (CipherListDisplay);
688 }
689
690 HiiFreeOpCodeHandle (StartOpCodeHandle);
691 HiiFreeOpCodeHandle (EndOpCodeHandle);
692
693 DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Network List is Refreshed!\n"));
694 return Status;
695 }
696
697 /**
698 Refresh the hidden network list configured by user.
699
700 @param[in] Private The pointer to the global private data structure.
701
702 @retval EFI_SUCCESS The operation is completed successfully.
703 @retval Other Errors Returned errors when creating Opcodes or updating the
704 Hii form.
705 **/
706 EFI_STATUS
707 WifiMgrRefreshHiddenList (
708 IN WIFI_MGR_PRIVATE_DATA *Private
709 )
710 {
711 EFI_STATUS Status;
712 EFI_TPL OldTpl;
713 UINTN Index;
714 EFI_STRING_ID StringId;
715 VOID *StartOpCodeHandle;
716 VOID *EndOpCodeHandle;
717 WIFI_HIDDEN_NETWORK_DATA *HiddenNetwork;
718 LIST_ENTRY *Entry;
719
720 if (Private == NULL) {
721 return EFI_SUCCESS;
722 }
723
724 Status = WifiMgrCreateOpCode (
725 LABEL_HIDDEN_NETWORK_ENTRY,
726 &StartOpCodeHandle,
727 &EndOpCodeHandle
728 );
729 if (EFI_ERROR (Status)) {
730 return Status;
731 }
732
733 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
734 Index = 0;
735
736 NET_LIST_FOR_EACH (Entry, &Private->HiddenNetworkList) {
737 HiddenNetwork = NET_LIST_USER_STRUCT_S (
738 Entry,
739 WIFI_HIDDEN_NETWORK_DATA,
740 Link,
741 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
742 );
743 StringId = HiiSetString (Private->RegisteredHandle, 0, HiddenNetwork->SSId, NULL);
744
745 HiiCreateCheckBoxOpCode (
746 StartOpCodeHandle,
747 (EFI_QUESTION_ID)(KEY_HIDDEN_NETWORK_ENTRY_BASE + Index),
748 MANAGER_VARSTORE_ID,
749 (UINT16)(HIDDEN_NETWORK_LIST_VAR_OFFSET + Index),
750 StringId,
751 0,
752 0,
753 0,
754 NULL
755 );
756 Index++;
757 }
758
759 Status = HiiUpdateForm (
760 Private->RegisteredHandle, // HII handle
761 &gWifiConfigFormSetGuid, // Formset GUID
762 FORMID_HIDDEN_NETWORK_LIST, // Form ID
763 StartOpCodeHandle, // Label for where to insert opcodes
764 EndOpCodeHandle // Replace data
765 );
766
767 gBS->RestoreTPL (OldTpl);
768 HiiFreeOpCodeHandle (StartOpCodeHandle);
769 HiiFreeOpCodeHandle (EndOpCodeHandle);
770 return Status;
771 }
772
773 /**
774 Callback function for user to select a Nic.
775
776 @param[in] Private The pointer to the global private data structure.
777 @param[in] KeyValue The key value received from HII input.
778
779 @retval EFI_NOT_FOUND The corresponding Nic is not found.
780 @retval EFI_SUCCESS The operation is completed successfully.
781
782 **/
783 EFI_STATUS
784 WifiMgrSelectNic (
785 IN WIFI_MGR_PRIVATE_DATA *Private,
786 IN EFI_QUESTION_ID KeyValue
787 )
788 {
789 WIFI_MGR_DEVICE_DATA *Nic;
790 UINT32 NicIndex;
791 CHAR16 MacString[WIFI_MGR_MAX_MAC_STRING_LEN];
792
793 NicIndex = KeyValue - KEY_MAC_ENTRY_BASE;
794 Nic = WifiMgrGetNicByIndex (Private, NicIndex);
795 if (Nic == NULL) {
796 return EFI_NOT_FOUND;
797 }
798
799 Private->CurrentNic = Nic;
800
801 WifiMgrMacAddrToStr (&Nic->MacAddress, sizeof (MacString), MacString);
802 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_MAC_ADDRESS), MacString, NULL);
803 return EFI_SUCCESS;
804 }
805
806 /**
807 Restore the NV data to be default.
808
809 @param[in] Private The pointer to the global private data structure.
810 @param[out] IfrNvData The IFR NV data.
811
812 **/
813 VOID
814 WifiMgrCleanUserInput (
815 IN WIFI_MGR_PRIVATE_DATA *Private
816 )
817 {
818 Private->SecurityType = SECURITY_TYPE_NONE;
819 Private->EapAuthMethod = EAP_AUTH_METHOD_TTLS;
820 Private->EapSecondAuthMethod = EAP_SEAUTH_METHOD_MSCHAPV2;
821 Private->FileType = FileTypeMax;
822 }
823
824 /**
825 UI handle function when user select a network to connect.
826
827 @param[in] Private The pointer to the global private data structure.
828 @param[in] ProfileIndex The profile index user selected to connect.
829
830 @retval EFI_INVALID_PARAMETER Nic is null.
831 @retval EFI_NOT_FOUND Profile could not be found.
832 @retval EFI_SUCCESS The operation is completed successfully.
833
834 **/
835 EFI_STATUS
836 WifiMgrUserSelectProfileToConnect (
837 IN WIFI_MGR_PRIVATE_DATA *Private,
838 IN UINT32 ProfileIndex
839 )
840 {
841 WIFI_MGR_NETWORK_PROFILE *Profile;
842 WIFI_MGR_DEVICE_DATA *Nic;
843
844 Nic = Private->CurrentNic;
845 if (Nic == NULL) {
846 return EFI_INVALID_PARAMETER;
847 }
848
849 //
850 // Initialize the connection page
851 //
852 WifiMgrCleanUserInput (Private);
853
854 Profile = WifiMgrGetProfileByProfileIndex (ProfileIndex, &Nic->ProfileList);
855 if (Profile == NULL) {
856 return EFI_NOT_FOUND;
857 }
858
859 Private->CurrentNic->UserSelectedProfile = Profile;
860
861 return EFI_SUCCESS;
862 }
863
864 /**
865 Record password from a HII input string.
866
867 @param[in] Private The pointer to the global private data structure.
868 @param[in] StringId The QuestionId received from HII input.
869 @param[in] StringBuffer The unicode string buffer to store password.
870 @param[in] StringBufferLen The len of unicode string buffer.
871
872 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
873 @retval EFI_NOT_FOUND The password string is not found or invalid.
874 @retval EFI_SUCCESS The operation is completed successfully.
875
876 **/
877 EFI_STATUS
878 WifiMgrRecordPassword (
879 IN WIFI_MGR_PRIVATE_DATA *Private,
880 IN EFI_STRING_ID StringId,
881 IN CHAR16 *StringBuffer,
882 IN UINTN StringBufferLen
883 )
884 {
885 CHAR16 *Password;
886
887 if ((StringId == 0) || (StringBuffer == NULL) || (StringBufferLen <= 0)) {
888 return EFI_INVALID_PARAMETER;
889 }
890
891 Password = HiiGetString (Private->RegisteredHandle, StringId, NULL);
892 if (Password == NULL) {
893 return EFI_NOT_FOUND;
894 }
895
896 if (StrLen (Password) > StringBufferLen) {
897 FreePool (Password);
898 return EFI_NOT_FOUND;
899 }
900
901 StrnCpyS (StringBuffer, StringBufferLen, Password, StrLen (Password));
902 ZeroMem (Password, (StrLen (Password) + 1) * sizeof (CHAR16));
903 FreePool (Password);
904
905 //
906 // Clean password in string package
907 //
908 HiiSetString (Private->RegisteredHandle, StringId, L"", NULL);
909 return EFI_SUCCESS;
910 }
911
912 /**
913 Update connection message on connect configuration page, and trigger related form refresh.
914
915 @param[in] Nic The related Nic for updating message.
916 @param[in] ConnectStateChanged The tag to tell if the connection state has been changed, only
917 when the connection changes from "Connected" or "Disconnecting"
918 to "Disconnected", or from "Disconnected" or "Connecting" to
919 "Connected", this tag can be set as TRUE.
920 @param[in] ConnectStatusMessage The message to show on connected status bar, if NULL, will
921 use default message.
922
923 **/
924 VOID
925 WifiMgrUpdateConnectMessage (
926 IN WIFI_MGR_DEVICE_DATA *Nic,
927 IN BOOLEAN ConnectStateChanged,
928 IN EFI_STRING ConnectStatusMessage
929 )
930 {
931 CHAR16 ConnectStatusStr[WIFI_STR_MAX_SIZE];
932 WIFI_MGR_PRIVATE_DATA *Private;
933
934 Private = Nic->Private;
935 if ((Private == NULL) || (Private->CurrentNic != Nic)) {
936 return;
937 }
938
939 //
940 // Update Connection Status Bar
941 //
942 if (ConnectStatusMessage != NULL) {
943 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusMessage, NULL);
944 } else {
945 if (Nic->ConnectState == WifiMgrConnectedToAp) {
946 UnicodeSPrint (
947 ConnectStatusStr,
948 sizeof (ConnectStatusStr),
949 L"Connected to %s",
950 Nic->CurrentOperateNetwork->SSId
951 );
952 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusStr, NULL);
953 } else if (Nic->ConnectState == WifiMgrDisconnected) {
954 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), L"Disconnected", NULL);
955 } else if (Nic->ConnectState == WifiMgrConnectingToAp) {
956 UnicodeSPrint (
957 ConnectStatusStr,
958 sizeof (ConnectStatusStr),
959 L"Connecting to %s ...",
960 Nic->CurrentOperateNetwork->SSId
961 );
962 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusStr, NULL);
963 } else if (Nic->ConnectState == WifiMgrDisconnectingToAp) {
964 UnicodeSPrint (
965 ConnectStatusStr,
966 sizeof (ConnectStatusStr),
967 L"Disconnecting from %s ...",
968 Nic->CurrentOperateNetwork->SSId
969 );
970 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusStr, NULL);
971 } else {
972 return;
973 }
974 }
975
976 //
977 // Update Connect Button
978 //
979 if ((Nic->ConnectState == WifiMgrConnectedToAp) && (Nic->UserSelectedProfile == Nic->CurrentOperateNetwork)) {
980 HiiSetString (
981 Private->RegisteredHandle,
982 STRING_TOKEN (STR_CONNECT_NOW),
983 L"Disconnect from this Network",
984 NULL
985 );
986 } else {
987 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_NOW), L"Connect to this Network", NULL);
988 }
989
990 gBS->SignalEvent (Private->ConnectFormRefreshEvent);
991
992 //
993 // Update Main Page and Network List
994 //
995 if (ConnectStateChanged) {
996 if (Nic->ConnectState == WifiMgrConnectedToAp) {
997 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECTION_INFO), L"Connected to", NULL);
998 HiiSetString (
999 Private->RegisteredHandle,
1000 STRING_TOKEN (STR_CONNECTED_SSID),
1001 Nic->CurrentOperateNetwork->SSId,
1002 NULL
1003 );
1004 } else {
1005 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECTION_INFO), L"Disconnected", NULL);
1006 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECTED_SSID), L"", NULL);
1007 }
1008
1009 gBS->SignalEvent (Private->NetworkListRefreshEvent);
1010 gBS->SignalEvent (Private->MainPageRefreshEvent);
1011 }
1012 }
1013
1014 /**
1015 Convert the driver configuration data into the IFR data.
1016
1017 @param[in] Private The pointer to the global private data structure.
1018 @param[out] IfrNvData The IFR NV data.
1019
1020 @retval EFI_SUCCESS The operation is completed successfully.
1021
1022 **/
1023 EFI_STATUS
1024 WifiMgrConvertConfigDataToIfrNvData (
1025 IN WIFI_MGR_PRIVATE_DATA *Private,
1026 OUT WIFI_MANAGER_IFR_NVDATA *IfrNvData
1027 )
1028 {
1029 //
1030 // Private shouldn't be NULL here, assert if Private is NULL.
1031 //
1032 ASSERT (Private != NULL);
1033
1034 if (Private->CurrentNic != NULL) {
1035 IfrNvData->ProfileCount = Private->CurrentNic->AvailableCount;
1036 } else {
1037 IfrNvData->ProfileCount = 0;
1038 }
1039
1040 return EFI_SUCCESS;
1041 }
1042
1043 /**
1044 Convert the IFR data into the driver configuration data.
1045
1046 @param[in] Private The pointer to the global private data structure.
1047 @param[in, out] IfrNvData The IFR NV data.
1048
1049 @retval EFI_SUCCESS The operation is completed successfully.
1050
1051 **/
1052 EFI_STATUS
1053 WifiMgrConvertIfrNvDataToConfigData (
1054 IN WIFI_MGR_PRIVATE_DATA *Private,
1055 IN OUT WIFI_MANAGER_IFR_NVDATA *IfrNvData
1056 )
1057 {
1058 return EFI_SUCCESS;
1059 }
1060
1061 /**
1062 This function allows the caller to request the current
1063 configuration for one or more named elements. The resulting
1064 string is in <ConfigAltResp> format. Any and all alternative
1065 configuration strings shall also be appended to the end of the
1066 current configuration string. If they are, they must appear
1067 after the current configuration. They must contain the same
1068 routing (GUID, NAME, PATH) as the current configuration string.
1069 They must have an additional description indicating the type of
1070 alternative configuration the string represents,
1071 "ALTCFG=<StringToken>". That <StringToken> (when
1072 converted from Hex UNICODE to binary) is a reference to a
1073 string in the associated string pack.
1074
1075 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1076
1077 @param Request A null-terminated Unicode string in
1078 <ConfigRequest> format. Note that this
1079 includes the routing information as well as
1080 the configurable name / value pairs. It is
1081 invalid for this string to be in
1082 <MultiConfigRequest> format.
1083 If a NULL is passed in for the Request field,
1084 all of the settings being abstracted by this function
1085 will be returned in the Results field. In addition,
1086 if a ConfigHdr is passed in with no request elements,
1087 all of the settings being abstracted for that particular
1088 ConfigHdr reference will be returned in the Results Field.
1089
1090 @param Progress On return, points to a character in the
1091 Request string. Points to the string's null
1092 terminator if request was successful. Points
1093 to the most recent "&" before the first
1094 failing name / value pair (or the beginning
1095 of the string if the failure is in the first
1096 name / value pair) if the request was not
1097 successful.
1098
1099 @param Results A null-terminated Unicode string in
1100 <MultiConfigAltResp> format which has all values
1101 filled in for the names in the Request string.
1102 String to be allocated by the called function.
1103
1104 @retval EFI_SUCCESS The Results string is filled with the
1105 values corresponding to all requested
1106 names.
1107
1108 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1109 parts of the results that must be
1110 stored awaiting possible future
1111 protocols.
1112
1113 @retval EFI_NOT_FOUND Routing data doesn't match any
1114 known driver. Progress set to the
1115 first character in the routing header.
1116 Note: There is no requirement that the
1117 driver validate the routing data. It
1118 must skip the <ConfigHdr> in order to
1119 process the names.
1120
1121 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
1122 to most recent "&" before the
1123 error or the beginning of the
1124 string.
1125
1126 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
1127 to the & before the name in
1128 question.
1129
1130 **/
1131 EFI_STATUS
1132 EFIAPI
1133 WifiMgrDxeHiiConfigAccessExtractConfig (
1134 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1135 IN CONST EFI_STRING Request,
1136 OUT EFI_STRING *Progress,
1137 OUT EFI_STRING *Results
1138 )
1139 {
1140 WIFI_MGR_PRIVATE_DATA *Private;
1141 WIFI_MANAGER_IFR_NVDATA *IfrNvData;
1142 EFI_STRING ConfigRequestHdr;
1143 EFI_STRING ConfigRequest;
1144 UINTN Size;
1145 BOOLEAN AllocatedRequest;
1146 UINTN BufferSize;
1147 EFI_STATUS Status;
1148
1149 if ((This == NULL) || (Progress == NULL) || (Results == NULL)) {
1150 return EFI_INVALID_PARAMETER;
1151 }
1152
1153 *Progress = Request;
1154 if ((Request != NULL) &&
1155 !HiiIsConfigHdrMatch (Request, &gWifiConfigFormSetGuid, mVendorStorageName))
1156 {
1157 return EFI_NOT_FOUND;
1158 }
1159
1160 ConfigRequestHdr = NULL;
1161 ConfigRequest = NULL;
1162 AllocatedRequest = FALSE;
1163 Size = 0;
1164
1165 Private = WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This);
1166
1167 BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);
1168 IfrNvData = AllocateZeroPool (BufferSize);
1169 if (IfrNvData == NULL) {
1170 return EFI_OUT_OF_RESOURCES;
1171 }
1172
1173 WifiMgrConvertConfigDataToIfrNvData (Private, IfrNvData);
1174
1175 ConfigRequest = Request;
1176 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
1177 //
1178 // Request has no request element, construct full request string.
1179 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1180 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
1181 //
1182 ConfigRequestHdr = HiiConstructConfigHdr (
1183 &gWifiConfigFormSetGuid,
1184 mVendorStorageName,
1185 Private->DriverHandle
1186 );
1187 if (ConfigRequestHdr == NULL) {
1188 FreePool (IfrNvData);
1189 return EFI_OUT_OF_RESOURCES;
1190 }
1191
1192 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
1193 ConfigRequest = AllocateZeroPool (Size);
1194 if (ConfigRequest == NULL) {
1195 FreePool (IfrNvData);
1196 FreePool (ConfigRequestHdr);
1197 return EFI_OUT_OF_RESOURCES;
1198 }
1199
1200 AllocatedRequest = TRUE;
1201 UnicodeSPrint (
1202 ConfigRequest,
1203 Size,
1204 L"%s&OFFSET=0&WIDTH=%016LX",
1205 ConfigRequestHdr,
1206 (UINT64)BufferSize
1207 );
1208 FreePool (ConfigRequestHdr);
1209 }
1210
1211 //
1212 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1213 //
1214 Status = gHiiConfigRouting->BlockToConfig (
1215 gHiiConfigRouting,
1216 ConfigRequest,
1217 (UINT8 *)IfrNvData,
1218 BufferSize,
1219 Results,
1220 Progress
1221 );
1222
1223 FreePool (IfrNvData);
1224 //
1225 // Free the allocated config request string.
1226 //
1227 if (AllocatedRequest) {
1228 FreePool (ConfigRequest);
1229 ConfigRequest = NULL;
1230 }
1231
1232 //
1233 // Set Progress string to the original request string.
1234 //
1235 if (Request == NULL) {
1236 *Progress = NULL;
1237 } else if (StrStr (Request, L"OFFSET") == NULL) {
1238 *Progress = Request + StrLen (Request);
1239 }
1240
1241 return Status;
1242 }
1243
1244 /**
1245 This function applies changes in a driver's configuration.
1246 Input is a Configuration, which has the routing data for this
1247 driver followed by name / value configuration pairs. The driver
1248 must apply those pairs to its configurable storage. If the
1249 driver's configuration is stored in a linear block of data
1250 and the driver's name / value pairs are in <BlockConfig>
1251 format, it may use the ConfigToBlock helper function (above) to
1252 simplify the job.
1253
1254 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1255
1256 @param Configuration A null-terminated Unicode string in
1257 <ConfigString> format.
1258
1259 @param Progress A pointer to a string filled in with the
1260 offset of the most recent '&' before the
1261 first failing name / value pair (or the
1262 beginn ing of the string if the failure
1263 is in the first name / value pair) or
1264 the terminating NULL if all was
1265 successful.
1266
1267 @retval EFI_SUCCESS The results have been distributed or are
1268 awaiting distribution.
1269
1270 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1271 parts of the results that must be
1272 stored awaiting possible future
1273 protocols.
1274
1275 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
1276 Results parameter would result
1277 in this type of error.
1278
1279 @retval EFI_NOT_FOUND Target for the specified routing data
1280 was not found
1281
1282 **/
1283 EFI_STATUS
1284 EFIAPI
1285 WifiMgrDxeHiiConfigAccessRouteConfig (
1286 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1287 IN CONST EFI_STRING Configuration,
1288 OUT EFI_STRING *Progress
1289 )
1290 {
1291 EFI_STATUS Status;
1292 UINTN BufferSize;
1293 WIFI_MGR_PRIVATE_DATA *Private;
1294 WIFI_MANAGER_IFR_NVDATA *IfrNvData;
1295
1296 if ((Configuration == NULL) || (Progress == NULL)) {
1297 return EFI_INVALID_PARAMETER;
1298 }
1299
1300 IfrNvData = NULL;
1301 *Progress = Configuration;
1302 BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);
1303 Private = WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This);
1304
1305 if (!HiiIsConfigHdrMatch (Configuration, &gWifiConfigFormSetGuid, mVendorStorageName)) {
1306 return EFI_NOT_FOUND;
1307 }
1308
1309 IfrNvData = AllocateZeroPool (BufferSize);
1310 if (IfrNvData == NULL) {
1311 return EFI_OUT_OF_RESOURCES;
1312 }
1313
1314 WifiMgrConvertConfigDataToIfrNvData (Private, IfrNvData);
1315
1316 Status = gHiiConfigRouting->ConfigToBlock (
1317 gHiiConfigRouting,
1318 Configuration,
1319 (UINT8 *)IfrNvData,
1320 &BufferSize,
1321 Progress
1322 );
1323 if (EFI_ERROR (Status)) {
1324 return Status;
1325 }
1326
1327 Status = WifiMgrConvertIfrNvDataToConfigData (Private, IfrNvData);
1328 ZeroMem (IfrNvData, sizeof (WIFI_MANAGER_IFR_NVDATA));
1329 FreePool (IfrNvData);
1330
1331 return Status;
1332 }
1333
1334 /**
1335 This function is called to provide results data to the driver.
1336 This data consists of a unique key that is used to identify
1337 which data is either being passed back or being asked for.
1338
1339 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1340 @param Action Specifies the type of action taken by the browser.
1341 @param QuestionId A unique value which is sent to the original
1342 exporting driver so that it can identify the type
1343 of data to expect. The format of the data tends to
1344 vary based on the opcode that generated the callback.
1345 @param Type The type of value for the question.
1346 @param Value A pointer to the data being sent to the original
1347 exporting driver.
1348 @param ActionRequest On return, points to the action requested by the
1349 callback function.
1350
1351 @retval EFI_SUCCESS The callback successfully handled the action.
1352 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1353 variable and its data.
1354 @retval EFI_DEVICE_ERROR The variable could not be saved.
1355 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1356 callback.
1357
1358 **/
1359 EFI_STATUS
1360 EFIAPI
1361 WifiMgrDxeHiiConfigAccessCallback (
1362 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1363 IN EFI_BROWSER_ACTION Action,
1364 IN EFI_QUESTION_ID QuestionId,
1365 IN UINT8 Type,
1366 IN OUT EFI_IFR_TYPE_VALUE *Value,
1367 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
1368 )
1369 {
1370 EFI_STATUS Status;
1371 EFI_INPUT_KEY Key;
1372 UINTN BufferSize;
1373 WIFI_MGR_PRIVATE_DATA *Private;
1374 WIFI_MANAGER_IFR_NVDATA *IfrNvData;
1375 EFI_DEVICE_PATH_PROTOCOL *FilePath;
1376 WIFI_MGR_NETWORK_PROFILE *Profile;
1377 WIFI_MGR_NETWORK_PROFILE *ProfileToConnect;
1378 WIFI_HIDDEN_NETWORK_DATA *HiddenNetwork;
1379 UINTN TempDataSize;
1380 VOID *TempData;
1381 LIST_ENTRY *Entry;
1382 UINT32 Index;
1383 UINT32 RemoveCount;
1384 CHAR16 *TempPassword;
1385 CHAR16 *ErrorMessage;
1386
1387 if ((Action != EFI_BROWSER_ACTION_FORM_OPEN) &&
1388 (Action != EFI_BROWSER_ACTION_FORM_CLOSE) &&
1389 (Action != EFI_BROWSER_ACTION_CHANGING) &&
1390 (Action != EFI_BROWSER_ACTION_CHANGED) &&
1391 (Action != EFI_BROWSER_ACTION_RETRIEVE))
1392 {
1393 return EFI_UNSUPPORTED;
1394 }
1395
1396 if ((Value == NULL) || (ActionRequest == NULL)) {
1397 return EFI_INVALID_PARAMETER;
1398 }
1399
1400 Status = EFI_SUCCESS;
1401 Private = WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This);
1402 if (Private->CurrentNic == NULL) {
1403 return EFI_DEVICE_ERROR;
1404 }
1405
1406 //
1407 // Retrieve uncommitted data from Browser
1408 //
1409 BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);
1410 IfrNvData = AllocateZeroPool (BufferSize);
1411 if (IfrNvData == NULL) {
1412 return EFI_OUT_OF_RESOURCES;
1413 }
1414
1415 HiiGetBrowserData (&gWifiConfigFormSetGuid, mVendorStorageName, BufferSize, (UINT8 *)IfrNvData);
1416
1417 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
1418 switch (QuestionId) {
1419 case KEY_MAC_LIST:
1420
1421 Status = WifiMgrShowNicList (Private);
1422 break;
1423
1424 case KEY_REFRESH_NETWORK_LIST:
1425
1426 if (Private->CurrentNic->UserSelectedProfile != NULL) {
1427 Profile = Private->CurrentNic->UserSelectedProfile;
1428
1429 //
1430 // Erase secrets since user has left Connection Page
1431 // Connection Page may direct to Network List Page or Eap Configuration Page,
1432 // secrets only need to be erased when head to Network List Page
1433 //
1434 WifiMgrCleanProfileSecrets (Profile);
1435
1436 Private->CurrentNic->UserSelectedProfile = NULL;
1437 }
1438
1439 break;
1440
1441 case KEY_CONNECT_ACTION:
1442
1443 if (Private->CurrentNic->UserSelectedProfile == NULL) {
1444 break;
1445 }
1446
1447 Profile = Private->CurrentNic->UserSelectedProfile;
1448
1449 //
1450 // Enter the network connection configuration page
1451 // Recovery from restored data
1452 //
1453 if (HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_SSID), Profile->SSId, NULL) == 0) {
1454 return EFI_OUT_OF_RESOURCES;
1455 }
1456
1457 IfrNvData->SecurityType = Profile->SecurityType;
1458 if (HiiSetString (
1459 Private->RegisteredHandle,
1460 STRING_TOKEN (STR_SECURITY_TYPE),
1461 mSecurityType[IfrNvData->SecurityType],
1462 NULL
1463 ) == 0)
1464 {
1465 return EFI_OUT_OF_RESOURCES;
1466 }
1467
1468 if ((IfrNvData->SecurityType == SECURITY_TYPE_WPA2_ENTERPRISE) ||
1469 (IfrNvData->SecurityType == SECURITY_TYPE_WPA3_ENTERPRISE))
1470 {
1471 IfrNvData->EapAuthMethod = Profile->EapAuthMethod;
1472 IfrNvData->EapSecondAuthMethod = Profile->EapSecondAuthMethod;
1473 StrCpyS (IfrNvData->EapIdentity, EAP_IDENTITY_SIZE, Profile->EapIdentity);
1474 }
1475
1476 break;
1477
1478 case KEY_ENROLLED_CERT_NAME:
1479
1480 if (Private->CurrentNic->UserSelectedProfile == NULL) {
1481 break;
1482 }
1483
1484 Profile = Private->CurrentNic->UserSelectedProfile;
1485
1486 //
1487 // Enter the key enrollment page
1488 // For TTLS and PEAP, only CA cert needs to be cared
1489 //
1490 if (Private->FileType == FileTypeCACert) {
1491 if (Profile->CACertData != NULL) {
1492 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), Profile->CACertName, NULL);
1493 } else {
1494 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), L"", NULL);
1495 }
1496 } else if (Private->FileType == FileTypeClientCert) {
1497 if (Profile->ClientCertData != NULL) {
1498 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), Profile->ClientCertName, NULL);
1499 } else {
1500 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), L"", NULL);
1501 }
1502 }
1503
1504 break;
1505
1506 case KEY_ENROLLED_PRIVATE_KEY_NAME:
1507
1508 if (Private->CurrentNic->UserSelectedProfile == NULL) {
1509 break;
1510 }
1511
1512 Profile = Private->CurrentNic->UserSelectedProfile;
1513
1514 if (Profile->PrivateKeyData != NULL) {
1515 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME), Profile->PrivateKeyName, NULL);
1516 } else {
1517 HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME), L"", NULL);
1518 }
1519
1520 break;
1521
1522 default:
1523 break;
1524 }
1525 } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
1526 switch (QuestionId) {
1527 case KEY_CONNECT_ACTION:
1528
1529 if (Private->CurrentNic->UserSelectedProfile == NULL) {
1530 break;
1531 }
1532
1533 Profile = Private->CurrentNic->UserSelectedProfile;
1534
1535 //
1536 // Restore User Config Data for Page recovery
1537 //
1538 if ((IfrNvData->SecurityType == SECURITY_TYPE_WPA2_ENTERPRISE) ||
1539 (IfrNvData->SecurityType == SECURITY_TYPE_WPA3_ENTERPRISE))
1540 {
1541 Profile->EapAuthMethod = IfrNvData->EapAuthMethod;
1542 Profile->EapSecondAuthMethod = IfrNvData->EapSecondAuthMethod;
1543 StrCpyS (Profile->EapIdentity, EAP_IDENTITY_SIZE, IfrNvData->EapIdentity);
1544 }
1545
1546 break;
1547
1548 default:
1549 break;
1550 }
1551 } else if (Action == EFI_BROWSER_ACTION_CHANGING) {
1552 switch (QuestionId) {
1553 case KEY_NETWORK_LIST:
1554
1555 //
1556 // User triggered a scan process.
1557 //
1558 Private->CurrentNic->OneTimeScanRequest = TRUE;
1559 break;
1560
1561 case KEY_PASSWORD_CONNECT_NETWORK:
1562 case KEY_EAP_PASSWORD_CONNECT_NETWORK:
1563 case KEY_PRIVATE_KEY_PASSWORD:
1564
1565 if (Private->CurrentNic->UserSelectedProfile == NULL) {
1566 break;
1567 }
1568
1569 Profile = Private->CurrentNic->UserSelectedProfile;
1570
1571 if (QuestionId == KEY_PASSWORD_CONNECT_NETWORK) {
1572 TempPassword = Profile->Password;
1573 } else if (QuestionId == KEY_EAP_PASSWORD_CONNECT_NETWORK) {
1574 TempPassword = Profile->EapPassword;
1575 } else {
1576 TempPassword = Profile->PrivateKeyPassword;
1577 }
1578
1579 Status = WifiMgrRecordPassword (Private, Value->string, TempPassword, PASSWORD_STORAGE_SIZE);
1580 if (EFI_ERROR (Status)) {
1581 DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Error: Failed to input password!"));
1582 break;
1583 }
1584
1585 //
1586 // This password is not a new created password, so no need to confirm.
1587 //
1588 Status = EFI_NOT_FOUND;
1589 break;
1590
1591 case KEY_CONNECT_ACTION:
1592
1593 ErrorMessage = NULL;
1594 ProfileToConnect = NULL;
1595
1596 if (Private->CurrentNic->UserSelectedProfile == NULL) {
1597 break;
1598 }
1599
1600 Profile = Private->CurrentNic->UserSelectedProfile;
1601
1602 if ((Private->CurrentNic->ConnectState == WifiMgrDisconnected) ||
1603 (Profile != Private->CurrentNic->CurrentOperateNetwork))
1604 {
1605 //
1606 // When this network is not currently connected, pend it to connect.
1607 //
1608 if (Profile->AKMSuiteSupported && Profile->CipherSuiteSupported) {
1609 if ((Profile->SecurityType == SECURITY_TYPE_NONE) ||
1610 (Profile->SecurityType == SECURITY_TYPE_WPA2_PERSONAL) ||
1611 (Profile->SecurityType == SECURITY_TYPE_WPA3_PERSONAL))
1612 {
1613 //
1614 // For Open network, connect directly.
1615 //
1616 ProfileToConnect = Profile;
1617 } else if ((Profile->SecurityType == SECURITY_TYPE_WPA2_ENTERPRISE) ||
1618 (Profile->SecurityType == SECURITY_TYPE_WPA3_ENTERPRISE))
1619 {
1620 //
1621 // For WPA/WPA2-Enterprise network, conduct eap configuration first.
1622 // Only EAP-TLS, TTLS and PEAP is supported now!
1623 //
1624 Profile->EapAuthMethod = IfrNvData->EapAuthMethod;
1625 StrCpyS (Profile->EapIdentity, EAP_IDENTITY_SIZE, IfrNvData->EapIdentity);
1626
1627 if ((IfrNvData->EapAuthMethod == EAP_AUTH_METHOD_TTLS) || (IfrNvData->EapAuthMethod == EAP_AUTH_METHOD_PEAP)) {
1628 Profile->EapSecondAuthMethod = IfrNvData->EapSecondAuthMethod;
1629 ProfileToConnect = Profile;
1630 } else if (IfrNvData->EapAuthMethod == EAP_AUTH_METHOD_TLS) {
1631 ProfileToConnect = Profile;
1632 } else {
1633 ErrorMessage = L"ERROR: Only EAP-TLS, TTLS or PEAP is supported now!";
1634 }
1635 } else {
1636 ErrorMessage = L"ERROR: Can't connect to this network!";
1637 }
1638 } else {
1639 ErrorMessage = L"ERROR: This network is not supported!";
1640 }
1641
1642 if (ErrorMessage != NULL) {
1643 CreatePopUp (
1644 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1645 &Key,
1646 ErrorMessage,
1647 NULL
1648 );
1649 }
1650
1651 if (ProfileToConnect != NULL) {
1652 Private->CurrentNic->OneTimeConnectRequest = TRUE;
1653 Private->CurrentNic->ConnectPendingNetwork = ProfileToConnect;
1654 }
1655 } else if (Private->CurrentNic->ConnectState == WifiMgrConnectedToAp) {
1656 //
1657 // This network is currently connected, just disconnect from it.
1658 //
1659 Private->CurrentNic->OneTimeDisconnectRequest = TRUE;
1660 Private->CurrentNic->HasDisconnectPendingNetwork = TRUE;
1661 }
1662
1663 break;
1664
1665 case KEY_ENROLL_CA_CERT_CONNECT_NETWORK:
1666
1667 Private->FileType = FileTypeCACert;
1668 break;
1669
1670 case KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK:
1671
1672 Private->FileType = FileTypeClientCert;
1673 break;
1674
1675 case KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE:
1676
1677 FilePath = NULL;
1678 ChooseFile (NULL, NULL, NULL, &FilePath);
1679
1680 if (FilePath != NULL) {
1681 UpdatePrivateKeyFromFile (Private, FilePath);
1682 FreePool (FilePath);
1683 }
1684
1685 break;
1686
1687 case KEY_EAP_ENROLL_CERT_FROM_FILE:
1688
1689 //
1690 // User will select a cert file from File Explore
1691 //
1692 FilePath = NULL;
1693 ChooseFile (NULL, NULL, NULL, &FilePath);
1694
1695 if (FilePath != NULL) {
1696 UpdateCAFromFile (Private, FilePath);
1697 FreePool (FilePath);
1698 }
1699
1700 break;
1701
1702 case KEY_SAVE_PRIVATE_KEY_TO_MEM:
1703
1704 if ((Private->FileContext != NULL) && (Private->FileContext->FHandle != NULL) &&
1705 (Private->CurrentNic->UserSelectedProfile != NULL))
1706 {
1707 //
1708 // Read Private Key file to Buffer
1709 //
1710 Profile = Private->CurrentNic->UserSelectedProfile;
1711 if (Profile->PrivateKeyData != NULL) {
1712 ZeroMem (Profile->PrivateKeyData, Profile->PrivateKeyDataSize);
1713 FreePool (Profile->PrivateKeyData);
1714 Profile->PrivateKeyData = NULL;
1715 }
1716
1717 Status = WifiMgrReadFileToBuffer (
1718 Private->FileContext,
1719 &TempData,
1720 &TempDataSize
1721 );
1722 if (EFI_ERROR (Status)) {
1723 CreatePopUp (
1724 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1725 &Key,
1726 L"ERROR: Can't read this private key file!",
1727 NULL
1728 );
1729 } else {
1730 ASSERT (Private->FileContext->FileName != NULL);
1731
1732 Profile->PrivateKeyData = TempData;
1733 Profile->PrivateKeyDataSize = TempDataSize;
1734 StrCpyS (Profile->PrivateKeyName, WIFI_FILENAME_STR_MAX_SIZE, Private->FileContext->FileName);
1735
1736 DEBUG ((
1737 DEBUG_INFO,
1738 "[WiFi Connection Manager] Private Key: %s has been enrolled! Size: %d\n",
1739 Profile->PrivateKeyName,
1740 Profile->PrivateKeyDataSize
1741 ));
1742 }
1743 }
1744
1745 break;
1746
1747 case KEY_SAVE_CERT_TO_MEM:
1748
1749 if ((Private->FileContext != NULL) && (Private->FileContext->FHandle != NULL) &&
1750 (Private->CurrentNic->UserSelectedProfile != NULL))
1751 {
1752 //
1753 // Read Cert file to Buffer
1754 //
1755 Profile = Private->CurrentNic->UserSelectedProfile;
1756
1757 if (Private->FileType == FileTypeCACert) {
1758 if (Profile->CACertData != NULL) {
1759 ZeroMem (Profile->CACertData, Profile->CACertSize);
1760 FreePool (Profile->CACertData);
1761 Profile->CACertData = NULL;
1762 }
1763 } else if (Private->FileType == FileTypeClientCert) {
1764 if (Profile->ClientCertData != NULL) {
1765 ZeroMem (Profile->ClientCertData, Profile->ClientCertSize);
1766 FreePool (Profile->ClientCertData);
1767 Profile->ClientCertData = NULL;
1768 }
1769 } else {
1770 break;
1771 }
1772
1773 Status = WifiMgrReadFileToBuffer (
1774 Private->FileContext,
1775 &TempData,
1776 &TempDataSize
1777 );
1778 if (EFI_ERROR (Status)) {
1779 CreatePopUp (
1780 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1781 &Key,
1782 L"ERROR: Can't read this certificate file!",
1783 NULL
1784 );
1785 } else {
1786 ASSERT (Private->FileContext->FileName != NULL);
1787 if (Private->FileType == FileTypeCACert) {
1788 Profile->CACertData = TempData;
1789 Profile->CACertSize = TempDataSize;
1790 StrCpyS (Profile->CACertName, WIFI_FILENAME_STR_MAX_SIZE, Private->FileContext->FileName);
1791 DEBUG ((
1792 DEBUG_INFO,
1793 "[WiFi Connection Manager] CA Cert: %s has been enrolled! Size: %d\n",
1794 Profile->CACertName,
1795 Profile->CACertSize
1796 ));
1797 } else {
1798 Profile->ClientCertData = TempData;
1799 Profile->ClientCertSize = TempDataSize;
1800 StrCpyS (Profile->ClientCertName, WIFI_FILENAME_STR_MAX_SIZE, Private->FileContext->FileName);
1801 DEBUG ((
1802 DEBUG_INFO,
1803 "[WiFi Connection Manager] Client Cert: %s has been enrolled! Size: %d\n",
1804 Profile->ClientCertName,
1805 Profile->ClientCertSize
1806 ));
1807 }
1808 }
1809 }
1810
1811 break;
1812
1813 case KEY_ADD_HIDDEN_NETWORK:
1814
1815 //
1816 // Add a Hidden Network
1817 //
1818 if ((StrLen (IfrNvData->SSId) < SSID_MIN_LEN) ||
1819 (Private->HiddenNetworkCount >= HIDDEN_NETWORK_LIST_COUNT_MAX))
1820 {
1821 Status = EFI_ABORTED;
1822 break;
1823 } else {
1824 //
1825 // Check if this SSId is already in Hidden Network List
1826 //
1827 NET_LIST_FOR_EACH (Entry, &Private->HiddenNetworkList) {
1828 HiddenNetwork = NET_LIST_USER_STRUCT_S (
1829 Entry,
1830 WIFI_HIDDEN_NETWORK_DATA,
1831 Link,
1832 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
1833 );
1834 if (StrCmp (HiddenNetwork->SSId, IfrNvData->SSId) == 0) {
1835 Status = EFI_ABORTED;
1836 break;
1837 }
1838 }
1839 }
1840
1841 HiddenNetwork = (WIFI_HIDDEN_NETWORK_DATA *)AllocateZeroPool (sizeof (WIFI_HIDDEN_NETWORK_DATA));
1842 if (HiddenNetwork == NULL) {
1843 Status = EFI_OUT_OF_RESOURCES;
1844 break;
1845 }
1846
1847 HiddenNetwork->Signature = WIFI_MGR_HIDDEN_NETWORK_SIGNATURE;
1848 StrCpyS (HiddenNetwork->SSId, SSID_STORAGE_SIZE, IfrNvData->SSId);
1849
1850 InsertTailList (&Private->HiddenNetworkList, &HiddenNetwork->Link);
1851 Private->HiddenNetworkCount++;
1852
1853 WifiMgrRefreshHiddenList (Private);
1854 break;
1855
1856 case KEY_REMOVE_HIDDEN_NETWORK:
1857
1858 //
1859 // Remove Hidden Networks
1860 //
1861 Entry = GetFirstNode (&Private->HiddenNetworkList);
1862 RemoveCount = 0;
1863 for (Index = 0; Index < Private->HiddenNetworkCount; Index++) {
1864 if (IfrNvData->HiddenNetworkList[Index] != 0) {
1865 HiddenNetwork = NET_LIST_USER_STRUCT_S (Entry, WIFI_HIDDEN_NETWORK_DATA, Link, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE);
1866 Entry = RemoveEntryList (Entry);
1867 RemoveCount++;
1868
1869 FreePool (HiddenNetwork);
1870 } else {
1871 Entry = GetNextNode (&Private->HiddenNetworkList, Entry);
1872 }
1873 }
1874
1875 Private->HiddenNetworkCount -= RemoveCount;
1876 WifiMgrRefreshHiddenList (Private);
1877 break;
1878
1879 default:
1880
1881 if ((QuestionId >= KEY_MAC_ENTRY_BASE) && (QuestionId < KEY_MAC_ENTRY_BASE + Private->NicCount)) {
1882 //
1883 // User selects a wireless NIC.
1884 //
1885 Status = WifiMgrSelectNic (Private, QuestionId);
1886 if (EFI_ERROR (Status)) {
1887 CreatePopUp (
1888 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1889 &Key,
1890 L"ERROR: Fail to operate the wireless NIC!",
1891 NULL
1892 );
1893 }
1894 } else if (Private->CurrentNic != NULL) {
1895 if ((QuestionId >= KEY_AVAILABLE_NETWORK_ENTRY_BASE) &&
1896 (QuestionId <= KEY_AVAILABLE_NETWORK_ENTRY_BASE + Private->CurrentNic->MaxProfileIndex))
1897 {
1898 Status = WifiMgrUserSelectProfileToConnect (Private, QuestionId - KEY_AVAILABLE_NETWORK_ENTRY_BASE);
1899 if (!EFI_ERROR (Status)) {
1900 WifiMgrUpdateConnectMessage (Private->CurrentNic, FALSE, NULL);
1901 }
1902 }
1903
1904 if (EFI_ERROR (Status)) {
1905 CreatePopUp (
1906 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1907 &Key,
1908 L"ERROR: Fail to operate this profile!",
1909 NULL
1910 );
1911 }
1912 }
1913
1914 break;
1915 }
1916 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
1917 switch (QuestionId) {
1918 case KEY_SAVE_CERT_TO_MEM:
1919 case KEY_SAVE_PRIVATE_KEY_TO_MEM:
1920
1921 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
1922 break;
1923
1924 case KEY_NO_SAVE_CERT_TO_MEM:
1925 case KEY_NO_SAVE_PRIVATE_KEY_TO_MEM:
1926
1927 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
1928 break;
1929
1930 default:
1931
1932 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
1933 break;
1934 }
1935 } else if (Action == EFI_BROWSER_ACTION_RETRIEVE) {
1936 switch (QuestionId) {
1937 case KEY_REFRESH_NETWORK_LIST:
1938
1939 WifiMgrRefreshNetworkList (Private, IfrNvData);
1940 break;
1941
1942 default:
1943 break;
1944 }
1945 }
1946
1947 if (!EFI_ERROR (Status)) {
1948 //
1949 // Pass changed uncommitted data back to Form Browser.
1950 //
1951 BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);
1952 HiiSetBrowserData (&gWifiConfigFormSetGuid, mVendorStorageName, BufferSize, (UINT8 *)IfrNvData, NULL);
1953 }
1954
1955 ZeroMem (IfrNvData, sizeof (WIFI_MANAGER_IFR_NVDATA));
1956 FreePool (IfrNvData);
1957 return Status;
1958 }
1959
1960 /**
1961 Initialize the WiFi configuration form.
1962
1963 @param[in] Private The pointer to the global private data structure.
1964
1965 @retval EFI_SUCCESS The configuration form is initialized.
1966 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1967 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1968 @retval Other Erros Returned Errors when installing protocols.
1969
1970 **/
1971 EFI_STATUS
1972 WifiMgrDxeConfigFormInit (
1973 WIFI_MGR_PRIVATE_DATA *Private
1974 )
1975 {
1976 EFI_STATUS Status;
1977
1978 if (Private == NULL) {
1979 return EFI_INVALID_PARAMETER;
1980 }
1981
1982 Private->ConfigAccess.ExtractConfig = WifiMgrDxeHiiConfigAccessExtractConfig;
1983 Private->ConfigAccess.RouteConfig = WifiMgrDxeHiiConfigAccessRouteConfig;
1984 Private->ConfigAccess.Callback = WifiMgrDxeHiiConfigAccessCallback;
1985
1986 //
1987 // Install Device Path Protocol and Config Access protocol to driver handle.
1988 //
1989 Status = gBS->InstallMultipleProtocolInterfaces (
1990 &Private->DriverHandle,
1991 &gEfiDevicePathProtocolGuid,
1992 &mWifiMgrDxeHiiVendorDevicePath,
1993 &gEfiHiiConfigAccessProtocolGuid,
1994 &Private->ConfigAccess,
1995 NULL
1996 );
1997 if (EFI_ERROR (Status)) {
1998 return Status;
1999 }
2000
2001 //
2002 // Publish our HII data.
2003 //
2004 Private->RegisteredHandle = HiiAddPackages (
2005 &gWifiConfigFormSetGuid,
2006 Private->DriverHandle,
2007 WifiConnectionManagerDxeStrings,
2008 WifiConnectionManagerDxeBin,
2009 NULL
2010 );
2011 if (Private->RegisteredHandle == NULL) {
2012 gBS->UninstallMultipleProtocolInterfaces (
2013 Private->DriverHandle,
2014 &gEfiDevicePathProtocolGuid,
2015 &mWifiMgrDxeHiiVendorDevicePath,
2016 &gEfiHiiConfigAccessProtocolGuid,
2017 &Private->ConfigAccess,
2018 NULL
2019 );
2020 return EFI_OUT_OF_RESOURCES;
2021 }
2022
2023 Private->FileContext = AllocateZeroPool (sizeof (WIFI_MGR_FILE_CONTEXT));
2024 if (Private->FileContext == NULL) {
2025 return EFI_OUT_OF_RESOURCES;
2026 }
2027
2028 return EFI_SUCCESS;
2029 }
2030
2031 /**
2032 Unload the WiFi configuration form.
2033
2034 @param[in] Private The pointer to the global private data structure.
2035
2036 @retval EFI_SUCCESS The configuration form is unloaded successfully.
2037 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
2038 @retval Other Errors Returned Erros when uninstalling protocols.
2039
2040 **/
2041 EFI_STATUS
2042 WifiMgrDxeConfigFormUnload (
2043 WIFI_MGR_PRIVATE_DATA *Private
2044 )
2045 {
2046 EFI_STATUS Status;
2047
2048 if (Private == NULL) {
2049 return EFI_INVALID_PARAMETER;
2050 }
2051
2052 if (Private->FileContext != NULL) {
2053 if (Private->FileContext->FHandle != NULL) {
2054 Private->FileContext->FHandle->Close (Private->FileContext->FHandle);
2055 }
2056
2057 if (Private->FileContext->FileName != NULL) {
2058 FreePool (Private->FileContext->FileName);
2059 }
2060
2061 FreePool (Private->FileContext);
2062 }
2063
2064 HiiRemovePackages (Private->RegisteredHandle);
2065
2066 Status = gBS->UninstallMultipleProtocolInterfaces (
2067 Private->DriverHandle,
2068 &gEfiDevicePathProtocolGuid,
2069 &mWifiMgrDxeHiiVendorDevicePath,
2070 &gEfiHiiConfigAccessProtocolGuid,
2071 &Private->ConfigAccess,
2072 NULL
2073 );
2074
2075 return Status;
2076 }