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