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.
* 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 */
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. */