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