Skip to content

Commit

Permalink
Merge branch 'gornek/nfc_refactoring_v1' into st25tb_poller
Browse files Browse the repository at this point in the history
  • Loading branch information
augustozanellato committed Oct 13, 2023
2 parents c45cae9 + b58e7ab commit 8992e08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions applications/main/nfc/nfc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ bool nfc_delete(NfcApp* instance) {
nfc_delete_shadow_file(instance);
}

if(furi_string_end_with_str(instance->file_path, NFC_APP_SHADOW_EXTENSION)) {
size_t path_len = furi_string_size(instance->file_path);
furi_string_replace_at(instance->file_path, path_len - 4, 4, NFC_APP_EXTENSION);
}

return storage_simply_remove(instance->storage, furi_string_get_cstr(instance->file_path));
}

Expand Down
30 changes: 20 additions & 10 deletions lib/nfc/protocols/mf_ultralight/mf_ultralight_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ static void mf_ultralight_listener_perform_read(
mf_ultralight_single_counter_try_increase(instance);
}

static void mf_ultralight_listener_perform_write(
static MfUltralightCommand mf_ultralight_listener_perform_write(
MfUltralightListener* instance,
const uint8_t* const rx_data,
uint16_t start_page,
bool do_i2c_check) {
if(start_page == 2 && instance->sector == 0)
MfUltralightCommand command = MfUltralightCommandProcessedACK;

if(start_page < 2 && instance->sector == 0)
command = MfUltralightCommandNotProcessedNAK;
else if(start_page == 2 && instance->sector == 0)
mf_ultralight_static_lock_bytes_write(instance->static_lock, *((uint16_t*)&rx_data[2]));
else if(start_page == 3 && instance->sector == 0)
mf_ultralight_capability_container_write(&instance->data->page[start_page], rx_data);
Expand All @@ -102,6 +106,8 @@ static void mf_ultralight_listener_perform_write(

memcpy(instance->data->page[page].data, rx_data, sizeof(MfUltralightPage));
}

return command;
}

static MfUltralightCommand
Expand Down Expand Up @@ -201,20 +207,20 @@ static MfUltralightCommand

if(do_i2c_check) {
if(!mf_ultralight_i2c_validate_pages(start_page, start_page, instance)) break;
} else if(pages_total < start_page) {
break;
}

if(pages_total < start_page ||
!mf_ultralight_listener_check_access(
if(!mf_ultralight_listener_check_access(
instance, start_page, MfUltralightListenerAccessTypeWrite))
break;

if(mf_ultralight_static_lock_check_page(instance->static_lock, start_page)) break;
if(mf_ultralight_dynamic_lock_check_page(instance, start_page)) break;

const uint8_t* rx_data = bit_buffer_get_data(buffer);
mf_ultralight_listener_perform_write(instance, &rx_data[2], start_page, do_i2c_check);

command = MfUltralightCommandProcessedACK;
command =
mf_ultralight_listener_perform_write(instance, &rx_data[2], start_page, do_i2c_check);
} while(false);

return command;
Expand Down Expand Up @@ -463,9 +469,7 @@ static MfUltralightCommand
const uint8_t* rx_data = bit_buffer_get_data(buffer);
uint8_t start_page = instance->composite_cmd.data;

mf_ultralight_listener_perform_write(instance, rx_data, start_page, false);

command = MfUltralightCommandProcessedACK;
command = mf_ultralight_listener_perform_write(instance, rx_data, start_page, false);
} while(false);

return command;
Expand All @@ -490,6 +494,12 @@ static MfUltralightCommand
break;
}

if(!mf_ultralight_listener_check_access(
instance, start_page, MfUltralightListenerAccessTypeWrite)) {
command = MfUltralightCommandNotProcessedNAK;
break;
}

if(mf_ultralight_static_lock_check_page(instance->static_lock, start_page) ||
mf_ultralight_dynamic_lock_check_page(instance, start_page)) {
command = MfUltralightCommandNotProcessedNAK;
Expand Down

0 comments on commit 8992e08

Please sign in to comment.