summaryrefslogtreecommitdiffstats
path: root/src/hci
diff options
context:
space:
mode:
authorMichael Brown2013-11-04 17:15:21 +0100
committerMichael Brown2013-11-05 18:15:24 +0100
commit55e85ad1ee318aa559f071d95741391eaf2dc1de (patch)
tree3800d4c1246319e68c914664a6d4afbad1d5b313 /src/hci
parent[ifmgmt] Rewrite iflinkwait() to use monojob_wait() (diff)
downloadipxe-55e85ad1ee318aa559f071d95741391eaf2dc1de.tar.gz
ipxe-55e85ad1ee318aa559f071d95741391eaf2dc1de.tar.xz
ipxe-55e85ad1ee318aa559f071d95741391eaf2dc1de.zip
[cmdline] Allow "if<xxx>" commands to take options
Allow commands implemented using ifcommon_exec() to accept command-specific options. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci')
-rw-r--r--src/hci/commands/autoboot_cmd.c27
-rw-r--r--src/hci/commands/dhcp_cmd.c21
-rw-r--r--src/hci/commands/ifmgmt_cmd.c83
-rw-r--r--src/hci/commands/iwmgmt_cmd.c42
4 files changed, 121 insertions, 52 deletions
diff --git a/src/hci/commands/autoboot_cmd.c b/src/hci/commands/autoboot_cmd.c
index f3886b1f..62235a27 100644
--- a/src/hci/commands/autoboot_cmd.c
+++ b/src/hci/commands/autoboot_cmd.c
@@ -33,10 +33,29 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
*/
+/** "autoboot" options */
+struct autoboot_options {};
+
+/** "autoboot" option list */
+static struct option_descriptor autoboot_opts[] = {};
+
+/**
+ * "autoboot" payload
+ *
+ * @v netdev Network device
+ * @v opts Command options
+ * @ret rc Return status code
+ */
+static int autoboot_payload ( struct net_device *netdev,
+ struct autoboot_options *opts __unused ) {
+ return netboot ( netdev );
+}
+
/** "autoboot" command descriptor */
-static struct command_descriptor autoboot_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>...]" );
+static struct ifcommon_command_descriptor autoboot_cmd =
+ IFCOMMON_COMMAND_DESC ( struct autoboot_options, autoboot_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ autoboot_payload, 0 );
/**
* "autoboot" command
@@ -46,7 +65,7 @@ static struct command_descriptor autoboot_cmd =
* @ret rc Return status code
*/
static int autoboot_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &autoboot_cmd, netboot, 0 );
+ return ifcommon_exec ( argc, argv, &autoboot_cmd );
}
/** Booting commands */
diff --git a/src/hci/commands/dhcp_cmd.c b/src/hci/commands/dhcp_cmd.c
index 279620c3..1b7df765 100644
--- a/src/hci/commands/dhcp_cmd.c
+++ b/src/hci/commands/dhcp_cmd.c
@@ -41,18 +41,21 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
*/
-/** "dhcp" command descriptor */
-static struct command_descriptor dhcp_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>...]" );
+/** "dhcp" options */
+struct dhcp_options {};
+
+/** "dhcp" option list */
+static struct option_descriptor dhcp_opts[] = {};
/**
* Execute "dhcp" command for a network device
*
* @v netdev Network device
+ * @v opts Command options
* @ret rc Return status code
*/
-static int dhcp_payload ( struct net_device *netdev ) {
+static int dhcp_payload ( struct net_device *netdev,
+ struct dhcp_options *opts __unused ) {
int rc;
if ( ( rc = dhcp ( netdev ) ) != 0 ) {
@@ -68,6 +71,12 @@ static int dhcp_payload ( struct net_device *netdev ) {
return 0;
}
+/** "dhcp" command descriptor */
+static struct ifcommon_command_descriptor dhcp_cmd =
+ IFCOMMON_COMMAND_DESC ( struct dhcp_options, dhcp_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ dhcp_payload, 1 );
+
/**
* The "dhcp" command
*
@@ -76,7 +85,7 @@ static int dhcp_payload ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int dhcp_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &dhcp_cmd, dhcp_payload, 1 );
+ return ifcommon_exec ( argc, argv, &dhcp_cmd );
}
/** "pxebs" options */
diff --git a/src/hci/commands/ifmgmt_cmd.c b/src/hci/commands/ifmgmt_cmd.c
index 350f14d0..771d947f 100644
--- a/src/hci/commands/ifmgmt_cmd.c
+++ b/src/hci/commands/ifmgmt_cmd.c
@@ -34,9 +34,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
*/
-/** "if<xxx>" command options */
-struct option_descriptor ifcommon_opts[0];
-
/**
* Execute if<xxx> command
*
@@ -48,16 +45,15 @@ struct option_descriptor ifcommon_opts[0];
* @ret rc Return status code
*/
int ifcommon_exec ( int argc, char **argv,
- struct command_descriptor *cmd,
- int ( * payload ) ( struct net_device * ),
- int stop_on_first_success ) {
- struct ifcommon_options opts;
+ struct ifcommon_command_descriptor *ifcmd ) {
+ struct command_descriptor *cmd = &ifcmd->cmd;
+ uint8_t opts[cmd->len];
struct net_device *netdev;
int i;
int rc;
/* Parse options */
- if ( ( rc = parse_options ( argc, argv, cmd, &opts ) ) != 0 )
+ if ( ( rc = parse_options ( argc, argv, cmd, opts ) ) != 0 )
return rc;
if ( optind != argc ) {
@@ -65,8 +61,8 @@ int ifcommon_exec ( int argc, char **argv,
for ( i = optind ; i < argc ; i++ ) {
if ( ( rc = parse_netdev ( argv[i], &netdev ) ) != 0 )
continue;
- if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
- stop_on_first_success ) {
+ if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
+ && ifcmd->stop_on_first_success ) {
return 0;
}
}
@@ -74,8 +70,8 @@ int ifcommon_exec ( int argc, char **argv,
/* Try all interfaces */
rc = -ENODEV;
for_each_netdev ( netdev ) {
- if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
- stop_on_first_success ) {
+ if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
+ && ifcmd->stop_on_first_success ) {
return 0;
}
}
@@ -84,21 +80,30 @@ int ifcommon_exec ( int argc, char **argv,
return rc;
}
-/** "ifopen" command descriptor */
-static struct command_descriptor ifopen_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>...]" );
+/** "ifopen" options */
+struct ifopen_options {};
+
+/** "ifopen" option list */
+static struct option_descriptor ifopen_opts[] = {};
/**
* "ifopen" payload
*
* @v netdev Network device
+ * @v opts Command options
* @ret rc Return status code
*/
-static int ifopen_payload ( struct net_device *netdev ) {
+static int ifopen_payload ( struct net_device *netdev,
+ struct ifopen_options *opts __unused ) {
return ifopen ( netdev );
}
+/** "ifopen" command descriptor */
+static struct ifcommon_command_descriptor ifopen_cmd =
+ IFCOMMON_COMMAND_DESC ( struct ifopen_options, ifopen_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ ifopen_payload, 0 );
+
/**
* The "ifopen" command
*
@@ -107,25 +112,34 @@ static int ifopen_payload ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int ifopen_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &ifopen_cmd, ifopen_payload, 0 );
+ return ifcommon_exec ( argc, argv, &ifopen_cmd );
}
-/** "ifclose" command descriptor */
-static struct command_descriptor ifclose_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>...]" );
+/** "ifclose" options */
+struct ifclose_options {};
+
+/** "ifclose" option list */
+static struct option_descriptor ifclose_opts[] = {};
/**
* "ifclose" payload
*
* @v netdev Network device
+ * @v opts Command options
* @ret rc Return status code
*/
-static int ifclose_payload ( struct net_device *netdev ) {
+static int ifclose_payload ( struct net_device *netdev,
+ struct ifclose_options *opts __unused ) {
ifclose ( netdev );
return 0;
}
+/** "ifclose" command descriptor */
+static struct ifcommon_command_descriptor ifclose_cmd =
+ IFCOMMON_COMMAND_DESC ( struct ifclose_options, ifclose_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ ifclose_payload, 0 );
+
/**
* The "ifclose" command
*
@@ -134,25 +148,34 @@ static int ifclose_payload ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int ifclose_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &ifclose_cmd, ifclose_payload, 0 );
+ return ifcommon_exec ( argc, argv, &ifclose_cmd );
}
-/** "ifstat" command descriptor */
-static struct command_descriptor ifstat_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>...]" );
+/** "ifstat" options */
+struct ifstat_options {};
+
+/** "ifstat" option list */
+static struct option_descriptor ifstat_opts[] = {};
/**
* "ifstat" payload
*
* @v netdev Network device
+ * @v opts Command options
* @ret rc Return status code
*/
-static int ifstat_payload ( struct net_device *netdev ) {
+static int ifstat_payload ( struct net_device *netdev,
+ struct ifstat_options *opts __unused ) {
ifstat ( netdev );
return 0;
}
+/** "ifstat" command descriptor */
+static struct ifcommon_command_descriptor ifstat_cmd =
+ IFCOMMON_COMMAND_DESC ( struct ifstat_options, ifstat_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ ifstat_payload, 0 );
+
/**
* The "ifstat" command
*
@@ -161,7 +184,7 @@ static int ifstat_payload ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int ifstat_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &ifstat_cmd, ifstat_payload, 0 );
+ return ifcommon_exec ( argc, argv, &ifstat_cmd );
}
/** Interface management commands */
diff --git a/src/hci/commands/iwmgmt_cmd.c b/src/hci/commands/iwmgmt_cmd.c
index d91ad1e3..b61ee8c7 100644
--- a/src/hci/commands/iwmgmt_cmd.c
+++ b/src/hci/commands/iwmgmt_cmd.c
@@ -32,18 +32,21 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
*/
-/** "iwstat" command descriptor */
-static struct command_descriptor iwstat_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>...]" );
+/** "iwstat" options */
+struct iwstat_options {};
+
+/** "iwstat" option list */
+static struct option_descriptor iwstat_opts[] = {};
/**
* "iwstat" payload
*
* @v netdev Network device
+ * @v opts Command options
* @ret rc Return status code
*/
-static int iwstat_payload ( struct net_device *netdev ) {
+static int iwstat_payload ( struct net_device *netdev,
+ struct iwstat_options *opts __unused ) {
struct net80211_device *dev = net80211_get ( netdev );
if ( dev )
@@ -52,6 +55,12 @@ static int iwstat_payload ( struct net_device *netdev ) {
return 0;
}
+/** "iwstat" command descriptor */
+static struct ifcommon_command_descriptor iwstat_cmd =
+ IFCOMMON_COMMAND_DESC ( struct iwstat_options, iwstat_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ iwstat_payload, 0 );
+
/**
* The "iwstat" command
*
@@ -60,21 +69,24 @@ static int iwstat_payload ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int iwstat_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &iwstat_cmd, iwstat_payload, 0 );
+ return ifcommon_exec ( argc, argv, &iwstat_cmd );
}
-/** "iwlist" command descriptor */
-static struct command_descriptor iwlist_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>...]" );
+/** "iwlist" options */
+struct iwlist_options {};
+
+/** "iwlist" option list */
+static struct option_descriptor iwlist_opts[] = {};
/**
* "iwlist" payload
*
* @v netdev Network device
+ * @v opts Command options
* @ret rc Return status code
*/
-static int iwlist_payload ( struct net_device *netdev ) {
+static int iwlist_payload ( struct net_device *netdev,
+ struct iwlist_options *opts __unused ) {
struct net80211_device *dev = net80211_get ( netdev );
if ( dev )
@@ -83,6 +95,12 @@ static int iwlist_payload ( struct net_device *netdev ) {
return 0;
}
+/** "iwlist" command descriptor */
+static struct ifcommon_command_descriptor iwlist_cmd =
+ IFCOMMON_COMMAND_DESC ( struct iwlist_options, iwlist_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ iwlist_payload, 0 );
+
/**
* The "iwlist" command
*
@@ -91,7 +109,7 @@ static int iwlist_payload ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int iwlist_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &iwlist_cmd, iwlist_payload, 0 );
+ return ifcommon_exec ( argc, argv, &iwlist_cmd );
}
/** Wireless interface management commands */