Skip to content

Commit

Permalink
Use the card-supplied FWT for ISO14443-4A based cards
Browse files Browse the repository at this point in the history
  • Loading branch information
gsurkov committed Oct 18, 2023
1 parent 8b35a6a commit 6783940
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 68 deletions.
8 changes: 5 additions & 3 deletions lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ Iso14443_4aError
Iso14443_4aError iso14443_4a_poller_send_block(
Iso14443_4aPoller* instance,
const BitBuffer* tx_buffer,
BitBuffer* rx_buffer,
uint32_t fwt) {
BitBuffer* rx_buffer) {
furi_assert(instance);

bit_buffer_reset(instance->tx_buffer);
Expand All @@ -64,7 +63,10 @@ Iso14443_4aError iso14443_4a_poller_send_block(

do {
Iso14443_3aError iso14443_3a_error = iso14443_3a_poller_send_standard_frame(
instance->iso14443_3a_poller, instance->tx_buffer, instance->rx_buffer, fwt);
instance->iso14443_3a_poller,
instance->tx_buffer,
instance->rx_buffer,
iso14443_4a_get_fwt_fc_max(instance->data));

if(iso14443_3a_error != Iso14443_3aErrorNone) {
error = iso14443_4a_process_error(iso14443_3a_error);
Expand Down
3 changes: 1 addition & 2 deletions lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ Iso14443_4aError
Iso14443_4aError iso14443_4a_poller_send_block(
Iso14443_4aPoller* instance,
const BitBuffer* tx_buffer,
BitBuffer* rx_buffer,
uint32_t fwt);
BitBuffer* rx_buffer);

#ifdef __cplusplus
}
Expand Down
74 changes: 15 additions & 59 deletions lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ MfDesfireError mf_desfire_process_error(Iso14443_4aError error) {
MfDesfireError mf_desfire_send_chunks(
MfDesfirePoller* instance,
const BitBuffer* tx_buffer,
BitBuffer* rx_buffer,
uint32_t fwt) {
BitBuffer* rx_buffer) {
furi_assert(instance);
furi_assert(instance->iso14443_4a_poller);
furi_assert(instance->tx_buffer);
Expand All @@ -35,7 +34,7 @@ MfDesfireError mf_desfire_send_chunks(

do {
Iso14443_4aError iso14443_4a_error = iso14443_4a_poller_send_block(
instance->iso14443_4a_poller, tx_buffer, instance->rx_buffer, fwt);
instance->iso14443_4a_poller, tx_buffer, instance->rx_buffer);

if(iso14443_4a_error != Iso14443_4aErrorNone) {
error = mf_desfire_process_error(iso14443_4a_error);
Expand All @@ -53,7 +52,7 @@ MfDesfireError mf_desfire_send_chunks(

while(bit_buffer_starts_with_byte(instance->rx_buffer, MF_DESFIRE_FLAG_HAS_NEXT)) {
Iso14443_4aError iso14443_4a_error = iso14443_4a_poller_send_block(
instance->iso14443_4a_poller, instance->tx_buffer, instance->rx_buffer, fwt);
instance->iso14443_4a_poller, instance->tx_buffer, instance->rx_buffer);

if(iso14443_4a_error != Iso14443_4aErrorNone) {
error = mf_desfire_process_error(iso14443_4a_error);
Expand All @@ -77,11 +76,7 @@ MfDesfireError
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand All @@ -103,11 +98,7 @@ MfDesfireError
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand All @@ -130,11 +121,7 @@ MfDesfireError mf_desfire_poller_async_read_key_settings(
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand Down Expand Up @@ -163,11 +150,7 @@ MfDesfireError mf_desfire_poller_async_read_key_versions(
for(uint32_t i = 0; i < count; ++i) {
bit_buffer_set_byte(instance->input_buffer, 1, i);

error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand All @@ -190,11 +173,7 @@ MfDesfireError
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand Down Expand Up @@ -226,11 +205,8 @@ MfDesfireError mf_desfire_poller_async_select_application(
bit_buffer_append_bytes(
instance->input_buffer, (const uint8_t*)id, sizeof(MfDesfireApplicationId));

MfDesfireError error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
MfDesfireError error =
mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

return error;
}
Expand All @@ -245,11 +221,7 @@ MfDesfireError
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand Down Expand Up @@ -283,11 +255,7 @@ MfDesfireError mf_desfire_poller_async_read_file_settings(
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand Down Expand Up @@ -339,11 +307,7 @@ MfDesfireError mf_desfire_poller_async_read_file_data(
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand All @@ -368,11 +332,7 @@ MfDesfireError mf_desfire_poller_async_read_file_value(
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand Down Expand Up @@ -401,11 +361,7 @@ MfDesfireError mf_desfire_poller_async_read_file_records(
MfDesfireError error;

do {
error = mf_desfire_send_chunks(
instance,
instance->input_buffer,
instance->result_buffer,
MF_DESFIRE_POLLER_STANDARD_FWT_FC);
error = mf_desfire_send_chunks(instance, instance->input_buffer, instance->result_buffer);

if(error != MfDesfireErrorNone) break;

Expand Down
5 changes: 1 addition & 4 deletions lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
extern "C" {
#endif

#define MF_DESFIRE_POLLER_STANDARD_FWT_FC (200000)

typedef enum {
MfDesfirePollerStateIdle,
MfDesfirePollerStateReadVersion,
Expand Down Expand Up @@ -54,8 +52,7 @@ const MfDesfireData* mf_desfire_poller_get_data(MfDesfirePoller* instance);
MfDesfireError mf_desfire_send_chunks(
MfDesfirePoller* instance,
const BitBuffer* tx_buffer,
BitBuffer* rx_buffer,
uint32_t fwt);
BitBuffer* rx_buffer);

MfDesfireError
mf_desfire_poller_async_read_version(MfDesfirePoller* instance, MfDesfireVersion* data);
Expand Down

0 comments on commit 6783940

Please sign in to comment.