use sc_debug_hex for hexdump
This commit is contained in:
parent
91aad373be
commit
ef40021417
|
@ -171,23 +171,6 @@ static int sc_apdu2bytes(sc_context_t *ctx, const sc_apdu_t *apdu,
|
|||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
void sc_apdu_log(sc_context_t *ctx, int level, const u8 *data, size_t len, int is_out)
|
||||
{
|
||||
size_t blen = len * 5 + 128;
|
||||
char *buf = malloc(blen);
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
sc_hex_dump(ctx, level, data, len, buf, blen);
|
||||
|
||||
sc_debug(ctx, level, "\n%s APDU data [%5u bytes] =====================================\n"
|
||||
"%s"
|
||||
"======================================================================\n",
|
||||
is_out != 0 ? "Outgoing" : "Incoming", len,
|
||||
buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int sc_apdu_get_octets(sc_context_t *ctx, const sc_apdu_t *apdu, u8 **buf,
|
||||
size_t *len, unsigned int proto)
|
||||
{
|
||||
|
|
|
@ -515,7 +515,8 @@ static int select_file_id(sc_card_t *card, const u8 *buf, size_t buflen,
|
|||
u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
|
||||
sc_file_t *file;
|
||||
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called, p1=%u, path=%s\n", p1, sc_dump_hex(buf, buflen));
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called, p1=%u\n", p1);
|
||||
sc_debug_hex(card->ctx, SC_LOG_DEBUG_NORMAL, "path", buf, buflen);
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, p1, 0);
|
||||
apdu.resp = rbuf;
|
||||
|
|
|
@ -239,8 +239,8 @@ int sc_apdu_set_resp(sc_context_t *ctx, sc_apdu_t *apdu, const u8 *buf,
|
|||
* @param len length of the APDU
|
||||
* @param is_outgoing != 0 if the data is send to the card
|
||||
*/
|
||||
void sc_apdu_log(sc_context_t *ctx, int level, const u8 *data, size_t len,
|
||||
int is_outgoing);
|
||||
#define sc_apdu_log(ctx, level, data, len, is_outgoing) \
|
||||
sc_debug_hex(ctx, level, is_outgoing != 0 ? "Outgoing APDU" : "Incoming APDU", data, len)
|
||||
|
||||
extern struct sc_reader_driver *sc_get_pcsc_driver(void);
|
||||
extern struct sc_reader_driver *sc_get_ctapi_driver(void);
|
||||
|
|
|
@ -87,6 +87,7 @@ sc_disconnect_card
|
|||
sc_do_log
|
||||
sc_do_log_noframe
|
||||
_sc_debug
|
||||
_sc_debug_hex
|
||||
sc_enum_apps
|
||||
sc_encode_oid
|
||||
sc_parse_ef_atr
|
||||
|
|
|
@ -161,6 +161,28 @@ void _sc_log(struct sc_context *ctx, const char *format, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
void _sc_debug_hex(sc_context_t *ctx, int type, const char *file, int line,
|
||||
const char *func, const char *label, const u8 *data, size_t len)
|
||||
{
|
||||
size_t blen = len * 5 + 128;
|
||||
char *buf = malloc(blen);
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
sc_hex_dump(ctx, type, data, len, buf, blen);
|
||||
|
||||
if (label)
|
||||
sc_do_log(ctx, type, file, line, func,
|
||||
"\n%s (%u byte%s):\n%s",
|
||||
label, (unsigned int) len, len==1?"":"s", buf);
|
||||
else
|
||||
sc_do_log(ctx, type, file, line, func,
|
||||
"%u byte%s:\n%s",
|
||||
(unsigned int) len, len==1?"":"s", buf);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
/* Although not used, we need this for consistent exports */
|
||||
void sc_hex_dump(struct sc_context *ctx, int level, const u8 * in, size_t count, char *buf, size_t len)
|
||||
{
|
||||
|
|
|
@ -57,6 +57,31 @@ void sc_do_log(struct sc_context *ctx, int level, const char *file, int line, co
|
|||
void sc_do_log_noframe(sc_context_t *ctx, int level, const char *format, va_list args);
|
||||
void _sc_debug(struct sc_context *ctx, int level, const char *format, ...);
|
||||
void _sc_log(struct sc_context *ctx, const char *format, ...);
|
||||
/**
|
||||
* @brief Log binary data to a sc context
|
||||
*
|
||||
* @param[in] ctx Context for logging
|
||||
* @param[in] level
|
||||
* @param[in] label Label to prepend to the buffer
|
||||
* @param[in] data Binary data
|
||||
* @param[in] len Length of \a data
|
||||
*/
|
||||
#define sc_debug_hex(ctx, level, label, data, len) \
|
||||
_sc_debug_hex(ctx, level, __FILE__, __LINE__, __FUNCTION__, label, data, len)
|
||||
/**
|
||||
* @brief Log binary data
|
||||
*
|
||||
* @param[in] ctx Context for logging
|
||||
* @param[in] type Debug level
|
||||
* @param[in] file File name to be prepended
|
||||
* @param[in] line Line to be prepended
|
||||
* @param[in] func Function to be prepended
|
||||
* @param[in] label label to prepend to the buffer
|
||||
* @param[in] data binary data
|
||||
* @param[in] len length of \a data
|
||||
*/
|
||||
void _sc_debug_hex(struct sc_context *ctx, int level, const char *file, int line,
|
||||
const char *func, const char *label, const u8 *data, size_t len);
|
||||
|
||||
void sc_hex_dump(struct sc_context *ctx, int level, const u8 * buf, size_t len, char *out, size_t outlen);
|
||||
char * sc_dump_hex(const u8 * in, size_t count);
|
||||
|
|
|
@ -1804,7 +1804,7 @@ pcsc_pin_cmd(sc_reader_t *reader, struct sc_pin_cmd_data *data)
|
|||
/* If PIN block building failed, we fail too */
|
||||
SC_TEST_RET(reader->ctx, SC_LOG_DEBUG_NORMAL, r, "PC/SC v2 pinpad block building failed!");
|
||||
/* If not, debug it, just for fun */
|
||||
sc_debug(reader->ctx, SC_LOG_DEBUG_NORMAL, "PC/SC v2 pinpad block: %s", sc_dump_hex(sbuf, scount));
|
||||
sc_debug_hex(reader->ctx, SC_LOG_DEBUG_NORMAL, "PC/SC v2 pinpad block", sbuf, scount);
|
||||
|
||||
r = pcsc_internal_transmit(reader, sbuf, scount, rbuf, &rcount, ioctl);
|
||||
|
||||
|
|
Loading…
Reference in New Issue