VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c

最後變更 在這個檔案是 99404,由 vboxsync 提交於 20 月 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 23.8 KB
 
1/** @file
2 The Miscellaneous Routines for WiFi Connection Manager.
3
4 Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include "WifiConnectionMgrDxe.h"
11
12//
13// STA AKM preference order
14// REF: https://www.wi-fi.org/file/wpa3-specification
15//
16STATIC UINT32 mAKMSuitePreference[] = {
17 IEEE_80211_AKM_SUITE_8021X_SUITE_B192, // AKM Suite 12
18 IEEE_80211_AKM_SUITE_8021X_SUITE_B, // AKM Suite 11
19 IEEE_80211_AKM_SUITE_8021X_OR_PMKSA_SHA256, // AKM Suite 5
20 IEEE_80211_AKM_SUITE_8021X_OR_PMKSA, // AKM Suite 1
21
22 IEEE_80211_AKM_SUITE_SAE, // AKM Suite 8
23 IEEE_80211_AKM_SUITE_PSK_SHA256, // AKM Suite 6
24 IEEE_80211_AKM_SUITE_PSK, // AKM Suite 2
25
26 IEEE_80211_AKM_SUITE_OWE // AKM Suite 18
27};
28#define AKM_SUITE_PREFERENCE_COUNT (sizeof (mAKMSuitePreference) / sizeof (UINT32))
29
30/**
31 Empty function for event process function.
32
33 @param Event The Event need to be process
34 @param Context The context of the event.
35
36**/
37VOID
38EFIAPI
39WifiMgrInternalEmptyFunction (
40 IN EFI_EVENT Event,
41 IN VOID *Context
42 )
43{
44 return;
45}
46
47/**
48 Convert the mac address into a hexadecimal encoded ":" seperated string.
49
50 @param[in] Mac The mac address.
51 @param[in] StrSize The size, in bytes, of the output buffer specified by Str.
52 @param[out] Str The storage to return the mac string.
53
54**/
55VOID
56WifiMgrMacAddrToStr (
57 IN EFI_80211_MAC_ADDRESS *Mac,
58 IN UINT32 StrSize,
59 OUT CHAR16 *Str
60 )
61{
62 if ((Mac == NULL) || (Str == NULL)) {
63 return;
64 }
65
66 UnicodeSPrint (
67 Str,
68 StrSize,
69 L"%02X:%02X:%02X:%02X:%02X:%02X",
70 Mac->Addr[0],
71 Mac->Addr[1],
72 Mac->Addr[2],
73 Mac->Addr[3],
74 Mac->Addr[4],
75 Mac->Addr[5]
76 );
77}
78
79/**
80 Read private key file to buffer.
81
82 @param[in] FileContext The file context of private key file.
83 @param[out] PrivateKeyDataAddr The buffer address to restore private key file, should be
84 freed by caller.
85 @param[out] PrivateKeyDataSize The size of read private key file.
86
87 @retval EFI_SUCCESS Successfully read the private key file.
88 @retval EFI_INVALID_PARAMETER One or more of the parameters is invalid.
89
90**/
91EFI_STATUS
92WifiMgrReadFileToBuffer (
93 IN WIFI_MGR_FILE_CONTEXT *FileContext,
94 OUT VOID **DataAddr,
95 OUT UINTN *DataSize
96 )
97{
98 EFI_STATUS Status;
99
100 if ((FileContext != NULL) && (FileContext->FHandle != NULL)) {
101 Status = ReadFileContent (
102 FileContext->FHandle,
103 DataAddr,
104 DataSize,
105 0
106 );
107
108 if (FileContext->FHandle != NULL) {
109 FileContext->FHandle->Close (FileContext->FHandle);
110 }
111
112 FileContext->FHandle = NULL;
113 return Status;
114 }
115
116 return EFI_INVALID_PARAMETER;
117}
118
119/**
120 Get the Nic data by the NicIndex.
121
122 @param[in] Private The pointer to the global private data structure.
123 @param[in] NicIndex The index indicates the position of wireless NIC.
124
125 @return Pointer to the Nic data, or NULL if not found.
126
127**/
128WIFI_MGR_DEVICE_DATA *
129WifiMgrGetNicByIndex (
130 IN WIFI_MGR_PRIVATE_DATA *Private,
131 IN UINT32 NicIndex
132 )
133{
134 LIST_ENTRY *Entry;
135 WIFI_MGR_DEVICE_DATA *Nic;
136
137 if (Private == NULL) {
138 return NULL;
139 }
140
141 NET_LIST_FOR_EACH (Entry, &Private->NicList) {
142 Nic = NET_LIST_USER_STRUCT_S (
143 Entry,
144 WIFI_MGR_DEVICE_DATA,
145 Link,
146 WIFI_MGR_DEVICE_DATA_SIGNATURE
147 );
148 if (Nic->NicIndex == NicIndex) {
149 return Nic;
150 }
151 }
152
153 return NULL;
154}
155
156/**
157 Find a network profile through its' SSId and securit type, and the SSId is an unicode string.
158
159 @param[in] SSId The target network's SSId.
160 @param[in] SecurityType The target network's security type.
161 @param[in] ProfileList The profile list on a Nic.
162
163 @return Pointer to a network profile, or NULL if not found.
164
165**/
166WIFI_MGR_NETWORK_PROFILE *
167WifiMgrGetProfileByUnicodeSSId (
168 IN CHAR16 *SSId,
169 IN UINT8 SecurityType,
170 IN LIST_ENTRY *ProfileList
171 )
172{
173 LIST_ENTRY *Entry;
174 WIFI_MGR_NETWORK_PROFILE *Profile;
175
176 if ((SSId == NULL) || (ProfileList == NULL)) {
177 return NULL;
178 }
179
180 NET_LIST_FOR_EACH (Entry, ProfileList) {
181 Profile = NET_LIST_USER_STRUCT_S (
182 Entry,
183 WIFI_MGR_NETWORK_PROFILE,
184 Link,
185 WIFI_MGR_PROFILE_SIGNATURE
186 );
187 if ((StrCmp (SSId, Profile->SSId) == 0) && (SecurityType == Profile->SecurityType)) {
188 return Profile;
189 }
190 }
191
192 return NULL;
193}
194
195/**
196 Find a network profile through its' SSId and securit type, and the SSId is an ascii string.
197
198 @param[in] SSId The target network's SSId.
199 @param[in] SecurityType The target network's security type.
200 @param[in] ProfileList The profile list on a Nic.
201
202 @return Pointer to a network profile, or NULL if not found.
203
204**/
205WIFI_MGR_NETWORK_PROFILE *
206WifiMgrGetProfileByAsciiSSId (
207 IN CHAR8 *SSId,
208 IN UINT8 SecurityType,
209 IN LIST_ENTRY *ProfileList
210 )
211{
212 CHAR16 SSIdUniCode[SSID_STORAGE_SIZE];
213
214 if (SSId == NULL) {
215 return NULL;
216 }
217
218 if (AsciiStrToUnicodeStrS (SSId, SSIdUniCode, SSID_STORAGE_SIZE) != RETURN_SUCCESS) {
219 return NULL;
220 }
221
222 return WifiMgrGetProfileByUnicodeSSId (SSIdUniCode, SecurityType, ProfileList);
223}
224
225/**
226 Find a network profile through its' profile index.
227
228 @param[in] ProfileIndex The target network's profile index.
229 @param[in] ProfileList The profile list on a Nic.
230
231 @return Pointer to a network profile, or NULL if not found.
232
233**/
234WIFI_MGR_NETWORK_PROFILE *
235WifiMgrGetProfileByProfileIndex (
236 IN UINT32 ProfileIndex,
237 IN LIST_ENTRY *ProfileList
238 )
239{
240 WIFI_MGR_NETWORK_PROFILE *Profile;
241 LIST_ENTRY *Entry;
242
243 if (ProfileList == NULL) {
244 return NULL;
245 }
246
247 NET_LIST_FOR_EACH (Entry, ProfileList) {
248 Profile = NET_LIST_USER_STRUCT_S (
249 Entry,
250 WIFI_MGR_NETWORK_PROFILE,
251 Link,
252 WIFI_MGR_PROFILE_SIGNATURE
253 );
254 if (Profile->ProfileIndex == ProfileIndex) {
255 return Profile;
256 }
257 }
258 return NULL;
259}
260
261/**
262 To test if the AKMSuite is in supported AKMSuite list.
263
264 @param[in] SupportedAKMSuiteCount The count of the supported AKMSuites.
265 @param[in] SupportedAKMSuiteList The supported AKMSuite list.
266 @param[in] AKMSuite The AKMSuite to be tested.
267
268 @return True if this AKMSuite is supported, or False if not.
269
270**/
271BOOLEAN
272WifiMgrSupportAKMSuite (
273 IN UINT16 SupportedAKMSuiteCount,
274 IN UINT32 *SupportedAKMSuiteList,
275 IN UINT32 *AKMSuite
276 )
277{
278 UINT16 Index;
279
280 if ((AKMSuite == NULL) || (SupportedAKMSuiteList == NULL) ||
281 (SupportedAKMSuiteCount == 0))
282 {
283 return FALSE;
284 }
285
286 for (Index = 0; Index < SupportedAKMSuiteCount; Index++) {
287 if (SupportedAKMSuiteList[Index] == *AKMSuite) {
288 return TRUE;
289 }
290 }
291
292 return FALSE;
293}
294
295/**
296 To check if the CipherSuite is in supported CipherSuite list.
297
298 @param[in] SupportedCipherSuiteCount The count of the supported CipherSuites.
299 @param[in] SupportedCipherSuiteList The supported CipherSuite list.
300 @param[in] CipherSuite The CipherSuite to be tested.
301
302 @return True if this CipherSuite is supported, or False if not.
303
304**/
305BOOLEAN
306WifiMgrSupportCipherSuite (
307 IN UINT16 SupportedCipherSuiteCount,
308 IN UINT32 *SupportedCipherSuiteList,
309 IN UINT32 *CipherSuite
310 )
311{
312 UINT16 Index;
313
314 if ((CipherSuite == NULL) || (SupportedCipherSuiteCount == 0) ||
315 (SupportedCipherSuiteList == NULL))
316 {
317 return FALSE;
318 }
319
320 for (Index = 0; Index < SupportedCipherSuiteCount; Index++) {
321 if (SupportedCipherSuiteList[Index] == *CipherSuite) {
322 return TRUE;
323 }
324 }
325
326 return FALSE;
327}
328
329/**
330 Check an AKM suite list and a Cipher suite list to see if one or more AKM suites or Cipher suites
331 are supported and find the matchable security type.
332
333 @param[in] AKMList The target AKM suite list to be checked.
334 @param[in] CipherList The target Cipher suite list to be checked
335 @param[in] Nic The Nic to operate, contains the supported AKMSuite list
336 and supported CipherSuite list
337 @param[out] SecurityType To identify a security type from the AKM suite list and
338 Cipher suite list
339 @param[out] AKMSuiteSupported To identify if this security type is supported. If it is
340 NULL, overcome this field
341 @param[out] CipherSuiteSupported To identify if this security type is supported. If it is
342 NULL, overcome this field
343
344 @retval EFI_SUCCESS This operation has completed successfully.
345 @retval EFI_INVALID_PARAMETER No Nic found or the suite list is null.
346
347**/
348EFI_STATUS
349WifiMgrCheckRSN (
350 IN EFI_80211_AKM_SUITE_SELECTOR *AKMList,
351 IN EFI_80211_CIPHER_SUITE_SELECTOR *CipherList,
352 IN WIFI_MGR_DEVICE_DATA *Nic,
353 OUT UINT8 *SecurityType,
354 OUT BOOLEAN *AKMSuiteSupported,
355 OUT BOOLEAN *CipherSuiteSupported
356 )
357{
358 EFI_80211_AKM_SUITE_SELECTOR *SupportedAKMSuites;
359 EFI_80211_CIPHER_SUITE_SELECTOR *SupportedSwCipherSuites;
360 EFI_80211_CIPHER_SUITE_SELECTOR *SupportedHwCipherSuites;
361 UINT32 *AKMSuite;
362 EFI_80211_SUITE_SELECTOR *CipherSuite;
363 UINT16 AKMIndex;
364 UINT16 CipherIndex;
365
366 if ((Nic == NULL) || (AKMList == NULL) || (CipherList == NULL) || (SecurityType == NULL)) {
367 return EFI_INVALID_PARAMETER;
368 }
369
370 SupportedAKMSuites = Nic->SupportedSuites.SupportedAKMSuites;
371 SupportedSwCipherSuites = Nic->SupportedSuites.SupportedSwCipherSuites;
372 SupportedHwCipherSuites = Nic->SupportedSuites.SupportedHwCipherSuites;
373
374 *SecurityType = SECURITY_TYPE_UNKNOWN;
375 if ((AKMSuiteSupported != NULL) && (CipherSuiteSupported != NULL)) {
376 *AKMSuiteSupported = FALSE;
377 *CipherSuiteSupported = FALSE;
378 }
379
380 if (AKMList->AKMSuiteCount == 0) {
381 if (CipherList->CipherSuiteCount == 0) {
382 *SecurityType = SECURITY_TYPE_NONE;
383 if ((AKMSuiteSupported != NULL) && (CipherSuiteSupported != NULL)) {
384 *AKMSuiteSupported = TRUE;
385 *CipherSuiteSupported = TRUE;
386 }
387 }
388
389 return EFI_SUCCESS;
390 }
391
392 for (AKMIndex = 0; AKMIndex < AKM_SUITE_PREFERENCE_COUNT; AKMIndex++) {
393 AKMSuite = mAKMSuitePreference + AKMIndex;
394 if (WifiMgrSupportAKMSuite (AKMList->AKMSuiteCount, (UINT32 *)AKMList->AKMSuiteList, AKMSuite) &&
395 WifiMgrSupportAKMSuite (SupportedAKMSuites->AKMSuiteCount, (UINT32 *)SupportedAKMSuites->AKMSuiteList, AKMSuite))
396 {
397 if ((AKMSuiteSupported != NULL) && (CipherSuiteSupported != NULL)) {
398 *AKMSuiteSupported = TRUE;
399 }
400
401 //
402 // OWE transition mode allow CipherSuiteCount is 0
403 //
404 if (CipherList->CipherSuiteCount == 0) {
405 *SecurityType = WifiMgrGetSecurityType ((UINT32 *)AKMSuite, NULL);
406 if (*SecurityType != SECURITY_TYPE_UNKNOWN) {
407 if ((AKMSuiteSupported != NULL) && (CipherSuiteSupported != NULL)) {
408 *CipherSuiteSupported = TRUE;
409 }
410
411 return EFI_SUCCESS;
412 }
413 }
414
415 for (CipherIndex = 0; CipherIndex < CipherList->CipherSuiteCount; CipherIndex++) {
416 CipherSuite = CipherList->CipherSuiteList + CipherIndex;
417
418 if (SupportedSwCipherSuites != NULL) {
419 if (WifiMgrSupportCipherSuite (
420 SupportedSwCipherSuites->CipherSuiteCount,
421 (UINT32 *)SupportedSwCipherSuites->CipherSuiteList,
422 (UINT32 *)CipherSuite
423 ))
424 {
425 *SecurityType = WifiMgrGetSecurityType ((UINT32 *)AKMSuite, (UINT32 *)CipherSuite);
426
427 if (*SecurityType != SECURITY_TYPE_UNKNOWN) {
428 if ((AKMSuiteSupported != NULL) && (CipherSuiteSupported != NULL)) {
429 *CipherSuiteSupported = TRUE;
430 }
431
432 return EFI_SUCCESS;
433 }
434 }
435 }
436
437 if (SupportedHwCipherSuites != NULL) {
438 if (WifiMgrSupportCipherSuite (
439 SupportedHwCipherSuites->CipherSuiteCount,
440 (UINT32 *)SupportedHwCipherSuites->CipherSuiteList,
441 (UINT32 *)CipherSuite
442 ))
443 {
444 *SecurityType = WifiMgrGetSecurityType ((UINT32 *)AKMSuite, (UINT32 *)CipherSuite);
445
446 if (*SecurityType != SECURITY_TYPE_UNKNOWN) {
447 if ((AKMSuiteSupported != NULL) && (CipherSuiteSupported != NULL)) {
448 *CipherSuiteSupported = TRUE;
449 }
450
451 return EFI_SUCCESS;
452 }
453 }
454 }
455 }
456 }
457 }
458
459 *SecurityType = WifiMgrGetSecurityType (
460 (UINT32 *)AKMList->AKMSuiteList,
461 (UINT32 *)CipherList->CipherSuiteList
462 );
463
464 return EFI_SUCCESS;
465}
466
467/**
468 Get the security type for a certain AKMSuite and CipherSuite.
469
470 @param[in] AKMSuite An certain AKMSuite.
471 @param[in] CipherSuite An certain CipherSuite.
472
473 @return a security type if found, or SECURITY_TYPE_UNKNOWN.
474
475**/
476UINT8
477WifiMgrGetSecurityType (
478 IN UINT32 *AKMSuite,
479 IN UINT32 *CipherSuite
480 )
481{
482 if ((AKMSuite != NULL) && (*AKMSuite == IEEE_80211_AKM_SUITE_OWE)) {
483 return SECURITY_TYPE_NONE;
484 }
485
486 if (CipherSuite == NULL) {
487 if (AKMSuite == NULL) {
488 return SECURITY_TYPE_NONE;
489 } else {
490 return SECURITY_TYPE_UNKNOWN;
491 }
492 } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_USE_GROUP) {
493 if (AKMSuite == NULL) {
494 return SECURITY_TYPE_NONE;
495 } else {
496 return SECURITY_TYPE_UNKNOWN;
497 }
498 } else if ((*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_WEP40) ||
499 (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_WEP104))
500 {
501 return SECURITY_TYPE_WEP;
502 } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_CCMP) {
503 if (AKMSuite == NULL) {
504 return SECURITY_TYPE_UNKNOWN;
505 }
506
507 if (*AKMSuite == IEEE_80211_AKM_SUITE_SAE) {
508 return SECURITY_TYPE_WPA3_PERSONAL;
509 } else if ((*AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA) ||
510 (*AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA_SHA256))
511 {
512 return SECURITY_TYPE_WPA2_ENTERPRISE;
513 } else if ((*AKMSuite == IEEE_80211_AKM_SUITE_PSK) ||
514 (*AKMSuite == IEEE_80211_AKM_SUITE_PSK_SHA256))
515 {
516 return SECURITY_TYPE_WPA2_PERSONAL;
517 } else {
518 return SECURITY_TYPE_UNKNOWN;
519 }
520 } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_TKIP) {
521 if (AKMSuite == NULL) {
522 return SECURITY_TYPE_UNKNOWN;
523 }
524
525 if ((*AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA) ||
526 (*AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA_SHA256))
527 {
528 return SECURITY_TYPE_WPA_ENTERPRISE;
529 } else if ((*AKMSuite == IEEE_80211_AKM_SUITE_PSK) ||
530 (*AKMSuite == IEEE_80211_AKM_SUITE_PSK_SHA256))
531 {
532 return SECURITY_TYPE_WPA_PERSONAL;
533 } else {
534 return SECURITY_TYPE_UNKNOWN;
535 }
536 } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_GCMP) {
537 if (AKMSuite == NULL) {
538 return SECURITY_TYPE_UNKNOWN;
539 }
540
541 if (*AKMSuite == IEEE_80211_AKM_SUITE_8021X_SUITE_B) {
542 return SECURITY_TYPE_WPA3_ENTERPRISE;
543 } else {
544 return SECURITY_TYPE_UNKNOWN;
545 }
546 } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_GCMP256) {
547 if (AKMSuite == NULL) {
548 return SECURITY_TYPE_UNKNOWN;
549 }
550
551 if (*AKMSuite == IEEE_80211_AKM_SUITE_8021X_SUITE_B192) {
552 return SECURITY_TYPE_WPA3_ENTERPRISE;
553 } else {
554 return SECURITY_TYPE_UNKNOWN;
555 }
556 } else {
557 return SECURITY_TYPE_UNKNOWN;
558 }
559}
560
561/**
562 Get supported AKMSuites and CipherSuites from supplicant for a Nic.
563
564 @param[in] Nic The Nic to operate.
565
566 @retval EFI_SUCCESS Get the supported suite list successfully.
567 @retval EFI_INVALID_PARAMETER No Nic found or supplicant is NULL.
568
569**/
570EFI_STATUS
571WifiMgrGetSupportedSuites (
572 IN WIFI_MGR_DEVICE_DATA *Nic
573 )
574{
575 EFI_STATUS Status;
576 EFI_SUPPLICANT_PROTOCOL *Supplicant;
577 EFI_80211_AKM_SUITE_SELECTOR *SupportedAKMSuites;
578 EFI_80211_CIPHER_SUITE_SELECTOR *SupportedSwCipherSuites;
579 EFI_80211_CIPHER_SUITE_SELECTOR *SupportedHwCipherSuites;
580 UINTN DataSize;
581
582 SupportedAKMSuites = NULL;
583 SupportedSwCipherSuites = NULL;
584 SupportedHwCipherSuites = NULL;
585
586 if ((Nic == NULL) || (Nic->Supplicant == NULL)) {
587 return EFI_INVALID_PARAMETER;
588 }
589
590 Supplicant = Nic->Supplicant;
591
592 DataSize = 0;
593 Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedAKMSuites, NULL, &DataSize);
594 if ((Status == EFI_BUFFER_TOO_SMALL) && (DataSize > 0)) {
595 SupportedAKMSuites = AllocateZeroPool (DataSize);
596 if (SupportedAKMSuites == NULL) {
597 return EFI_OUT_OF_RESOURCES;
598 }
599
600 Status = Supplicant->GetData (
601 Supplicant,
602 EfiSupplicant80211SupportedAKMSuites,
603 (UINT8 *)SupportedAKMSuites,
604 &DataSize
605 );
606 if (!EFI_ERROR (Status)) {
607 Nic->SupportedSuites.SupportedAKMSuites = SupportedAKMSuites;
608 } else {
609 FreePool (SupportedAKMSuites);
610 }
611 } else {
612 SupportedAKMSuites = NULL;
613 }
614
615 DataSize = 0;
616 Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedSoftwareCipherSuites, NULL, &DataSize);
617 if ((Status == EFI_BUFFER_TOO_SMALL) && (DataSize > 0)) {
618 SupportedSwCipherSuites = AllocateZeroPool (DataSize);
619 if (SupportedSwCipherSuites == NULL) {
620 return EFI_OUT_OF_RESOURCES;
621 }
622
623 Status = Supplicant->GetData (
624 Supplicant,
625 EfiSupplicant80211SupportedSoftwareCipherSuites,
626 (UINT8 *)SupportedSwCipherSuites,
627 &DataSize
628 );
629 if (!EFI_ERROR (Status)) {
630 Nic->SupportedSuites.SupportedSwCipherSuites = SupportedSwCipherSuites;
631 } else {
632 FreePool (SupportedSwCipherSuites);
633 }
634 } else {
635 SupportedSwCipherSuites = NULL;
636 }
637
638 DataSize = 0;
639 Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedHardwareCipherSuites, NULL, &DataSize);
640 if ((Status == EFI_BUFFER_TOO_SMALL) && (DataSize > 0)) {
641 SupportedHwCipherSuites = AllocateZeroPool (DataSize);
642 if (SupportedHwCipherSuites == NULL) {
643 return EFI_OUT_OF_RESOURCES;
644 }
645
646 Status = Supplicant->GetData (
647 Supplicant,
648 EfiSupplicant80211SupportedHardwareCipherSuites,
649 (UINT8 *)SupportedHwCipherSuites,
650 &DataSize
651 );
652 if (!EFI_ERROR (Status)) {
653 Nic->SupportedSuites.SupportedHwCipherSuites = SupportedHwCipherSuites;
654 } else {
655 FreePool (SupportedHwCipherSuites);
656 }
657 } else {
658 SupportedHwCipherSuites = NULL;
659 }
660
661 return EFI_SUCCESS;
662}
663
664/**
665 Clean secrets from a network profile.
666
667 @param[in] Profile The profile to be cleanned.
668
669**/
670VOID
671WifiMgrCleanProfileSecrets (
672 IN WIFI_MGR_NETWORK_PROFILE *Profile
673 )
674{
675 EFI_STATUS Status;
676 EDKII_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;
677
678 ZeroMem (Profile->Password, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
679 ZeroMem (Profile->EapPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
680 ZeroMem (Profile->PrivateKeyPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
681
682 //
683 // When EFI WiFi profile sync protocol is found the system is performing a recovery boot in secure
684 // boot mode. The profile sync driver will manage the CA certificate, client certificate, and key
685 // data, cleaning them at exit boot services.
686 //
687 Status = gBS->LocateProtocol (&gEdkiiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);
688 if (!EFI_ERROR (Status)) {
689 return;
690 }
691
692 if (Profile->CACertData != NULL) {
693 ZeroMem (Profile->CACertData, Profile->CACertSize);
694 FreePool (Profile->CACertData);
695 }
696
697 Profile->CACertData = NULL;
698 Profile->CACertSize = 0;
699
700 if (Profile->ClientCertData != NULL) {
701 ZeroMem (Profile->ClientCertData, Profile->ClientCertSize);
702 FreePool (Profile->ClientCertData);
703 }
704
705 Profile->ClientCertData = NULL;
706 Profile->ClientCertSize = 0;
707
708 if (Profile->PrivateKeyData != NULL) {
709 ZeroMem (Profile->PrivateKeyData, Profile->PrivateKeyDataSize);
710 FreePool (Profile->PrivateKeyData);
711 }
712
713 Profile->PrivateKeyData = NULL;
714 Profile->PrivateKeyDataSize = 0;
715}
716
717/**
718 Free all network profiles in a profile list.
719
720 @param[in] ProfileList The profile list to be freed.
721
722**/
723VOID
724WifiMgrFreeProfileList (
725 IN LIST_ENTRY *ProfileList
726 )
727{
728 WIFI_MGR_NETWORK_PROFILE *Profile;
729 LIST_ENTRY *Entry;
730 LIST_ENTRY *NextEntry;
731
732 if (ProfileList == NULL) {
733 return;
734 }
735
736 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, ProfileList) {
737 Profile = NET_LIST_USER_STRUCT_S (
738 Entry,
739 WIFI_MGR_NETWORK_PROFILE,
740 Link,
741 WIFI_MGR_PROFILE_SIGNATURE
742 );
743
744 WifiMgrCleanProfileSecrets (Profile);
745
746 if (Profile->Network.AKMSuite != NULL) {
747 FreePool (Profile->Network.AKMSuite);
748 }
749
750 if (Profile->Network.CipherSuite != NULL) {
751 FreePool (Profile->Network.CipherSuite);
752 }
753
754 FreePool (Profile);
755 }
756}
757
758/**
759 Free user configured hidden network list.
760
761 @param[in] HiddenList The hidden network list to be freed.
762
763**/
764VOID
765WifiMgrFreeHiddenList (
766 IN LIST_ENTRY *HiddenList
767 )
768{
769 WIFI_HIDDEN_NETWORK_DATA *HiddenNetwork;
770 LIST_ENTRY *Entry;
771 LIST_ENTRY *NextEntry;
772
773 if (HiddenList == NULL) {
774 return;
775 }
776
777 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, HiddenList) {
778 HiddenNetwork = NET_LIST_USER_STRUCT_S (
779 Entry,
780 WIFI_HIDDEN_NETWORK_DATA,
781 Link,
782 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
783 );
784 FreePool (HiddenNetwork);
785 }
786}
787
788/**
789 Free the resources of a config token.
790
791 @param[in] ConfigToken The config token to be freed.
792**/
793VOID
794WifiMgrFreeToken (
795 IN WIFI_MGR_MAC_CONFIG_TOKEN *ConfigToken
796 )
797{
798 EFI_80211_GET_NETWORKS_RESULT *Result;
799
800 if (ConfigToken == NULL) {
801 return;
802 }
803
804 switch (ConfigToken->Type) {
805 case TokenTypeGetNetworksToken:
806
807 if (ConfigToken->Token.GetNetworksToken != NULL) {
808 gBS->CloseEvent (ConfigToken->Token.GetNetworksToken->Event);
809 if (ConfigToken->Token.GetNetworksToken->Data != NULL) {
810 FreePool (ConfigToken->Token.GetNetworksToken->Data);
811 }
812
813 Result = ConfigToken->Token.GetNetworksToken->Result;
814 if (Result != NULL) {
815 FreePool (Result);
816 }
817
818 FreePool (ConfigToken->Token.GetNetworksToken);
819 }
820
821 FreePool (ConfigToken);
822 break;
823
824 case TokenTypeConnectNetworkToken:
825
826 if (ConfigToken->Token.ConnectNetworkToken != NULL) {
827 gBS->CloseEvent (ConfigToken->Token.ConnectNetworkToken->Event);
828 if (ConfigToken->Token.ConnectNetworkToken->Data != NULL) {
829 FreePool (ConfigToken->Token.ConnectNetworkToken->Data);
830 }
831
832 FreePool (ConfigToken->Token.ConnectNetworkToken);
833 }
834
835 FreePool (ConfigToken);
836 break;
837
838 case TokenTypeDisconnectNetworkToken:
839
840 if (ConfigToken->Token.DisconnectNetworkToken != NULL) {
841 FreePool (ConfigToken->Token.DisconnectNetworkToken);
842 }
843
844 FreePool (ConfigToken);
845 break;
846
847 default:
848 break;
849 }
850}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette