From: Klas Lindfors Date: Tue, 27 Mar 2012 08:13:56 +0000 (+0200) Subject: new function yk_write_command to support more commands X-Git-Tag: v1.7.0~1^2~62 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d84816ec67b8c4db37c80501a70c23da90d64440;p=yubikey-personalization new function yk_write_command to support more commands let yk_write_config wrap yk_write_command. --- diff --git a/ykcore/ykcore.c b/ykcore/ykcore.c index 200b585..486b032 100644 --- a/ykcore/ykcore.c +++ b/ykcore/ykcore.c @@ -177,13 +177,12 @@ int yk_get_serial(YK_KEY *yk, uint8_t slot, unsigned int flags, unsigned int *se return 1; } -int yk_write_config(YK_KEY *yk, YK_CONFIG *cfg, int confnum, +int yk_write_command(YK_KEY *yk, YK_CONFIG *cfg, uint8_t command, unsigned char *acc_code) { unsigned char buf[sizeof(YK_CONFIG) + ACC_CODE_SIZE]; YK_STATUS stat; int seq; - uint8_t slot; /* Get current sequence # from status block */ @@ -209,17 +208,7 @@ int yk_write_config(YK_KEY *yk, YK_CONFIG *cfg, int confnum, memcpy(buf + sizeof(YK_CONFIG), acc_code, ACC_CODE_SIZE); /* Write to Yubikey */ - - switch(confnum) { - case 1: - slot = SLOT_CONFIG; - break; - case 2: - slot = SLOT_CONFIG2; - break; - } - - if (!yk_write_to_key(yk, slot, buf, sizeof(buf))) + if (!yk_write_to_key(yk, command, buf, sizeof(buf))) return 0; /* When the Yubikey clears the SLOT_WRITE_FLAG, it has processed the last write. @@ -227,7 +216,7 @@ int yk_write_config(YK_KEY *yk, YK_CONFIG *cfg, int confnum, * 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, 0, WAIT_FOR_WRITE_FLAG, false, SLOT_WRITE_FLAG, NULL); + yk_wait_for_key_status(yk, command, 0, WAIT_FOR_WRITE_FLAG, false, SLOT_WRITE_FLAG, NULL); /* Verify update */ @@ -240,7 +229,26 @@ int yk_write_config(YK_KEY *yk, YK_CONFIG *cfg, int confnum, } return stat.pgmSeq == 0; +} +/* deprecated wrapper function for yk_write_command */ +int yk_write_config(YK_KEY *yk, YK_CONFIG *cfg, int confnum, + unsigned char *acc_code) +{ + uint8_t command; + switch(confnum) { + case 1: + command = SLOT_CONFIG; + break; + case 2: + command = SLOT_CONFIG2; + break; + default: + return 0; + } + if(!yk_write_command(yk, cfg, command, acc_code)) { + return 0; + } } int * const _yk_errno_location(void)