]> err.no Git - yubikey-personalization/commitdiff
complete commands for setting usb_mode
authorKlas Lindfors <klas@yubico.com>
Mon, 3 Dec 2012 10:08:22 +0000 (11:08 +0100)
committerKlas Lindfors <klas@yubico.com>
Mon, 3 Dec 2012 10:08:22 +0000 (11:08 +0100)
ykpers-args.c
ykpers-args.h
ykpers.c
ykpersonalize.c

index 1aeb2398465a7701cae2e5f25754a0c65042f258..1dfcdf9f01245fec42783ba0cd9163d8d7cc0969 100644 (file)
@@ -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;
index d42ad3823a2c47aee2f96e14125ba6a32c8d1bf0..3f563b88826b194abb75d65f02ba519231104000 100644 (file)
@@ -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);
index 0daf6fecd1273cfe7d5e931a3f4f1dce15b3f157..f800d485fe83d425d6b078fe729848291ceedfbb 100644 (file)
--- 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;
                }
index f8681010e4df7bebdacd5434d7235f7566676f2b..6c4e1716dfa1a5afe95ecbc8d442acce2e9bb2ea 100644 (file)
@@ -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 */