WifiConnectionMgrMisc.c 25 KB

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