Fixed chained response.

Now it returns exactly 256 bytes (including SW).

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2023-08-16 19:19:50 +02:00
parent 4cfbc19aa7
commit e84258c434

View File

@@ -115,14 +115,14 @@ size_t apdu_process(uint8_t itf, const uint8_t *buffer, size_t buffer_size) {
usb_prepare_response(itf); usb_prepare_response(itf);
} }
else { else {
rdata_gr += apdu.ne; rdata_gr += apdu.ne - 2;
rdata_bk = *rdata_gr; rdata_bk = *rdata_gr;
rdata_gr[0] = 0x61; rdata_gr[0] = 0x61;
if (apdu.rlen - apdu.ne >= 256) { if (apdu.rlen - apdu.ne >= 254) {
rdata_gr[1] = 0; rdata_gr[1] = 0;
} }
else { else {
rdata_gr[1] = apdu.rlen - apdu.ne; rdata_gr[1] = apdu.rlen - apdu.ne + 2;
} }
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
#ifdef USB_ITF_HID #ifdef USB_ITF_HID
@@ -138,7 +138,7 @@ size_t apdu_process(uint8_t itf, const uint8_t *buffer, size_t buffer_size) {
#else #else
driver_exec_finished_cont_emul(itf, apdu.ne + 2, rdata_gr - apdu.ne - usb_get_tx(itf)); driver_exec_finished_cont_emul(itf, apdu.ne + 2, rdata_gr - apdu.ne - usb_get_tx(itf));
#endif #endif
apdu.rlen -= apdu.ne; apdu.rlen -= apdu.ne - 2;
} }
return 0; return 0;
} }
@@ -209,18 +209,18 @@ size_t apdu_next() {
return apdu.rlen + 2; return apdu.rlen + 2;
} }
else { else {
rdata_gr = apdu.rdata + apdu.ne; rdata_gr = apdu.rdata + apdu.ne - 2;
rdata_bk = *(uint16_t *) rdata_gr; rdata_bk = *(uint16_t *) rdata_gr;
rdata_gr[0] = 0x61; rdata_gr[0] = 0x61;
if (apdu.rlen - apdu.ne >= 256) { if (apdu.rlen - apdu.ne >= 254) {
rdata_gr[1] = 0; rdata_gr[1] = 0;
} }
else { else {
rdata_gr[1] = apdu.rlen - apdu.ne; rdata_gr[1] = apdu.rlen - apdu.ne + 2;
} }
apdu.rlen -= apdu.ne; apdu.rlen -= apdu.ne - 2;
} }
return apdu.ne + 2; return apdu.ne;
} }
return 0; return 0;
} }