Fix some edge cases with max NDEF size

This commit is contained in:
Willy-JL
2025-03-20 07:19:54 +00:00
parent e2b7cd2d2c
commit c4f220625c
3 changed files with 6 additions and 4 deletions

View File

@@ -50,7 +50,8 @@ void type_4_tag_cc_dump(const Type4TagData* data, uint8_t* buf, size_t len) {
sizeof(cc->tlv[0].value.ndef_file_ctrl.file_id), sizeof(cc->tlv[0].value.ndef_file_ctrl.file_id),
(void*)&cc->tlv[0].value.ndef_file_ctrl.file_id); (void*)&cc->tlv[0].value.ndef_file_ctrl.file_id);
bit_lib_num_to_bytes_be( bit_lib_num_to_bytes_be(
data->is_tag_specific ? data->ndef_max_len : TYPE_4_TAG_DEFAULT_NDEF_SIZE, sizeof(uint16_t) +
(data->is_tag_specific ? data->ndef_max_len : TYPE_4_TAG_DEFAULT_NDEF_SIZE),
sizeof(cc->tlv[0].value.ndef_file_ctrl.max_len), sizeof(cc->tlv[0].value.ndef_file_ctrl.max_len),
(void*)&cc->tlv[0].value.ndef_file_ctrl.max_len); (void*)&cc->tlv[0].value.ndef_file_ctrl.max_len);
cc->tlv[0].value.ndef_file_ctrl.read_perm = cc->tlv[0].value.ndef_file_ctrl.read_perm =

View File

@@ -56,7 +56,7 @@
#define TYPE_4_TAG_BUF_SIZE (256U - 3U - 2U) #define TYPE_4_TAG_BUF_SIZE (256U - 3U - 2U)
// Read returns 2 byte status trailer, write sends 5 byte command header // Read returns 2 byte status trailer, write sends 5 byte command header
#define TYPE_4_TAG_CHUNK_LEN MIN(TYPE_4_TAG_BUF_SIZE - 5U, TYPE_4_TAG_ISO_RW_CHUNK_LEN) #define TYPE_4_TAG_CHUNK_LEN MIN(TYPE_4_TAG_BUF_SIZE - 5U, TYPE_4_TAG_ISO_RW_CHUNK_LEN)
#define TYPE_4_TAG_DEFAULT_NDEF_SIZE (2048U) #define TYPE_4_TAG_DEFAULT_NDEF_SIZE (2048U - sizeof(uint16_t))
extern const uint8_t type_4_tag_iso_mf_name[TYPE_4_TAG_ISO_NAME_LEN]; extern const uint8_t type_4_tag_iso_mf_name[TYPE_4_TAG_ISO_NAME_LEN];
extern const uint8_t type_4_tag_iso_df_name[TYPE_4_TAG_ISO_NAME_LEN]; extern const uint8_t type_4_tag_iso_df_name[TYPE_4_TAG_ISO_NAME_LEN];

View File

@@ -196,8 +196,9 @@ static Type4TagError type_4_tag_listener_iso_write(
} }
if(instance->state == Type4TagListenerStateSelectedNdefMessage) { if(instance->state == Type4TagListenerStateSelectedNdefMessage) {
if(offset + lc > (instance->data->is_tag_specific ? instance->data->ndef_max_len : if(offset + lc > sizeof(uint16_t) + (instance->data->is_tag_specific ?
TYPE_4_TAG_DEFAULT_NDEF_SIZE)) { instance->data->ndef_max_len :
TYPE_4_TAG_DEFAULT_NDEF_SIZE)) {
bit_buffer_append_bytes( bit_buffer_append_bytes(
instance->tx_buffer, instance->tx_buffer,
type_4_tag_offset_error_apdu, type_4_tag_offset_error_apdu,