Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Fix NFC14443-3B (NFC-B) poller #2946

Merged
merged 1 commit into from
Aug 4, 2023
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: 1 addition & 0 deletions lib/nfc/helpers/bit_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void bit_buffer_reset(BitBuffer* buf) {
furi_assert(buf);

memset(buf->data, 0, buf->capacity_bytes);
memset(buf->parity, 0, buf->capacity_bytes);
buf->size_bits = 0;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/nfc/protocols/iso14443_3b/iso14443_3b_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ static NfcCommand iso14443_3b_poller_run(NfcGenericEvent event, void* context) {

if(nfc_event->type == NfcEventTypePollerReady) {
if(instance->state != Iso14443_3bPollerStateActivated) {
Iso14443_3bData data = {};
Iso14443_3bError error = iso14443_3b_poller_async_activate(instance, &data);
Iso14443_3bError error = iso14443_3b_poller_async_activate(instance, instance->data);
if(error == Iso14443_3bErrorNone) {
instance->iso14443_3b_event.type = Iso14443_3bPollerEventTypeReady;
instance->iso14443_3b_event_data.error = error;
Expand Down Expand Up @@ -105,7 +104,7 @@ static bool iso14443_3b_poller_detect(NfcGenericEvent event, void* context) {
furi_assert(instance->state == Iso14443_3bPollerStateIdle);

if(nfc_event->type == NfcEventTypePollerReady) {
Iso14443_3bError error = iso14443_3b_poller_async_activate(instance, NULL);
Iso14443_3bError error = iso14443_3b_poller_async_activate(instance, instance->data);
protocol_detected = (error == Iso14443_3bErrorNone);
}

Expand Down
15 changes: 5 additions & 10 deletions lib/nfc/protocols/iso14443_3b/iso14443_3b_poller_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Iso14443_3bError
furi_assert(instance);
furi_assert(instance->nfc);

iso14443_3b_reset(instance->data);
iso14443_3b_reset(data);

Iso14443_3bError ret;

Expand Down Expand Up @@ -99,16 +99,16 @@ Iso14443_3bError
const Iso14443_3bAtqB* atqb =
(const Iso14443_3bAtqB*)bit_buffer_get_data(instance->rx_buffer);

memcpy(instance->data->uid, atqb->uid, ISO14443_3B_UID_SIZE);
memcpy(instance->data->app_data, atqb->app_data, ISO14443_3B_APP_DATA_SIZE);
memcpy(instance->data->protocol_info, atqb->protocol_info, ISO14443_3B_PROTOCOL_INFO_SIZE);
memcpy(data->uid, atqb->uid, ISO14443_3B_UID_SIZE);
memcpy(data->app_data, atqb->app_data, ISO14443_3B_APP_DATA_SIZE);
memcpy(data->protocol_info, atqb->protocol_info, ISO14443_3B_PROTOCOL_INFO_SIZE);

bit_buffer_reset(instance->tx_buffer);
bit_buffer_reset(instance->rx_buffer);

// Send ATTRIB
bit_buffer_append_byte(instance->tx_buffer, 0x1d);
bit_buffer_append_bytes(instance->tx_buffer, atqb->uid, ISO14443_3B_UID_SIZE);
bit_buffer_append_bytes(instance->tx_buffer, data->uid, ISO14443_3B_UID_SIZE);
bit_buffer_append_byte(instance->tx_buffer, 0x00);
bit_buffer_append_byte(instance->tx_buffer, ISO14443_3B_ATTRIB_FRAME_SIZE_256);
bit_buffer_append_byte(instance->tx_buffer, 0x01);
Expand All @@ -130,11 +130,6 @@ Iso14443_3bError
}

instance->state = Iso14443_3bPollerStateActivated;

if(data) {
iso14443_3b_copy(data, instance->data);
}

} while(false);

return ret;
Expand Down