1/** @file
2  EBL commands for Network Devices
3
4  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5  (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
6
7  This program and the accompanying materials
8  are licensed and made available under the terms and conditions of the BSD License
9  which accompanies this distribution.  The full text of the license may be found at
10  http://opensource.org/licenses/bsd-license.php
11
12  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15**/
16
17#include "Ebl.h"
18
19EFI_STATUS
20ParseIp (
21  IN  CHAR8           *String,
22  OUT EFI_IP_ADDRESS  *Address
23  )
24{
25  Address->v4.Addr[0] = (UINT8)AsciiStrDecimalToUintn (String);
26  String = AsciiStrStr(String, ".") + 1;
27  Address->v4.Addr[1] = (UINT8)AsciiStrDecimalToUintn (String);
28  String = AsciiStrStr(String, ".") + 1;
29  Address->v4.Addr[2] = (UINT8)AsciiStrDecimalToUintn (String);
30  String = AsciiStrStr(String, ".") + 1;
31  Address->v4.Addr[3] = (UINT8)AsciiStrDecimalToUintn (String);
32
33  return EFI_SUCCESS;
34}
35
36EFI_STATUS
37EFIAPI
38EblIpCmd (
39  IN UINTN  Argc,
40  IN CHAR8  **Argv
41  )
42{
43  EFI_STATUS        Status = EFI_INVALID_PARAMETER;
44  EFI_MAC_ADDRESS   Mac;
45  EFI_IP_ADDRESS    Ip;
46
47  if (Argc == 1) {
48    // Get current IP/MAC
49
50    // Get current MAC address
51    Status = EblGetCurrentMacAddress (&Mac);
52    if (EFI_ERROR (Status)) {
53      goto Exit;
54    }
55
56    AsciiPrint ("MAC Address:  %02x:%02x:%02x:%02x:%02x:%02x\n", Mac.Addr[0],  Mac.Addr[1],  Mac.Addr[2],  Mac.Addr[3],  Mac.Addr[4],  Mac.Addr[5]);
57
58    // Get current IP address
59    Status = EblGetCurrentIpAddress (&Ip);
60    if (EFI_ERROR(Status)) {
61      AsciiPrint("IP Address is not configured.\n");
62      Status = EFI_SUCCESS;
63      goto Exit;
64    }
65
66    AsciiPrint("IP Address:   %d.%d.%d.%d\n", Ip.v4.Addr[0], Ip.v4.Addr[1],Ip.v4.Addr[2], Ip.v4.Addr[3]);
67
68  } else if ((Argv[1][0] == 'r') && (Argc == 2)) {
69    // Get new address via dhcp
70    Status = EblPerformDHCP (TRUE);
71  } else if ((Argv[1][0] == 's') && (Argc == 3)) {
72    // Set static IP
73    Status = ParseIp (Argv[2], &Ip);
74    if (EFI_ERROR (Status)) {
75      goto Exit;
76    }
77
78    Status = EblSetStationIp (&Ip, NULL);
79  }
80
81Exit:
82  return Status;
83}
84
85GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdNetworkTemplate[] =
86{
87  {
88    "ip",
89    " ; print current ip address\n\r   [r]; request DHCP address\n\r   [s] ipaddr; set static IP address",
90    NULL,
91    EblIpCmd
92  }
93};
94
95
96/**
97  Initialize the commands in this in this file
98**/
99VOID
100EblInitializeNetworkCmd (
101  VOID
102  )
103{
104  EblAddCommands (mCmdNetworkTemplate, sizeof (mCmdNetworkTemplate)/sizeof (EBL_COMMAND_TABLE));
105}
106
107