]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Add WiFi profile sync protocol support
authorZachary Clark-Williams <zclarkw112@gmail.com>
Wed, 10 Aug 2022 22:32:11 +0000 (15:32 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 10 Jan 2023 21:31:29 +0000 (21:31 +0000)
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 <maciej.rabeda@linux.intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Cc: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
Signed-off-by: Zachary Clark-Williams <zachary.clark-williams@intel.com>
Acked-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h [new file with mode: 0644]
NetworkPkg/NetworkPkg.dec
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c

diff --git a/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h b/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h
new file mode 100644 (file)
index 0000000..c6d1fda
--- /dev/null
@@ -0,0 +1,93 @@
+/** @file\r
+  WiFi profile sync protocol. Supports One Click Recovery or KVM OS recovery\r
+  boot flow over WiFi. This protocol will hold the WiFi profile provided by AMT\r
+  in its original structure, then convert the profile when the WifiConnectionManager\r
+  is attempting a connection during a system recovery reboot, OCR or KVM. These\r
+  converstion and operations are found in the WifiProfileSync driver and in\r
+  the link provided below.\r
+\r
+  This protocol facilitates the reporting and storing of the connection state\r
+  incase of failure, to which a connection attempt will rety a maximum of 3 times.\r
+\r
+  Pulbic links to speficiation document for KVM and One Click Recovery feature.\r
+  https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Foneclickrecovery.htm\r
+\r
+  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#ifndef WIFI_PROFILE_SYNC_PROTOCOL_H_\r
+#define WIFI_PROFILE_SYNC_PROTOCOL_H_\r
+\r
+#include <WifiConnectionManagerDxe/WifiConnectionMgrConfig.h>\r
+\r
+//\r
+//  WiFi Profile Sync Protocol GUID variable.\r
+//\r
+extern EFI_GUID  gEdkiiWiFiProfileSyncProtocolGuid;\r
+\r
+/**\r
+  Used by the WiFi connection manager to get the WiFi profile that AMT shared\r
+  and was stored in WiFi profile protocol. Aligns the AMT WiFi profile data to\r
+  the WiFi connection manager profile structure fo connection use.\r
+\r
+  @param[in, out]  WcmProfile       WiFi Connection Manager profile structure\r
+  @param[in, out]  MacAddress       MAC address from AMT saved to NiC MAC address\r
+\r
+  @retval EFI_SUCCESS               Stored WiFi profile converted and returned succefully\r
+  @retval EFI_UNSUPPORTED           Profile protocol sharing not supported or enabled\r
+  @retval EFI_NOT_FOUND             No profiles to returned\r
+  @retval Others                    Error Occurred\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *WIFI_PROFILE_GET)(\r
+  IN OUT  WIFI_MGR_NETWORK_PROFILE  *Profile,\r
+  IN OUT  EFI_80211_MAC_ADDRESS     MacAddress\r
+  );\r
+\r
+/**\r
+  Saves the WiFi connection status recieved by the WiFiConnectionManager when\r
+  in a KVM OR One Click Recovery WLAN recovery flow. Input as\r
+  EFI_80211_CONNECT_NETWORK_RESULT_CODE then converted and stored as EFI_STATUS type.\r
+\r
+  @param[in] ConnectionStatus     WiFi connection attempt results\r
+**/\r
+typedef\r
+VOID\r
+(EFIAPI *WIFI_SET_CONNECT_STATE)(\r
+  IN  EFI_80211_CONNECT_NETWORK_RESULT_CODE ConnectionStatus\r
+  );\r
+\r
+/**\r
+  Retrieves the stored WiFi connection status when in either KVM OR One Click\r
+  Recovery WLAN recovery flow.\r
+\r
+  @retval EFI_SUCCESS               WiFi connection completed succesfully\r
+  @retval Others                    Connection failure occurred\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *WIFI_GET_CONNECT_STATE)(\r
+  VOID\r
+  );\r
+\r
+//\r
+//  WiFi Profile Sync Protocol structure.\r
+//\r
+typedef struct {\r
+  UINT32                    Revision;\r
+  WIFI_SET_CONNECT_STATE    SetConnectState;\r
+  WIFI_GET_CONNECT_STATE    GetConnectState;\r
+  WIFI_PROFILE_GET          GetProfile;\r
+} EDKII_WIFI_PROFILE_SYNC_PROTOCOL;\r
+\r
+/**\r
+  WiFi Profile Protocol revision number.\r
+\r
+  Revision 1:   Initial version\r
+**/\r
+#define EDKII_WIFI_PROFILE_SYNC_PROTOCOL_REVISION  1\r
+\r
+#endif //  WIFI_PROFILE_SYNC_PROTOCOL_H_\r
index 5e43ebf8c5da4a6650ab8eb57bd937b9a795d49b..e06f35e7747cb4ae85b4d40411640736160f0d49 100644 (file)
@@ -91,6 +91,9 @@
   ## Include/Protocol/HttpCallback.h\r
   gEdkiiHttpCallbackProtocolGuid  = {0x611114f1, 0xa37b, 0x4468, {0xa4, 0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2, 0x40}}\r
 \r
+  ## Include/Protocol/WiFiProfileSyncProtocol.h\r
+  gEdkiiWiFiProfileSyncProtocolGuid = {0x399a2b8a, 0xc267, 0x44aa, {0x9a, 0xb4, 0x30, 0x58, 0x8c, 0xd2, 0x2d, 0xcc}}\r
+\r
 [PcdsFixedAtBuild]\r
   ## The max attempt number will be created by iSCSI driver.\r
   # @Prompt Max attempt number.\r
index 4394b6f4bb6d27f573a8908a45d8a21f0560529d..47901d75abef585db6f373c549e1a0cb9fd56225 100644 (file)
@@ -9,7 +9,7 @@
 #  2). WPA2 Personal Network\r
 #  3). EAP Networks (EAP-TLS, EAP-TTLS/MSCHAPv2 and PEAPv0/MSCHAPv2)\r
 #\r
-#  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
@@ -71,6 +71,7 @@
   gEfiAdapterInformationProtocolGuid            ## SOMETIMES_CONSUMES\r
   gEfiSupplicantProtocolGuid                    ## SOMETIMES_CONSUMES\r
   gEfiEapConfigurationProtocolGuid              ## SOMETIMES_CONSUMES\r
+  gEdkiiWiFiProfileSyncProtocolGuid             ## SOMETIMES_CONSUMES\r
 \r
 [Guids]\r
   gWifiConfigGuid                               ## PRODUCES  ## GUID\r
index b5518a74d8a39af5350f04669668dccaf608a815..dcc4bf7e2749ce029e646d0216c4c0aa703356f0 100644 (file)
@@ -25,7 +25,7 @@
 \r
 #define PASSWORD_MIN_LEN       8\r
 #define PASSWORD_MAX_LEN       63\r
-#define PASSWORD_STORAGE_SIZE  64\r
+#define PASSWORD_STORAGE_SIZE  65\r
 \r
 #define EAP_IDENTITY_LEN   63\r
 #define EAP_IDENTITY_SIZE  64\r
index 67a01ca0583f9df60388bdcc90d5860da8ab90fd..36c467025f9b80af5abca22bca662ebc1e69a02c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The driver binding protocol for the WiFi Connection Manager.\r
 \r
-  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -39,6 +39,11 @@ EFI_GUID  mWifiConfigNetworkListRefreshGuid = WIFI_CONFIG_NETWORK_LIST_REFRESH_G
 EFI_GUID  mWifiConfigConnectFormRefreshGuid = WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID;\r
 EFI_GUID  mWifiConfigMainFormRefreshGuid    = WIFI_CONFIG_MAIN_FORM_REFRESH_GUID;\r
 \r
+//\r
+// Wifi connection attempt counter for retries\r
+//\r
+extern UINT8  mWifiConnectionCount;\r
+\r
 /**\r
   Tests to see if this driver supports a given controller. If a child device is provided,\r
   it further tests to see if this driver supports creating a handle for the specified child device.\r
@@ -167,8 +172,10 @@ WifiMgrDxeDriverBindingStart (
   EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL  *Wmp;\r
   EFI_SUPPLICANT_PROTOCOL                  *Supplicant;\r
   EFI_EAP_CONFIGURATION_PROTOCOL           *EapConfig;\r
+  EDKII_WIFI_PROFILE_SYNC_PROTOCOL         *WiFiProfileSyncProtocol;\r
 \r
-  Nic = NULL;\r
+  mWifiConnectionCount = 0;\r
+  Nic                  = NULL;\r
 \r
   //\r
   // Open Protocols\r
@@ -236,47 +243,73 @@ WifiMgrDxeDriverBindingStart (
   InitializeListHead (&Nic->ProfileList);\r
 \r
   //\r
-  // Record the MAC address of the incoming NIC.\r
+  // WiFi profile sync protocol installation check for OS recovery flow.\r
   //\r
-  Status = NetLibGetMacAddress (\r
-             ControllerHandle,\r
-             (EFI_MAC_ADDRESS *)&Nic->MacAddress,\r
-             &AddressSize\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ERROR2;\r
-  }\r
-\r
-  //\r
-  // Create and start the timer for the status check\r
-  //\r
-  Status = gBS->CreateEvent (\r
-                  EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
-                  TPL_CALLBACK,\r
-                  WifiMgrOnTimerTick,\r
-                  Nic,\r
-                  &Nic->TickTimer\r
+  Status = gBS->LocateProtocol (\r
+                  &gEdkiiWiFiProfileSyncProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&WiFiProfileSyncProtocol\r
                   );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ERROR2;\r
-  }\r
+  if (!EFI_ERROR (Status)) {\r
+    Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));\r
+    if (Nic->ConnectPendingNetwork == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto ERROR1;\r
+    }\r
 \r
-  Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));\r
-  if (EFI_ERROR (Status)) {\r
-    goto ERROR3;\r
-  }\r
+    WiFiProfileSyncProtocol->GetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);\r
+    if (Nic->ConnectPendingNetwork != NULL) {\r
+      Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);\r
+      if (!EFI_ERROR (Status)) {\r
+        goto ERROR1;\r
+      }\r
+\r
+      WiFiProfileSyncProtocol->SetConnectState (Status);\r
+    }\r
+  } else {\r
+    //\r
+    // Record the MAC address of the incoming NIC.\r
+    //\r
+    Status = NetLibGetMacAddress (\r
+               ControllerHandle,\r
+               (EFI_MAC_ADDRESS *)&Nic->MacAddress,\r
+               &AddressSize\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ERROR2;\r
+    }\r
 \r
-  Nic->ConnectState = WifiMgrDisconnected;\r
-  Nic->ScanState    = WifiMgrScanFinished;\r
+    //\r
+    // Create and start the timer for the status check\r
+    //\r
+    Status = gBS->CreateEvent (\r
+                    EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
+                    TPL_CALLBACK,\r
+                    WifiMgrOnTimerTick,\r
+                    Nic,\r
+                    &Nic->TickTimer\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ERROR2;\r
+    }\r
 \r
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-  InsertTailList (&mPrivate->NicList, &Nic->Link);\r
-  Nic->NicIndex = mPrivate->NicCount++;\r
-  if (mPrivate->CurrentNic == NULL) {\r
-    mPrivate->CurrentNic = Nic;\r
-  }\r
+    Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));\r
+    if (EFI_ERROR (Status)) {\r
+      goto ERROR3;\r
+    }\r
 \r
-  gBS->RestoreTPL (OldTpl);\r
+    Nic->ConnectState = WifiMgrDisconnected;\r
+    Nic->ScanState    = WifiMgrScanFinished;\r
+\r
+    OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+    InsertTailList (&mPrivate->NicList, &Nic->Link);\r
+    Nic->NicIndex = mPrivate->NicCount++;\r
+    if (mPrivate->CurrentNic == NULL) {\r
+      mPrivate->CurrentNic = Nic;\r
+    }\r
+\r
+    gBS->RestoreTPL (OldTpl);\r
+  }\r
 \r
   Status = gBS->InstallProtocolInterface (\r
                   &ControllerHandle,\r
@@ -385,10 +418,11 @@ WifiMgrDxeDriverBindingStop (
   IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS                 Status;\r
-  EFI_TPL                    OldTpl;\r
-  WIFI_MGR_PRIVATE_PROTOCOL  *WifiMgrIdentifier;\r
-  WIFI_MGR_DEVICE_DATA       *Nic;\r
+  EFI_STATUS                        Status;\r
+  EFI_TPL                           OldTpl;\r
+  WIFI_MGR_PRIVATE_PROTOCOL         *WifiMgrIdentifier;\r
+  WIFI_MGR_DEVICE_DATA              *Nic;\r
+  EDKII_WIFI_PROFILE_SYNC_PROTOCOL  *WiFiProfileSyncProtocol;\r
 \r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -481,7 +515,15 @@ WifiMgrDxeDriverBindingStop (
   //\r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
-  RemoveEntryList (&Nic->Link);\r
+  Status = gBS->LocateProtocol (\r
+                  &gEdkiiWiFiProfileSyncProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&WiFiProfileSyncProtocol\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    RemoveEntryList (&Nic->Link);\r
+  }\r
+\r
   mPrivate->NicCount--;\r
   if (mPrivate->CurrentNic == Nic) {\r
     mPrivate->CurrentNic = NULL;\r
index 7b2e41e1559450b2499d23e8f655d306e7872897..047f85dbc2f22a1f8382dbd00945f5b60c948541 100644 (file)
@@ -47,6 +47,7 @@
 #include <Protocol/SimpleNetwork.h>\r
 #include <Protocol/SimpleFileSystem.h>\r
 #include <Protocol/EapConfiguration.h>\r
+#include <Protocol/WiFiProfileSyncProtocol.h>\r
 \r
 //\r
 // Produced Protocols\r
@@ -73,7 +74,8 @@
 //\r
 #define WIFI_MGR_DXE_VERSION  0xb\r
 \r
-#define OUI_IEEE_80211I  0xAC0F00\r
+#define OUI_IEEE_80211I              0xAC0F00\r
+#define MAX_WIFI_CONNETION_ATTEMPTS  3\r
 \r
 typedef enum {\r
   Ieee80211PairwiseCipherSuiteUseGroupCipherSuite = 0,\r
index 59bac48c42401cf1508f19f057721d38ea7d85a6..2e596c1981f56bb6c2cdfc2a78d7d1c67a7914a8 100644 (file)
@@ -19,6 +19,8 @@ EFI_EAP_TYPE  mEapSecondAuthMethod[] = {
   EFI_EAP_TYPE_MSCHAPV2\r
 };\r
 \r
+UINT8  mWifiConnectionCount = 0;\r
+\r
 /**\r
   The callback function for scan operation. This function updates networks\r
   according to the latest scan result, and trigger UI refresh.\r
@@ -424,18 +426,26 @@ WifiMgrConfigPassword (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  AsciiPassword = AllocateZeroPool ((StrLen (Profile->Password) + 1) * sizeof (UINT8));\r
+  if (StrLen (Profile->Password) >= PASSWORD_STORAGE_SIZE) {\r
+    ASSERT (EFI_INVALID_PARAMETER);\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AsciiPassword = AllocateZeroPool ((StrLen (Profile->Password) + 1) * sizeof (CHAR8));\r
   if (AsciiPassword == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  UnicodeStrToAsciiStrS (Profile->Password, (CHAR8 *)AsciiPassword, PASSWORD_STORAGE_SIZE);\r
-  Status = Supplicant->SetData (\r
-                         Supplicant,\r
-                         EfiSupplicant80211PskPassword,\r
-                         AsciiPassword,\r
-                         (StrLen (Profile->Password) + 1) * sizeof (UINT8)\r
-                         );\r
+  Status = UnicodeStrToAsciiStrS (Profile->Password, (CHAR8 *)AsciiPassword, (StrLen (Profile->Password) + 1));\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = Supplicant->SetData (\r
+                           Supplicant,\r
+                           EfiSupplicant80211PskPassword,\r
+                           AsciiPassword,\r
+                           (StrLen (Profile->Password) + 1) * sizeof (CHAR8)\r
+                           );\r
+  }\r
+\r
   ZeroMem (AsciiPassword, AsciiStrLen ((CHAR8 *)AsciiPassword) + 1);\r
   FreePool (AsciiPassword);\r
 \r
@@ -465,19 +475,20 @@ WifiMgrConfigEap (
   IN    WIFI_MGR_NETWORK_PROFILE  *Profile\r
   )\r
 {\r
-  EFI_STATUS                      Status;\r
-  EFI_EAP_CONFIGURATION_PROTOCOL  *EapConfig;\r
-  EFI_EAP_TYPE                    EapAuthMethod;\r
-  EFI_EAP_TYPE                    EapSecondAuthMethod;\r
-  EFI_EAP_TYPE                    *AuthMethodList;\r
-  CHAR8                           *Identity;\r
-  UINTN                           IdentitySize;\r
-  CHAR16                          *Password;\r
-  UINTN                           PasswordSize;\r
-  UINTN                           EncryptPasswordLen;\r
-  CHAR8                           *AsciiEncryptPassword;\r
-  UINTN                           AuthMethodListSize;\r
-  UINTN                           Index;\r
+  EFI_STATUS                        Status;\r
+  EDKII_WIFI_PROFILE_SYNC_PROTOCOL  *WiFiProfileSyncProtocol;\r
+  EFI_EAP_CONFIGURATION_PROTOCOL    *EapConfig;\r
+  EFI_EAP_TYPE                      EapAuthMethod;\r
+  EFI_EAP_TYPE                      EapSecondAuthMethod;\r
+  EFI_EAP_TYPE                      *AuthMethodList;\r
+  CHAR8                             *Identity;\r
+  UINTN                             IdentitySize;\r
+  CHAR16                            *Password;\r
+  UINTN                             PasswordSize;\r
+  UINTN                             EncryptPasswordLen;\r
+  CHAR8                             *AsciiEncryptPassword;\r
+  UINTN                             AuthMethodListSize;\r
+  UINTN                             Index;\r
 \r
   if ((Nic == NULL) || (Nic->EapConfig == NULL) || (Profile == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -567,7 +578,13 @@ WifiMgrConfigEap (
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    UnicodeStrToAsciiStrS (Profile->EapIdentity, Identity, IdentitySize);\r
+    Status = gBS->LocateProtocol (&gEdkiiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);\r
+    if (!EFI_ERROR (Status)) {\r
+      CopyMem (Identity, &Profile->EapIdentity, IdentitySize);\r
+    } else {\r
+      UnicodeStrToAsciiStrS (Profile->EapIdentity, Identity, IdentitySize);\r
+    }\r
+\r
     Status = EapConfig->SetData (\r
                           EapConfig,\r
                           EFI_EAP_TYPE_IDENTITY,\r
@@ -892,6 +909,133 @@ WifiMgrPrepareConnection (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Will reset NiC data, get profile from profile sync driver, and send for\r
+  another connection attempt.This function should not be called more than\r
+  3 times.\r
+\r
+  @param[in]  WiFiProfileSyncProtocol  The target network profile to connect.\r
+\r
+  @retval EFI_SUCCESS                  The operation is completed.\r
+  @retval other                        Operation failure.\r
+\r
+**/\r
+EFI_STATUS\r
+ConnectionRetry (\r
+  IN   EDKII_WIFI_PROFILE_SYNC_PROTOCOL  *WiFiProfileSyncProtocol\r
+  )\r
+{\r
+  EFI_STATUS                               Status;\r
+  WIFI_MGR_DEVICE_DATA                     *Nic;\r
+  EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL  *Wmp;\r
+  EFI_SUPPLICANT_PROTOCOL                  *Supplicant;\r
+  EFI_EAP_CONFIGURATION_PROTOCOL           *EapConfig;\r
+\r
+  Nic = NULL;\r
+\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiWiFi2ProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&Wmp\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiSupplicantProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&Supplicant\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Supplicant = NULL;\r
+  }\r
+\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiEapConfigurationProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&EapConfig\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    EapConfig = NULL;\r
+  }\r
+\r
+  //\r
+  // Initialize Nic device data\r
+  //\r
+  Nic = AllocateZeroPool (sizeof (WIFI_MGR_DEVICE_DATA));\r
+  if (Nic == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    return Status;\r
+  }\r
+\r
+  Nic->Signature           = WIFI_MGR_DEVICE_DATA_SIGNATURE;\r
+  Nic->Private             = mPrivate;\r
+  Nic->Wmp                 = Wmp;\r
+  Nic->Supplicant          = Supplicant;\r
+  Nic->EapConfig           = EapConfig;\r
+  Nic->UserSelectedProfile = NULL;\r
+  Nic->OneTimeScanRequest  = FALSE;\r
+\r
+  if (Nic->Supplicant != NULL) {\r
+    Status = WifiMgrGetSupportedSuites (Nic);\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    InitializeListHead (&Nic->ProfileList);\r
+\r
+    Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));\r
+    if (Nic->ConnectPendingNetwork == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to allocate memory for ConnectPendingNetwork\n"));\r
+      goto ERROR;\r
+    }\r
+\r
+    Status = WiFiProfileSyncProtocol->GetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);\r
+    if (!EFI_ERROR (Status) && (Nic->ConnectPendingNetwork != NULL)) {\r
+      Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);\r
+      if (!EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    } else {\r
+      DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to get WiFi profile with status %r\n", Status));\r
+    }\r
+  } else {\r
+    DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to get Supported suites with status %r\n", Status));\r
+  }\r
+\r
+  if (Nic->ConnectPendingNetwork != NULL) {\r
+    if (Nic->ConnectPendingNetwork->Network.AKMSuite != NULL) {\r
+      FreePool (Nic->ConnectPendingNetwork->Network.AKMSuite);\r
+    }\r
+\r
+    if (Nic->ConnectPendingNetwork->Network.CipherSuite != NULL) {\r
+      FreePool (Nic->ConnectPendingNetwork->Network.CipherSuite);\r
+    }\r
+\r
+    FreePool (Nic->ConnectPendingNetwork);\r
+  }\r
+\r
+ERROR:\r
+  if (Nic->Supplicant != NULL) {\r
+    if (Nic->SupportedSuites.SupportedAKMSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedAKMSuites);\r
+    }\r
+\r
+    if (Nic->SupportedSuites.SupportedSwCipherSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedSwCipherSuites);\r
+    }\r
+\r
+    if (Nic->SupportedSuites.SupportedHwCipherSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedHwCipherSuites);\r
+    }\r
+  }\r
+\r
+  FreePool (Nic);\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   The callback function for connect operation.\r
 \r
@@ -908,12 +1052,13 @@ WifiMgrOnConnectFinished (
   IN  VOID       *Context\r
   )\r
 {\r
-  EFI_STATUS                 Status;\r
-  WIFI_MGR_MAC_CONFIG_TOKEN  *ConfigToken;\r
-  WIFI_MGR_NETWORK_PROFILE   *ConnectedProfile;\r
-  UINT8                      SecurityType;\r
-  UINT8                      SSIdLen;\r
-  CHAR8                      *AsciiSSId;\r
+  EFI_STATUS                        Status;\r
+  WIFI_MGR_MAC_CONFIG_TOKEN         *ConfigToken;\r
+  WIFI_MGR_NETWORK_PROFILE          *ConnectedProfile;\r
+  UINT8                             SecurityType;\r
+  UINT8                             SSIdLen;\r
+  CHAR8                             *AsciiSSId;\r
+  EDKII_WIFI_PROFILE_SYNC_PROTOCOL  *WiFiProfileSyncProtocol;\r
 \r
   ASSERT (Context != NULL);\r
 \r
@@ -925,6 +1070,24 @@ WifiMgrOnConnectFinished (
   ASSERT (ConfigToken->Type == TokenTypeConnectNetworkToken);\r
 \r
   ASSERT (ConfigToken->Token.ConnectNetworkToken != NULL);\r
+\r
+  Status = gBS->LocateProtocol (&gEdkiiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);\r
+  if (!EFI_ERROR (Status)) {\r
+    WiFiProfileSyncProtocol->SetConnectState (ConfigToken->Token.ConnectNetworkToken->ResultCode);\r
+    if ((mWifiConnectionCount < MAX_WIFI_CONNETION_ATTEMPTS) &&\r
+        (ConfigToken->Token.ConnectNetworkToken->ResultCode != ConnectSuccess))\r
+    {\r
+      mWifiConnectionCount++;\r
+      gBS->CloseEvent (Event);\r
+      Status = ConnectionRetry (WiFiProfileSyncProtocol);\r
+      if (!EFI_ERROR (Status)) {\r
+        return;\r
+      }\r
+\r
+      WiFiProfileSyncProtocol->SetConnectState (Status);\r
+    }\r
+  }\r
+\r
   if (ConfigToken->Token.ConnectNetworkToken->Status != EFI_SUCCESS) {\r
     if (ConfigToken->Nic->OneTimeConnectRequest) {\r
       //\r
index 4ad5643c2453a47ee005d10228f4850ccaf9939b..154f2968c764f687b9e9d623b0b7cba8b598e35a 100644 (file)
@@ -672,10 +672,23 @@ WifiMgrCleanProfileSecrets (
   IN  WIFI_MGR_NETWORK_PROFILE  *Profile\r
   )\r
 {\r
+  EFI_STATUS                        Status;\r
+  EDKII_WIFI_PROFILE_SYNC_PROTOCOL  *WiFiProfileSyncProtocol;\r
+\r
   ZeroMem (Profile->Password, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);\r
   ZeroMem (Profile->EapPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);\r
   ZeroMem (Profile->PrivateKeyPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);\r
 \r
+  //\r
+  //  When EFI WiFi profile sync protocol is found the system is performing a recovery boot in secure\r
+  //  boot mode. The profile sync driver will manage the CA certificate, client certificate, and key\r
+  //  data, cleaning them at exit boot services.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEdkiiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);\r
+  if (!EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
+\r
   if (Profile->CACertData != NULL) {\r
     ZeroMem (Profile->CACertData, Profile->CACertSize);\r
     FreePool (Profile->CACertData);\r