mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-29 04:09:58 -07:00
Format
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "mykey.h"
|
||||
|
||||
uint32_t encode_decode_block(uint32_t input) {
|
||||
/*
|
||||
/*
|
||||
* Swap all values using XOR
|
||||
* 32 bit: 1111222233334444
|
||||
*/
|
||||
@@ -14,13 +14,11 @@ uint32_t encode_decode_block(uint32_t input) {
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void endian_swap_uint8_array(uint8_t *array, size_t size) {
|
||||
void endian_swap_uint8_array(uint8_t* array, size_t size) {
|
||||
size_t i;
|
||||
uint8_t temp;
|
||||
|
||||
for (i = 0; i < size / 2; i++) {
|
||||
for(i = 0; i < size / 2; i++) {
|
||||
temp = array[i];
|
||||
array[i] = array[size - 1 - i];
|
||||
array[size - 1 - i] = temp;
|
||||
@@ -42,7 +40,7 @@ uint32_t get_block(uint32_t block) {
|
||||
return encode_decode_block(st25tb_get_block_value(block));
|
||||
}
|
||||
|
||||
//decode for credit
|
||||
//decode for credit
|
||||
uint32_t get_xored_block(uint32_t block, uint32_t key) {
|
||||
return encode_decode_block(st25tb_get_block_value(block) ^ key);
|
||||
}
|
||||
@@ -19,11 +19,13 @@ typedef enum {
|
||||
} LockIdStatus;
|
||||
|
||||
#define get_uid(uid) ((uid)[7] | ((uid)[6] << 8) | ((uid)[5] << 16) | ((uid)[4] << 24))
|
||||
#define new_get_count_down_counter(b6) (~(b6 << 24 | (b6 & 0x0000FF00) << 8 | (b6 & 0x00FF0000) >> 8 | b6 >> 24))
|
||||
#define new_get_count_down_counter(b6) \
|
||||
(~(b6 << 24 | (b6 & 0x0000FF00) << 8 | (b6 & 0x00FF0000) >> 8 | b6 >> 24))
|
||||
#define get_vendor(b1, b2) (get_block(b1) << 16 | (get_block(b2) & 0x0000FFFF))
|
||||
#define get_master_key(uid, vendor_id) ((uid) * ((vendor_id) + 1))
|
||||
#define get_is_bound(vendor_id) ((vendor_id) != MYKEY_DEFAULT_VENDOR_ID)
|
||||
#define get_encryption_key(master_key, count_down_counter)((master_key) * ((count_down_counter) + 1))
|
||||
#define get_encryption_key(master_key, count_down_counter) \
|
||||
((master_key) * ((count_down_counter) + 1))
|
||||
|
||||
uint32_t encode_decode_block(uint32_t input);
|
||||
uint32_t st25tb_get_block_value(uint32_t block);
|
||||
|
||||
@@ -12,15 +12,18 @@ void nfc_render_st25tb_info(
|
||||
}
|
||||
|
||||
uint32_t _uid = get_uid(data->uid);
|
||||
uint32_t _count_down_counter_new = new_get_count_down_counter(st25tb_get_block_value(data->blocks[6]));
|
||||
uint32_t _vendor_id = get_vendor(data->blocks[MYKEY_BLOCK_VENDOR_ID_1], data->blocks[MYKEY_BLOCK_VENDOR_ID_2]);
|
||||
uint32_t _count_down_counter_new =
|
||||
new_get_count_down_counter(st25tb_get_block_value(data->blocks[6]));
|
||||
uint32_t _vendor_id =
|
||||
get_vendor(data->blocks[MYKEY_BLOCK_VENDOR_ID_1], data->blocks[MYKEY_BLOCK_VENDOR_ID_2]);
|
||||
uint32_t _master_key = get_master_key(_uid, _vendor_id);
|
||||
uint32_t _encryption_key = get_encryption_key(_master_key, _count_down_counter_new);
|
||||
uint16_t credit = get_xored_block(data->blocks[MYKEY_BLOCK_CURRENT_CREDIT], _encryption_key);
|
||||
uint16_t _previous_credit = get_block(data->blocks[MYKEY_BLOCK_PREVIOUS_CREDIT]);
|
||||
bool _is_bound = get_is_bound(_vendor_id);
|
||||
furi_string_cat_printf(str, "\nCurrent Credit: %d.%02d E", credit / 100, credit % 100);
|
||||
furi_string_cat_printf(str, "\nPrevius Credit: %d.%02d E", _previous_credit / 100, _previous_credit % 100);
|
||||
furi_string_cat_printf(
|
||||
str, "\nPrevius Credit: %d.%02d E", _previous_credit / 100, _previous_credit % 100);
|
||||
furi_string_cat_printf(str, "\nIs Bound: %s \n", _is_bound ? "Yes" : "No");
|
||||
|
||||
if(format_type == NfcProtocolFormatTypeFull) {
|
||||
@@ -34,7 +37,11 @@ void nfc_render_st25tb_info(
|
||||
furi_string_cat_printf(str, "\nBlocks:");
|
||||
for(size_t i = 0; i < st25tb_get_block_count(data->type); i += 2) {
|
||||
furi_string_cat_printf(
|
||||
str, "\n %02X %08lX %08lX", i, st25tb_get_block_value(data->blocks[i]), st25tb_get_block_value(data->blocks[i + 1]));
|
||||
str,
|
||||
"\n %02X %08lX %08lX",
|
||||
i,
|
||||
st25tb_get_block_value(data->blocks[i]),
|
||||
st25tb_get_block_value(data->blocks[i + 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user