[edk2-devel] [edk2-staging/HttpProxy PATCH v3 7/7] NetworkPkg/HttpBootDxe: Add Proxy URI input in setup menu

Saloni Kasbekar saloni.kasbekar at intel.com
Fri Dec 2 19:12:26 UTC 2022


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

Allows users to input the Proxy Server URI in the
HTTP setup menu

Cc: Maciej Rabeda <maciej.rabeda at linux.intel.com>
Cc: Wu Jiaxin <jiaxin.wu at intel.com>
Cc: Siyuan Fu <siyuan.fu at intel.com>
Signed-off-by: Saloni Kasbekar <saloni.kasbekar at intel.com>
---
 NetworkPkg/HttpBootDxe/HttpBootConfig.c       | 99 ++++++++++++++-----
 .../HttpBootDxe/HttpBootConfigNVDataStruc.h   |  4 +-
 .../HttpBootDxe/HttpBootConfigStrings.uni     |  2 +
 NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr  |  9 ++
 4 files changed, 88 insertions(+), 26 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfig.c b/NetworkPkg/HttpBootDxe/HttpBootConfig.c
index 42d3fdc1fb..2cdd5043fe 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootConfig.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootConfig.c
@@ -18,6 +18,7 @@ CHAR16  mHttpBootConfigStorageName[] = L"HTTP_BOOT_CONFIG_IFR_NVDATA";
   @param[in]  UsingIpv6           Set to TRUE if creating boot option for IPv6.
   @param[in]  Description         The description text of the boot option.
   @param[in]  Uri                 The URI string of the boot file.
+  @param[in]  ProxyUri            The Proxy URI string for the boot path.
 
   @retval EFI_SUCCESS             The boot option is created successfully.
   @retval Others                  Failed to create new boot option.
@@ -28,48 +29,59 @@ HttpBootAddBootOption (
   IN   HTTP_BOOT_PRIVATE_DATA  *Private,
   IN   BOOLEAN                 UsingIpv6,
   IN   CHAR16                  *Description,
-  IN   CHAR16                  *Uri
+  IN   CHAR16                  *Uri,
+  IN   CHAR16                  *ProxyUri
   )
 {
   EFI_DEV_PATH                  *Node;
   EFI_DEVICE_PATH_PROTOCOL      *TmpDevicePath;
   EFI_DEVICE_PATH_PROTOCOL      *NewDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL      *FinalDevicePath;
   UINTN                         Length;
   CHAR8                         AsciiUri[URI_STR_MAX_SIZE];
+  CHAR8                         AsciiProxyUri[URI_STR_MAX_SIZE];
+  UINTN                         AsciiProxyUriSize;
   EFI_STATUS                    Status;
-  UINTN                         Index;
   EFI_BOOT_MANAGER_LOAD_OPTION  NewOption;
 
-  NewDevicePath = NULL;
-  Node          = NULL;
-  TmpDevicePath = NULL;
+  NewDevicePath   = NULL;
+  Node            = NULL;
+  TmpDevicePath   = NULL;
+  FinalDevicePath = NULL;
 
   if (StrLen (Description) == 0) {
     return EFI_INVALID_PARAMETER;
   }
 
   //
-  // Convert the scheme to all lower case.
+  // Check the URI Scheme
   //
-  for (Index = 0; Index < StrLen (Uri); Index++) {
-    if (Uri[Index] == L':') {
-      break;
+  UnicodeStrToAsciiStrS (Uri, AsciiUri, sizeof (AsciiUri));
+  UnicodeStrToAsciiStrS (ProxyUri, AsciiProxyUri, sizeof (AsciiProxyUri));
+  Status = HttpBootCheckUriScheme (AsciiUri);
+  if (EFI_ERROR (Status)) {
+    if (Status == EFI_INVALID_PARAMETER) {
+      DEBUG ((DEBUG_ERROR, "Error: Invalid URI address.\n"));
+    } else if (Status == EFI_ACCESS_DENIED) {
+      DEBUG ((DEBUG_ERROR, "Error: Access forbidden, only HTTPS connection is allowed.\n"));
     }
 
-    if ((Uri[Index] >= L'A') && (Uri[Index] <= L'Z')) {
-      Uri[Index] -= (CHAR16)(L'A' - L'a');
-    }
+    return Status;
   }
 
-  //
-  // Only accept empty URI, or http and https URI.
-  //
-  if ((StrLen (Uri) != 0) && (StrnCmp (Uri, L"http://", 7) != 0) && (StrnCmp (Uri, L"https://", 8) != 0)) {
-    return EFI_INVALID_PARAMETER;
+  Status = HttpBootCheckUriScheme (AsciiProxyUri);
+  if (EFI_ERROR (Status)) {
+    if (Status == EFI_INVALID_PARAMETER) {
+      DEBUG ((DEBUG_ERROR, "Error: Invalid URI address.\n"));
+    } else if (Status == EFI_ACCESS_DENIED) {
+      DEBUG ((DEBUG_ERROR, "Error: Access forbidden, only HTTPS connection is allowed.\n"));
+    }
+
+    return Status;
   }
 
   //
-  // Create a new device path by appending the IP node and URI node to
+  // Create a new device path by appending the IP node, Proxy node and URI node to
   // the driver's parent device path
   //
   if (!UsingIpv6) {
@@ -100,15 +112,43 @@ HttpBootAddBootOption (
     return EFI_OUT_OF_RESOURCES;
   }
 
+  //
+  // Update the Proxy node with the input Proxy URI
+  //
+  if (StrLen (ProxyUri) != 0) {
+    AsciiProxyUriSize = AsciiStrSize (AsciiProxyUri);
+    Length            = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiProxyUriSize;
+    Node              = AllocatePool (Length);
+    if (Node == NULL) {
+      Status = EFI_OUT_OF_RESOURCES;
+      goto ON_EXIT;
+    }
+
+    Node->DevPath.Type    = MESSAGING_DEVICE_PATH;
+    Node->DevPath.SubType = MSG_URI_DP;
+    SetDevicePathNodeLength (Node, Length);
+    CopyMem (
+      (UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL),
+      AsciiProxyUri,
+      AsciiProxyUriSize
+      );
+    NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
+    FreePool (Node);
+    if (NewDevicePath == NULL) {
+      Status = EFI_OUT_OF_RESOURCES;
+      goto ON_EXIT;
+    }
+  } else {
+    NewDevicePath = TmpDevicePath;
+  }
+
   //
   // Update the URI node with the input boot file URI.
   //
-  UnicodeStrToAsciiStrS (Uri, AsciiUri, sizeof (AsciiUri));
   Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (AsciiUri);
   Node   = AllocatePool (Length);
   if (Node == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
-    FreePool (TmpDevicePath);
     goto ON_EXIT;
   }
 
@@ -116,10 +156,9 @@ HttpBootAddBootOption (
   Node->DevPath.SubType = MSG_URI_DP;
   SetDevicePathNodeLength (Node, Length);
   CopyMem ((UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), AsciiUri, AsciiStrSize (AsciiUri));
-  NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
+  FinalDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
   FreePool (Node);
-  FreePool (TmpDevicePath);
-  if (NewDevicePath == NULL) {
+  if (FinalDevicePath == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
     goto ON_EXIT;
   }
@@ -133,7 +172,7 @@ HttpBootAddBootOption (
              LoadOptionTypeBoot,
              LOAD_OPTION_ACTIVE,
              Description,
-             NewDevicePath,
+             FinalDevicePath,
              NULL,
              0
              );
@@ -146,10 +185,18 @@ HttpBootAddBootOption (
 
 ON_EXIT:
 
+  if (TmpDevicePath != NULL) {
+    FreePool (TmpDevicePath);
+  }
+
   if (NewDevicePath != NULL) {
     FreePool (NewDevicePath);
   }
 
+  if (FinalDevicePath != NULL) {
+    FreePool (FinalDevicePath);
+  }
+
   return Status;
 }
 
@@ -406,7 +453,8 @@ HttpBootFormRouteConfig (
     Private,
     (CallbackInfo->HttpBootNvData.IpVersion == HTTP_BOOT_IP_VERSION_6) ? TRUE : FALSE,
     CallbackInfo->HttpBootNvData.Description,
-    CallbackInfo->HttpBootNvData.Uri
+    CallbackInfo->HttpBootNvData.Uri,
+    CallbackInfo->HttpBootNvData.ProxyUri
     );
 
   return EFI_SUCCESS;
@@ -472,6 +520,7 @@ HttpBootFormCallback (
 
   switch (QuestionId) {
     case KEY_INITIATOR_URI:
+    case KEY_INITIATOR_PROXY_URI:
       //
       // Get user input URI string
       //
diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h b/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h
index a24fa5cb08..f0da21e8fd 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h
@@ -27,7 +27,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #define FORMID_MAIN_FORM  1
 
-#define KEY_INITIATOR_URI  0x101
+#define KEY_INITIATOR_URI        0x101
+#define KEY_INITIATOR_PROXY_URI  0x102
 
 #define HTTP_BOOT_DEFAULT_DESCRIPTION_STR  L"UEFI HTTP"
 
@@ -37,6 +38,7 @@ typedef struct _HTTP_BOOT_CONFIG_IFR_NVDATA {
   UINT8     Padding;
   CHAR16    Description[DESCRIPTION_STR_MAX_SIZE];
   CHAR16    Uri[URI_STR_MAX_SIZE];
+  CHAR16    ProxyUri[URI_STR_MAX_SIZE];
 } HTTP_BOOT_CONFIG_IFR_NVDATA;
 #pragma pack()
 
diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni b/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni
index 40abb13d0d..28af02bc14 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni
+++ b/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni
@@ -18,4 +18,6 @@
 #string STR_BOOT_URI_PROMPT                   #language en-US "Boot URI"
 #string STR_BOOT_URI_HELP                     #language en-US "A new Boot Option will be created according to this Boot URI."
 #string STR_BOOT_DESCRIPTION_PROMPT           #language en-US "Input the description"
+#string STR_BOOT_PROXY_URI_PROMPT             #language en-US "Proxy URI"
+#string STR_BOOT_PROXY_URI_HELP               #language en-US "Proxy URI through which to connect to Boot URI"
 #string STR_NULL_STRING                       #language en-US ""
diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr b/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr
index 65a60216bc..6a23e57d6b 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr
+++ b/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr
@@ -44,6 +44,15 @@ formset
             minsize = URI_STR_MIN_SIZE,
             maxsize = URI_STR_MAX_SIZE,
     endstring;
+
+    string  varid   = HTTP_BOOT_CONFIG_IFR_NVDATA.ProxyUri,
+            prompt  = STRING_TOKEN(STR_BOOT_PROXY_URI_PROMPT),
+            help    = STRING_TOKEN(STR_BOOT_PROXY_URI_HELP),
+            flags   = INTERACTIVE,
+            key     = KEY_INITIATOR_PROXY_URI,
+            minsize = URI_STR_MIN_SIZE,
+            maxsize = URI_STR_MAX_SIZE,
+    endstring;
   endform;
 
 endformset;
-- 
2.36.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#96923): https://edk2.groups.io/g/devel/message/96923
Mute This Topic: https://groups.io/mt/95413298/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list