2 The driver binding protocol for the WiFi Connection Manager.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "WifiConnectionMgrDxe.h"
19 /// Driver Binding Protocol instance
21 EFI_DRIVER_BINDING_PROTOCOL gWifiMgrDxeDriverBinding
= {
22 WifiMgrDxeDriverBindingSupported
,
23 WifiMgrDxeDriverBindingStart
,
24 WifiMgrDxeDriverBindingStop
,
31 //The private global data for WiFi Connection Manager
33 WIFI_MGR_PRIVATE_DATA
*mPrivate
= NULL
;
36 //The private guid to identify WiFi Connection Manager
38 EFI_GUID mEfiWifiMgrPrivateGuid
= EFI_WIFIMGR_PRIVATE_GUID
;
41 //The Hii config guids
43 EFI_GUID gWifiConfigFormSetGuid
= WIFI_CONNECTION_MANAGER_CONFIG_GUID
;
44 EFI_GUID mWifiConfigNetworkListRefreshGuid
= WIFI_CONFIG_NETWORK_LIST_REFRESH_GUID
;
45 EFI_GUID mWifiConfigConnectFormRefreshGuid
= WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID
;
46 EFI_GUID mWifiConfigMainFormRefreshGuid
= WIFI_CONFIG_MAIN_FORM_REFRESH_GUID
;
49 Tests to see if this driver supports a given controller. If a child device is provided,
50 it further tests to see if this driver supports creating a handle for the specified child device.
52 This function checks to see if the driver specified by This supports the device specified by
53 ControllerHandle. Drivers will typically use the device path attached to
54 ControllerHandle and/or the services from the bus I/O abstraction attached to
55 ControllerHandle to determine if the driver supports ControllerHandle. This function
56 may be called many times during platform initialization. In order to reduce boot times, the tests
57 performed by this function must be very small, and take as little time as possible to execute. This
58 function must not change the state of any hardware devices, and this function must be aware that the
59 device specified by ControllerHandle may already be managed by the same driver or a
60 different driver. This function must match its calls to AllocatePages() with FreePages(),
61 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
62 Because ControllerHandle may have been previously started by the same driver, if a protocol is
63 already in the opened state, then it must not be closed with CloseProtocol(). This is required
64 to guarantee the state of ControllerHandle is not modified by this function.
66 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
67 @param[in] ControllerHandle The handle of the controller to test. This handle
68 must support a protocol interface that supplies
69 an I/O abstraction to the driver.
70 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
71 parameter is ignored by device drivers, and is optional for bus
72 drivers. For bus drivers, if this parameter is not NULL, then
73 the bus driver must determine if the bus controller specified
74 by ControllerHandle and the child controller specified
75 by RemainingDevicePath are both supported by this
78 @retval EFI_SUCCESS The device specified by ControllerHandle and
79 RemainingDevicePath is supported by the driver specified by This.
80 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
81 RemainingDevicePath is already being managed by the driver
83 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
84 RemainingDevicePath is already being managed by a different
85 driver or an application that requires exclusive access.
86 Currently not implemented.
87 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
88 RemainingDevicePath is not supported by the driver specified by This.
93 WifiMgrDxeDriverBindingSupported (
94 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
95 IN EFI_HANDLE ControllerHandle
,
96 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
101 Status
= gBS
->OpenProtocol (
103 &mEfiWifiMgrPrivateGuid
,
105 This
->DriverBindingHandle
,
107 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
109 if (!EFI_ERROR (Status
)) {
110 return EFI_ALREADY_STARTED
;
114 // Test for the wireless MAC connection 2 protocol
116 return gBS
->OpenProtocol (
118 &gEfiWiFi2ProtocolGuid
,
120 This
->DriverBindingHandle
,
122 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
127 Starts a device controller or a bus controller.
129 The Start() function is designed to be invoked from the EFI boot service ConnectController().
130 As a result, much of the error checking on the parameters to Start() has been moved into this
131 common boot service. It is legal to call Start() from other locations,
132 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
133 1. ControllerHandle must be a valid EFI_HANDLE.
134 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
135 EFI_DEVICE_PATH_PROTOCOL.
136 3. Prior to calling Start(), the Supported() function for the driver specified by This must
137 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
139 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
140 @param[in] ControllerHandle The handle of the controller to start. This handle
141 must support a protocol interface that supplies
142 an I/O abstraction to the driver.
143 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
144 parameter is ignored by device drivers, and is optional for bus
145 drivers. For a bus driver, if this parameter is NULL, then handles
146 for all the children of Controller are created by this driver.
147 If this parameter is not NULL and the first Device Path Node is
148 not the End of Device Path Node, then only the handle for the
149 child device specified by the first Device Path Node of
150 RemainingDevicePath is created by this driver.
151 If the first Device Path Node of RemainingDevicePath is
152 the End of Device Path Node, no child handle is created by this
155 @retval EFI_SUCCESS The device was started.
156 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
157 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
158 @retval Others The driver failded to start the device.
163 WifiMgrDxeDriverBindingStart (
164 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
165 IN EFI_HANDLE ControllerHandle
,
166 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
172 WIFI_MGR_DEVICE_DATA
*Nic
;
173 EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL
*Wmp
;
174 EFI_SUPPLICANT_PROTOCOL
*Supplicant
;
175 EFI_EAP_CONFIGURATION_PROTOCOL
*EapConfig
;
182 Status
= gBS
->OpenProtocol (
184 &gEfiWiFi2ProtocolGuid
,
186 This
->DriverBindingHandle
,
188 EFI_OPEN_PROTOCOL_BY_DRIVER
190 if (EFI_ERROR (Status
)) {
194 Status
= gBS
->OpenProtocol (
196 &gEfiSupplicantProtocolGuid
,
197 (VOID
**) &Supplicant
,
198 This
->DriverBindingHandle
,
200 EFI_OPEN_PROTOCOL_BY_DRIVER
202 if (EFI_ERROR (Status
)) {
206 Status
= gBS
->OpenProtocol (
208 &gEfiEapConfigurationProtocolGuid
,
210 This
->DriverBindingHandle
,
212 EFI_OPEN_PROTOCOL_BY_DRIVER
214 if (EFI_ERROR (Status
)) {
219 //Initialize Nic device data
221 Nic
= AllocateZeroPool (sizeof (WIFI_MGR_DEVICE_DATA
));
223 Status
= EFI_OUT_OF_RESOURCES
;
226 Nic
->Signature
= WIFI_MGR_DEVICE_DATA_SIGNATURE
;
227 Nic
->DriverHandle
= This
->DriverBindingHandle
;
228 Nic
->ControllerHandle
= ControllerHandle
;
229 Nic
->Private
= mPrivate
;
231 Nic
->Supplicant
= Supplicant
;
232 Nic
->EapConfig
= EapConfig
;
233 Nic
->UserSelectedProfile
= NULL
;
234 Nic
->OneTimeScanRequest
= FALSE
;
235 Nic
->ScanTickTime
= WIFI_SCAN_FREQUENCY
; //Initialize the first scan
237 if (Nic
->Supplicant
!= NULL
) {
238 WifiMgrGetSupportedSuites(Nic
);
241 InitializeListHead (&Nic
->ProfileList
);
244 // Record the MAC address of the incoming NIC.
246 Status
= NetLibGetMacAddress (
248 (EFI_MAC_ADDRESS
*) &Nic
->MacAddress
,
251 if (EFI_ERROR (Status
)) {
256 // Create and start the timer for the status check
258 Status
= gBS
->CreateEvent (
259 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
265 if (EFI_ERROR (Status
)) {
269 Status
= gBS
->SetTimer (Nic
->TickTimer
, TimerPeriodic
, EFI_TIMER_PERIOD_MILLISECONDS(500));
270 if (EFI_ERROR (Status
)) {
274 Nic
->ConnectState
= WifiMgrDisconnected
;
275 Nic
->ScanState
= WifiMgrScanFinished
;
277 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
278 InsertTailList (&mPrivate
->NicList
, &Nic
->Link
);
279 Nic
->NicIndex
= mPrivate
->NicCount
++;
280 if (mPrivate
->CurrentNic
== NULL
) {
281 mPrivate
->CurrentNic
= Nic
;
283 gBS
->RestoreTPL (OldTpl
);
285 Status
= gBS
->InstallProtocolInterface (
287 &mEfiWifiMgrPrivateGuid
,
288 EFI_NATIVE_INTERFACE
,
289 &Nic
->WifiMgrIdentifier
291 if (EFI_ERROR (Status
)) {
299 gBS
->SetTimer (Nic
->TickTimer
, TimerCancel
, 0);
300 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
301 RemoveEntryList (&Nic
->Link
);
302 mPrivate
->NicCount
--;
303 gBS
->RestoreTPL (OldTpl
);
307 gBS
->CloseEvent (Nic
->TickTimer
);
311 if (Nic
->Supplicant
!= NULL
) {
312 if (Nic
->SupportedSuites
.SupportedAKMSuites
!= NULL
) {
313 FreePool (Nic
->SupportedSuites
.SupportedAKMSuites
);
315 if (Nic
->SupportedSuites
.SupportedSwCipherSuites
!= NULL
) {
316 FreePool (Nic
->SupportedSuites
.SupportedSwCipherSuites
);
318 if (Nic
->SupportedSuites
.SupportedHwCipherSuites
!= NULL
) {
319 FreePool (Nic
->SupportedSuites
.SupportedHwCipherSuites
);
326 if (Supplicant
!= NULL
) {
329 &gEfiSupplicantProtocolGuid
,
330 This
->DriverBindingHandle
,
335 if (EapConfig
!= NULL
) {
338 &gEfiEapConfigurationProtocolGuid
,
339 This
->DriverBindingHandle
,
346 &gEfiWiFi2ProtocolGuid
,
347 This
->DriverBindingHandle
,
355 Stops a device controller or a bus controller.
357 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
358 As a result, much of the error checking on the parameters to Stop() has been moved
359 into this common boot service. It is legal to call Stop() from other locations,
360 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
361 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
362 same driver's Start() function.
363 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
364 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
365 Start() function, and the Start() function must have called OpenProtocol() on
366 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
368 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
369 @param[in] ControllerHandle A handle to the device being stopped. The handle must
370 support a bus specific I/O protocol for the driver
371 to use to stop the device.
372 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
373 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
374 if NumberOfChildren is 0.
376 @retval EFI_SUCCESS The device was stopped.
377 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
382 WifiMgrDxeDriverBindingStop (
383 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
384 IN EFI_HANDLE ControllerHandle
,
385 IN UINTN NumberOfChildren
,
386 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
391 WIFI_MGR_PRIVATE_PROTOCOL
*WifiMgrIdentifier
;
392 WIFI_MGR_DEVICE_DATA
*Nic
;
394 Status
= gBS
->OpenProtocol (
396 &mEfiWifiMgrPrivateGuid
,
397 (VOID
**) &WifiMgrIdentifier
,
398 This
->DriverBindingHandle
,
400 EFI_OPEN_PROTOCOL_GET_PROTOCOL
402 if (EFI_ERROR (Status
)) {
403 return EFI_DEVICE_ERROR
;
406 Nic
= WIFI_MGR_DEVICE_DATA_FROM_IDENTIFIER (WifiMgrIdentifier
);
408 return EFI_DEVICE_ERROR
;
414 gBS
->CloseEvent (Nic
->TickTimer
);
417 // Clean Supported Suites
419 if (Nic
->Supplicant
!= NULL
) {
420 if (Nic
->SupportedSuites
.SupportedAKMSuites
!= NULL
) {
421 FreePool (Nic
->SupportedSuites
.SupportedAKMSuites
);
423 if (Nic
->SupportedSuites
.SupportedSwCipherSuites
!= NULL
) {
424 FreePool (Nic
->SupportedSuites
.SupportedSwCipherSuites
);
426 if (Nic
->SupportedSuites
.SupportedHwCipherSuites
!= NULL
) {
427 FreePool (Nic
->SupportedSuites
.SupportedHwCipherSuites
);
434 Status
= gBS
->UninstallProtocolInterface (
436 &mEfiWifiMgrPrivateGuid
,
437 &Nic
->WifiMgrIdentifier
439 if (EFI_ERROR (Status
)) {
443 Status
= gBS
->CloseProtocol (
445 &gEfiWiFi2ProtocolGuid
,
447 Nic
->ControllerHandle
449 if (EFI_ERROR (Status
)) {
453 if (Nic
->Supplicant
!= NULL
) {
454 Status
= gBS
->CloseProtocol (
456 &gEfiSupplicantProtocolGuid
,
458 Nic
->ControllerHandle
460 if (EFI_ERROR (Status
)) {
465 if (Nic
->EapConfig
!= NULL
) {
466 Status
= gBS
->CloseProtocol (
468 &gEfiEapConfigurationProtocolGuid
,
470 Nic
->ControllerHandle
472 if (EFI_ERROR (Status
)) {
478 // Remove this Nic from Nic list
480 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
482 RemoveEntryList (&Nic
->Link
);
483 mPrivate
->NicCount
--;
484 if (mPrivate
->CurrentNic
== Nic
) {
485 mPrivate
->CurrentNic
= NULL
;
488 gBS
->RestoreTPL (OldTpl
);
490 WifiMgrFreeProfileList (&Nic
->ProfileList
);
493 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Device Controller has been Disconnected!\n"));
498 This is the declaration of an EFI image entry point. This entry point is
499 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
500 both device drivers and bus drivers.
502 @param ImageHandle The firmware allocated handle for the UEFI image.
503 @param SystemTable A pointer to the EFI System Table.
505 @retval EFI_SUCCESS The operation completed successfully.
506 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
507 @retval Others An unexpected error occurred.
512 WifiMgrDxeDriverEntryPoint (
513 IN EFI_HANDLE ImageHandle
,
514 IN EFI_SYSTEM_TABLE
*SystemTable
519 Status
= EfiLibInstallDriverBindingComponentName2 (
522 &gWifiMgrDxeDriverBinding
,
524 &gWifiMgrDxeComponentName
,
525 &gWifiMgrDxeComponentName2
527 if (EFI_ERROR (Status
)) {
532 // Initialize the global private data structure.
534 mPrivate
= AllocateZeroPool (sizeof (WIFI_MGR_PRIVATE_DATA
));
535 if (mPrivate
== NULL
) {
536 Status
= EFI_OUT_OF_RESOURCES
;
539 mPrivate
->Signature
= WIFI_MGR_PRIVATE_DATA_SIGNATURE
;
540 mPrivate
->DriverHandle
= ImageHandle
;
541 InitializeListHead (&mPrivate
->NicList
);
542 mPrivate
->NicCount
= 0;
543 mPrivate
->CurrentNic
= NULL
;
544 InitializeListHead (&mPrivate
->HiddenNetworkList
);
545 mPrivate
->HiddenNetworkCount
= 0;
548 //Create events for page refresh
550 Status
= gBS
->CreateEventEx (
553 WifiMgrInternalEmptyFunction
,
555 &mWifiConfigNetworkListRefreshGuid
,
556 &mPrivate
->NetworkListRefreshEvent
558 if (EFI_ERROR (Status
)) {
562 Status
= gBS
->CreateEventEx (
565 WifiMgrInternalEmptyFunction
,
567 &mWifiConfigConnectFormRefreshGuid
,
568 &mPrivate
->ConnectFormRefreshEvent
570 if (EFI_ERROR (Status
)) {
574 Status
= gBS
->CreateEventEx (
577 WifiMgrInternalEmptyFunction
,
579 &mWifiConfigMainFormRefreshGuid
,
580 &mPrivate
->MainPageRefreshEvent
582 if (EFI_ERROR (Status
)) {
586 Status
= WifiMgrDxeConfigFormInit (mPrivate
);
587 if (EFI_ERROR (Status
)) {
594 gBS
->CloseEvent (mPrivate
->MainPageRefreshEvent
);
597 gBS
->CloseEvent (mPrivate
->ConnectFormRefreshEvent
);
600 gBS
->CloseEvent (mPrivate
->NetworkListRefreshEvent
);
603 if (mPrivate
!= NULL
) {
609 gBS
->UninstallMultipleProtocolInterfaces (
611 &gEfiDriverBindingProtocolGuid
,
612 &gWifiMgrDxeDriverBinding
,
613 &gEfiComponentNameProtocolGuid
,
614 &gWifiMgrDxeComponentName
,
615 &gEfiComponentName2ProtocolGuid
,
616 &gWifiMgrDxeComponentName2
,