diff options
Diffstat (limited to 'gpxe/src/hci/commands')
-rw-r--r-- | gpxe/src/hci/commands/autoboot_cmd.c | 2 | ||||
-rw-r--r-- | gpxe/src/hci/commands/config_cmd.c | 2 | ||||
-rw-r--r-- | gpxe/src/hci/commands/dhcp_cmd.c | 2 | ||||
-rw-r--r-- | gpxe/src/hci/commands/digest_cmd.c | 120 | ||||
-rw-r--r-- | gpxe/src/hci/commands/ifmgmt_cmd.c | 21 | ||||
-rw-r--r-- | gpxe/src/hci/commands/image_cmd.c | 25 | ||||
-rw-r--r-- | gpxe/src/hci/commands/iwmgmt_cmd.c | 69 | ||||
-rw-r--r-- | gpxe/src/hci/commands/login_cmd.c | 2 | ||||
-rw-r--r-- | gpxe/src/hci/commands/nvo_cmd.c | 2 | ||||
-rw-r--r-- | gpxe/src/hci/commands/route_cmd.c | 2 | ||||
-rw-r--r-- | gpxe/src/hci/commands/sanboot_cmd.c | 2 | ||||
-rw-r--r-- | gpxe/src/hci/commands/time_cmd.c | 84 |
12 files changed, 319 insertions, 14 deletions
diff --git a/gpxe/src/hci/commands/autoboot_cmd.c b/gpxe/src/hci/commands/autoboot_cmd.c index 0e6f2948..95b172d1 100644 --- a/gpxe/src/hci/commands/autoboot_cmd.c +++ b/gpxe/src/hci/commands/autoboot_cmd.c @@ -2,6 +2,8 @@ #include <gpxe/command.h> #include <usr/autoboot.h> +FILE_LICENCE ( GPL2_OR_LATER ); + static int autoboot_exec ( int argc, char **argv ) { if ( argc != 1 ) { diff --git a/gpxe/src/hci/commands/config_cmd.c b/gpxe/src/hci/commands/config_cmd.c index 87abb05a..a9e1f169 100644 --- a/gpxe/src/hci/commands/config_cmd.c +++ b/gpxe/src/hci/commands/config_cmd.c @@ -4,6 +4,8 @@ #include <gpxe/settings.h> #include <gpxe/settings_ui.h> +FILE_LICENCE ( GPL2_OR_LATER ); + static int config_exec ( int argc, char **argv ) { char *settings_name; struct settings *settings; diff --git a/gpxe/src/hci/commands/dhcp_cmd.c b/gpxe/src/hci/commands/dhcp_cmd.c index 9b577c86..96aac8d4 100644 --- a/gpxe/src/hci/commands/dhcp_cmd.c +++ b/gpxe/src/hci/commands/dhcp_cmd.c @@ -16,6 +16,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +FILE_LICENCE ( GPL2_OR_LATER ); + #include <stdio.h> #include <stdint.h> #include <stdlib.h> diff --git a/gpxe/src/hci/commands/digest_cmd.c b/gpxe/src/hci/commands/digest_cmd.c new file mode 100644 index 00000000..bc6e5516 --- /dev/null +++ b/gpxe/src/hci/commands/digest_cmd.c @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2009 Daniel Verkamp <daniel@drv.nu>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <gpxe/command.h> +#include <gpxe/image.h> +#include <gpxe/crypto.h> + +#include <gpxe/md5.h> +#include <gpxe/sha1.h> + +/** + * "digest" command syntax message + * + * @v argv Argument list + */ +static void digest_syntax ( char **argv ) { + printf ( "Usage:\n" + " %s <image name>\n" + "\n" + "Calculate the %s of an image\n", + argv[0], argv[0] ); +} + +/** + * The "digest" command + * + * @v argc Argument count + * @v argv Argument list + * @v digest Digest algorithm + * @ret rc Exit code + */ +static int digest_exec ( int argc, char **argv, + struct digest_algorithm *digest ) { + const char *image_name; + struct image *image; + uint8_t digest_ctx[digest->ctxsize]; + uint8_t digest_out[digest->digestsize]; + uint8_t buf[128]; + size_t offset; + size_t len; + size_t frag_len; + int i; + unsigned j; + + if ( argc < 2 || + !strcmp ( argv[1], "--help" ) || + !strcmp ( argv[1], "-h" ) ) { + digest_syntax ( argv ); + return 1; + } + + for ( i = 1 ; i < argc ; i++ ) { + image_name = argv[i]; + + /* find image */ + image = find_image ( image_name ); + if ( ! image ) { + printf ( "No such image: %s\n", image_name ); + continue; + } + offset = 0; + len = image->len; + + /* calculate digest */ + digest_init ( digest, digest_ctx ); + while ( len ) { + frag_len = len; + if ( frag_len > sizeof ( buf ) ) + frag_len = sizeof ( buf ); + copy_from_user ( buf, image->data, offset, frag_len ); + digest_update ( digest, digest_ctx, buf, frag_len ); + len -= frag_len; + offset += frag_len; + } + digest_final ( digest, digest_ctx, digest_out ); + + for ( j = 0 ; j < sizeof ( digest_out ) ; j++ ) + printf ( "%02x", digest_out[j] ); + + printf ( " %s\n", image->name ); + } + + return 0; +} + +static int md5sum_exec ( int argc, char **argv ) { + return digest_exec ( argc, argv, &md5_algorithm ); +} + +static int sha1sum_exec ( int argc, char **argv ) { + return digest_exec ( argc, argv, &sha1_algorithm ); +} + +struct command md5sum_command __command = { + .name = "md5sum", + .exec = md5sum_exec, +}; + +struct command sha1sum_command __command = { + .name = "sha1sum", + .exec = sha1sum_exec, +}; diff --git a/gpxe/src/hci/commands/ifmgmt_cmd.c b/gpxe/src/hci/commands/ifmgmt_cmd.c index f2508e55..ad069f14 100644 --- a/gpxe/src/hci/commands/ifmgmt_cmd.c +++ b/gpxe/src/hci/commands/ifmgmt_cmd.c @@ -16,11 +16,14 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +FILE_LICENCE ( GPL2_OR_LATER ); + #include <stdio.h> #include <getopt.h> #include <gpxe/netdevice.h> #include <gpxe/command.h> #include <usr/ifmgmt.h> +#include <hci/ifmgmt_cmd.h> /** @file * @@ -95,15 +98,15 @@ static int ifcommon_do_list ( int ( * payload ) ( struct net_device * ), /** * Execute if<xxx> command * - * @v payload Command to execute - * @v verb Verb describing the action of the command * @v argc Argument count * @v argv Argument list + * @v payload Command to execute + * @v verb Verb describing the action of the command * @ret rc Exit code */ -static __attribute__ (( regparm ( 2 ) )) int -ifcommon_exec ( int ( * payload ) ( struct net_device * ), - const char *verb, int argc, char **argv ) { +int ifcommon_exec ( int argc, char **argv, + int ( * payload ) ( struct net_device * ), + const char *verb ) { int c; /* Parse options */ @@ -134,7 +137,7 @@ static int ifopen_payload ( struct net_device *netdev ) { } static int ifopen_exec ( int argc, char **argv ) { - return ifcommon_exec ( ifopen_payload, "Open", argc, argv ); + return ifcommon_exec ( argc, argv, ifopen_payload, "Open" ); } /* "ifclose" command */ @@ -145,7 +148,7 @@ static int ifclose_payload ( struct net_device *netdev ) { } static int ifclose_exec ( int argc, char **argv ) { - return ifcommon_exec ( ifclose_payload, "Close", argc, argv ); + return ifcommon_exec ( argc, argv, ifclose_payload, "Close" ); } /* "ifstat" command */ @@ -156,8 +159,8 @@ static int ifstat_payload ( struct net_device *netdev ) { } static int ifstat_exec ( int argc, char **argv ) { - return ifcommon_exec ( ifstat_payload, "Display status of", - argc, argv ); + return ifcommon_exec ( argc, argv, + ifstat_payload, "Display status of" ); } /** Interface management commands */ diff --git a/gpxe/src/hci/commands/image_cmd.c b/gpxe/src/hci/commands/image_cmd.c index 6d8b5908..33994b51 100644 --- a/gpxe/src/hci/commands/image_cmd.c +++ b/gpxe/src/hci/commands/image_cmd.c @@ -16,6 +16,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +FILE_LICENCE ( GPL2_OR_LATER ); + #include <stdint.h> #include <stdlib.h> #include <stdio.h> @@ -497,9 +499,9 @@ static int imgstat_exec ( int argc, char **argv ) { */ static void imgfree_syntax ( char **argv ) { printf ( "Usage:\n" - " %s\n" + " %s [<image name>]\n" "\n" - "Free all executable/loadable images\n", + "Free one or all executable/loadable images\n", argv[0] ); } @@ -517,6 +519,7 @@ static int imgfree_exec ( int argc, char **argv ) { }; struct image *image; struct image *tmp; + const char *name = NULL; int c; /* Parse options */ @@ -531,15 +534,27 @@ static int imgfree_exec ( int argc, char **argv ) { } } - /* No arguments */ + /* Need no more than one image name */ + if ( optind != argc ) + name = argv[optind++]; if ( optind != argc ) { imgfree_syntax ( argv ); return 1; } - /* Free all images */ - list_for_each_entry_safe ( image, tmp, &images, list ) { + if ( name ) { + /* Free specified image (may leak) */ + image = find_image ( name ); + if ( ! image ) { + printf ( "No such image: %s\n", name ); + return 1; + } imgfree ( image ); + } else { + /* Free all images */ + list_for_each_entry_safe ( image, tmp, &images, list ) { + imgfree ( image ); + } } return 0; } diff --git a/gpxe/src/hci/commands/iwmgmt_cmd.c b/gpxe/src/hci/commands/iwmgmt_cmd.c new file mode 100644 index 00000000..006c9f1d --- /dev/null +++ b/gpxe/src/hci/commands/iwmgmt_cmd.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009 Joshua Oreman <oremanj@rwcr.net>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <gpxe/netdevice.h> +#include <gpxe/net80211.h> +#include <gpxe/command.h> +#include <usr/iwmgmt.h> +#include <hci/ifmgmt_cmd.h> + +/* "iwstat" command */ + +static int iwstat_payload ( struct net_device *netdev ) { + struct net80211_device *dev = net80211_get ( netdev ); + + if ( dev ) + iwstat ( dev ); + + return 0; +} + +static int iwstat_exec ( int argc, char **argv ) { + return ifcommon_exec ( argc, argv, + iwstat_payload, "Display wireless status of" ); +} + +/* "iwlist" command */ + +static int iwlist_payload ( struct net_device *netdev ) { + struct net80211_device *dev = net80211_get ( netdev ); + + if ( dev ) + return iwlist ( dev ); + + return 0; +} + +static int iwlist_exec ( int argc, char **argv ) { + return ifcommon_exec ( argc, argv, iwlist_payload, + "List wireless networks available via" ); +} + +/** Wireless interface management commands */ +struct command iwmgmt_commands[] __command = { + { + .name = "iwstat", + .exec = iwstat_exec, + }, + { + .name = "iwlist", + .exec = iwlist_exec, + }, +}; diff --git a/gpxe/src/hci/commands/login_cmd.c b/gpxe/src/hci/commands/login_cmd.c index e425247d..0da2497a 100644 --- a/gpxe/src/hci/commands/login_cmd.c +++ b/gpxe/src/hci/commands/login_cmd.c @@ -3,6 +3,8 @@ #include <gpxe/command.h> #include <gpxe/login_ui.h> +FILE_LICENCE ( GPL2_OR_LATER ); + static int login_exec ( int argc, char **argv ) { int rc; diff --git a/gpxe/src/hci/commands/nvo_cmd.c b/gpxe/src/hci/commands/nvo_cmd.c index c0c07280..5eb2f06f 100644 --- a/gpxe/src/hci/commands/nvo_cmd.c +++ b/gpxe/src/hci/commands/nvo_cmd.c @@ -7,6 +7,8 @@ #include <gpxe/settings.h> #include <gpxe/command.h> +FILE_LICENCE ( GPL2_OR_LATER ); + static int show_exec ( int argc, char **argv ) { char buf[256]; int rc; diff --git a/gpxe/src/hci/commands/route_cmd.c b/gpxe/src/hci/commands/route_cmd.c index 227682cb..4372e34f 100644 --- a/gpxe/src/hci/commands/route_cmd.c +++ b/gpxe/src/hci/commands/route_cmd.c @@ -16,6 +16,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +FILE_LICENCE ( GPL2_OR_LATER ); + #include <stdio.h> #include <getopt.h> #include <gpxe/command.h> diff --git a/gpxe/src/hci/commands/sanboot_cmd.c b/gpxe/src/hci/commands/sanboot_cmd.c index d5bbfb85..783b747b 100644 --- a/gpxe/src/hci/commands/sanboot_cmd.c +++ b/gpxe/src/hci/commands/sanboot_cmd.c @@ -4,6 +4,8 @@ #include <gpxe/command.h> #include <usr/autoboot.h> +FILE_LICENCE ( GPL2_OR_LATER ); + /** * "sanboot" command syntax message * diff --git a/gpxe/src/hci/commands/time_cmd.c b/gpxe/src/hci/commands/time_cmd.c new file mode 100644 index 00000000..947410ec --- /dev/null +++ b/gpxe/src/hci/commands/time_cmd.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2009 Daniel Verkamp <daniel@drv.nu>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * March-19-2009 @ 02:44: Added sleep command. + * Shao Miller <shao.miller@yrdsb.edu.on.ca>. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <gpxe/command.h> +#include <gpxe/nap.h> +#include <gpxe/timer.h> + +static int time_exec ( int argc, char **argv ) { + unsigned long start; + int rc, secs; + + if ( argc == 1 || + !strcmp ( argv[1], "--help" ) || + !strcmp ( argv[1], "-h" ) ) + { + printf ( "Usage:\n" + " %s <command>\n" + "\n" + "Time a command\n", + argv[0] ); + return 1; + } + + start = currticks(); + rc = execv ( argv[1], argv + 1 ); + secs = (currticks() - start) / ticks_per_sec(); + + printf ( "%s: %ds\n", argv[0], secs ); + + return rc; +} + +struct command time_command __command = { + .name = "time", + .exec = time_exec, +}; + +static int sleep_exec ( int argc, char **argv ) { + unsigned long start, delay; + + if ( argc == 1 || + !strcmp ( argv[1], "--help" ) || + !strcmp ( argv[1], "-h" )) + { + printf ( "Usage:\n" + " %s <seconds>\n" + "\n" + "Sleep for <seconds> seconds\n", + argv[0] ); + return 1; + } + start = currticks(); + delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec(); + while ( ( currticks() - start ) <= delay ) + cpu_nap(); + return 0; +} + +struct command sleep_command __command = { + .name = "sleep", + .exec = sleep_exec, +}; |