]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Add WiFi Connection Manager to NetworkPkg
authorWang Fan <fan.wang@intel.com>
Fri, 22 Feb 2019 07:48:25 +0000 (15:48 +0800)
committerLiming Gao <liming.gao@intel.com>
Thu, 28 Feb 2019 01:47:09 +0000 (09:47 +0800)
* V2

* Remove Arch dependency in Inf file
* Add a global guid for WiFi formset and set other guids to module levels
* Open supplicant and EapConfig by BY_DRIVER
* Remove token free function to avoid potential NULL reference
* Update WifiMgrUpdateConnectMessage() to only display message for Current Nic
* Fix the potential NULL reference in AIP call

* REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1492

Add WiFi Connection Manager in NetworkPkg to provide UI for users to scan
networks, connect or disconnect to networks.

This connection manager won't include the UNDI driver, supplicant driver,
or other device specific drivers and is therefor not a complete solution
stack for UEFI Wi-Fi, users can seek help for Wireless card vendors.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Wang Fan <fan.wang@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Siyuan Fu <siyuan.fu@intel.com>
23 files changed:
NetworkPkg/Include/Guid/WifiConnectionManagerConfigHii.h [new file with mode: 0644]
NetworkPkg/NetworkPkg.dec
NetworkPkg/NetworkPkg.dsc
NetworkPkg/WifiConnectionManagerDxe/EapContext.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.vfr [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxeStrings.uni [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrComponentName.c [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrComponentName.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfig.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigHii.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriverBinding.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrFileUtil.c [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrFileUtil.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrHiiConfigAccess.c [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrHiiConfigAccess.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.h [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c [new file with mode: 0644]
NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.h [new file with mode: 0644]

diff --git a/NetworkPkg/Include/Guid/WifiConnectionManagerConfigHii.h b/NetworkPkg/Include/Guid/WifiConnectionManagerConfigHii.h
new file mode 100644 (file)
index 0000000..af15078
--- /dev/null
@@ -0,0 +1,25 @@
+/** @file\r
+  GUIDs used as HII FormSet and HII Package list GUID in WiFi Connection Manager.\r
+\r
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __WIFI_CONNECTION_MANAGER_HII_GUID_H__\r
+#define __WIFI_CONNECTION_MANAGER_HII_GUID_H__\r
+\r
+#define WIFI_CONNECTION_MANAGER_CONFIG_GUID \\r
+  { \\r
+    0x9f94d327, 0x0b18, 0x4245, { 0x8f, 0xf2, 0x83, 0x2e, 0x30, 0xd, 0x2c, 0xef } \\r
+  }\r
+\r
+extern EFI_GUID gWifiConfigGuid;\r
+\r
+#endif\r
index 6672d90fe1d3427975b19e1b5c0a18f9b34d2859..a922de6ebe9614d61925df9d912ab677f1c41be3 100644 (file)
@@ -49,6 +49,9 @@
   # Include/Guid/HttpTlsCipherList.h\r
   gEdkiiHttpTlsCipherListGuid   = { 0x46ddb415, 0x5244, 0x49c7, { 0x93, 0x74, 0xf0, 0xe2, 0x98, 0xe7, 0xd3, 0x86 }}\r
 \r
+  # Include/Guid/WifiConnectionManagerConfigHii.h\r
+  gWifiConfigGuid               = { 0x9f94d327, 0x0b18, 0x4245, { 0x8f, 0xf2, 0x83, 0x2e, 0x30, 0xd, 0x2c, 0xef }}\r
+\r
 [PcdsFixedAtBuild]\r
   ## The max attempt number will be created by iSCSI driver.\r
   # @Prompt Max attempt number.\r
index b543caa08fb1956971c0b451aeaeb2106fb4fcd2..b17df4654212b4adc3567a25c9c0e3185b039c10 100644 (file)
   NetworkPkg/HttpDxe/HttpDxe.inf\r
   NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesDxe.inf\r
   NetworkPkg/HttpBootDxe/HttpBootDxe.inf\r
+  NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf\r
 \r
   NetworkPkg/Application/IpsecConfig/IpSecConfig.inf\r
   NetworkPkg/Application/VConfig/VConfig.inf\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/EapContext.h b/NetworkPkg/WifiConnectionManagerDxe/EapContext.h
new file mode 100644 (file)
index 0000000..b8a474c
--- /dev/null
@@ -0,0 +1,28 @@
+/** @file\r
+  Eap configuration data structure definitions for EAP connections.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_EAP_CONTEXT_H__\r
+#define __EFI_WIFI_EAP_CONTEXT_H__\r
+\r
+typedef struct {\r
+\r
+  BOOLEAN                   IsEncrypted;\r
+  CHAR16                    EncryptPassword[PASSWORD_STORAGE_SIZE];\r
+  UINTN                     KeySize;\r
+  UINT8                     KeyData[1];\r
+\r
+} EFI_EAP_PRIVATE_KEY;\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
new file mode 100644 (file)
index 0000000..e431f2b
--- /dev/null
@@ -0,0 +1,87 @@
+## @file\r
+#  WiFi Connection Manager.\r
+#\r
+#  This module is an example of how to make use of UEFI WiFi connection capabilities.\r
+#  User can scan, connect and diconnect to networks through UI operations.\r
+#\r
+#  Supported networks include:\r
+#  1). Open Network\r
+#  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
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION               = 0x00010005\r
+  BASE_NAME                 = WifiConnectionManagerDxe\r
+  FILE_GUID                 = c6df98f2-5ec0-4a94-8c11-9a9828ef03f2\r
+  MODULE_TYPE               = DXE_DRIVER\r
+  VERSION_STRING            = 0.1\r
+  ENTRY_POINT               = WifiMgrDxeDriverEntryPoint\r
+\r
+[Sources]\r
+  WifiConnectionMgrDxe.h\r
+  WifiConnectionMgrDriverBinding.h\r
+  WifiConnectionMgrConfig.h\r
+  WifiConnectionMgrMisc.h\r
+  WifiConnectionMgrImpl.h\r
+  WifiConnectionMgrConfigNVDataStruct.h\r
+  WifiConnectionMgrHiiConfigAccess.h\r
+  WifiConnectionMgrComponentName.h\r
+  WifiConnectionMgrFileUtil.h\r
+  WifiConnectionMgrDriver.c\r
+  WifiConnectionMgrComponentName.c\r
+  WifiConnectionMgrMisc.c\r
+  WifiConnectionMgrHiiConfigAccess.c\r
+  WifiConnectionMgrImpl.c\r
+  WifiConnectionMgrFileUtil.c\r
+  WifiConnectionManagerDxeStrings.uni\r
+  WifiConnectionManagerDxe.vfr\r
+  EapContext.h\r
+  WifiConnectionMgrConfigHii.h\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  NetworkPkg/NetworkPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  UefiRuntimeServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  UefiLib\r
+  DevicePathLib\r
+  DebugLib\r
+  HiiLib\r
+  PrintLib\r
+  UefiHiiServicesLib\r
+  NetLib\r
+  FileExplorerLib\r
+\r
+[Protocols]\r
+  gEfiHiiConfigAccessProtocolGuid               ## PRODUCES\r
+  gEfiWiFi2ProtocolGuid                         ## TO_START\r
+  gEfiAdapterInformationProtocolGuid            ## SOMETIMES_CONSUMES\r
+  gEfiSupplicantProtocolGuid                    ## SOMETIMES_CONSUMES\r
+  gEfiEapConfigurationProtocolGuid              ## SOMETIMES_CONSUMES\r
+\r
+[Guids]\r
+  gWifiConfigGuid                               ## PRODUCES  ## GUID\r
+  gEfiIfrTianoGuid                              ## CONSUMES  ## GUID (Extended IFR Guid Opcode)\r
+  gEfiAdapterInfoMediaStateGuid                 ## SOMETIMES_CONSUMES  ## GUID  # Indicate the current media state status\r
+\r
+[Depex]\r
+  gEfiHiiConfigRoutingProtocolGuid\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.vfr b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.vfr
new file mode 100644 (file)
index 0000000..66c6e9b
--- /dev/null
@@ -0,0 +1,353 @@
+/** @file\r
+  Vfr files used in WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "WifiConnectionMgrConfigNVDataStruct.h"\r
+\r
+#define EFI_NETWORK_DEVICE_CLASS  0x04\r
+\r
+formset\r
+  guid     = WIFI_CONNECTION_MANAGER_CONFIG_GUID,\r
+  title    = STRING_TOKEN(STR_WIFI_MGR_FORM_TITLE),\r
+  help     = STRING_TOKEN(STR_WIFI_MGR_FORM_HELP),\r
+  class    = EFI_NETWORK_DEVICE_CLASS,\r
+  subclass = 0x03,\r
+\r
+  varstore WIFI_MANAGER_IFR_NVDATA,\r
+    varid = MANAGER_VARSTORE_ID,\r
+    name  = WIFI_MANAGER_IFR_NVDATA,\r
+    guid  = WIFI_CONNECTION_MANAGER_CONFIG_GUID;\r
+\r
+  form formid = FORMID_MAC_SELECTION,\r
+    title = STRING_TOKEN(STR_WIFI_MAC_FORM_TITLE);\r
+\r
+    suppressif TRUE;\r
+      text\r
+        help   = STRING_TOKEN(STR_NULL_STRING),\r
+        text   = STRING_TOKEN(STR_NULL_STRING),\r
+        flags  = INTERACTIVE,\r
+        key    = KEY_MAC_LIST;\r
+      endif;\r
+\r
+    label LABEL_MAC_ENTRY;\r
+    label LABEL_END;\r
+  endform;\r
+\r
+  form formid = FORMID_WIFI_MAINPAGE,\r
+    title = STRING_TOKEN(STR_NETWORK_MANAGEMENT_TITLE);\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_MAC_ADDRESS_HELP),      // Help string\r
+      text   = STRING_TOKEN(STR_MAC_ADDRESS_TITLE),     // Prompt string\r
+        text   = STRING_TOKEN(STR_MAC_ADDRESS);         // TextTwo\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_NULL_STRING),           // Help string\r
+      text   = STRING_TOKEN(STR_CONNECTION_INFO),       // Prompt string\r
+        text   = STRING_TOKEN(STR_CONNECTED_SSID);      // TextTwo;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    goto FORMID_NETWORK_LIST,\r
+         prompt = STRING_TOKEN(STR_NETWORK_LIST),\r
+         help   = STRING_TOKEN(STR_NETWORK_LIST_HELP),\r
+         flags  = INTERACTIVE,\r
+         key    = KEY_NETWORK_LIST;\r
+\r
+    goto FORMID_WIFI_SETTINGS,\r
+         prompt = STRING_TOKEN(STR_WIFI_SETTINGS),\r
+         help   = STRING_TOKEN(STR_WIFI_SETTINGS_HELP),\r
+         flags  = INTERACTIVE,\r
+         key    = KEY_WIFI_SETTINGS;\r
+\r
+    action\r
+         questionid  = KEY_REFRESH_TITLE_CONNECTION_STATUS,\r
+         prompt      = STRING_TOKEN(STR_NULL_STRING),\r
+         help        = STRING_TOKEN(STR_NULL_STRING),\r
+         flags       = INTERACTIVE,\r
+         config      = STRING_TOKEN(STR_NULL_STRING),\r
+         refreshguid = WIFI_CONFIG_MAIN_FORM_REFRESH_GUID,\r
+    endaction;\r
+\r
+  endform;\r
+\r
+  form formid = FORMID_NETWORK_LIST,\r
+    title = STRING_TOKEN(STR_NETWORK_LIST);\r
+\r
+    numeric varid   = WIFI_MANAGER_IFR_NVDATA.ProfileCount,\r
+            prompt  = STRING_TOKEN(STR_REFRESH_NETWORK_COUNT),\r
+            help    = STRING_TOKEN(STR_REFRESH_NETWORK_COUNT_HELP),\r
+            flags   = INTERACTIVE | READ_ONLY,\r
+            key     = KEY_REFRESH_NETWORK_LIST,\r
+            minimum = 0,\r
+            maximum = 0xffffffff,\r
+            step    = 0,\r
+            default = 0,\r
+            refreshguid = WIFI_CONFIG_NETWORK_LIST_REFRESH_GUID,\r
+    endnumeric;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    label LABEL_NETWORK_LIST_ENTRY;\r
+    label LABEL_END;\r
+  endform;\r
+\r
+  form formid = FORMID_CONNECT_NETWORK,\r
+    title = STRING_TOKEN(STR_NETWORK_CONFIGURATION);\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_CONNECT_STATUS_TITLE_HELP), // Help string\r
+      text   = STRING_TOKEN(STR_CONNECT_STATUS_TITLE),      // Prompt string\r
+        text   = STRING_TOKEN(STR_CONNECT_STATUS);          // TextTwo\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_SSID_HELP),     // Help string\r
+      text   = STRING_TOKEN(STR_SSID_TITLE),    // Prompt string\r
+        text   = STRING_TOKEN(STR_SSID);        // TextTwo\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_SECURITY_TYPE_HELP),       // Help string\r
+      text   = STRING_TOKEN(STR_SECURITY_TYPE_TITLE),      // Prompt string\r
+        text   = STRING_TOKEN(STR_SECURITY_TYPE);          // TextTwo\r
+\r
+\r
+    suppressif NOT ideqval WIFI_MANAGER_IFR_NVDATA.SecurityType == SECURITY_TYPE_WPA2_PERSONAL;\r
+      password  varid    = WIFI_MANAGER_IFR_NVDATA.Password,\r
+                prompt   = STRING_TOKEN(STR_PASSWORD),\r
+                help     = STRING_TOKEN(STR_PASSWORD_HELP),\r
+                flags    = INTERACTIVE,\r
+                key      = KEY_PASSWORD_CONNECT_NETWORK,\r
+                minsize  = PASSWORD_MIN_LEN,\r
+                maxsize  = PASSWORD_MAX_LEN,\r
+      endpassword;\r
+    endif;\r
+\r
+    suppressif NOT ideqval WIFI_MANAGER_IFR_NVDATA.SecurityType == SECURITY_TYPE_WPA2_ENTERPRISE;\r
+\r
+      oneof varid       = WIFI_MANAGER_IFR_NVDATA.EapAuthMethod,\r
+            questionid  = KEY_EAP_AUTH_METHOD_CONNECT_NETWORK,\r
+            prompt      = STRING_TOKEN(STR_EAP_AUTH_METHOD),\r
+            help        = STRING_TOKEN(STR_EAP_AUTH_METHOD_HELP),\r
+            flags       = INTERACTIVE,\r
+            option text = STRING_TOKEN(STR_EAP_AUTH_METHOD_TTLS), value = EAP_AUTH_METHOD_TTLS, flags = DEFAULT;\r
+            option text = STRING_TOKEN(STR_EAP_AUTH_METHOD_PEAP), value = EAP_AUTH_METHOD_PEAP, flags = 0;\r
+            option text = STRING_TOKEN(STR_EAP_AUTH_METHOD_TLS),  value = EAP_AUTH_METHOD_TLS,  flags = 0;\r
+      endoneof;\r
+\r
+      suppressif NOT ideqvallist WIFI_MANAGER_IFR_NVDATA.EapAuthMethod == EAP_AUTH_METHOD_TLS\r
+                                                                          EAP_AUTH_METHOD_TTLS\r
+                                                                          EAP_AUTH_METHOD_PEAP;\r
+\r
+        goto FORMID_ENROLL_CERT,\r
+           prompt = STRING_TOKEN(STR_EAP_ENROLL_CA_CERT),\r
+           help   = STRING_TOKEN(STR_EAP_ENROLL_CA_CERT_HELP),\r
+           flags  = INTERACTIVE,\r
+           key    = KEY_ENROLL_CA_CERT_CONNECT_NETWORK;\r
+\r
+        suppressif NOT ideqval WIFI_MANAGER_IFR_NVDATA.EapAuthMethod == EAP_AUTH_METHOD_TLS;\r
+\r
+            goto FORMID_ENROLL_CERT,\r
+               prompt = STRING_TOKEN(STR_EAP_ENROLL_CLIENT_CERT),\r
+               help   = STRING_TOKEN(STR_EAP_ENROLL_CLIENT_CERT_HELP),\r
+               flags  = INTERACTIVE,\r
+               key    = KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK;\r
+\r
+            goto FORMID_ENROLL_PRIVATE_KEY,\r
+               prompt = STRING_TOKEN(STR_EAP_ENROLL_CLIENT_KEY),\r
+               help   = STRING_TOKEN(STR_EAP_ENROLL_CLIENT_KEY_HELP),\r
+               flags  = INTERACTIVE,\r
+               key    = KEY_ENROLL_PRIVATE_KEY_CONNECT_NETWORK;\r
+\r
+        endif;\r
+\r
+        suppressif NOT ideqvallist WIFI_MANAGER_IFR_NVDATA.EapAuthMethod == EAP_AUTH_METHOD_TTLS\r
+                                                                            EAP_AUTH_METHOD_PEAP;\r
+\r
+            oneof varid       = WIFI_MANAGER_IFR_NVDATA.EapSecondAuthMethod,\r
+                  questionid  = KEY_EAP_SEAUTH_METHOD_CONNECT_NETWORK,\r
+                  prompt      = STRING_TOKEN(STR_EAP_SEAUTH_METHOD),\r
+                  help        = STRING_TOKEN(STR_EAP_SEAUTH_METHOD_HELP),\r
+                  flags       = INTERACTIVE,\r
+                  option text = STRING_TOKEN(STR_EAP_SEAUTH_METHOD_MSCHAPV2), value = EAP_SEAUTH_METHOD_MSCHAPV2, flags = DEFAULT;\r
+            endoneof;\r
+        endif;\r
+\r
+        string  varid  = WIFI_MANAGER_IFR_NVDATA.EapIdentity,\r
+                prompt  = STRING_TOKEN(STR_EAP_IDENTITY),\r
+                help    = STRING_TOKEN(STR_EAP_IDENTITY_HELP),\r
+                flags   = INTERACTIVE,\r
+                key     = KEY_EAP_IDENTITY_CONNECT_NETWORK,\r
+                minsize = 6,\r
+                maxsize = EAP_IDENTITY_LEN,\r
+        endstring;\r
+\r
+        suppressif NOT ideqvallist WIFI_MANAGER_IFR_NVDATA.EapAuthMethod == EAP_AUTH_METHOD_TTLS\r
+                                                                            EAP_AUTH_METHOD_PEAP;\r
+\r
+            password  varid    = WIFI_MANAGER_IFR_NVDATA.EapPassword,\r
+                      prompt   = STRING_TOKEN(STR_EAP_PASSWORD),\r
+                      help     = STRING_TOKEN(STR_EAP_PASSWORD_HELP),\r
+                      flags    = INTERACTIVE,\r
+                      key      = KEY_EAP_PASSWORD_CONNECT_NETWORK,\r
+                      minsize  = 0,\r
+                      maxsize  = PASSWORD_MAX_LEN,\r
+            endpassword;\r
+        endif;\r
+      endif;\r
+    endif;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_CONNECT_NOW_HELP),\r
+      text   = STRING_TOKEN(STR_CONNECT_NOW),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_CONNECT_ACTION;\r
+\r
+    action\r
+      questionid  = KEY_REFRESH_CONNECT_CONFIGURATION,\r
+      prompt      = STRING_TOKEN(STR_NULL_STRING),\r
+      help        = STRING_TOKEN(STR_NULL_STRING),\r
+      flags       = INTERACTIVE,\r
+      config      = STRING_TOKEN(STR_NULL_STRING),\r
+      refreshguid = WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID,\r
+    endaction;\r
+\r
+  endform;\r
+\r
+  form formid = FORMID_ENROLL_CERT,\r
+    title = STRING_TOKEN(STR_EAP_ENROLL_CERT);\r
+\r
+    goto FORMID_ENROLL_CERT,\r
+         prompt = STRING_TOKEN(STR_EAP_ENROLL_CERT_FROM_FILE),\r
+         help   = STRING_TOKEN(STR_EAP_ENROLL_CERT_FROM_FILE_HELP),\r
+         flags  = INTERACTIVE,\r
+         key    = KEY_EAP_ENROLL_CERT_FROM_FILE;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_NULL_STRING),\r
+      text   = STRING_TOKEN(STR_EAP_ENROLLED_CERT_NAME),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_ENROLLED_CERT_NAME;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_SAVE_EXIT_HELP),\r
+      text   = STRING_TOKEN(STR_SAVE_EXIT),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_SAVE_CERT_TO_MEM;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_NO_SAVE_EXIT_HELP),\r
+      text   = STRING_TOKEN(STR_NO_SAVE_EXIT),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_NO_SAVE_CERT_TO_MEM;\r
+\r
+  endform;\r
+\r
+  form formid = FORMID_ENROLL_PRIVATE_KEY,\r
+    title = STRING_TOKEN(STR_EAP_ENROLL_CLIENT_KEY);\r
+\r
+    goto FORMID_ENROLL_PRIVATE_KEY,\r
+         prompt = STRING_TOKEN(STR_EAP_ENROLL_KEY_FROM_FILE),\r
+         help   = STRING_TOKEN(STR_EAP_ENROLL_KEY_FROM_FILE_HELP),\r
+         flags  = INTERACTIVE,\r
+         key    = KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_NULL_STRING),\r
+      text   = STRING_TOKEN(STR_EAP_ENROLLED_PRIVATE_KEY_NAME),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_ENROLLED_PRIVATE_KEY_NAME;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    password  varid    = WIFI_MANAGER_IFR_NVDATA.PrivateKeyPassword,\r
+              prompt   = STRING_TOKEN(STR_EAP_CLIENT_KEY_PASSWORD),\r
+              help     = STRING_TOKEN(STR_NULL_STRING),\r
+              flags    = INTERACTIVE,\r
+              key      = KEY_PRIVATE_KEY_PASSWORD,\r
+              minsize  = 0,\r
+              maxsize  = PASSWORD_MAX_LEN,\r
+    endpassword;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_SAVE_EXIT_HELP),\r
+      text   = STRING_TOKEN(STR_SAVE_EXIT),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_SAVE_PRIVATE_KEY_TO_MEM;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_NO_SAVE_EXIT_HELP),\r
+      text   = STRING_TOKEN(STR_NO_SAVE_EXIT),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_NO_SAVE_PRIVATE_KEY_TO_MEM;\r
+\r
+  endform;\r
+\r
+  form formid = FORMID_WIFI_SETTINGS,\r
+    title = STRING_TOKEN(STR_WIFI_SETTINGS_FORM_TITLE);\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+    goto FORMID_HIDDEN_NETWORK_LIST,\r
+         prompt = STRING_TOKEN(STR_HIDDEN_NETWORK),\r
+         help   = STRING_TOKEN(STR_HIDDEN_NETWORK_HELP),\r
+         flags  = INTERACTIVE,\r
+         key    = KEY_HIDDEN_NETWORK;\r
+\r
+  endform;\r
+\r
+  form formid = FORMID_HIDDEN_NETWORK_LIST,\r
+    title = STRING_TOKEN(STR_HIDDEN_NETWORK_FORM_TITLE);\r
+\r
+    string\r
+      varid   = WIFI_MANAGER_IFR_NVDATA.SSId,\r
+      prompt  = STRING_TOKEN(STR_SSID_TITLE),\r
+      help    = STRING_TOKEN(STR_SSID_HELP),\r
+      flags   = INTERACTIVE,\r
+      minsize = SSID_MIN_LEN,\r
+      maxsize = SSID_MAX_LEN,\r
+    endstring;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_ADD_HIDDEN_NETWORK_HELP),\r
+      text   = STRING_TOKEN(STR_ADD_HIDDEN_NETWORK),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_ADD_HIDDEN_NETWORK;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+    subtitle text = STRING_TOKEN(STR_HIDDEN_NETWORK_LIST);\r
+\r
+    label LABEL_HIDDEN_NETWORK_ENTRY;\r
+    label LABEL_END;\r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_REMOVE_HIDDEN_NETWORK_HELP),\r
+      text   = STRING_TOKEN(STR_REMOVE_HIDDEN_NETWORK),\r
+      flags  = INTERACTIVE,\r
+      key    = KEY_REMOVE_HIDDEN_NETWORK;\r
+\r
+  endform;\r
+\r
+endformset;\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxeStrings.uni b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxeStrings.uni
new file mode 100644 (file)
index 0000000..59bffec
--- /dev/null
@@ -0,0 +1,109 @@
+// /** @file\r
+//   String definitions for WiFi Connection Manager Forms.\r
+//\r
+//   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+//   This program and the accompanying materials\r
+//   are licensed and made available under the terms and conditions of the BSD License\r
+//   which accompanies this distribution.  The full text of the license may be found at\r
+//   http://opensource.org/licenses/bsd-license.php\r
+//\r
+//   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+#langdef en-US "English"\r
+\r
+#string STR_WIFI_MGR_FORM_TITLE           #language en-US "Wi-Fi Configuration"\r
+#string STR_WIFI_MGR_FORM_HELP            #language en-US "Configure the Wi-Fi parameters."\r
+\r
+#string STR_WIFI_MAC_FORM_TITLE           #language en-US "MAC Selection"\r
+#string STR_WIFI_MAC_FORM_HELP            #language en-US "Select a Nic"\r
+\r
+#string STR_MAC_ADDRESS_TITLE             #language en-US "MAC Address"\r
+#string STR_MAC_ADDRESS                   #language en-US "88-88-88-88-88-87"\r
+#string STR_MAC_ADDRESS_HELP              #language en-US "MAC Address"\r
+#string STR_CONNECTION_INFO               #language en-US "Disconnected"\r
+#string STR_CONNECTED_SSID                #language en-US ""\r
+#string STR_NULL_STRING                   #language en-US ""\r
+\r
+#string STR_NETWORK_MANAGEMENT_TITLE      #language en-US "Wi-Fi Network Management"\r
+#string STR_NETWORK_LIST                  #language en-US "Wi-Fi Network List"\r
+#string STR_NETWORK_LIST_HELP             #language en-US "Available Network List"\r
+#string STR_NETWORK_CONFIGURATION         #language en-US "Wi-Fi Network Configuration"\r
+\r
+#string STR_SSID_TITLE                    #language en-US "SSID"\r
+#string STR_SSID                          #language en-US ""\r
+#string STR_SSID_HELP                     #language en-US "SSID Length: 1 - 32 characters"\r
+#string STR_SECURITY_TYPE_TITLE           #language en-US "Security"\r
+#string STR_SECURITY_TYPE                 #language en-US ""\r
+#string STR_SECURITY_TYPE_HELP            #language en-US "Network Security Type"\r
+\r
+#string STR_EAP_AUTH_METHOD               #language en-US "EAP Authentication Method"\r
+#string STR_EAP_AUTH_METHOD_HELP          #language en-US "EAP Authentication Method"\r
+#string STR_EAP_SEAUTH_METHOD             #language en-US "EAP Second Authentication Method"\r
+#string STR_EAP_SEAUTH_METHOD_HELP        #language en-US "EAP Second Authentication Method"\r
+#string STR_SECURITY_NONE                 #language en-US "Open"\r
+#string STR_SECURITY_WEP                  #language en-US "WEP"\r
+#string STR_SECURITY_WPA_PERSONAL         #language en-US "WPA-Personal"\r
+#string STR_SECURITY_WPA_ENTERPRISE       #language en-US "WPA-Enterprise"\r
+#string STR_SECURITY_WPA2_PERSONAL        #language en-US "WPA2-Personal"\r
+#string STR_SECURITY_WPA2_ENTERPRISE      #language en-US "WPA2-Enterprise"\r
+#string STR_SECURITY_UNKNOWN              #language en-US "Unknown"\r
+#string STR_EAP_AUTH_METHOD_TLS           #language en-US "EAPTLS"\r
+#string STR_EAP_AUTH_METHOD_TTLS          #language en-US "TTLS"\r
+#string STR_EAP_AUTH_METHOD_PEAP          #language en-US "PEAP"\r
+#string STR_EAP_SEAUTH_METHOD_MSCHAPV2    #language en-US "MSCHAPv2"\r
+#string STR_EAP_SEAUTH_METHOD_GTC         #language en-US "GTC"\r
+\r
+#string STR_PASSWORD                      #language en-US "Password"\r
+#string STR_PASSWORD_HELP                 #language en-US "Password Length: 8 - 63 characters"\r
+#string STR_CONNECT_STATUS_TITLE          #language en-US "Connection Status:"\r
+#string STR_CONNECT_STATUS_TITLE_HELP     #language en-US ""\r
+#string STR_CONNECT_STATUS                #language en-US ""\r
+#string STR_CONNECT_STATUS_HELP           #language en-US ""\r
+\r
+#string STR_CONNECT_NOW                   #language en-US "Connect to network now"\r
+#string STR_CONNECT_NOW_HELP              #language en-US ""\r
+#string STR_DISCONNECT_NOW                #language en-US "Disconnect from this network"\r
+#string STR_DISCONNECT_NOW_HELP           #language en-US ""\r
+#string STR_REFRESH_NETWORK_COUNT         #language en-US "Number of Networks"\r
+#string STR_REFRESH_NETWORK_COUNT_HELP    #language en-US "The number of current available networks around"\r
+\r
+#string STR_EAP_IDENTITY                  #language en-US "Identity"\r
+#string STR_EAP_IDENTITY_HELP             #language en-US "It is used to query the identity of the peer."\r
+#string STR_EAP_PASSWORD                  #language en-US "EAP Password"\r
+#string STR_EAP_PASSWORD_HELP             #language en-US "Password Length: 1 - 63 characters"\r
+\r
+#string STR_SAVE_EXIT                     #language en-US "Commit Changes and Exit"\r
+#string STR_SAVE_EXIT_HELP                #language en-US ""\r
+#string STR_NO_SAVE_EXIT                  #language en-US "Discard Changes and Exit"\r
+#string STR_NO_SAVE_EXIT_HELP             #language en-US ""\r
+\r
+#string STR_EAP_ENROLL_CERT                   #language en-US "Enroll Certificate"\r
+#string STR_EAP_ENROLL_CA_CERT                #language en-US "Enroll CA Cert"\r
+#string STR_EAP_ENROLL_CA_CERT_HELP           #language en-US ""\r
+#string STR_EAP_ENROLL_CLIENT_CERT            #language en-US "Enroll Client Cert"\r
+#string STR_EAP_ENROLL_CLIENT_CERT_HELP       #language en-US ""\r
+#string STR_EAP_ENROLL_CLIENT_KEY             #language en-US "Enroll Client Private Key"\r
+#string STR_EAP_ENROLL_CLIENT_KEY_HELP        #language en-US ""\r
+#string STR_EAP_ENROLL_CERT_FROM_FILE         #language en-US "Enroll Cert Using File"\r
+#string STR_EAP_ENROLL_CERT_FROM_FILE_HELP    #language en-US ""\r
+#string STR_EAP_ENROLL_KEY_FROM_FILE          #language en-US "Enroll Private Key Using File"\r
+#string STR_EAP_ENROLL_KEY_FROM_FILE_HELP     #language en-US ""\r
+#string STR_EAP_CLIENT_KEY_PASSWORD           #language en-US "Client Private Key Password"\r
+#string STR_EAP_ENROLLED_CERT_NAME            #language en-US ""\r
+#string STR_EAP_ENROLLED_PRIVATE_KEY_NAME     #language en-US ""\r
+\r
+#string STR_WIFI_SETTINGS_FORM_TITLE          #language en-US "Wi-Fi Settings"\r
+#string STR_WIFI_SETTINGS                     #language en-US "Wi-Fi Settings"\r
+#string STR_WIFI_SETTINGS_HELP                #language en-US ""\r
+\r
+#string STR_HIDDEN_NETWORK_FORM_TITLE         #language en-US "Hidden Network Configuration"\r
+#string STR_HIDDEN_NETWORK                    #language en-US "Hidden Network Configuration"\r
+#string STR_HIDDEN_NETWORK_HELP               #language en-US ""\r
+#string STR_ADD_HIDDEN_NETWORK_HELP           #language en-US "Hidden Network List won't be saved in Storage, they will be cleaned after Reset!"\r
+#string STR_ADD_HIDDEN_NETWORK                #language en-US "Add Hidden Network"\r
+#string STR_HIDDEN_NETWORK_LIST               #language en-US "Hidden Network List"\r
+#string STR_REMOVE_HIDDEN_NETWORK_HELP        #language en-US ""\r
+#string STR_REMOVE_HIDDEN_NETWORK             #language en-US "Remove Hidden Network"\r
\ No newline at end of file
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrComponentName.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrComponentName.c
new file mode 100644 (file)
index 0000000..0d7d695
--- /dev/null
@@ -0,0 +1,191 @@
+/** @file\r
+  UEFI Component Name(2) protocol implementation for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "WifiConnectionMgrDxe.h"\r
+\r
+extern EFI_GUID mEfiWifiMgrPrivateGuid;\r
+\r
+///\r
+/// Component Name Protocol instance\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+EFI_COMPONENT_NAME_PROTOCOL  gWifiMgrDxeComponentName = {\r
+  (EFI_COMPONENT_NAME_GET_DRIVER_NAME)     WifiMgrDxeComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) WifiMgrDxeComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+///\r
+/// Component Name 2 Protocol instance\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+EFI_COMPONENT_NAME2_PROTOCOL  gWifiMgrDxeComponentName2 = {\r
+  WifiMgrDxeComponentNameGetDriverName,\r
+  WifiMgrDxeComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+///\r
+/// Table of driver names\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+EFI_UNICODE_STRING_TABLE mWifiMgrDxeDriverNameTable[] = {\r
+  {\r
+    "eng;en",\r
+    L"UEFI WiFi Connection Manager"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+///\r
+/// Table of controller names\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+EFI_UNICODE_STRING_TABLE mWifiMgrDxeControllerNameTable[] = {\r
+  {\r
+    "eng;en",\r
+    L"UEFI WiFi Connection Manager Controller"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user-readable name of the EFI Driver.\r
+\r
+  @param  This       A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  Language   A pointer to a three-character ISO 639-2 language identifier.\r
+                     This is the language of the driver name that that the caller\r
+                     is requesting, and it must match one of the languages specified\r
+                     in SupportedLanguages.  The number of languages supported by a\r
+                     driver is up to the driver writer.\r
+  @param  DriverName A pointer to the Unicode string to return.  This Unicode string\r
+                     is the name of the driver specified by This in the language\r
+                     specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by This\r
+                                and the language specified by Language was returned\r
+                                in DriverName.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support the\r
+                                language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeComponentNameGetDriverName (\r
+  IN EFI_COMPONENT_NAME2_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mWifiMgrDxeDriverNameTable,\r
+           DriverName,\r
+           (BOOLEAN)(This != &gWifiMgrDxeComponentName2)\r
+           );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by an EFI Driver.\r
+\r
+  @param  This             A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  ControllerHandle The handle of a controller that the driver specified by\r
+                           This is managing.  This handle specifies the controller\r
+                           whose name is to be returned.\r
+  @param  ChildHandle      The handle of the child controller to retrieve the name\r
+                           of.  This is an optional parameter that may be NULL.  It\r
+                           will be NULL for device drivers.  It will also be NULL\r
+                           for a bus drivers that wish to retrieve the name of the\r
+                           bus controller.  It will not be NULL for a bus driver\r
+                           that wishes to retrieve the name of a child controller.\r
+  @param  Language         A pointer to a three character ISO 639-2 language\r
+                           identifier.  This is the language of the controller name\r
+                           that the caller is requesting, and it must match one\r
+                           of the languages specified in SupportedLanguages.  The\r
+                           number of languages supported by a driver is up to the\r
+                           driver writer.\r
+  @param  ControllerName   A pointer to the Unicode string to return.  This Unicode\r
+                           string is the name of the controller specified by\r
+                           ControllerHandle and ChildHandle in the language specified\r
+                           by Language, from the point of view of the driver specified\r
+                           by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user-readable name in the\r
+                                language specified by Language for the driver\r
+                                specified by This was returned in DriverName.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently managing\r
+                                the controller specified by ControllerHandle and\r
+                                ChildHandle.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support the\r
+                                language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  EFI_HANDLE                    ChildHandle        OPTIONAL,\r
+  IN  CHAR8                         *Language,\r
+  OUT CHAR16                        **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  WIFI_MGR_PRIVATE_PROTOCOL    *WifiMgrPrivate;\r
+\r
+  //\r
+  // ChildHandle must be NULL for a Device Driver\r
+  //\r
+  if (ControllerHandle == NULL || ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Check Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &mEfiWifiMgrPrivateGuid,\r
+                  (VOID **) &WifiMgrPrivate,\r
+                  NULL,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mWifiMgrDxeControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This != &gWifiMgrDxeComponentName2)\r
+           );\r
+}\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrComponentName.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrComponentName.h
new file mode 100644 (file)
index 0000000..f69e682
--- /dev/null
@@ -0,0 +1,99 @@
+/** @file\r
+  UEFI Component Name(2) protocol implementation for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_COMPONENT_NAME__\r
+#define __EFI_WIFI_COMPONENT_NAME__\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user-readable name of the EFI Driver.\r
+\r
+  @param  This       A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  Language   A pointer to a three-character ISO 639-2 language identifier.\r
+                     This is the language of the driver name that that the caller\r
+                     is requesting, and it must match one of the languages specified\r
+                     in SupportedLanguages.  The number of languages supported by a\r
+                     driver is up to the driver writer.\r
+  @param  DriverName A pointer to the Unicode string to return.  This Unicode string\r
+                     is the name of the driver specified by This in the language\r
+                     specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by This\r
+                                and the language specified by Language was returned\r
+                                in DriverName.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support the\r
+                                language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeComponentNameGetDriverName (\r
+  IN EFI_COMPONENT_NAME2_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by an EFI Driver.\r
+\r
+  @param  This             A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  ControllerHandle The handle of a controller that the driver specified by\r
+                           This is managing.  This handle specifies the controller\r
+                           whose name is to be returned.\r
+  @param  ChildHandle      The handle of the child controller to retrieve the name\r
+                           of.  This is an optional parameter that may be NULL.  It\r
+                           will be NULL for device drivers.  It will also be NULL\r
+                           for a bus drivers that wish to retrieve the name of the\r
+                           bus controller.  It will not be NULL for a bus driver\r
+                           that wishes to retrieve the name of a child controller.\r
+  @param  Language         A pointer to a three character ISO 639-2 language\r
+                           identifier.  This is the language of the controller name\r
+                           that the caller is requesting, and it must match one\r
+                           of the languages specified in SupportedLanguages.  The\r
+                           number of languages supported by a driver is up to the\r
+                           driver writer.\r
+  @param  ControllerName   A pointer to the Unicode string to return.  This Unicode\r
+                           string is the name of the controller specified by\r
+                           ControllerHandle and ChildHandle in the language specified\r
+                           by Language, from the point of view of the driver specified\r
+                           by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user-readable name in the\r
+                                language specified by Language for the driver\r
+                                specified by This was returned in DriverName.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently managing\r
+                                the controller specified by ControllerHandle and\r
+                                ChildHandle.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support the\r
+                                language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  EFI_HANDLE                    ChildHandle        OPTIONAL,\r
+  IN  CHAR8                         *Language,\r
+  OUT CHAR16                        **ControllerName\r
+  );\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfig.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfig.h
new file mode 100644 (file)
index 0000000..f179fbc
--- /dev/null
@@ -0,0 +1,74 @@
+/** @file\r
+  Define network structure used by the WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _WIFI_MGR_CONFIG_H_\r
+#define _WIFI_MGR_CONFIG_H_\r
+\r
+#include "WifiConnectionMgrConfigNVDataStruct.h"\r
+\r
+extern UINT8        WifiConnectionManagerDxeBin[];\r
+extern UINT8        WifiConnectionManagerDxeStrings[];\r
+\r
+typedef struct {\r
+  UINT32               Signature;\r
+\r
+  //\r
+  // Link to the current profile list in NIC device data (WIFI_MGR_DEVICE_DATA)\r
+  //\r
+  LIST_ENTRY           Link;\r
+\r
+  UINT32               NicIndex;\r
+  UINT32               ProfileIndex;   // The unique identifier for network profile, starts from 1\r
+  CHAR16               SSId[SSID_STORAGE_SIZE];\r
+  CHAR16               Password[PASSWORD_STORAGE_SIZE];\r
+\r
+  UINT8                SecurityType;\r
+  UINT8                EapAuthMethod;\r
+\r
+  CHAR16               CACertName[WIFI_FILENAME_STR_MAX_SIZE];\r
+  VOID                 *CACertData;\r
+  UINTN                CACertSize;\r
+  CHAR16               ClientCertName[WIFI_FILENAME_STR_MAX_SIZE];\r
+  VOID                 *ClientCertData;\r
+  UINTN                ClientCertSize;\r
+  CHAR16               PrivateKeyName[WIFI_FILENAME_STR_MAX_SIZE];\r
+  VOID                 *PrivateKeyData;\r
+  UINTN                PrivateKeyDataSize;\r
+  CHAR16               PrivateKeyPassword[PASSWORD_STORAGE_SIZE];    //Password to protect private key file\r
+  CHAR16               EapIdentity[EAP_IDENTITY_SIZE];\r
+  CHAR16               EapPassword[PASSWORD_STORAGE_SIZE];\r
+  UINT8                EapSecondAuthMethod;\r
+\r
+  BOOLEAN              AKMSuiteSupported;\r
+  BOOLEAN              CipherSuiteSupported;\r
+  BOOLEAN              IsAvailable;\r
+  EFI_80211_NETWORK    Network;\r
+  UINT8                NetworkQuality;\r
+  EFI_STRING_ID        TitleToken;\r
+} WIFI_MGR_NETWORK_PROFILE;\r
+\r
+#define WIFI_MGR_PROFILE_SIGNATURE  SIGNATURE_32 ('W','M','N','P')\r
+\r
+#pragma pack(1)\r
+///\r
+/// HII specific Vendor Device Path definition.\r
+///\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH               VendorDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL         End;\r
+} HII_VENDOR_DEVICE_PATH;\r
+#pragma pack()\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigHii.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigHii.h
new file mode 100644 (file)
index 0000000..43c0f02
--- /dev/null
@@ -0,0 +1,35 @@
+/** @file\r
+  Module level GUIDs used in WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __WIFI_CONFIG_HII_GUID_H__\r
+#define __WIFI_CONFIG_HII_GUID_H__\r
+\r
+// {36AF7790-0C2F-4055-9D3D-DB72A44953CB}\r
+#define WIFI_CONFIG_NETWORK_LIST_REFRESH_GUID \\r
+  { \\r
+    0xc5f3c7f9, 0xfb9d, 0x49f1, { 0xbe, 0x67, 0x8b, 0xad, 0x20, 0xa7, 0xc6, 0xac } \\r
+  }\r
+\r
+#define WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID \\r
+  { \\r
+    0xe5faf2b2, 0x5ecc, 0x44ac, { 0x91, 0x75, 0xfb, 0x78, 0xb2, 0x8a, 0x59, 0x6c } \\r
+  }\r
+\r
+#define WIFI_CONFIG_MAIN_FORM_REFRESH_GUID \\r
+  { \\r
+    0xde609972, 0xcbcc, 0x4e82, { 0x8b, 0x3e, 0x6a, 0xc5, 0xcf, 0x56, 0x73, 0x8d } \\r
+  }\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h
new file mode 100644 (file)
index 0000000..d62b36d
--- /dev/null
@@ -0,0 +1,158 @@
+/** @file\r
+  Define IFR NVData structures used by the WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _WIFI_NVDATASTRUC_H_\r
+#define _WIFI_NVDATASTRUC_H_\r
+\r
+#include <Guid/WifiConnectionManagerConfigHii.h>\r
+#include "WifiConnectionMgrConfigHii.h"\r
+\r
+#define MANAGER_VARSTORE_ID           0x0802\r
+\r
+#define WIFI_STR_MAX_SIZE             224\r
+#define WIFI_FILENAME_STR_MAX_SIZE    224\r
+#define WIFI_MGR_MAX_MAC_STRING_LEN   96\r
+\r
+#define SSID_MIN_LEN                  1\r
+#define SSID_MAX_LEN                  32\r
+#define SSID_STORAGE_SIZE             33\r
+\r
+#define PASSWORD_MIN_LEN              8\r
+#define PASSWORD_MAX_LEN              63\r
+#define PASSWORD_STORAGE_SIZE         64\r
+\r
+#define EAP_IDENTITY_LEN              63\r
+#define EAP_IDENTITY_SIZE             64\r
+\r
+#define FORMID_NONE_FORM              0\r
+#define FORMID_MAC_SELECTION          1\r
+#define FORMID_WIFI_MAINPAGE          2\r
+#define FORMID_NETWORK_LIST           3\r
+#define FORMID_CONNECT_NETWORK        4\r
+#define FORMID_ENROLL_CERT            5\r
+#define FORMID_CA_LIST                6\r
+#define FORMID_ENROLL_PRIVATE_KEY     7\r
+#define FORMID_PRIVATE_KEY_LIST       8\r
+#define FORMID_WIFI_SETTINGS          9\r
+#define FORMID_HIDDEN_NETWORK_LIST    10\r
+\r
+//\r
+// Mac List Form Key\r
+//\r
+#define KEY_MAC_LIST                              0x100\r
+\r
+//\r
+// Main Form Key\r
+//\r
+#define KEY_REFRESH_TITLE_CONNECTION_STATUS       0x101\r
+\r
+//\r
+// Network List Form Key\r
+//\r
+#define KEY_NETWORK_LIST                          0x102\r
+#define KEY_REFRESH_NETWORK_LIST                  0x103\r
+#define KEY_WIFI_SETTINGS                         0x104\r
+\r
+//\r
+// Connect Network Form Key\r
+//\r
+#define KEY_PASSWORD_CONNECT_NETWORK              0x201\r
+#define KEY_CONNECT_ACTION                        0x202\r
+#define KEY_REFRESH_CONNECT_CONFIGURATION         0x203\r
+#define KEY_EAP_AUTH_METHOD_CONNECT_NETWORK       0x204\r
+#define KEY_EAP_SEAUTH_METHOD_CONNECT_NETWORK     0x205\r
+#define KEY_ENROLL_CA_CERT_CONNECT_NETWORK        0x206\r
+#define KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK    0x207\r
+#define KEY_ENROLL_PRIVATE_KEY_CONNECT_NETWORK    0x208\r
+#define KEY_EAP_IDENTITY_CONNECT_NETWORK          0x209\r
+#define KEY_EAP_PASSWORD_CONNECT_NETWORK          0x210\r
+\r
+//\r
+//Cert Form And Private Key Form\r
+//\r
+#define KEY_EAP_ENROLL_CERT_FROM_FILE             0x301\r
+#define KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE      0x302\r
+#define KEY_SAVE_CERT_TO_MEM                      0x303\r
+#define KEY_NO_SAVE_CERT_TO_MEM                   0x304\r
+#define KEY_SAVE_PRIVATE_KEY_TO_MEM               0x305\r
+#define KEY_NO_SAVE_PRIVATE_KEY_TO_MEM            0x306\r
+#define KEY_PRIVATE_KEY_PASSWORD                  0x307\r
+#define KEY_ENROLLED_CERT_NAME                    0x308\r
+#define KEY_ENROLLED_PRIVATE_KEY_NAME             0x309\r
+\r
+//\r
+// Hidden Network Configuration Form\r
+//\r
+#define KEY_HIDDEN_NETWORK                        0x401\r
+#define KEY_ADD_HIDDEN_NETWORK                    0x402\r
+#define KEY_REMOVE_HIDDEN_NETWORK                 0x403\r
+\r
+//\r
+// Dynamic Lists\r
+//\r
+#define MAC_LIST_COUNT_MAX                        255\r
+#define LABEL_MAC_ENTRY                           0x1000\r
+#define KEY_MAC_ENTRY_BASE                        0x1100\r
+\r
+#define NETWORK_LIST_COUNT_MAX                    4095\r
+#define LABEL_NETWORK_LIST_ENTRY                  0x2000\r
+#define KEY_AVAILABLE_NETWORK_ENTRY_BASE          0x3000\r
+\r
+#define HIDDEN_NETWORK_LIST_COUNT_MAX             255\r
+#define LABEL_HIDDEN_NETWORK_ENTRY                0x4000\r
+#define KEY_HIDDEN_NETWORK_ENTRY_BASE             0x4100\r
+\r
+#define LABEL_END                                 0xffff\r
+\r
+//\r
+// Network Security Type\r
+//\r
+#define SECURITY_TYPE_NONE                        0\r
+#define SECURITY_TYPE_WPA_ENTERPRISE              1\r
+#define SECURITY_TYPE_WPA2_ENTERPRISE             2\r
+#define SECURITY_TYPE_WPA_PERSONAL                3\r
+#define SECURITY_TYPE_WPA2_PERSONAL               4\r
+#define SECURITY_TYPE_WEP                         5\r
+#define SECURITY_TYPE_UNKNOWN                     6\r
+#define SECURITY_TYPE_MAX                         7\r
+\r
+#define EAP_AUTH_METHOD_TTLS                      0\r
+#define EAP_AUTH_METHOD_PEAP                      1\r
+#define EAP_AUTH_METHOD_TLS                       2\r
+#define EAP_AUTH_METHOD_MAX                       3\r
+\r
+#define EAP_SEAUTH_METHOD_MSCHAPV2                0\r
+#define EAP_SEAUTH_METHOD_MAX                     1\r
+\r
+#define HIDDEN_NETWORK_LIST_VAR_OFFSET ((UINT16) OFFSET_OF (WIFI_MANAGER_IFR_NVDATA, HiddenNetworkList))\r
+\r
+#pragma pack(1)\r
+typedef struct _WIFI_MANAGER_IFR_NVDATA {\r
+\r
+  UINT32      ProfileCount;\r
+  CHAR16      SSId[SSID_STORAGE_SIZE];\r
+  CHAR16      Password[PASSWORD_STORAGE_SIZE];\r
+  CHAR16      PrivateKeyPassword[PASSWORD_STORAGE_SIZE];\r
+  CHAR16      EapIdentity[EAP_IDENTITY_SIZE];\r
+  CHAR16      EapPassword[PASSWORD_STORAGE_SIZE];\r
+  UINT8       SecurityType;\r
+  UINT8       EapAuthMethod;\r
+  UINT8       EapSecondAuthMethod;\r
+  UINT8       HiddenNetworkList[HIDDEN_NETWORK_LIST_COUNT_MAX];\r
+\r
+} WIFI_MANAGER_IFR_NVDATA;\r
+#pragma pack()\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
new file mode 100644 (file)
index 0000000..1431cdc
--- /dev/null
@@ -0,0 +1,621 @@
+/** @file\r
+  The driver binding protocol for the WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "WifiConnectionMgrDxe.h"\r
+\r
+///\r
+/// Driver Binding Protocol instance\r
+///\r
+EFI_DRIVER_BINDING_PROTOCOL gWifiMgrDxeDriverBinding = {\r
+  WifiMgrDxeDriverBindingSupported,\r
+  WifiMgrDxeDriverBindingStart,\r
+  WifiMgrDxeDriverBindingStop,\r
+  WIFI_MGR_DXE_VERSION,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+//\r
+//The private global data for WiFi Connection Manager\r
+//\r
+WIFI_MGR_PRIVATE_DATA    *mPrivate = NULL;\r
+\r
+//\r
+//The private guid to identify WiFi Connection Manager\r
+//\r
+EFI_GUID mEfiWifiMgrPrivateGuid            = EFI_WIFIMGR_PRIVATE_GUID;\r
+\r
+//\r
+//The Hii config guids\r
+//\r
+EFI_GUID gWifiConfigFormSetGuid            = WIFI_CONNECTION_MANAGER_CONFIG_GUID;\r
+EFI_GUID mWifiConfigNetworkListRefreshGuid = WIFI_CONFIG_NETWORK_LIST_REFRESH_GUID;\r
+EFI_GUID mWifiConfigConnectFormRefreshGuid = WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID;\r
+EFI_GUID mWifiConfigMainFormRefreshGuid    = WIFI_CONFIG_MAIN_FORM_REFRESH_GUID;\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
+\r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &mEfiWifiMgrPrivateGuid,\r
+                  NULL,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  //\r
+  // Test for the wireless MAC connection 2 protocol\r
+  //\r
+  return gBS->OpenProtocol (\r
+                ControllerHandle,\r
+                &gEfiWiFi2ProtocolGuid,\r
+                NULL,\r
+                This->DriverBindingHandle,\r
+                ControllerHandle,\r
+                EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                );\r
+}\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
+                                   for all the children of Controller are created by this driver.\r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is\r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                                 Status;\r
+  EFI_TPL                                    OldTpl;\r
+  UINTN                                      AddressSize;\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
+  //\r
+  //Open Protocols\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiWiFi2ProtocolGuid,\r
+                  (VOID**) &Wmp,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSupplicantProtocolGuid,\r
+                  (VOID**) &Supplicant,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Supplicant = NULL;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiEapConfigurationProtocolGuid,\r
+                  (VOID**) &EapConfig,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\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
+    goto ERROR1;\r
+  }\r
+  Nic->Signature            = WIFI_MGR_DEVICE_DATA_SIGNATURE;\r
+  Nic->DriverHandle         = This->DriverBindingHandle;\r
+  Nic->ControllerHandle     = ControllerHandle;\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
+  Nic->ScanTickTime         = WIFI_SCAN_FREQUENCY;  //Initialize the first scan\r
+\r
+  if (Nic->Supplicant != NULL) {\r
+    WifiMgrGetSupportedSuites(Nic);\r
+  }\r
+\r
+  InitializeListHead (&Nic->ProfileList);\r
+\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
+  //\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
+  Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS(500));\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR3;\r
+  }\r
+\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
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &ControllerHandle,\r
+                  &mEfiWifiMgrPrivateGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &Nic->WifiMgrIdentifier\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR4;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+ERROR4:\r
+\r
+  gBS->SetTimer (Nic->TickTimer, TimerCancel, 0);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  RemoveEntryList (&Nic->Link);\r
+  mPrivate->NicCount--;\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+ERROR3:\r
+\r
+  gBS->CloseEvent (Nic->TickTimer);\r
+\r
+ERROR2:\r
+\r
+  if (Nic->Supplicant != NULL) {\r
+    if (Nic->SupportedSuites.SupportedAKMSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedAKMSuites);\r
+    }\r
+    if (Nic->SupportedSuites.SupportedSwCipherSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedSwCipherSuites);\r
+    }\r
+    if (Nic->SupportedSuites.SupportedHwCipherSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedHwCipherSuites);\r
+    }\r
+  }\r
+  FreePool (Nic);\r
+\r
+ERROR1:\r
+\r
+  if (Supplicant != NULL) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           &gEfiSupplicantProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
+  }\r
+\r
+  if (EapConfig != NULL) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           &gEfiEapConfigurationProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+         ControllerHandle,\r
+         &gEfiWiFi2ProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         ControllerHandle\r
+         );\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+\r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeDriverBindingStop (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     ControllerHandle,\r
+  IN UINTN                          NumberOfChildren,\r
+  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
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &mEfiWifiMgrPrivateGuid,\r
+                  (VOID **) &WifiMgrIdentifier,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  Nic = WIFI_MGR_DEVICE_DATA_FROM_IDENTIFIER (WifiMgrIdentifier);\r
+  if (Nic == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Close Event\r
+  //\r
+  gBS->CloseEvent (Nic->TickTimer);\r
+\r
+  //\r
+  // Clean Supported Suites\r
+  //\r
+  if (Nic->Supplicant != NULL) {\r
+    if (Nic->SupportedSuites.SupportedAKMSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedAKMSuites);\r
+    }\r
+    if (Nic->SupportedSuites.SupportedSwCipherSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedSwCipherSuites);\r
+    }\r
+    if (Nic->SupportedSuites.SupportedHwCipherSuites != NULL) {\r
+      FreePool (Nic->SupportedSuites.SupportedHwCipherSuites);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Close Protocols\r
+  //\r
+  Status = gBS->UninstallProtocolInterface (\r
+             ControllerHandle,\r
+             &mEfiWifiMgrPrivateGuid,\r
+             &Nic->WifiMgrIdentifier\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->CloseProtocol (\r
+             ControllerHandle,\r
+             &gEfiWiFi2ProtocolGuid,\r
+             Nic->DriverHandle,\r
+             Nic->ControllerHandle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (Nic->Supplicant != NULL) {\r
+    Status = gBS->CloseProtocol (\r
+               ControllerHandle,\r
+               &gEfiSupplicantProtocolGuid,\r
+               Nic->DriverHandle,\r
+               Nic->ControllerHandle\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if (Nic->EapConfig != NULL) {\r
+    Status = gBS->CloseProtocol (\r
+               ControllerHandle,\r
+               &gEfiEapConfigurationProtocolGuid,\r
+               Nic->DriverHandle,\r
+               Nic->ControllerHandle\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Remove this Nic from Nic list\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  RemoveEntryList (&Nic->Link);\r
+  mPrivate->NicCount--;\r
+  if (mPrivate->CurrentNic == Nic) {\r
+    mPrivate->CurrentNic = NULL;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  WifiMgrFreeProfileList (&Nic->ProfileList);\r
+  FreePool (Nic);\r
+\r
+  DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Device Controller has been Disconnected!\n"));\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This is the declaration of an EFI image entry point. This entry point is\r
+  the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
+  both device drivers and bus drivers.\r
+\r
+  @param  ImageHandle           The firmware allocated handle for the UEFI image.\r
+  @param  SystemTable           A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+  @retval Others                An unexpected error occurred.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeDriverEntryPoint (\r
+  IN EFI_HANDLE          ImageHandle,\r
+  IN EFI_SYSTEM_TABLE    *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gWifiMgrDxeDriverBinding,\r
+             ImageHandle,\r
+             &gWifiMgrDxeComponentName,\r
+             &gWifiMgrDxeComponentName2\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Initialize the global private data structure.\r
+  //\r
+  mPrivate = AllocateZeroPool (sizeof (WIFI_MGR_PRIVATE_DATA));\r
+  if (mPrivate == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ERROR1;\r
+  }\r
+  mPrivate->Signature    = WIFI_MGR_PRIVATE_DATA_SIGNATURE;\r
+  mPrivate->DriverHandle = ImageHandle;\r
+  InitializeListHead (&mPrivate->NicList);\r
+  mPrivate->NicCount = 0;\r
+  mPrivate->CurrentNic = NULL;\r
+  InitializeListHead (&mPrivate->HiddenNetworkList);\r
+  mPrivate->HiddenNetworkCount = 0;\r
+\r
+  //\r
+  //Create events for page refresh\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  WifiMgrInternalEmptyFunction,\r
+                  NULL,\r
+                  &mWifiConfigNetworkListRefreshGuid,\r
+                  &mPrivate->NetworkListRefreshEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR2;\r
+  }\r
+\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  WifiMgrInternalEmptyFunction,\r
+                  NULL,\r
+                  &mWifiConfigConnectFormRefreshGuid,\r
+                  &mPrivate->ConnectFormRefreshEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR3;\r
+  }\r
+\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  WifiMgrInternalEmptyFunction,\r
+                  NULL,\r
+                  &mWifiConfigMainFormRefreshGuid,\r
+                  &mPrivate->MainPageRefreshEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR4;\r
+  }\r
+\r
+  Status = WifiMgrDxeConfigFormInit (mPrivate);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR5;\r
+  }\r
+\r
+  return Status;\r
+\r
+ERROR5:\r
+  gBS->CloseEvent (mPrivate->MainPageRefreshEvent);\r
+\r
+ERROR4:\r
+  gBS->CloseEvent (mPrivate->ConnectFormRefreshEvent);\r
+\r
+ERROR3:\r
+  gBS->CloseEvent (mPrivate->NetworkListRefreshEvent);\r
+\r
+ERROR2:\r
+  if (mPrivate != NULL) {\r
+    FreePool (mPrivate);\r
+    mPrivate = NULL;\r
+  }\r
+\r
+ERROR1:\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+         ImageHandle,\r
+         &gEfiDriverBindingProtocolGuid,\r
+         &gWifiMgrDxeDriverBinding,\r
+         &gEfiComponentNameProtocolGuid,\r
+         &gWifiMgrDxeComponentName,\r
+         &gEfiComponentName2ProtocolGuid,\r
+         &gWifiMgrDxeComponentName2,\r
+         NULL\r
+         );\r
+\r
+  return Status;\r
+}\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriverBinding.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriverBinding.h
new file mode 100644 (file)
index 0000000..e557d67
--- /dev/null
@@ -0,0 +1,148 @@
+/** @file\r
+  The driver binding protocol for the WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_DRIVER_BINDING__\r
+#define __EFI_WIFI_DRIVER_BINDING__\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
+\r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  );\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
+                                   for all the children of Controller are created by this driver.\r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is\r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  );\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+\r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeDriverBindingStop (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                  ControllerHandle,\r
+  IN  UINTN                       NumberOfChildren,\r
+  IN  EFI_HANDLE                  *ChildHandleBuffer OPTIONAL\r
+  );\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
new file mode 100644 (file)
index 0000000..a7e67d6
--- /dev/null
@@ -0,0 +1,327 @@
+/** @file\r
+  The miscellaneous structure definitions for WiFi connection driver.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_MGR_DXE_H__\r
+#define __EFI_WIFI_MGR_DXE_H__\r
+\r
+#include <Uefi.h>\r
+\r
+//\r
+// Libraries\r
+//\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/NetLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/UefiHiiServicesLib.h>\r
+#include <Library/FileExplorerLib.h>\r
+\r
+//\r
+// UEFI Driver Model Protocols\r
+//\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/HiiDatabase.h>\r
+#include <Protocol/HiiPackageList.h>\r
+#include <Protocol/ComponentName2.h>\r
+#include <Protocol/ComponentName.h>\r
+\r
+//\r
+// Consumed Protocols\r
+//\r
+#include <Protocol/WiFi2.h>\r
+#include <Protocol/AdapterInformation.h>\r
+#include <Protocol/Supplicant.h>\r
+#include <Protocol/SimpleNetwork.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+#include <Protocol/EapConfiguration.h>\r
+\r
+//\r
+// Produced Protocols\r
+//\r
+#include <Protocol/HiiConfigAccess.h>\r
+\r
+//\r
+// Guids\r
+//\r
+#include <Guid/ImageAuthentication.h>\r
+#include <Guid/MdeModuleHii.h>\r
+#include <Guid/WifiConnectionManagerConfigHii.h>\r
+\r
+//\r
+// NvData struct definition\r
+//\r
+#include "WifiConnectionMgrConfigNVDataStruct.h"\r
+#include "WifiConnectionMgrConfig.h"\r
+#include "EapContext.h"\r
+#include "WifiConnectionMgrConfigHii.h"\r
+\r
+//\r
+// Driver Version\r
+//\r
+#define WIFI_MGR_DXE_VERSION  0xb\r
+\r
+#define OUI_IEEE_80211I 0xAC0F00\r
+\r
+typedef enum {\r
+  Ieee80211PairwiseCipherSuiteUseGroupCipherSuite = 0,\r
+  Ieee80211PairwiseCipherSuiteWEP40  = 1,\r
+  Ieee80211PairwiseCipherSuiteTKIP   = 2,\r
+  Ieee80211PairwiseCipherSuiteCCMP   = 4,\r
+  Ieee80211PairwiseCipherSuiteWEP104 = 5,\r
+  Ieee80211PairwiseCipherSuiteBIP    = 6,\r
+  //...\r
+} IEEE_80211_PAIRWISE_CIPHER_SUITE;\r
+\r
+#define IEEE_80211_PAIRWISE_CIPHER_SUITE_USE_GROUP   (OUI_IEEE_80211I | (Ieee80211PairwiseCipherSuiteUseGroupCipherSuite << 24))\r
+#define IEEE_80211_PAIRWISE_CIPHER_SUITE_WEP40       (OUI_IEEE_80211I | (Ieee80211PairwiseCipherSuiteWEP40 << 24))\r
+#define IEEE_80211_PAIRWISE_CIPHER_SUITE_TKIP        (OUI_IEEE_80211I | (Ieee80211PairwiseCipherSuiteTKIP << 24))\r
+#define IEEE_80211_PAIRWISE_CIPHER_SUITE_CCMP        (OUI_IEEE_80211I | (Ieee80211PairwiseCipherSuiteCCMP << 24))\r
+#define IEEE_80211_PAIRWISE_CIPHER_SUITE_WEP104      (OUI_IEEE_80211I | (Ieee80211PairwiseCipherSuiteWEP104 << 24))\r
+#define IEEE_80211_PAIRWISE_CIPHER_SUITE_BIP         (OUI_IEEE_80211I | (Ieee80211PairwiseCipherSuiteBIP << 24))\r
+\r
+typedef enum {\r
+  Ieee80211AkmSuite8021XOrPMKSA       = 1,\r
+  Ieee80211AkmSuitePSK                = 2,\r
+  Ieee80211AkmSuite8021XOrPMKSASHA256 = 5,\r
+  Ieee80211AkmSuitePSKSHA256          = 6\r
+  //...\r
+} IEEE_80211_AKM_SUITE;\r
+\r
+#define IEEE_80211_AKM_SUITE_8021X_OR_PMKSA         (OUI_IEEE_80211I | (Ieee80211AkmSuite8021XOrPMKSA << 24))\r
+#define IEEE_80211_AKM_SUITE_PSK                    (OUI_IEEE_80211I | (Ieee80211AkmSuitePSK << 24))\r
+#define IEEE_80211_AKM_SUITE_8021X_OR_PMKSA_SHA256  (OUI_IEEE_80211I | (Ieee80211AkmSuite8021XOrPMKSASHA256 << 24))\r
+#define IEEE_80211_AKM_SUITE_PSK_SHA256             (OUI_IEEE_80211I | (Ieee80211AkmSuitePSKSHA256 << 24))\r
+\r
+//\r
+// Protocol instances\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL       gWifiMgrDxeDriverBinding;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL      gWifiMgrDxeComponentName2;\r
+extern EFI_COMPONENT_NAME_PROTOCOL       gWifiMgrDxeComponentName;\r
+extern EFI_HII_CONFIG_ACCESS_PROTOCOL    gWifiMgrDxeHiiConfigAccess;\r
+\r
+//\r
+// Private Context Data Structure\r
+//\r
+typedef enum {\r
+  WifiMgrDisconnected,\r
+  WifiMgrConnectingToAp,\r
+  WifiMgrConnectedToAp,\r
+  WifiMgrDisconnectingToAp,\r
+  WifiMgrConnectStateMaximum\r
+} WIFI_MGR_CONNECT_STATE;\r
+\r
+typedef enum {\r
+  WifiMgrScanFinished,\r
+  WifiMgrScanning,\r
+  WifiMgrScanStateMaximum\r
+} WIFI_MGR_SCAN_STATE;\r
+\r
+#define  WIFI_SCAN_FREQUENCY    30\r
+\r
+typedef struct _WIFI_MGR_SUPPORTED_SUITES {\r
+  EFI_80211_AKM_SUITE_SELECTOR     *SupportedAKMSuites;\r
+  EFI_80211_CIPHER_SUITE_SELECTOR  *SupportedSwCipherSuites;\r
+  EFI_80211_CIPHER_SUITE_SELECTOR  *SupportedHwCipherSuites;\r
+} WIFI_MGR_SUPPORTED_SUITES;\r
+\r
+#define EFI_WIFIMGR_PRIVATE_GUID \\r
+  { \\r
+    0x99b7c019, 0x4789, 0x4829, { 0xa7, 0xbd, 0x0d, 0x4b, 0xaa, 0x62, 0x28, 0x72 } \\r
+  }\r
+\r
+typedef struct _WIFI_MGR_PRIVATE_DATA  WIFI_MGR_PRIVATE_DATA;\r
+\r
+typedef struct _WIFI_MGR_PRIVATE_PROTOCOL {\r
+  UINT32  Reserved;\r
+} WIFI_MGR_PRIVATE_PROTOCOL;\r
+\r
+typedef struct _WIFI_MGR_FILE_CONTEXT {\r
+  EFI_FILE_HANDLE                   FHandle;\r
+  UINT16                            *FileName;\r
+} WIFI_MGR_FILE_CONTEXT;\r
+\r
+typedef enum {\r
+  FileTypeCACert,\r
+  FileTypeClientCert,\r
+  FileTypeMax\r
+} WIFI_MGR_FILE_TYPE;\r
+\r
+typedef struct {\r
+  UINT32                                     Signature;\r
+  EFI_HANDLE                                 DriverHandle;\r
+  EFI_HANDLE                                 ControllerHandle;\r
+  EFI_EVENT                                  TickTimer;\r
+  WIFI_MGR_PRIVATE_DATA                      *Private;\r
+\r
+  //\r
+  // Pointers to consumed protocols\r
+  //\r
+  EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL    *Wmp;\r
+  EFI_SUPPLICANT_PROTOCOL                    *Supplicant;\r
+  EFI_EAP_CONFIGURATION_PROTOCOL             *EapConfig;\r
+\r
+  //\r
+  // Produced protocols\r
+  //\r
+  WIFI_MGR_PRIVATE_PROTOCOL                   WifiMgrIdentifier;\r
+\r
+  //\r
+  // Private functions and data fields\r
+  //\r
+  LIST_ENTRY                                  Link;  // Link to the NicList in global private data structure.\r
+  UINT32                                      NicIndex;\r
+  EFI_80211_MAC_ADDRESS                       MacAddress;\r
+  WIFI_MGR_SUPPORTED_SUITES                   SupportedSuites;\r
+  EFI_ADAPTER_INFO_MEDIA_STATE                LastLinkState;\r
+\r
+  //\r
+  // The network is currently connected, connecting or disconnecting.\r
+  // Only one network can be operated at one time.\r
+  //\r
+  WIFI_MGR_NETWORK_PROFILE                    *CurrentOperateNetwork;\r
+  WIFI_MGR_NETWORK_PROFILE                    *ConnectPendingNetwork;\r
+  BOOLEAN                                     HasDisconnectPendingNetwork;\r
+\r
+  //\r
+  //Profile related data fields\r
+  //\r
+  LIST_ENTRY                                  ProfileList; // List of WIFI_MGR_NETWORK_PROFILE\r
+  UINT32                                      AvailableCount;\r
+  UINT32                                      MaxProfileIndex;\r
+  WIFI_MGR_NETWORK_PROFILE                    *UserSelectedProfile;\r
+\r
+  //\r
+  // Data fields for Hii functionlity\r
+  //\r
+  BOOLEAN                                     OneTimeScanRequest;\r
+  BOOLEAN                                     OneTimeConnectRequest;\r
+  BOOLEAN                                     OneTimeDisconnectRequest;\r
+  WIFI_MGR_SCAN_STATE                         ScanState;\r
+  UINTN                                       ScanTickTime;\r
+  WIFI_MGR_CONNECT_STATE                      ConnectState;\r
+  BOOLEAN                                     ConnectStateChanged;\r
+} WIFI_MGR_DEVICE_DATA;\r
+\r
+#define WIFI_MGR_DEVICE_DATA_SIGNATURE  SIGNATURE_32 ('W','M','D','D')\r
+\r
+#define WIFI_MGR_DEVICE_DATA_FROM_IDENTIFIER(Identifier) \\r
+  CR ( \\r
+    Identifier, \\r
+    WIFI_MGR_DEVICE_DATA, \\r
+    WifiMgrIdentifier, \\r
+    WIFI_MGR_DEVICE_DATA_SIGNATURE \\r
+    )\r
+\r
+typedef struct {\r
+  UINT32                                     Signature;\r
+  LIST_ENTRY                                 Link;\r
+  CHAR16                                     SSId[SSID_STORAGE_SIZE];\r
+} WIFI_HIDDEN_NETWORK_DATA;\r
+\r
+#define WIFI_MGR_HIDDEN_NETWORK_SIGNATURE  SIGNATURE_32 ('W','M','H','N')\r
+\r
+#define WIFI_MGR_HIDDEN_NETWORK_FROM_IDENTIFIER(Identifier) \\r
+  CR ( \\r
+    Identifier, \\r
+    WIFI_HIDDEN_NETWORK_DATA, \\r
+    WifiMgrIdentifier, \\r
+    WIFI_MGR_HIDDEN_NETWORK_SIGNATURE \\r
+    )\r
+\r
+//\r
+// Global private data struct\r
+//\r
+struct _WIFI_MGR_PRIVATE_DATA {\r
+\r
+  UINT32                            Signature;\r
+  EFI_HANDLE                        DriverHandle;\r
+  EFI_HII_HANDLE                    RegisteredHandle;\r
+  EFI_HII_CONFIG_ACCESS_PROTOCOL    ConfigAccess;\r
+\r
+  UINT32                            NicCount;\r
+  LIST_ENTRY                        NicList;\r
+  WIFI_MGR_DEVICE_DATA              *CurrentNic;\r
+\r
+  //\r
+  // Data fields for Hii functionlity\r
+  //\r
+  EFI_EVENT                         NetworkListRefreshEvent;        // Event to refresh the network list form\r
+  EFI_EVENT                         ConnectFormRefreshEvent;        // Event to refresh the connect form\r
+  EFI_EVENT                         MainPageRefreshEvent;           // Event to refresh the main page\r
+\r
+  //\r
+  //User Input Record\r
+  //\r
+  UINT8                             SecurityType;\r
+  UINT8                             EapAuthMethod;\r
+  UINT8                             EapSecondAuthMethod;\r
+  CHAR16                            EapIdentity[EAP_IDENTITY_SIZE];\r
+\r
+  WIFI_MGR_FILE_CONTEXT             *FileContext;\r
+  WIFI_MGR_FILE_TYPE                FileType;\r
+\r
+  UINT32                            HiddenNetworkCount;\r
+  LIST_ENTRY                        HiddenNetworkList;\r
+};\r
+\r
+#define WIFI_MGR_PRIVATE_DATA_SIGNATURE  SIGNATURE_32 ('W','M','P','D')\r
+\r
+#define WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS(This) \\r
+  CR ( \\r
+    This, \\r
+    WIFI_MGR_PRIVATE_DATA, \\r
+    ConfigAccess, \\r
+    WIFI_MGR_PRIVATE_DATA_SIGNATURE \\r
+    )\r
+extern    WIFI_MGR_PRIVATE_DATA    *mPrivate;\r
+\r
+typedef enum {\r
+  TokenTypeGetNetworksToken,\r
+  TokenTypeConnectNetworkToken,\r
+  TokenTypeDisconnectNetworkToken,\r
+  TokenTypeMax,\r
+} WIFI_MGR_MAC_CONFIG_TOKEN_TYPE;\r
+\r
+typedef union {\r
+  EFI_80211_GET_NETWORKS_TOKEN         *GetNetworksToken;\r
+  EFI_80211_CONNECT_NETWORK_TOKEN      *ConnectNetworkToken;\r
+  EFI_80211_DISCONNECT_NETWORK_TOKEN   *DisconnectNetworkToken;\r
+} MAC_CONNECTION2_ADAPTER_TOKEN;\r
+\r
+typedef struct {\r
+  WIFI_MGR_DEVICE_DATA            *Nic;\r
+  WIFI_MGR_MAC_CONFIG_TOKEN_TYPE  Type;\r
+  MAC_CONNECTION2_ADAPTER_TOKEN   Token;\r
+} WIFI_MGR_MAC_CONFIG_TOKEN;\r
+\r
+//\r
+// Include files with function prototypes\r
+//\r
+#include "WifiConnectionMgrDriverBinding.h"\r
+#include "WifiConnectionMgrImpl.h"\r
+#include "WifiConnectionMgrComponentName.h"\r
+#include "WifiConnectionMgrHiiConfigAccess.h"\r
+#include "WifiConnectionMgrMisc.h"\r
+#include "WifiConnectionMgrFileUtil.h"\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrFileUtil.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrFileUtil.c
new file mode 100644 (file)
index 0000000..6db1626
--- /dev/null
@@ -0,0 +1,308 @@
+/** @file\r
+  The file operation functions for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "WifiConnectionMgrFileUtil.h"\r
+\r
+CHAR16*  mDerPemEncodedSuffix[] = {\r
+  L".cer",\r
+  L".der",\r
+  L".crt",\r
+  L".pem",\r
+  NULL\r
+};\r
+\r
+/**\r
+  This code checks if the FileSuffix is one of the possible DER/PEM-encoded certificate suffix.\r
+\r
+  @param[in] FileSuffix     The suffix of the input certificate file\r
+\r
+  @retval    TRUE           It's a DER/PEM-encoded certificate.\r
+  @retval    FALSE          It's NOT a DER/PEM-encoded certificate.\r
+\r
+**/\r
+BOOLEAN\r
+IsDerPemEncodeCertificate (\r
+  IN CONST CHAR16         *FileSuffix\r
+)\r
+{\r
+  UINTN     Index;\r
+  for (Index = 0; mDerPemEncodedSuffix[Index] != NULL; Index++) {\r
+    if (StrCmp (FileSuffix, mDerPemEncodedSuffix[Index]) == 0) {\r
+      return TRUE;\r
+    }\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Read file content into BufferPtr, the size of the allocate buffer\r
+  is *FileSize plus AddtionAllocateSize.\r
+\r
+  @param[in]       FileHandle            The file to be read.\r
+  @param[in, out]  BufferPtr             Pointers to the pointer of allocated buffer.\r
+  @param[out]      FileSize              Size of input file\r
+  @param[in]       AddtionAllocateSize   Addtion size the buffer need to be allocated.\r
+                                         In case the buffer need to contain others besides the file content.\r
+\r
+  @retval   EFI_SUCCESS                  The file was read into the buffer.\r
+  @retval   EFI_INVALID_PARAMETER        A parameter was invalid.\r
+  @retval   EFI_OUT_OF_RESOURCES         A memory allocation failed.\r
+  @retval   others                       Unexpected error.\r
+\r
+**/\r
+EFI_STATUS\r
+ReadFileContent (\r
+  IN      EFI_FILE_HANDLE           FileHandle,\r
+  IN OUT  VOID                      **BufferPtr,\r
+     OUT  UINTN                     *FileSize,\r
+  IN      UINTN                     AddtionAllocateSize\r
+  )\r
+{\r
+  UINTN      BufferSize;\r
+  UINT64     SourceFileSize;\r
+  VOID       *Buffer;\r
+  EFI_STATUS Status;\r
+\r
+  if ((FileHandle == NULL) || (FileSize == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Buffer = NULL;\r
+\r
+  //\r
+  // Get the file size\r
+  //\r
+  Status = FileHandle->SetPosition (FileHandle, (UINT64) -1);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  Status = FileHandle->GetPosition (FileHandle, &SourceFileSize);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  Status = FileHandle->SetPosition (FileHandle, 0);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  BufferSize = (UINTN) SourceFileSize + AddtionAllocateSize;\r
+  Buffer =  AllocateZeroPool(BufferSize);\r
+  if (Buffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  BufferSize = (UINTN) SourceFileSize;\r
+  *FileSize  = BufferSize;\r
+\r
+  Status = FileHandle->Read (FileHandle, &BufferSize, Buffer);\r
+  if (EFI_ERROR (Status) || BufferSize != *FileSize) {\r
+    FreePool (Buffer);\r
+    Buffer = NULL;\r
+    Status  = EFI_BAD_BUFFER_SIZE;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+ON_EXIT:\r
+\r
+  *BufferPtr = Buffer;\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function converts an input device structure to a Unicode string.\r
+\r
+  @param[in] DevPath                  A pointer to the device path structure.\r
+\r
+  @return A new allocated Unicode string that represents the device path.\r
+\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+DevicePathToStr (\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *DevPath\r
+  )\r
+{\r
+  return ConvertDevicePathToText (\r
+           DevPath,\r
+           FALSE,\r
+           TRUE\r
+           );\r
+}\r
+\r
+/**\r
+  Extract filename from device path. The returned buffer is allocated using AllocateCopyPool.\r
+  The caller is responsible for freeing the allocated buffer using FreePool(). If return NULL\r
+  means not enough memory resource.\r
+\r
+  @param DevicePath       Device path.\r
+\r
+  @retval NULL            Not enough memory resourece for AllocateCopyPool.\r
+  @retval Other           A new allocated string that represents the file name.\r
+\r
+**/\r
+CHAR16 *\r
+ExtractFileNameFromDevicePath (\r
+  IN   EFI_DEVICE_PATH_PROTOCOL    *DevicePath\r
+  )\r
+{\r
+  CHAR16          *String;\r
+  CHAR16          *MatchString;\r
+  CHAR16          *LastMatch;\r
+  CHAR16          *FileName;\r
+  UINTN           Length;\r
+\r
+  ASSERT(DevicePath != NULL);\r
+\r
+  String = DevicePathToStr(DevicePath);\r
+  if (String == NULL) {\r
+    return NULL;\r
+  }\r
+  MatchString = String;\r
+  LastMatch   = String;\r
+  FileName    = NULL;\r
+\r
+  while(MatchString != NULL){\r
+    LastMatch   = MatchString + 1;\r
+    MatchString = StrStr(LastMatch,L"\\");\r
+  }\r
+\r
+  Length = StrLen(LastMatch);\r
+  FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch);\r
+  if (FileName != NULL) {\r
+    *(FileName + Length) = 0;\r
+  }\r
+\r
+  FreePool(String);\r
+\r
+  return FileName;\r
+}\r
+\r
+/**\r
+  Update the form base on the selected file.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[in]  FilePath            Point to the file path.\r
+  @param[in]  FormId              The form needs to display.\r
+\r
+  @retval TRUE   Exit caller function.\r
+  @retval FALSE  Not exit caller function.\r
+\r
+**/\r
+BOOLEAN\r
+UpdatePage(\r
+  IN  WIFI_MGR_PRIVATE_DATA       *Private,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL    *FilePath,\r
+  IN  EFI_FORM_ID                 FormId\r
+  )\r
+{\r
+  CHAR16           *FileName;\r
+  EFI_STATUS       Status;\r
+\r
+  FileName = NULL;\r
+\r
+  if (FilePath != NULL) {\r
+    FileName = ExtractFileNameFromDevicePath(FilePath);\r
+  }\r
+  if (FileName == NULL) {\r
+    //\r
+    // FileName = NULL has two cases:\r
+    // 1. FilePath == NULL, not select file.\r
+    // 2. FilePath != NULL, but ExtractFileNameFromDevicePath return NULL not enough memory resource.\r
+    // In these two case, no need to update the form, and exit the caller function.\r
+    //\r
+    return TRUE;\r
+  }\r
+\r
+  //\r
+  // Close the previous file handle before open a new one.\r
+  //\r
+  if (Private->FileContext->FHandle != NULL) {\r
+    Private->FileContext->FHandle->Close (Private->FileContext->FHandle);\r
+  }\r
+  Private->FileContext->FHandle = NULL;\r
+\r
+  Status = EfiOpenFileByDevicePath (\r
+             &FilePath,\r
+             &Private->FileContext->FHandle,\r
+             EFI_FILE_MODE_READ,\r
+             0\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    if (FormId == FORMID_ENROLL_CERT) {\r
+      HiiSetString (Private->RegisteredHandle,\r
+        STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), L"", NULL);\r
+    } else if (FormId == FORMID_ENROLL_PRIVATE_KEY){\r
+      HiiSetString (Private->RegisteredHandle,\r
+        STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME), L"", NULL);\r
+    }\r
+  } else {\r
+\r
+    if (Private->FileContext->FileName != NULL) {\r
+      FreePool (Private->FileContext->FileName);\r
+    }\r
+    Private->FileContext->FileName = FileName;\r
+\r
+    if (FormId == FORMID_ENROLL_CERT) {\r
+      HiiSetString (Private->RegisteredHandle,\r
+        STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), FileName, NULL);\r
+    } else if (FormId == FORMID_ENROLL_PRIVATE_KEY){\r
+      HiiSetString (Private->RegisteredHandle,\r
+        STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME), FileName, NULL);\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+/**\r
+  Update the CA form base on the input file path info.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[in]  FilePath            Point to the file path.\r
+\r
+  @retval TRUE   Exit caller function.\r
+  @retval FALSE  Not exit caller function.\r
+\r
+**/\r
+BOOLEAN\r
+UpdateCAFromFile (\r
+  IN  WIFI_MGR_PRIVATE_DATA       *Private,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL    *FilePath\r
+  )\r
+{\r
+  return UpdatePage(Private, FilePath, FORMID_ENROLL_CERT);\r
+}\r
+\r
+/**\r
+  Update the Private Key form base on the input file path info.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[in]  FilePath            Point to the file path.\r
+\r
+  @retval TRUE   Exit caller function.\r
+  @retval FALSE  Not exit caller function.\r
+\r
+**/\r
+BOOLEAN\r
+UpdatePrivateKeyFromFile (\r
+  IN  WIFI_MGR_PRIVATE_DATA       *Private,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL    *FilePath\r
+  )\r
+{\r
+  return UpdatePage(Private, FilePath, FORMID_ENROLL_PRIVATE_KEY);\r
+}\r
+\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrFileUtil.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrFileUtil.h
new file mode 100644 (file)
index 0000000..5426a5f
--- /dev/null
@@ -0,0 +1,77 @@
+/** @file\r
+  The file operation functions for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_MGR_FILE_UTIL__\r
+#define __EFI_WIFI_MGR_FILE_UTIL__\r
+\r
+#include "WifiConnectionMgrDxe.h"\r
+\r
+/**\r
+  Read file content into BufferPtr, the size of the allocate buffer\r
+  is *FileSize plus AddtionAllocateSize.\r
+\r
+  @param[in]       FileHandle            The file to be read.\r
+  @param[in, out]  BufferPtr             Pointers to the pointer of allocated buffer.\r
+  @param[out]      FileSize              Size of input file\r
+  @param[in]       AddtionAllocateSize   Addtion size the buffer need to be allocated.\r
+                                         In case the buffer need to contain others besides the file content.\r
+\r
+  @retval   EFI_SUCCESS                  The file was read into the buffer.\r
+  @retval   EFI_INVALID_PARAMETER        A parameter was invalid.\r
+  @retval   EFI_OUT_OF_RESOURCES         A memory allocation failed.\r
+  @retval   others                       Unexpected error.\r
+\r
+**/\r
+EFI_STATUS\r
+ReadFileContent (\r
+  IN      EFI_FILE_HANDLE           FileHandle,\r
+  IN OUT  VOID                      **BufferPtr,\r
+     OUT  UINTN                     *FileSize,\r
+  IN      UINTN                     AddtionAllocateSize\r
+  );\r
+\r
+/**\r
+  Update the CA cert base on the input file path info.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[in]  FilePath            Point to the file path.\r
+\r
+  @retval TRUE   Exit caller function.\r
+  @retval FALSE  Not exit caller function.\r
+\r
+**/\r
+BOOLEAN\r
+UpdateCAFromFile (\r
+  IN  WIFI_MGR_PRIVATE_DATA           *Private,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *FilePath\r
+  );\r
+\r
+/**\r
+  Update the Private Key base on the input file path info.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[in]  FilePath            Point to the file path.\r
+\r
+  @retval TRUE   Exit caller function.\r
+  @retval FALSE  Not exit caller function.\r
+\r
+**/\r
+BOOLEAN\r
+UpdatePrivateKeyFromFile (\r
+  IN  WIFI_MGR_PRIVATE_DATA           *Private,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *FilePath\r
+  );\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrHiiConfigAccess.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrHiiConfigAccess.c
new file mode 100644 (file)
index 0000000..bfb6b6e
--- /dev/null
@@ -0,0 +1,2014 @@
+/** @file\r
+  The Hii functions for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "WifiConnectionMgrDxe.h"\r
+\r
+CHAR16  mVendorStorageName[] = L"WIFI_MANAGER_IFR_NVDATA";\r
+\r
+HII_VENDOR_DEVICE_PATH  mWifiMgrDxeHiiVendorDevicePath = {\r
+  {\r
+    {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      {\r
+        (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+        (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
+      }\r
+    },\r
+    WIFI_CONNECTION_MANAGER_CONFIG_GUID\r
+  },\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    {\r
+      (UINT8) (END_DEVICE_PATH_LENGTH),\r
+      (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
+    }\r
+  }\r
+};\r
+\r
+//\r
+// HII Config Access Protocol instance\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+EFI_HII_CONFIG_ACCESS_PROTOCOL gWifiMgrDxeHiiConfigAccess = {\r
+  WifiMgrDxeHiiConfigAccessExtractConfig,\r
+  WifiMgrDxeHiiConfigAccessRouteConfig,\r
+  WifiMgrDxeHiiConfigAccessCallback\r
+};\r
+\r
+CHAR16*   mSecurityType[] = {\r
+  L"OPEN           ",\r
+  L"WPA-Enterprise ",\r
+  L"WPA2-Enterprise",\r
+  L"WPA-Personal   ",\r
+  L"WPA2-Personal  ",\r
+  L"WEP            ",\r
+  L"UnKnown        "\r
+};\r
+\r
+CHAR16*  mSignalStrengthBar[] = {\r
+  L"[-----]",\r
+  L"[*----]",\r
+  L"[**---]",\r
+  L"[***--]",\r
+  L"[****-]",\r
+  L"[*****]"\r
+};\r
+\r
+#define  RSSI_TO_SIGNAL_STRENGTH_BAR(Rssi)  mSignalStrengthBar[((Rssi + 19)/20)]\r
+\r
+#define  NET_LIST_FOR_EACH_FROM_NODE(Entry, Node, ListHead) \\r
+  for(Entry = Node->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)\r
+\r
+extern EFI_GUID    gWifiConfigFormSetGuid;\r
+\r
+/**\r
+  Create Hii Extend Label OpCode as the start opcode and end opcode.\r
+  The caller is responsible for freeing the OpCode with HiiFreeOpCodeHandle().\r
+\r
+  @param[in]  StartLabelNumber   The number of start label.\r
+  @param[out] StartOpCodeHandle  Points to the start opcode handle.\r
+  @param[out] EndOpCodeHandle    Points to the end opcode handle.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES   Do not have sufficient resource to finish this\r
+                                 operation.\r
+  @retval EFI_INVALID_PARAMETER  Any input parameter is invalid.\r
+  @retval EFI_SUCCESS            The operation is completed successfully.\r
+  @retval Other Errors           Returned errors when updating the HII form.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrCreateOpCode (\r
+  IN  UINT16    StartLabelNumber,\r
+  OUT VOID      **StartOpCodeHandle,\r
+  OUT VOID      **EndOpCodeHandle\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_IFR_GUID_LABEL    *InternalStartLabel;\r
+  EFI_IFR_GUID_LABEL    *InternalEndLabel;\r
+\r
+  if (StartOpCodeHandle == NULL || EndOpCodeHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status             = EFI_OUT_OF_RESOURCES;\r
+  *StartOpCodeHandle = NULL;\r
+  *EndOpCodeHandle   = NULL;\r
+\r
+  //\r
+  // Initialize the container for dynamic opcodes.\r
+  //\r
+  *StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+  if (*StartOpCodeHandle == NULL) {\r
+    goto Exit;\r
+  }\r
+  *EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+  if (*EndOpCodeHandle == NULL) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Create Hii Extend Label OpCode as the start opcode.\r
+  //\r
+  InternalStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
+                                                *StartOpCodeHandle,\r
+                                                &gEfiIfrTianoGuid,\r
+                                                NULL,\r
+                                                sizeof (EFI_IFR_GUID_LABEL)\r
+                                                );\r
+  if (InternalStartLabel == NULL) {\r
+    goto Exit;\r
+  }\r
+  InternalStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+  InternalStartLabel->Number       = StartLabelNumber;\r
+\r
+  //\r
+  // Create Hii Extend Label OpCode as the end opcode.\r
+  //\r
+  InternalEndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
+                                              *EndOpCodeHandle,\r
+                                              &gEfiIfrTianoGuid,\r
+                                              NULL,\r
+                                              sizeof (EFI_IFR_GUID_LABEL)\r
+                                              );\r
+  if (InternalEndLabel == NULL) {\r
+    goto Exit;\r
+  }\r
+  InternalEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+  InternalEndLabel->Number       = LABEL_END;\r
+\r
+  return EFI_SUCCESS;\r
+\r
+Exit:\r
+\r
+  if (*StartOpCodeHandle != NULL) {\r
+    HiiFreeOpCodeHandle (*StartOpCodeHandle);\r
+  }\r
+  if (*EndOpCodeHandle != NULL) {\r
+    HiiFreeOpCodeHandle (*EndOpCodeHandle);\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Display the Nic list contains all available Nics.\r
+\r
+  @param[in]  Private            The pointer to the global private data structure.\r
+\r
+  @retval EFI_INVALID_PARAMETER  Any input parameter is invalid.\r
+  @retval EFI_SUCCESS            The operation is completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrShowNicList (\r
+  IN  WIFI_MGR_PRIVATE_DATA    *Private\r
+)\r
+{\r
+  EFI_STATUS              Status;\r
+  CHAR16                  MacString[WIFI_MGR_MAX_MAC_STRING_LEN];\r
+  CHAR16                  PortString[WIFI_STR_MAX_SIZE];\r
+  EFI_STRING_ID           PortTitleToken;\r
+  EFI_STRING_ID           PortTitleHelpToken;\r
+  WIFI_MGR_DEVICE_DATA    *Nic;\r
+  LIST_ENTRY              *Entry;\r
+  VOID                    *StartOpCodeHandle;\r
+  VOID                    *EndOpCodeHandle;\r
+\r
+  if (Private == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = WifiMgrCreateOpCode (\r
+             LABEL_MAC_ENTRY,\r
+             &StartOpCodeHandle,\r
+             &EndOpCodeHandle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  NET_LIST_FOR_EACH (Entry, &Private->NicList) {\r
+    Nic = NET_LIST_USER_STRUCT_S (Entry, WIFI_MGR_DEVICE_DATA, Link, WIFI_MGR_DEVICE_DATA_SIGNATURE);\r
+    WifiMgrMacAddrToStr (&Nic->MacAddress, sizeof (MacString), MacString);\r
+    UnicodeSPrint (PortString, sizeof (PortString), L"MAC %s", MacString);\r
+    PortTitleToken = HiiSetString (\r
+                       Private->RegisteredHandle,\r
+                       0,\r
+                       PortString,\r
+                       NULL\r
+                       );\r
+    if (PortTitleToken == 0) {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto Exit;\r
+    }\r
+\r
+    UnicodeSPrint (PortString, sizeof (PortString), L"MAC Address");\r
+    PortTitleHelpToken = HiiSetString (\r
+                           Private->RegisteredHandle,\r
+                           0,\r
+                           PortString,\r
+                           NULL\r
+                           );\r
+    if (PortTitleHelpToken == 0) {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto Exit;\r
+    }\r
+\r
+    HiiCreateGotoOpCode (\r
+      StartOpCodeHandle,\r
+      FORMID_WIFI_MAINPAGE,\r
+      PortTitleToken,\r
+      PortTitleHelpToken,\r
+      EFI_IFR_FLAG_CALLBACK,\r
+      (UINT16) (KEY_MAC_ENTRY_BASE + Nic->NicIndex)\r
+      );\r
+  }\r
+\r
+  Status = HiiUpdateForm (\r
+             Private->RegisteredHandle,       // HII handle\r
+             &gWifiConfigFormSetGuid,         // Formset GUID\r
+             FORMID_MAC_SELECTION,            // Form ID\r
+             StartOpCodeHandle,               // Label for where to insert opcodes\r
+             EndOpCodeHandle                  // Replace data\r
+             );\r
+\r
+Exit:\r
+\r
+  HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Retreive the unicode string of the AKM Suite list of a profile.\r
+  The caller is responsible for freeing the string with FreePool().\r
+\r
+  @param[in]  Profile           The network profile contains a AKM suite list.\r
+\r
+  @return the unicode string of AKM suite list or "None".\r
+\r
+**/\r
+CHAR16*\r
+WifiMgrGetStrAKMList (\r
+  IN  WIFI_MGR_NETWORK_PROFILE         *Profile\r
+)\r
+{\r
+  UINT8     Index;\r
+  UINT16    AKMSuiteCount;\r
+  CHAR16    *AKMListDisplay;\r
+\r
+  AKMListDisplay = NULL;\r
+  if (Profile == NULL || Profile->Network.AKMSuite == NULL) {\r
+    goto Exit;\r
+  }\r
+\r
+  AKMSuiteCount = Profile->Network.AKMSuite->AKMSuiteCount;\r
+  if (AKMSuiteCount != 0) {\r
+\r
+    //\r
+    // Current AKM Suite is between 1-9\r
+    //\r
+    AKMListDisplay = (CHAR16 *) AllocateZeroPool(sizeof (CHAR16) * AKMSuiteCount * 2);\r
+    if (AKMListDisplay != NULL) {\r
+      for (Index = 0; Index < AKMSuiteCount; Index ++) {\r
+        UnicodeSPrint (\r
+          AKMListDisplay + (Index * 2),\r
+          sizeof (CHAR16) * 2,\r
+          L"%d ",\r
+          Profile->Network.AKMSuite->AKMSuiteList[Index].SuiteType\r
+          );\r
+        if (Index == AKMSuiteCount - 1) {\r
+          *(AKMListDisplay + (Index * 2 + 1)) = L'\0';\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+Exit:\r
+\r
+  if (AKMListDisplay == NULL) {\r
+    AKMListDisplay = AllocateCopyPool (sizeof (L"None"), L"None");\r
+  }\r
+  return AKMListDisplay;\r
+}\r
+\r
+/**\r
+  Retreive the unicode string of the Cipher Suite list of a profile.\r
+  The caller is responsible for freeing the string with FreePool().\r
+\r
+  @param[in]  Profile           The network profile contains a Cipher suite list.\r
+\r
+  @return the unicode string of Cipher suite list or "None".\r
+\r
+**/\r
+CHAR16*\r
+WifiMgrGetStrCipherList (\r
+  IN  WIFI_MGR_NETWORK_PROFILE          *Profile\r
+)\r
+{\r
+  UINT8     Index;\r
+  UINT16    CipherSuiteCount;\r
+  CHAR16    *CipherListDisplay;\r
+\r
+  CipherListDisplay = NULL;\r
+  if (Profile == NULL || Profile->Network.CipherSuite == NULL) {\r
+    goto Exit;\r
+  }\r
+\r
+  CipherSuiteCount   = Profile->Network.CipherSuite->CipherSuiteCount;\r
+  if (CipherSuiteCount != 0) {\r
+\r
+    //\r
+    // Current Cipher Suite is between 1-9\r
+    //\r
+    CipherListDisplay = (CHAR16 *) AllocateZeroPool(sizeof (CHAR16) * CipherSuiteCount * 2);\r
+    if (CipherListDisplay != NULL) {\r
+      for (Index = 0; Index < CipherSuiteCount; Index ++) {\r
+        UnicodeSPrint (\r
+          CipherListDisplay + (Index * 2),\r
+          sizeof (CHAR16) * 2,\r
+          L"%d ",\r
+          Profile->Network.CipherSuite->CipherSuiteList[Index].SuiteType\r
+          );\r
+        if (Index == CipherSuiteCount - 1) {\r
+          *(CipherListDisplay + (Index * 2 + 1)) = L'\0';\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+Exit:\r
+\r
+  if (CipherListDisplay == NULL) {\r
+    CipherListDisplay = AllocateCopyPool (sizeof (L"None"), L"None");\r
+  }\r
+  return CipherListDisplay;\r
+}\r
+\r
+/**\r
+  Refresh the network list display of the current Nic.\r
+\r
+  @param[in]   Private           The pointer to the global private data structure.\r
+  @param[out]  IfrNvData         The IFR NV data.\r
+\r
+  @retval EFI_SUCCESS            The operation is completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+  @retval Other Errors           Returned errors when creating Opcodes or updating the\r
+                                 Hii form.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrRefreshNetworkList (\r
+  IN    WIFI_MGR_PRIVATE_DATA      *Private,\r
+  OUT   WIFI_MANAGER_IFR_NVDATA    *IfrNvData\r
+  )\r
+{\r
+  EFI_STATUS                         Status;\r
+  EFI_TPL                            OldTpl;\r
+  UINT32                             AvailableCount;\r
+  EFI_STRING_ID                      PortPromptToken;\r
+  EFI_STRING_ID                      PortTextToken;\r
+  EFI_STRING_ID                      PortHelpToken;\r
+  WIFI_MGR_NETWORK_PROFILE           *Profile;\r
+  LIST_ENTRY                         *Entry;\r
+  VOID                               *StartOpCodeHandle;\r
+  VOID                               *EndOpCodeHandle;\r
+  CHAR16                             *AKMListDisplay;\r
+  CHAR16                             *CipherListDisplay;\r
+  CHAR16                             PortString[WIFI_STR_MAX_SIZE];\r
+  UINTN                              PortStringSize;\r
+  WIFI_MGR_NETWORK_PROFILE           *ConnectedProfile;\r
+\r
+  if (Private->CurrentNic == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = WifiMgrCreateOpCode (\r
+             LABEL_NETWORK_LIST_ENTRY,\r
+             &StartOpCodeHandle,\r
+             &EndOpCodeHandle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  AvailableCount    = 0;\r
+  PortStringSize    = sizeof (PortString);\r
+  ConnectedProfile  = NULL;\r
+  AKMListDisplay    = NULL;\r
+  CipherListDisplay = NULL;\r
+\r
+  if (Private->CurrentNic->ConnectState == WifiMgrConnectedToAp) {\r
+\r
+    //\r
+    // Display the current connected network.\r
+    // Find the current operate network under connected status.\r
+    //\r
+    if (Private->CurrentNic->CurrentOperateNetwork != NULL &&\r
+      Private->CurrentNic->CurrentOperateNetwork->IsAvailable) {\r
+\r
+      Profile = Private->CurrentNic->CurrentOperateNetwork;\r
+      AvailableCount ++;\r
+\r
+      AKMListDisplay = WifiMgrGetStrAKMList (Profile);\r
+      if (AKMListDisplay == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+      CipherListDisplay = WifiMgrGetStrCipherList(Profile);\r
+      if (CipherListDisplay == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+\r
+      UnicodeSPrint (PortString, PortStringSize, L"%s (Connected)", Profile->SSId);\r
+      PortPromptToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);\r
+\r
+      if (Profile->SecurityType == SECURITY_TYPE_NONE) {\r
+        PortHelpToken = 0;\r
+      } else {\r
+        UnicodeSPrint (PortString, PortStringSize, L"AKMSuite: %s CipherSuite: %s", AKMListDisplay, CipherListDisplay);\r
+        PortHelpToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);\r
+      }\r
+      FreePool (AKMListDisplay);\r
+      FreePool (CipherListDisplay);\r
+\r
+      HiiCreateGotoOpCode (\r
+        StartOpCodeHandle,\r
+        FORMID_CONNECT_NETWORK,\r
+        PortPromptToken,\r
+        PortHelpToken,\r
+        EFI_IFR_FLAG_CALLBACK,\r
+        (UINT16) (KEY_AVAILABLE_NETWORK_ENTRY_BASE + Profile->ProfileIndex)\r
+        );\r
+\r
+      UnicodeSPrint (\r
+        PortString,\r
+        PortStringSize,\r
+        L"%s       %s %s",\r
+        (Profile->SecurityType != SECURITY_TYPE_NONE ? L"Secured" : L"Open   "),\r
+        mSecurityType[Profile->SecurityType],\r
+        RSSI_TO_SIGNAL_STRENGTH_BAR(Profile->NetworkQuality)\r
+        );\r
+      PortTextToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);\r
+\r
+      HiiCreateTextOpCode (\r
+        StartOpCodeHandle,\r
+        PortTextToken,\r
+        0,\r
+        0\r
+      );\r
+\r
+      ConnectedProfile = Profile;\r
+    } else {\r
+      Private->CurrentNic->HasDisconnectPendingNetwork = TRUE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Display all supported available networks.\r
+  //\r
+  NET_LIST_FOR_EACH (Entry, &Private->CurrentNic->ProfileList) {\r
+\r
+    Profile = NET_LIST_USER_STRUCT_S (\r
+                Entry,\r
+                WIFI_MGR_NETWORK_PROFILE,\r
+                Link,\r
+                WIFI_MGR_PROFILE_SIGNATURE\r
+                );\r
+    if (ConnectedProfile == Profile) {\r
+      continue;\r
+    }\r
+    if (Profile->IsAvailable && Profile->CipherSuiteSupported) {\r
+\r
+      AvailableCount ++;\r
+\r
+      AKMListDisplay = WifiMgrGetStrAKMList (Profile);\r
+      if (AKMListDisplay == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+      CipherListDisplay = WifiMgrGetStrCipherList(Profile);\r
+      if (CipherListDisplay == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+\r
+      PortPromptToken = HiiSetString (Private->RegisteredHandle, 0, Profile->SSId, NULL);\r
+      if (PortPromptToken == 0) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+\r
+      if (Profile->SecurityType == SECURITY_TYPE_NONE) {\r
+        PortHelpToken = 0;\r
+      } else {\r
+        UnicodeSPrint (\r
+          PortString,\r
+          PortStringSize,\r
+          L"AKMSuite: %s CipherSuite: %s",\r
+          AKMListDisplay, CipherListDisplay\r
+          );\r
+        PortHelpToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);\r
+        if (PortHelpToken == 0) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Exit;\r
+        }\r
+      }\r
+      FreePool (AKMListDisplay);\r
+      FreePool (CipherListDisplay);\r
+\r
+      HiiCreateGotoOpCode (\r
+        StartOpCodeHandle,\r
+        FORMID_CONNECT_NETWORK,\r
+        PortPromptToken,\r
+        PortHelpToken,\r
+        EFI_IFR_FLAG_CALLBACK,\r
+        (UINT16) (KEY_AVAILABLE_NETWORK_ENTRY_BASE + Profile->ProfileIndex)\r
+        );\r
+\r
+      UnicodeSPrint (\r
+        PortString,\r
+        PortStringSize,\r
+        L"%s       %s %s",\r
+        (Profile->SecurityType != SECURITY_TYPE_NONE ? L"Secured" : L"Open   "),\r
+        mSecurityType[Profile->SecurityType],\r
+        RSSI_TO_SIGNAL_STRENGTH_BAR(Profile->NetworkQuality)\r
+        );\r
+      PortTextToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);\r
+      if (PortTextToken == 0) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+      HiiCreateTextOpCode (\r
+        StartOpCodeHandle,\r
+        PortTextToken,\r
+        0,\r
+        0\r
+        );\r
+    }\r
+  }\r
+\r
+  //\r
+  // Display all Unsupported available networks.\r
+  //\r
+  NET_LIST_FOR_EACH (Entry, &Private->CurrentNic->ProfileList) {\r
+\r
+    Profile = NET_LIST_USER_STRUCT_S (\r
+                Entry,\r
+                WIFI_MGR_NETWORK_PROFILE,\r
+                Link,\r
+                WIFI_MGR_PROFILE_SIGNATURE\r
+                );\r
+    if (ConnectedProfile == Profile) {\r
+      continue;\r
+    }\r
+    if (Profile->IsAvailable && !Profile->CipherSuiteSupported) {\r
+\r
+      AvailableCount ++;\r
+\r
+      AKMListDisplay = WifiMgrGetStrAKMList (Profile);\r
+      if (AKMListDisplay == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+      CipherListDisplay = WifiMgrGetStrCipherList(Profile);\r
+      if (CipherListDisplay == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+\r
+      PortPromptToken = HiiSetString (Private->RegisteredHandle, 0, Profile->SSId, NULL);\r
+\r
+      if (Profile->AKMSuiteSupported) {\r
+        UnicodeSPrint (\r
+          PortString,\r
+          PortStringSize,\r
+          L"AKMSuite: %s CipherSuite(UnSupported): %s",\r
+          AKMListDisplay, CipherListDisplay\r
+          );\r
+      } else {\r
+        UnicodeSPrint (\r
+          PortString,\r
+          PortStringSize,\r
+          L"AKMSuite(UnSupported): %s CipherSuite(UnSupported): %s",\r
+          AKMListDisplay, CipherListDisplay\r
+          );\r
+      }\r
+      FreePool (AKMListDisplay);\r
+      FreePool (CipherListDisplay);\r
+\r
+      PortHelpToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);\r
+\r
+      HiiCreateGotoOpCode (\r
+        StartOpCodeHandle,\r
+        FORMID_CONNECT_NETWORK,\r
+        PortPromptToken,\r
+        PortHelpToken,\r
+        EFI_IFR_FLAG_CALLBACK,\r
+        (UINT16) (KEY_AVAILABLE_NETWORK_ENTRY_BASE + Profile->ProfileIndex)\r
+        );\r
+\r
+      UnicodeSPrint (\r
+        PortString,\r
+        PortStringSize,\r
+        L"%s       %s %s",\r
+        L"UnSupported",\r
+        mSecurityType[Profile->SecurityType],\r
+        RSSI_TO_SIGNAL_STRENGTH_BAR(Profile->NetworkQuality)\r
+        );\r
+      PortTextToken = HiiSetString (Private->RegisteredHandle, 0, PortString, NULL);\r
+\r
+      HiiCreateTextOpCode (\r
+        StartOpCodeHandle,\r
+        PortTextToken,\r
+        0,\r
+        0\r
+        );\r
+    }\r
+  }\r
+\r
+  Status = HiiUpdateForm (\r
+             Private->RegisteredHandle,       // HII handle\r
+             &gWifiConfigFormSetGuid,         // Formset GUID\r
+             FORMID_NETWORK_LIST,             // Form ID\r
+             StartOpCodeHandle,               // Label for where to insert opcodes\r
+             EndOpCodeHandle                  // Replace data\r
+             );\r
+\r
+Exit:\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  if (AKMListDisplay != NULL) {\r
+    FreePool (AKMListDisplay);\r
+  }\r
+  if (CipherListDisplay != NULL) {\r
+    FreePool (CipherListDisplay);\r
+  }\r
+\r
+  HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
+\r
+  DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Network List is Refreshed!\n"));\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Refresh the hidden network list configured by user.\r
+\r
+  @param[in]   Private           The pointer to the global private data structure.\r
+\r
+  @retval EFI_SUCCESS            The operation is completed successfully.\r
+  @retval Other Errors           Returned errors when creating Opcodes or updating the\r
+                                 Hii form.\r
+**/\r
+EFI_STATUS\r
+WifiMgrRefreshHiddenList (\r
+  IN    WIFI_MGR_PRIVATE_DATA      *Private\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_TPL                          OldTpl;\r
+  UINTN                            Index;\r
+  EFI_STRING_ID                    StringId;\r
+  VOID                             *StartOpCodeHandle;\r
+  VOID                             *EndOpCodeHandle;\r
+  WIFI_HIDDEN_NETWORK_DATA         *HiddenNetwork;\r
+  LIST_ENTRY                       *Entry;\r
+\r
+  if (Private == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = WifiMgrCreateOpCode (\r
+             LABEL_HIDDEN_NETWORK_ENTRY,\r
+             &StartOpCodeHandle,\r
+             &EndOpCodeHandle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  Index  = 0;\r
+\r
+  NET_LIST_FOR_EACH (Entry, &Private->HiddenNetworkList) {\r
+\r
+    HiddenNetwork = NET_LIST_USER_STRUCT_S (\r
+                      Entry,\r
+                      WIFI_HIDDEN_NETWORK_DATA,\r
+                      Link,\r
+                      WIFI_MGR_HIDDEN_NETWORK_SIGNATURE\r
+                      );\r
+    StringId = HiiSetString (Private->RegisteredHandle, 0, HiddenNetwork->SSId, NULL);\r
+\r
+    HiiCreateCheckBoxOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (KEY_HIDDEN_NETWORK_ENTRY_BASE + Index),\r
+      MANAGER_VARSTORE_ID,\r
+      (UINT16) (HIDDEN_NETWORK_LIST_VAR_OFFSET + Index),\r
+      StringId,\r
+      0,\r
+      0,\r
+      0,\r
+      NULL\r
+      );\r
+    Index ++;\r
+  }\r
+\r
+  Status = HiiUpdateForm (\r
+             Private->RegisteredHandle,       // HII handle\r
+             &gWifiConfigFormSetGuid,         // Formset GUID\r
+             FORMID_HIDDEN_NETWORK_LIST,      // Form ID\r
+             StartOpCodeHandle,               // Label for where to insert opcodes\r
+             EndOpCodeHandle                  // Replace data\r
+             );\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Callback function for user to select a Nic.\r
+\r
+  @param[in]  Private            The pointer to the global private data structure.\r
+  @param[in]  KeyValue           The key value received from HII input.\r
+\r
+  @retval EFI_NOT_FOUND          The corresponding Nic is not found.\r
+  @retval EFI_SUCCESS            The operation is completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrSelectNic (\r
+  IN     WIFI_MGR_PRIVATE_DATA         *Private,\r
+  IN     EFI_QUESTION_ID               KeyValue\r
+  )\r
+{\r
+  WIFI_MGR_DEVICE_DATA    *Nic;\r
+  UINT32                  NicIndex;\r
+  CHAR16                  MacString[WIFI_MGR_MAX_MAC_STRING_LEN];\r
+\r
+  NicIndex = KeyValue - KEY_MAC_ENTRY_BASE;\r
+  Nic      = WifiMgrGetNicByIndex (Private, NicIndex);\r
+  if (Nic == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  Private->CurrentNic = Nic;\r
+\r
+  WifiMgrMacAddrToStr (&Nic->MacAddress, sizeof (MacString), MacString);\r
+  HiiSetString (Private->RegisteredHandle, STRING_TOKEN(STR_MAC_ADDRESS), MacString, NULL);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Restore the NV data to be default.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[out] IfrNvData           The IFR NV data.\r
+\r
+**/\r
+VOID\r
+WifiMgrCleanUserInput (\r
+  IN  WIFI_MGR_PRIVATE_DATA      *Private\r
+  )\r
+{\r
+  Private->SecurityType        = SECURITY_TYPE_NONE;\r
+  Private->EapAuthMethod       = EAP_AUTH_METHOD_TTLS;\r
+  Private->EapSecondAuthMethod = EAP_SEAUTH_METHOD_MSCHAPV2;\r
+  Private->FileType            = FileTypeMax;\r
+}\r
+\r
+/**\r
+  UI handle function when user select a network to connect.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[in]  ProfileIndex        The profile index user selected to connect.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Nic is null.\r
+  @retval EFI_NOT_FOUND           Profile could not be found.\r
+  @retval EFI_SUCCESS             The operation is completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrUserSelectProfileToConnect(\r
+  IN     WIFI_MGR_PRIVATE_DATA         *Private,\r
+  IN     UINT32                        ProfileIndex\r
+  )\r
+{\r
+  WIFI_MGR_NETWORK_PROFILE         *Profile;\r
+  WIFI_MGR_DEVICE_DATA             *Nic;\r
+\r
+  Nic = Private->CurrentNic;\r
+  if (Nic == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  //Initialize the connection page\r
+  //\r
+  WifiMgrCleanUserInput(Private);\r
+\r
+  Profile = WifiMgrGetProfileByProfileIndex (ProfileIndex, &Nic->ProfileList);\r
+  if (Profile == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  Private->CurrentNic->UserSelectedProfile = Profile;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Record password from a HII input string.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+  @param[in]  StringId            The QuestionId received from HII input.\r
+  @param[in]  StringBuffer        The unicode string buffer to store password.\r
+  @param[in]  StringBufferLen     The len of unicode string buffer.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Any input parameter is invalid.\r
+  @retval EFI_NOT_FOUND           The password string is not found or invalid.\r
+  @retval EFI_SUCCESS             The operation is completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrRecordPassword (\r
+  IN   WIFI_MGR_PRIVATE_DATA      *Private,\r
+  IN   EFI_STRING_ID              StringId,\r
+  IN   CHAR16                     *StringBuffer,\r
+  IN   UINTN                      StringBufferLen\r
+  )\r
+{\r
+  CHAR16                          *Password;\r
+\r
+  if (StringId == 0 || StringBuffer == NULL || StringBufferLen <= 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Password = HiiGetString (Private->RegisteredHandle, StringId, NULL);\r
+  if (Password == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  if (StrLen (Password) > StringBufferLen) {\r
+    FreePool (Password);\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  StrnCpyS (StringBuffer, StringBufferLen, Password, StrLen (Password));\r
+  ZeroMem (Password, (StrLen (Password) + 1) * sizeof (CHAR16));\r
+  FreePool (Password);\r
+\r
+  //\r
+  // Clean password in string package\r
+  //\r
+  HiiSetString (Private->RegisteredHandle, StringId, L"", NULL);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Update connection message on connect configuration page, and trigger related form refresh.\r
+\r
+  @param[in]   Nic                        The related Nic for updating message.\r
+  @param[in]   ConnectStateChanged        The tag to tell if the connection state has been changed, only\r
+                                          when the connection changes from "Connected" or "Disconnecting"\r
+                                          to "Disconnected", or from "Disconnected" or "Connecting" to\r
+                                          "Connected", this tag can be set as TRUE.\r
+  @param[in]   ConnectStatusMessage       The message to show on connected status bar, if NULL, will\r
+                                          use default message.\r
+\r
+**/\r
+VOID\r
+WifiMgrUpdateConnectMessage (\r
+  IN  WIFI_MGR_DEVICE_DATA      *Nic,\r
+  IN  BOOLEAN                   ConnectStateChanged,\r
+  IN  EFI_STRING                ConnectStatusMessage\r
+  )\r
+{\r
+  CHAR16                   ConnectStatusStr[WIFI_STR_MAX_SIZE];\r
+  WIFI_MGR_PRIVATE_DATA    *Private;\r
+\r
+  Private = Nic->Private;\r
+  if (Private == NULL || Private->CurrentNic != Nic) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Update Connection Status Bar\r
+  //\r
+  if (ConnectStatusMessage != NULL) {\r
+    HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusMessage, NULL);\r
+  } else {\r
+    if (Nic->ConnectState == WifiMgrConnectedToAp) {\r
+\r
+      UnicodeSPrint (ConnectStatusStr, sizeof (ConnectStatusStr), L"Connected to %s",\r
+        Nic->CurrentOperateNetwork->SSId);\r
+      HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusStr, NULL);\r
+    } else if (Nic->ConnectState == WifiMgrDisconnected) {\r
+\r
+      HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), L"Disconnected", NULL);\r
+    } else if (Nic->ConnectState == WifiMgrConnectingToAp) {\r
+\r
+      UnicodeSPrint (ConnectStatusStr, sizeof (ConnectStatusStr), L"Connecting to %s ...",\r
+        Nic->CurrentOperateNetwork->SSId);\r
+      HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusStr, NULL);\r
+    } else if (Nic->ConnectState == WifiMgrDisconnectingToAp) {\r
+\r
+      UnicodeSPrint (ConnectStatusStr, sizeof (ConnectStatusStr), L"Disconnecting from %s ...",\r
+        Nic->CurrentOperateNetwork->SSId);\r
+      HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_STATUS), ConnectStatusStr, NULL);\r
+    } else {\r
+      return;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Update Connect Button\r
+  //\r
+  if (Nic->ConnectState == WifiMgrConnectedToAp && Nic->UserSelectedProfile == Nic->CurrentOperateNetwork) {\r
+\r
+    HiiSetString (Private->RegisteredHandle,\r
+      STRING_TOKEN (STR_CONNECT_NOW), L"Disconnect from this Network", NULL);\r
+  } else {\r
+    HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECT_NOW), L"Connect to this Network", NULL);\r
+  }\r
+  gBS->SignalEvent (Private->ConnectFormRefreshEvent);\r
+\r
+  //\r
+  // Update Main Page and Network List\r
+  //\r
+  if (ConnectStateChanged) {\r
+\r
+    if (Nic->ConnectState == WifiMgrConnectedToAp) {\r
+\r
+      HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECTION_INFO), L"Connected to", NULL);\r
+      HiiSetString (Private->RegisteredHandle,\r
+        STRING_TOKEN (STR_CONNECTED_SSID), Nic->CurrentOperateNetwork->SSId, NULL);\r
+    } else {\r
+      HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECTION_INFO), L"Disconnected", NULL);\r
+      HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_CONNECTED_SSID), L"", NULL);\r
+    }\r
+\r
+    gBS->SignalEvent (Private->NetworkListRefreshEvent);\r
+    gBS->SignalEvent (Private->MainPageRefreshEvent);\r
+  }\r
+}\r
+\r
+/**\r
+  Convert the driver configuration data into the IFR data.\r
+\r
+  @param[in]   Private            The pointer to the global private data structure.\r
+  @param[out]  IfrNvData          The IFR NV data.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrConvertConfigDataToIfrNvData (\r
+  IN   WIFI_MGR_PRIVATE_DATA      *Private,\r
+  OUT  WIFI_MANAGER_IFR_NVDATA    *IfrNvData\r
+  )\r
+{\r
+  //\r
+  // Private shouldn't be NULL here, assert if Private is NULL.\r
+  //\r
+  ASSERT (Private != NULL);\r
+\r
+  if (Private->CurrentNic != NULL) {\r
+    IfrNvData->ProfileCount = Private->CurrentNic->AvailableCount;\r
+  } else {\r
+    IfrNvData->ProfileCount = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Convert the IFR data into the driver configuration data.\r
+\r
+  @param[in]       Private             The pointer to the global private data structure.\r
+  @param[in, out]  IfrNvData           The IFR NV data.\r
+\r
+  @retval EFI_SUCCESS                  The operation is completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrConvertIfrNvDataToConfigData (\r
+  IN     WIFI_MGR_PRIVATE_DATA         *Private,\r
+  IN OUT WIFI_MANAGER_IFR_NVDATA       *IfrNvData\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function allows the caller to request the current\r
+  configuration for one or more named elements. The resulting\r
+  string is in <ConfigAltResp> format. Any and all alternative\r
+  configuration strings shall also be appended to the end of the\r
+  current configuration string. If they are, they must appear\r
+  after the current configuration. They must contain the same\r
+  routing (GUID, NAME, PATH) as the current configuration string.\r
+  They must have an additional description indicating the type of\r
+  alternative configuration the string represents,\r
+  "ALTCFG=<StringToken>". That <StringToken> (when\r
+  converted from Hex UNICODE to binary) is a reference to a\r
+  string in the associated string pack.\r
+\r
+  @param This       Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+\r
+  @param Request    A null-terminated Unicode string in\r
+                    <ConfigRequest> format. Note that this\r
+                    includes the routing information as well as\r
+                    the configurable name / value pairs. It is\r
+                    invalid for this string to be in\r
+                    <MultiConfigRequest> format.\r
+                    If a NULL is passed in for the Request field,\r
+                    all of the settings being abstracted by this function\r
+                    will be returned in the Results field.  In addition,\r
+                    if a ConfigHdr is passed in with no request elements,\r
+                    all of the settings being abstracted for that particular\r
+                    ConfigHdr reference will be returned in the Results Field.\r
+\r
+  @param Progress   On return, points to a character in the\r
+                    Request string. Points to the string's null\r
+                    terminator if request was successful. Points\r
+                    to the most recent "&" before the first\r
+                    failing name / value pair (or the beginning\r
+                    of the string if the failure is in the first\r
+                    name / value pair) if the request was not\r
+                    successful.\r
+\r
+  @param Results    A null-terminated Unicode string in\r
+                    <MultiConfigAltResp> format which has all values\r
+                    filled in for the names in the Request string.\r
+                    String to be allocated by the called function.\r
+\r
+  @retval EFI_SUCCESS             The Results string is filled with the\r
+                                  values corresponding to all requested\r
+                                  names.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough memory to store the\r
+                                  parts of the results that must be\r
+                                  stored awaiting possible future\r
+                                  protocols.\r
+\r
+  @retval EFI_NOT_FOUND           Routing data doesn't match any\r
+                                  known driver. Progress set to the\r
+                                  first character in the routing header.\r
+                                  Note: There is no requirement that the\r
+                                  driver validate the routing data. It\r
+                                  must skip the <ConfigHdr> in order to\r
+                                  process the names.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Illegal syntax. Progress set\r
+                                  to most recent "&" before the\r
+                                  error or the beginning of the\r
+                                  string.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Unknown name. Progress points\r
+                                  to the & before the name in\r
+                                  question.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeHiiConfigAccessExtractConfig (\r
+  IN CONST  EFI_HII_CONFIG_ACCESS_PROTOCOL  *This,\r
+  IN CONST  EFI_STRING                      Request,\r
+  OUT       EFI_STRING                      *Progress,\r
+  OUT       EFI_STRING                      *Results\r
+  )\r
+{\r
+  WIFI_MGR_PRIVATE_DATA             *Private;\r
+  WIFI_MANAGER_IFR_NVDATA           *IfrNvData;\r
+  EFI_STRING                        ConfigRequestHdr;\r
+  EFI_STRING                        ConfigRequest;\r
+  UINTN                             Size;\r
+  BOOLEAN                           AllocatedRequest;\r
+  UINTN                             BufferSize;\r
+  EFI_STATUS                        Status;\r
+\r
+  if (This == NULL || Progress == NULL || Results == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *Progress = Request;\r
+  if ((Request != NULL) &&\r
+      !HiiIsConfigHdrMatch (Request, &gWifiConfigFormSetGuid, mVendorStorageName)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  ConfigRequestHdr = NULL;\r
+  ConfigRequest    = NULL;\r
+  AllocatedRequest = FALSE;\r
+  Size             = 0;\r
+\r
+  Private   = WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This);\r
+\r
+  BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);\r
+  IfrNvData = AllocateZeroPool (BufferSize);\r
+  if (IfrNvData == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  WifiMgrConvertConfigDataToIfrNvData (Private, IfrNvData);\r
+\r
+  ConfigRequest = Request;\r
+  if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
+    //\r
+    // Request has no request element, construct full request string.\r
+    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
+    // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.\r
+    //\r
+    ConfigRequestHdr = HiiConstructConfigHdr (\r
+                         &gWifiConfigFormSetGuid,\r
+                         mVendorStorageName,\r
+                         Private->DriverHandle);\r
+    if (ConfigRequestHdr == NULL) {\r
+      FreePool (IfrNvData);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
+    ConfigRequest = AllocateZeroPool (Size);\r
+    if (ConfigRequest == NULL) {\r
+\r
+      FreePool (IfrNvData);\r
+      FreePool (ConfigRequestHdr);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    AllocatedRequest = TRUE;\r
+    UnicodeSPrint (\r
+      ConfigRequest,\r
+      Size,\r
+      L"%s&OFFSET=0&WIDTH=%016LX",\r
+      ConfigRequestHdr,\r
+      (UINT64) BufferSize\r
+      );\r
+    FreePool (ConfigRequestHdr);\r
+  }\r
+\r
+  //\r
+  // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
+  //\r
+  Status = gHiiConfigRouting->BlockToConfig (\r
+                                gHiiConfigRouting,\r
+                                ConfigRequest,\r
+                                (UINT8 *) IfrNvData,\r
+                                BufferSize,\r
+                                Results,\r
+                                Progress\r
+                                );\r
+\r
+  FreePool (IfrNvData);\r
+  //\r
+  // Free the allocated config request string.\r
+  //\r
+  if (AllocatedRequest) {\r
+    FreePool (ConfigRequest);\r
+    ConfigRequest = NULL;\r
+  }\r
+  //\r
+  // Set Progress string to the original request string.\r
+  //\r
+  if (Request == NULL) {\r
+    *Progress = NULL;\r
+  } else if (StrStr (Request, L"OFFSET") == NULL) {\r
+    *Progress = Request + StrLen (Request);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function applies changes in a driver's configuration.\r
+  Input is a Configuration, which has the routing data for this\r
+  driver followed by name / value configuration pairs. The driver\r
+  must apply those pairs to its configurable storage. If the\r
+  driver's configuration is stored in a linear block of data\r
+  and the driver's name / value pairs are in <BlockConfig>\r
+  format, it may use the ConfigToBlock helper function (above) to\r
+  simplify the job.\r
+\r
+  @param This           Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+\r
+  @param Configuration  A null-terminated Unicode string in\r
+                        <ConfigString> format.\r
+\r
+  @param Progress       A pointer to a string filled in with the\r
+                        offset of the most recent '&' before the\r
+                        first failing name / value pair (or the\r
+                        beginn ing of the string if the failure\r
+                        is in the first name / value pair) or\r
+                        the terminating NULL if all was\r
+                        successful.\r
+\r
+  @retval EFI_SUCCESS             The results have been distributed or are\r
+                                  awaiting distribution.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough memory to store the\r
+                                  parts of the results that must be\r
+                                  stored awaiting possible future\r
+                                  protocols.\r
+\r
+  @retval EFI_INVALID_PARAMETERS  Passing in a NULL for the\r
+                                  Results parameter would result\r
+                                  in this type of error.\r
+\r
+  @retval EFI_NOT_FOUND           Target for the specified routing data\r
+                                  was not found\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeHiiConfigAccessRouteConfig (\r
+  IN CONST  EFI_HII_CONFIG_ACCESS_PROTOCOL  *This,\r
+  IN CONST  EFI_STRING                      Configuration,\r
+  OUT       EFI_STRING                      *Progress\r
+  )\r
+{\r
+  EFI_STATUS                     Status;\r
+  UINTN                          BufferSize;\r
+  WIFI_MGR_PRIVATE_DATA          *Private;\r
+  WIFI_MANAGER_IFR_NVDATA        *IfrNvData;\r
+\r
+  if (Configuration == NULL || Progress == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  IfrNvData  = NULL;\r
+  *Progress  = Configuration;\r
+  BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);\r
+  Private    = WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This);\r
+\r
+  if (!HiiIsConfigHdrMatch (Configuration, &gWifiConfigFormSetGuid, mVendorStorageName)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  IfrNvData = AllocateZeroPool (BufferSize);\r
+  if (IfrNvData == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  WifiMgrConvertConfigDataToIfrNvData (Private, IfrNvData);\r
+\r
+  Status = gHiiConfigRouting->ConfigToBlock (\r
+                                gHiiConfigRouting,\r
+                                Configuration,\r
+                                (UINT8*) IfrNvData,\r
+                                &BufferSize,\r
+                                Progress\r
+                                );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = WifiMgrConvertIfrNvDataToConfigData (Private, IfrNvData);\r
+  ZeroMem (IfrNvData, sizeof (WIFI_MANAGER_IFR_NVDATA));\r
+  FreePool (IfrNvData);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function is called to provide results data to the driver.\r
+  This data consists of a unique key that is used to identify\r
+  which data is either being passed back or being asked for.\r
+\r
+  @param  This                   Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param  Action                 Specifies the type of action taken by the browser.\r
+  @param  QuestionId             A unique value which is sent to the original\r
+                                 exporting driver so that it can identify the type\r
+                                 of data to expect. The format of the data tends to\r
+                                 vary based on the opcode that generated the callback.\r
+  @param  Type                   The type of value for the question.\r
+  @param  Value                  A pointer to the data being sent to the original\r
+                                 exporting driver.\r
+  @param  ActionRequest          On return, points to the action requested by the\r
+                                 callback function.\r
+\r
+  @retval EFI_SUCCESS            The callback successfully handled the action.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the\r
+                                 variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be saved.\r
+  @retval EFI_UNSUPPORTED        The specified Action is not supported by the\r
+                                 callback.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeHiiConfigAccessCallback (\r
+  IN     CONST EFI_HII_CONFIG_ACCESS_PROTOCOL    *This,\r
+  IN     EFI_BROWSER_ACTION                      Action,\r
+  IN     EFI_QUESTION_ID                         QuestionId,\r
+  IN     UINT8                                   Type,\r
+  IN OUT EFI_IFR_TYPE_VALUE                      *Value,\r
+  OUT    EFI_BROWSER_ACTION_REQUEST              *ActionRequest\r
+  )\r
+{\r
+  EFI_STATUS                         Status;\r
+  EFI_INPUT_KEY                      Key;\r
+  UINTN                              BufferSize;\r
+  WIFI_MGR_PRIVATE_DATA              *Private;\r
+  WIFI_MANAGER_IFR_NVDATA            *IfrNvData;\r
+  EFI_DEVICE_PATH_PROTOCOL           *FilePath;\r
+  WIFI_MGR_NETWORK_PROFILE           *Profile;\r
+  WIFI_MGR_NETWORK_PROFILE           *ProfileToConnect;\r
+  WIFI_HIDDEN_NETWORK_DATA           *HiddenNetwork;\r
+  UINTN                              TempDataSize;\r
+  VOID                               *TempData;\r
+  LIST_ENTRY                         *Entry;\r
+  UINT32                             Index;\r
+  UINT32                             RemoveCount;\r
+  CHAR16                             *TempPassword;\r
+  CHAR16                             *ErrorMessage;\r
+\r
+  if (Action != EFI_BROWSER_ACTION_FORM_OPEN &&\r
+      Action != EFI_BROWSER_ACTION_FORM_CLOSE &&\r
+      Action != EFI_BROWSER_ACTION_CHANGING &&\r
+      Action != EFI_BROWSER_ACTION_CHANGED &&\r
+      Action != EFI_BROWSER_ACTION_RETRIEVE) {\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  if ((Value == NULL) || (ActionRequest == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status  = EFI_SUCCESS;\r
+  Private = WIFI_MGR_PRIVATE_DATA_FROM_CONFIG_ACCESS (This);\r
+  if (Private->CurrentNic == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Retrieve uncommitted data from Browser\r
+  //\r
+  BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);\r
+  IfrNvData = AllocateZeroPool (BufferSize);\r
+  if (IfrNvData == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  HiiGetBrowserData (&gWifiConfigFormSetGuid, mVendorStorageName, BufferSize, (UINT8 *) IfrNvData);\r
+\r
+  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
+    switch (QuestionId) {\r
+\r
+    case KEY_MAC_LIST:\r
+\r
+      Status = WifiMgrShowNicList (Private);\r
+      break;\r
+\r
+    case KEY_REFRESH_NETWORK_LIST:\r
+\r
+      if (Private->CurrentNic->UserSelectedProfile != NULL) {\r
+\r
+        Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+        //\r
+        // Erase secrets since user has left Connection Page\r
+        // Connection Page may direct to Network List Page or Eap Configuration Page,\r
+        // secrets only need to be erased when head to Network List Page\r
+        //\r
+        WifiMgrCleanProfileSecrets (Profile);\r
+\r
+        Private->CurrentNic->UserSelectedProfile = NULL;\r
+      }\r
+\r
+      break;\r
+\r
+    case KEY_CONNECT_ACTION:\r
+\r
+      if (Private->CurrentNic->UserSelectedProfile == NULL) {\r
+        break;\r
+      }\r
+      Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+      //\r
+      //Enter the network connection configuration page\r
+      //Recovery from restored data\r
+      //\r
+      if (HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_SSID), Profile->SSId, NULL) == 0) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      IfrNvData->SecurityType = Profile->SecurityType;\r
+      if (HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_SECURITY_TYPE),\r
+            mSecurityType[IfrNvData->SecurityType], NULL) == 0) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      if (IfrNvData->SecurityType == SECURITY_TYPE_WPA2_ENTERPRISE) {\r
+\r
+        IfrNvData->EapAuthMethod        = Profile->EapAuthMethod;\r
+        IfrNvData->EapSecondAuthMethod  = Profile->EapSecondAuthMethod;\r
+        StrCpyS (IfrNvData->EapIdentity, EAP_IDENTITY_SIZE, Profile->EapIdentity);\r
+      }\r
+\r
+      break;\r
+\r
+    case KEY_ENROLLED_CERT_NAME:\r
+\r
+      if (Private->CurrentNic->UserSelectedProfile == NULL) {\r
+        break;\r
+      }\r
+      Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+      //\r
+      //Enter the key enrollment page\r
+      //For TTLS and PEAP, only CA cert needs to be cared\r
+      //\r
+      if (Private->FileType == FileTypeCACert) {\r
+\r
+        if (Profile->CACertData != NULL) {\r
+          HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), Profile->CACertName, NULL);\r
+        } else {\r
+          HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), L"", NULL);\r
+        }\r
+      } else if (Private->FileType == FileTypeClientCert) {\r
+\r
+        if (Profile->ClientCertData != NULL) {\r
+          HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), Profile->ClientCertName, NULL);\r
+        } else {\r
+          HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME), L"", NULL);\r
+        }\r
+      }\r
+      break;\r
+\r
+    case KEY_ENROLLED_PRIVATE_KEY_NAME:\r
+\r
+      if (Private->CurrentNic->UserSelectedProfile == NULL) {\r
+        break;\r
+      }\r
+      Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+      if (Profile->PrivateKeyData != NULL) {\r
+        HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME), Profile->PrivateKeyName, NULL);\r
+      } else {\r
+        HiiSetString (Private->RegisteredHandle, STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME), L"", NULL);\r
+      }\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {\r
+    switch (QuestionId) {\r
+\r
+    case KEY_CONNECT_ACTION:\r
+\r
+      if (Private->CurrentNic->UserSelectedProfile == NULL) {\r
+        break;\r
+      }\r
+      Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+      //\r
+      //Restore User Config Data for Page recovery\r
+      //\r
+      if (IfrNvData->SecurityType == SECURITY_TYPE_WPA2_ENTERPRISE) {\r
+\r
+        Profile->EapAuthMethod        = IfrNvData->EapAuthMethod;\r
+        Profile->EapSecondAuthMethod  = IfrNvData->EapSecondAuthMethod;\r
+        StrCpyS (Profile->EapIdentity, EAP_IDENTITY_SIZE, IfrNvData->EapIdentity);\r
+      }\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  } else if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
+    switch (QuestionId) {\r
+\r
+    case KEY_NETWORK_LIST:\r
+\r
+      //\r
+      //User triggered a scan process.\r
+      //\r
+      Private->CurrentNic->OneTimeScanRequest = TRUE;\r
+      break;\r
+\r
+    case KEY_PASSWORD_CONNECT_NETWORK:\r
+    case KEY_EAP_PASSWORD_CONNECT_NETWORK:\r
+    case KEY_PRIVATE_KEY_PASSWORD:\r
+\r
+      if (Private->CurrentNic->UserSelectedProfile == NULL) {\r
+        break;\r
+      }\r
+      Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+      if (QuestionId == KEY_PASSWORD_CONNECT_NETWORK) {\r
+        TempPassword = Profile->Password;\r
+      } else if (QuestionId == KEY_EAP_PASSWORD_CONNECT_NETWORK) {\r
+        TempPassword = Profile->EapPassword;\r
+      } else {\r
+        TempPassword = Profile->PrivateKeyPassword;\r
+      }\r
+\r
+      Status = WifiMgrRecordPassword (Private, Value->string, TempPassword, PASSWORD_STORAGE_SIZE);\r
+      if (EFI_ERROR (Status)) {\r
+        DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Error: Failed to input password!"));\r
+        break;\r
+      }\r
+\r
+      //\r
+      // This password is not a new created password, so no need to confirm.\r
+      //\r
+      Status = EFI_NOT_FOUND;\r
+      break;\r
+\r
+    case KEY_CONNECT_ACTION:\r
+\r
+      ErrorMessage     = NULL;\r
+      ProfileToConnect = NULL;\r
+\r
+      if (Private->CurrentNic->UserSelectedProfile == NULL) {\r
+        break;\r
+      }\r
+      Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+      if (Private->CurrentNic->ConnectState == WifiMgrDisconnected ||\r
+        Profile != Private->CurrentNic->CurrentOperateNetwork) {\r
+\r
+        //\r
+        // When this network is not currently connected, pend it to connect.\r
+        //\r
+        if (Profile->AKMSuiteSupported && Profile->CipherSuiteSupported) {\r
+\r
+          if (Profile->SecurityType == SECURITY_TYPE_NONE || Profile->SecurityType == SECURITY_TYPE_WPA2_PERSONAL) {\r
+\r
+            //\r
+            // For Open network, connect directly.\r
+            //\r
+            ProfileToConnect = Profile;\r
+\r
+          } else if (Profile->SecurityType == SECURITY_TYPE_WPA2_ENTERPRISE) {\r
+\r
+            //\r
+            // For WPA/WPA2-Enterprise network, conduct eap configuration first.\r
+            // Only EAP-TLS, TTLS and PEAP is supported now!\r
+            //\r
+            Profile->EapAuthMethod = IfrNvData->EapAuthMethod;\r
+            StrCpyS (Profile->EapIdentity, EAP_IDENTITY_SIZE, IfrNvData->EapIdentity);\r
+\r
+            if (IfrNvData->EapAuthMethod == EAP_AUTH_METHOD_TTLS || IfrNvData->EapAuthMethod == EAP_AUTH_METHOD_PEAP) {\r
+\r
+              Profile->EapSecondAuthMethod = IfrNvData->EapSecondAuthMethod;\r
+              ProfileToConnect = Profile;\r
+            } else if (IfrNvData->EapAuthMethod == EAP_AUTH_METHOD_TLS) {\r
+              ProfileToConnect = Profile;\r
+            } else {\r
+              ErrorMessage = L"ERROR: Only EAP-TLS, TTLS or PEAP is supported now!";\r
+            }\r
+          } else {\r
+            ErrorMessage = L"ERROR: Can't connect to this network!";\r
+          }\r
+        } else {\r
+          ErrorMessage = L"ERROR: This network is not supported!";\r
+        }\r
+\r
+        if (ErrorMessage != NULL) {\r
+          CreatePopUp (\r
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+            &Key,\r
+            ErrorMessage,\r
+            NULL\r
+            );\r
+        }\r
+\r
+        if (ProfileToConnect != NULL) {\r
+\r
+          Private->CurrentNic->OneTimeConnectRequest = TRUE;\r
+          Private->CurrentNic->ConnectPendingNetwork = ProfileToConnect;\r
+        }\r
+      } else if (Private->CurrentNic->ConnectState == WifiMgrConnectedToAp) {\r
+\r
+        //\r
+        // This network is currently connected, just disconnect from it.\r
+        //\r
+        Private->CurrentNic->OneTimeDisconnectRequest    = TRUE;\r
+        Private->CurrentNic->HasDisconnectPendingNetwork = TRUE;\r
+      }\r
+      break;\r
+\r
+    case KEY_ENROLL_CA_CERT_CONNECT_NETWORK:\r
+\r
+      Private->FileType = FileTypeCACert;\r
+      break;\r
+\r
+    case KEY_ENROLL_CLIENT_CERT_CONNECT_NETWORK:\r
+\r
+      Private->FileType = FileTypeClientCert;\r
+      break;\r
+\r
+    case KEY_EAP_ENROLL_PRIVATE_KEY_FROM_FILE:\r
+\r
+      FilePath = NULL;\r
+      ChooseFile (NULL, NULL, NULL, &FilePath);\r
+\r
+      if (FilePath != NULL) {\r
+\r
+        UpdatePrivateKeyFromFile(Private, FilePath);\r
+        FreePool (FilePath);\r
+      }\r
+      break;\r
+\r
+    case KEY_EAP_ENROLL_CERT_FROM_FILE:\r
+\r
+      //\r
+      //User will select a cert file from File Explore\r
+      //\r
+      FilePath = NULL;\r
+      ChooseFile( NULL, NULL, NULL, &FilePath);\r
+\r
+      if (FilePath != NULL) {\r
+\r
+        UpdateCAFromFile(Private, FilePath);\r
+        FreePool (FilePath);\r
+      }\r
+      break;\r
+\r
+    case KEY_SAVE_PRIVATE_KEY_TO_MEM:\r
+\r
+      if (Private->FileContext != NULL && Private->FileContext->FHandle != NULL &&\r
+        Private->CurrentNic->UserSelectedProfile != NULL) {\r
+\r
+        //\r
+        // Read Private Key file to Buffer\r
+        //\r
+        Profile = Private->CurrentNic->UserSelectedProfile;\r
+        if (Profile->PrivateKeyData != NULL) {\r
+\r
+          ZeroMem (Profile->PrivateKeyData, Profile->PrivateKeyDataSize);\r
+          FreePool (Profile->PrivateKeyData);\r
+        }\r
+\r
+        Status = WifiMgrReadFileToBuffer (\r
+                   Private->FileContext,\r
+                   &TempData,\r
+                   &TempDataSize\r
+                   );\r
+        if (EFI_ERROR (Status)) {\r
+          CreatePopUp (\r
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+            &Key,\r
+            L"ERROR: Can't read this private key file!",\r
+            NULL\r
+            );\r
+        } else {\r
+\r
+          ASSERT (Private->FileContext->FileName != NULL);\r
+\r
+          Profile->PrivateKeyData = TempData;\r
+          Profile->PrivateKeyDataSize = TempDataSize;\r
+          StrCpyS(Profile->PrivateKeyName, WIFI_FILENAME_STR_MAX_SIZE, Private->FileContext->FileName);\r
+\r
+          DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Private Key: %s has been enrolled! Size: %d\n",\r
+            Profile->PrivateKeyName, Profile->PrivateKeyDataSize));\r
+        }\r
+      }\r
+      break;\r
+\r
+    case KEY_SAVE_CERT_TO_MEM:\r
+\r
+      if (Private->FileContext != NULL && Private->FileContext->FHandle != NULL &&\r
+        Private->CurrentNic->UserSelectedProfile != NULL) {\r
+\r
+        //\r
+        // Read Cert file to Buffer\r
+        //\r
+        Profile = Private->CurrentNic->UserSelectedProfile;\r
+\r
+        if (Private->FileType == FileTypeCACert) {\r
+          if (Profile->CACertData != NULL) {\r
+\r
+            ZeroMem (Profile->CACertData, Profile->CACertSize);\r
+            FreePool (Profile->CACertData);\r
+          }\r
+        } else if (Private->FileType == FileTypeClientCert) {\r
+          if (Profile->ClientCertData != NULL) {\r
+\r
+            ZeroMem (Profile->ClientCertData, Profile->ClientCertSize);\r
+            FreePool (Profile->ClientCertData);\r
+          }\r
+        } else {\r
+          break;\r
+        }\r
+\r
+        Status = WifiMgrReadFileToBuffer (\r
+                   Private->FileContext,\r
+                   &TempData,\r
+                   &TempDataSize\r
+                   );\r
+        if (EFI_ERROR (Status)) {\r
+          CreatePopUp (\r
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+            &Key,\r
+            L"ERROR: Can't read this certificate file!",\r
+            NULL\r
+            );\r
+        } else {\r
+\r
+          ASSERT (Private->FileContext->FileName != NULL);\r
+          if (Private->FileType == FileTypeCACert) {\r
+\r
+            Profile->CACertData = TempData;\r
+            Profile->CACertSize = TempDataSize;\r
+            StrCpyS(Profile->CACertName, WIFI_FILENAME_STR_MAX_SIZE, Private->FileContext->FileName);\r
+            DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] CA Cert: %s has been enrolled! Size: %d\n",\r
+              Profile->CACertName, Profile->CACertSize));\r
+          } else {\r
+\r
+            Profile->ClientCertData = TempData;\r
+            Profile->ClientCertSize = TempDataSize;\r
+            StrCpyS(Profile->ClientCertName, WIFI_FILENAME_STR_MAX_SIZE, Private->FileContext->FileName);\r
+            DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Client Cert: %s has been enrolled! Size: %d\n",\r
+              Profile->ClientCertName, Profile->ClientCertSize));\r
+          }\r
+        }\r
+      }\r
+      break;\r
+\r
+    case KEY_ADD_HIDDEN_NETWORK:\r
+\r
+      //\r
+      // Add a Hidden Network\r
+      //\r
+      if (StrLen (IfrNvData->SSId) < SSID_MIN_LEN ||\r
+        Private->HiddenNetworkCount >= HIDDEN_NETWORK_LIST_COUNT_MAX) {\r
+\r
+        Status = EFI_ABORTED;\r
+        break;\r
+      } else {\r
+\r
+        //\r
+        // Check if this SSId is already in Hidden Network List\r
+        //\r
+        NET_LIST_FOR_EACH (Entry, &Private->HiddenNetworkList) {\r
+\r
+          HiddenNetwork = NET_LIST_USER_STRUCT_S (Entry, WIFI_HIDDEN_NETWORK_DATA,\r
+                            Link, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE);\r
+          if (StrCmp (HiddenNetwork->SSId, IfrNvData->SSId) == 0) {\r
+\r
+            Status = EFI_ABORTED;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+\r
+      HiddenNetwork = (WIFI_HIDDEN_NETWORK_DATA *) AllocateZeroPool (sizeof (WIFI_HIDDEN_NETWORK_DATA));\r
+      if (HiddenNetwork == NULL) {\r
+\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        break;\r
+      }\r
+      HiddenNetwork->Signature = WIFI_MGR_HIDDEN_NETWORK_SIGNATURE;\r
+      StrCpyS (HiddenNetwork->SSId, SSID_STORAGE_SIZE, IfrNvData->SSId);\r
+\r
+      InsertTailList (&Private->HiddenNetworkList, &HiddenNetwork->Link);\r
+      Private->HiddenNetworkCount ++;\r
+\r
+      WifiMgrRefreshHiddenList (Private);\r
+      break;\r
+\r
+    case KEY_REMOVE_HIDDEN_NETWORK:\r
+\r
+      //\r
+      // Remove Hidden Networks\r
+      //\r
+      Entry = GetFirstNode (&Private->HiddenNetworkList);\r
+      RemoveCount = 0;\r
+      for (Index = 0; Index < Private->HiddenNetworkCount; Index ++) {\r
+        if (IfrNvData->HiddenNetworkList[Index] != 0) {\r
+\r
+          HiddenNetwork = NET_LIST_USER_STRUCT_S (Entry, WIFI_HIDDEN_NETWORK_DATA, Link, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE);\r
+          Entry = RemoveEntryList (Entry);\r
+          RemoveCount ++;\r
+\r
+          FreePool (HiddenNetwork);\r
+        } else {\r
+          Entry = GetNextNode (&Private->HiddenNetworkList, Entry);\r
+        }\r
+      }\r
+\r
+      Private->HiddenNetworkCount -= RemoveCount;\r
+      WifiMgrRefreshHiddenList (Private);\r
+      break;\r
+\r
+    default:\r
+\r
+      if (QuestionId >= KEY_MAC_ENTRY_BASE && QuestionId < KEY_MAC_ENTRY_BASE + Private->NicCount) {\r
+        //\r
+        // User selects a wireless NIC.\r
+        //\r
+        Status = WifiMgrSelectNic (Private, QuestionId);\r
+        if (EFI_ERROR (Status)) {\r
+          CreatePopUp (\r
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+            &Key,\r
+            L"ERROR: Fail to operate the wireless NIC!",\r
+            NULL\r
+          );\r
+        }\r
+      } else if (Private->CurrentNic != NULL) {\r
+        if (QuestionId >= KEY_AVAILABLE_NETWORK_ENTRY_BASE &&\r
+          QuestionId <= KEY_AVAILABLE_NETWORK_ENTRY_BASE + Private->CurrentNic->MaxProfileIndex) {\r
+\r
+          Status = WifiMgrUserSelectProfileToConnect (Private, QuestionId - KEY_AVAILABLE_NETWORK_ENTRY_BASE);\r
+          if (!EFI_ERROR (Status)) {\r
+            WifiMgrUpdateConnectMessage(Private->CurrentNic, FALSE, NULL);\r
+          }\r
+        }\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          CreatePopUp (\r
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+            &Key,\r
+            L"ERROR: Fail to operate this profile!",\r
+            NULL\r
+          );\r
+        }\r
+      }\r
+\r
+      break;\r
+    }\r
+  } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
+    switch (QuestionId) {\r
+\r
+    case KEY_SAVE_CERT_TO_MEM:\r
+    case KEY_SAVE_PRIVATE_KEY_TO_MEM:\r
+\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
+      break;\r
+\r
+    case KEY_NO_SAVE_CERT_TO_MEM:\r
+    case KEY_NO_SAVE_PRIVATE_KEY_TO_MEM:\r
+\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
+      break;\r
+\r
+    default:\r
+\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+      break;\r
+    }\r
+  } else if (Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
+\r
+    switch (QuestionId) {\r
+\r
+    case KEY_REFRESH_NETWORK_LIST:\r
+\r
+      WifiMgrRefreshNetworkList (Private, IfrNvData);\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Pass changed uncommitted data back to Form Browser.\r
+    //\r
+    BufferSize = sizeof (WIFI_MANAGER_IFR_NVDATA);\r
+    HiiSetBrowserData (&gWifiConfigFormSetGuid, mVendorStorageName, BufferSize, (UINT8 *) IfrNvData, NULL);\r
+  }\r
+\r
+  ZeroMem (IfrNvData, sizeof (WIFI_MANAGER_IFR_NVDATA));\r
+  FreePool (IfrNvData);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Initialize the WiFi configuration form.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+\r
+  @retval EFI_SUCCESS             The configuration form is initialized.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval EFI_INVALID_PARAMETER   Any input parameter is invalid.\r
+  @retval Other Erros             Returned Errors when installing protocols.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrDxeConfigFormInit (\r
+  WIFI_MGR_PRIVATE_DATA    *Private\r
+)\r
+{\r
+  EFI_STATUS                      Status;\r
+\r
+  if (Private == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Private->ConfigAccess.ExtractConfig = WifiMgrDxeHiiConfigAccessExtractConfig;\r
+  Private->ConfigAccess.RouteConfig   = WifiMgrDxeHiiConfigAccessRouteConfig;\r
+  Private->ConfigAccess.Callback      = WifiMgrDxeHiiConfigAccessCallback;\r
+\r
+  //\r
+  // Install Device Path Protocol and Config Access protocol to driver handle.\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->DriverHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  &mWifiMgrDxeHiiVendorDevicePath,\r
+                  &gEfiHiiConfigAccessProtocolGuid,\r
+                  &Private->ConfigAccess,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Publish our HII data.\r
+  //\r
+  Private->RegisteredHandle = HiiAddPackages (\r
+                                &gWifiConfigFormSetGuid,\r
+                                Private->DriverHandle,\r
+                                WifiConnectionManagerDxeStrings,\r
+                                WifiConnectionManagerDxeBin,\r
+                                NULL\r
+                                );\r
+  if (Private->RegisteredHandle == NULL) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+           Private->DriverHandle,\r
+           &gEfiDevicePathProtocolGuid,\r
+           &mWifiMgrDxeHiiVendorDevicePath,\r
+           &gEfiHiiConfigAccessProtocolGuid,\r
+           &Private->ConfigAccess,\r
+           NULL\r
+           );\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Private->FileContext = AllocateZeroPool (sizeof (WIFI_MGR_FILE_CONTEXT));\r
+  if (Private->FileContext == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Unload the WiFi configuration form.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+\r
+  @retval EFI_SUCCESS             The configuration form is unloaded successfully.\r
+  @retval EFI_INVALID_PARAMETER   Any input parameter is invalid.\r
+  @retval Other Errors            Returned Erros when uninstalling protocols.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrDxeConfigFormUnload (\r
+  WIFI_MGR_PRIVATE_DATA    *Private\r
+)\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  if (Private == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (Private->FileContext != NULL) {\r
+\r
+    if (Private->FileContext->FHandle != NULL) {\r
+      Private->FileContext->FHandle->Close (Private->FileContext->FHandle);\r
+    }\r
+\r
+    if (Private->FileContext->FileName != NULL) {\r
+      FreePool (Private->FileContext->FileName);\r
+    }\r
+    FreePool (Private->FileContext);\r
+  }\r
+\r
+  HiiRemovePackages(Private->RegisteredHandle);\r
+\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+             Private->DriverHandle,\r
+             &gEfiDevicePathProtocolGuid,\r
+             &mWifiMgrDxeHiiVendorDevicePath,\r
+             &gEfiHiiConfigAccessProtocolGuid,\r
+             &Private->ConfigAccess,\r
+             NULL\r
+             );\r
+\r
+  return Status;\r
+}\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrHiiConfigAccess.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrHiiConfigAccess.h
new file mode 100644 (file)
index 0000000..41a11ca
--- /dev/null
@@ -0,0 +1,247 @@
+/** @file\r
+  The Hii functions for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_MGR_HII_CONFIG_ACCESS__\r
+#define __EFI_WIFI_MGR_HII_CONFIG_ACCESS__\r
+\r
+/**\r
+  Update connection message on connect configuration page, and trigger related form refresh.\r
+\r
+  @param[in]   Nic                        The related Nic for updating message.\r
+  @param[in]   ConnectStateChanged        The tag to tell if the connection state has been changed, only\r
+                                          when the connection changes from "Connected" or "Disconnecting"\r
+                                          to "Disconnected", or from "Disconnected" or "Connecting" to\r
+                                          "Connected", this tag can be set as TRUE.\r
+  @param[in]   ConnectStatusMessage       The message to show on connected status bar, if NULL, will\r
+                                          use default message.\r
+\r
+**/\r
+VOID\r
+WifiMgrUpdateConnectMessage (\r
+  IN  WIFI_MGR_DEVICE_DATA      *Nic,\r
+  IN  BOOLEAN                   ConnectStateChanged,\r
+  IN  EFI_STRING                ConnectStatusMessage\r
+  );\r
+\r
+/**\r
+  This function allows the caller to request the current\r
+  configuration for one or more named elements. The resulting\r
+  string is in <ConfigAltResp> format. Any and all alternative\r
+  configuration strings shall also be appended to the end of the\r
+  current configuration string. If they are, they must appear\r
+  after the current configuration. They must contain the same\r
+  routing (GUID, NAME, PATH) as the current configuration string.\r
+  They must have an additional description indicating the type of\r
+  alternative configuration the string represents,\r
+  "ALTCFG=<StringToken>". That <StringToken> (when\r
+  converted from Hex UNICODE to binary) is a reference to a\r
+  string in the associated string pack.\r
+\r
+  @param This       Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+\r
+  @param Request    A null-terminated Unicode string in\r
+                    <ConfigRequest> format. Note that this\r
+                    includes the routing information as well as\r
+                    the configurable name / value pairs. It is\r
+                    invalid for this string to be in\r
+                    <MultiConfigRequest> format.\r
+                    If a NULL is passed in for the Request field,\r
+                    all of the settings being abstracted by this function\r
+                    will be returned in the Results field.  In addition,\r
+                    if a ConfigHdr is passed in with no request elements,\r
+                    all of the settings being abstracted for that particular\r
+                    ConfigHdr reference will be returned in the Results Field.\r
+\r
+  @param Progress   On return, points to a character in the\r
+                    Request string. Points to the string's null\r
+                    terminator if request was successful. Points\r
+                    to the most recent "&" before the first\r
+                    failing name / value pair (or the beginning\r
+                    of the string if the failure is in the first\r
+                    name / value pair) if the request was not\r
+                    successful.\r
+\r
+  @param Results    A null-terminated Unicode string in\r
+                    <MultiConfigAltResp> format which has all values\r
+                    filled in for the names in the Request string.\r
+                    String to be allocated by the called function.\r
+\r
+  @retval EFI_SUCCESS             The Results string is filled with the\r
+                                  values corresponding to all requested\r
+                                  names.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough memory to store the\r
+                                  parts of the results that must be\r
+                                  stored awaiting possible future\r
+                                  protocols.\r
+\r
+  @retval EFI_NOT_FOUND           Routing data doesn't match any\r
+                                  known driver. Progress set to the\r
+                                  first character in the routing header.\r
+                                  Note: There is no requirement that the\r
+                                  driver validate the routing data. It\r
+                                  must skip the <ConfigHdr> in order to\r
+                                  process the names.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Illegal syntax. Progress set\r
+                                  to most recent "&" before the\r
+                                  error or the beginning of the\r
+                                  string.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Unknown name. Progress points\r
+                                  to the & before the name in\r
+                                  question.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeHiiConfigAccessExtractConfig (\r
+  IN CONST  EFI_HII_CONFIG_ACCESS_PROTOCOL  *This,\r
+  IN CONST  EFI_STRING                      Request,\r
+  OUT       EFI_STRING                      *Progress,\r
+  OUT       EFI_STRING                      *Results\r
+  );\r
+\r
+/**\r
+  This function applies changes in a driver's configuration.\r
+  Input is a Configuration, which has the routing data for this\r
+  driver followed by name / value configuration pairs. The driver\r
+  must apply those pairs to its configurable storage. If the\r
+  driver's configuration is stored in a linear block of data\r
+  and the driver's name / value pairs are in <BlockConfig>\r
+  format, it may use the ConfigToBlock helper function (above) to\r
+  simplify the job.\r
+\r
+  @param This           Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+\r
+  @param Configuration  A null-terminated Unicode string in\r
+                        <ConfigString> format.\r
+\r
+  @param Progress       A pointer to a string filled in with the\r
+                        offset of the most recent '&' before the\r
+                        first failing name / value pair (or the\r
+                        beginn ing of the string if the failure\r
+                        is in the first name / value pair) or\r
+                        the terminating NULL if all was\r
+                        successful.\r
+\r
+  @retval EFI_SUCCESS             The results have been distributed or are\r
+                                  awaiting distribution.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough memory to store the\r
+                                  parts of the results that must be\r
+                                  stored awaiting possible future\r
+                                  protocols.\r
+\r
+  @retval EFI_INVALID_PARAMETERS  Passing in a NULL for the\r
+                                  Results parameter would result\r
+                                  in this type of error.\r
+\r
+  @retval EFI_NOT_FOUND           Target for the specified routing data\r
+                                  was not found\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeHiiConfigAccessRouteConfig (\r
+  IN CONST  EFI_HII_CONFIG_ACCESS_PROTOCOL  *This,\r
+  IN CONST  EFI_STRING                      Configuration,\r
+  OUT       EFI_STRING                      *Progress\r
+  );\r
+\r
+/**\r
+  This function is called to provide results data to the driver.\r
+  This data consists of a unique key that is used to identify\r
+  which data is either being passed back or being asked for.\r
+\r
+  @param  This                   Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+  @param  Action                 Specifies the type of action taken by the browser.\r
+  @param  QuestionId             A unique value which is sent to the original\r
+                                 exporting driver so that it can identify the type\r
+                                 of data to expect. The format of the data tends to\r
+                                 vary based on the opcode that generated the callback.\r
+  @param  Type                   The type of value for the question.\r
+  @param  Value                  A pointer to the data being sent to the original\r
+                                 exporting driver.\r
+  @param  ActionRequest          On return, points to the action requested by the\r
+                                 callback function.\r
+\r
+  @retval EFI_SUCCESS            The callback successfully handled the action.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the\r
+                                 variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be saved.\r
+  @retval EFI_UNSUPPORTED        The specified Action is not supported by the\r
+                                 callback.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WifiMgrDxeHiiConfigAccessCallback (\r
+  IN     CONST EFI_HII_CONFIG_ACCESS_PROTOCOL   *This,\r
+  IN     EFI_BROWSER_ACTION                     Action,\r
+  IN     EFI_QUESTION_ID                        QuestionId,\r
+  IN     UINT8                                  Type,\r
+  IN OUT EFI_IFR_TYPE_VALUE                     *Value,\r
+  OUT    EFI_BROWSER_ACTION_REQUEST             *ActionRequest\r
+  );\r
+\r
+/**\r
+  Initialize the WiFi configuration form.\r
+\r
+  @param[in]  Private             The pointer to the global private data structure.\r
+\r
+  @retval EFI_SUCCESS             The configuration form is initialized.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Erros             Returned errors when installing protocols.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrDxeConfigFormInit (\r
+  WIFI_MGR_PRIVATE_DATA    *Private\r
+  );\r
+\r
+/**\r
+  Unload the WiFi configuration form.\r
+\r
+  @param[in]  Private      The pointer to the global private data structure.\r
+\r
+  @retval EFI_SUCCESS      The configuration form is unloaded successfully.\r
+  @retval Other Errors     Returned Erros when uninstalling protocols.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrDxeConfigFormUnload (\r
+  WIFI_MGR_PRIVATE_DATA    *Private\r
+  );\r
+\r
+/**\r
+  Refresh the network list display of the current Nic.\r
+\r
+  @param[in]   Private            The pointer to the global private data structure.\r
+  @param[out]  IfrNvData          The IFR NV data.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Errors            Returned errors when creating Opcodes or updating the\r
+                                  Hii form.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrRefreshNetworkList (\r
+  IN    WIFI_MGR_PRIVATE_DATA        *Private,\r
+  OUT   WIFI_MANAGER_IFR_NVDATA      *IfrNvData\r
+  );\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
new file mode 100644 (file)
index 0000000..52ce18d
--- /dev/null
@@ -0,0 +1,1292 @@
+/** @file\r
+  The Mac Connection2 Protocol adapter functions for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "WifiConnectionMgrDxe.h"\r
+\r
+EFI_EAP_TYPE mEapAuthMethod[] = {\r
+  EFI_EAP_TYPE_TTLS,\r
+  EFI_EAP_TYPE_PEAP,\r
+  EFI_EAP_TYPE_EAPTLS\r
+};\r
+\r
+EFI_EAP_TYPE mEapSecondAuthMethod[] = {\r
+  EFI_EAP_TYPE_MSCHAPV2\r
+};\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
+\r
+  ASSERT when errors occur in config token.\r
+\r
+  @param[in]  Event                 The GetNetworks token receive event.\r
+  @param[in]  Context               The context of the GetNetworks token.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WifiMgrOnScanFinished (\r
+  IN  EFI_EVENT                     Event,\r
+  IN  VOID                          *Context\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  WIFI_MGR_MAC_CONFIG_TOKEN         *ConfigToken;\r
+  WIFI_MGR_DEVICE_DATA              *Nic;\r
+  WIFI_MGR_NETWORK_PROFILE          *Profile;\r
+  EFI_80211_NETWORK                 *Network;\r
+  UINTN                             DataSize;\r
+  EFI_80211_NETWORK_DESCRIPTION     *NetworkDescription;\r
+  EFI_80211_GET_NETWORKS_RESULT     *Result;\r
+  LIST_ENTRY                        *Entry;\r
+  UINT8                             SecurityType;\r
+  BOOLEAN                           AKMSuiteSupported;\r
+  BOOLEAN                           CipherSuiteSupported;\r
+  CHAR8                             *AsciiSSId;\r
+  UINTN                             Index;\r
+\r
+  ASSERT (Context != NULL);\r
+\r
+  ConfigToken = (WIFI_MGR_MAC_CONFIG_TOKEN *) Context;\r
+  ASSERT (ConfigToken->Nic != NULL);\r
+  ASSERT (ConfigToken->Type == TokenTypeGetNetworksToken);\r
+\r
+  //\r
+  // It is the GetNetworks token, set scan state to "ScanFinished"\r
+  //\r
+  ConfigToken->Nic->ScanState = WifiMgrScanFinished;\r
+\r
+  ASSERT (ConfigToken->Token.GetNetworksToken != NULL);\r
+  Result = ConfigToken->Token.GetNetworksToken->Result;\r
+  Nic    = ConfigToken->Nic;\r
+\r
+  //\r
+  // Clean previous result, and update network list according to the scan result\r
+  //\r
+  Nic->AvailableCount    = 0;\r
+\r
+  NET_LIST_FOR_EACH (Entry, &Nic->ProfileList) {\r
+    Profile = NET_LIST_USER_STRUCT_S (Entry, WIFI_MGR_NETWORK_PROFILE,\r
+                Link, WIFI_MGR_PROFILE_SIGNATURE);\r
+    Profile->IsAvailable = FALSE;\r
+  }\r
+\r
+  if (Result == NULL) {\r
+    gBS->SignalEvent (Nic->Private->NetworkListRefreshEvent);\r
+    WifiMgrFreeToken(ConfigToken);\r
+    return;\r
+  }\r
+\r
+  for (Index = 0; Index < Result->NumOfNetworkDesc; Index ++) {\r
+\r
+    NetworkDescription = Result->NetworkDesc + Index;\r
+    if (NetworkDescription == NULL) {\r
+      continue;\r
+    }\r
+\r
+    Network = &NetworkDescription->Network;\r
+    if (Network == NULL || Network->SSId.SSIdLen == 0) {\r
+      continue;\r
+    }\r
+\r
+    Status = WifiMgrCheckRSN (\r
+               Network->AKMSuite,\r
+               Network->CipherSuite,\r
+               Nic,\r
+               &SecurityType,\r
+               &AKMSuiteSupported,\r
+               &CipherSuiteSupported\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+\r
+      SecurityType          = SECURITY_TYPE_UNKNOWN;\r
+      AKMSuiteSupported     = FALSE;\r
+      CipherSuiteSupported  = FALSE;\r
+    }\r
+\r
+    AsciiSSId = (CHAR8*) AllocateZeroPool(sizeof (CHAR8) * (Network->SSId.SSIdLen + 1));\r
+    if (AsciiSSId == NULL) {\r
+      continue;\r
+    }\r
+    CopyMem(AsciiSSId, (CHAR8 *) Network->SSId.SSId, sizeof (CHAR8) * Network->SSId.SSIdLen);\r
+    *(AsciiSSId + Network->SSId.SSIdLen) = '\0';\r
+\r
+    Profile = WifiMgrGetProfileByAsciiSSId (AsciiSSId, SecurityType, &Nic->ProfileList);\r
+    if (Profile == NULL) {\r
+\r
+      if (Nic->MaxProfileIndex >= NETWORK_LIST_COUNT_MAX) {\r
+        FreePool (AsciiSSId);\r
+        continue;\r
+      }\r
+\r
+      //\r
+      // Create a new profile\r
+      //\r
+      Profile = AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));\r
+      if (Profile == NULL) {\r
+        FreePool (AsciiSSId);\r
+        continue;\r
+      }\r
+      Profile->Signature    = WIFI_MGR_PROFILE_SIGNATURE;\r
+      Profile->NicIndex     = Nic->NicIndex;\r
+      Profile->ProfileIndex = Nic->MaxProfileIndex + 1;\r
+      AsciiStrToUnicodeStrS (AsciiSSId, Profile->SSId, SSID_STORAGE_SIZE);\r
+      InsertTailList (&Nic->ProfileList, &Profile->Link);\r
+      Nic->MaxProfileIndex ++;\r
+    }\r
+    FreePool (AsciiSSId);\r
+\r
+    //\r
+    //May receive duplicate networks in scan results, check if it has already\r
+    //been processed.\r
+    //\r
+    if (!Profile->IsAvailable) {\r
+\r
+      Profile->IsAvailable          = TRUE;\r
+      Profile->SecurityType         = SecurityType;\r
+      Profile->AKMSuiteSupported    = AKMSuiteSupported;\r
+      Profile->CipherSuiteSupported = CipherSuiteSupported;\r
+      Profile->NetworkQuality       = NetworkDescription->NetworkQuality;\r
+      Nic->AvailableCount ++;\r
+\r
+      //\r
+      //Copy BSSType and SSId\r
+      //\r
+      CopyMem(&Profile->Network, Network, sizeof (EFI_80211_NETWORK));\r
+\r
+      //\r
+      //Copy AKMSuite list\r
+      //\r
+      if (Network->AKMSuite != NULL) {\r
+\r
+        if (Network->AKMSuite->AKMSuiteCount == 0) {\r
+          DataSize = sizeof (EFI_80211_AKM_SUITE_SELECTOR);\r
+        } else {\r
+          DataSize = sizeof (EFI_80211_AKM_SUITE_SELECTOR) + sizeof (EFI_80211_SUITE_SELECTOR)\r
+                       * (Network->AKMSuite->AKMSuiteCount - 1);\r
+        }\r
+        Profile->Network.AKMSuite = (EFI_80211_AKM_SUITE_SELECTOR *) AllocateZeroPool (DataSize);\r
+        if (Profile->Network.AKMSuite == NULL) {\r
+          continue;\r
+        }\r
+        CopyMem (Profile->Network.AKMSuite, Network->AKMSuite, DataSize);\r
+      }\r
+\r
+      //\r
+      //Copy CipherSuite list\r
+      //\r
+      if (Network->CipherSuite != NULL) {\r
+\r
+        if (Network->CipherSuite->CipherSuiteCount == 0) {\r
+          DataSize = sizeof (EFI_80211_CIPHER_SUITE_SELECTOR);\r
+        } else {\r
+          DataSize = sizeof (EFI_80211_CIPHER_SUITE_SELECTOR) + sizeof (EFI_80211_SUITE_SELECTOR)\r
+                       * (Network->CipherSuite->CipherSuiteCount - 1);\r
+        }\r
+        Profile->Network.CipherSuite = (EFI_80211_CIPHER_SUITE_SELECTOR *) AllocateZeroPool (DataSize);\r
+        if (Profile->Network.CipherSuite == NULL) {\r
+          continue;\r
+        }\r
+        CopyMem (Profile->Network.CipherSuite, Network->CipherSuite, DataSize);\r
+      }\r
+    } else {\r
+      //\r
+      // A duplicate network, update signal quality\r
+      //\r
+      if (Profile->NetworkQuality < NetworkDescription->NetworkQuality) {\r
+        Profile->NetworkQuality = NetworkDescription->NetworkQuality;\r
+      }\r
+      continue;\r
+    }\r
+  }\r
+\r
+  FreePool (Result);\r
+  gBS->SignalEvent (Nic->Private->NetworkListRefreshEvent);\r
+\r
+  //\r
+  // The current connected network should always be available until disconnection\r
+  // happens in Wifi FW layer, even when it is not in this time's scan result.\r
+  //\r
+  if (Nic->ConnectState == WifiMgrConnectedToAp && Nic->CurrentOperateNetwork != NULL) {\r
+    if (!Nic->CurrentOperateNetwork->IsAvailable) {\r
+      Nic->CurrentOperateNetwork->IsAvailable = TRUE;\r
+      Nic->AvailableCount ++;\r
+    }\r
+  }\r
+\r
+  WifiMgrFreeToken(ConfigToken);\r
+}\r
+\r
+/**\r
+  Start scan operation, and send out a token to collect available networks.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_ALREADY_STARTED     A former scan operation is already ongoing.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Errors            Return errors when getting networks from low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrStartScan (\r
+  IN      WIFI_MGR_DEVICE_DATA        *Nic\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_TPL                             OldTpl;\r
+  WIFI_MGR_MAC_CONFIG_TOKEN           *ConfigToken;\r
+  EFI_80211_GET_NETWORKS_TOKEN        *GetNetworksToken;\r
+  UINT32                              HiddenSSIdIndex;\r
+  UINT32                              HiddenSSIdCount;\r
+  EFI_80211_SSID                      *HiddenSSIdList;\r
+  WIFI_HIDDEN_NETWORK_DATA            *HiddenNetwork;\r
+  LIST_ENTRY                          *Entry;\r
+\r
+  if (Nic == NULL || Nic->Wmp == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (Nic->ScanState == WifiMgrScanning) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  Nic->ScanState  = WifiMgrScanning;\r
+  OldTpl          = gBS->RaiseTPL (TPL_CALLBACK);\r
+  Status          = EFI_SUCCESS;\r
+  HiddenSSIdList  = NULL;\r
+  HiddenSSIdCount = Nic->Private->HiddenNetworkCount;\r
+  HiddenSSIdIndex = 0;\r
+\r
+  //\r
+  //create a new get network token\r
+  //\r
+  ConfigToken     = AllocateZeroPool (sizeof (WIFI_MGR_MAC_CONFIG_TOKEN));\r
+  if (ConfigToken == NULL) {\r
+    gBS->RestoreTPL (OldTpl);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  ConfigToken->Type      = TokenTypeGetNetworksToken;\r
+  ConfigToken->Nic       = Nic;\r
+  ConfigToken->Token.GetNetworksToken = AllocateZeroPool (sizeof (EFI_80211_GET_NETWORKS_TOKEN));\r
+  if (ConfigToken->Token.GetNetworksToken == NULL) {\r
+    WifiMgrFreeToken(ConfigToken);\r
+    gBS->RestoreTPL (OldTpl);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  GetNetworksToken = ConfigToken->Token.GetNetworksToken;\r
+\r
+  //\r
+  // There are some hidden networks to scan, add them into scan list\r
+  //\r
+  if (HiddenSSIdCount > 0) {\r
+    HiddenSSIdList = AllocateZeroPool(HiddenSSIdCount * sizeof (EFI_80211_SSID));\r
+    if (HiddenSSIdList == NULL) {\r
+      WifiMgrFreeToken(ConfigToken);\r
+      gBS->RestoreTPL (OldTpl);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    HiddenSSIdIndex = 0;\r
+    NET_LIST_FOR_EACH (Entry, &Nic->Private->HiddenNetworkList) {\r
+\r
+      HiddenNetwork = NET_LIST_USER_STRUCT_S (Entry, WIFI_HIDDEN_NETWORK_DATA,\r
+                        Link, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE);\r
+      HiddenSSIdList[HiddenSSIdIndex].SSIdLen = (UINT8) StrLen (HiddenNetwork->SSId);\r
+      UnicodeStrToAsciiStrS(HiddenNetwork->SSId,\r
+        (CHAR8 *) HiddenSSIdList[HiddenSSIdIndex].SSId, SSID_STORAGE_SIZE);\r
+      HiddenSSIdIndex ++;\r
+    }\r
+    GetNetworksToken->Data = AllocateZeroPool (sizeof (EFI_80211_GET_NETWORKS_DATA) +\r
+                               (HiddenSSIdCount - 1) * sizeof (EFI_80211_SSID));\r
+    if (GetNetworksToken->Data == NULL) {\r
+      FreePool (HiddenSSIdList);\r
+      WifiMgrFreeToken(ConfigToken);\r
+      gBS->RestoreTPL (OldTpl);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    GetNetworksToken->Data->NumOfSSID = HiddenSSIdCount;\r
+    CopyMem(GetNetworksToken->Data->SSIDList, HiddenSSIdList, HiddenSSIdCount * sizeof (EFI_80211_SSID));\r
+    FreePool(HiddenSSIdList);\r
+  } else {\r
+\r
+    GetNetworksToken->Data = AllocateZeroPool (sizeof (EFI_80211_GET_NETWORKS_DATA));\r
+    if (GetNetworksToken->Data == NULL) {\r
+      WifiMgrFreeToken(ConfigToken);\r
+      gBS->RestoreTPL (OldTpl);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    GetNetworksToken->Data->NumOfSSID = 0;\r
+  }\r
+\r
+  //\r
+  //Create a handle when scan process ends\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  WifiMgrOnScanFinished,\r
+                  ConfigToken,\r
+                  &GetNetworksToken->Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    WifiMgrFreeToken(ConfigToken);\r
+    gBS->RestoreTPL (OldTpl);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  //Start scan ...\r
+  //\r
+  Status = Nic->Wmp->GetNetworks (Nic->Wmp, GetNetworksToken);\r
+  if (EFI_ERROR (Status)) {\r
+    Nic->ScanState  = WifiMgrScanFinished;\r
+    WifiMgrFreeToken(ConfigToken);\r
+    gBS->RestoreTPL (OldTpl);\r
+    return Status;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Configure password to supplicant before connecting to a secured network.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+  @param[in]  Profile             The target network to be connected.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval EFI_NOT_FOUND           No valid password is found to configure.\r
+  @retval Other Errors            Returned errors when setting data to supplicant.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrConfigPassword (\r
+  IN    WIFI_MGR_DEVICE_DATA              *Nic,\r
+  IN    WIFI_MGR_NETWORK_PROFILE          *Profile\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_SUPPLICANT_PROTOCOL    *Supplicant;\r
+  EFI_80211_SSID             SSId;\r
+  UINT8                      *AsciiPassword;\r
+\r
+  if (Nic == NULL || Nic->Supplicant == NULL || Profile == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  Supplicant = Nic->Supplicant;\r
+  //\r
+  //Set SSId to supplicant\r
+  //\r
+  SSId.SSIdLen = Profile->Network.SSId.SSIdLen;\r
+  CopyMem(SSId.SSId, Profile->Network.SSId.SSId, sizeof (Profile->Network.SSId.SSId));\r
+  Status = Supplicant->SetData(Supplicant,EfiSupplicant80211TargetSSIDName,\r
+                         (VOID *)&SSId, sizeof(EFI_80211_SSID));\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  //Set password to supplicant\r
+  //\r
+  if (StrLen (Profile->Password) < PASSWORD_MIN_LEN) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  AsciiPassword = AllocateZeroPool ((StrLen(Profile->Password) + 1) * sizeof (UINT8));\r
+  if (AsciiPassword == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  UnicodeStrToAsciiStrS (Profile->Password, (CHAR8 *) AsciiPassword, PASSWORD_STORAGE_SIZE);\r
+  Status = Supplicant->SetData (Supplicant, EfiSupplicant80211PskPassword,\r
+                         AsciiPassword, (StrLen(Profile->Password) + 1) * sizeof (UINT8));\r
+  ZeroMem (AsciiPassword, AsciiStrLen ((CHAR8 *) AsciiPassword) + 1);\r
+  FreePool(AsciiPassword);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Conduct EAP configuration to supplicant before connecting to a EAP network.\r
+  Current WiFi Connection Manager only supports three kinds of EAP networks:\r
+  1). EAP-TLS (Two-Way Authentication is required in our implementation)\r
+  2). EAP-TTLS/MSCHAPv2 (One-Way Authentication is required in our implementation)\r
+  3). PEAPv0/MSCHAPv2 (One-Way Authentication is required in our implementation)\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+  @param[in]  Profile             The target network to be connected.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED         The expected EAP method is not supported.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Errors            Returned errors when setting data to supplicant.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrConfigEap (\r
+  IN    WIFI_MGR_DEVICE_DATA              *Nic,\r
+  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
+\r
+  if (Nic == NULL || Nic->EapConfig == NULL || Profile == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  EapConfig = Nic->EapConfig;\r
+\r
+  if (Profile->EapAuthMethod >= EAP_AUTH_METHOD_MAX) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  EapAuthMethod = mEapAuthMethod[Profile->EapAuthMethod];\r
+\r
+  if (EapAuthMethod != EFI_EAP_TYPE_EAPTLS) {\r
+    if (Profile->EapSecondAuthMethod >= EAP_SEAUTH_METHOD_MAX) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    EapSecondAuthMethod = mEapSecondAuthMethod[Profile->EapSecondAuthMethod];\r
+  }\r
+\r
+  //\r
+  //The first time to get Supported Auth Method list, return the size.\r
+  //\r
+  AuthMethodListSize  = 0;\r
+  AuthMethodList      = NULL;\r
+  Status = EapConfig->GetData (EapConfig, EFI_EAP_TYPE_ATTRIBUTE, EfiEapConfigEapSupportedAuthMethod,\r
+                        (VOID *) AuthMethodList, &AuthMethodListSize);\r
+  if (Status == EFI_SUCCESS) {\r
+    //\r
+    //No Supported Eap Auth Method\r
+    //\r
+    return EFI_UNSUPPORTED;\r
+  } else if (Status != EFI_BUFFER_TOO_SMALL) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // The second time to get Supported Auth Method list, return the list.\r
+  // In current design, only EAPTLS, TTLS and PEAP are supported\r
+  //\r
+  AuthMethodList = (EFI_EAP_TYPE *) AllocateZeroPool(AuthMethodListSize);\r
+  if (AuthMethodList == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  Status = EapConfig->GetData (EapConfig, EFI_EAP_TYPE_ATTRIBUTE, EfiEapConfigEapSupportedAuthMethod,\r
+                        (VOID *) AuthMethodList, &AuthMethodListSize);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (AuthMethodList);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  //Check if EapAuthMethod is in supported Auth Method list, if found, skip the loop.\r
+  //\r
+  for (Index = 0; Index < AuthMethodListSize / sizeof (EFI_EAP_TYPE); Index ++) {\r
+    if (EapAuthMethod == AuthMethodList[Index]) {\r
+      break;\r
+    }\r
+  }\r
+  if (Index == AuthMethodListSize / sizeof (EFI_EAP_TYPE)) {\r
+    FreePool (AuthMethodList);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  FreePool (AuthMethodList);\r
+\r
+  //\r
+  // Set Identity to Eap peer, Mandatory field for PEAP and TTLS\r
+  //\r
+  if (StrLen (Profile->EapIdentity) > 0) {\r
+\r
+    IdentitySize = sizeof(CHAR8) * (StrLen(Profile->EapIdentity) + 1);\r
+    Identity = AllocateZeroPool (IdentitySize);\r
+    if (Identity == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    UnicodeStrToAsciiStrS(Profile->EapIdentity, Identity, IdentitySize);\r
+    Status = EapConfig->SetData (EapConfig, EFI_EAP_TYPE_IDENTITY, EfiEapConfigIdentityString,\r
+                          (VOID *) Identity, IdentitySize - 1);\r
+    if (EFI_ERROR(Status)) {\r
+      FreePool (Identity);\r
+      return Status;\r
+    }\r
+    FreePool (Identity);\r
+  } else {\r
+    if (EapAuthMethod != EFI_EAP_TYPE_EAPTLS) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
+  //\r
+  //Set Auth Method to Eap peer, Mandatory field\r
+  //\r
+  Status = EapConfig->SetData (EapConfig, EFI_EAP_TYPE_ATTRIBUTE, EfiEapConfigEapAuthMethod,\r
+                        (VOID *) &EapAuthMethod, sizeof (EapAuthMethod));\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (EapAuthMethod == EFI_EAP_TYPE_TTLS || EapAuthMethod == EFI_EAP_TYPE_PEAP) {\r
+\r
+    Status = EapConfig->SetData (EapConfig, EapAuthMethod, EfiEapConfigEap2ndAuthMethod,\r
+                          (VOID *) &EapSecondAuthMethod, sizeof (EapSecondAuthMethod));\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Set Password to Eap peer\r
+    //\r
+    if (StrLen (Profile->EapPassword) < PASSWORD_MIN_LEN) {\r
+\r
+      DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Error: No Eap Password for Network: %s.\n", Profile->SSId));\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    PasswordSize = sizeof (CHAR16) * (StrLen (Profile->EapPassword) + 1);\r
+    Password = AllocateZeroPool (PasswordSize);\r
+    if (Password == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    StrCpyS (Password, PasswordSize, Profile->EapPassword);;\r
+    Status = EapConfig->SetData (EapConfig, EFI_EAP_TYPE_MSCHAPV2, EfiEapConfigEapMSChapV2Password,\r
+               (VOID *) Password, PasswordSize);\r
+    ZeroMem (Password, PasswordSize);\r
+    FreePool (Password);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    //If CA cert is required, set it to Eap peer\r
+    //\r
+    if (Profile->CACertData != NULL) {\r
+\r
+      Status = EapConfig->SetData (EapConfig, EapAuthMethod, EfiEapConfigEapTlsCACert,\r
+                 Profile->CACertData, Profile->CACertSize);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
+    } else {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  } else if (EapAuthMethod == EFI_EAP_TYPE_EAPTLS) {\r
+\r
+    //\r
+    //Set CA cert to Eap peer\r
+    //\r
+    if (Profile->CACertData == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    Status = EapConfig->SetData (EapConfig, EFI_EAP_TYPE_EAPTLS, EfiEapConfigEapTlsCACert,\r
+               Profile->CACertData, Profile->CACertSize);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    //Set Client cert to Eap peer\r
+    //\r
+    if (Profile->ClientCertData == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    Status = EapConfig->SetData (EapConfig, EFI_EAP_TYPE_EAPTLS, EfiEapConfigEapTlsClientCert,\r
+               Profile->ClientCertData, Profile->ClientCertSize);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    //Set Private key to Eap peer\r
+    //\r
+    if (Profile->PrivateKeyData == NULL) {\r
+\r
+      DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager]  Error: No Private Key for Network: %s.\n", Profile->SSId));\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    Status = EapConfig->SetData (EapConfig, EFI_EAP_TYPE_EAPTLS, EfiEapConfigEapTlsClientPrivateKeyFile,\r
+               Profile->PrivateKeyData, Profile->PrivateKeyDataSize);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    if (StrLen (Profile->PrivateKeyPassword) > 0) {\r
+\r
+      EncryptPasswordLen = StrLen (Profile->PrivateKeyPassword);\r
+      AsciiEncryptPassword = AllocateZeroPool(EncryptPasswordLen + 1);\r
+      if (AsciiEncryptPassword == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      UnicodeStrToAsciiStrS(Profile->PrivateKeyPassword, AsciiEncryptPassword, EncryptPasswordLen + 1);\r
+      Status = EapConfig->SetData(EapConfig, EFI_EAP_TYPE_EAPTLS,\r
+                                    EfiEapConfigEapTlsClientPrivateKeyFilePassword,\r
+                                    (VOID *) AsciiEncryptPassword, EncryptPasswordLen + 1);\r
+      if (EFI_ERROR(Status)) {\r
+\r
+        ZeroMem (AsciiEncryptPassword, EncryptPasswordLen + 1);\r
+        FreePool (AsciiEncryptPassword);\r
+        return Status;\r
+      }\r
+\r
+      ZeroMem (AsciiEncryptPassword, EncryptPasswordLen + 1);\r
+      FreePool (AsciiEncryptPassword);\r
+    }\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Get current link state from low layer.\r
+\r
+  @param[in]   Nic                Pointer to the device data of the selected NIC.\r
+  @param[out]  LinkState          The pointer to buffer to retrieve link state.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED         Adapter information protocol is not supported.\r
+  @retval Other Errors            Returned errors when retrieving link state from low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrGetLinkState (\r
+  IN   WIFI_MGR_DEVICE_DATA            *Nic,\r
+  OUT  EFI_ADAPTER_INFO_MEDIA_STATE    *LinkState\r
+  )\r
+{\r
+  EFI_STATUS                           Status;\r
+  EFI_TPL                              OldTpl;\r
+  UINTN                                DataSize;\r
+  EFI_ADAPTER_INFO_MEDIA_STATE         *UndiState;\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL     *Aip;\r
+\r
+  if (Nic == NULL || LinkState == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  Status = gBS->OpenProtocol (\r
+                  Nic->ControllerHandle,\r
+                  &gEfiAdapterInformationProtocolGuid,\r
+                  (VOID**) &Aip,\r
+                  Nic->DriverHandle,\r
+                  Nic->ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->RestoreTPL (OldTpl);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = Aip->GetInformation(\r
+                  Aip,\r
+                  &gEfiAdapterInfoMediaStateGuid,\r
+                  (VOID **) &UndiState,\r
+                  &DataSize\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->RestoreTPL (OldTpl);\r
+    return Status;\r
+  }\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  CopyMem (LinkState, UndiState, sizeof (EFI_ADAPTER_INFO_MEDIA_STATE));\r
+  FreePool (UndiState);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Prepare configuration work before connecting to the target network.\r
+  For WPA2 Personal networks, password should be checked; and for EAP networks, parameters\r
+  are different for different networks.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+  @param[in]  Profile             The target network to be connected.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_UNSUPPORTED         This network is not supported.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrPrepareConnection (\r
+  IN    WIFI_MGR_DEVICE_DATA              *Nic,\r
+  IN    WIFI_MGR_NETWORK_PROFILE          *Profile\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  UINT8                SecurityType;\r
+  BOOLEAN              AKMSuiteSupported;\r
+  BOOLEAN              CipherSuiteSupported;\r
+\r
+  if (Profile == NULL || Nic == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = WifiMgrCheckRSN (Profile->Network.AKMSuite, Profile->Network.CipherSuite,\r
+             Nic, &SecurityType, &AKMSuiteSupported, &CipherSuiteSupported);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (AKMSuiteSupported && CipherSuiteSupported) {\r
+    switch (SecurityType) {\r
+      case SECURITY_TYPE_WPA2_PERSONAL:\r
+\r
+        Status = WifiMgrConfigPassword (Nic, Profile);\r
+        if (EFI_ERROR (Status)) {\r
+          if (Status == EFI_NOT_FOUND) {\r
+            if (Nic->OneTimeConnectRequest) {\r
+              WifiMgrUpdateConnectMessage (Nic, FALSE, L"Connect Failed: Invalid Password!");\r
+            }\r
+          }\r
+          return Status;\r
+        }\r
+        break;\r
+\r
+      case SECURITY_TYPE_WPA2_ENTERPRISE:\r
+\r
+        Status = WifiMgrConfigEap (Nic, Profile);\r
+        if (EFI_ERROR (Status)) {\r
+          if (Status == EFI_INVALID_PARAMETER) {\r
+            if (Nic->OneTimeConnectRequest) {\r
+              WifiMgrUpdateConnectMessage (Nic, FALSE, L"Connect Failed: Invalid Configuration!");\r
+            }\r
+          }\r
+          return Status;\r
+        }\r
+        break;\r
+\r
+      case SECURITY_TYPE_NONE:\r
+        break;\r
+\r
+      default:\r
+        return EFI_UNSUPPORTED;\r
+    }\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  The callback function for connect operation.\r
+\r
+  ASSERT when errors occur in config token.\r
+\r
+  @param[in]  Event                 The Connect token receive event.\r
+  @param[in]  Context               The context of the connect token.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WifiMgrOnConnectFinished (\r
+  IN  EFI_EVENT              Event,\r
+  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
+\r
+  ASSERT (Context != NULL);\r
+\r
+  ConnectedProfile = NULL;\r
+  ConfigToken = (WIFI_MGR_MAC_CONFIG_TOKEN*) Context;\r
+  ASSERT (ConfigToken->Nic != NULL);\r
+\r
+  ConfigToken->Nic->ConnectState = WifiMgrDisconnected;\r
+  ASSERT (ConfigToken->Type == TokenTypeConnectNetworkToken);\r
+\r
+  ASSERT (ConfigToken->Token.ConnectNetworkToken != NULL);\r
+  if (ConfigToken->Token.ConnectNetworkToken->Status != EFI_SUCCESS) {\r
+\r
+    if (ConfigToken->Nic->OneTimeConnectRequest) {\r
+      //\r
+      // Only update message for user triggered connection\r
+      //\r
+      if (ConfigToken->Token.ConnectNetworkToken->Status == EFI_ACCESS_DENIED) {\r
+\r
+        WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, L"Connect Failed: Permission Denied!");\r
+      } else {\r
+        WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, L"Connect Failed!");\r
+      }\r
+      ConfigToken->Nic->OneTimeConnectRequest = FALSE;\r
+    }\r
+    ConfigToken->Nic->CurrentOperateNetwork = NULL;\r
+    return;\r
+  }\r
+\r
+  if (ConfigToken->Token.ConnectNetworkToken->ResultCode != ConnectSuccess) {\r
+\r
+    if (ConfigToken->Nic->OneTimeConnectRequest) {\r
+\r
+      if (ConfigToken->Token.ConnectNetworkToken->ResultCode == ConnectFailedReasonUnspecified) {\r
+        WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, L"Connect Failed: Wrong Password or Unexpected Error!");\r
+      } else {\r
+        WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, L"Connect Failed!");\r
+      }\r
+    }\r
+    goto Exit;\r
+  }\r
+\r
+  if (ConfigToken->Token.ConnectNetworkToken->Data == NULL ||\r
+    ConfigToken->Token.ConnectNetworkToken->Data->Network == NULL) {\r
+\r
+    //\r
+    // An unexpected error occurs, tell low layer to perform a disconnect\r
+    //\r
+    ConfigToken->Nic->HasDisconnectPendingNetwork = TRUE;\r
+    WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, NULL);\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // A correct connect token received, terminate the connection process\r
+  //\r
+  Status = WifiMgrCheckRSN(ConfigToken->Token.ConnectNetworkToken->Data->Network->AKMSuite,\r
+             ConfigToken->Token.ConnectNetworkToken->Data->Network->CipherSuite,\r
+             ConfigToken->Nic, &SecurityType, NULL, NULL);\r
+  if (EFI_ERROR(Status)) {\r
+    SecurityType = SECURITY_TYPE_UNKNOWN;\r
+  }\r
+\r
+  SSIdLen   = ConfigToken->Token.ConnectNetworkToken->Data->Network->SSId.SSIdLen;\r
+  AsciiSSId = (CHAR8*) AllocateZeroPool(sizeof (CHAR8) * (SSIdLen + 1));\r
+  if (AsciiSSId == NULL) {\r
+    ConfigToken->Nic->HasDisconnectPendingNetwork = TRUE;\r
+    WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, NULL);\r
+    goto Exit;\r
+  }\r
+\r
+  CopyMem(AsciiSSId, ConfigToken->Token.ConnectNetworkToken->Data->Network->SSId.SSId, SSIdLen);\r
+  *(AsciiSSId + SSIdLen) = '\0';\r
+\r
+  ConnectedProfile = WifiMgrGetProfileByAsciiSSId(AsciiSSId, SecurityType, &ConfigToken->Nic->ProfileList);\r
+  FreePool(AsciiSSId);\r
+  if (ConnectedProfile == NULL) {\r
+    ConfigToken->Nic->HasDisconnectPendingNetwork = TRUE;\r
+    WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, NULL);\r
+    goto Exit;\r
+  }\r
+\r
+  ConfigToken->Nic->ConnectState = WifiMgrConnectedToAp;\r
+  WifiMgrUpdateConnectMessage (ConfigToken->Nic, TRUE, NULL);\r
+\r
+Exit:\r
+\r
+  if (ConfigToken->Nic->ConnectState == WifiMgrDisconnected) {\r
+    ConfigToken->Nic->CurrentOperateNetwork = NULL;\r
+  }\r
+  ConfigToken->Nic->OneTimeConnectRequest = FALSE;\r
+  WifiMgrFreeToken(ConfigToken);\r
+}\r
+\r
+/**\r
+  Start connect operation, and send out a token to connect to a target network.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+  @param[in]  Profile             The target network to be connected.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_ALREADY_STARTED     Already in "connected" state, need to perform a disconnect\r
+                                  operation first.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Errors            Return errors when connecting network on low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrConnectToNetwork (\r
+  IN    WIFI_MGR_DEVICE_DATA              *Nic,\r
+  IN    WIFI_MGR_NETWORK_PROFILE          *Profile\r
+  )\r
+{\r
+  EFI_STATUS                             Status;\r
+  EFI_TPL                                OldTpl;\r
+  EFI_ADAPTER_INFO_MEDIA_STATE           LinkState;\r
+  WIFI_MGR_MAC_CONFIG_TOKEN              *ConfigToken;\r
+  EFI_80211_CONNECT_NETWORK_TOKEN        *ConnectToken;\r
+\r
+  if (Nic == NULL || Nic->Wmp == NULL || Profile == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = WifiMgrGetLinkState (Nic, &LinkState);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  if (LinkState.MediaState == EFI_SUCCESS) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  Status = WifiMgrPrepareConnection (Nic, Profile);\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->RestoreTPL (OldTpl);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Create a new connect token\r
+  //\r
+  ConfigToken = AllocateZeroPool (sizeof (WIFI_MGR_MAC_CONFIG_TOKEN));\r
+  if (ConfigToken == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Exit;\r
+  }\r
+\r
+  ConfigToken->Type      = TokenTypeConnectNetworkToken;\r
+  ConfigToken->Nic       = Nic;\r
+  ConfigToken->Token.ConnectNetworkToken  = AllocateZeroPool (sizeof (EFI_80211_CONNECT_NETWORK_TOKEN));\r
+  if (ConfigToken->Token.ConnectNetworkToken == NULL) {\r
+    goto Exit;\r
+  }\r
+\r
+  ConnectToken           = ConfigToken->Token.ConnectNetworkToken;\r
+  ConnectToken->Data     = AllocateZeroPool (sizeof (EFI_80211_CONNECT_NETWORK_DATA));\r
+  if (ConnectToken->Data == NULL) {\r
+    goto Exit;\r
+  }\r
+\r
+  ConnectToken->Data->Network = AllocateZeroPool (sizeof (EFI_80211_NETWORK));\r
+  if (ConnectToken->Data->Network == NULL) {\r
+    goto Exit;\r
+  }\r
+  CopyMem(ConnectToken->Data->Network, &Profile->Network, sizeof (EFI_80211_NETWORK));\r
+\r
+  //\r
+  // Add event handle and start to connect\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  WifiMgrOnConnectFinished,\r
+                  ConfigToken,\r
+                  &ConnectToken->Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  Nic->ConnectState = WifiMgrConnectingToAp;\r
+  Nic->CurrentOperateNetwork = Profile;\r
+  WifiMgrUpdateConnectMessage (Nic, FALSE, NULL);\r
+\r
+  //\r
+  //Start Connecting ...\r
+  //\r
+  Status = Nic->Wmp->ConnectNetwork (Nic->Wmp, ConnectToken);\r
+\r
+  //\r
+  // Erase secrets after connection is triggered\r
+  //\r
+  WifiMgrCleanProfileSecrets (Profile);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_ALREADY_STARTED) {\r
+      Nic->ConnectState = WifiMgrConnectedToAp;\r
+      WifiMgrUpdateConnectMessage (Nic, TRUE, NULL);\r
+    } else {\r
+\r
+      Nic->ConnectState          = WifiMgrDisconnected;\r
+      Nic->CurrentOperateNetwork = NULL;\r
+\r
+      if (Nic->OneTimeConnectRequest) {\r
+        if (Status == EFI_NOT_FOUND) {\r
+          WifiMgrUpdateConnectMessage (Nic, FALSE, L"Connect Failed: Not Available!");\r
+        } else {\r
+          WifiMgrUpdateConnectMessage (Nic, FALSE, L"Connect Failed: Unexpected Error!");\r
+        }\r
+      }\r
+    }\r
+    goto Exit;\r
+  }\r
+\r
+Exit:\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    WifiMgrFreeToken (ConfigToken);\r
+  }\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] WifiMgrConnectToNetwork: %r\n", Status));\r
+  return Status;\r
+}\r
+\r
+/**\r
+  The callback function for disconnect operation.\r
+\r
+  ASSERT when errors occur in config token.\r
+\r
+  @param[in]  Event                 The Disconnect token receive event.\r
+  @param[in]  Context               The context of the Disconnect token.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WifiMgrOnDisconnectFinished (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  WIFI_MGR_MAC_CONFIG_TOKEN         *ConfigToken;\r
+\r
+  ASSERT (Context != NULL);\r
+\r
+  ConfigToken = (WIFI_MGR_MAC_CONFIG_TOKEN*) Context;\r
+  ASSERT (ConfigToken->Nic != NULL);\r
+  ASSERT (ConfigToken->Type == TokenTypeDisconnectNetworkToken);\r
+\r
+  ASSERT (ConfigToken->Token.DisconnectNetworkToken != NULL);\r
+  if (ConfigToken->Token.DisconnectNetworkToken->Status != EFI_SUCCESS) {\r
+    ConfigToken->Nic->ConnectState          = WifiMgrConnectedToAp;\r
+    WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, NULL);\r
+    ConfigToken->Nic->OneTimeDisconnectRequest = FALSE;\r
+    goto Exit;\r
+  }\r
+\r
+  ConfigToken->Nic->ConnectState          = WifiMgrDisconnected;\r
+  ConfigToken->Nic->CurrentOperateNetwork = NULL;\r
+  WifiMgrUpdateConnectMessage (ConfigToken->Nic, TRUE, NULL);\r
+  ConfigToken->Nic->OneTimeDisconnectRequest = FALSE;\r
+\r
+  //\r
+  // Disconnected network may not be in network list now, trigger a scan again!\r
+  //\r
+  ConfigToken->Nic->OneTimeScanRequest       = TRUE;\r
+\r
+  Exit:\r
+    WifiMgrFreeToken(ConfigToken);\r
+    return;\r
+}\r
+\r
+/**\r
+  Start disconnect operation, and send out a token to disconnect from current connected\r
+  network.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval Other Errors            Return errors when disconnecting a network on low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrDisconnectToNetwork (\r
+  IN    WIFI_MGR_DEVICE_DATA             *Nic\r
+  )\r
+{\r
+  EFI_STATUS                             Status;\r
+  EFI_TPL                                OldTpl;\r
+  WIFI_MGR_MAC_CONFIG_TOKEN              *ConfigToken;\r
+  EFI_80211_DISCONNECT_NETWORK_TOKEN     *DisconnectToken;\r
+\r
+  if (Nic == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl      = gBS->RaiseTPL (TPL_CALLBACK);\r
+  Status      = EFI_SUCCESS;\r
+  ConfigToken = AllocateZeroPool (sizeof (WIFI_MGR_MAC_CONFIG_TOKEN));\r
+  if (ConfigToken == NULL) {\r
+    gBS->RestoreTPL (OldTpl);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  ConfigToken->Type      = TokenTypeDisconnectNetworkToken;\r
+  ConfigToken->Nic       = Nic;\r
+  ConfigToken->Token.DisconnectNetworkToken = AllocateZeroPool (sizeof (EFI_80211_DISCONNECT_NETWORK_TOKEN));\r
+  if (ConfigToken->Token.DisconnectNetworkToken == NULL) {\r
+    WifiMgrFreeToken(ConfigToken);\r
+    gBS->RestoreTPL (OldTpl);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  DisconnectToken = ConfigToken->Token.DisconnectNetworkToken;\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  WifiMgrOnDisconnectFinished,\r
+                  ConfigToken,\r
+                  &DisconnectToken->Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    WifiMgrFreeToken(ConfigToken);\r
+    gBS->RestoreTPL (OldTpl);\r
+    return Status;\r
+  }\r
+\r
+  Nic->ConnectState = WifiMgrDisconnectingToAp;\r
+  WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, NULL);\r
+\r
+  Status = Nic->Wmp->DisconnectNetwork (Nic->Wmp, DisconnectToken);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_NOT_FOUND) {\r
+\r
+      Nic->ConnectState          = WifiMgrDisconnected;\r
+      Nic->CurrentOperateNetwork = NULL;\r
+\r
+      //\r
+      // This network is not in network list now, trigger a scan again!\r
+      //\r
+      Nic->OneTimeScanRequest    = TRUE;\r
+\r
+      //\r
+      // State has been changed from Connected to Disconnected\r
+      //\r
+      WifiMgrUpdateConnectMessage (ConfigToken->Nic, TRUE, NULL);\r
+      Status                     = EFI_SUCCESS;\r
+    } else {\r
+      if (Nic->OneTimeDisconnectRequest) {\r
+\r
+        WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, L"Disconnect Failed: Unexpected Error!");\r
+      }\r
+\r
+      Nic->ConnectState     = WifiMgrConnectedToAp;\r
+      WifiMgrUpdateConnectMessage (ConfigToken->Nic, FALSE, NULL);\r
+    }\r
+    WifiMgrFreeToken(ConfigToken);\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  The state machine of the connection manager, periodically check the state and\r
+  perform a corresponding operation.\r
+\r
+  @param[in]  Event                   The timer event to be triggered.\r
+  @param[in]  Context                 The context of the Nic device data.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WifiMgrOnTimerTick (\r
+  IN EFI_EVENT                        Event,\r
+  IN VOID                             *Context\r
+  )\r
+{\r
+  WIFI_MGR_DEVICE_DATA                *Nic;\r
+  EFI_STATUS                          Status;\r
+  EFI_ADAPTER_INFO_MEDIA_STATE        LinkState;\r
+  WIFI_MGR_NETWORK_PROFILE            *Profile;\r
+\r
+  if (Context == NULL) {\r
+    return;\r
+  }\r
+\r
+  Nic = (WIFI_MGR_DEVICE_DATA*) Context;\r
+  NET_CHECK_SIGNATURE (Nic, WIFI_MGR_DEVICE_DATA_SIGNATURE);\r
+\r
+  Status = WifiMgrGetLinkState (Nic, &LinkState);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Error: Failed to get link state!\n"));\r
+    return;\r
+  }\r
+\r
+  if (Nic->LastLinkState.MediaState != LinkState.MediaState) {\r
+    if (Nic->LastLinkState.MediaState == EFI_SUCCESS && LinkState.MediaState == EFI_NO_MEDIA) {\r
+      Nic->HasDisconnectPendingNetwork = TRUE;\r
+    }\r
+    Nic->LastLinkState.MediaState = LinkState.MediaState;\r
+  }\r
+\r
+  Nic->ScanTickTime ++;\r
+  if ((Nic->ScanTickTime > WIFI_SCAN_FREQUENCY || Nic->OneTimeScanRequest) &&\r
+    Nic->ScanState == WifiMgrScanFinished) {\r
+\r
+    Nic->OneTimeScanRequest = FALSE;\r
+    Nic->ScanTickTime = 0;\r
+\r
+    DEBUG ((DEBUG_INFO, "[WiFi Connection Manager] Scan is triggered.\n"));\r
+    WifiMgrStartScan (Nic);\r
+  }\r
+\r
+  if (Nic->AvailableCount > 0 && Nic->ScanState == WifiMgrScanFinished) {\r
+\r
+    switch (Nic->ConnectState) {\r
+    case WifiMgrDisconnected:\r
+\r
+      if (Nic->HasDisconnectPendingNetwork) {\r
+        Nic->HasDisconnectPendingNetwork = FALSE;\r
+      }\r
+\r
+      if (Nic->ConnectPendingNetwork != NULL) {\r
+\r
+        Profile   = Nic->ConnectPendingNetwork;\r
+        Status    = WifiMgrConnectToNetwork(Nic, Profile);\r
+        Nic->ConnectPendingNetwork = NULL;\r
+        if (EFI_ERROR (Status)) {\r
+          //\r
+          // Some error happened, don't wait for a return connect token!\r
+          //\r
+          Nic->OneTimeConnectRequest = FALSE;\r
+        }\r
+      }\r
+      break;\r
+\r
+    case WifiMgrConnectingToAp:\r
+      break;\r
+\r
+    case WifiMgrDisconnectingToAp:\r
+      break;\r
+\r
+    case WifiMgrConnectedToAp:\r
+\r
+      if (Nic->ConnectPendingNetwork != NULL || Nic->HasDisconnectPendingNetwork) {\r
+\r
+        Status    = WifiMgrDisconnectToNetwork(Nic);\r
+        if (EFI_ERROR (Status)) {\r
+          //\r
+          // Some error happened, don't wait for a return disconnect token!\r
+          //\r
+          Nic->OneTimeDisconnectRequest = FALSE;\r
+        }\r
+      }\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+}\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.h
new file mode 100644 (file)
index 0000000..f742db0
--- /dev/null
@@ -0,0 +1,105 @@
+/** @file\r
+  The Mac Connection2 Protocol adapter functions for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_IMPL__\r
+#define __EFI_WIFI_IMPL__\r
+\r
+/**\r
+  Start scan operation, and send out a token to collect available networks.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_ALREADY_STARTED     A former scan operation is already ongoing.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Errors            Return errors when getting networks from low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrStartScan (\r
+  IN      WIFI_MGR_DEVICE_DATA        *Nic\r
+  );\r
+\r
+/**\r
+  Get current link state from low layer.\r
+\r
+  @param[in]   Nic                Pointer to the device data of the selected NIC.\r
+  @param[out]  LinkState          The pointer to buffer to retrieve link state.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED         Adapter information protocol is not supported.\r
+  @retval Other Errors            Returned errors when retrieving link state from low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrGetLinkState (\r
+  IN    WIFI_MGR_DEVICE_DATA          *Nic,\r
+  OUT   EFI_ADAPTER_INFO_MEDIA_STATE  *LinkState\r
+  );\r
+\r
+/**\r
+  Start connect operation, and send out a token to connect to a target network.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+  @param[in]  Profile             The target network to be connected.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_ALREADY_STARTED     Already in "connected" state, need to perform a disconnect\r
+                                  operation first.\r
+  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Errors            Return errors when connecting network on low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrConnectToNetwork (\r
+  IN    WIFI_MGR_DEVICE_DATA              *Nic,\r
+  IN    WIFI_MGR_NETWORK_PROFILE          *Profile\r
+  );\r
+\r
+/**\r
+  Start disconnect operation, and send out a token to disconnect from current connected\r
+  network.\r
+\r
+  @param[in]  Nic                 Pointer to the device data of the selected NIC.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
+  @retval Other Errors            Return errors when disconnecting a network on low layer.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrDisconnectToNetwork (\r
+  IN    WIFI_MGR_DEVICE_DATA              *Nic\r
+  );\r
+\r
+/**\r
+  The state machine of the connection manager, periodically check the state and\r
+  perform a corresponding operation.\r
+\r
+  @param[in]  Event                   The timer event to be triggered.\r
+  @param[in]  Context                 The context of the Nic device data.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WifiMgrOnTimerTick (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  );\r
+\r
+#endif\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
new file mode 100644 (file)
index 0000000..baac907
--- /dev/null
@@ -0,0 +1,750 @@
+/** @file\r
+  The Miscellaneous Routines for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "WifiConnectionMgrDxe.h"\r
+\r
+/**\r
+  Empty function for event process function.\r
+\r
+  @param Event    The Event need to be process\r
+  @param Context  The context of the event.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WifiMgrInternalEmptyFunction (\r
+  IN  EFI_EVENT    Event,\r
+  IN  VOID         *Context\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+/**\r
+  Convert the mac address into a hexadecimal encoded ":" seperated string.\r
+\r
+  @param[in]  Mac     The mac address.\r
+  @param[in]  StrSize The size, in bytes, of the output buffer specified by Str.\r
+  @param[out] Str     The storage to return the mac string.\r
+\r
+**/\r
+VOID\r
+WifiMgrMacAddrToStr (\r
+  IN  EFI_80211_MAC_ADDRESS  *Mac,\r
+  IN  UINT32                 StrSize,\r
+  OUT CHAR16                 *Str\r
+  )\r
+{\r
+  if (Mac == NULL || Str == NULL) {\r
+    return;\r
+  }\r
+\r
+  UnicodeSPrint (\r
+    Str,\r
+    StrSize,\r
+    L"%02X:%02X:%02X:%02X:%02X:%02X",\r
+    Mac->Addr[0], Mac->Addr[1], Mac->Addr[2],\r
+    Mac->Addr[3], Mac->Addr[4], Mac->Addr[5]\r
+    );\r
+}\r
+\r
+/**\r
+  Read private key file to buffer.\r
+\r
+  @param[in]   FileContext           The file context of private key file.\r
+  @param[out]  PrivateKeyDataAddr    The buffer address to restore private key file, should be\r
+                                     freed by caller.\r
+  @param[out]  PrivateKeyDataSize    The size of read private key file.\r
+\r
+  @retval EFI_SUCCESS                Successfully read the private key file.\r
+  @retval EFI_INVALID_PARAMETER      One or more of the parameters is invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrReadFileToBuffer (\r
+  IN   WIFI_MGR_FILE_CONTEXT          *FileContext,\r
+  OUT  VOID                           **DataAddr,\r
+  OUT  UINTN                          *DataSize\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  if (FileContext != NULL && FileContext->FHandle != NULL) {\r
+\r
+    Status = ReadFileContent (\r
+               FileContext->FHandle,\r
+               DataAddr,\r
+               DataSize,\r
+               0\r
+               );\r
+\r
+    if (FileContext->FHandle != NULL) {\r
+      FileContext->FHandle->Close (FileContext->FHandle);\r
+    }\r
+    FileContext->FHandle = NULL;\r
+    return Status;\r
+  }\r
+\r
+  return EFI_INVALID_PARAMETER;\r
+}\r
+\r
+/**\r
+  Get the Nic data by the NicIndex.\r
+\r
+  @param[in]  Private        The pointer to the global private data structure.\r
+  @param[in]  NicIndex       The index indicates the position of wireless NIC.\r
+\r
+  @return     Pointer to the Nic data, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_DEVICE_DATA *\r
+WifiMgrGetNicByIndex (\r
+  IN WIFI_MGR_PRIVATE_DATA   *Private,\r
+  IN UINT32                  NicIndex\r
+  )\r
+{\r
+  LIST_ENTRY             *Entry;\r
+  WIFI_MGR_DEVICE_DATA   *Nic;\r
+\r
+  if (Private == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  NET_LIST_FOR_EACH (Entry, &Private->NicList) {\r
+    Nic = NET_LIST_USER_STRUCT_S (Entry, WIFI_MGR_DEVICE_DATA,\r
+            Link, WIFI_MGR_DEVICE_DATA_SIGNATURE);\r
+    if (Nic->NicIndex == NicIndex) {\r
+      return Nic;\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Find a network profile through its' SSId and securit type, and the SSId is an unicode string.\r
+\r
+  @param[in]  SSId                   The target network's SSId.\r
+  @param[in]  SecurityType           The target network's security type.\r
+  @param[in]  ProfileList            The profile list on a Nic.\r
+\r
+  @return Pointer to a network profile, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_NETWORK_PROFILE *\r
+WifiMgrGetProfileByUnicodeSSId (\r
+  IN  CHAR16                         *SSId,\r
+  IN  UINT8                          SecurityType,\r
+  IN  LIST_ENTRY                     *ProfileList\r
+  )\r
+{\r
+  LIST_ENTRY                         *Entry;\r
+  WIFI_MGR_NETWORK_PROFILE           *Profile;\r
+\r
+  if (SSId == NULL || ProfileList == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  NET_LIST_FOR_EACH (Entry, ProfileList) {\r
+    Profile = NET_LIST_USER_STRUCT_S (Entry, WIFI_MGR_NETWORK_PROFILE,\r
+                Link, WIFI_MGR_PROFILE_SIGNATURE);\r
+    if (StrCmp (SSId, Profile->SSId) == 0 && SecurityType == Profile->SecurityType) {\r
+      return Profile;\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Find a network profile through its' SSId and securit type, and the SSId is an ascii string.\r
+\r
+  @param[in]  SSId               The target network's SSId.\r
+  @param[in]  SecurityType       The target network's security type.\r
+  @param[in]  ProfileList        The profile list on a Nic.\r
+\r
+  @return Pointer to a network profile, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_NETWORK_PROFILE *\r
+WifiMgrGetProfileByAsciiSSId (\r
+  IN  CHAR8                      *SSId,\r
+  IN  UINT8                      SecurityType,\r
+  IN  LIST_ENTRY                 *ProfileList\r
+  )\r
+{\r
+  CHAR16   SSIdUniCode[SSID_STORAGE_SIZE];\r
+\r
+  if (SSId == NULL) {\r
+    return NULL;\r
+  }\r
+  if (AsciiStrToUnicodeStrS (SSId, SSIdUniCode, SSID_STORAGE_SIZE) != RETURN_SUCCESS) {\r
+    return NULL;\r
+  }\r
+\r
+  return WifiMgrGetProfileByUnicodeSSId (SSIdUniCode, SecurityType, ProfileList);\r
+}\r
+\r
+/**\r
+  Find a network profile through its' profile index.\r
+\r
+  @param[in]  ProfileIndex           The target network's profile index.\r
+  @param[in]  ProfileList            The profile list on a Nic.\r
+\r
+  @return Pointer to a network profile, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_NETWORK_PROFILE *\r
+WifiMgrGetProfileByProfileIndex (\r
+  IN  UINT32                         ProfileIndex,\r
+  IN  LIST_ENTRY                     *ProfileList\r
+  )\r
+{\r
+  WIFI_MGR_NETWORK_PROFILE           *Profile;\r
+  LIST_ENTRY                         *Entry;\r
+\r
+  if (ProfileList == NULL) {\r
+    return NULL;\r
+  }\r
+  NET_LIST_FOR_EACH (Entry, ProfileList) {\r
+    Profile = NET_LIST_USER_STRUCT_S (Entry, WIFI_MGR_NETWORK_PROFILE,\r
+                Link, WIFI_MGR_PROFILE_SIGNATURE);\r
+    if (Profile->ProfileIndex == ProfileIndex) {\r
+      return Profile;\r
+    }\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  To test if the AKMSuite is in supported AKMSuite list.\r
+\r
+  @param[in]  SupportedAKMSuiteCount       The count of the supported AKMSuites.\r
+  @param[in]  SupportedAKMSuiteList        The supported AKMSuite list.\r
+  @param[in]  AKMSuite                     The AKMSuite to be tested.\r
+\r
+  @return True if this AKMSuite is supported, or False if not.\r
+\r
+**/\r
+BOOLEAN\r
+WifiMgrSupportAKMSuite (\r
+  IN  UINT16                               SupportedAKMSuiteCount,\r
+  IN  UINT32                               *SupportedAKMSuiteList,\r
+  IN  UINT32                               *AKMSuite\r
+  )\r
+{\r
+  UINT16    Index;\r
+\r
+  if (AKMSuite == NULL || SupportedAKMSuiteList == NULL ||\r
+    SupportedAKMSuiteCount == 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  for (Index = 0; Index < SupportedAKMSuiteCount; Index ++) {\r
+    if (SupportedAKMSuiteList[Index] == *AKMSuite) {\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  To check if the CipherSuite is in supported CipherSuite list.\r
+\r
+  @param[in]  SupportedCipherSuiteCount       The count of the supported CipherSuites.\r
+  @param[in]  SupportedCipherSuiteList        The supported CipherSuite list.\r
+  @param[in]  CipherSuite                     The CipherSuite to be tested.\r
+\r
+  @return True if this CipherSuite is supported, or False if not.\r
+\r
+**/\r
+BOOLEAN\r
+WifiMgrSupportCipherSuite (\r
+  IN  UINT16                                  SupportedCipherSuiteCount,\r
+  IN  UINT32                                  *SupportedCipherSuiteList,\r
+  IN  UINT32                                  *CipherSuite\r
+  )\r
+{\r
+  UINT16  Index;\r
+\r
+  if (CipherSuite == NULL || SupportedCipherSuiteCount == 0 ||\r
+    SupportedCipherSuiteList == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  for (Index = 0; Index < SupportedCipherSuiteCount; Index ++) {\r
+    if (SupportedCipherSuiteList[Index] == *CipherSuite) {\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Check an AKM suite list and a Cipher suite list to see if one or more AKM suites or Cipher suites\r
+  are supported and find the matchable security type.\r
+\r
+  @param[in]   AKMList                     The target AKM suite list to be checked.\r
+  @param[in]   CipherList                  The target Cipher suite list to be checked\r
+  @param[in]   Nic                         The Nic to operate, contains the supported AKMSuite list\r
+                                           and supported CipherSuite list\r
+  @param[out]  SecurityType                To identify a security type from the AKM suite list and\r
+                                           Cipher suite list\r
+  @param[out]  AKMSuiteSupported           To identify if this security type is supported. If it is\r
+                                           NULL, overcome this field\r
+  @param[out]  CipherSuiteSupported        To identify if this security type is supported. If it is\r
+                                           NULL, overcome this field\r
+\r
+  @retval EFI_SUCCESS                      This operation has completed successfully.\r
+  @retval EFI_INVALID_PARAMETER            No Nic found or the suite list is null.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrCheckRSN (\r
+  IN    EFI_80211_AKM_SUITE_SELECTOR       *AKMList,\r
+  IN    EFI_80211_CIPHER_SUITE_SELECTOR    *CipherList,\r
+  IN    WIFI_MGR_DEVICE_DATA               *Nic,\r
+  OUT   UINT8                              *SecurityType,\r
+  OUT   BOOLEAN                            *AKMSuiteSupported,\r
+  OUT   BOOLEAN                            *CipherSuiteSupported\r
+  )\r
+{\r
+  EFI_80211_AKM_SUITE_SELECTOR             *SupportedAKMSuites;\r
+  EFI_80211_CIPHER_SUITE_SELECTOR          *SupportedSwCipherSuites;\r
+  EFI_80211_CIPHER_SUITE_SELECTOR          *SupportedHwCipherSuites;\r
+  EFI_80211_SUITE_SELECTOR                 *AKMSuite;\r
+  EFI_80211_SUITE_SELECTOR                 *CipherSuite;\r
+  UINT16                                   AKMIndex;\r
+  UINT16                                   CipherIndex;\r
+\r
+  if (Nic == NULL || AKMList == NULL || CipherList == NULL|| SecurityType == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SupportedAKMSuites      = Nic->SupportedSuites.SupportedAKMSuites;\r
+  SupportedSwCipherSuites = Nic->SupportedSuites.SupportedSwCipherSuites;\r
+  SupportedHwCipherSuites = Nic->SupportedSuites.SupportedHwCipherSuites;\r
+\r
+  *SecurityType = SECURITY_TYPE_UNKNOWN;\r
+  if (AKMSuiteSupported != NULL && CipherSuiteSupported != NULL) {\r
+    *AKMSuiteSupported    = FALSE;\r
+    *CipherSuiteSupported = FALSE;\r
+  }\r
+\r
+  if (AKMList->AKMSuiteCount == 0) {\r
+    if (CipherList->CipherSuiteCount == 0) {\r
+      *SecurityType = SECURITY_TYPE_NONE;\r
+      if (AKMSuiteSupported != NULL && CipherSuiteSupported != NULL) {\r
+        *AKMSuiteSupported    = TRUE;\r
+        *CipherSuiteSupported = TRUE;\r
+      }\r
+    }\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  for (AKMIndex = 0; AKMIndex < AKMList->AKMSuiteCount; AKMIndex ++) {\r
+\r
+    AKMSuite = AKMList->AKMSuiteList + AKMIndex;\r
+    if (WifiMgrSupportAKMSuite(SupportedAKMSuites->AKMSuiteCount,\r
+      (UINT32*) SupportedAKMSuites->AKMSuiteList, (UINT32*) AKMSuite)) {\r
+\r
+      if (AKMSuiteSupported != NULL && CipherSuiteSupported != NULL) {\r
+        *AKMSuiteSupported = TRUE;\r
+      }\r
+      for (CipherIndex = 0; CipherIndex < CipherList->CipherSuiteCount; CipherIndex ++) {\r
+\r
+        CipherSuite = CipherList->CipherSuiteList + CipherIndex;\r
+\r
+        if (SupportedSwCipherSuites != NULL) {\r
+\r
+          if (WifiMgrSupportCipherSuite(SupportedSwCipherSuites->CipherSuiteCount,\r
+            (UINT32*) SupportedSwCipherSuites->CipherSuiteList, (UINT32*) CipherSuite)) {\r
+\r
+            *SecurityType = WifiMgrGetSecurityType ((UINT32*) AKMSuite, (UINT32*) CipherSuite);\r
+\r
+            if (*SecurityType != SECURITY_TYPE_UNKNOWN) {\r
+\r
+              if (AKMSuiteSupported != NULL && CipherSuiteSupported != NULL) {\r
+                *CipherSuiteSupported = TRUE;\r
+              }\r
+              return EFI_SUCCESS;\r
+            }\r
+          }\r
+        }\r
+\r
+        if (SupportedHwCipherSuites != NULL) {\r
+\r
+          if (WifiMgrSupportCipherSuite(SupportedHwCipherSuites->CipherSuiteCount,\r
+            (UINT32*) SupportedHwCipherSuites->CipherSuiteList, (UINT32*) CipherSuite)) {\r
+\r
+            *SecurityType = WifiMgrGetSecurityType ((UINT32*) AKMSuite, (UINT32*) CipherSuite);\r
+\r
+            if (*SecurityType != SECURITY_TYPE_UNKNOWN) {\r
+\r
+              if (AKMSuiteSupported != NULL && CipherSuiteSupported != NULL) {\r
+                *CipherSuiteSupported = TRUE;\r
+              }\r
+              return EFI_SUCCESS;\r
+            }\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  *SecurityType = WifiMgrGetSecurityType ((UINT32*) AKMList->AKMSuiteList,\r
+                    (UINT32*) CipherList->CipherSuiteList);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Get the security type for a certain AKMSuite and CipherSuite.\r
+\r
+  @param[in]   AKMSuite             An certain AKMSuite.\r
+  @param[in]   CipherSuite          An certain CipherSuite.\r
+\r
+  @return a security type if found, or SECURITY_TYPE_UNKNOWN.\r
+\r
+**/\r
+UINT8\r
+WifiMgrGetSecurityType (\r
+  IN  UINT32    *AKMSuite,\r
+  IN  UINT32    *CipherSuite\r
+  )\r
+{\r
+  if (CipherSuite == NULL) {\r
+\r
+    if (AKMSuite == NULL) {\r
+      return SECURITY_TYPE_NONE;\r
+    } else {\r
+      return SECURITY_TYPE_UNKNOWN;\r
+    }\r
+  } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_USE_GROUP) {\r
+\r
+    if (AKMSuite == NULL) {\r
+      return SECURITY_TYPE_NONE;\r
+    } else {\r
+      return SECURITY_TYPE_UNKNOWN;\r
+    }\r
+  } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_WEP40 ||\r
+    *CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_WEP104) {\r
+\r
+    return SECURITY_TYPE_WEP;\r
+  } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_CCMP) {\r
+\r
+    if (AKMSuite == NULL) {\r
+      return SECURITY_TYPE_UNKNOWN;\r
+    }\r
+\r
+    if (*AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA ||\r
+      *AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA_SHA256) {\r
+\r
+      return SECURITY_TYPE_WPA2_ENTERPRISE;\r
+    } else if (*AKMSuite == IEEE_80211_AKM_SUITE_PSK ||\r
+        *AKMSuite == IEEE_80211_AKM_SUITE_PSK_SHA256){\r
+\r
+      return SECURITY_TYPE_WPA2_PERSONAL;\r
+    }else {\r
+      return SECURITY_TYPE_UNKNOWN;\r
+    }\r
+  } else if (*CipherSuite == IEEE_80211_PAIRWISE_CIPHER_SUITE_TKIP) {\r
+\r
+    if (AKMSuite == NULL) {\r
+      return SECURITY_TYPE_UNKNOWN;\r
+    }\r
+\r
+    if (*AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA ||\r
+      *AKMSuite == IEEE_80211_AKM_SUITE_8021X_OR_PMKSA_SHA256) {\r
+\r
+      return SECURITY_TYPE_WPA_ENTERPRISE;\r
+    } else if (*AKMSuite == IEEE_80211_AKM_SUITE_PSK ||\r
+        *AKMSuite == IEEE_80211_AKM_SUITE_PSK_SHA256){\r
+\r
+      return SECURITY_TYPE_WPA_PERSONAL;\r
+    }else {\r
+      return SECURITY_TYPE_UNKNOWN;\r
+    }\r
+  } else {\r
+    return SECURITY_TYPE_UNKNOWN;\r
+  }\r
+}\r
+\r
+/**\r
+  Get supported AKMSuites and CipherSuites from supplicant for a Nic.\r
+\r
+  @param[in]   Nic                      The Nic to operate.\r
+\r
+  @retval EFI_SUCCESS                   Get the supported suite list successfully.\r
+  @retval EFI_INVALID_PARAMETER         No Nic found or supplicant is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrGetSupportedSuites (\r
+  IN    WIFI_MGR_DEVICE_DATA            *Nic\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  EFI_SUPPLICANT_PROTOCOL               *Supplicant;\r
+  EFI_80211_AKM_SUITE_SELECTOR          *SupportedAKMSuites;\r
+  EFI_80211_CIPHER_SUITE_SELECTOR       *SupportedSwCipherSuites;\r
+  EFI_80211_CIPHER_SUITE_SELECTOR       *SupportedHwCipherSuites;\r
+  UINTN                                 DataSize;\r
+\r
+  SupportedAKMSuites      = NULL;\r
+  SupportedSwCipherSuites = NULL;\r
+  SupportedHwCipherSuites = NULL;\r
+\r
+  if (Nic == NULL || Nic->Supplicant == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Supplicant = Nic->Supplicant;\r
+\r
+  DataSize  = 0;\r
+  Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedAKMSuites, NULL, &DataSize);\r
+  if (Status == EFI_BUFFER_TOO_SMALL && DataSize > 0) {\r
+\r
+    SupportedAKMSuites = AllocateZeroPool(DataSize);\r
+    if (SupportedAKMSuites == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedAKMSuites,\r
+                           (UINT8 *) SupportedAKMSuites, &DataSize);\r
+    if (!EFI_ERROR (Status)) {\r
+      Nic->SupportedSuites.SupportedAKMSuites = SupportedAKMSuites;\r
+    } else {\r
+      FreePool (SupportedAKMSuites);\r
+    }\r
+  } else {\r
+    SupportedAKMSuites = NULL;\r
+  }\r
+\r
+  DataSize  = 0;\r
+  Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedSoftwareCipherSuites, NULL, &DataSize);\r
+  if (Status == EFI_BUFFER_TOO_SMALL && DataSize > 0) {\r
+\r
+\r
+    SupportedSwCipherSuites = AllocateZeroPool(DataSize);\r
+    if (SupportedSwCipherSuites == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedSoftwareCipherSuites,\r
+                           (UINT8 *) SupportedSwCipherSuites, &DataSize);\r
+    if (!EFI_ERROR (Status)) {\r
+      Nic->SupportedSuites.SupportedSwCipherSuites = SupportedSwCipherSuites;\r
+    } else {\r
+      FreePool (SupportedSwCipherSuites);\r
+    }\r
+  } else {\r
+    SupportedSwCipherSuites = NULL;\r
+  }\r
+\r
+  DataSize  = 0;\r
+  Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedHardwareCipherSuites, NULL, &DataSize);\r
+  if (Status == EFI_BUFFER_TOO_SMALL && DataSize > 0) {\r
+\r
+    SupportedHwCipherSuites = AllocateZeroPool(DataSize);\r
+    if (SupportedHwCipherSuites == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Status = Supplicant->GetData (Supplicant, EfiSupplicant80211SupportedHardwareCipherSuites,\r
+                           (UINT8 *) SupportedHwCipherSuites, &DataSize);\r
+    if (!EFI_ERROR (Status)) {\r
+      Nic->SupportedSuites.SupportedHwCipherSuites = SupportedHwCipherSuites;\r
+    } else {\r
+      FreePool (SupportedHwCipherSuites);\r
+    }\r
+  } else {\r
+    SupportedHwCipherSuites = NULL;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Clean secrets from a network profile.\r
+\r
+  @param[in]   Profile               The profile to be cleanned.\r
+\r
+**/\r
+VOID\r
+WifiMgrCleanProfileSecrets (\r
+  IN  WIFI_MGR_NETWORK_PROFILE       *Profile\r
+  )\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
+  if (Profile->CACertData != NULL) {\r
+\r
+    ZeroMem (Profile->CACertData, Profile->CACertSize);\r
+    FreePool (Profile->CACertData);\r
+  }\r
+  Profile->CACertData = NULL;\r
+  Profile->CACertSize = 0;\r
+\r
+  if (Profile->ClientCertData != NULL) {\r
+\r
+    ZeroMem (Profile->ClientCertData, Profile->ClientCertSize);\r
+    FreePool (Profile->ClientCertData);\r
+  }\r
+  Profile->ClientCertData = NULL;\r
+  Profile->ClientCertSize = 0;\r
+\r
+  if (Profile->PrivateKeyData != NULL) {\r
+\r
+    ZeroMem (Profile->PrivateKeyData, Profile->PrivateKeyDataSize);\r
+    FreePool (Profile->PrivateKeyData);\r
+  }\r
+  Profile->PrivateKeyData     = NULL;\r
+  Profile->PrivateKeyDataSize = 0;\r
+}\r
+\r
+/**\r
+  Free all network profiles in a profile list.\r
+\r
+  @param[in]   ProfileList           The profile list to be freed.\r
+\r
+**/\r
+VOID\r
+WifiMgrFreeProfileList (\r
+  IN  LIST_ENTRY                     *ProfileList\r
+  )\r
+{\r
+  WIFI_MGR_NETWORK_PROFILE           *Profile;\r
+  LIST_ENTRY                         *Entry;\r
+  LIST_ENTRY                         *NextEntry;\r
+\r
+  if (ProfileList == NULL) {\r
+    return;\r
+  }\r
+\r
+  NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, ProfileList) {\r
+\r
+    Profile = NET_LIST_USER_STRUCT_S (Entry, WIFI_MGR_NETWORK_PROFILE,\r
+                Link, WIFI_MGR_PROFILE_SIGNATURE);\r
+\r
+    WifiMgrCleanProfileSecrets (Profile);\r
+\r
+    if (Profile->Network.AKMSuite != NULL) {\r
+      FreePool(Profile->Network.AKMSuite);\r
+    }\r
+\r
+    if (Profile->Network.CipherSuite != NULL) {\r
+      FreePool(Profile->Network.CipherSuite);\r
+    }\r
+\r
+    FreePool (Profile);\r
+  }\r
+}\r
+\r
+/**\r
+  Free user configured hidden network list.\r
+\r
+  @param[in]   HiddenList           The hidden network list to be freed.\r
+\r
+**/\r
+VOID\r
+WifiMgrFreeHiddenList (\r
+  IN  LIST_ENTRY                     *HiddenList\r
+  )\r
+{\r
+  WIFI_HIDDEN_NETWORK_DATA           *HiddenNetwork;\r
+  LIST_ENTRY                         *Entry;\r
+  LIST_ENTRY                         *NextEntry;\r
+\r
+  if (HiddenList == NULL) {\r
+    return;\r
+  }\r
+\r
+  NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, HiddenList) {\r
+\r
+    HiddenNetwork = NET_LIST_USER_STRUCT_S (Entry, WIFI_HIDDEN_NETWORK_DATA,\r
+                      Link, WIFI_MGR_HIDDEN_NETWORK_SIGNATURE);\r
+    FreePool (HiddenNetwork);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  Free the resources of a config token.\r
+\r
+  @param[in]   ConfigToken          The config token to be freed.\r
+**/\r
+VOID\r
+WifiMgrFreeToken (\r
+  IN   WIFI_MGR_MAC_CONFIG_TOKEN    *ConfigToken\r
+  )\r
+{\r
+  EFI_80211_GET_NETWORKS_RESULT     *Result;\r
+\r
+  if (ConfigToken == NULL) {\r
+    return;\r
+  }\r
+\r
+  switch (ConfigToken->Type) {\r
+\r
+    case TokenTypeGetNetworksToken:\r
+\r
+      if (ConfigToken->Token.GetNetworksToken != NULL) {\r
+\r
+        gBS->CloseEvent (ConfigToken->Token.GetNetworksToken->Event);\r
+        if (ConfigToken->Token.GetNetworksToken->Data != NULL) {\r
+          FreePool(ConfigToken->Token.GetNetworksToken->Data);\r
+        }\r
+\r
+        Result = ConfigToken->Token.GetNetworksToken->Result;\r
+        if (Result != NULL) {\r
+          FreePool (Result);\r
+        }\r
+\r
+        FreePool(ConfigToken->Token.GetNetworksToken);\r
+      }\r
+\r
+      FreePool (ConfigToken);\r
+      break;\r
+\r
+    case TokenTypeConnectNetworkToken:\r
+\r
+      if (ConfigToken->Token.ConnectNetworkToken != NULL) {\r
+\r
+        gBS->CloseEvent (ConfigToken->Token.ConnectNetworkToken->Event);\r
+        if (ConfigToken->Token.ConnectNetworkToken->Data != NULL) {\r
+          FreePool(ConfigToken->Token.ConnectNetworkToken->Data);\r
+        }\r
+        FreePool(ConfigToken->Token.ConnectNetworkToken);\r
+      }\r
+      FreePool (ConfigToken);\r
+      break;\r
+\r
+    case TokenTypeDisconnectNetworkToken:\r
+\r
+      if (ConfigToken->Token.DisconnectNetworkToken != NULL) {\r
+\r
+        FreePool(ConfigToken->Token.DisconnectNetworkToken);\r
+      }\r
+\r
+      FreePool (ConfigToken);\r
+      break;\r
+\r
+    default :\r
+      break;\r
+  }\r
+}\r
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.h
new file mode 100644 (file)
index 0000000..6c88068
--- /dev/null
@@ -0,0 +1,268 @@
+/** @file\r
+  The Miscellaneous Routines for WiFi Connection Manager.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_WIFI_MGR_MISC_H__\r
+#define __EFI_WIFI_MGR_MISC_H__\r
+\r
+/**\r
+  Empty function for event process function.\r
+\r
+  @param[in] Event    The Event needs to be processed\r
+  @param[in] Context  The context of the event\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WifiMgrInternalEmptyFunction (\r
+  IN  EFI_EVENT   Event,\r
+  IN  VOID        *Context\r
+  );\r
+\r
+/**\r
+  Convert the mac address into a hexadecimal encoded ":" seperated string.\r
+\r
+  @param[in]  Mac     The mac address\r
+  @param[in]  StrSize The size, in bytes, of the output buffer specified by Str\r
+  @param[out] Str     The storage to return the mac string\r
+\r
+**/\r
+VOID\r
+WifiMgrMacAddrToStr (\r
+  IN  EFI_80211_MAC_ADDRESS     *Mac,\r
+  IN  UINT32                    StrSize,\r
+  OUT CHAR16                    *Str\r
+  );\r
+\r
+/**\r
+  Read private key file to buffer.\r
+\r
+  @param[in]   FileContext           The file context of private key file.\r
+  @param[out]  PrivateKeyDataAddr    The buffer address to restore private key file, should be\r
+                                     freed by caller.\r
+  @param[out]  PrivateKeyDataSize    The size of read private key file.\r
+\r
+  @retval EFI_SUCCESS                Successfully read the private key file.\r
+  @retval EFI_INVALID_PARAMETER      One or more of the parameters is invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrReadFileToBuffer (\r
+  IN   WIFI_MGR_FILE_CONTEXT          *FileContext,\r
+  OUT  VOID                           **PrivateKeyDataAddr,\r
+  OUT  UINTN                          *PrivateKeyDataSize\r
+  );\r
+\r
+\r
+/**\r
+  Get the Nic data by the NicIndex.\r
+\r
+  @param[in]  Private        The pointer to the global private data structure.\r
+  @param[in]  NicIndex       The index indicates the position of wireless NIC.\r
+\r
+  @return     Pointer to the Nic data, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_DEVICE_DATA *\r
+WifiMgrGetNicByIndex (\r
+  IN WIFI_MGR_PRIVATE_DATA      *Private,\r
+  IN UINT32                     NicIndex\r
+  );\r
+\r
+/**\r
+  Find a network profile through its' SSId and securit type, and the SSId is an unicode string.\r
+\r
+  @param[in]  SSId                   The target network's SSId.\r
+  @param[in]  SecurityType           The target network's security type.\r
+  @param[in]  ProfileList            The profile list on a Nic.\r
+\r
+  @return Pointer to a network profile, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_NETWORK_PROFILE *\r
+WifiMgrGetProfileByUnicodeSSId (\r
+  IN  CHAR16                         *SSId,\r
+  IN  UINT8                          SecurityType,\r
+  IN  LIST_ENTRY                     *ProfileList\r
+  );\r
+\r
+/**\r
+  Find a network profile through its' SSId and securit type, and the SSId is an ascii string.\r
+\r
+  @param[in]  SSId                   The target network's SSId.\r
+  @param[in]  SecurityType           The target network's security type.\r
+  @param[in]  ProfileList            The profile list on a Nic.\r
+\r
+  @return Pointer to a network profile, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_NETWORK_PROFILE *\r
+WifiMgrGetProfileByAsciiSSId (\r
+  IN  CHAR8                          *SSId,\r
+  IN  UINT8                          SecurityType,\r
+  IN  LIST_ENTRY                     *ProfileList\r
+  );\r
+\r
+/**\r
+  Find a network profile through its' profile index.\r
+\r
+  @param[in]  ProfileIndex           The target network's profile index.\r
+  @param[in]  ProfileList            The profile list on a Nic.\r
+\r
+  @return Pointer to a network profile, or NULL if not found.\r
+\r
+**/\r
+WIFI_MGR_NETWORK_PROFILE *\r
+WifiMgrGetProfileByProfileIndex (\r
+  IN UINT32                     ProfileIndex,\r
+  IN LIST_ENTRY                 *ProfileList\r
+  );\r
+\r
+/**\r
+  To test if the AKMSuite is in supported AKMSuite list.\r
+\r
+  @param[in]  SupportedAKMSuiteCount      The count of the supported AKMSuites.\r
+  @param[in]  SupportedAKMSuiteList       The supported AKMSuite list.\r
+  @param[in]  AKMSuite                    The AKMSuite to be tested.\r
+\r
+  @return True if this AKMSuite is supported, or False if not.\r
+\r
+**/\r
+BOOLEAN\r
+WifiMgrSupportAKMSuite (\r
+  IN  UINT16                              SupportedAKMSuiteCount,\r
+  IN  UINT32                              *SupportedAKMSuiteList,\r
+  IN  UINT32                              *AKMSuite\r
+  );\r
+\r
+/**\r
+  To check if the CipherSuite is in supported CipherSuite list.\r
+\r
+  @param[in]  SupportedCipherSuiteCount   The count of the supported CipherSuites.\r
+  @param[in]  SupportedCipherSuiteList    The supported CipherSuite list.\r
+  @param[in]  CipherSuite                 The CipherSuite to be tested.\r
+\r
+  @return True if this CipherSuite is supported, or False if not.\r
+\r
+**/\r
+BOOLEAN\r
+WifiMgrSupportCipherSuite (\r
+  IN  UINT16                              SupportedCipherSuiteCount,\r
+  IN  UINT32                              *SupportedCipherSuiteList,\r
+  IN  UINT32                              *CipherSuite\r
+  );\r
+\r
+/**\r
+  Check an AKM suite list and a Cipher suite list to see if one or more AKM suites or Cipher suites\r
+  are supported and find the matchable security type.\r
+\r
+  @param[in]   AKMList                     The target AKM suite list to be checked.\r
+  @param[in]   CipherList                  The target Cipher suite list to be checked\r
+  @param[in]   Nic                         The Nic to operate, contains the supported AKMSuite list\r
+                                           and supported CipherSuite list\r
+  @param[out]  SecurityType                To identify a security type from the AKM suite list and\r
+                                           Cipher suite list\r
+  @param[out]  AKMSuiteSupported           To identify if this security type is supported. If it is\r
+                                           NULL, overcome this field\r
+  @param[out]  CipherSuiteSupported        To identify if this security type is supported. If it is\r
+                                           NULL, overcome this field\r
+\r
+  @retval EFI_SUCCESS                      This operation has completed successfully.\r
+  @retval EFI_INVALID_PARAMETER            No Nic found or the suite list is null.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrCheckRSN (\r
+  IN    EFI_80211_AKM_SUITE_SELECTOR      *AKMList,\r
+  IN    EFI_80211_CIPHER_SUITE_SELECTOR   *CipherList,\r
+  IN    WIFI_MGR_DEVICE_DATA              *Nic,\r
+  OUT   UINT8                             *SecurityType,\r
+  OUT   BOOLEAN                           *AKMSuiteSupported,\r
+  OUT   BOOLEAN                           *CipherSuiteSupported\r
+  );\r
+\r
+/**\r
+  To get the security type for a certain AKMSuite and CipherSuite.\r
+\r
+  @param[in]   AKMSuite             An certain AKMSuite.\r
+  @param[in]   CipherSuite          An certain CipherSuite.\r
+\r
+  @return a security type if found, or SECURITY_TYPE_UNKNOWN.\r
+\r
+**/\r
+UINT8\r
+WifiMgrGetSecurityType (\r
+  IN    UINT32                          *AKMSuite,\r
+  IN    UINT32                          *CipherSuite\r
+  );\r
+\r
+/**\r
+  Get supported AKMSuites and CipherSuites from supplicant.\r
+\r
+  @param[in]   Nic                      The Nic to operate.\r
+\r
+  @retval EFI_SUCCESS                   Get the supported suite list successfully.\r
+  @retval EFI_INVALID_PARAMETER         No Nic found or supplicant is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+WifiMgrGetSupportedSuites (\r
+  IN    WIFI_MGR_DEVICE_DATA            *Nic\r
+  );\r
+\r
+/**\r
+  Clean secrets from a network profile.\r
+\r
+  @param[in]   Profile               The profile to be cleanned.\r
+\r
+**/\r
+VOID\r
+WifiMgrCleanProfileSecrets (\r
+  IN  WIFI_MGR_NETWORK_PROFILE       *Profile\r
+  );\r
+\r
+/**\r
+  Free all network profiles in a profile list.\r
+\r
+  @param[in]   ProfileList           The profile list to be freed.\r
+\r
+**/\r
+VOID\r
+WifiMgrFreeProfileList (\r
+  IN  LIST_ENTRY               *ProfileList\r
+  );\r
+\r
+/**\r
+  Free user configured hidden network list.\r
+\r
+  @param[in]   HiddenList           The hidden network list to be freed.\r
+\r
+**/\r
+VOID\r
+WifiMgrFreeHiddenList (\r
+  IN  LIST_ENTRY                     *HiddenList\r
+  );\r
+\r
+/**\r
+  Free the resources of a config token.\r
+\r
+  @param[in]   ConfigToken          The config token to be freed.\r
+\r
+**/\r
+VOID\r
+WifiMgrFreeToken (\r
+  IN   WIFI_MGR_MAC_CONFIG_TOKEN        *ConfigToken\r
+  );\r
+\r
+#endif\r