From: Fredrik Thulin Date: Thu, 3 Nov 2011 11:00:22 +0000 (+0100) Subject: Define YK_DEBUG to get hex dumps of USB read/writes. X-Git-Tag: v1.6.2~4 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c582d007ca884251cca9b8a4bdfd76c6a33d150;p=yubikey-personalization.old Define YK_DEBUG to get hex dumps of USB read/writes. --- diff --git a/ykcore/ykcore.c b/ykcore/ykcore.c index ca1083d..80a1a23 100644 --- a/ykcore/ykcore.c +++ b/ykcore/ykcore.c @@ -425,6 +425,9 @@ int yk_read_response_from_key(YK_KEY *yk, uint8_t slot, unsigned int flags, memset(buf, 0, bufsize); *bytes_read = 0; +#ifdef YK_DEBUG + fprintf(stderr, "YK_DEBUG: Read %i bytes from YubiKey :\n", expect_bytes); +#endif /* Wait for the key to turn on RESP_PENDING_FLAG */ if (! yk_wait_for_key_status(yk, slot, flags, 1000, true, RESP_PENDING_FLAG, (char *) &data)) return 0; @@ -440,7 +443,9 @@ int yk_read_response_from_key(YK_KEY *yk, uint8_t slot, unsigned int flags, if (!_ykusb_read(yk, REPORT_TYPE_FEATURE, 0, (char *)data, FEATURE_RPT_SIZE)) return 0; - +#ifdef YK_DEBUG + _yk_hexdump(data, FEATURE_RPT_SIZE); +#endif if (data[FEATURE_RPT_SIZE - 1] & RESP_PENDING_FLAG) { /* The lower five bits of the status byte has the response sequence * number. If that gets reset to zero we are done. @@ -523,6 +528,9 @@ int yk_write_to_key(YK_KEY *yk, uint8_t slot, const void *buf, int bufcount) if (! yk_wait_for_key_status(yk, slot, 0, 1000, false, SLOT_WRITE_FLAG, NULL)) return 0; */ +#ifdef YK_DEBUG + fprintf(stderr, "YK_DEBUG: Write %i bytes to YubiKey :\n", bufcount); +#endif for (seq = 0; ptr < end; seq++) { int all_zeros = 1; /* Ignore parts that are all zeroes except first and last @@ -543,7 +551,9 @@ int yk_write_to_key(YK_KEY *yk, uint8_t slot, const void *buf, int bufcount) if (! yk_wait_for_key_status(yk, slot, 0, WAIT_FOR_WRITE_FLAG, false, SLOT_WRITE_FLAG, NULL)) return 0; - +#ifdef YK_DEBUG + _yk_hexdump(repbuf, FEATURE_RPT_SIZE); +#endif if (!_ykusb_write(yk, REPORT_TYPE_FEATURE, 0, (char *)repbuf, FEATURE_RPT_SIZE)) return 0;