ccid-emulator: removed unused implementation
This commit is contained in:
@@ -31,8 +31,7 @@
|
|||||||
|
|
||||||
#include "ccid.h"
|
#include "ccid.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "scutil.h"
|
||||||
#include <npa/scutil.h>
|
|
||||||
|
|
||||||
#ifndef HAVE_BOXING_BUF_TO_PACE_INPUT
|
#ifndef HAVE_BOXING_BUF_TO_PACE_INPUT
|
||||||
#include <libopensc/reader-boxing.c>
|
#include <libopensc/reader-boxing.c>
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ size_t sc_get_max_send_size(const sc_card_t *card) {}
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <libopensc/log.h>
|
#include <libopensc/log.h>
|
||||||
#include <npa/iso-sm.h>
|
|
||||||
#include <npa/scutil.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -171,175 +169,3 @@ int print_avail(int verbose)
|
|||||||
|
|
||||||
return r;
|
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -88,34 +88,6 @@ void _bin_log(sc_context_t *ctx, int type, const char *file, int line,
|
|||||||
*/
|
*/
|
||||||
int print_avail(int verbose);
|
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)
|
* OPENSC functions that do not get exported (sometimes)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/usb/gadgetfs.h>
|
#include <linux/usb/gadgetfs.h>
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
#include <npa/scutil.h>
|
|
||||||
//#include <usb.h>
|
//#include <usb.h>
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user