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