Skip to content

Commit

Permalink
pcsc-relay: allow no-ops when sending/receiving
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Feb 27, 2024
1 parent 1a39571 commit 780cc7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
28 changes: 16 additions & 12 deletions pcsc-relay/src/lnfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ static int lnfc_receive_capdu(driver_data_t *driver_data,
}


p = realloc(*capdu, data->iCapduLen);
if (!p) {
RELAY_ERROR("Error allocating memory for C-APDU\n");
return 0;
if (data->iCapduLen) {
p = realloc(*capdu, data->iCapduLen);
if (!p) {
RELAY_ERROR("Error allocating memory for C-APDU (%d bytes)\n", data->iCapduLen);
return 0;
}
memcpy(p, data->abtCapdu, data->iCapduLen);
*capdu = p;
}
memcpy(p, data->abtCapdu, data->iCapduLen);
*capdu = p;
*len = data->iCapduLen;


Expand All @@ -230,13 +232,15 @@ static int lnfc_send_rapdu(driver_data_t *driver_data,
return 0;


r = nfc_target_send_bytes(data->pndTarget, rapdu, len, -1);
if (r < 0) {
RELAY_ERROR ("nfc_target_send_bytes: %s\n", nfc_strerror(data->pndTarget));
return 0;
if (len) {
r = nfc_target_send_bytes(data->pndTarget, rapdu, len, -1);
if (r < 0) {
RELAY_ERROR ("nfc_target_send_bytes: %s\n", nfc_strerror(data->pndTarget));
return 0;
}
if (r < len)
INFO ("Transmitted %u less bytes than desired: %s\n", (unsigned int) len-r, nfc_strerror(data->pndTarget));
}
if (r < len)
INFO ("Transmitted %u less bytes than desired: %s\n", (unsigned int) len-r, nfc_strerror(data->pndTarget));


return 1;
Expand Down
19 changes: 10 additions & 9 deletions pcsc-relay/src/opicc.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,13 @@ static int picc_receive_capdu(driver_data_t *driver_data,

/* read C-APDU */
linelen = getline(&data->line, &data->linemax, data->fd);
if (linelen <= 0) {
if (linelen < 0) {
RELAY_ERROR("Error reading from %s: %s\n", PICCDEV, strerror(errno));
return 0;
}
if (linelen == 0) {
*len = 0;
return 1;
}
if (linelen < 0) {
RELAY_ERROR("Error reading from %s: %s\n", PICCDEV, strerror(errno));
return 0;
}
if (linelen == 0) {
*len = 0;
return 1;
}
if (fflush(data->fd) != 0)
RELAY_ERROR("Warning, fflush failed: %s\n", strerror(errno));
Expand All @@ -237,6 +235,9 @@ static int picc_send_rapdu(driver_data_t *driver_data,
if (!data || !rapdu)
return 0;

if (!len)
return 1;


/* encode R-APDU */
if (!picc_encode_rapdu(rapdu, len, &data->e_rapdu, &buflen))
Expand Down
2 changes: 1 addition & 1 deletion pcsc-relay/src/vicc.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static int vicc_receive_capdu(driver_data_t *driver_data,
goto err;
}
} else {
// finaly we got the capdu
// finally we got the C-APDU
*len = size;
r = 1;
}
Expand Down

0 comments on commit 780cc7c

Please sign in to comment.