Skip to content

Commit

Permalink
Merge branch 'dev' into gornek/3719_nfc_plugins_rework
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes authored Dec 15, 2023
2 parents e459dad + 0954092 commit 0a6dc5a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
6 changes: 3 additions & 3 deletions applications/main/nfc/plugins/supported_cards/mykey.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static bool mykey_parse(const NfcDevice* device, FuriString* parsed_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, "LockID: %s\n", mykey_has_lockid(data) ? "maybe" : "no");

Expand All @@ -66,7 +66,7 @@ static bool mykey_parse(const NfcDevice* device, FuriString* parsed_data) {

if(!is_blank) {
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];
if(block3C == 0xFFFFFFFF) {
Expand All @@ -75,7 +75,7 @@ static bool mykey_parse(const NfcDevice* device, FuriString* parsed_data) {
block3C ^= data->blocks[0x07];
uint32_t startingOffset = ((block3C & 0x30000000) >> 28) |
((block3C & 0x00100000) >> 18);
furi_check(startingOffset < 8);
furi_check(startingOffset < 8); //-V547
for(int txnOffset = 8; txnOffset > 0; txnOffset--) {
uint32_t txnBlock =
__bswap32(data->blocks[0x34 + ((startingOffset + txnOffset) % 8)]);
Expand Down
13 changes: 13 additions & 0 deletions lib/nfc/helpers/nfc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ uint64_t nfc_util_bytes2num(const uint8_t* src, uint8_t len) {
return res;
}

uint64_t nfc_util_bytes2num_little_endian(const uint8_t* src, uint8_t len) {
furi_assert(src);
furi_assert(len <= 8);

uint64_t res = 0;
uint8_t shift = 0;
while(len--) {
res |= ((uint64_t)*src) << (8 * shift++);
src++;
}
return res;
}

uint8_t nfc_util_even_parity32(uint32_t data) {
// data ^= data >> 16;
// data ^= data >> 8;
Expand Down
2 changes: 2 additions & 0 deletions lib/nfc/helpers/nfc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void nfc_util_num2bytes(uint64_t src, uint8_t len, uint8_t* dest);

uint64_t nfc_util_bytes2num(const uint8_t* src, uint8_t len);

uint64_t nfc_util_bytes2num_little_endian(const uint8_t* src, uint8_t len);

uint8_t nfc_util_even_parity32(uint32_t data);

uint8_t nfc_util_odd_parity8(uint8_t data);
Expand Down
14 changes: 7 additions & 7 deletions lib/nfc/protocols/mf_classic/mf_classic_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ static void mf_classic_listener_reset_state(MfClassicListener* instance) {

static MfClassicListenerCommand
mf_classic_listener_halt_handler(MfClassicListener* instance, BitBuffer* buff) {
UNUSED(instance);

MfClassicListenerCommand command = MfClassicListenerCommandNack;

if(bit_buffer_get_byte(buff, 1) == MF_CLASSIC_CMD_HALT_LSB) {
mf_classic_listener_reset_state(instance);
command = MfClassicListenerCommandSleep;
}

Expand All @@ -59,10 +60,7 @@ static MfClassicListenerCommand mf_classic_listener_auth_first_part_handler(
do {
instance->state = MfClassicListenerStateIdle;

if(block_num >= instance->total_block_num) {
mf_classic_listener_reset_state(instance);
break;
}
if(block_num >= instance->total_block_num) break;

uint8_t sector_num = mf_classic_get_sector_by_block(block_num);

Expand Down Expand Up @@ -135,7 +133,7 @@ static MfClassicListenerCommand
instance->cmd_in_progress = false;

if(bit_buffer_get_size_bytes(buff) != (sizeof(MfClassicNr) + sizeof(MfClassicAr))) {
mf_classic_listener_reset_state(instance);
command = MfClassicListenerCommandSleep;
break;
}
bit_buffer_write_bytes_mid(buff, instance->auth_context.nr.data, 0, sizeof(MfClassicNr));
Expand All @@ -157,7 +155,7 @@ static MfClassicListenerCommand
if(secret_poller != prng_successor(nt_num, 64)) {
FURI_LOG_T(
TAG, "Wrong reader key: %08lX != %08lX", secret_poller, prng_successor(nt_num, 64));
mf_classic_listener_reset_state(instance);
command = MfClassicListenerCommandSleep;
break;
}

Expand Down Expand Up @@ -610,9 +608,11 @@ NfcCommand mf_classic_listener_run(NfcGenericEvent event, void* context) {
}

mf_classic_listener_send_short_frame(instance, nack);
mf_classic_listener_reset_state(instance);
} else if(mfc_command == MfClassicListenerCommandSilent) {
command = NfcCommandReset;
} else if(mfc_command == MfClassicListenerCommandSleep) {
mf_classic_listener_reset_state(instance);
command = NfcCommandSleep;
}
} else if(iso3_event->type == Iso14443_3aListenerEventTypeHalted) {
Expand Down
2 changes: 1 addition & 1 deletion targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,49.2,,
Version,+,49.3,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down
3 changes: 2 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,49.2,,
Version,+,49.3,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Expand Down Expand Up @@ -2488,6 +2488,7 @@ Function,+,nfc_set_mask_receive_time_fc,void,"Nfc*, uint32_t"
Function,+,nfc_start,void,"Nfc*, NfcEventCallback, void*"
Function,+,nfc_stop,void,Nfc*
Function,+,nfc_util_bytes2num,uint64_t,"const uint8_t*, uint8_t"
Function,+,nfc_util_bytes2num_little_endian,uint64_t,"const uint8_t*, uint8_t"
Function,+,nfc_util_even_parity32,uint8_t,uint32_t
Function,+,nfc_util_num2bytes,void,"uint64_t, uint8_t, uint8_t*"
Function,+,nfc_util_odd_parity,void,"const uint8_t*, uint8_t*, uint8_t"
Expand Down

0 comments on commit 0a6dc5a

Please sign in to comment.