mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-17 04:34:44 -07:00
bit_lib and nfc_util refactor (#3383)
* nfc_util functions for processing bytes moved into bit_lib * bitlib test update * bit_lib moved from lfrfid to standalone lib * Added bit functions for any supported data types * Error fix and api add * Added test for 64 * Added doc * Testcase for 64 rewrited * Realization error fix * API version bump * sync api version, fix after-merge old libs usage * fix build errors * build fix * fbt format Co-authored-by: assasinfil <nfa57643@gmail.com> Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include <flipper_application/flipper_application.h>
|
||||
|
||||
#include <nfc/nfc_device.h>
|
||||
#include <nfc/helpers/nfc_util.h>
|
||||
#include <bit_lib/bit_lib.h>
|
||||
#include <nfc/protocols/mf_classic/mf_classic_poller_sync.h>
|
||||
|
||||
#define TAG "WashCity"
|
||||
@@ -63,7 +63,8 @@ static bool washcity_verify(Nfc* nfc) {
|
||||
FURI_LOG_D(TAG, "Verifying sector %u", ticket_sector_number);
|
||||
|
||||
MfClassicKey key = {0};
|
||||
nfc_util_num2bytes(washcity_1k_keys[ticket_sector_number].a, COUNT_OF(key.data), key.data);
|
||||
bit_lib_num_to_bytes_be(
|
||||
washcity_1k_keys[ticket_sector_number].a, COUNT_OF(key.data), key.data);
|
||||
|
||||
MfClassicAuthContext auth_context;
|
||||
MfClassicError error = mf_classic_poller_sync_auth(
|
||||
@@ -101,9 +102,11 @@ static bool washcity_read(Nfc* nfc, NfcDevice* device) {
|
||||
.key_b_mask = 0,
|
||||
};
|
||||
for(size_t i = 0; i < mf_classic_get_total_sectors_num(data->type); i++) {
|
||||
nfc_util_num2bytes(washcity_1k_keys[i].a, sizeof(MfClassicKey), keys.key_a[i].data);
|
||||
bit_lib_num_to_bytes_be(
|
||||
washcity_1k_keys[i].a, sizeof(MfClassicKey), keys.key_a[i].data);
|
||||
FURI_BIT_SET(keys.key_a_mask, i);
|
||||
nfc_util_num2bytes(washcity_1k_keys[i].b, sizeof(MfClassicKey), keys.key_b[i].data);
|
||||
bit_lib_num_to_bytes_be(
|
||||
washcity_1k_keys[i].b, sizeof(MfClassicKey), keys.key_b[i].data);
|
||||
FURI_BIT_SET(keys.key_b_mask, i);
|
||||
}
|
||||
|
||||
@@ -138,7 +141,8 @@ static bool washcity_parse(const NfcDevice* device, FuriString* parsed_data) {
|
||||
const MfClassicSectorTrailer* sec_tr =
|
||||
mf_classic_get_sector_trailer_by_sector(data, ticket_sector_number);
|
||||
|
||||
const uint64_t key = nfc_util_bytes2num(sec_tr->key_a.data, COUNT_OF(sec_tr->key_a.data));
|
||||
const uint64_t key =
|
||||
bit_lib_bytes_to_num_be(sec_tr->key_a.data, COUNT_OF(sec_tr->key_a.data));
|
||||
if(key != washcity_1k_keys[ticket_sector_number].a) break;
|
||||
|
||||
// Parse data
|
||||
@@ -148,7 +152,7 @@ static bool washcity_parse(const NfcDevice* device, FuriString* parsed_data) {
|
||||
const uint8_t* block_start_ptr =
|
||||
&data->block[start_block_num + ticket_block_number].data[0];
|
||||
|
||||
uint32_t balance = nfc_util_bytes2num(block_start_ptr + 2, 2);
|
||||
uint32_t balance = bit_lib_bytes_to_num_be(block_start_ptr + 2, 2);
|
||||
|
||||
uint32_t balance_eur = balance / 100;
|
||||
uint8_t balance_cents = balance % 100;
|
||||
@@ -157,7 +161,7 @@ static bool washcity_parse(const NfcDevice* device, FuriString* parsed_data) {
|
||||
const uint8_t* uid = mf_classic_get_uid(data, &uid_len);
|
||||
|
||||
// Card Number is printed in HEX (equal to UID)
|
||||
uint64_t card_number = nfc_util_bytes2num(uid, uid_len);
|
||||
uint64_t card_number = bit_lib_bytes_to_num_be(uid, uid_len);
|
||||
|
||||
furi_string_printf(
|
||||
parsed_data,
|
||||
|
||||
Reference in New Issue
Block a user