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