From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com [IPv6:2a00:1450:400c:c09::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C660981CDC for ; Fri, 4 Nov 2016 11:27:48 -0700 (PDT) Received: by mail-wm0-x22f.google.com with SMTP id a197so67968526wmd.0 for ; Fri, 04 Nov 2016 11:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8UJGD4fWSqjRspA2yDSzVXOYjrkxAYWLbLUBCpysB+Q=; b=QqM1NEus62LZl2v2vLCwidNrwYLoWqA2Ubf7rO36dG50hgoeDWlIEteWmPXQJEr27S pbRZMD78629DA7NSAOk4PJNZR8Y53fR/UkHDfkur3XDMOWYPHAn1QVzulRL6blXKiuTT mlqfATNq20JUIy6lcJyB6IMMLaX8StZ0fkBS3nmDKBvGgoerpG8F+8v6xtETS9zR/iPk 9HYotCOHX4qrqDCnHbfNgsNRYzFzgSip8s0t0Xj7k1FyUumaRY+gYSbs6MIC/RsC1iKj ehF4G7h8bYbdAT6OKZMLRj3BsD6UP82P1vR8j4iENhTPlzVgP8XrNqqG8u+KuPNlN1on kBaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8UJGD4fWSqjRspA2yDSzVXOYjrkxAYWLbLUBCpysB+Q=; b=OijS8dLzfAQnBUTXj5YqIR6Ip4xrYXY1oHrMVi91tAK2ObMCl7ZLdfwI2Y4zOWC4A6 PKj3jJpDegy9rUC6Rk/uqGrRDv6cHjjiDdMMKOV9nBz3OQysMBnJebteJXVOC9VpOjRz HY84BsNdNWFC0gnPIZdnNuCWA+WUn5Q69zcy8MBVmcmZdh/dJlxBAZ8v6OlbUz/DdRMj 6p2heD+wLL5ukj916vv/3hBB77UM+M0UjnQYPsP1TTimHJ6JHF4Ltsi2nH0ZMhjC9IP4 qnTsXZc59AS9IPFBkOCwOoKCptLTKHO5H3PmSdJFizY69jm/rbDgokok78/AV/eGrWWz 8MfA== X-Gm-Message-State: ABUngvcEwmIqcDDckSQpFyjF2H6uzE50oncJUaej6/52eJmoJlaoOk/D9j2ELEwxv8U+ZA== X-Received: by 10.28.154.140 with SMTP id c134mr4849241wme.25.1478284069337; Fri, 04 Nov 2016 11:27:49 -0700 (PDT) Received: from enkidu.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id jb2sm15552903wjb.44.2016.11.04.11.27.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Nov 2016 11:27:48 -0700 (PDT) From: Marcin Wojtas 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 Date: Fri, 4 Nov 2016 19:28:43 +0100 Message-Id: <1478284123-4355-3-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1478284123-4355-1-git-send-email-mw@semihalf.com> References: <1478284123-4355-1-git-send-email-mw@semihalf.com> Subject: [PATCH 2/2] ShellPkg/Ifconfig: Enable setting MAC address X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Nov 2016 18:27:49 -0000 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 --- .../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 dhcp | > | >]\r\n" +"IFCONFIG [-s dhcp | > | > | | >]\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