- lnfc: capdu was not copied, fixed

- changed some output messages


git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@354 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
frankmorgner
2010-11-10 20:44:34 +00:00
parent 44dc9f6c7d
commit a012c02caf
3 changed files with 24 additions and 13 deletions

View File

@@ -124,21 +124,21 @@ static int lnfc_connect(void **driver_data)
*driver_data = data; *driver_data = data;
// Try to open the NFC emulator device
data->pndTarget = nfc_connect (NULL); data->pndTarget = nfc_connect (NULL);
if (data->pndTarget == NULL) { if (data->pndTarget == NULL) {
ERROR("Error connecting NFC emulator device\n"); ERROR("Error connecting to NFC emulator device\n");
return 0; return 0;
} }
INFO("Connected to the NFC emulator device: %s\n", data->pndTarget->acName); if (verbose >= 0)
printf("Connected to %s\n", data->pndTarget->acName);
if (!nfc_target_init (data->pndTarget, &ntEmulatedTarget, data->abtCapdu, &data->szCapduLen)) { if (!nfc_target_init (data->pndTarget, &ntEmulatedTarget, data->abtCapdu, &data->szCapduLen)) {
ERROR("Initialization of NFC emulator failed"); ERROR("Initialization of NFC emulator failed");
nfc_disconnect (data->pndTarget); nfc_disconnect (data->pndTarget);
return 0; return 0;
} }
DEBUG("%s\n", "Done, relaying frames now!"); DEBUG("Initialized NFC emulator\n");
return 1; return 1;
@@ -159,6 +159,7 @@ static int lnfc_receive_capdu(void *driver_data,
unsigned char **capdu, size_t *len) unsigned char **capdu, size_t *len)
{ {
struct lnfc_data *data = driver_data; struct lnfc_data *data = driver_data;
unsigned char *p;
if (!data || !capdu || !len) if (!data || !capdu || !len)
return 0; return 0;
@@ -172,6 +173,16 @@ static int lnfc_receive_capdu(void *driver_data,
} }
p = realloc(*capdu, data->szCapduLen);
if (!p) {
ERROR("Error allocating memory for C-APDU\n");
return 0;
}
memcpy(p, data->abtCapdu, data->szCapduLen);
*capdu = p;
*len = data->szCapduLen;
return 1; return 1;
} }

View File

@@ -25,7 +25,7 @@
struct picc_data { struct picc_data {
char *buf; char *buf;
size_t buflen; size_t bufmax;
FILE *fd; FILE *fd;
}; };
static int picc_encode_rapdu(const unsigned char *inbuf, size_t inlen, static int picc_encode_rapdu(const unsigned char *inbuf, size_t inlen,
@@ -75,7 +75,6 @@ int picc_decode_apdu(const char *inbuf, size_t inlen,
unsigned long int b; unsigned long int b;
if (!outbuf || !outlen) { if (!outbuf || !outlen) {
/* Invalid parameters */
return 0; return 0;
} }
if (inbuf == NULL || inlen == 0 || inbuf[0] == '\0') { if (inbuf == NULL || inlen == 0 || inbuf[0] == '\0') {
@@ -135,10 +134,11 @@ static int picc_connect(void **driver_data)
} }
data->buf = NULL; data->buf = NULL;
data->buflen = 0; data->bufmax = 0;
INFO("Connected to %s\n", PICCDEV); if (verbose >= 0)
printf("Connected to %s\n", PICCDEV);
return 1; return 1;
} }
@@ -154,7 +154,7 @@ static int picc_disconnect(void *driver_data)
data->fd = NULL; data->fd = NULL;
free(data->buf); free(data->buf);
data->buf = NULL; data->buf = NULL;
data->buflen = 0; data->bufmax = 0;
} }
@@ -211,12 +211,12 @@ static int picc_send_rapdu(void *driver_data,
/* encode R-APDU */ /* encode R-APDU */
if (!picc_encode_rapdu(rapdu, len, &data->buf, &buflen)) if (!picc_encode_rapdu(rapdu, len, &data->buf, &buflen))
return 0; return 0;
if (data->buflen < buflen) if (data->bufmax < buflen)
data->buflen = buflen; data->bufmax = buflen;
/* write R-APDU */ /* write R-APDU */
DEBUG("INF: Writing R-APDU\n\n%s\n\n", data->buf); DEBUG("INF: Writing R-APDU\r\n%s\r\n", data->buf);
if (fprintf(data->fd,"%s\r\n", (char *) data->buf) < 0 if (fprintf(data->fd,"%s\r\n", (char *) data->buf) < 0
|| fflush(data->fd) != 0) { || fflush(data->fd) != 0) {

View File

@@ -51,7 +51,7 @@ static const char *option_help[] = {
"Print help and exit", "Print help and exit",
"Number of reader to use (default: 0)", "Number of reader to use (default: 0)",
"Stay in foreground", "Stay in foreground",
"Emulation backend (openpicc [default], libnfc)", "NFC emulator backend (openpicc [default], libnfc)",
"Use (several times) to be more verbose", "Use (several times) to be more verbose",
}; };
static int doinfo = 0; static int doinfo = 0;