[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
					
				@ -203,10 +203,21 @@ static void mf_ultralight_reader_test(const char* path) {
 | 
				
			|||||||
    NfcDevice* nfc_device = nfc_device_alloc();
 | 
					    NfcDevice* nfc_device = nfc_device_alloc();
 | 
				
			||||||
    mu_assert(nfc_device_load(nfc_device, path), "nfc_device_load() failed\r\n");
 | 
					    mu_assert(nfc_device_load(nfc_device, path), "nfc_device_load() failed\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    NfcListener* mfu_listener = nfc_listener_alloc(
 | 
					    MfUltralightData* data =
 | 
				
			||||||
        listener,
 | 
					        (MfUltralightData*)nfc_device_get_data(nfc_device, NfcProtocolMfUltralight);
 | 
				
			||||||
        NfcProtocolMfUltralight,
 | 
					
 | 
				
			||||||
        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);
 | 
					    nfc_listener_start(mfu_listener, NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MfUltralightData* mfu_data = mf_ultralight_alloc();
 | 
					    MfUltralightData* mfu_data = mf_ultralight_alloc();
 | 
				
			||||||
 | 
				
			|||||||
@ -122,7 +122,7 @@ static MfUltralightCommand
 | 
				
			|||||||
    uint16_t pages_total = instance->data->pages_total;
 | 
					    uint16_t pages_total = instance->data->pages_total;
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_READ: %d", start_page);
 | 
					    FURI_LOG_T(TAG, "CMD_READ: %d", start_page);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        bool do_i2c_check = mf_ultralight_is_i2c_tag(instance->data->type);
 | 
					        bool do_i2c_check = mf_ultralight_is_i2c_tag(instance->data->type);
 | 
				
			||||||
@ -154,7 +154,7 @@ static MfUltralightCommand
 | 
				
			|||||||
static MfUltralightCommand
 | 
					static MfUltralightCommand
 | 
				
			||||||
    mf_ultralight_listener_fast_read_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
					    mf_ultralight_listener_fast_read_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_FAST_READ");
 | 
					    FURI_LOG_T(TAG, "CMD_FAST_READ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportFastRead))
 | 
					        if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportFastRead))
 | 
				
			||||||
@ -206,7 +206,7 @@ static MfUltralightCommand
 | 
				
			|||||||
    uint16_t pages_total = instance->data->pages_total;
 | 
					    uint16_t pages_total = instance->data->pages_total;
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_WRITE");
 | 
					    FURI_LOG_T(TAG, "CMD_WRITE");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        bool do_i2c_check = mf_ultralight_is_i2c_tag(instance->data->type);
 | 
					        bool do_i2c_check = mf_ultralight_is_i2c_tag(instance->data->type);
 | 
				
			||||||
@ -235,7 +235,7 @@ static MfUltralightCommand
 | 
				
			|||||||
static MfUltralightCommand
 | 
					static MfUltralightCommand
 | 
				
			||||||
    mf_ultralight_listener_fast_write_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
					    mf_ultralight_listener_fast_write_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_FAST_WRITE");
 | 
					    FURI_LOG_T(TAG, "CMD_FAST_WRITE");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportFastWrite))
 | 
					        if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportFastWrite))
 | 
				
			||||||
@ -261,7 +261,7 @@ static MfUltralightCommand
 | 
				
			|||||||
    UNUSED(buffer);
 | 
					    UNUSED(buffer);
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
					    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)) {
 | 
					    if(mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportReadVersion)) {
 | 
				
			||||||
        bit_buffer_copy_bytes(
 | 
					        bit_buffer_copy_bytes(
 | 
				
			||||||
@ -280,7 +280,7 @@ static MfUltralightCommand mf_ultralight_listener_read_signature_handler(
 | 
				
			|||||||
    UNUSED(buffer);
 | 
					    UNUSED(buffer);
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
					    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)) {
 | 
					    if(mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportReadSignature)) {
 | 
				
			||||||
        bit_buffer_copy_bytes(
 | 
					        bit_buffer_copy_bytes(
 | 
				
			||||||
@ -297,7 +297,7 @@ static MfUltralightCommand
 | 
				
			|||||||
    mf_ultralight_listener_read_counter_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
					    mf_ultralight_listener_read_counter_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_READ_CNT");
 | 
					    FURI_LOG_T(TAG, "CMD_READ_CNT");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        uint8_t counter_num = bit_buffer_get_byte(buffer, 1);
 | 
					        uint8_t counter_num = bit_buffer_get_byte(buffer, 1);
 | 
				
			||||||
@ -338,7 +338,7 @@ static MfUltralightCommand mf_ultralight_listener_increase_counter_handler(
 | 
				
			|||||||
    BitBuffer* buffer) {
 | 
					    BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_INCR_CNT");
 | 
					    FURI_LOG_T(TAG, "CMD_INCR_CNT");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(!mf_ultralight_support_feature(
 | 
					        if(!mf_ultralight_support_feature(
 | 
				
			||||||
@ -374,7 +374,7 @@ static MfUltralightCommand mf_ultralight_listener_check_tearing_handler(
 | 
				
			|||||||
    BitBuffer* buffer) {
 | 
					    BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_CHECK_TEARING");
 | 
					    FURI_LOG_T(TAG, "CMD_CHECK_TEARING");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        uint8_t tearing_flag_num = bit_buffer_get_byte(buffer, 1);
 | 
					        uint8_t tearing_flag_num = bit_buffer_get_byte(buffer, 1);
 | 
				
			||||||
@ -410,7 +410,7 @@ static MfUltralightCommand
 | 
				
			|||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
				
			||||||
    UNUSED(instance);
 | 
					    UNUSED(instance);
 | 
				
			||||||
    UNUSED(buffer);
 | 
					    UNUSED(buffer);
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_VCSL");
 | 
					    FURI_LOG_T(TAG, "CMD_VCSL");
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportVcsl))
 | 
					        if(!mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportVcsl))
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
@ -432,7 +432,7 @@ static MfUltralightCommand
 | 
				
			|||||||
    mf_ultralight_listener_auth_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
					    mf_ultralight_listener_auth_handler(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_AUTH");
 | 
					    FURI_LOG_T(TAG, "CMD_AUTH");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(!mf_ultralight_support_feature(
 | 
					        if(!mf_ultralight_support_feature(
 | 
				
			||||||
@ -474,7 +474,7 @@ static MfUltralightCommand
 | 
				
			|||||||
static MfUltralightCommand
 | 
					static MfUltralightCommand
 | 
				
			||||||
    mf_ultralight_comp_write_handler_p2(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
					    mf_ultralight_comp_write_handler_p2(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_CM_WR_2");
 | 
					    FURI_LOG_T(TAG, "CMD_CM_WR_2");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(bit_buffer_get_size_bytes(buffer) != 16) break;
 | 
					        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) {
 | 
					    mf_ultralight_comp_write_handler_p1(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedSilent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_CM_WR_1");
 | 
					    FURI_LOG_T(TAG, "CMD_CM_WR_1");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(!mf_ultralight_support_feature(
 | 
					        if(!mf_ultralight_support_feature(
 | 
				
			||||||
@ -532,7 +532,7 @@ static MfUltralightCommand
 | 
				
			|||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
    UNUSED(instance);
 | 
					    UNUSED(instance);
 | 
				
			||||||
    UNUSED(buffer);
 | 
					    UNUSED(buffer);
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_SEC_SEL_2");
 | 
					    FURI_LOG_T(TAG, "CMD_SEC_SEL_2");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(bit_buffer_get_size_bytes(buffer) != 4) break;
 | 
					        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) {
 | 
					    mf_ultralight_sector_select_handler_p1(MfUltralightListener* instance, BitBuffer* buffer) {
 | 
				
			||||||
    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
					    MfUltralightCommand command = MfUltralightCommandNotProcessedNAK;
 | 
				
			||||||
    UNUSED(buffer);
 | 
					    UNUSED(buffer);
 | 
				
			||||||
    FURI_LOG_D(TAG, "CMD_SEC_SEL_1");
 | 
					    FURI_LOG_T(TAG, "CMD_SEC_SEL_1");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        if(!mf_ultralight_support_feature(
 | 
					        if(!mf_ultralight_support_feature(
 | 
				
			||||||
 | 
				
			|||||||
@ -487,6 +487,7 @@ static NfcCommand mf_ultralight_poller_handler_try_default_pass(MfUltralightPoll
 | 
				
			|||||||
                    sizeof(MfUltralightAuthPassword),
 | 
					                    sizeof(MfUltralightAuthPassword),
 | 
				
			||||||
                    config->password.data);
 | 
					                    config->password.data);
 | 
				
			||||||
                config->pack = instance->auth_context.pack;
 | 
					                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
 | 
					            // original card
 | 
				
			||||||
            config->auth0 = instance->pages_read;
 | 
					            config->auth0 = instance->pages_read;
 | 
				
			||||||
            config->access.prot = true;
 | 
					            config->access.prot = true;
 | 
				
			||||||
 | 
					        } else if(!instance->auth_context.auth_success) {
 | 
				
			||||||
 | 
					            instance->pages_read -= 2;
 | 
				
			||||||
 | 
					            instance->data->pages_read -= 2;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } while(false);
 | 
					    } while(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user