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