From 42dcdd337277362b874503f5a36560e78c26d1f7 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Sun, 24 Sep 2023 10:29:49 +0200 Subject: [PATCH] Fix when chunking Signed-off-by: Pol Henarejos --- src/usb/emulation/emulation.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/usb/emulation/emulation.c b/src/usb/emulation/emulation.c index 0c38134..5b28d02 100644 --- a/src/usb/emulation/emulation.c +++ b/src/usb/emulation/emulation.c @@ -231,14 +231,17 @@ int driver_process_usb_packet_emul(uint8_t itf, uint16_t len) { } } else { + size_t sent = 0; DEBUG_PAYLOAD(data, len); - if (apdu_process(itf, data, len) > 0) { + if ((sent = apdu_process(itf, data, len)) > 0) { process_apdu(); } apdu_finish(); - size_t ret = apdu_next(); - DEBUG_PAYLOAD(rdata, ret); - emul_write(itf, ret); + if (sent > 0) { + size_t ret = apdu_next(); + DEBUG_PAYLOAD(rdata, ret); + emul_write(itf, ret); + } } } #endif