mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 23:18:35 -07:00
Fix reading empty NDEF message
This commit is contained in:
@@ -44,12 +44,16 @@ static void nfc_scene_more_info_on_enter_type_4_tag(NfcApp* instance) {
|
|||||||
scene_manager_get_scene_state(instance->scene_manager, NfcSceneMoreInfo);
|
scene_manager_get_scene_state(instance->scene_manager, NfcSceneMoreInfo);
|
||||||
|
|
||||||
if(scene_state == NfcSceneMoreInfoStateASCII) {
|
if(scene_state == NfcSceneMoreInfoStateASCII) {
|
||||||
pretty_format_bytes_hex_canonical(
|
if(simple_array_get_count(data->ndef_data) == 0) {
|
||||||
instance->text_box_store,
|
furi_string_cat_str(instance->text_box_store, "No NDEF data to show");
|
||||||
TYPE_4_TAG_RENDER_BYTES_PER_LINE,
|
} else {
|
||||||
PRETTY_FORMAT_FONT_MONOSPACE,
|
pretty_format_bytes_hex_canonical(
|
||||||
simple_array_cget_data(data->ndef_data),
|
instance->text_box_store,
|
||||||
simple_array_get_count(data->ndef_data));
|
TYPE_4_TAG_RENDER_BYTES_PER_LINE,
|
||||||
|
PRETTY_FORMAT_FONT_MONOSPACE,
|
||||||
|
simple_array_cget_data(data->ndef_data),
|
||||||
|
simple_array_get_count(data->ndef_data));
|
||||||
|
}
|
||||||
|
|
||||||
widget_add_text_scroll_element(
|
widget_add_text_scroll_element(
|
||||||
instance->widget, 0, 0, 128, 48, furi_string_get_cstr(instance->text_box_store));
|
instance->widget, 0, 0, 128, 48, furi_string_get_cstr(instance->text_box_store));
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ void nfc_render_type_4_tag_info(
|
|||||||
FuriString* str) {
|
FuriString* str) {
|
||||||
nfc_render_iso14443_4a_brief(type_4_tag_get_base_data(data), str);
|
nfc_render_iso14443_4a_brief(type_4_tag_get_base_data(data), str);
|
||||||
|
|
||||||
furi_string_cat(str, "\n::::::::::::::::::[Tag Specs]::::::::::::::::::\n");
|
furi_string_cat(str, "\n:::::::::::::::[Stored NDEF]:::::::::::::::\n");
|
||||||
|
furi_string_cat_printf(
|
||||||
|
str, "Current NDEF Size: %lu\n", simple_array_get_count(data->ndef_data));
|
||||||
|
|
||||||
|
furi_string_cat(str, "::::::::::::::::::[Tag Specs]::::::::::::::::::\n");
|
||||||
furi_string_cat_printf(
|
furi_string_cat_printf(
|
||||||
str, "T4T Mapping Version: %u.%u\n", data->t4t_version.major, data->t4t_version.minor);
|
str, "T4T Mapping Version: %u.%u\n", data->t4t_version.major, data->t4t_version.minor);
|
||||||
furi_string_cat_printf(str, "NDEF File ID: 0x%04X\n", data->ndef_file_id);
|
furi_string_cat_printf(str, "NDEF File ID: 0x%04X\n", data->ndef_file_id);
|
||||||
@@ -24,13 +28,10 @@ void nfc_render_type_4_tag_info(
|
|||||||
data->ndef_read_lock == 0 ? " (unlocked)" : "");
|
data->ndef_read_lock == 0 ? " (unlocked)" : "");
|
||||||
furi_string_cat_printf(
|
furi_string_cat_printf(
|
||||||
str,
|
str,
|
||||||
"Write Lock: 0x%02X%s\n",
|
"Write Lock: 0x%02X%s",
|
||||||
data->ndef_write_lock,
|
data->ndef_write_lock,
|
||||||
data->ndef_write_lock == 0 ? " (unlocked)" : "");
|
data->ndef_write_lock == 0 ? " (unlocked)" : "");
|
||||||
|
|
||||||
furi_string_cat(str, ":::::::::::::::[Stored NDEF]:::::::::::::::\n");
|
|
||||||
furi_string_cat_printf(str, "Current NDEF Size: %lu", simple_array_get_count(data->ndef_data));
|
|
||||||
|
|
||||||
if(format_type != NfcProtocolFormatTypeFull) return;
|
if(format_type != NfcProtocolFormatTypeFull) return;
|
||||||
|
|
||||||
furi_string_cat(str, "\n\e#ISO14443-4 data");
|
furi_string_cat(str, "\n\e#ISO14443-4 data");
|
||||||
@@ -38,9 +39,13 @@ void nfc_render_type_4_tag_info(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nfc_render_type_4_tag_dump(const Type4TagData* data, FuriString* str) {
|
void nfc_render_type_4_tag_dump(const Type4TagData* data, FuriString* str) {
|
||||||
furi_string_cat_printf(str, "\e*");
|
|
||||||
const uint8_t* ndef_data = simple_array_cget_data(data->ndef_data);
|
|
||||||
size_t ndef_len = simple_array_get_count(data->ndef_data);
|
size_t ndef_len = simple_array_get_count(data->ndef_data);
|
||||||
|
if(ndef_len == 0) {
|
||||||
|
furi_string_cat_str(str, "No NDEF data to show");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const uint8_t* ndef_data = simple_array_cget_data(data->ndef_data);
|
||||||
|
furi_string_cat_printf(str, "\e*");
|
||||||
for(size_t i = 0; i < ndef_len; i += TYPE_4_TAG_RENDER_BYTES_PER_LINE) {
|
for(size_t i = 0; i < ndef_len; i += TYPE_4_TAG_RENDER_BYTES_PER_LINE) {
|
||||||
const uint8_t* line_data = &ndef_data[i];
|
const uint8_t* line_data = &ndef_data[i];
|
||||||
for(size_t j = 0; j < TYPE_4_TAG_RENDER_BYTES_PER_LINE; j += 2) {
|
for(size_t j = 0; j < TYPE_4_TAG_RENDER_BYTES_PER_LINE; j += 2) {
|
||||||
|
|||||||
@@ -208,14 +208,20 @@ Type4TagError type_4_tag_poller_read_ndef(Type4TagPoller* instance) {
|
|||||||
|
|
||||||
ndef_len =
|
ndef_len =
|
||||||
bit_lib_bytes_to_num_be(bit_buffer_get_data(instance->rx_buffer), sizeof(ndef_len));
|
bit_lib_bytes_to_num_be(bit_buffer_get_data(instance->rx_buffer), sizeof(ndef_len));
|
||||||
simple_array_init(instance->data->ndef_data, ndef_len);
|
if(ndef_len == 0) {
|
||||||
|
FURI_LOG_D(TAG, "NDEF file is empty");
|
||||||
|
break;
|
||||||
|
}
|
||||||
if(ndef_len > 510) {
|
if(ndef_len > 510) {
|
||||||
// Both size and offset for READ BINARY are 1 byte uint
|
// Both size and offset for READ BINARY are 1 byte uint
|
||||||
// So the furthest we can read is 255 bytes at offset 255
|
// So the furthest we can read is 255 bytes at offset 255
|
||||||
// AKA 2 * 255 byte chunks = 510 bytes
|
// AKA 2 * 255 byte chunks = 510 bytes
|
||||||
// TODO: Surely there has to be another way?
|
// TODO: Surely there has to be another way?
|
||||||
FURI_LOG_E(TAG, "NDEF file too long: %zu bytes", ndef_len);
|
FURI_LOG_E(TAG, "NDEF file too long: %zu bytes", ndef_len);
|
||||||
|
error = Type4TagErrorProtocol;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
simple_array_init(instance->data->ndef_data, ndef_len);
|
||||||
|
|
||||||
FURI_LOG_D(TAG, "Read NDEF");
|
FURI_LOG_D(TAG, "Read NDEF");
|
||||||
const uint8_t type_4_tag_read_ndef_apdu_1[] = {
|
const uint8_t type_4_tag_read_ndef_apdu_1[] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user