fix pck length math

This commit is contained in:
merlokk 2019-08-20 19:07:33 +03:00 committed by Conor Patrick
parent 8059a9765f
commit 62b4418dac

View File

@ -551,6 +551,7 @@ void nfc_process_iblock(uint8_t * buf, int len)
if (apdu.p1 != 0x00 || apdu.p2 != 0x00) if (apdu.p1 != 0x00 || apdu.p2 != 0x00)
{ {
nfc_write_response(buf[0], SW_INCORRECT_P1P2); nfc_write_response(buf[0], SW_INCORRECT_P1P2);
printf1(TAG_NFC, "P1 or P2 error\r\n");
return; return;
} }
@ -561,15 +562,20 @@ void nfc_process_iblock(uint8_t * buf, int len)
if (resp_chain_buffer_len <= 0xff) if (resp_chain_buffer_len <= 0xff)
wlresp += resp_chain_buffer_len & 0xff; wlresp += resp_chain_buffer_len & 0xff;
nfc_write_response(buf[0], wlresp); nfc_write_response(buf[0], wlresp);
printf1(TAG_NFC, "buffer length less than requesteds\r\n");
return; return;
} }
// create temporary packet // create temporary packet
uint8_t pck[255] = {0}; uint8_t pck[255] = {0};
int pcklen = MIN(253, apdu.le); size_t pcklen = 253;
if (apdu.le)
pcklen = apdu.le;
if (pcklen > resp_chain_buffer_len) if (pcklen > resp_chain_buffer_len)
pcklen = resp_chain_buffer_len; pcklen = resp_chain_buffer_len;
printf1(TAG_NFC, "--- %d/%d\r\n", pcklen, resp_chain_buffer_len);
// create packet and add 61XX there if we have another portion(s) of data // create packet and add 61XX there if we have another portion(s) of data
memmove(pck, resp_chain_buffer, pcklen); memmove(pck, resp_chain_buffer, pcklen);
size_t dlen = 0; size_t dlen = 0;