]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
4ad5643c2453a47ee005d10228f4850ccaf9939b
[mirror_edk2.git] / NetworkPkg / WifiConnectionManagerDxe / WifiConnectionMgrMisc.c
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 //
16 STATIC 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 **/
37 VOID
38 EFIAPI
39 WifiMgrInternalEmptyFunction (
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 **/
55 VOID
56 WifiMgrMacAddrToStr (
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 **/
91 EFI_STATUS
92 WifiMgrReadFileToBuffer (
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 **/
128 WIFI_MGR_DEVICE_DATA *
129 WifiMgrGetNicByIndex (
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 **/
166 WIFI_MGR_NETWORK_PROFILE *
167 WifiMgrGetProfileByUnicodeSSId (
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 **/
205 WIFI_MGR_NETWORK_PROFILE *
206 WifiMgrGetProfileByAsciiSSId (
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 **/
234 WIFI_MGR_NETWORK_PROFILE *
235 WifiMgrGetProfileByProfileIndex (
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 **/
271 BOOLEAN
272 WifiMgrSupportAKMSuite (
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 **/
305 BOOLEAN
306 WifiMgrSupportCipherSuite (
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 **/
348 EFI_STATUS
349 WifiMgrCheckRSN (
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 **/
476 UINT8
477 WifiMgrGetSecurityType (
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 **/
570 EFI_STATUS
571 WifiMgrGetSupportedSuites (
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 **/
670 VOID
671 WifiMgrCleanProfileSecrets (
672 IN WIFI_MGR_NETWORK_PROFILE *Profile
673 )
674 {
675 ZeroMem (Profile->Password, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
676 ZeroMem (Profile->EapPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
677 ZeroMem (Profile->PrivateKeyPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
678
679 if (Profile->CACertData != NULL) {
680 ZeroMem (Profile->CACertData, Profile->CACertSize);
681 FreePool (Profile->CACertData);
682 }
683
684 Profile->CACertData = NULL;
685 Profile->CACertSize = 0;
686
687 if (Profile->ClientCertData != NULL) {
688 ZeroMem (Profile->ClientCertData, Profile->ClientCertSize);
689 FreePool (Profile->ClientCertData);
690 }
691
692 Profile->ClientCertData = NULL;
693 Profile->ClientCertSize = 0;
694
695 if (Profile->PrivateKeyData != NULL) {
696 ZeroMem (Profile->PrivateKeyData, Profile->PrivateKeyDataSize);
697 FreePool (Profile->PrivateKeyData);
698 }
699
700 Profile->PrivateKeyData = NULL;
701 Profile->PrivateKeyDataSize = 0;
702 }
703
704 /**
705 Free all network profiles in a profile list.
706
707 @param[in] ProfileList The profile list to be freed.
708
709 **/
710 VOID
711 WifiMgrFreeProfileList (
712 IN LIST_ENTRY *ProfileList
713 )
714 {
715 WIFI_MGR_NETWORK_PROFILE *Profile;
716 LIST_ENTRY *Entry;
717 LIST_ENTRY *NextEntry;
718
719 if (ProfileList == NULL) {
720 return;
721 }
722
723 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, ProfileList) {
724 Profile = NET_LIST_USER_STRUCT_S (
725 Entry,
726 WIFI_MGR_NETWORK_PROFILE,
727 Link,
728 WIFI_MGR_PROFILE_SIGNATURE
729 );
730
731 WifiMgrCleanProfileSecrets (Profile);
732
733 if (Profile->Network.AKMSuite != NULL) {
734 FreePool (Profile->Network.AKMSuite);
735 }
736
737 if (Profile->Network.CipherSuite != NULL) {
738 FreePool (Profile->Network.CipherSuite);
739 }
740
741 FreePool (Profile);
742 }
743 }
744
745 /**
746 Free user configured hidden network list.
747
748 @param[in] HiddenList The hidden network list to be freed.
749
750 **/
751 VOID
752 WifiMgrFreeHiddenList (
753 IN LIST_ENTRY *HiddenList
754 )
755 {
756 WIFI_HIDDEN_NETWORK_DATA *HiddenNetwork;
757 LIST_ENTRY *Entry;
758 LIST_ENTRY *NextEntry;
759
760 if (HiddenList == NULL) {
761 return;
762 }
763
764 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, HiddenList) {
765 HiddenNetwork = NET_LIST_USER_STRUCT_S (
766 Entry,
767 WIFI_HIDDEN_NETWORK_DATA,
768 Link,
769 WIFI_MGR_HIDDEN_NETWORK_SIGNATURE
770 );
771 FreePool (HiddenNetwork);
772 }
773 }
774
775 /**
776 Free the resources of a config token.
777
778 @param[in] ConfigToken The config token to be freed.
779 **/
780 VOID
781 WifiMgrFreeToken (
782 IN WIFI_MGR_MAC_CONFIG_TOKEN *ConfigToken
783 )
784 {
785 EFI_80211_GET_NETWORKS_RESULT *Result;
786
787 if (ConfigToken == NULL) {
788 return;
789 }
790
791 switch (ConfigToken->Type) {
792 case TokenTypeGetNetworksToken:
793
794 if (ConfigToken->Token.GetNetworksToken != NULL) {
795 gBS->CloseEvent (ConfigToken->Token.GetNetworksToken->Event);
796 if (ConfigToken->Token.GetNetworksToken->Data != NULL) {
797 FreePool (ConfigToken->Token.GetNetworksToken->Data);
798 }
799
800 Result = ConfigToken->Token.GetNetworksToken->Result;
801 if (Result != NULL) {
802 FreePool (Result);
803 }
804
805 FreePool (ConfigToken->Token.GetNetworksToken);
806 }
807
808 FreePool (ConfigToken);
809 break;
810
811 case TokenTypeConnectNetworkToken:
812
813 if (ConfigToken->Token.ConnectNetworkToken != NULL) {
814 gBS->CloseEvent (ConfigToken->Token.ConnectNetworkToken->Event);
815 if (ConfigToken->Token.ConnectNetworkToken->Data != NULL) {
816 FreePool (ConfigToken->Token.ConnectNetworkToken->Data);
817 }
818
819 FreePool (ConfigToken->Token.ConnectNetworkToken);
820 }
821
822 FreePool (ConfigToken);
823 break;
824
825 case TokenTypeDisconnectNetworkToken:
826
827 if (ConfigToken->Token.DisconnectNetworkToken != NULL) {
828 FreePool (ConfigToken->Token.DisconnectNetworkToken);
829 }
830
831 FreePool (ConfigToken);
832 break;
833
834 default:
835 break;
836 }
837 }