Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/drivers/st25r3916_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ void st25r3916_read_pta_mem(FuriHalSpiBusHandle* handle, uint8_t* buff, size_t l
st25r3916_reg_tx_byte(handle, ST25R3916_PT_MEM_READ);
furi_hal_spi_bus_rx(handle, tmp_buff, length + 1, 200);
furi_hal_gpio_write(handle->cs, true);
furi_hal_gpio_write(handle->cs, true);
memcpy(buff, tmp_buff + 1, length);
}

Expand Down
4 changes: 1 addition & 3 deletions lib/nfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ static int32_t nfc_worker_listener(void* context) {
while(true) {
FHalNfcEvent event = f_hal_nfc_wait_event(F_HAL_NFC_EVENT_WAIT_FOREVER);
if(event & FHalNfcEventAbortRequest) {
FURI_LOG_D(TAG, "Abort request received");
nfc_event.type = NfcEventTypeUserAbort;
instance->callback(nfc_event, instance->context);
break;
Expand All @@ -105,7 +104,6 @@ static int32_t nfc_worker_listener(void* context) {
instance->callback(nfc_event, instance->context);
}
if(event & FHalNfcEventFieldOff) {
FURI_LOG_T(TAG, "Field off");
nfc_event.type = NfcEventTypeFieldOff;
instance->callback(nfc_event, instance->context);
f_hal_nfc_listener_sleep();
Expand All @@ -124,7 +122,7 @@ static int32_t nfc_worker_listener(void* context) {
if(command == NfcCommandStop) {
break;
} else if(command == NfcCommandReset) {
f_hal_nfc_listen_reset();
//f_hal_nfc_listen_reset();
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/nfc/protocols/iso14443_3a/iso14443_3a_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ NfcCommand iso14443_3a_listener_run(NfcGenericEvent event, void* context) {
if(instance->callback) {
command = instance->callback(instance->generic_event, instance->context);
}

if(command == NfcCommandReset) {
iso14443_3a_listener_sleep(instance);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/nfc/protocols/mf_classic/mf_classic_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ static MfClassicListenerCommand
instance->auth_state = MfClassicListenerAuthStateIdle;
instance->state = MfClassicListenerStateAuthComplete;
instance->comm_state = MfClassicListenerCommStateEncrypted;
command = MfClassicListenerCommandProcessed;

if(instance->callback) {
instance->mfc_event.type = MfClassicListenerEventTypeAuthContextFullCollected,
Expand Down
2 changes: 1 addition & 1 deletion lib/nfc/protocols/mf_ultralight/mf_ultralight.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ bool mf_ultralight_save(const MfUltralightData* data, FlipperFormat* ff) {
}
furi_string_printf(temp_str, "%s %d", MF_ULTRALIGHT_TEARING_KEY, i);
if(!flipper_format_write_hex(
ff, furi_string_get_cstr(temp_str), data->tearing_flag->data, 1)) {
ff, furi_string_get_cstr(temp_str), data->tearing_flag[i].data, 1)) {
counters_saved = false;
break;
}
Expand Down
53 changes: 42 additions & 11 deletions lib/nfc/protocols/mf_ultralight/mf_ultralight_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ static bool
uint16_t pages_total = instance->data->pages_total;
MfUltralightPageReadCommandData read_cmd_data = {};

FURI_LOG_D(TAG, "CMD_READ");

if(pages_total < start_page) {
mf_ultralight_listener_send_short_resp(instance, MF_ULTRALIGHT_CMD_NACK);
instance->state = MfUltraligthListenerStateIdle;
Expand Down Expand Up @@ -106,6 +108,8 @@ static bool
uint8_t start_page = bit_buffer_get_byte(buffer, 1);
uint16_t pages_total = instance->data->pages_total;

FURI_LOG_D(TAG, "CMD_WRITE");

if(pages_total < start_page) {
mf_ultralight_listener_send_short_resp(instance, MF_ULTRALIGHT_CMD_NACK);
instance->state = MfUltraligthListenerStateIdle;
Expand All @@ -129,6 +133,8 @@ static bool
mf_ultralight_listener_read_version_handler(MfUltralightListener* instance, BitBuffer* buffer) {
UNUSED(buffer);

FURI_LOG_D(TAG, "CMD_GET_VERSION");

bool command_processed = false;

if((instance->features & MfUltralightFeatureSupportReadVersion)) {
Expand All @@ -150,6 +156,8 @@ static bool mf_ultralight_listener_read_signature_handler(
BitBuffer* buffer) {
UNUSED(buffer);

FURI_LOG_D(TAG, "CMD_READ_SIG");

bool command_processed = false;

if((instance->features & MfUltralightFeatureSupportReadSignature)) {
Expand All @@ -170,6 +178,8 @@ static bool
mf_ultralight_listener_read_counter_handler(MfUltralightListener* instance, BitBuffer* buffer) {
bool command_processed = false;

FURI_LOG_D(TAG, "CMD_READ_CNT");

do {
uint8_t counter_num = bit_buffer_get_byte(buffer, 1);
if((instance->features & MfUltralightFeatureSupportReadCounter) == 0) break;
Expand All @@ -179,9 +189,9 @@ static bool
}
}
if(instance->config) {
if(!instance->config->access.nfc_cnt_en) {
/* if(!instance->config->access.nfc_cnt_en) {
break;
}
}*/
if(instance->config->access.nfc_cnt_pwd_prot) {
if(instance->auth_state != MfUltralightListenerAuthStateSuccess) {
break;
Expand All @@ -208,15 +218,24 @@ static bool mf_ultralight_listener_check_tearing_handler(
BitBuffer* buffer) {
bool command_processed = false;

FURI_LOG_D(TAG, "CMD_CHECK_TEARING");

do {
uint8_t tearing_flag_num = bit_buffer_get_byte(buffer, 1);
if((instance->features & MfUltralightFeatureSupportCheckTearingFlag) == 0) break;
if(tearing_flag_num > 2) break;
bit_buffer_set_size_bytes(instance->tx_buffer, 1);
bit_buffer_set_byte(instance->tx_buffer, 0, instance->data->tearing_flag->data[0]);
iso14443_3a_listener_send_standard_frame(
instance->iso14443_3a_listener, instance->tx_buffer);
command_processed = true;
if(instance->features & (MfUltralightFeatureSupportCheckTearingFlag |
MfUltralightFeatureSupportSingleCounter)) {
if((instance->features & MfUltralightFeatureSupportSingleCounter) &&
(tearing_flag_num != 2)) {
break;
}

bit_buffer_set_size_bytes(instance->tx_buffer, 1);
bit_buffer_set_byte(
instance->tx_buffer, 0, instance->data->tearing_flag->data[tearing_flag_num]);
iso14443_3a_listener_send_standard_frame(
instance->iso14443_3a_listener, instance->tx_buffer);
command_processed = true;
}
} while(false);

return command_processed;
Expand All @@ -226,6 +245,8 @@ static bool
mf_ultralight_listener_auth_handler(MfUltralightListener* instance, BitBuffer* buffer) {
bool command_processed = false;

FURI_LOG_D(TAG, "CMD_AUTH");

do {
if((instance->features & MfUltralightFeatureSupportAuthentication) == 0) break;

Expand Down Expand Up @@ -357,14 +378,24 @@ NfcCommand mf_ultralight_listener_run(NfcGenericEvent event, void* context) {
for(size_t i = 0; i < COUNT_OF(mf_ultralight_command); i++) {
if(bit_buffer_get_size(rx_buffer) != mf_ultralight_command[i].cmd_len_bits) continue;
if(bit_buffer_get_byte(rx_buffer, 0) != mf_ultralight_command[i].cmd) continue;
cmd_processed = mf_ultralight_command[i].callback(instance, rx_buffer);
if(cmd_processed) break;
cmd_processed = mf_ultralight_command[i].callback(
instance, rx_buffer); //TODO make commands return enumed status, not just bool
if(cmd_processed) { //to make immediate NACK response when not processed
break;
}
}
if(!cmd_processed) {
mf_ultralight_listener_send_short_resp(instance, MF_ULTRALIGHT_CMD_NACK);
instance->state = MfUltraligthListenerStateIdle;
instance->auth_state = MfUltralightListenerAuthStateIdle;
command = NfcCommandReset;
}
} else if(iso14443_3a_event->type == Iso14443_3aListenerEventTypeReceivedData) {
command = NfcCommandReset;
} else if(iso14443_3a_event->type == Iso14443_3aListenerEventTypeFieldOff) {
command = NfcCommandReset;
} else if(iso14443_3a_event->type == Iso14443_3aListenerEventTypeHalted) {
command = NfcCommandReset;
}

return command;
Expand Down
6 changes: 5 additions & 1 deletion lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,14 @@ static NfcCommand mf_ultralight_poller_handler_read_counters(MfUltralightPoller*
}

static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPoller* instance) {
if(instance->feature_set & MfUltralightFeatureSupportCheckTearingFlag) {
if(instance->feature_set &
(MfUltralightFeatureSupportCheckTearingFlag | MfUltralightFeatureSupportSingleCounter)) {
if(instance->tearing_flag_read == instance->tearing_flag_total) {
instance->state = MfUltralightPollerStateTryDefaultPass;
} else {
if(instance->feature_set & MfUltralightFeatureSupportSingleCounter) {
instance->tearing_flag_read = 2;
}
FURI_LOG_D(TAG, "Reading tearing flag %d", instance->tearing_flag_read);
instance->error = mf_ultralight_poller_async_read_tearing_flag(
instance,
Expand Down