mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 15:04:19 +00:00
[NFC] MF Ultralight no pwd polling adjustment (#3207)
* Listener log level changed to Trace * Show pages count without pwd pages in case of no auth success * Fixed unit tests Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
dc246ddb09
commit
d0b9a3a4ae
3 changed files with 34 additions and 19 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue