2 The driver binding protocol for the WiFi Connection Manager.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "WifiConnectionMgrDxe.h"
13 /// Driver Binding Protocol instance
15 EFI_DRIVER_BINDING_PROTOCOL gWifiMgrDxeDriverBinding
= {
16 WifiMgrDxeDriverBindingSupported
,
17 WifiMgrDxeDriverBindingStart
,
18 WifiMgrDxeDriverBindingStop
,
25 //The private global data for WiFi Connection Manager
27 WIFI_MGR_PRIVATE_DATA
*mPrivate
= NULL
;
30 //The private guid to identify WiFi Connection Manager
32 EFI_GUID mEfiWifiMgrPrivateGuid
= EFI_WIFIMGR_PRIVATE_GUID
;
35 //The Hii config guids
37 EFI_GUID gWifiConfigFormSetGuid
= WIFI_CONNECTION_MANAGER_CONFIG_GUID
;
38 EFI_GUID mWifiConfigNetworkListRefreshGuid
= WIFI_CONFIG_NETWORK_LIST_REFRESH_GUID
;
39 EFI_GUID mWifiConfigConnectFormRefreshGuid
= WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID
;
40 EFI_GUID mWifiConfigMainFormRefreshGuid
= WIFI_CONFIG_MAIN_FORM_REFRESH_GUID
;
43 Tests to see if this driver supports a given controller. If a child device is provided,
44 it further tests to see if this driver supports creating a handle for the specified child device.
46 This function checks to see if the driver specified by This supports the device specified by
47 ControllerHandle. Drivers will typically use the device path attached to
48 ControllerHandle and/or the services from the bus I/O abstraction attached to
49 ControllerHandle to determine if the driver supports ControllerHandle. This function
50 may be called many times during platform initialization. In order to reduce boot times, the tests
51 performed by this function must be very small, and take as little time as possible to execute. This
52 function must not change the state of any hardware devices, and this function must be aware that the
53 device specified by ControllerHandle may already be managed by the same driver or a
54 different driver. This function must match its calls to AllocatePages() with FreePages(),
55 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
56 Because ControllerHandle may have been previously started by the same driver, if a protocol is
57 already in the opened state, then it must not be closed with CloseProtocol(). This is required
58 to guarantee the state of ControllerHandle is not modified by this function.
60 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
61 @param[in] ControllerHandle The handle of the controller to test. This handle
62 must support a protocol interface that supplies
63 an I/O abstraction to the driver.
64 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
65 parameter is ignored by device drivers, and is optional for bus
66 drivers. For bus drivers, if this parameter is not NULL, then
67 the bus driver must determine if the bus controller specified
68 by ControllerHandle and the child controller specified
69 by RemainingDevicePath are both supported by this
72 @retval EFI_SUCCESS The device specified by ControllerHandle and
73 RemainingDevicePath is supported by the driver specified by This.
74 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
75 RemainingDevicePath is already being managed by the driver
77 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
78 RemainingDevicePath is already being managed by a different
79 driver or an application that requires exclusive access.
80 Currently not implemented.
81 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
82 RemainingDevicePath is not supported by the driver specified by This.
87 WifiMgrDxeDriverBindingSupported (
88 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
89 IN EFI_HANDLE ControllerHandle
,
90 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
95 Status
= gBS
->OpenProtocol (
97 &mEfiWifiMgrPrivateGuid
,
99 This
->DriverBindingHandle
,
101 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
103 if (!EFI_ERROR (Status
)) {
104 return EFI_ALREADY_STARTED
;
108 // Test for the wireless MAC connection 2 protocol
110 return gBS
->OpenProtocol (
112 &gEfiWiFi2ProtocolGuid
,
114 This
->DriverBindingHandle
,
116 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
121 Starts a device controller or a bus controller.
123 The Start() function is designed to be invoked from the EFI boot service ConnectController().
124 As a result, much of the error checking on the parameters to Start() has been moved into this
125 common boot service. It is legal to call Start() from other locations,
126 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
127 1. ControllerHandle must be a valid EFI_HANDLE.
128 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
129 EFI_DEVICE_PATH_PROTOCOL.
130 3. Prior to calling Start(), the Supported() function for the driver specified by This must
131 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
133 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
134 @param[in] ControllerHandle The handle of the controller to start. This handle
135 must support a protocol interface that supplies
136 an I/O abstraction to the driver.
137 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
138 parameter is ignored by device drivers, and is optional for bus
139 drivers. For a bus driver, if this parameter is NULL, then handles
140 for all the children of Controller are created by this driver.
141 If this parameter is not NULL and the first Device Path Node is
142 not the End of Device Path Node, then only the handle for the
143 child device specified by the first Device Path Node of
144 RemainingDevicePath is created by this driver.
145 If the first Device Path Node of RemainingDevicePath is
146 the End of Device Path Node, no child handle is created by this
149 @retval EFI_SUCCESS The device was started.
150 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
151 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
152 @retval Others The driver failded to start the device.
157 WifiMgrDxeDriverBindingStart (
158 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
159 IN EFI_HANDLE ControllerHandle
,
160 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
166 WIFI_MGR_DEVICE_DATA
*Nic
;
167 EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL
*Wmp
;
168 EFI_SUPPLICANT_PROTOCOL
*Supplicant
;
169 EFI_EAP_CONFIGURATION_PROTOCOL
*EapConfig
;
176 Status
= gBS
->OpenProtocol (
178 &gEfiWiFi2ProtocolGuid
,
180 This
->DriverBindingHandle
,
182 EFI_OPEN_PROTOCOL_BY_DRIVER
184 if (EFI_ERROR (Status
)) {
188 Status
= gBS
->OpenProtocol (
190 &gEfiSupplicantProtocolGuid
,
191 (VOID
**) &Supplicant
,
192 This
->DriverBindingHandle
,
194 EFI_OPEN_PROTOCOL_BY_DRIVER
196 if (EFI_ERROR (Status
)) {
200 Status
= gBS
->OpenProtocol (
202 &gEfiEapConfigurationProtocolGuid
,
204 This
->DriverBindingHandle
,
206 EFI_OPEN_PROTOCOL_BY_DRIVER
208 if (EFI_ERROR (Status
)) {
213 //Initialize Nic device data
215 Nic
= AllocateZeroPool (sizeof (WIFI_MGR_DEVICE_DATA
));
217 Status
= EFI_OUT_OF_RESOURCES
;
220 Nic
->Signature
= WIFI_MGR_DEVICE_DATA_SIGNATURE
;
221 Nic
->DriverHandle
= This
->DriverBindingHandle
;
222 Nic
->ControllerHandle
= ControllerHandle
;
223 Nic
->Private
= mPrivate
;
225 Nic
->Supplicant
= Supplicant
;
226 Nic
->EapConfig
= EapConfig
;
227 Nic
->UserSelectedProfile
= NULL
;
228 Nic
->OneTimeScanRequest
= FALSE
;
229 Nic
->ScanTickTime
= WIFI_SCAN_FREQUENCY
; //Initialize the first scan
231 if (Nic
->Supplicant
!= NULL
) {
232 WifiMgrGetSupportedSuites(Nic
);
235 InitializeListHead (&Nic
->ProfileList
);
238 // Record the MAC address of the incoming NIC.
240 Status
= NetLibGetMacAddress (
242 (EFI_MAC_ADDRESS
*) &Nic
->MacAddress
,
245 if (EFI_ERROR (Status
)) {
250 // Create and start the timer for the status check
252 Status
= gBS
->CreateEvent (
253 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
259 if (EFI_ERROR (Status
)) {
263 Status
= gBS
->SetTimer (Nic
->TickTimer
, TimerPeriodic
, EFI_TIMER_PERIOD_MILLISECONDS(500));
264 if (EFI_ERROR (Status
)) {
268 Nic
->ConnectState
= WifiMgrDisconnected
;
269 Nic
->ScanState
= WifiMgrScanFinished
;
271 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
272 InsertTailList (&mPrivate
->NicList
, &Nic
->Link
);
273 Nic
->NicIndex
= mPrivate
->NicCount
++;
274 if (mPrivate
->CurrentNic
== NULL
) {
275 mPrivate
->CurrentNic
= Nic
;
277 gBS
->RestoreTPL (OldTpl
);
279 Status
= gBS
->InstallProtocolInterface (
281 &mEfiWifiMgrPrivateGuid
,
282 EFI_NATIVE_INTERFACE
,
283 &Nic
->WifiMgrIdentifier
285 if (EFI_ERROR (Status
)) {
293 gBS
->SetTimer (Nic
->TickTimer
, TimerCancel
, 0);
294 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
295 RemoveEntryList (&Nic
->Link
);
296 mPrivate
->NicCount
--;
297 gBS
->RestoreTPL (OldTpl
);
301 gBS
->CloseEvent (Nic
->TickTimer
);
305 if (Nic
->Supplicant
!= NULL
) {
306 if (Nic
->SupportedSuites
.SupportedAKMSuites
!= NULL
) {
307 FreePool (Nic
->SupportedSuites
.SupportedAKMSuites
);
309 if (Nic
->SupportedSuites
.SupportedSwCipherSuites
!= NULL
) {
310 FreePool (Nic
->SupportedSuites
.SupportedSwCipherSuites
);
312 if (Nic
->SupportedSuites
.SupportedHwCipherSuites
!= NULL
) {
313 FreePool (Nic
->SupportedSuites
.SupportedHwCipherSuites
);
320 if (Supplicant
!= NULL
) {
323 &gEfiSupplicantProtocolGuid
,
324 This
->DriverBindingHandle
,
329 if (EapConfig
!= NULL
) {
332 &gEfiEapConfigurationProtocolGuid
,
333 This
->DriverBindingHandle
,
340 &gEfiWiFi2ProtocolGuid
,
341 This
->DriverBindingHandle
,
349 Stops a device controller or a bus controller.
351 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
352 As a result, much of the error checking on the parameters to Stop() has been moved
353 into this common boot service. It is legal to call Stop() from other locations,
354 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
355 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
356 same driver's Start() function.
357 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
358 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
359 Start() function, and the Start() function must have called OpenProtocol() on
360 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
362 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
363 @param[in] ControllerHandle A handle to the device being stopped. The handle must
364 support a bus specific I/O protocol for the driver
365 to use to stop the device.
366 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
367 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
368 if NumberOfChildren is 0.
370 @retval EFI_SUCCESS The device was stopped.
371 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
376 WifiMgrDxeDriverBindingStop (
377 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
378 IN EFI_HANDLE ControllerHandle
,
379 IN UINTN NumberOfChildren
,
380 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
385 WIFI_MGR_PRIVATE_PROTOCOL
*WifiMgrIdentifier
;
386 WIFI_MGR_DEVICE_DATA
*Nic
;
388 Status
= gBS
->OpenProtocol (
390 &mEfiWifiMgrPrivateGuid
,
391 (VOID
**) &WifiMgrIdentifier
,
392 This
->DriverBindingHandle
,
394 EFI_OPEN_PROTOCOL_GET_PROTOCOL
396 if (EFI_ERROR (Status
)) {
397 return EFI_DEVICE_ERROR
;
400 Nic
= WIFI_MGR_DEVICE_DATA_FROM_IDENTIFIER (WifiMgrIdentifier
);
402 return EFI_DEVICE_ERROR
;
408 gBS
->SetTimer (Nic
->TickTimer
, TimerCancel
, 0);
409 gBS
->CloseEvent (Nic
->TickTimer
);
412 // Clean Supported Suites
414 if (Nic
->Supplicant
!= NULL
) {
415 if (Nic
->SupportedSuites
.SupportedAKMSuites
!= NULL
) {
416 FreePool (Nic
->SupportedSuites
.SupportedAKMSuites
);
418 if (Nic
->SupportedSuites
.SupportedSwCipherSuites
!= NULL
) {
419 FreePool (Nic
->SupportedSuites
.SupportedSwCipherSuites
);
421 if (Nic
->SupportedSuites
.SupportedHwCipherSuites
!= NULL
) {
422 FreePool (Nic
->SupportedSuites
.SupportedHwCipherSuites
);
429 Status
= gBS
->UninstallProtocolInterface (
431 &mEfiWifiMgrPrivateGuid
,
432 &Nic
->WifiMgrIdentifier
434 if (EFI_ERROR (Status
)) {
438 Status
= gBS
->CloseProtocol (
440 &gEfiWiFi2ProtocolGuid
,
442 Nic
->ControllerHandle
444 if (EFI_ERROR (Status
)) {
448 if (Nic
->Supplicant
!= NULL
) {
449 Status
= gBS
->CloseProtocol (
451 &gEfiSupplicantProtocolGuid
,
453 Nic
->ControllerHandle
455 if (EFI_ERROR (Status
)) {
460 if (Nic
->EapConfig
!= NULL
) {
461 Status
= gBS
->CloseProtocol (
463 &gEfiEapConfigurationProtocolGuid
,
465 Nic
->ControllerHandle
467 if (EFI_ERROR (Status
)) {
473 // Remove this Nic from Nic list
475 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
477 RemoveEntryList (&Nic
->Link
);
478 mPrivate
->NicCount
--;
479 if (mPrivate
->CurrentNic
== Nic
) {
480 mPrivate
->CurrentNic
= NULL
;
483 gBS
->RestoreTPL (OldTpl
);
485 WifiMgrFreeProfileList (&Nic
->ProfileList
);
488 DEBUG ((DEBUG_INFO
, "[WiFi Connection Manager] Device Controller has been Disconnected!\n"));
493 This is the declaration of an EFI image entry point. This entry point is
494 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
495 both device drivers and bus drivers.
497 @param ImageHandle The firmware allocated handle for the UEFI image.
498 @param SystemTable A pointer to the EFI System Table.
500 @retval EFI_SUCCESS The operation completed successfully.
501 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
502 @retval Others An unexpected error occurred.
507 WifiMgrDxeDriverEntryPoint (
508 IN EFI_HANDLE ImageHandle
,
509 IN EFI_SYSTEM_TABLE
*SystemTable
514 Status
= EfiLibInstallDriverBindingComponentName2 (
517 &gWifiMgrDxeDriverBinding
,
519 &gWifiMgrDxeComponentName
,
520 &gWifiMgrDxeComponentName2
522 if (EFI_ERROR (Status
)) {
527 // Initialize the global private data structure.
529 mPrivate
= AllocateZeroPool (sizeof (WIFI_MGR_PRIVATE_DATA
));
530 if (mPrivate
== NULL
) {
531 Status
= EFI_OUT_OF_RESOURCES
;
534 mPrivate
->Signature
= WIFI_MGR_PRIVATE_DATA_SIGNATURE
;
535 mPrivate
->DriverHandle
= ImageHandle
;
536 InitializeListHead (&mPrivate
->NicList
);
537 mPrivate
->NicCount
= 0;
538 mPrivate
->CurrentNic
= NULL
;
539 InitializeListHead (&mPrivate
->HiddenNetworkList
);
540 mPrivate
->HiddenNetworkCount
= 0;
543 //Create events for page refresh
545 Status
= gBS
->CreateEventEx (
548 WifiMgrInternalEmptyFunction
,
550 &mWifiConfigNetworkListRefreshGuid
,
551 &mPrivate
->NetworkListRefreshEvent
553 if (EFI_ERROR (Status
)) {
557 Status
= gBS
->CreateEventEx (
560 WifiMgrInternalEmptyFunction
,
562 &mWifiConfigConnectFormRefreshGuid
,
563 &mPrivate
->ConnectFormRefreshEvent
565 if (EFI_ERROR (Status
)) {
569 Status
= gBS
->CreateEventEx (
572 WifiMgrInternalEmptyFunction
,
574 &mWifiConfigMainFormRefreshGuid
,
575 &mPrivate
->MainPageRefreshEvent
577 if (EFI_ERROR (Status
)) {
581 Status
= WifiMgrDxeConfigFormInit (mPrivate
);
582 if (EFI_ERROR (Status
)) {
589 gBS
->CloseEvent (mPrivate
->MainPageRefreshEvent
);
592 gBS
->CloseEvent (mPrivate
->ConnectFormRefreshEvent
);
595 gBS
->CloseEvent (mPrivate
->NetworkListRefreshEvent
);
598 if (mPrivate
!= NULL
) {
604 gBS
->UninstallMultipleProtocolInterfaces (
606 &gEfiDriverBindingProtocolGuid
,
607 &gWifiMgrDxeDriverBinding
,
608 &gEfiComponentNameProtocolGuid
,
609 &gWifiMgrDxeComponentName
,
610 &gEfiComponentName2ProtocolGuid
,
611 &gWifiMgrDxeComponentName2
,