iPXE
pxe_cmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 #include <ipxe/netdevice.h>
25 #include <ipxe/command.h>
26 #include <ipxe/parseopt.h>
27 #include <hci/ifmgmt_cmd.h>
28 #include <pxe_call.h>
29 
30 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
31 
32 /** @file
33  *
34  * PXE commands
35  *
36  */
37 
38 /** "startpxe" options */
39 struct startpxe_options {};
40 
41 /** "startpxe" option list */
42 static struct option_descriptor startpxe_opts[] = {};
43 
44 /**
45  * "startpxe" payload
46  *
47  * @v netdev Network device
48  * @v opts Command options
49  * @ret rc Return status code
50  */
51 static int startpxe_payload ( struct net_device *netdev,
52  struct startpxe_options *opts __unused ) {
53 
54  if ( netdev_is_open ( netdev ) )
55  pxe_activate ( netdev );
56 
57  return 0;
58 }
59 
60 /** "startpxe" command descriptor */
63  0, MAX_ARGUMENTS, "[<interface>]",
64  startpxe_payload, 0 );
65 
66 /**
67  * The "startpxe" command
68  *
69  * @v argc Argument count
70  * @v argv Argument list
71  * @ret rc Return status code
72  */
73 static int startpxe_exec ( int argc, char **argv ) {
74  return ifcommon_exec ( argc, argv, &startpxe_cmd );
75 }
76 
77 /** "stoppxe" options */
78 struct stoppxe_options {};
79 
80 /** "stoppxe" option list */
81 static struct option_descriptor stoppxe_opts[] = {};
82 
83 /** "stoppxe" command descriptor */
85  COMMAND_DESC ( struct stoppxe_options, stoppxe_opts, 0, 0, NULL );
86 
87 /**
88  * The "stoppxe" command
89  *
90  * @v argc Argument count
91  * @v argv Argument list
92  * @ret rc Return status code
93  */
94 static int stoppxe_exec ( int argc __unused, char **argv __unused ) {
95  struct stoppxe_options opts;
96  int rc;
97 
98  /* Parse options */
99  if ( ( rc = parse_options ( argc, argv, &stoppxe_cmd, &opts ) ) != 0 )
100  return rc;
101 
102  pxe_deactivate();
103 
104  return 0;
105 }
106 
107 /** PXE commands */
108 struct command pxe_commands[] __command = {
109  {
110  .name = "startpxe",
111  .exec = startpxe_exec,
112  },
113  {
114  .name = "stoppxe",
115  .exec = stoppxe_exec,
116  },
117 };
void pxe_activate(struct net_device *netdev)
Activate PXE stack.
Definition: pxe_call.c:276
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A command-line command.
Definition: command.h:9
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
An "if<xxx>" command descriptor.
Definition: ifmgmt_cmd.h:34
PXE API entry point.
static struct ifcommon_command_descriptor startpxe_cmd
"startpxe" command descriptor
Definition: pxe_cmd.c:61
A command descriptor.
Definition: parseopt.h:76
static int stoppxe_exec(int argc __unused, char **argv __unused)
The "stoppxe" command.
Definition: pxe_cmd.c:94
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
int pxe_deactivate(void)
Deactivate PXE stack.
Definition: pxe_call.c:307
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:96
static struct net_device * netdev
Definition: gdbudp.c:52
static int startpxe_payload(struct net_device *netdev, struct startpxe_options *opts __unused)
"startpxe" payload
Definition: pxe_cmd.c:51
static struct command_descriptor stoppxe_cmd
"stoppxe" command descriptor
Definition: pxe_cmd.c:84
"startpxe" options
Definition: pxe_cmd.c:39
static union @423 opts
"cert<xxx>" option list
"stoppxe" options
Definition: pxe_cmd.c:78
struct command pxe_commands [] __command
PXE commands.
Definition: pxe_cmd.c:108
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
Command line option parsing.
A network device.
Definition: netdevice.h:348
const char * name
Name of the command.
Definition: command.h:11
Network device management.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
int ifcommon_exec(int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
Execute if<xxx> command.
Definition: ifmgmt_cmd.c:51
A command-line option descriptor.
Definition: parseopt.h:22
static struct option_descriptor stoppxe_opts[]
"stoppxe" option list
Definition: pxe_cmd.c:81
static int startpxe_exec(int argc, char **argv)
The "startpxe" command.
Definition: pxe_cmd.c:73
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107
#define IFCOMMON_COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage, _payload, _stop_on_first_success)
Construct "if<xxx>" command descriptor.
Definition: ifmgmt_cmd.h:57
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static struct option_descriptor startpxe_opts[]
"startpxe" option list
Definition: pxe_cmd.c:42