Skip to content

Commit

Permalink
NetworkPkg: Add WiFi profile sync protocol support
Browse files Browse the repository at this point in the history
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3845

Enables KVM and One Click Recovery WLAN capability with WiFi Profile
Sync feature and protocol. Adding WiFiProfileSyncProtocol, which
supports the profilesync driver operations for transferring WiFi profiles
from AMT to the Supplicant. WiFiConnectionManager will check for the
WifiProfileSyncProtocol and if found will operate on the premise of a
One Click Recovery, or KVM flow with a Wifi profile provided by AMT.

Cc: Maciej Rabeda <[email protected]>
Cc: Wu Jiaxin <[email protected]>
Cc: Andrei Otcheretianski <[email protected]>

Signed-off-by: Zachary Clark-Williams <[email protected]>
Acked-by: Michael D Kinney <[email protected]>
Reviewed-by: Jiaxin Wu <[email protected]>
  • Loading branch information
Zclarkwilliams authored and mergify[bot] committed Jan 10, 2023
1 parent ec54ce1 commit fe405f0
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 73 deletions.
93 changes: 93 additions & 0 deletions NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/** @file
WiFi profile sync protocol. Supports One Click Recovery or KVM OS recovery
boot flow over WiFi. This protocol will hold the WiFi profile provided by AMT
in its original structure, then convert the profile when the WifiConnectionManager
is attempting a connection during a system recovery reboot, OCR or KVM. These
converstion and operations are found in the WifiProfileSync driver and in
the link provided below.
This protocol facilitates the reporting and storing of the connection state
incase of failure, to which a connection attempt will rety a maximum of 3 times.
Pulbic links to speficiation document for KVM and One Click Recovery feature.
https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Foneclickrecovery.htm
Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef WIFI_PROFILE_SYNC_PROTOCOL_H_
#define WIFI_PROFILE_SYNC_PROTOCOL_H_

#include <WifiConnectionManagerDxe/WifiConnectionMgrConfig.h>

//
// WiFi Profile Sync Protocol GUID variable.
//
extern EFI_GUID gEdkiiWiFiProfileSyncProtocolGuid;

/**
Used by the WiFi connection manager to get the WiFi profile that AMT shared
and was stored in WiFi profile protocol. Aligns the AMT WiFi profile data to
the WiFi connection manager profile structure fo connection use.
@param[in, out] WcmProfile WiFi Connection Manager profile structure
@param[in, out] MacAddress MAC address from AMT saved to NiC MAC address
@retval EFI_SUCCESS Stored WiFi profile converted and returned succefully
@retval EFI_UNSUPPORTED Profile protocol sharing not supported or enabled
@retval EFI_NOT_FOUND No profiles to returned
@retval Others Error Occurred
**/
typedef
EFI_STATUS
(EFIAPI *WIFI_PROFILE_GET)(
IN OUT WIFI_MGR_NETWORK_PROFILE *Profile,
IN OUT EFI_80211_MAC_ADDRESS MacAddress
);

/**
Saves the WiFi connection status recieved by the WiFiConnectionManager when
in a KVM OR One Click Recovery WLAN recovery flow. Input as
EFI_80211_CONNECT_NETWORK_RESULT_CODE then converted and stored as EFI_STATUS type.
@param[in] ConnectionStatus WiFi connection attempt results
**/
typedef
VOID
(EFIAPI *WIFI_SET_CONNECT_STATE)(
IN EFI_80211_CONNECT_NETWORK_RESULT_CODE ConnectionStatus
);

/**
Retrieves the stored WiFi connection status when in either KVM OR One Click
Recovery WLAN recovery flow.
@retval EFI_SUCCESS WiFi connection completed succesfully
@retval Others Connection failure occurred
**/
typedef
EFI_STATUS
(EFIAPI *WIFI_GET_CONNECT_STATE)(
VOID
);

//
// WiFi Profile Sync Protocol structure.
//
typedef struct {
UINT32 Revision;
WIFI_SET_CONNECT_STATE SetConnectState;
WIFI_GET_CONNECT_STATE GetConnectState;
WIFI_PROFILE_GET GetProfile;
} EDKII_WIFI_PROFILE_SYNC_PROTOCOL;

/**
WiFi Profile Protocol revision number.
Revision 1: Initial version
**/
#define EDKII_WIFI_PROFILE_SYNC_PROTOCOL_REVISION 1

#endif // WIFI_PROFILE_SYNC_PROTOCOL_H_
3 changes: 3 additions & 0 deletions NetworkPkg/NetworkPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
## Include/Protocol/HttpCallback.h
gEdkiiHttpCallbackProtocolGuid = {0x611114f1, 0xa37b, 0x4468, {0xa4, 0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2, 0x40}}

## Include/Protocol/WiFiProfileSyncProtocol.h
gEdkiiWiFiProfileSyncProtocolGuid = {0x399a2b8a, 0xc267, 0x44aa, {0x9a, 0xb4, 0x30, 0x58, 0x8c, 0xd2, 0x2d, 0xcc}}

[PcdsFixedAtBuild]
## The max attempt number will be created by iSCSI driver.
# @Prompt Max attempt number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# 2). WPA2 Personal Network
# 3). EAP Networks (EAP-TLS, EAP-TTLS/MSCHAPv2 and PEAPv0/MSCHAPv2)
#
# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -71,6 +71,7 @@
gEfiAdapterInformationProtocolGuid ## SOMETIMES_CONSUMES
gEfiSupplicantProtocolGuid ## SOMETIMES_CONSUMES
gEfiEapConfigurationProtocolGuid ## SOMETIMES_CONSUMES
gEdkiiWiFiProfileSyncProtocolGuid ## SOMETIMES_CONSUMES

[Guids]
gWifiConfigGuid ## PRODUCES ## GUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define PASSWORD_MIN_LEN 8
#define PASSWORD_MAX_LEN 63
#define PASSWORD_STORAGE_SIZE 64
#define PASSWORD_STORAGE_SIZE 65

#define EAP_IDENTITY_LEN 63
#define EAP_IDENTITY_SIZE 64
Expand Down
126 changes: 84 additions & 42 deletions NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
The driver binding protocol for the WiFi Connection Manager.
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -39,6 +39,11 @@ EFI_GUID mWifiConfigNetworkListRefreshGuid = WIFI_CONFIG_NETWORK_LIST_REFRESH_G
EFI_GUID mWifiConfigConnectFormRefreshGuid = WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID;
EFI_GUID mWifiConfigMainFormRefreshGuid = WIFI_CONFIG_MAIN_FORM_REFRESH_GUID;

//
// Wifi connection attempt counter for retries
//
extern UINT8 mWifiConnectionCount;

/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
Expand Down Expand Up @@ -167,8 +172,10 @@ WifiMgrDxeDriverBindingStart (
EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL *Wmp;
EFI_SUPPLICANT_PROTOCOL *Supplicant;
EFI_EAP_CONFIGURATION_PROTOCOL *EapConfig;
EDKII_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

Nic = NULL;
mWifiConnectionCount = 0;
Nic = NULL;

//
// Open Protocols
Expand Down Expand Up @@ -236,47 +243,73 @@ WifiMgrDxeDriverBindingStart (
InitializeListHead (&Nic->ProfileList);

//
// Record the MAC address of the incoming NIC.
// WiFi profile sync protocol installation check for OS recovery flow.
//
Status = NetLibGetMacAddress (
ControllerHandle,
(EFI_MAC_ADDRESS *)&Nic->MacAddress,
&AddressSize
);
if (EFI_ERROR (Status)) {
goto ERROR2;
}

//
// Create and start the timer for the status check
//
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL | EVT_TIMER,
TPL_CALLBACK,
WifiMgrOnTimerTick,
Nic,
&Nic->TickTimer
Status = gBS->LocateProtocol (
&gEdkiiWiFiProfileSyncProtocolGuid,
NULL,
(VOID **)&WiFiProfileSyncProtocol
);
if (EFI_ERROR (Status)) {
goto ERROR2;
}
if (!EFI_ERROR (Status)) {
Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));
if (Nic->ConnectPendingNetwork == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ERROR1;
}

Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));
if (EFI_ERROR (Status)) {
goto ERROR3;
}
WiFiProfileSyncProtocol->GetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);
if (Nic->ConnectPendingNetwork != NULL) {
Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);
if (!EFI_ERROR (Status)) {
goto ERROR1;
}

WiFiProfileSyncProtocol->SetConnectState (Status);
}
} else {
//
// Record the MAC address of the incoming NIC.
//
Status = NetLibGetMacAddress (
ControllerHandle,
(EFI_MAC_ADDRESS *)&Nic->MacAddress,
&AddressSize
);
if (EFI_ERROR (Status)) {
goto ERROR2;
}

Nic->ConnectState = WifiMgrDisconnected;
Nic->ScanState = WifiMgrScanFinished;
//
// Create and start the timer for the status check
//
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL | EVT_TIMER,
TPL_CALLBACK,
WifiMgrOnTimerTick,
Nic,
&Nic->TickTimer
);
if (EFI_ERROR (Status)) {
goto ERROR2;
}

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
InsertTailList (&mPrivate->NicList, &Nic->Link);
Nic->NicIndex = mPrivate->NicCount++;
if (mPrivate->CurrentNic == NULL) {
mPrivate->CurrentNic = Nic;
}
Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));
if (EFI_ERROR (Status)) {
goto ERROR3;
}

gBS->RestoreTPL (OldTpl);
Nic->ConnectState = WifiMgrDisconnected;
Nic->ScanState = WifiMgrScanFinished;

OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
InsertTailList (&mPrivate->NicList, &Nic->Link);
Nic->NicIndex = mPrivate->NicCount++;
if (mPrivate->CurrentNic == NULL) {
mPrivate->CurrentNic = Nic;
}

gBS->RestoreTPL (OldTpl);
}

Status = gBS->InstallProtocolInterface (
&ControllerHandle,
Expand Down Expand Up @@ -385,10 +418,11 @@ WifiMgrDxeDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
EFI_STATUS Status;
EFI_TPL OldTpl;
WIFI_MGR_PRIVATE_PROTOCOL *WifiMgrIdentifier;
WIFI_MGR_DEVICE_DATA *Nic;
EFI_STATUS Status;
EFI_TPL OldTpl;
WIFI_MGR_PRIVATE_PROTOCOL *WifiMgrIdentifier;
WIFI_MGR_DEVICE_DATA *Nic;
EDKII_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

Status = gBS->OpenProtocol (
ControllerHandle,
Expand Down Expand Up @@ -481,7 +515,15 @@ WifiMgrDxeDriverBindingStop (
//
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

RemoveEntryList (&Nic->Link);
Status = gBS->LocateProtocol (
&gEdkiiWiFiProfileSyncProtocolGuid,
NULL,
(VOID **)&WiFiProfileSyncProtocol
);
if (EFI_ERROR (Status)) {
RemoveEntryList (&Nic->Link);
}

mPrivate->NicCount--;
if (mPrivate->CurrentNic == Nic) {
mPrivate->CurrentNic = NULL;
Expand Down
4 changes: 3 additions & 1 deletion NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <Protocol/SimpleNetwork.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/EapConfiguration.h>
#include <Protocol/WiFiProfileSyncProtocol.h>

//
// Produced Protocols
Expand All @@ -73,7 +74,8 @@
//
#define WIFI_MGR_DXE_VERSION 0xb

#define OUI_IEEE_80211I 0xAC0F00
#define OUI_IEEE_80211I 0xAC0F00
#define MAX_WIFI_CONNETION_ATTEMPTS 3

typedef enum {
Ieee80211PairwiseCipherSuiteUseGroupCipherSuite = 0,
Expand Down
Loading

0 comments on commit fe405f0

Please sign in to comment.