*
*/
-/** "startpxe" command descriptor */
-static struct command_descriptor startpxe_cmd =
- COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
- "[<interface>]" );
+/** "startpxe" options */
+struct startpxe_options {};
+
+/** "startpxe" option list */
+static struct option_descriptor startpxe_opts[] = {};
/**
* "startpxe" payload
*
* @v netdev Network device
+ * @v opts Command options
* @ret rc Return status code
*/
-static int startpxe_payload ( struct net_device *netdev ) {
+static int startpxe_payload ( struct net_device *netdev,
+ struct startpxe_options *opts __unused ) {
if ( netdev_is_open ( netdev ) )
pxe_activate ( netdev );
return 0;
}
+/** "startpxe" command descriptor */
+static struct ifcommon_command_descriptor startpxe_cmd =
+ IFCOMMON_COMMAND_DESC ( struct startpxe_options, startpxe_opts,
+ 0, MAX_ARGUMENTS, "[<interface>]",
+ startpxe_payload, 0 );
+
/**
* The "startpxe" command
*
* @ret rc Return status code
*/
static int startpxe_exec ( int argc, char **argv ) {
- return ifcommon_exec ( argc, argv, &startpxe_cmd, startpxe_payload, 0 );
+ return ifcommon_exec ( argc, argv, &startpxe_cmd );
}
/** "stoppxe" options */
*
*/
+/** "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
* @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 */
*
*/
-/** "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 ) {
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
*
* @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 */
*
*/
-/** "if<xxx>" command options */
-struct option_descriptor ifcommon_opts[0];
-
/**
* Execute if<xxx> command
*
* @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 ) {
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;
}
}
/* 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;
}
}
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
*
* @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
*
* @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
*
* @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 */
*
*/
-/** "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 )
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
*
* @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 )
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
*
* @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 */
struct net_device;
-struct ifcommon_options {};
+/** An "if<xxx>" command descriptor */
+struct ifcommon_command_descriptor {
+ /** Command descriptor */
+ struct command_descriptor cmd;
+ /** Payload
+ *
+ * @v netdev Network device
+ * @v opts Command options
+ * @ret rc Return status code
+ */
+ int ( * payload ) ( struct net_device *netdev, void *opts );
+ /** Stop on first success */
+ int stop_on_first_success;
+};
-extern struct option_descriptor ifcommon_opts[0];
+/**
+ * Construct "if<xxx>" command descriptor
+ *
+ * @v _struct Options structure type
+ * @v _options Option descriptor array
+ * @v _check_args Remaining argument checker
+ * @v _usage Command usage
+ * @ret _command Command descriptor
+ */
+#define IFCOMMON_COMMAND_DESC( _struct, _options, _min_args, \
+ _max_args, _usage, _payload, \
+ _stop_on_first_success ) \
+ { \
+ .cmd = COMMAND_DESC ( _struct, _options, _min_args, \
+ _max_args, _usage ), \
+ .payload = ( ( int ( * ) ( struct net_device *netdev, \
+ void *opts ) ) \
+ ( ( ( ( int ( * ) ( struct net_device *, \
+ _struct * ) ) NULL ) \
+ == ( typeof ( _payload ) * ) NULL ) \
+ ? _payload : _payload ) ), \
+ .stop_on_first_success = _stop_on_first_success, \
+ }
extern int ifcommon_exec ( int argc, char **argv,
- struct command_descriptor *cmd,
- int ( * payload ) ( struct net_device * ),
- int stop_on_first_success );
+ struct ifcommon_command_descriptor *cmd );
#endif /* _IFMGMT_CMD_H */