libopensc: use short debug macros in card.c

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5319 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
vtarasov 2011-04-10 09:20:15 +00:00
parent b614444aae
commit 848180ab50
1 changed files with 147 additions and 115 deletions

View File

@ -96,7 +96,7 @@ static void sc_card_free(sc_card_t *card)
if (card->mutex != NULL) {
int r = sc_mutex_destroy(card->ctx, card->mutex);
if (r != SC_SUCCESS)
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "unable to destroy mutex");
sc_log(card->ctx, "unable to destroy mutex");
}
sc_mem_clear(card, sizeof(*card));
free(card);
@ -114,11 +114,11 @@ int sc_connect_card(sc_reader_t *reader, sc_card_t **card_out)
ctx = reader->ctx;
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
if (reader->ops->connect == NULL)
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
card = sc_card_new(ctx);
if (card == NULL)
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY);
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
r = reader->ops->connect(reader);
if (r)
goto err;
@ -213,45 +213,49 @@ int sc_connect_card(sc_reader_t *reader, sc_card_t **card_out)
* Note that zero means no limitations at all.
*/
if ((card->max_recv_size == 0) ||
((reader->driver->max_recv_size != 0) && (reader->driver->max_recv_size < card->max_recv_size))) {
((reader->driver->max_recv_size != 0) && (reader->driver->max_recv_size < card->max_recv_size)))
card->max_recv_size = reader->driver->max_recv_size;
}
if ((card->max_send_size == 0) ||
((reader->driver->max_send_size != 0) && (reader->driver->max_send_size < card->max_send_size))) {
card->max_send_size = reader->driver->max_send_size;
}
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "card info name:'%s', type:%i, flags:0x%X, max_send/recv_size:%i/%i",
if ((card->max_send_size == 0) ||
((reader->driver->max_send_size != 0) && (reader->driver->max_send_size < card->max_send_size)))
card->max_send_size = reader->driver->max_send_size;
sc_log(ctx, "card info name:'%s', type:%i, flags:0x%X, max_send/recv_size:%i/%i",
card->name, card->type, card->flags, card->max_send_size, card->max_recv_size);
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, 0);
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
err:
if (connected)
reader->ops->disconnect(reader);
if (card != NULL)
sc_card_free(card);
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, r);
LOG_FUNC_RETURN(ctx, r);
}
int sc_disconnect_card(sc_card_t *card)
{
sc_context_t *ctx;
if (!card)
return SC_ERROR_INVALID_ARGUMENTS;
ctx = card->ctx;
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
LOG_FUNC_CALLED(ctx);
assert(card->lock_count == 0);
if (card->ops->finish) {
int r = card->ops->finish(card);
if (r)
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "card driver finish() failed: %s",
sc_strerror(r));
sc_log(ctx, "card driver finish() failed: %s", sc_strerror(r));
}
if (card->reader->ops->disconnect) {
int r = card->reader->ops->disconnect(card->reader);
if (r)
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "disconnect() failed: %s",
sc_strerror(r));
sc_log(ctx, "disconnect() failed: %s", sc_strerror(r));
}
sc_card_free(card);
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, 0);
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}
int sc_reset(sc_card_t *card, int do_cold_reset)
@ -274,7 +278,7 @@ int sc_reset(sc_card_t *card, int do_cold_reset)
r2 = sc_mutex_unlock(card->ctx, card->mutex);
if (r2 != SC_SUCCESS) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "unable to release lock");
sc_log(card->ctx, "unable to release lock");
r = r != SC_SUCCESS ? r : r2;
}
@ -285,7 +289,7 @@ int sc_lock(sc_card_t *card)
{
int r = 0, r2 = 0;
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card == NULL)
return SC_ERROR_INVALID_ARGUMENTS;
@ -309,9 +313,10 @@ int sc_lock(sc_card_t *card)
card->lock_count++;
r2 = sc_mutex_unlock(card->ctx, card->mutex);
if (r2 != SC_SUCCESS) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "unable to release lock");
sc_log(card->ctx, "unable to release lock");
r = r != SC_SUCCESS ? r : r2;
}
return r;
}
@ -319,20 +324,22 @@ int sc_unlock(sc_card_t *card)
{
int r, r2;
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
if (card == NULL)
if (!card)
return SC_ERROR_INVALID_ARGUMENTS;
LOG_FUNC_CALLED(card->ctx);
r = sc_mutex_lock(card->ctx, card->mutex);
if (r != SC_SUCCESS)
return r;
assert(card->lock_count >= 1);
if (--card->lock_count == 0) {
#ifdef INVALIDATE_CARD_CACHE_IN_UNLOCK
/* invalidate cache */
memset(&card->cache, 0, sizeof(card->cache));
card->cache.valid = 0;
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "cache invalidated");
sc_log(card->ctx, "cache invalidated");
#endif
/* release reader lock */
if (card->reader->ops->unlock != NULL)
@ -340,9 +347,10 @@ int sc_unlock(sc_card_t *card)
}
r2 = sc_mutex_unlock(card->ctx, card->mutex);
if (r2 != SC_SUCCESS) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "unable to release lock");
sc_log(card->ctx, "unable to release lock");
r = (r == SC_SUCCESS) ? r2 : r;
}
return r;
}
@ -351,11 +359,13 @@ int sc_list_files(sc_card_t *card, u8 *buf, size_t buflen)
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->list_files == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->list_files(card, buf, buflen);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_create_file(sc_card_t *card, sc_file_t *file)
@ -370,16 +380,17 @@ int sc_create_file(sc_card_t *card, sc_file_t *file)
if (r != SC_SUCCESS)
pbuf[0] = '\0';
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called; type=%d, path=%s, size=%u",
in_path->type, pbuf, file->size);
sc_log(card->ctx, "called; type=%d, path=%s, size=%u", in_path->type, pbuf, file->size);
/* ISO 7816-4: "Number of data bytes in the file, including structural information if any"
* can not be bigger than two bytes */
if (file->size > 0xFFFF)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
if (card->ops->create_file == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->create_file(card, file);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_delete_file(sc_card_t *card, const sc_path_t *path)
@ -393,11 +404,12 @@ int sc_delete_file(sc_card_t *card, const sc_path_t *path)
if (r != SC_SUCCESS)
pbuf[0] = '\0';
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called; type=%d, path=%s", path->type, pbuf);
sc_log(card->ctx, "called; type=%d, path=%s", path->type, pbuf);
if (card->ops->delete_file == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->delete_file(card, path);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_read_binary(sc_card_t *card, unsigned int idx,
@ -407,23 +419,25 @@ int sc_read_binary(sc_card_t *card, unsigned int idx,
int r;
assert(card != NULL && card->ops != NULL && buf != NULL);
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called; %d bytes at index %d", count, idx);
sc_log(card->ctx, "called; %d bytes at index %d", count, idx);
if (count == 0)
return 0;
if (card->ops->read_binary == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
if (count > max_le) {
int bytes_read = 0;
unsigned char *p = buf;
r = sc_lock(card);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
while (count > 0) {
size_t n = count > max_le ? max_le : count;
r = sc_read_binary(card, idx, p, n, flags);
if (r < 0) {
sc_unlock(card);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_read_binary() failed");
LOG_TEST_RET(card->ctx, r, "sc_read_binary() failed");
}
p += r;
idx += r;
@ -431,14 +445,14 @@ int sc_read_binary(sc_card_t *card, unsigned int idx,
count -= r;
if (r == 0) {
sc_unlock(card);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, bytes_read);
LOG_FUNC_RETURN(card->ctx, bytes_read);
}
}
sc_unlock(card);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, bytes_read);
LOG_FUNC_RETURN(card->ctx, bytes_read);
}
r = card->ops->read_binary(card, idx, buf, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_write_binary(sc_card_t *card, unsigned int idx,
@ -448,23 +462,24 @@ int sc_write_binary(sc_card_t *card, unsigned int idx,
int r;
assert(card != NULL && card->ops != NULL && buf != NULL);
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called; %d bytes at index %d", count, idx);
sc_log(card->ctx, "called; %d bytes at index %d", count, idx);
if (count == 0)
return 0;
LOG_FUNC_RETURN(card->ctx, 0);
if (card->ops->write_binary == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
if (count > max_lc) {
int bytes_written = 0;
const u8 *p = buf;
r = sc_lock(card);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
while (count > 0) {
size_t n = count > max_lc? max_lc : count;
r = sc_write_binary(card, idx, p, n, flags);
if (r < 0) {
sc_unlock(card);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_write_binary() failed");
LOG_TEST_RET(card->ctx, r, "sc_write_binary() failed");
}
p += r;
idx += r;
@ -472,14 +487,15 @@ int sc_write_binary(sc_card_t *card, unsigned int idx,
count -= r;
if (r == 0) {
sc_unlock(card);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, bytes_written);
LOG_FUNC_RETURN(card->ctx, bytes_written);
}
}
sc_unlock(card);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, bytes_written);
LOG_FUNC_RETURN(card->ctx, bytes_written);
}
r = card->ops->write_binary(card, idx, buf, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_update_binary(sc_card_t *card, unsigned int idx,
@ -489,23 +505,24 @@ int sc_update_binary(sc_card_t *card, unsigned int idx,
int r;
assert(card != NULL && card->ops != NULL && buf != NULL);
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called; %d bytes at index %d", count, idx);
sc_log(card->ctx, "called; %d bytes at index %d", count, idx);
if (count == 0)
return 0;
if (card->ops->update_binary == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
if (count > max_lc) {
int bytes_written = 0;
const u8 *p = buf;
r = sc_lock(card);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
while (count > 0) {
size_t n = count > max_lc? max_lc : count;
r = sc_update_binary(card, idx, p, n, flags);
if (r < 0) {
sc_unlock(card);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_update_binary() failed");
LOG_TEST_RET(card->ctx, r, "sc_update_binary() failed");
}
p += r;
idx += r;
@ -513,36 +530,34 @@ int sc_update_binary(sc_card_t *card, unsigned int idx,
count -= r;
if (r == 0) {
sc_unlock(card);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, bytes_written);
LOG_FUNC_RETURN(card->ctx, bytes_written);
}
}
sc_unlock(card);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, bytes_written);
LOG_FUNC_RETURN(card->ctx, bytes_written);
}
r = card->ops->update_binary(card, idx, buf, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_erase_binary(struct sc_card *card, unsigned int offs, size_t count,
unsigned long flags)
int sc_erase_binary(struct sc_card *card, unsigned int offs, size_t count, unsigned long flags)
{
int r;
assert(card != NULL && card->ops != NULL);
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called; erase %d bytes from offset %d", count, offs);
sc_log(card->ctx, "called; erase %d bytes from offset %d", count, offs);
if (card->ops->erase_binary == NULL)
SC_FUNC_RETURN(card->ctx, 2, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->erase_binary(card, offs, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_select_file(sc_card_t *card,
const sc_path_t *in_path,
sc_file_t **file)
int sc_select_file(sc_card_t *card, const sc_path_t *in_path, sc_file_t **file)
{
int r;
char pbuf[SC_MAX_PATH_STRING_SIZE];
@ -553,50 +568,59 @@ int sc_select_file(sc_card_t *card,
if (r != SC_SUCCESS)
pbuf[0] = '\0';
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called; type=%d, path=%s", in_path->type, pbuf);
sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
if (in_path->len > SC_MAX_PATH_SIZE)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
if (in_path->type == SC_PATH_TYPE_PATH) {
/* Perform a sanity check */
size_t i;
if ((in_path->len & 1) != 0)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
for (i = 0; i < in_path->len/2; i++) {
u8 p1 = in_path->value[2*i],
p2 = in_path->value[2*i+1];
if ((p1 == 0x3F && p2 == 0x00) && i != 0)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
}
}
if (card->ops->select_file == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->select_file(card, in_path, file);
/* Remember file path */
if (r == 0 && file && *file)
(*file)->path = *in_path;
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_get_data(sc_card_t *card, unsigned int tag, u8 *buf, size_t len)
{
int r;
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called, tag=%04x", tag);
sc_log(card->ctx, "called, tag=%04x", tag);
if (card->ops->get_data == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->get_data(card, tag, buf, len);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t len)
{
int r;
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called, tag=%04x", tag);
sc_log(card->ctx,"called, tag=%04x", tag);
if (card->ops->put_data == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->put_data(card, tag, buf, len);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_get_challenge(sc_card_t *card, u8 *rnd, size_t len)
@ -604,11 +628,13 @@ int sc_get_challenge(sc_card_t *card, u8 *rnd, size_t len)
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->get_challenge == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->get_challenge(card, rnd, len);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_read_record(sc_card_t *card, unsigned int rec_nr, u8 *buf,
@ -617,11 +643,13 @@ int sc_read_record(sc_card_t *card, unsigned int rec_nr, u8 *buf,
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->read_record == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->read_record(card, rec_nr, buf, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_write_record(sc_card_t *card, unsigned int rec_nr, const u8 * buf,
@ -630,11 +658,13 @@ int sc_write_record(sc_card_t *card, unsigned int rec_nr, const u8 * buf,
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->write_record == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->write_record(card, rec_nr, buf, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_append_record(sc_card_t *card, const u8 * buf, size_t count,
@ -643,11 +673,13 @@ int sc_append_record(sc_card_t *card, const u8 * buf, size_t count,
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->append_record == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->append_record(card, buf, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_update_record(sc_card_t *card, unsigned int rec_nr, const u8 * buf,
@ -656,11 +688,13 @@ int sc_update_record(sc_card_t *card, unsigned int rec_nr, const u8 * buf,
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->update_record == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->update_record(card, rec_nr, buf, count, flags);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int sc_delete_record(sc_card_t *card, unsigned int rec_nr)
@ -668,11 +702,13 @@ int sc_delete_record(sc_card_t *card, unsigned int rec_nr)
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->delete_record == NULL)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
r = card->ops->delete_record(card, rec_nr);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int
@ -681,16 +717,17 @@ sc_card_ctl(sc_card_t *card, unsigned long cmd, void *args)
int r = SC_ERROR_NOT_SUPPORTED;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
LOG_FUNC_CALLED(card->ctx);
if (card->ops->card_ctl != NULL)
r = card->ops->card_ctl(card, cmd, args);
/* suppress "not supported" error messages */
if (r == SC_ERROR_NOT_SUPPORTED) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "card_ctl(%lu) not supported", cmd);
sc_log(card->ctx, "card_ctl(%lu) not supported", cmd);
return r;
}
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
LOG_FUNC_RETURN(card->ctx, r);
}
int _sc_card_add_algorithm(sc_card_t *card, const sc_algorithm_info_t *info)
@ -789,7 +826,7 @@ static int match_atr_table(sc_context_t *ctx, struct sc_atr_table *table, struct
sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
card_atr_hex_len = strlen(card_atr_hex);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "ATR : %s", card_atr_hex);
sc_log(ctx, "ATR : %s", card_atr_hex);
for (i = 0; table[i].atr != NULL; i++) {
const char *tatr = table[i].atr;
@ -800,14 +837,14 @@ static int match_atr_table(sc_context_t *ctx, struct sc_atr_table *table, struct
size_t fix_hex_len = card_atr_hex_len;
size_t fix_bin_len = card_atr_bin_len;
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "ATR try : %s", tatr);
sc_log(ctx, "ATR try : %s", tatr);
if (tatr_len != fix_hex_len) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "ignored - wrong length");
sc_log(ctx, "ignored - wrong length");
continue;
}
if (matr != NULL) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "ATR mask: %s", matr);
sc_log(ctx, "ATR mask: %s", matr);
matr_len = strlen(matr);
if (tatr_len != matr_len)
@ -817,8 +854,7 @@ static int match_atr_table(sc_context_t *ctx, struct sc_atr_table *table, struct
mbin_len = sizeof(mbin);
sc_hex_to_bin(matr, mbin, &mbin_len);
if (mbin_len != fix_bin_len) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
"length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);
sc_log(ctx, "length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);
continue;
}
for (s = 0; s < tbin_len; s++) {
@ -968,21 +1004,17 @@ void sc_print_cache(struct sc_card *card) {
ctx = card->ctx;
if (!card->cache.valid || (!card->cache.current_ef && !card->cache.current_df)) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "card cache invalid");
sc_log(ctx, "card cache invalid");
return;
}
if (card->cache.current_ef) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "current_ef(type=%i) %s",
card->cache.current_ef->path.type,
if (card->cache.current_ef)
sc_log(ctx, "current_ef(type=%i) %s", card->cache.current_ef->path.type,
sc_print_path(&card->cache.current_ef->path));
}
if (card->cache.current_df) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "current_df(type=%i, aid_len=%i) %s",
card->cache.current_df->path.type,
if (card->cache.current_df)
sc_log(ctx, "current_df(type=%i, aid_len=%i) %s", card->cache.current_df->path.type,
card->cache.current_df->path.aid.len,
sc_print_path(&card->cache.current_df->path));
}
}