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