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