From ee1f538b11aa63367a13ca99e75a95c59376f102 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Mon, 10 Oct 2016 13:14:02 +0200 Subject: [PATCH] ccid-emulator: removed unused implementation --- ccid/src/ccid.c | 3 +- ccid/src/scutil.c | 174 ---------------------------------------------- ccid/src/scutil.h | 28 -------- ccid/src/usb.c | 1 - 4 files changed, 1 insertion(+), 205 deletions(-) diff --git a/ccid/src/ccid.c b/ccid/src/ccid.c index d17d314..f49cd5f 100644 --- a/ccid/src/ccid.c +++ b/ccid/src/ccid.c @@ -31,8 +31,7 @@ #include "ccid.h" #include "config.h" - -#include +#include "scutil.h" #ifndef HAVE_BOXING_BUF_TO_PACE_INPUT #include diff --git a/ccid/src/scutil.c b/ccid/src/scutil.c index b69528a..05cec74 100644 --- a/ccid/src/scutil.c +++ b/ccid/src/scutil.c @@ -44,8 +44,6 @@ size_t sc_get_max_send_size(const sc_card_t *card) {} #endif #include -#include -#include #include #include #include @@ -171,175 +169,3 @@ int print_avail(int verbose) return r; } - -#define ISO_READ_BINARY 0xB0 -#define ISO_P1_FLAG_SFID 0x80 -int read_binary_rec(sc_card_t *card, unsigned char sfid, - u8 **ef, size_t *ef_len) -{ - int r; - size_t read = MAX_SM_APDU_RESP_SIZE; - sc_apdu_t apdu; - u8 *p; - - if (!card || !ef || !ef_len) { - r = SC_ERROR_INVALID_ARGUMENTS; - goto err; - } - *ef_len = 0; - - if (read > 0xff+1) - sc_format_apdu(card, &apdu, SC_APDU_CASE_2_EXT, - ISO_READ_BINARY, ISO_P1_FLAG_SFID|sfid, 0); - else - sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, - ISO_READ_BINARY, ISO_P1_FLAG_SFID|sfid, 0); - - p = realloc(*ef, read); - if (!p) { - r = SC_ERROR_OUT_OF_MEMORY; - goto err; - } - *ef = p; - apdu.resp = *ef; - apdu.resplen = read; - apdu.le = read; - - r = sc_transmit_apdu(card, &apdu); - /* emulate the behaviour of sc_read_binary */ - if (r >= 0) - r = apdu.resplen; - - while(1) { - if (r >= 0 && r != read) { - *ef_len += r; - break; - } - if (r < 0) { - sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Could not read EF."); - goto err; - } - *ef_len += r; - - p = realloc(*ef, *ef_len + read); - if (!p) { - r = SC_ERROR_OUT_OF_MEMORY; - goto err; - } - *ef = p; - - r = sc_read_binary(card, *ef_len, - *ef + *ef_len, read, 0); - } - - r = SC_SUCCESS; - -err: - return r; -} - -#define ISO_WRITE_BINARY 0xD0 -int write_binary_rec(sc_card_t *card, unsigned char sfid, - u8 *ef, size_t ef_len) -{ - int r; - size_t write = MAX_SM_APDU_DATA_SIZE, wrote = 0; - sc_apdu_t apdu; -#ifdef ENABLE_SM - struct iso_sm_ctx *iso_sm_ctx; -#endif - - if (!card) { - r = SC_ERROR_INVALID_ARGUMENTS; - goto err; - } - -#ifdef ENABLE_SM - iso_sm_ctx = card->sm_ctx.info.cmd_data; - if (write > SC_MAX_APDU_BUFFER_SIZE-2 - || (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT - && write > (((SC_MAX_APDU_BUFFER_SIZE-2 - /* for encrypted APDUs we usually get authenticated status - * bytes (4B), a MAC (11B) and a cryptogram with padding - * indicator (3B without data). The cryptogram is always - * padded to the block size. */ - -18) / iso_sm_ctx->block_length) - * iso_sm_ctx->block_length - 1))) - sc_format_apdu(card, &apdu, SC_APDU_CASE_3_EXT, - ISO_WRITE_BINARY, ISO_P1_FLAG_SFID|sfid, 0); - else -#endif - sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, - ISO_WRITE_BINARY, ISO_P1_FLAG_SFID|sfid, 0); - - if (write > ef_len) { - apdu.datalen = ef_len; - apdu.lc = ef_len; - } else { - apdu.datalen = write; - apdu.lc = write; - } - apdu.data = ef; - - - r = sc_transmit_apdu(card, &apdu); - /* emulate the behaviour of sc_write_binary */ - if (r >= 0) - r = apdu.datalen; - - while (1) { - if (r < 0 || r > ef_len) { - sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Could not write EF."); - goto err; - } - wrote += r; - apdu.data += r; - if (wrote >= ef_len) - break; - - r = sc_write_binary(card, wrote, ef, write, 0); - } - - r = SC_SUCCESS; - -err: - return r; -} - -int fread_to_eof(const char *file, unsigned char **buf, size_t *buflen) -{ - FILE *input = NULL; - int r = 0; - unsigned char *p; - - if (!buflen || !buf || !file) - goto err; - -#define MAX_READ_LEN 0xfff - p = realloc(*buf, MAX_READ_LEN); - if (!p) - goto err; - *buf = p; - - input = fopen(file, "rb"); - if (!input) { - fprintf(stderr, "Could not open %s.\n", file); - goto err; - } - - *buflen = 0; - while (feof(input) == 0 && *buflen < MAX_READ_LEN) { - *buflen += fread(*buf+*buflen, 1, MAX_READ_LEN-*buflen, input); - if (ferror(input)) { - fprintf(stderr, "Could not read %s.\n", file); - goto err; - } - } - - r = 1; -err: - if (input) - fclose(input); - - return r; -} diff --git a/ccid/src/scutil.h b/ccid/src/scutil.h index 1b723ea..04ad123 100644 --- a/ccid/src/scutil.h +++ b/ccid/src/scutil.h @@ -88,34 +88,6 @@ void _bin_log(sc_context_t *ctx, int type, const char *file, int line, */ int print_avail(int verbose); -/** - * @brief Recursively read an EF by short file identifier. - * - * @param[in] card - * @param[in] sfid Short file identifier - * @param[in,out] ef Where to safe the file. the buffer will be allocated - * using \c realloc() and should be set to NULL, if - * empty. - * @param[in,out] ef_len Length of \a *ef - * - * @note The appropriate directory must be selected before calling this function. - * */ -int read_binary_rec(sc_card_t *card, unsigned char sfid, - u8 **ef, size_t *ef_len); - -/** - * @brief Recursively write an EF by short file identifier. - * - * @param[in] card - * @param[in] sfid Short file identifier - * @param[in] ef Date to write - * @param[in] ef_len Length of \a ef - * - * @note The appropriate directory must be selected before calling this function. - * */ -int write_binary_rec(sc_card_t *card, unsigned char sfid, - u8 *ef, size_t ef_len); - /* * OPENSC functions that do not get exported (sometimes) */ diff --git a/ccid/src/usb.c b/ccid/src/usb.c index 947d259..aa7d8d4 100644 --- a/ccid/src/usb.c +++ b/ccid/src/usb.c @@ -35,7 +35,6 @@ #include #include #include -#include //#include //