TianoCore EDK2 master
Loading...
Searching...
No Matches
WifiConnectionMgrDriver.c
Go to the documentation of this file.
1
11
19 WIFI_MGR_DXE_VERSION,
20 NULL,
21 NULL
22};
23
24//
25// The private global data for WiFi Connection Manager
26//
27WIFI_MGR_PRIVATE_DATA *mPrivate = NULL;
28
29//
30// The private guid to identify WiFi Connection Manager
31//
32EFI_GUID mEfiWifiMgrPrivateGuid = EFI_WIFIMGR_PRIVATE_GUID;
33
34//
35// The Hii config guids
36//
37EFI_GUID gWifiConfigFormSetGuid = WIFI_CONNECTION_MANAGER_CONFIG_GUID;
38EFI_GUID mWifiConfigNetworkListRefreshGuid = WIFI_CONFIG_NETWORK_LIST_REFRESH_GUID;
39EFI_GUID mWifiConfigConnectFormRefreshGuid = WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID;
40EFI_GUID mWifiConfigMainFormRefreshGuid = WIFI_CONFIG_MAIN_FORM_REFRESH_GUID;
41
42//
43// Wifi connection attempt counter for retries
44//
45extern UINT8 mWifiConnectionCount;
46
91EFIAPI
94 IN EFI_HANDLE ControllerHandle,
95 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
96 )
97{
98 EFI_STATUS Status;
99
100 Status = gBS->OpenProtocol (
101 ControllerHandle,
102 &mEfiWifiMgrPrivateGuid,
103 NULL,
104 This->DriverBindingHandle,
105 ControllerHandle,
106 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
107 );
108 if (!EFI_ERROR (Status)) {
109 return EFI_ALREADY_STARTED;
110 }
111
112 //
113 // Test for the wireless MAC connection 2 protocol
114 //
115 return gBS->OpenProtocol (
116 ControllerHandle,
117 &gEfiWiFi2ProtocolGuid,
118 NULL,
119 This->DriverBindingHandle,
120 ControllerHandle,
121 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
122 );
123}
124
161EFIAPI
164 IN EFI_HANDLE ControllerHandle,
165 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
166 )
167{
168 EFI_STATUS Status;
169 EFI_TPL OldTpl;
170 UINTN AddressSize;
173 EFI_SUPPLICANT_PROTOCOL *Supplicant;
175 EDKII_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;
176
177 mWifiConnectionCount = 0;
178 Nic = NULL;
179
180 //
181 // Open Protocols
182 //
183 Status = gBS->OpenProtocol (
184 ControllerHandle,
185 &gEfiWiFi2ProtocolGuid,
186 (VOID **)&Wmp,
187 This->DriverBindingHandle,
188 ControllerHandle,
189 EFI_OPEN_PROTOCOL_BY_DRIVER
190 );
191 if (EFI_ERROR (Status)) {
192 return Status;
193 }
194
195 Status = gBS->OpenProtocol (
196 ControllerHandle,
197 &gEfiSupplicantProtocolGuid,
198 (VOID **)&Supplicant,
199 This->DriverBindingHandle,
200 ControllerHandle,
201 EFI_OPEN_PROTOCOL_BY_DRIVER
202 );
203 if (EFI_ERROR (Status)) {
204 Supplicant = NULL;
205 }
206
207 Status = gBS->OpenProtocol (
208 ControllerHandle,
209 &gEfiEapConfigurationProtocolGuid,
210 (VOID **)&EapConfig,
211 This->DriverBindingHandle,
212 ControllerHandle,
213 EFI_OPEN_PROTOCOL_BY_DRIVER
214 );
215 if (EFI_ERROR (Status)) {
216 EapConfig = NULL;
217 }
218
219 //
220 // Initialize Nic device data
221 //
222 Nic = AllocateZeroPool (sizeof (WIFI_MGR_DEVICE_DATA));
223 if (Nic == NULL) {
224 Status = EFI_OUT_OF_RESOURCES;
225 goto ERROR1;
226 }
227
228 Nic->Signature = WIFI_MGR_DEVICE_DATA_SIGNATURE;
229 Nic->DriverHandle = This->DriverBindingHandle;
230 Nic->ControllerHandle = ControllerHandle;
231 Nic->Private = mPrivate;
232 Nic->Wmp = Wmp;
233 Nic->Supplicant = Supplicant;
234 Nic->EapConfig = EapConfig;
235 Nic->UserSelectedProfile = NULL;
236 Nic->OneTimeScanRequest = FALSE;
237 Nic->ScanTickTime = WIFI_SCAN_FREQUENCY; // Initialize the first scan
238
239 if (Nic->Supplicant != NULL) {
241 }
242
243 InitializeListHead (&Nic->ProfileList);
244
245 //
246 // WiFi profile sync protocol installation check for OS recovery flow.
247 //
248 Status = gBS->LocateProtocol (
249 &gEdkiiWiFiProfileSyncProtocolGuid,
250 NULL,
251 (VOID **)&WiFiProfileSyncProtocol
252 );
253 if (!EFI_ERROR (Status)) {
254 Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));
255 if (Nic->ConnectPendingNetwork == NULL) {
256 Status = EFI_OUT_OF_RESOURCES;
257 goto ERROR1;
258 }
259
260 WiFiProfileSyncProtocol->GetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);
261 if (Nic->ConnectPendingNetwork != NULL) {
262 Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);
263 if (!EFI_ERROR (Status)) {
264 goto ERROR1;
265 }
266
267 WiFiProfileSyncProtocol->SetConnectState (Status);
268 }
269 } else {
270 //
271 // Record the MAC address of the incoming NIC.
272 //
273 Status = NetLibGetMacAddress (
274 ControllerHandle,
275 (EFI_MAC_ADDRESS *)&Nic->MacAddress,
276 &AddressSize
277 );
278 if (EFI_ERROR (Status)) {
279 goto ERROR2;
280 }
281
282 //
283 // Create and start the timer for the status check
284 //
285 Status = gBS->CreateEvent (
286 EVT_NOTIFY_SIGNAL | EVT_TIMER,
287 TPL_CALLBACK,
289 Nic,
290 &Nic->TickTimer
291 );
292 if (EFI_ERROR (Status)) {
293 goto ERROR2;
294 }
295
296 Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));
297 if (EFI_ERROR (Status)) {
298 goto ERROR3;
299 }
300
301 Nic->ConnectState = WifiMgrDisconnected;
302 Nic->ScanState = WifiMgrScanFinished;
303
304 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
305 InsertTailList (&mPrivate->NicList, &Nic->Link);
306 Nic->NicIndex = mPrivate->NicCount++;
307 if (mPrivate->CurrentNic == NULL) {
308 mPrivate->CurrentNic = Nic;
309 }
310
311 gBS->RestoreTPL (OldTpl);
312 }
313
314 Status = gBS->InstallProtocolInterface (
315 &ControllerHandle,
316 &mEfiWifiMgrPrivateGuid,
318 &Nic->WifiMgrIdentifier
319 );
320 if (EFI_ERROR (Status)) {
321 goto ERROR4;
322 }
323
324 return EFI_SUCCESS;
325
326ERROR4:
327
328 gBS->SetTimer (Nic->TickTimer, TimerCancel, 0);
329 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
330 RemoveEntryList (&Nic->Link);
331 mPrivate->NicCount--;
332 gBS->RestoreTPL (OldTpl);
333
334ERROR3:
335
336 gBS->CloseEvent (Nic->TickTimer);
337
338ERROR2:
339
340 if (Nic->Supplicant != NULL) {
341 if (Nic->SupportedSuites.SupportedAKMSuites != NULL) {
342 FreePool (Nic->SupportedSuites.SupportedAKMSuites);
343 }
344
345 if (Nic->SupportedSuites.SupportedSwCipherSuites != NULL) {
346 FreePool (Nic->SupportedSuites.SupportedSwCipherSuites);
347 }
348
349 if (Nic->SupportedSuites.SupportedHwCipherSuites != NULL) {
350 FreePool (Nic->SupportedSuites.SupportedHwCipherSuites);
351 }
352 }
353
354 FreePool (Nic);
355
356ERROR1:
357
358 if (Supplicant != NULL) {
359 gBS->CloseProtocol (
360 ControllerHandle,
361 &gEfiSupplicantProtocolGuid,
362 This->DriverBindingHandle,
363 ControllerHandle
364 );
365 }
366
367 if (EapConfig != NULL) {
368 gBS->CloseProtocol (
369 ControllerHandle,
370 &gEfiEapConfigurationProtocolGuid,
371 This->DriverBindingHandle,
372 ControllerHandle
373 );
374 }
375
376 gBS->CloseProtocol (
377 ControllerHandle,
378 &gEfiWiFi2ProtocolGuid,
379 This->DriverBindingHandle,
380 ControllerHandle
381 );
382
383 return Status;
384}
385
413EFIAPI
416 IN EFI_HANDLE ControllerHandle,
417 IN UINTN NumberOfChildren,
418 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
419 )
420{
421 EFI_STATUS Status;
422 EFI_TPL OldTpl;
423 WIFI_MGR_PRIVATE_PROTOCOL *WifiMgrIdentifier;
425 EDKII_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;
426
427 Status = gBS->OpenProtocol (
428 ControllerHandle,
429 &mEfiWifiMgrPrivateGuid,
430 (VOID **)&WifiMgrIdentifier,
431 This->DriverBindingHandle,
432 ControllerHandle,
433 EFI_OPEN_PROTOCOL_GET_PROTOCOL
434 );
435 if (EFI_ERROR (Status)) {
436 return EFI_DEVICE_ERROR;
437 }
438
439 Nic = WIFI_MGR_DEVICE_DATA_FROM_IDENTIFIER (WifiMgrIdentifier);
440 if (Nic == NULL) {
441 return EFI_DEVICE_ERROR;
442 }
443
444 //
445 // Close Event
446 //
447 gBS->SetTimer (Nic->TickTimer, TimerCancel, 0);
448 gBS->CloseEvent (Nic->TickTimer);
449
450 //
451 // Clean Supported Suites
452 //
453 if (Nic->Supplicant != NULL) {
454 if (Nic->SupportedSuites.SupportedAKMSuites != NULL) {
455 FreePool (Nic->SupportedSuites.SupportedAKMSuites);
456 }
457
458 if (Nic->SupportedSuites.SupportedSwCipherSuites != NULL) {
459 FreePool (Nic->SupportedSuites.SupportedSwCipherSuites);
460 }
461
462 if (Nic->SupportedSuites.SupportedHwCipherSuites != NULL) {
463 FreePool (Nic->SupportedSuites.SupportedHwCipherSuites);
464 }
465 }
466
467 //
468 // Close Protocols
469 //
470 Status = gBS->UninstallProtocolInterface (
471 ControllerHandle,
472 &mEfiWifiMgrPrivateGuid,
473 &Nic->WifiMgrIdentifier
474 );
475 if (EFI_ERROR (Status)) {
476 return Status;
477 }
478
479 Status = gBS->CloseProtocol (
480 ControllerHandle,
481 &gEfiWiFi2ProtocolGuid,
482 Nic->DriverHandle,
483 Nic->ControllerHandle
484 );
485 if (EFI_ERROR (Status)) {
486 return Status;
487 }
488
489 if (Nic->Supplicant != NULL) {
490 Status = gBS->CloseProtocol (
491 ControllerHandle,
492 &gEfiSupplicantProtocolGuid,
493 Nic->DriverHandle,
494 Nic->ControllerHandle
495 );
496 if (EFI_ERROR (Status)) {
497 return Status;
498 }
499 }
500
501 if (Nic->EapConfig != NULL) {
502 Status = gBS->CloseProtocol (
503 ControllerHandle,
504 &gEfiEapConfigurationProtocolGuid,
505 Nic->DriverHandle,
506 Nic->ControllerHandle
507 );
508 if (EFI_ERROR (Status)) {
509 return Status;
510 }
511 }
512
513 //
514 // Remove this Nic from Nic list
515 //
516 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
517
518 Status = gBS->LocateProtocol (
519 &gEdkiiWiFiProfileSyncProtocolGuid,
520 NULL,
521 (VOID **)&WiFiProfileSyncProtocol
522 );
523 if (EFI_ERROR (Status)) {
524 RemoveEntryList (&Nic->Link);
525 }
526
527 mPrivate->NicCount--;
528 if (mPrivate->CurrentNic == Nic) {
529 mPrivate->CurrentNic = NULL;
530 }
531
532 gBS->RestoreTPL (OldTpl);
533
534 WifiMgrFreeProfileList (&Nic->ProfileList);
535 FreePool (Nic);
536
537 DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Device Controller has been Disconnected!\n"));
538 return EFI_SUCCESS;
539}
540
555EFIAPI
557 IN EFI_HANDLE ImageHandle,
558 IN EFI_SYSTEM_TABLE *SystemTable
559 )
560{
561 EFI_STATUS Status;
562
564 ImageHandle,
565 SystemTable,
567 ImageHandle,
570 );
571 if (EFI_ERROR (Status)) {
572 return Status;
573 }
574
575 //
576 // Initialize the global private data structure.
577 //
578 mPrivate = AllocateZeroPool (sizeof (WIFI_MGR_PRIVATE_DATA));
579 if (mPrivate == NULL) {
580 Status = EFI_OUT_OF_RESOURCES;
581 goto ERROR1;
582 }
583
584 mPrivate->Signature = WIFI_MGR_PRIVATE_DATA_SIGNATURE;
585 mPrivate->DriverHandle = ImageHandle;
586 InitializeListHead (&mPrivate->NicList);
587 mPrivate->NicCount = 0;
588 mPrivate->CurrentNic = NULL;
589 InitializeListHead (&mPrivate->HiddenNetworkList);
590 mPrivate->HiddenNetworkCount = 0;
591
592 //
593 // Create events for page refresh
594 //
595 Status = gBS->CreateEventEx (
596 EVT_NOTIFY_SIGNAL,
597 TPL_CALLBACK,
599 NULL,
600 &mWifiConfigNetworkListRefreshGuid,
601 &mPrivate->NetworkListRefreshEvent
602 );
603 if (EFI_ERROR (Status)) {
604 goto ERROR2;
605 }
606
607 Status = gBS->CreateEventEx (
608 EVT_NOTIFY_SIGNAL,
609 TPL_CALLBACK,
611 NULL,
612 &mWifiConfigConnectFormRefreshGuid,
613 &mPrivate->ConnectFormRefreshEvent
614 );
615 if (EFI_ERROR (Status)) {
616 goto ERROR3;
617 }
618
619 Status = gBS->CreateEventEx (
620 EVT_NOTIFY_SIGNAL,
621 TPL_CALLBACK,
623 NULL,
624 &mWifiConfigMainFormRefreshGuid,
625 &mPrivate->MainPageRefreshEvent
626 );
627 if (EFI_ERROR (Status)) {
628 goto ERROR4;
629 }
630
631 Status = WifiMgrDxeConfigFormInit (mPrivate);
632 if (EFI_ERROR (Status)) {
633 goto ERROR5;
634 }
635
636 return Status;
637
638ERROR5:
639 gBS->CloseEvent (mPrivate->MainPageRefreshEvent);
640
641ERROR4:
642 gBS->CloseEvent (mPrivate->ConnectFormRefreshEvent);
643
644ERROR3:
645 gBS->CloseEvent (mPrivate->NetworkListRefreshEvent);
646
647ERROR2:
648 if (mPrivate != NULL) {
649 FreePool (mPrivate);
650 mPrivate = NULL;
651 }
652
653ERROR1:
654 gBS->UninstallMultipleProtocolInterfaces (
655 ImageHandle,
656 &gEfiDriverBindingProtocolGuid,
658 &gEfiComponentNameProtocolGuid,
660 &gEfiComponentName2ProtocolGuid,
662 NULL
663 );
664
665 return Status;
666}
UINT64 UINTN
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI NetLibGetMacAddress(IN EFI_HANDLE ServiceHandle, OUT EFI_MAC_ADDRESS *MacAddress, OUT UINTN *AddressSize)
Definition: DxeNetLib.c:2251
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define EFI_TIMER_PERIOD_MILLISECONDS(Milliseconds)
Definition: UefiLib.h:86
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
@ TimerCancel
Definition: UefiSpec.h:531
@ TimerPeriodic
Definition: UefiSpec.h:535
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gWifiMgrDxeComponentName
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gWifiMgrDxeComponentName2
EFI_DRIVER_BINDING_PROTOCOL gWifiMgrDxeDriverBinding
EFI_STATUS EFIAPI WifiMgrDxeDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI WifiMgrDxeDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
EFI_STATUS EFIAPI WifiMgrDxeDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS EFIAPI WifiMgrDxeDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS WifiMgrDxeConfigFormInit(WIFI_MGR_PRIVATE_DATA *Private)
VOID EFIAPI WifiMgrOnTimerTick(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS WifiMgrConnectToNetwork(IN WIFI_MGR_DEVICE_DATA *Nic, IN WIFI_MGR_NETWORK_PROFILE *Profile)
VOID WifiMgrFreeProfileList(IN LIST_ENTRY *ProfileList)
VOID EFIAPI WifiMgrInternalEmptyFunction(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS WifiMgrGetSupportedSuites(IN WIFI_MGR_DEVICE_DATA *Nic)
Definition: Base.h:213