From: Klas Lindfors Date: Mon, 3 Dec 2012 09:54:27 +0000 (+0100) Subject: change around to work with device_config instead of raw mode X-Git-Tag: v1.10.0~20^2~2 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4e6b3dd95df0ea419fac5a6c5f2a1aa53c2fc7f;p=yubikey-personalization change around to work with device_config instead of raw mode --- diff --git a/libykpers-1.map b/libykpers-1.map index 56dab36..6603490 100644 --- a/libykpers-1.map +++ b/libykpers-1.map @@ -168,7 +168,7 @@ LIBYKPERS_1.10 { yk_write_ndef2; ykp_ndef_as_text; yk_check_firmware_version2; - yk_set_usb_mode; + yk_set_device_config; ykp_alloc_device_config; ykp_free_device_config; ykp_set_device_mode; diff --git a/ykcore/ykcore.c b/ykcore/ykcore.c index 5b1ed4d..7a245d2 100644 --- a/ykcore/ykcore.c +++ b/ykcore/ykcore.c @@ -312,27 +312,23 @@ int yk_write_ndef2(YK_KEY *yk, YK_NDEF *ndef, int confnum) return stat.pgmSeq != seq; } -int yk_set_usb_mode(YK_KEY *yk, int usb_mode) +int yk_write_device_config(YK_KEY *yk, YK_DEVICE_CONFIG *device_config) { - if(!(usb_mode >= 0 && usb_mode < 4)) { - yk_errno = YK_EINVALIDCMD; - return 1; - } - - unsigned char buf[sizeof(YK_NDEF)]; + unsigned char buf[sizeof(YK_DEVICE_CONFIG)]; YK_STATUS stat; int seq; + memset(buf, 0, sizeof(buf)); + memcpy(buf, device_config, sizeof(YK_DEVICE_CONFIG)); + /* Get current sequence # from status block */ if (!yk_get_status(yk, &stat)) return 0; seq = stat.pgmSeq; - fprintf(stderr, "Pretending to set the USB mode to: %d\n", usb_mode); - /* Write to Yubikey */ - if(/*TODO: !yk_write_to_key(yk, SLOT_USB_MODE, buf, sizeof(buf)) */ 1 == 2) + if(!yk_write_to_key(yk, SLOT_DEVICE_CONFIG, buf, sizeof(buf))) return 0; /* When the Yubikey clears the SLOT_WRITE_FLAG, it has processed the last write. @@ -340,7 +336,7 @@ int yk_set_usb_mode(YK_KEY *yk, int usb_mode) * want to get the bytes in the status message, but when writing configuration * we don't expect any data back. */ - yk_wait_for_key_status(yk, SLOT_USB_MODE, 0, WAIT_FOR_WRITE_FLAG, false, SLOT_WRITE_FLAG, NULL); + yk_wait_for_key_status(yk, SLOT_DEVICE_CONFIG, 0, WAIT_FOR_WRITE_FLAG, false, SLOT_WRITE_FLAG, NULL); /* Verify update */ diff --git a/ykcore/ykcore.h b/ykcore/ykcore.h index f7acaf0..ea2fccb 100644 --- a/ykcore/ykcore.h +++ b/ykcore/ykcore.h @@ -121,6 +121,8 @@ extern int yk_write_config(YK_KEY *k, YK_CONFIG *cfg, int confnum, extern int yk_write_ndef(YK_KEY *yk, YK_NDEF *ndef); /* writes the given ndef to the key. */ extern int yk_write_ndef2(YK_KEY *yk, YK_NDEF *ndef, int confnum); +/* writes a device config block to the key. */ +extern int yk_write_device_config(YK_KEY *yk, YK_DEVICE_CONFIG *device_config); /* Write something to the YubiKey (a command that is). */ extern int yk_write_to_key(YK_KEY *yk, uint8_t slot, const void *buf, int bufcount); /* Do a challenge-response round with the key. */