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] MF Ultralight no pwd polling adjustment #3207

Merged
merged 5 commits into from
Nov 15, 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
19 changes: 15 additions & 4 deletions applications/debug/unit_tests/nfc/nfc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,21 @@ static void mf_ultralight_reader_test(const char* path) {
NfcDevice* nfc_device = nfc_device_alloc();
mu_assert(nfc_device_load(nfc_device, path), "nfc_device_load() failed\r\n");

NfcListener* mfu_listener = nfc_listener_alloc(
listener,
NfcProtocolMfUltralight,
nfc_device_get_data(nfc_device, NfcProtocolMfUltralight));
MfUltralightData* data =
(MfUltralightData*)nfc_device_get_data(nfc_device, NfcProtocolMfUltralight);

uint32_t features = mf_ultralight_get_feature_support_set(data->type);
bool pwd_supported =
mf_ultralight_support_feature(features, MfUltralightFeatureSupportPasswordAuth);
uint8_t pwd_num = mf_ultralight_get_pwd_page_num(data->type);
const uint8_t zero_pwd[4] = {0, 0, 0, 0};

if(pwd_supported && !memcmp(data->page[pwd_num].data, zero_pwd, sizeof(zero_pwd))) {
data->pages_read -= 2;
}

NfcListener* mfu_listener = nfc_listener_alloc(listener, NfcProtocolMfUltralight, data);

nfc_listener_start(mfu_listener, NULL, NULL);

MfUltralightData* mfu_data = mf_ultralight_alloc();
Expand Down
30 changes: 15 additions & 15 deletions lib/nfc/protocols/mf_ultralight/mf_ultralight_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static MfUltralightCommand
uint16_t pages_total = instance->data->pages_total;
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;

FURI_LOG_D(TAG, "CMD_READ: %d", start_page);
FURI_LOG_T(TAG, "CMD_READ: %d", start_page);

do {
bool do_i2c_check = mf_ultralight_is_i2c_tag(instance->data->type);
Expand Down Expand Up @@ -154,7 +154,7 @@ static MfUltralightCommand
static MfUltralightCommand
mf_ultralight_listener_fast_read_handler(MfUltralightListener* instance, BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
FURI_LOG_D(TAG, "CMD_FAST_READ");
FURI_LOG_T(TAG, "CMD_FAST_READ");

do {
if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportFastRead))
Expand Down Expand Up @@ -206,7 +206,7 @@ static MfUltralightCommand
uint16_t pages_total = instance->data->pages_total;
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;

FURI_LOG_D(TAG, "CMD_WRITE");
FURI_LOG_T(TAG, "CMD_WRITE");

do {
bool do_i2c_check = mf_ultralight_is_i2c_tag(instance->data->type);
Expand Down Expand Up @@ -235,7 +235,7 @@ static MfUltralightCommand
static MfUltralightCommand
mf_ultralight_listener_fast_write_handler(MfUltralightListener* instance, BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
FURI_LOG_D(TAG, "CMD_FAST_WRITE");
FURI_LOG_T(TAG, "CMD_FAST_WRITE");

do {
if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportFastWrite))
Expand All @@ -261,7 +261,7 @@ static MfUltralightCommand
UNUSED(buffer);
MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;

FURI_LOG_D(TAG, "CMD_GET_VERSION");
FURI_LOG_T(TAG, "CMD_GET_VERSION");

if(mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportReadVersion)) {
bit_buffer_copy_bytes(
Expand All @@ -280,7 +280,7 @@ static MfUltralightCommand mf_ultralight_listener_read_signature_handler(
UNUSED(buffer);
MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;

FURI_LOG_D(TAG, "CMD_READ_SIG");
FURI_LOG_T(TAG, "CMD_READ_SIG");

if(mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportReadSignature)) {
bit_buffer_copy_bytes(
Expand All @@ -297,7 +297,7 @@ static MfUltralightCommand
mf_ultralight_listener_read_counter_handler(MfUltralightListener* instance, BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;

FURI_LOG_D(TAG, "CMD_READ_CNT");
FURI_LOG_T(TAG, "CMD_READ_CNT");

do {
uint8_t counter_num = bit_buffer_get_byte(buffer, 1);
Expand Down Expand Up @@ -338,7 +338,7 @@ static MfUltralightCommand mf_ultralight_listener_increase_counter_handler(
BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;

FURI_LOG_D(TAG, "CMD_INCR_CNT");
FURI_LOG_T(TAG, "CMD_INCR_CNT");

do {
if(!mf_ultralight_support_feature(
Expand Down Expand Up @@ -374,7 +374,7 @@ static MfUltralightCommand mf_ultralight_listener_check_tearing_handler(
BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;

FURI_LOG_D(TAG, "CMD_CHECK_TEARING");
FURI_LOG_T(TAG, "CMD_CHECK_TEARING");

do {
uint8_t tearing_flag_num = bit_buffer_get_byte(buffer, 1);
Expand Down Expand Up @@ -410,7 +410,7 @@ static MfUltralightCommand
MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
UNUSED(instance);
UNUSED(buffer);
FURI_LOG_D(TAG, "CMD_VCSL");
FURI_LOG_T(TAG, "CMD_VCSL");
do {
if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportVcsl))
break;
Expand All @@ -432,7 +432,7 @@ static MfUltralightCommand
mf_ultralight_listener_auth_handler(MfUltralightListener* instance, BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;

FURI_LOG_D(TAG, "CMD_AUTH");
FURI_LOG_T(TAG, "CMD_AUTH");

do {
if(!mf_ultralight_support_feature(
Expand Down Expand Up @@ -474,7 +474,7 @@ static MfUltralightCommand
static MfUltralightCommand
mf_ultralight_comp_write_handler_p2(MfUltralightListener* instance, BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
FURI_LOG_D(TAG, "CMD_CM_WR_2");
FURI_LOG_T(TAG, "CMD_CM_WR_2");

do {
if(bit_buffer_get_size_bytes(buffer) != 16) break;
Expand All @@ -492,7 +492,7 @@ static MfUltralightCommand
mf_ultralight_comp_write_handler_p1(MfUltralightListener* instance, BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;

FURI_LOG_D(TAG, "CMD_CM_WR_1");
FURI_LOG_T(TAG, "CMD_CM_WR_1");

do {
if(!mf_ultralight_support_feature(
Expand Down Expand Up @@ -532,7 +532,7 @@ static MfUltralightCommand
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
UNUSED(instance);
UNUSED(buffer);
FURI_LOG_D(TAG, "CMD_SEC_SEL_2");
FURI_LOG_T(TAG, "CMD_SEC_SEL_2");

do {
if(bit_buffer_get_size_bytes(buffer) != 4) break;
Expand All @@ -550,7 +550,7 @@ static MfUltralightCommand
mf_ultralight_sector_select_handler_p1(MfUltralightListener* instance, BitBuffer* buffer) {
MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
UNUSED(buffer);
FURI_LOG_D(TAG, "CMD_SEC_SEL_1");
FURI_LOG_T(TAG, "CMD_SEC_SEL_1");

do {
if(!mf_ultralight_support_feature(
Expand Down
4 changes: 4 additions & 0 deletions lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ static NfcCommand mf_ultralight_poller_handler_try_default_pass(MfUltralightPoll
sizeof(MfUltralightAuthPassword),
config->password.data);
config->pack = instance->auth_context.pack;
instance->auth_context.auth_success = true;
}
}

Expand All @@ -496,6 +497,9 @@ static NfcCommand mf_ultralight_poller_handler_try_default_pass(MfUltralightPoll
// original card
config->auth0 = instance->pages_read;
config->access.prot = true;
} else if(!instance->auth_context.auth_success) {
instance->pages_read -= 2;
instance->data->pages_read -= 2;
}
} while(false);

Expand Down