Skip to content

Commit ffde714

Browse files
fix: Apdu exchange recv pkts limit
1 parent 7a8375e commit ffde714

File tree

1 file changed

+17
-14
lines changed
  • common/interfaces/card_interface

1 file changed

+17
-14
lines changed

common/interfaces/card_interface/nfc.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ ISO7816 nfc_select_applet(uint8_t expected_family_id[],
194194
ISO7816 status_word;
195195
uint8_t send_apdu[255], recv_apdu[255] = {0},
196196
_version[CARD_VERSION_SIZE] = {0};
197-
uint16_t send_len = 5, recv_len = 236;
197+
uint16_t send_len = 5, recv_len = 255;
198198

199199
send_len = create_apdu_select_applet(send_apdu);
200200

@@ -262,7 +262,7 @@ ISO7816 nfc_pair(uint8_t *data_inOut, uint8_t *length_inOut) {
262262

263263
ISO7816 status_word = CLA_ISO7816;
264264
uint8_t send_apdu[255], recv_apdu[255] = {0};
265-
uint16_t send_len = 5, recv_len = 236;
265+
uint16_t send_len = 5, recv_len = 255;
266266

267267
send_len = create_apdu_pair(data_inOut, *length_inOut, send_apdu);
268268

@@ -293,7 +293,7 @@ ISO7816 nfc_pair(uint8_t *data_inOut, uint8_t *length_inOut) {
293293
ISO7816 nfc_unpair() {
294294
ISO7816 status_word = CLA_ISO7816;
295295
uint8_t send_apdu[255], recv_apdu[255] = {0};
296-
uint16_t send_len = 5, recv_len = 236;
296+
uint16_t send_len = 5, recv_len = 255;
297297

298298
hex_string_to_byte_array("00130000", 8, send_apdu);
299299
nfc_secure_comm = true;
@@ -321,7 +321,7 @@ ISO7816 nfc_list_all_wallet(wallet_list_t *wallet_list) {
321321

322322
// recv_len receives the length of response APDU. It also
323323
// acts as expected length of response APDU.
324-
uint16_t recv_len = 236;
324+
uint16_t recv_len = 300;
325325

326326
send_len = create_apdu_list_wallet(send_apdu);
327327

@@ -367,7 +367,7 @@ ISO7816 nfc_add_wallet(const struct Wallet *wallet) {
367367
// Call nfc_select_card() before
368368
ISO7816 status_word = CLA_ISO7816;
369369
uint8_t send_apdu[600] = {0}, *recv_apdu = send_apdu;
370-
uint16_t send_len = 0, recv_len = 236;
370+
uint16_t send_len = 0, recv_len = 600;
371371

372372
calculate_checksum(wallet, (uint8_t *)wallet->checksum);
373373
if (WALLET_IS_ARBITRARY_DATA(wallet->wallet_info))
@@ -437,7 +437,7 @@ ISO7816 nfc_delete_wallet(const struct Wallet *wallet) {
437437

438438
ISO7816 status_word = CLA_ISO7816;
439439
uint8_t send_apdu[600] = {0}, *recv_apdu = send_apdu;
440-
uint16_t send_len = 0, recv_len = 236;
440+
uint16_t send_len = 0, recv_len = 600;
441441

442442
send_len = create_apdu_delete_wallet(wallet, send_apdu);
443443

@@ -466,7 +466,7 @@ ISO7816 nfc_ecdsa(uint8_t data_inOut[ECDSA_SIGNATURE_SIZE],
466466

467467
ISO7816 status_word = CLA_ISO7816;
468468
uint8_t send_apdu[600] = {0}, *recv_apdu = send_apdu;
469-
uint16_t send_len = 0, recv_len = 236;
469+
uint16_t send_len = 0, recv_len = 600;
470470

471471
send_len = create_apdu_ecdsa(data_inOut, *length_inOut, send_apdu);
472472

@@ -507,7 +507,7 @@ ISO7816 nfc_verify_challenge(const uint8_t name[NAME_SIZE],
507507

508508
ISO7816 status_word = CLA_ISO7816;
509509
uint8_t send_apdu[600] = {0}, *recv_apdu = send_apdu;
510-
uint16_t send_len = 0, recv_len = 236;
510+
uint16_t send_len = 0, recv_len = 600;
511511

512512
send_len = create_apdu_verify_challenge(name, nonce, password, send_apdu);
513513

@@ -537,7 +537,7 @@ ISO7816 nfc_get_challenge(const uint8_t name[NAME_SIZE],
537537

538538
ISO7816 status_word = CLA_ISO7816;
539539
uint8_t send_apdu[600] = {0}, *recv_apdu = send_apdu;
540-
uint16_t send_len = 0, recv_len = 236;
540+
uint16_t send_len = 0, recv_len = 600;
541541

542542
send_len = create_apdu_get_challenge(name, send_apdu);
543543

@@ -575,7 +575,7 @@ ISO7816 nfc_encrypt_data(const uint8_t name[NAME_SIZE],
575575
#if USE_SIMULATOR == 0
576576
ISO7816 status_word = CLA_ISO7816;
577577
uint8_t send_apdu[600] = {0}, *recv_apdu = send_apdu;
578-
uint16_t send_len = 0, recv_len = 236;
578+
uint16_t send_len = 0, recv_len = 600;
579579

580580
send_len = create_apdu_inheritance(name,
581581
plain_data,
@@ -628,7 +628,7 @@ ISO7816 nfc_decrypt_data(const uint8_t name[NAME_SIZE],
628628

629629
ISO7816 status_word = CLA_ISO7816;
630630
uint8_t send_apdu[600] = {0}, *recv_apdu = send_apdu;
631-
uint16_t send_len = 0, recv_len = 236;
631+
uint16_t send_len = 0, recv_len = 600;
632632

633633
send_len = create_apdu_inheritance(name,
634634
encrypted_data,
@@ -670,7 +670,7 @@ ret_code_t nfc_exchange_apdu(uint8_t *send_apdu,
670670
ASSERT(recv_len != NULL);
671671
ASSERT(send_len != 0);
672672

673-
uint16_t expected_recv_len = MAX_EXPECTED_RECV_LEN;
673+
uint16_t expected_recv_len = *recv_len;
674674
*recv_len = 0;
675675

676676
ret_code_t err_code = adafruit_diagnose_card_presence();
@@ -697,8 +697,11 @@ ret_code_t nfc_exchange_apdu(uint8_t *send_apdu,
697697

698698
total_packets = ceil(send_len / (1.0 * SEND_PACKET_MAX_LEN));
699699
for (int packet = 1; packet <= total_packets;) {
700-
recv_pkt_len = RECV_PACKET_MAX_ENC_LEN; /* On every request set acceptable
701-
packet length */
700+
recv_pkt_len =
701+
RECV_PACKET_MAX_ENC_LEN <= expected_recv_len
702+
? RECV_PACKET_MAX_ENC_LEN
703+
: expected_recv_len; /* On every request set acceptable
704+
packet length */
702705

703706
/**
704707
* Sets appropriate CLA byte for each packet. CLA byte (first byte of

0 commit comments

Comments
 (0)