iPXE
pxe_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 #include <ipxe/netdevice.h>
00025 #include <ipxe/command.h>
00026 #include <ipxe/parseopt.h>
00027 #include <hci/ifmgmt_cmd.h>
00028 #include <pxe_call.h>
00029 
00030 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00031 
00032 /** @file
00033  *
00034  * PXE commands
00035  *
00036  */
00037 
00038 /** "startpxe" options */
00039 struct startpxe_options {};
00040 
00041 /** "startpxe" option list */
00042 static struct option_descriptor startpxe_opts[] = {};
00043 
00044 /**
00045  * "startpxe" payload
00046  *
00047  * @v netdev            Network device
00048  * @v opts              Command options
00049  * @ret rc              Return status code
00050  */
00051 static int startpxe_payload ( struct net_device *netdev,
00052                               struct startpxe_options *opts __unused ) {
00053 
00054         if ( netdev_is_open ( netdev ) )
00055                 pxe_activate ( netdev );
00056 
00057         return 0;
00058 }
00059 
00060 /** "startpxe" command descriptor */
00061 static struct ifcommon_command_descriptor startpxe_cmd =
00062         IFCOMMON_COMMAND_DESC ( struct startpxe_options, startpxe_opts,
00063                                 0, MAX_ARGUMENTS, "[<interface>]",
00064                                 startpxe_payload, 0 );
00065 
00066 /**
00067  * The "startpxe" command
00068  *
00069  * @v argc              Argument count
00070  * @v argv              Argument list
00071  * @ret rc              Return status code
00072  */
00073 static int startpxe_exec ( int argc, char **argv ) {
00074         return ifcommon_exec ( argc, argv, &startpxe_cmd );
00075 }
00076 
00077 /** "stoppxe" options */
00078 struct stoppxe_options {};
00079 
00080 /** "stoppxe" option list */
00081 static struct option_descriptor stoppxe_opts[] = {};
00082 
00083 /** "stoppxe" command descriptor */
00084 static struct command_descriptor stoppxe_cmd =
00085         COMMAND_DESC ( struct stoppxe_options, stoppxe_opts, 0, 0, NULL );
00086 
00087 /**
00088  * The "stoppxe" command
00089  *
00090  * @v argc              Argument count
00091  * @v argv              Argument list
00092  * @ret rc              Return status code
00093  */
00094 static int stoppxe_exec ( int argc __unused, char **argv __unused ) {
00095         struct stoppxe_options opts;
00096         int rc;
00097 
00098         /* Parse options */
00099         if ( ( rc = parse_options ( argc, argv, &stoppxe_cmd, &opts ) ) != 0 )
00100                 return rc;
00101 
00102         pxe_deactivate();
00103 
00104         return 0;
00105 }
00106 
00107 /** PXE commands */
00108 struct command pxe_commands[] __command = {
00109         {
00110                 .name = "startpxe",
00111                 .exec = startpxe_exec,
00112         },
00113         {
00114                 .name = "stoppxe",
00115                 .exec = stoppxe_exec,
00116         },
00117 };