From: Klas Lindfors Date: Mon, 3 Dec 2012 10:08:22 +0000 (+0100) Subject: complete commands for setting usb_mode X-Git-Tag: v1.10.0~20^2~1 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecf56b2f3c4575b3337fdde412267db551e28605;p=yubikey-personalization complete commands for setting usb_mode --- diff --git a/ykpers-args.c b/ykpers-args.c index 1aeb239..1dfcdf9 100644 --- a/ykpers-args.c +++ b/ykpers-args.c @@ -74,9 +74,9 @@ const char *usage = "-mMODE Set the USB operation mode of the YubiKey NEO.\n" " Possible MODE arguments are:\n" " 0 HID device only.\n" -" 1 CCID device only, permanently attached.\n" -" 2 CCID device only, with insert/removal.\n" -" 3 HID/CCID composite device.\n" +" 1 CCID device only.\n" +" 2 HID/CCID composite device.\n" +" Add 80 to set MODE_FLAG_EJECT, for example: 81\n" "-oOPTION change configuration option. Possible OPTION arguments are:\n" " salt=ssssssss Salt to be used when deriving key from a\n" " password. If none is given, a unique random\n" @@ -225,7 +225,7 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, bool *autocommit, char *salt, YK_STATUS *st, bool *verbose, unsigned char *access_code, bool *use_access_code, - bool *aesviahash, char *ndef_type, char *ndef, int *usb_mode, bool *zap, + bool *aesviahash, char *ndef_type, char *ndef, unsigned char *usb_mode, bool *zap, int *exit_code) { int c; @@ -442,10 +442,14 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, *exit_code = 1; return 0; } + if(optarg[0] == '8') { + *usb_mode |= 0x80; + optarg++; + } if(optarg[1] == '\0') { int mode = optarg[0] - '0'; - if(mode >= 0 && mode < 4) { - *usb_mode = mode; + if(mode >= 0 && mode < MODE_MASK) { + *usb_mode |= mode; usb_mode_seen = true; } } @@ -455,7 +459,7 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, *exit_code = 1; return 0; } - if (!ykp_configure_command(cfg, SLOT_USB_MODE)) + if (!ykp_configure_command(cfg, SLOT_DEVICE_CONFIG)) return 0; break; diff --git a/ykpers-args.h b/ykpers-args.h index d42ad38..3f563b8 100644 --- a/ykpers-args.h +++ b/ykpers-args.h @@ -38,7 +38,7 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, bool *autocommit, char *salt, YK_STATUS *st, bool *verbose, unsigned char *access_code, bool *use_access_code, - bool *aesviahash, char *ndef_type, char *ndef, int *usb_mode, + bool *aesviahash, char *ndef_type, char *ndef, unsigned char *usb_mode, bool *zap, int *exit_code); void report_yk_error(void); diff --git a/ykpers.c b/ykpers.c index 0daf6fe..f800d48 100644 --- a/ykpers.c +++ b/ykpers.c @@ -185,9 +185,9 @@ int ykp_configure_command(YKP_CONFIG *cfg, uint8_t command) } break; /* TODO: Make sure this is correct */ - case SLOT_USB_MODE: + case SLOT_DEVICE_CONFIG: /* For testing only */ - if(!(cfg->yk_major_version == 2 && cfg->yk_minor_version == 3 && cfg->yk_build_version == 1)) { + if(!(cfg->yk_major_version >= 3)) { ykp_errno = YKP_EYUBIKEYVER; return 0; } diff --git a/ykpersonalize.c b/ykpersonalize.c index f868101..6c4e171 100644 --- a/ykpersonalize.c +++ b/ykpersonalize.c @@ -67,7 +67,7 @@ int main(int argc, char **argv) char *salt = NULL; char ndef_string[128] = {0}; char ndef_type = 0; - int usb_mode = -1; + unsigned char usb_mode = 0; bool zap = false; bool error = false; @@ -205,8 +205,8 @@ int main(int argc, char **argv) fprintf(stderr, "Configuration in slot 1 and 2 will be swapped\n"); } else if(ykp_command(cfg) == SLOT_NDEF || ykp_command(cfg) == SLOT_NDEF2) { fprintf(stderr, "New NDEF will be written as:\n%s\n", ndef_string); - } else if(ykp_command(cfg) == SLOT_USB_MODE) { - fprintf(stderr, "The USB mode will be set to: %d\n", usb_mode); + } else if(ykp_command(cfg) == SLOT_DEVICE_CONFIG) { + fprintf(stderr, "The USB mode will be set to: 0x%x\n", usb_mode); } else if(zap) { fprintf(stderr, "Configuration in slot %d will be deleted\n", ykp_config_num(cfg)); } else { @@ -253,12 +253,15 @@ int main(int argc, char **argv) goto err; } ykp_free_ndef(ndef); - } else if(ykp_command(cfg) == SLOT_USB_MODE) { - if(!yk_set_usb_mode(yk, usb_mode)) { + } else if(ykp_command(cfg) == SLOT_DEVICE_CONFIG) { + YK_DEVICE_CONFIG *device_config = ykp_alloc_device_config(); + ykp_set_device_mode(device_config, usb_mode); + if(!yk_write_device_config(yk, device_config)) { if(verbose) printf(" failure\n"); goto err; } + ykp_free_device_config(device_config); } else { YK_CONFIG *ycfg = NULL; /* if we're deleting a slot we send the configuration as NULL */