From: Marcin Wojtas <mw@semihalf.com>
To: edk2-devel@lists.01.org
Cc: feng.tian@intel.com, michael.d.kinney@intel.com,
liming.gao@intel.com, leif.lindholm@linaro.org, mw@semihalf.com,
jsd@semihalf.com, bsz@semihalf.com
Subject: [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address
Date: Fri, 4 Nov 2016 19:28:43 +0100 [thread overview]
Message-ID: <1478284123-4355-3-git-send-email-mw@semihalf.com> (raw)
In-Reply-To: <1478284123-4355-1-git-send-email-mw@semihalf.com>
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
next prev parent reply other threads:[~2016-11-04 18:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2016-11-04 20:38 ` [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address Carsey, Jaben
2016-11-07 11:54 ` Marcin Wojtas
2016-11-07 18:16 ` Carsey, Jaben
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478284123-4355-3-git-send-email-mw@semihalf.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox