]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
ShellPkg/[hex]edit: use SimpleTextInEx to read console
[mirror_edk2.git] / ShellPkg / Library / UefiShellNetwork1CommandsLib / Ifconfig.c
index 5e243d58843017810d57dd7c688ca4748cf75e30..ab6ab8b57ea251b939a04592453f9e4d016861b4 100644 (file)
@@ -2,7 +2,7 @@
   The implementation for Shell command ifconfig based on IP4Config2 protocol.\r
 \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
   The implementation for Shell command ifconfig based on IP4Config2 protocol.\r
 \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2017, 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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -550,11 +550,11 @@ IfConfigShowInterfaceInfo (
   LIST_ENTRY                   *Entry;\r
   LIST_ENTRY                   *Next;\r
   IFCONFIG_INTERFACE_CB        *IfCb;\r
   LIST_ENTRY                   *Entry;\r
   LIST_ENTRY                   *Next;\r
   IFCONFIG_INTERFACE_CB        *IfCb;\r
-  BOOLEAN                       MediaPresent;\r
+  EFI_STATUS                    MediaStatus;\r
   EFI_IPv4_ADDRESS              Gateway;\r
   UINT32                        Index;\r
   \r
   EFI_IPv4_ADDRESS              Gateway;\r
   UINT32                        Index;\r
   \r
-  MediaPresent = TRUE;\r
+  MediaStatus = EFI_SUCCESS;\r
 \r
   if (IsListEmpty (IfList)) {\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);\r
 \r
   if (IsListEmpty (IfList)) {\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);\r
@@ -576,11 +576,14 @@ IfConfigShowInterfaceInfo (
     //\r
     // Get Media State.\r
     //\r
     //\r
     // Get Media State.\r
     //\r
-    NetLibDetectMedia (IfCb->NicHandle, &MediaPresent);\r
-    if (!MediaPresent) {\r
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MEDIA_STATE), gShellNetwork1HiiHandle, L"Media disconnected");\r
+    if (EFI_SUCCESS == NetLibDetectMediaWaitTimeout (IfCb->NicHandle, 0, &MediaStatus)) {\r
+      if (MediaStatus != EFI_SUCCESS) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MEDIA_STATE), gShellNetwork1HiiHandle, L"Media disconnected");\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MEDIA_STATE), gShellNetwork1HiiHandle, L"Media present");\r
+      }\r
     } else {\r
     } else {\r
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MEDIA_STATE), gShellNetwork1HiiHandle, L"Media present");\r
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MEDIA_STATE), gShellNetwork1HiiHandle, L"Media state unknown");\r
     }\r
 \r
     //\r
     }\r
 \r
     //\r
@@ -837,6 +840,8 @@ IfConfigSetInterfaceInfo (
   EFI_IP4_CONFIG2_MANUAL_ADDRESS   ManualAddress;\r
   UINTN                            DataSize;\r
   EFI_IPv4_ADDRESS                 Gateway;\r
   EFI_IP4_CONFIG2_MANUAL_ADDRESS   ManualAddress;\r
   UINTN                            DataSize;\r
   EFI_IPv4_ADDRESS                 Gateway;\r
+  IP4_ADDR                         SubnetMask;\r
+  IP4_ADDR                         TempGateway;\r
   EFI_IPv4_ADDRESS                 *Dns;\r
   ARG_LIST                         *Tmp;\r
   UINTN                            Index;\r
   EFI_IPv4_ADDRESS                 *Dns;\r
   ARG_LIST                         *Tmp;\r
   UINTN                            Index;\r
@@ -1018,6 +1023,21 @@ IfConfigSetInterfaceInfo (
         goto ON_EXIT;\r
       }\r
 \r
         goto ON_EXIT;\r
       }\r
 \r
+      //\r
+      // Need to check the gateway validity before set Manual Address.\r
+      // In case we can set manual address but fail to configure Gateway.\r
+      //\r
+      CopyMem (&SubnetMask, &ManualAddress.SubnetMask, sizeof (IP4_ADDR));\r
+      CopyMem (&TempGateway, &Gateway, sizeof (IP4_ADDR));\r
+      SubnetMask  = NTOHL (SubnetMask);\r
+      TempGateway = NTOHL (TempGateway);\r
+      if ((SubnetMask != 0) &&\r
+          !NetIp4IsUnicast (TempGateway, SubnetMask)) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY), gShellNetwork1HiiHandle, VarArg->Arg);\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+        goto ON_EXIT;\r
+      }\r
+\r
       //\r
       // Set manual config policy.\r
       //\r
       //\r
       // Set manual config policy.\r
       //\r