public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] MAC address configuration from Shell
@ 2016-11-04 18:28 Marcin Wojtas
  2016-11-04 18:28 ` [PATCH 1/2] MdeModulePkg: NetLib: introduce MAC address handling helper routines Marcin Wojtas
  2016-11-04 18:28 ` [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address Marcin Wojtas
  0 siblings, 2 replies; 6+ messages in thread
From: Marcin Wojtas @ 2016-11-04 18:28 UTC (permalink / raw)
  To: edk2-devel
  Cc: feng.tian, michael.d.kinney, liming.gao, leif.lindholm, mw, jsd,
	bsz

Hi,

I present two commits that extend 'ifconfig' Shell command with ability
to configure/reset MAC address of the network interfaces. For that
purpose new routines were added to the NetLib. Details can be found in the
commit logs.

Any comments or remarks would be very welcome.

Best regards,
Marcin

Marcin Wojtas (2):
  MdeModulePkg: NetLib: introduce MAC address handling helper routines
  ShellPkg/Ifconfig: Enable setting MAC address

 MdeModulePkg/Include/Library/NetLib.h              |  83 +++++++++
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c         | 196 +++++++++++++++++++++
 .../UefiShellNetwork1CommandsLib/Ifconfig.c        |  54 ++++++
 .../UefiShellNetwork1CommandsLib.uni               |  12 +-
 4 files changed, 343 insertions(+), 2 deletions(-)

-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] MdeModulePkg: NetLib: introduce MAC address handling helper routines
  2016-11-04 18:28 [PATCH 0/2] MAC address configuration from Shell Marcin Wojtas
@ 2016-11-04 18:28 ` Marcin Wojtas
  2016-11-04 18:28 ` [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address Marcin Wojtas
  1 sibling, 0 replies; 6+ messages in thread
From: Marcin Wojtas @ 2016-11-04 18:28 UTC (permalink / raw)
  To: edk2-devel
  Cc: feng.tian, michael.d.kinney, liming.gao, leif.lindholm, mw, jsd,
	bsz

This patch introduces three functions that can be used for handling
MAC address update. It's also a preparation commit for adding support
for this feature using 'ifconfig' shell command. New functions are as
following:

* NetLibSetMacAddress - locate simple network protocol associated with the
  Service Binding Handle and try to update/reset the MAC address from SNP,
  using Snp->StationAddress() callback.

* NetLibStrToMac - convert one Null-terminated Unicode string to
  EFI_MAC_ADDRESS format.

* NetLibAsciiStrToMac - convert one Null-terminated ASCII string to
  EFI_MAC_ADDRESS format.

* NetLibReconnectInterface - reconnect the service handle. When called
  after NetLibSetMacAddress() it allows for updating associated
  protocols with new MAC address information.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 MdeModulePkg/Include/Library/NetLib.h      |  83 ++++++++++++
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 196 +++++++++++++++++++++++++++++
 2 files changed, 279 insertions(+)

diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h
index 26709af..7a50f9c 100644
--- a/MdeModulePkg/Include/Library/NetLib.h
+++ b/MdeModulePkg/Include/Library/NetLib.h
@@ -523,6 +523,9 @@ extern IP4_ADDR gIp4AllMasks[IP4_MASK_NUM];
 extern EFI_IPv4_ADDRESS  mZeroIp4Addr;
 
 #define NET_IS_DIGIT(Ch)            (('0' <= (Ch)) && ((Ch) <= '9'))
+#define NET_IS_HEX(Ch)              ((('0' <= (Ch)) && ((Ch) <= '9')) || \
+                                     (('A' <= (Ch)) && ((Ch) <= 'F')) || \
+                                     (('a' <= (Ch)) && ((Ch) <= 'f')))
 #define NET_ROUNDUP(size, unit)     (((size) + (unit) - 1) & (~((unit) - 1)))
 #define NET_IS_LOWER_CASE_CHAR(Ch)  (('a' <= (Ch)) && ((Ch) <= 'z'))
 #define NET_IS_UPPER_CASE_CHAR(Ch)  (('A' <= (Ch)) && ((Ch) <= 'Z'))
@@ -1180,6 +1183,49 @@ NetLibGetMacAddress (
   );
 
 /**
+  Update or reset MAC address associated with the network service handle.
+
+  Locate simple network protocol associated with the Service Binding Handle and
+  try to update/reset the mac address from SNP, using Snp->StationAddress().
+
+  @param[in]   ServiceHandle    The handle where network service binding protocols are
+                                installed on.
+  @param[in]   MacAddress       The pointer with new MAC address.
+  @param[in]   AddressSize      The length of set MAC address.
+  @param[in]   Reset            Reset MAC address to initial settings.
+
+  @retval EFI_SUCCESS           MAC address was updated/reset successfully.
+  @retval Others                Failed to set SNP MAC address.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibSetMacAddress (
+  IN EFI_HANDLE       ServiceHandle,
+  IN EFI_MAC_ADDRESS  *MacAddress,
+  IN UINT32            AddressSize,
+  IN BOOLEAN          Reset
+  );
+
+/**
+  Reconnect the network service handle.
+
+  Reconnect Service Binding Handle using Boot Services Dis/ConnectController() routines.
+
+  @param[in]   ServiceHandle    The handle where network service binding protocols are
+                                installed on.
+
+  @retval EFI_SUCCESS           Interface handle was reconnected successfully.
+  @retval Others                Failed to reconnect interface handle.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibReconnectInterface (
+  IN EFI_HANDLE             ServiceHandle
+  );
+
+/**
   Convert MAC address of the NIC associated with specified Service Binding Handle
   to a unicode string. Callers are responsible for freeing the string storage.
 
@@ -1348,6 +1394,24 @@ NetLibDefaultUnload (
   );
 
 /**
+  Convert one Null-terminated ASCII string to EFI_MAC_ADDRESS. The format of
+  the string has to be compliant with colon-separated EUI-48.
+
+  @param[in]      String         The pointer to the Ascii string.
+  @param[out]     MacAddress     The pointer to the converted MAC address.
+
+  @retval EFI_SUCCESS            Converted to an MAC address successfully.
+  @retval EFI_INVALID_PARAMETER  The string is malformated, or MacAddress is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibAsciiStrToMac (
+  IN CONST CHAR8                 *String,
+  OUT      EFI_MAC_ADDRESS       *MacAddress
+  );
+
+/**
   Convert one Null-terminated ASCII string (decimal dotted) to EFI_IPv4_ADDRESS.
 
   @param[in]      String         The pointer to the Ascii string.
@@ -1383,6 +1447,25 @@ NetLibAsciiStrToIp6 (
   );
 
 /**
+  Convert one Null-terminated Unicode string to EFI_MAC_ADDRESS. The format of
+  the string has to be compliant with colon-separated EUI-48.
+
+  @param[in]      String         The pointer to the Ascii string.
+  @param[out]     MacAddress     The pointer to the converted MAC address.
+
+  @retval EFI_SUCCESS            Converted to an MAC address successfully.
+  @retval EFI_INVALID_PARAMETER  The string is mal-formated or MacAddress is NULL.
+  @retval EFI_OUT_OF_RESOURCES   Failed to perform the operation due to lack of resources.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibStrToMac (
+  IN CONST CHAR16                *String,
+  OUT      EFI_MAC_ADDRESS       *MacAddress
+  );
+
+/**
   Convert one Null-terminated Unicode string (decimal dotted) to EFI_IPv4_ADDRESS.
 
   @param[in]      String         The pointer to the Ascii string.
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index 04d8345..f9ed863 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -2189,6 +2189,90 @@ NetLibGetMacAddress (
 }
 
 /**
+  Update or reset MAC address associated with the network service handle.
+
+  Locate simple network protocol associated with the Service Binding Handle and
+  try to update/reset the mac address from SNP, using Snp->StationAddress().
+
+  @param[in]   ServiceHandle    The handle where network service binding protocols are
+                                installed on.
+  @param[in]   MacAddress       The pointer with new MAC address.
+  @param[in]   AddressSize      The length of set MAC address.
+  @param[in]   Reset            Reset MAC address to initial settings.
+
+  @retval EFI_SUCCESS           MAC address was updated/reset successfully.
+  @retval Others                Failed to set SNP MAC address.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibSetMacAddress (
+  IN EFI_HANDLE       ServiceHandle,
+  IN EFI_MAC_ADDRESS  *MacAddress,
+  IN UINT32           AddressSize,
+  IN BOOLEAN          Reset
+  )
+{
+  EFI_STATUS                   Status;
+  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp;
+  EFI_HANDLE                   *SnpHandle;
+
+  ASSERT (AddressSize == NET_ETHER_ADDR_LEN);
+
+  //
+  // Get SNP handle
+  //
+  Snp = NULL;
+  SnpHandle = NetLibGetSnpHandle (ServiceHandle, &Snp);
+
+  if (SnpHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (!Snp->StationAddress) {
+    return EFI_UNSUPPORTED;
+  }
+
+  //
+  // Invoke Snp->StationAddress()
+  //
+  Status = Snp->StationAddress (Snp, Reset, MacAddress);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Reconnect the network service handle.
+
+  Reconnect Service Binding Handle using Boot Services Dis/ConnectController() routines.
+
+  @param[in]   ServiceHandle    The handle where network service binding protocols are
+                                installed on.
+
+  @retval EFI_SUCCESS           Interface handle was reconnected successfully.
+  @retval Others                Failed to reconnect interface handle.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibReconnectInterface (
+  IN EFI_HANDLE             ServiceHandle
+  )
+{
+  EFI_STATUS Status;
+
+  Status = gBS->DisconnectController(ServiceHandle, NULL, NULL);
+  if (!EFI_ERROR (Status)) {
+    Status = gBS->ConnectController(ServiceHandle, NULL, NULL, TRUE);
+  }
+
+  return Status;
+}
+
+/**
   Convert MAC address of the NIC associated with specified Service Binding Handle
   to a unicode string. Callers are responsible for freeing the string storage.
 
@@ -2693,6 +2777,76 @@ NetLibGetNicHandle (
 }
 
 /**
+  Convert one Null-terminated ASCII string to EFI_MAC_ADDRESS. The format of
+  the string has to be compliant with colon-separated EUI-48.
+
+  @param[in]      String         The pointer to the Ascii string.
+  @param[out]     MacAddress     The pointer to the converted MAC address.
+
+  @retval EFI_SUCCESS            Convert to MAC address successfully.
+  @retval EFI_INVALID_PARAMETER  The string is mal-formated or MacAddress is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibAsciiStrToMac (
+  IN CONST CHAR8                 *String,
+  OUT      EFI_MAC_ADDRESS       *MacAddress
+  )
+{
+  UINT8                          Index;
+  CHAR8                          *MacStr;
+  CHAR8                          *TempStr;
+  UINTN                          NodeVal;
+
+  if ((String == NULL) || (MacAddress == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  MacStr = (CHAR8 *) String;
+
+  for (Index = 0; Index < 6; Index++) {
+    TempStr = MacStr;
+
+    while ((*MacStr != '\0') && (*MacStr != ':')) {
+      if (!NET_IS_HEX (*MacStr)) {
+        return EFI_INVALID_PARAMETER;
+      }
+      MacStr++;
+    }
+
+    //
+    // The MAC address is X:X:X:X:X:X
+    //
+    if (*MacStr == ':') {
+      if (Index == 5) {
+        return EFI_INVALID_PARAMETER;
+      }
+    } else {
+      if (Index != 5) {
+        return EFI_INVALID_PARAMETER;
+      }
+    }
+
+    //
+    // Convert the string to MAC address. AsciiStrHexToUintn stops at the
+    // first character that is not a valid hexadecimal character,
+    // ':' or '\0' here.
+    //
+    NodeVal = AsciiStrHexToUintn (TempStr);
+    if (NodeVal > 0xFF) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    MacAddress->Addr[Index] = (UINT8) NodeVal;
+
+    MacStr++;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
   Convert one Null-terminated ASCII string (decimal dotted) to EFI_IPv4_ADDRESS.
 
   @param[in]      String         The pointer to the Ascii string.
@@ -2957,6 +3111,48 @@ NetLibAsciiStrToIp6 (
   return EFI_SUCCESS;
 }
 
+/**
+  Convert one Null-terminated Unicode string to EFI_MAC_ADDRESS. The format of
+  the string has to be compliant with colon-separated EUI-48.
+
+  @param[in]      String         The pointer to the Ascii string.
+  @param[out]     MacAddress     The pointer to the converted MAC address.
+
+  @retval EFI_SUCCESS            Convert to MAC address successfully.
+  @retval EFI_INVALID_PARAMETER  The string is mal-formated or MacAddress is NULL.
+  @retval EFI_OUT_OF_RESOURCES   Fail to perform the operation due to lack of resource.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibStrToMac (
+  IN CONST CHAR16                *String,
+  OUT      EFI_MAC_ADDRESS       *MacAddress
+  )
+{
+  CHAR8                          *MacStr;
+  UINTN                          StringSize;
+  EFI_STATUS                     Status;
+
+  if ((String == NULL) || (MacAddress == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  StringSize = StrLen (String) + 1;
+  MacStr = (CHAR8 *) AllocatePool (StringSize * sizeof (CHAR8));
+  if (MacStr == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  UnicodeStrToAsciiStrS (String, MacStr, StringSize);
+
+  Status = NetLibAsciiStrToMac (MacStr, MacAddress);
+
+  FreePool (MacStr);
+
+  return Status;
+}
+
 
 /**
   Convert one Null-terminated Unicode string (decimal dotted) to EFI_IPv4_ADDRESS.
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address
  2016-11-04 18:28 [PATCH 0/2] MAC address configuration from Shell Marcin Wojtas
  2016-11-04 18:28 ` [PATCH 1/2] MdeModulePkg: NetLib: introduce MAC address handling helper routines Marcin Wojtas
@ 2016-11-04 18:28 ` Marcin Wojtas
  2016-11-04 20:38   ` Carsey, Jaben
  1 sibling, 1 reply; 6+ messages in thread
From: Marcin Wojtas @ 2016-11-04 18:28 UTC (permalink / raw)
  To: edk2-devel
  Cc: feng.tian, michael.d.kinney, liming.gao, leif.lindholm, mw, jsd,
	bsz

This adds new feature to ifconfig shell command, which allow
for updating MAC address of the interface or resetting it to the
initial value.

It consumes newly added NetLib helpers for parsing the Unicode
string to EFI_MAC_ADDRESS, calling Snp->StationAddress() callback
and reconnecting controller, so that all interface's children
devices could get updated with new value of the MAC address.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 .../UefiShellNetwork1CommandsLib/Ifconfig.c        | 54 ++++++++++++++++++++++
 .../UefiShellNetwork1CommandsLib.uni               | 12 ++++-
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
index 5e243d5..e4ea308 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
@@ -120,6 +120,12 @@ VAR_CHECK_ITEM  mSetCheckList[] = {
     FlagTypeSingle
   },
   {
+    L"mac",
+    0x00000010,
+    0x00000005,
+    FlagTypeSingle
+  },
+  {
     NULL,
     0x0,
     0x0,
@@ -832,6 +838,7 @@ IfConfigSetInterfaceInfo (
   EFI_EVENT                        TimeOutEvt;
   EFI_EVENT                        MappedEvt;
   BOOLEAN                          IsAddressOk;
+  BOOLEAN                          MacAddressReset;
 
   EFI_IP4_CONFIG2_POLICY           Policy;
   EFI_IP4_CONFIG2_MANUAL_ADDRESS   ManualAddress;
@@ -840,6 +847,7 @@ IfConfigSetInterfaceInfo (
   EFI_IPv4_ADDRESS                 *Dns;
   ARG_LIST                         *Tmp;
   UINTN                            Index;
+  EFI_MAC_ADDRESS                  NewMac;
 
   CONST CHAR16* TempString;
 
@@ -1150,6 +1158,52 @@ IfConfigSetInterfaceInfo (
         ShellStatus = SHELL_ACCESS_DENIED;
         goto ON_EXIT;
       }
+    } else if (StrCmp (VarArg->Arg, L"mac") == 0) {
+      //
+      // Set MAC address.
+      //
+      MacAddressReset = FALSE;
+      VarArg = VarArg->Next;
+      if (VarArg == NULL) {
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);
+        ShellStatus = SHELL_INVALID_PARAMETER;
+        goto ON_EXIT;
+      }
+
+      if (StrCmp (VarArg->Arg, L"reset") == 0) {
+        MacAddressReset = TRUE;
+      } else {
+        Status = NetLibStrToMac (VarArg->Arg, &NewMac);
+        if (EFI_ERROR(Status)) {
+          ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_MACADDRESS), gShellNetwork1HiiHandle, VarArg->Arg);
+          ShellStatus = SHELL_INVALID_PARAMETER;
+          goto ON_EXIT;
+        }
+      }
+
+      Status = NetLibSetMacAddress (
+                      IfCb->NicHandle,
+                      &NewMac,
+                      IfCb->IfInfo->HwAddressSize,
+                      MacAddressReset
+                      );
+      if (EFI_ERROR(Status)) {
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);
+        ShellStatus = SHELL_ACCESS_DENIED;
+        goto ON_EXIT;
+      }
+
+      //
+      // Reconnect controller, so that all children get updated with
+      // new MAC address information.
+      //
+      Status = NetLibReconnectInterface (IfCb->NicHandle);
+      if (EFI_ERROR(Status)) {
+        ShellStatus = SHELL_DEVICE_ERROR;
+        goto ON_EXIT;
+      }
+
+      VarArg = VarArg->Next;
     }
   }
 
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
index 76b6188..ffc358d 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
@@ -66,6 +66,7 @@
 #string STR_IFCONFIG_LACK_COMMAND             #language en-US    "Lack interface config option.\n"
 #string STR_IFCONFIG_INVALID_INTERFACE        #language en-US    "Invalid interface name.\n"
 #string STR_IFCONFIG_INVALID_IPADDRESS        #language en-US    "Invalid ipv4 address: '%H%s%N'\n"
+#string STR_IFCONFIG_INVALID_MACADDRESS       #language en-US    "Invalid MAC address: '%H%s%N'\n"
 #string STR_IFCONFIG_DUPLICATE_COMMAND        #language en-US    "Duplicate commands. Bad command %H%s%N is skipped.\n"
 #string STR_IFCONFIG_CONFLICT_COMMAND         #language en-US    "Conflict commands. Bad command %H%s%N is skipped.\n"
 #string STR_IFCONFIG_UNKNOWN_COMMAND          #language en-US    "Unknown commands. Bad command %H%s%N is skipped.\n"
@@ -133,7 +134,7 @@
 ".SH SYNOPSIS\r\n"
 " \r\n"
 "IFCONFIG [-r [Name]] [-l [Name]]\r\n"
-"IFCONFIG [-s <Name> dhcp | <static <IP> <Mask>  <Gateway>> | <dns <IP>>]\r\n"
+"IFCONFIG [-s <Name> dhcp | <static <IP> <Mask>  <Gateway>> | <dns <IP>> | <mac reset> | <mac <MAC>>]\r\n"
 ".SH OPTIONS\r\n"
 " \r\n"
 "  -r          - Renew configuration of interface and set dhcp policy.\r\n"
@@ -146,6 +147,8 @@
 "                  - Example: 255.255.255.0\r\n"
 "  GatewayMask - Specifies a default gateway in four integer values:\r\n"
 "                  - Example: 192.168.0.1\r\n"
+"  MAC         - Specifies the MAC address:\r\n"
+"                  - Example: 00:11:22:33:44:55\r\n"
 ".SH DESCRIPTION\r\n"
 " \r\n"
 "NOTES:\r\n"
@@ -174,6 +177,11 @@
 " \r\n"
 "  * To configure DNS server address for the eth0 interface:\r\n"
 "    fs0:\> ifconfig -s eth0 dns 192.168.0.8 192.168.0.9\r\n"
-                                                                  
+" \r\n"
+"  * To configure MAC address for the eth0 interface:\r\n"
+"    fs0:\> ifconfig -s eth0 mac 00:11:22:33:44:55\r\n"
+" \r\n"
+"  * To reset MAC address of the eth0 interface to initial value:\r\n"
+"    fs0:\> ifconfig -s eth0 mac reset\r\n"
 
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address
  2016-11-04 18:28 ` [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address Marcin Wojtas
@ 2016-11-04 20:38   ` Carsey, Jaben
  2016-11-07 11:54     ` Marcin Wojtas
  0 siblings, 1 reply; 6+ messages in thread
From: Carsey, Jaben @ 2016-11-04 20:38 UTC (permalink / raw)
  To: Marcin Wojtas, edk2-devel@lists.01.org
  Cc: Tian, Feng, leif.lindholm@linaro.org, Gao, Liming,
	Kinney, Michael D, Carsey, Jaben

I think this is a good idea. But I see 2 issues.  
1 - ifconfig standard parameters are controlled by the UEFI Shell Specification.  If you want to extend the parameters you need to use parameters that start with underscore.  I do not quite know how to so this under the "-s" set of functions for this command.  Maybe just add this separate from "-s", using something like "-_mac"?
2 - whatever change is done here should also be done to the ipv6 version of the command.

-Jaben


> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Marcin Wojtas
> Sent: Friday, November 04, 2016 11:29 AM
> To: edk2-devel@lists.01.org
> Cc: Tian, Feng <feng.tian@intel.com>; leif.lindholm@linaro.org; Gao, Liming
> <liming.gao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>
> Subject: [edk2] [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address
> Importance: High
> 
> This adds new feature to ifconfig shell command, which allow
> for updating MAC address of the interface or resetting it to the
> initial value.
> 
> It consumes newly added NetLib helpers for parsing the Unicode
> string to EFI_MAC_ADDRESS, calling Snp->StationAddress() callback
> and reconnecting controller, so that all interface's children
> devices could get updated with new value of the MAC address.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  .../UefiShellNetwork1CommandsLib/Ifconfig.c        | 54
> ++++++++++++++++++++++
>  .../UefiShellNetwork1CommandsLib.uni               | 12 ++++-
>  2 files changed, 64 insertions(+), 2 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
> b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
> index 5e243d5..e4ea308 100644
> --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
> +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
> @@ -120,6 +120,12 @@ VAR_CHECK_ITEM  mSetCheckList[] = {
>      FlagTypeSingle
>    },
>    {
> +    L"mac",
> +    0x00000010,
> +    0x00000005,
> +    FlagTypeSingle
> +  },
> +  {
>      NULL,
>      0x0,
>      0x0,
> @@ -832,6 +838,7 @@ IfConfigSetInterfaceInfo (
>    EFI_EVENT                        TimeOutEvt;
>    EFI_EVENT                        MappedEvt;
>    BOOLEAN                          IsAddressOk;
> +  BOOLEAN                          MacAddressReset;
> 
>    EFI_IP4_CONFIG2_POLICY           Policy;
>    EFI_IP4_CONFIG2_MANUAL_ADDRESS   ManualAddress;
> @@ -840,6 +847,7 @@ IfConfigSetInterfaceInfo (
>    EFI_IPv4_ADDRESS                 *Dns;
>    ARG_LIST                         *Tmp;
>    UINTN                            Index;
> +  EFI_MAC_ADDRESS                  NewMac;
> 
>    CONST CHAR16* TempString;
> 
> @@ -1150,6 +1158,52 @@ IfConfigSetInterfaceInfo (
>          ShellStatus = SHELL_ACCESS_DENIED;
>          goto ON_EXIT;
>        }
> +    } else if (StrCmp (VarArg->Arg, L"mac") == 0) {
> +      //
> +      // Set MAC address.
> +      //
> +      MacAddressReset = FALSE;
> +      VarArg = VarArg->Next;
> +      if (VarArg == NULL) {
> +        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);
> +        ShellStatus = SHELL_INVALID_PARAMETER;
> +        goto ON_EXIT;
> +      }
> +
> +      if (StrCmp (VarArg->Arg, L"reset") == 0) {
> +        MacAddressReset = TRUE;
> +      } else {
> +        Status = NetLibStrToMac (VarArg->Arg, &NewMac);
> +        if (EFI_ERROR(Status)) {
> +          ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN
> (STR_IFCONFIG_INVALID_MACADDRESS), gShellNetwork1HiiHandle, VarArg-
> >Arg);
> +          ShellStatus = SHELL_INVALID_PARAMETER;
> +          goto ON_EXIT;
> +        }
> +      }
> +
> +      Status = NetLibSetMacAddress (
> +                      IfCb->NicHandle,
> +                      &NewMac,
> +                      IfCb->IfInfo->HwAddressSize,
> +                      MacAddressReset
> +                      );
> +      if (EFI_ERROR(Status)) {
> +        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);
> +        ShellStatus = SHELL_ACCESS_DENIED;
> +        goto ON_EXIT;
> +      }
> +
> +      //
> +      // Reconnect controller, so that all children get updated with
> +      // new MAC address information.
> +      //
> +      Status = NetLibReconnectInterface (IfCb->NicHandle);
> +      if (EFI_ERROR(Status)) {
> +        ShellStatus = SHELL_DEVICE_ERROR;
> +        goto ON_EXIT;
> +      }
> +
> +      VarArg = VarArg->Next;
>      }
>    }
> 
> diff --git
> a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com
> mandsLib.uni
> b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com
> mandsLib.uni
> index 76b6188..ffc358d 100644
> ---
> a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com
> mandsLib.uni
> +++
> b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com
> mandsLib.uni
> @@ -66,6 +66,7 @@
>  #string STR_IFCONFIG_LACK_COMMAND             #language en-US    "Lack
> interface config option.\n"
>  #string STR_IFCONFIG_INVALID_INTERFACE        #language en-US    "Invalid
> interface name.\n"
>  #string STR_IFCONFIG_INVALID_IPADDRESS        #language en-US    "Invalid
> ipv4 address: '%H%s%N'\n"
> +#string STR_IFCONFIG_INVALID_MACADDRESS       #language en-US
> "Invalid MAC address: '%H%s%N'\n"
>  #string STR_IFCONFIG_DUPLICATE_COMMAND        #language en-US
> "Duplicate commands. Bad command %H%s%N is skipped.\n"
>  #string STR_IFCONFIG_CONFLICT_COMMAND         #language en-US
> "Conflict commands. Bad command %H%s%N is skipped.\n"
>  #string STR_IFCONFIG_UNKNOWN_COMMAND          #language en-US
> "Unknown commands. Bad command %H%s%N is skipped.\n"
> @@ -133,7 +134,7 @@
>  ".SH SYNOPSIS\r\n"
>  " \r\n"
>  "IFCONFIG [-r [Name]] [-l [Name]]\r\n"
> -"IFCONFIG [-s <Name> dhcp | <static <IP> <Mask>  <Gateway>> | <dns
> <IP>>]\r\n"
> +"IFCONFIG [-s <Name> dhcp | <static <IP> <Mask>  <Gateway>> | <dns
> <IP>> | <mac reset> | <mac <MAC>>]\r\n"
>  ".SH OPTIONS\r\n"
>  " \r\n"
>  "  -r          - Renew configuration of interface and set dhcp policy.\r\n"
> @@ -146,6 +147,8 @@
>  "                  - Example: 255.255.255.0\r\n"
>  "  GatewayMask - Specifies a default gateway in four integer values:\r\n"
>  "                  - Example: 192.168.0.1\r\n"
> +"  MAC         - Specifies the MAC address:\r\n"
> +"                  - Example: 00:11:22:33:44:55\r\n"
>  ".SH DESCRIPTION\r\n"
>  " \r\n"
>  "NOTES:\r\n"
> @@ -174,6 +177,11 @@
>  " \r\n"
>  "  * To configure DNS server address for the eth0 interface:\r\n"
>  "    fs0:\> ifconfig -s eth0 dns 192.168.0.8 192.168.0.9\r\n"
> -
> +" \r\n"
> +"  * To configure MAC address for the eth0 interface:\r\n"
> +"    fs0:\> ifconfig -s eth0 mac 00:11:22:33:44:55\r\n"
> +" \r\n"
> +"  * To reset MAC address of the eth0 interface to initial value:\r\n"
> +"    fs0:\> ifconfig -s eth0 mac reset\r\n"
> 
> 
> --
> 1.8.3.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address
  2016-11-04 20:38   ` Carsey, Jaben
@ 2016-11-07 11:54     ` Marcin Wojtas
  2016-11-07 18:16       ` Carsey, Jaben
  0 siblings, 1 reply; 6+ messages in thread
From: Marcin Wojtas @ 2016-11-07 11:54 UTC (permalink / raw)
  To: Carsey, Jaben
  Cc: edk2-devel@lists.01.org, Tian, Feng, leif.lindholm@linaro.org,
	Gao, Liming, Kinney, Michael D

Hi Jaben,

2016-11-04 21:38 GMT+01:00 Carsey, Jaben <jaben.carsey@intel.com>:
> I think this is a good idea. But I see 2 issues.
> 1 - ifconfig standard parameters are controlled by the UEFI Shell Specification.  If you want to extend the parameters you need to use parameters that start with underscore.  I do not quite know how to so this under the "-s" set of functions for this command.  Maybe just add this separate from "-s", using something like "-_mac"?

No, problem. Since this will be an additional parameter in
mIfConfig[6]CheckList, and all consist of single letter, I propose
"-_m". Is it ok?

> 2 - whatever change is done here should also be done to the ipv6 version of the command.
>

Ok, I can see it should be not much than simple copy-paste.

Best regards,
Marcin


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address
  2016-11-07 11:54     ` Marcin Wojtas
@ 2016-11-07 18:16       ` Carsey, Jaben
  0 siblings, 0 replies; 6+ messages in thread
From: Carsey, Jaben @ 2016-11-07 18:16 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: edk2-devel@lists.01.org, Tian, Feng, leif.lindholm@linaro.org,
	Gao, Liming, Kinney, Michael D, Carsey, Jaben

Sounds good to me.

> -----Original Message-----
> From: Marcin Wojtas [mailto:mw@semihalf.com]
> Sent: Monday, November 07, 2016 3:55 AM
> To: Carsey, Jaben <jaben.carsey@intel.com>
> Cc: edk2-devel@lists.01.org; Tian, Feng <feng.tian@intel.com>;
> leif.lindholm@linaro.org; Gao, Liming <liming.gao@intel.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> Subject: Re: [edk2] [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC
> address
> Importance: High
> 
> Hi Jaben,
> 
> 2016-11-04 21:38 GMT+01:00 Carsey, Jaben <jaben.carsey@intel.com>:
> > I think this is a good idea. But I see 2 issues.
> > 1 - ifconfig standard parameters are controlled by the UEFI Shell
> Specification.  If you want to extend the parameters you need to use
> parameters that start with underscore.  I do not quite know how to so this
> under the "-s" set of functions for this command.  Maybe just add this
> separate from "-s", using something like "-_mac"?
> 
> No, problem. Since this will be an additional parameter in
> mIfConfig[6]CheckList, and all consist of single letter, I propose
> "-_m". Is it ok?
> 
> > 2 - whatever change is done here should also be done to the ipv6 version
> of the command.
> >
> 
> Ok, I can see it should be not much than simple copy-paste.
> 
> Best regards,
> Marcin

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-11-07 18:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-04 18:28 [PATCH 0/2] MAC address configuration from Shell Marcin Wojtas
2016-11-04 18:28 ` [PATCH 1/2] MdeModulePkg: NetLib: introduce MAC address handling helper routines Marcin Wojtas
2016-11-04 18:28 ` [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address Marcin Wojtas
2016-11-04 20:38   ` Carsey, Jaben
2016-11-07 11:54     ` Marcin Wojtas
2016-11-07 18:16       ` Carsey, Jaben

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox