aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShao Miller <sha0.miller@gmail.com>2012-11-23 15:36:52 -0500
committerShao Miller <sha0.miller@gmail.com>2012-11-23 15:38:08 -0500
commited69c5dc846109f2bd0f5ec14fd7ea87470bd569 (patch)
tree77a51e73204af67f0afad6534c7178b7056bd604
parenta5cd086b9c1b81ea45b40596afe1d587d5c2c9cd (diff)
downloadsyslinux-nictype.tar.gz
syslinux-nictype.tar.xz
syslinux-nictype.zip
nictype.c32: Accept --label and --fallback optionsnictype
This is a pretty major change. CardBus NICs are now supported, along with two new options. The new usage statement is: Usage: nictype.c32 [--config | --label] [--fallback <command>] --config will try to load a config-file with the name VVVVDDDD --label will try to jump to a label with name VVVVDDDD --fallback specifies a label or command to run if --config fails VVVV is the VENdor code and DDDD is the DEVice code, for PCI and CardBus NICs. Signed-off-by: Shao Miller <sha0.miller@gmail.com>
-rw-r--r--com32/modules/nictype.c149
1 files changed, 113 insertions, 36 deletions
diff --git a/com32/modules/nictype.c b/com32/modules/nictype.c
index 5af7fa90..0cde021d 100644
--- a/com32/modules/nictype.c
+++ b/com32/modules/nictype.c
@@ -27,6 +27,16 @@
#undef Countof
#define Countof(array) (sizeof (array) / sizeof *(array))
+enum {
+ flag_config_pos,
+ flag_label_pos,
+ flag_ids_supported_pos,
+ flag_config = 1 << flag_config_pos,
+ flag_label = 1 << flag_label_pos,
+ flag_ids_supported = 1 << flag_ids_supported_pos,
+ flags_empty = 0
+};
+
static int usage(void);
static const char *nic_type_names[] = {
@@ -38,10 +48,13 @@ static const char *nic_type_names[] = {
};
static const char *prog_name = "nictype.c32";
+static int flags = flags_empty;
+static const char *fallback;
int main(int argc, char **argv)
{
int status;
+ int arg;
t_PXENV_UNDI_GET_NIC_TYPE nic_type_info;
char vvvvdddd[] = "VVVVDDDD";
@@ -57,6 +70,48 @@ int main(int argc, char **argv)
--argc;
++argv;
+ for (arg = 0; arg < argc; ++arg, ++argv) {
+ if (!argv[0]) {
+ fprintf(stderr, "argc and argv mismatch!\n");
+ status = EXIT_FAILURE;
+ goto err_argv;
+ }
+
+ if (!strncmp(argv[0], "--config", sizeof "--config")) {
+ flags |= flag_config;
+ continue;
+ }
+
+ if (!strncmp(argv[0], "--label", sizeof "--label")) {
+ flags |= flag_label;
+ continue;
+ }
+
+ if (!strncmp(argv[0], "--fallback", sizeof "--fallback")) {
+ if (arg + 1 == argc || !argv[1]) {
+ fprintf(stderr, "--fallback command not provided\n");
+ return usage();
+ }
+ fallback = argv[1];
+ ++arg;
+ ++argv;
+ continue;
+ }
+
+ return usage();
+ }
+
+ /* Check mode */
+ if (flags & flag_config && flags & flag_label) {
+ fprintf(stderr, "--config and --label are mutually exclusive\n");
+ return usage();
+ }
+
+ if (fallback && !(flags & flag_config)) {
+ fprintf(stderr, "--fallback requires --config at this time\n");
+ return usage();
+ }
+
status = pxe_get_nic_type(&nic_type_info);
if (status == -1 || status != PXENV_STATUS_SUCCESS) {
fprintf(stderr, "pxe_get_nic_type failure. PXELINUX required.\n");
@@ -66,49 +121,66 @@ int main(int argc, char **argv)
/* Unknown NIC type? */
if (nic_type_info.NicType >= Countof(nic_type_names))
nic_type_info.NicType = 0;
-
- printf("NIC type: %s\n", nic_type_names[nic_type_info.NicType]);
-
- if (argc > 1 || (argc == 1 && argv[0] &&
- strncmp(argv[0], "--config",
- sizeof "--config"))) {
- status = usage();
- goto err_usage;
+ printf("NIC bus type: %s\n", nic_type_names[nic_type_info.NicType]);
+
+ if (nic_type_info.NicType == PCI_NIC ||
+ nic_type_info.NicType == CardBus_NIC) {
+ flags |= flag_ids_supported;
+
+ status = sprintf(vvvvdddd, "%04X%04X",
+ nic_type_info.info.pci.Vendor_ID,
+ nic_type_info.info.pci.Dev_ID);
+ if (status != sizeof vvvvdddd - 1) {
+ fprintf(stderr,
+ "Error constructing PCI VENdor and DEVice string\n");
+ status = EXIT_FAILURE;
+ goto err_vvvvdddd;
+ }
+ printf("VENdor and DEVice IDs: %s\n", vvvvdddd);
}
-
- if (argc == 0) {
- status = EXIT_SUCCESS;
- goto out;
- }
-
- if (nic_type_info.NicType != PCI_NIC) {
- fprintf(stderr, "NIC type not supported for --config\n");
- goto err_config_nic_type;
+ status = EXIT_SUCCESS;
+
+ if (flags & flag_config) {
+ if (!(flags & flag_ids_supported)) {
+ fprintf(stderr, "NIC bus type not supported for --config\n");
+ goto err_config_nic_bus_type;
+ }
+
+ printf("Loading config-file '%s'...\n", vvvvdddd);
+ syslinux_run_kernel_image(vvvvdddd, "", 0, IMAGE_TYPE_CONFIG);
+ fprintf(stderr, "Failed to load config-file\n");
+ if (fallback) {
+ printf("Falling back to command '%s'...\n", fallback);
+ syslinux_run_command(fallback);
+ }
+ err_config_nic_bus_type:
+ status = EXIT_FAILURE;
}
- status = sprintf(vvvvdddd, "%04X%04X", nic_type_info.info.pci.Vendor_ID,
- nic_type_info.info.pci.Dev_ID);
- if (status != sizeof vvvvdddd - 1) {
- fprintf(stderr, "Error constructing PCI VENdor and DEVice string\n");
+ if (flags & flag_label) {
+ if (!(flags & flag_ids_supported)) {
+ fprintf(stderr, "NIC bus type not supported for --label\n");
+ goto err_label_nic_bus_type;
+ }
+
+ printf("Jumping to label '%s'...\n", vvvvdddd);
+ syslinux_run_command(vvvvdddd);
+ /* Can't get here, but if we somehow do... */
+ fprintf(stderr, "Failed to jump to label\n");
+ if (fallback) {
+ printf("Falling back to command '%s'...\n", fallback);
+ syslinux_run_command(fallback);
+ }
+ err_label_nic_bus_type:
status = EXIT_FAILURE;
- goto err_vvvvdddd;
}
- printf("Loading config-file '%s'...\n", vvvvdddd);
- syslinux_run_kernel_image(vvvvdddd, "", 0, IMAGE_TYPE_CONFIG);
- fprintf(stderr, "Failed to load config-file\n");
- status = EXIT_FAILURE;
-
err_vvvvdddd:
- err_config_nic_type:
-
- out:
-
- err_usage:
-
err_nic_type_info:
+ err_argv:
+
err_prog_name:
return status;
@@ -117,10 +189,15 @@ int main(int argc, char **argv)
static int usage(void)
{
const char text[] =
-"Usage: %s [--config]\n"
"\n"
-"--config will try to load a config-file with the name VVVVDDDD, where VVVV\n"
-"is the PCI VENdor code and DDDD is the PCI DEVice code, both for the NIC\n";
+"Usage: %s [--config | --label] [--fallback <command>]\n"
+"\n"
+" --config will try to load a config-file with the name VVVVDDDD\n"
+" --label will try to jump to a label with name VVVVDDDD\n"
+" --fallback specifies a label or command to run if --config fails\n"
+"\n"
+"VVVV is the VENdor code and DDDD is the DEVice code, for PCI and\n"
+"CardBus NICs.\n\n";
fprintf(stderr, text, prog_name);
return EXIT_FAILURE;