[FL-3717] MFC emulation fix (#3291)

* mf classic listener: reset state before sleep and after nack
* Fix PVS warnings
* Fix PVS and compiler disagree on builtins

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich 2023-12-15 21:51:20 +04:00 committed by GitHub
parent 36aecfbec9
commit 09540929c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions

View file

@ -52,7 +52,7 @@ static bool mykey_parse(const NfcDevice* device, FuriString* parsed_data) {
} }
bool is_blank = mykey_is_blank(data); bool is_blank = mykey_is_blank(data);
furi_string_cat_printf(parsed_data, "Serial#: %08lX\n", __bswap32(data->blocks[7])); furi_string_cat_printf(parsed_data, "Serial#: %08lX\n", (uint32_t)__bswap32(data->blocks[7]));
furi_string_cat_printf(parsed_data, "Blank: %s\n", is_blank ? "yes" : "no"); furi_string_cat_printf(parsed_data, "Blank: %s\n", is_blank ? "yes" : "no");
furi_string_cat_printf(parsed_data, "LockID: %s\n", mykey_has_lockid(data) ? "maybe" : "no"); furi_string_cat_printf(parsed_data, "LockID: %s\n", mykey_has_lockid(data) ? "maybe" : "no");
@ -66,7 +66,7 @@ static bool mykey_parse(const NfcDevice* device, FuriString* parsed_data) {
if(!is_blank) { if(!is_blank) {
furi_string_cat_printf( furi_string_cat_printf(
parsed_data, "\nOp. count: %ld\n", __bswap32(data->blocks[0x12] & 0xFFFFFF00)); parsed_data, "\nOp. count: %zu\n", (size_t)__bswap32(data->blocks[0x12] & 0xFFFFFF00));
uint32_t block3C = data->blocks[0x3C]; uint32_t block3C = data->blocks[0x3C];
if(block3C == 0xFFFFFFFF) { if(block3C == 0xFFFFFFFF) {
@ -75,7 +75,7 @@ static bool mykey_parse(const NfcDevice* device, FuriString* parsed_data) {
block3C ^= data->blocks[0x07]; block3C ^= data->blocks[0x07];
uint32_t startingOffset = ((block3C & 0x30000000) >> 28) | uint32_t startingOffset = ((block3C & 0x30000000) >> 28) |
((block3C & 0x00100000) >> 18); ((block3C & 0x00100000) >> 18);
furi_check(startingOffset < 8); furi_check(startingOffset < 8); //-V547
for(int txnOffset = 8; txnOffset > 0; txnOffset--) { for(int txnOffset = 8; txnOffset > 0; txnOffset--) {
uint32_t txnBlock = uint32_t txnBlock =
__bswap32(data->blocks[0x34 + ((startingOffset + txnOffset) % 8)]); __bswap32(data->blocks[0x34 + ((startingOffset + txnOffset) % 8)]);

View file

@ -42,7 +42,7 @@ uint64_t nfc_util_bytes2num_little_endian(const uint8_t* src, uint8_t len) {
uint64_t res = 0; uint64_t res = 0;
uint8_t shift = 0; uint8_t shift = 0;
while(len--) { while(len--) {
res |= *src << (8 * shift++); res |= ((uint64_t)*src) << (8 * shift++);
src++; src++;
} }
return res; return res;

View file

@ -40,10 +40,11 @@ static void mf_classic_listener_reset_state(MfClassicListener* instance) {
static MfClassicListenerCommand static MfClassicListenerCommand
mf_classic_listener_halt_handler(MfClassicListener* instance, BitBuffer* buff) { mf_classic_listener_halt_handler(MfClassicListener* instance, BitBuffer* buff) {
UNUSED(instance);
MfClassicListenerCommand command = MfClassicListenerCommandNack; MfClassicListenerCommand command = MfClassicListenerCommandNack;
if(bit_buffer_get_byte(buff, 1) == MF_CLASSIC_CMD_HALT_LSB) { if(bit_buffer_get_byte(buff, 1) == MF_CLASSIC_CMD_HALT_LSB) {
mf_classic_listener_reset_state(instance);
command = MfClassicListenerCommandSleep; command = MfClassicListenerCommandSleep;
} }
@ -59,10 +60,7 @@ static MfClassicListenerCommand mf_classic_listener_auth_first_part_handler(
do { do {
instance->state = MfClassicListenerStateIdle; instance->state = MfClassicListenerStateIdle;
if(block_num >= instance->total_block_num) { if(block_num >= instance->total_block_num) break;
mf_classic_listener_reset_state(instance);
break;
}
uint8_t sector_num = mf_classic_get_sector_by_block(block_num); uint8_t sector_num = mf_classic_get_sector_by_block(block_num);
@ -135,7 +133,7 @@ static MfClassicListenerCommand
instance->cmd_in_progress = false; instance->cmd_in_progress = false;
if(bit_buffer_get_size_bytes(buff) != (sizeof(MfClassicNr) + sizeof(MfClassicAr))) { if(bit_buffer_get_size_bytes(buff) != (sizeof(MfClassicNr) + sizeof(MfClassicAr))) {
mf_classic_listener_reset_state(instance); command = MfClassicListenerCommandSleep;
break; break;
} }
bit_buffer_write_bytes_mid(buff, instance->auth_context.nr.data, 0, sizeof(MfClassicNr)); bit_buffer_write_bytes_mid(buff, instance->auth_context.nr.data, 0, sizeof(MfClassicNr));
@ -157,7 +155,7 @@ static MfClassicListenerCommand
if(secret_poller != prng_successor(nt_num, 64)) { if(secret_poller != prng_successor(nt_num, 64)) {
FURI_LOG_T( FURI_LOG_T(
TAG, "Wrong reader key: %08lX != %08lX", secret_poller, prng_successor(nt_num, 64)); TAG, "Wrong reader key: %08lX != %08lX", secret_poller, prng_successor(nt_num, 64));
mf_classic_listener_reset_state(instance); command = MfClassicListenerCommandSleep;
break; break;
} }
@ -610,9 +608,11 @@ NfcCommand mf_classic_listener_run(NfcGenericEvent event, void* context) {
} }
mf_classic_listener_send_short_frame(instance, nack); mf_classic_listener_send_short_frame(instance, nack);
mf_classic_listener_reset_state(instance);
} else if(mfc_command == MfClassicListenerCommandSilent) { } else if(mfc_command == MfClassicListenerCommandSilent) {
command = NfcCommandReset; command = NfcCommandReset;
} else if(mfc_command == MfClassicListenerCommandSleep) { } else if(mfc_command == MfClassicListenerCommandSleep) {
mf_classic_listener_reset_state(instance);
command = NfcCommandSleep; command = NfcCommandSleep;
} }
} else if(iso3_event->type == Iso14443_3aListenerEventTypeHalted) { } else if(iso3_event->type == Iso14443_3aListenerEventTypeHalted) {