mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
fix: run clang format
This commit is contained in:
+498
-339
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,8 @@
|
||||
#define APP_CMD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "dataframe.h"
|
||||
|
||||
#include "dataframe.h"
|
||||
|
||||
typedef data_frame_tx_t *(*cmd_processor)(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "device_info.h"
|
||||
|
||||
|
||||
// version code, 1byte, max = 0 -> 255
|
||||
//#define APP_FW_VER_MAJOR 2
|
||||
//#define APP_FW_VER_MINOR 0
|
||||
|
||||
+171
-110
File diff suppressed because it is too large
Load Diff
@@ -4,32 +4,36 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// 14a status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define STATUS_HF_TAG_OK (0x00) // IC card operation successful
|
||||
#define STATUS_HF_TAG_NO (0x01) // No IC card found
|
||||
#define STATUS_HF_ERR_STAT (0x02) // IC Card communication error
|
||||
#define STATUS_HF_ERR_CRC (0x03) // IC Card communication verification error
|
||||
#define STATUS_HF_COLLISION (0x04) // IC card conflict
|
||||
#define STATUS_HF_ERR_BCC (0x05) // IC card BCC error
|
||||
#define STATUS_MF_ERR_AUTH (0x06) // MF card verification failed
|
||||
#define STATUS_HF_ERR_PARITY (0x07) // IC card parity error
|
||||
#define STATUS_HF_ERR_ATS (0x08) // ATS should be present but card NAKed
|
||||
#define STATUS_HF_TAG_OK (0x00) // IC card operation successful
|
||||
#define STATUS_HF_TAG_NO (0x01) // No IC card found
|
||||
#define STATUS_HF_ERR_STAT (0x02) // IC Card communication error
|
||||
#define STATUS_HF_ERR_CRC (0x03) // IC Card communication verification error
|
||||
#define STATUS_HF_COLLISION (0x04) // IC card conflict
|
||||
#define STATUS_HF_ERR_BCC (0x05) // IC card BCC error
|
||||
#define STATUS_MF_ERR_AUTH (0x06) // MF card verification failed
|
||||
#define STATUS_HF_ERR_PARITY (0x07) // IC card parity error
|
||||
#define STATUS_HF_ERR_ATS (0x08) // ATS should be present but card NAKed
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// lf status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define STATUS_LF_TAG_OK (0x40) // Some of the low -frequency cards are successful!
|
||||
#define STATUS_LF_TAG_NO_FOUND (0x41) // Can't search for valid LF tags
|
||||
#define STATUS_LF_TAG_OK (0x40) // Some of the low -frequency cards are successful!
|
||||
#define STATUS_LF_TAG_NO_FOUND (0x41) // Can't search for valid LF tags
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// other status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define STATUS_PAR_ERR (0x60) // The parameter errors transferred by the BLE instruction, or call the parameter error transmitted by certain functions
|
||||
#define STATUS_DEVICE_MODE_ERROR (0x66) // The mode of the current device is wrong, and the corresponding API cannot be called
|
||||
#define STATUS_INVALID_CMD (0x67) // Invalid instruction
|
||||
#define STATUS_SUCCESS (0x68) // Device -related operations successfully executed
|
||||
#define STATUS_NOT_IMPLEMENTED (0x69) // Calling some unrealized operations, which belongs to the missed error of the developer
|
||||
#define STATUS_FLASH_WRITE_FAIL (0x70) // Flash writing failed
|
||||
#define STATUS_FLASH_READ_FAIL (0x71) // Flash read failed
|
||||
#define STATUS_INVALID_SLOT_TYPE (0x72) // Invalid slot type
|
||||
#define STATUS_PAR_ERR \
|
||||
(0x60) // The parameter errors transferred by the BLE instruction, or call the parameter error transmitted by
|
||||
// certain functions
|
||||
#define STATUS_DEVICE_MODE_ERROR \
|
||||
(0x66) // The mode of the current device is wrong, and the corresponding API cannot be called
|
||||
#define STATUS_INVALID_CMD (0x67) // Invalid instruction
|
||||
#define STATUS_SUCCESS (0x68) // Device -related operations successfully executed
|
||||
#define STATUS_NOT_IMPLEMENTED \
|
||||
(0x69) // Calling some unrealized operations, which belongs to the missed error of the developer
|
||||
#define STATUS_FLASH_WRITE_FAIL (0x70) // Flash writing failed
|
||||
#define STATUS_FLASH_READ_FAIL (0x71) // Flash read failed
|
||||
#define STATUS_INVALID_SLOT_TYPE (0x72) // Invalid slot type
|
||||
|
||||
#endif
|
||||
|
||||
+245
-211
File diff suppressed because it is too large
Load Diff
@@ -5,12 +5,8 @@
|
||||
|
||||
// Delay NMS
|
||||
// Pay attention to the range of NMS
|
||||
void bsp_delay_ms(uint16_t nms) {
|
||||
nrf_delay_us(nms * 1000);
|
||||
}
|
||||
void bsp_delay_ms(uint16_t nms) { nrf_delay_us(nms * 1000); }
|
||||
|
||||
// Delay NUS
|
||||
// NUS is the number of US numbers to be delayed.
|
||||
void bsp_delay_us(uint32_t nus) {
|
||||
nrf_delay_us(nus);
|
||||
}
|
||||
void bsp_delay_us(uint32_t nus) { nrf_delay_us(nus); }
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "bsp_time.h"
|
||||
|
||||
#include "app_timer.h"
|
||||
|
||||
|
||||
#define TICK_PERIOD APP_TIMER_TICKS(10) // Timing
|
||||
#define TICK_PERIOD APP_TIMER_TICKS(10) // Timing
|
||||
|
||||
// Define a soft timer
|
||||
APP_TIMER_DEF(m_app_timer);
|
||||
|
||||
// Timer pool
|
||||
autotimer bsptimers[TIMER_BSP_COUNT] = { 0 };
|
||||
autotimer bsptimers[TIMER_BSP_COUNT] = {0};
|
||||
// Timer iteration position
|
||||
static uint8_t g_timer_fori;
|
||||
// The current timer is running status
|
||||
@@ -17,15 +17,16 @@ static volatile enum {
|
||||
INIT,
|
||||
START,
|
||||
STOP,
|
||||
} bsp_timer_state = UNINIT;
|
||||
|
||||
} bsp_timer_state
|
||||
= UNINIT;
|
||||
|
||||
/*
|
||||
* Get a free timer, this timer
|
||||
* 1. Will run automatically
|
||||
* 2. It's free
|
||||
*/
|
||||
autotimer *bsp_obtain_timer(uint32_t start_value) {
|
||||
* Get a free timer, this timer
|
||||
* 1. Will run automatically
|
||||
* 2. It's free
|
||||
*/
|
||||
autotimer *bsp_obtain_timer(uint32_t start_value)
|
||||
{
|
||||
uint8_t i;
|
||||
for (i = 0; i < TIMER_BSP_COUNT; i++) {
|
||||
if (bsptimers[i].busy == 0) {
|
||||
@@ -38,19 +39,21 @@ autotimer *bsp_obtain_timer(uint32_t start_value) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the timer, the operation will operate the target timer and modify the current value
|
||||
*/
|
||||
inline uint8_t bsp_set_timer(autotimer *timer, uint32_t start_value) {
|
||||
* Set the timer, the operation will operate the target timer and modify the current value
|
||||
*/
|
||||
inline uint8_t bsp_set_timer(autotimer *timer, uint32_t start_value)
|
||||
{
|
||||
if (timer->busy == 0) return 0;
|
||||
timer->time = start_value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the timer, the operation will automatically release the timer
|
||||
* And zero to the timer
|
||||
*/
|
||||
inline void bsp_return_timer(autotimer *timer) {
|
||||
* Return the timer, the operation will automatically release the timer
|
||||
* And zero to the timer
|
||||
*/
|
||||
inline void bsp_return_timer(autotimer *timer)
|
||||
{
|
||||
timer->busy = 0;
|
||||
timer->time = 0;
|
||||
}
|
||||
@@ -59,7 +62,8 @@ inline void bsp_return_timer(autotimer *timer) {
|
||||
* @param arg Callback parameter
|
||||
* @return none
|
||||
*/
|
||||
void timer_app_callback(void *arg) {
|
||||
void timer_app_callback(void *arg)
|
||||
{
|
||||
UNUSED_PARAMETER(arg);
|
||||
for (g_timer_fori = 0; g_timer_fori < TIMER_BSP_COUNT; g_timer_fori++) {
|
||||
if (bsptimers[g_timer_fori].busy == 1) {
|
||||
@@ -69,7 +73,8 @@ void timer_app_callback(void *arg) {
|
||||
}
|
||||
|
||||
// Initialized timer
|
||||
void bsp_timer_init(void) {
|
||||
void bsp_timer_init(void)
|
||||
{
|
||||
if (bsp_timer_state == UNINIT) {
|
||||
bsp_timer_state = INIT;
|
||||
// Create a timer
|
||||
@@ -79,13 +84,15 @@ void bsp_timer_init(void) {
|
||||
}
|
||||
|
||||
// Counter -initialization timer
|
||||
void bsp_timer_uninit(void) {
|
||||
void bsp_timer_uninit(void)
|
||||
{
|
||||
// Can't reverse the initialized soft timer for the time being, it can only be closed
|
||||
bsp_timer_stop();
|
||||
}
|
||||
|
||||
// Start the timer
|
||||
void bsp_timer_start(void) {
|
||||
void bsp_timer_start(void)
|
||||
{
|
||||
if (bsp_timer_state != UNINIT) {
|
||||
// Make sure the timer is not started
|
||||
if (bsp_timer_state != START) {
|
||||
@@ -93,11 +100,11 @@ void bsp_timer_start(void) {
|
||||
bsp_timer_state = START;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Stop timer
|
||||
void bsp_timer_stop(void) {
|
||||
void bsp_timer_stop(void)
|
||||
{
|
||||
if (bsp_timer_state != UNINIT) {
|
||||
if (bsp_timer_state == START) {
|
||||
// Stop timer
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
//Define the maximum number of timer that can be used at the same time
|
||||
// Define the maximum number of timer that can be used at the same time
|
||||
#define TIMER_BSP_COUNT 10
|
||||
|
||||
// Define a structure
|
||||
@@ -18,9 +18,8 @@ typedef struct {
|
||||
uint8_t busy;
|
||||
} autotimer;
|
||||
|
||||
|
||||
// Realize a grand definition of judgment timeout
|
||||
#define NO_TIMEOUT_1MS(timer, count) ((((autotimer*)timer)->time <= (count))? 1: 0)
|
||||
#define NO_TIMEOUT_1MS(timer, count) ((((autotimer *)timer)->time <= (count)) ? 1 : 0)
|
||||
|
||||
void bsp_timer_init(void);
|
||||
void bsp_timer_uninit(void);
|
||||
@@ -31,5 +30,4 @@ void bsp_return_timer(autotimer *timer);
|
||||
autotimer *bsp_obtain_timer(uint32_t start_value);
|
||||
uint8_t bsp_set_timer(autotimer *timer, uint32_t start_value);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
#include "nrf_drv_wdt.h"
|
||||
#include "hw_connect.h"
|
||||
#include "nrf_drv_wdt.h"
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
static nrf_drv_wdt_channel_id m_channel_id;
|
||||
|
||||
static void wdt_event_handler(void) {
|
||||
//NOTE: The max amount of time we can spend in WDT interrupt is two cycles of 32768[Hz] clock - after that, reset occurs
|
||||
static void wdt_event_handler(void)
|
||||
{
|
||||
// NOTE: The max amount of time we can spend in WDT interrupt is two cycles of 32768[Hz] clock - after that, reset
|
||||
// occurs
|
||||
uint32_t *p_led_array = hw_get_led_array();
|
||||
for (uint8_t i = 0; i < RGB_LIST_NUM; i++) {
|
||||
nrf_gpio_pin_clear(p_led_array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void bsp_wdt_init(void) {
|
||||
void bsp_wdt_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
// err_code = nrf_drv_clock_init(); // already done by usb_cdc_init() -> app_usbd_init()
|
||||
// APP_ERROR_CHECK(err_code);
|
||||
nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG; // typo is in the SDK...
|
||||
// err_code = nrf_drv_clock_init(); // already done by usb_cdc_init() -> app_usbd_init()
|
||||
// APP_ERROR_CHECK(err_code);
|
||||
nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG; // typo is in the SDK...
|
||||
err_code = nrf_drv_wdt_init(&config, wdt_event_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
err_code = nrf_drv_wdt_channel_alloc(&m_channel_id);
|
||||
@@ -24,6 +27,4 @@ void bsp_wdt_init(void) {
|
||||
nrf_drv_wdt_enable();
|
||||
}
|
||||
|
||||
void bsp_wdt_feed(void) {
|
||||
nrf_drv_wdt_channel_feed(m_channel_id);
|
||||
}
|
||||
void bsp_wdt_feed(void) { nrf_drv_wdt_channel_feed(m_channel_id); }
|
||||
|
||||
@@ -12,4 +12,4 @@ void bsp_wdt_feed(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __BSP_WDT_H__
|
||||
#endif // __BSP_WDT_H__
|
||||
|
||||
+104
-109
@@ -1,145 +1,140 @@
|
||||
#ifndef DATA_CMD_H
|
||||
#define DATA_CMD_H
|
||||
|
||||
|
||||
// ******************************************************************
|
||||
// CMD for device
|
||||
// Range from 1000 -> 1999
|
||||
// ******************************************************************
|
||||
//
|
||||
#define DATA_CMD_GET_APP_VERSION (1000)
|
||||
#define DATA_CMD_CHANGE_DEVICE_MODE (1001)
|
||||
#define DATA_CMD_GET_DEVICE_MODE (1002)
|
||||
#define DATA_CMD_SET_ACTIVE_SLOT (1003)
|
||||
#define DATA_CMD_SET_SLOT_TAG_TYPE (1004)
|
||||
#define DATA_CMD_SET_SLOT_DATA_DEFAULT (1005)
|
||||
#define DATA_CMD_SET_SLOT_ENABLE (1006)
|
||||
#define DATA_CMD_SET_SLOT_TAG_NICK (1007)
|
||||
#define DATA_CMD_GET_SLOT_TAG_NICK (1008)
|
||||
#define DATA_CMD_SLOT_DATA_CONFIG_SAVE (1009)
|
||||
#define DATA_CMD_ENTER_BOOTLOADER (1010)
|
||||
#define DATA_CMD_GET_DEVICE_CHIP_ID (1011)
|
||||
#define DATA_CMD_GET_DEVICE_ADDRESS (1012)
|
||||
#define DATA_CMD_SAVE_SETTINGS (1013)
|
||||
#define DATA_CMD_RESET_SETTINGS (1014)
|
||||
#define DATA_CMD_SET_ANIMATION_MODE (1015)
|
||||
#define DATA_CMD_GET_ANIMATION_MODE (1016)
|
||||
#define DATA_CMD_GET_GIT_VERSION (1017)
|
||||
#define DATA_CMD_GET_ACTIVE_SLOT (1018)
|
||||
#define DATA_CMD_GET_SLOT_INFO (1019)
|
||||
#define DATA_CMD_WIPE_FDS (1020)
|
||||
#define DATA_CMD_DELETE_SLOT_TAG_NICK (1021)
|
||||
#define DATA_CMD_GET_APP_VERSION (1000)
|
||||
#define DATA_CMD_CHANGE_DEVICE_MODE (1001)
|
||||
#define DATA_CMD_GET_DEVICE_MODE (1002)
|
||||
#define DATA_CMD_SET_ACTIVE_SLOT (1003)
|
||||
#define DATA_CMD_SET_SLOT_TAG_TYPE (1004)
|
||||
#define DATA_CMD_SET_SLOT_DATA_DEFAULT (1005)
|
||||
#define DATA_CMD_SET_SLOT_ENABLE (1006)
|
||||
#define DATA_CMD_SET_SLOT_TAG_NICK (1007)
|
||||
#define DATA_CMD_GET_SLOT_TAG_NICK (1008)
|
||||
#define DATA_CMD_SLOT_DATA_CONFIG_SAVE (1009)
|
||||
#define DATA_CMD_ENTER_BOOTLOADER (1010)
|
||||
#define DATA_CMD_GET_DEVICE_CHIP_ID (1011)
|
||||
#define DATA_CMD_GET_DEVICE_ADDRESS (1012)
|
||||
#define DATA_CMD_SAVE_SETTINGS (1013)
|
||||
#define DATA_CMD_RESET_SETTINGS (1014)
|
||||
#define DATA_CMD_SET_ANIMATION_MODE (1015)
|
||||
#define DATA_CMD_GET_ANIMATION_MODE (1016)
|
||||
#define DATA_CMD_GET_GIT_VERSION (1017)
|
||||
#define DATA_CMD_GET_ACTIVE_SLOT (1018)
|
||||
#define DATA_CMD_GET_SLOT_INFO (1019)
|
||||
#define DATA_CMD_WIPE_FDS (1020)
|
||||
#define DATA_CMD_DELETE_SLOT_TAG_NICK (1021)
|
||||
|
||||
#define DATA_CMD_GET_ENABLED_SLOTS (1023)
|
||||
#define DATA_CMD_DELETE_SLOT_SENSE_TYPE (1024)
|
||||
#define DATA_CMD_GET_BATTERY_INFO (1025)
|
||||
#define DATA_CMD_GET_BUTTON_PRESS_CONFIG (1026)
|
||||
#define DATA_CMD_SET_BUTTON_PRESS_CONFIG (1027)
|
||||
#define DATA_CMD_GET_LONG_BUTTON_PRESS_CONFIG (1028)
|
||||
#define DATA_CMD_SET_LONG_BUTTON_PRESS_CONFIG (1029)
|
||||
#define DATA_CMD_SET_BLE_PAIRING_KEY (1030)
|
||||
#define DATA_CMD_GET_BLE_PAIRING_KEY (1031)
|
||||
#define DATA_CMD_DELETE_ALL_BLE_BONDS (1032)
|
||||
#define DATA_CMD_GET_DEVICE_MODEL (1033)
|
||||
#define DATA_CMD_GET_DEVICE_SETTINGS (1034)
|
||||
#define DATA_CMD_GET_DEVICE_CAPABILITIES (1035)
|
||||
#define DATA_CMD_GET_BLE_PAIRING_ENABLE (1036)
|
||||
#define DATA_CMD_SET_BLE_PAIRING_ENABLE (1037)
|
||||
#define DATA_CMD_GET_ALL_SLOT_NICKS (1038)
|
||||
#define DATA_CMD_GET_ENABLED_SLOTS (1023)
|
||||
#define DATA_CMD_DELETE_SLOT_SENSE_TYPE (1024)
|
||||
#define DATA_CMD_GET_BATTERY_INFO (1025)
|
||||
#define DATA_CMD_GET_BUTTON_PRESS_CONFIG (1026)
|
||||
#define DATA_CMD_SET_BUTTON_PRESS_CONFIG (1027)
|
||||
#define DATA_CMD_GET_LONG_BUTTON_PRESS_CONFIG (1028)
|
||||
#define DATA_CMD_SET_LONG_BUTTON_PRESS_CONFIG (1029)
|
||||
#define DATA_CMD_SET_BLE_PAIRING_KEY (1030)
|
||||
#define DATA_CMD_GET_BLE_PAIRING_KEY (1031)
|
||||
#define DATA_CMD_DELETE_ALL_BLE_BONDS (1032)
|
||||
#define DATA_CMD_GET_DEVICE_MODEL (1033)
|
||||
#define DATA_CMD_GET_DEVICE_SETTINGS (1034)
|
||||
#define DATA_CMD_GET_DEVICE_CAPABILITIES (1035)
|
||||
#define DATA_CMD_GET_BLE_PAIRING_ENABLE (1036)
|
||||
#define DATA_CMD_SET_BLE_PAIRING_ENABLE (1037)
|
||||
#define DATA_CMD_GET_ALL_SLOT_NICKS (1038)
|
||||
|
||||
//
|
||||
// ******************************************************************
|
||||
|
||||
|
||||
// ******************************************************************
|
||||
// CMD for hf reader
|
||||
// Range from 2000 -> 2999
|
||||
// ******************************************************************
|
||||
//
|
||||
#define DATA_CMD_HF14A_SCAN (2000)
|
||||
#define DATA_CMD_MF1_DETECT_SUPPORT (2001)
|
||||
#define DATA_CMD_MF1_DETECT_PRNG (2002)
|
||||
#define DATA_CMD_MF1_STATIC_NESTED_ACQUIRE (2003)
|
||||
#define DATA_CMD_MF1_DARKSIDE_ACQUIRE (2004)
|
||||
#define DATA_CMD_MF1_DETECT_NT_DIST (2005)
|
||||
#define DATA_CMD_MF1_NESTED_ACQUIRE (2006)
|
||||
#define DATA_CMD_MF1_AUTH_ONE_KEY_BLOCK (2007)
|
||||
#define DATA_CMD_MF1_READ_ONE_BLOCK (2008)
|
||||
#define DATA_CMD_MF1_WRITE_ONE_BLOCK (2009)
|
||||
#define DATA_CMD_HF14A_RAW (2010)
|
||||
#define DATA_CMD_MF1_MANIPULATE_VALUE_BLOCK (2011)
|
||||
#define DATA_CMD_MF1_CHECK_KEYS_OF_SECTORS (2012)
|
||||
#define DATA_CMD_MF1_HARDNESTED_ACQUIRE (2013)
|
||||
#define DATA_CMD_MF1_ENC_NESTED_ACQUIRE (2014)
|
||||
#define DATA_CMD_MF1_CHECK_KEYS_ON_BLOCK (2015)
|
||||
#define DATA_CMD_HF14A_SCAN (2000)
|
||||
#define DATA_CMD_MF1_DETECT_SUPPORT (2001)
|
||||
#define DATA_CMD_MF1_DETECT_PRNG (2002)
|
||||
#define DATA_CMD_MF1_STATIC_NESTED_ACQUIRE (2003)
|
||||
#define DATA_CMD_MF1_DARKSIDE_ACQUIRE (2004)
|
||||
#define DATA_CMD_MF1_DETECT_NT_DIST (2005)
|
||||
#define DATA_CMD_MF1_NESTED_ACQUIRE (2006)
|
||||
#define DATA_CMD_MF1_AUTH_ONE_KEY_BLOCK (2007)
|
||||
#define DATA_CMD_MF1_READ_ONE_BLOCK (2008)
|
||||
#define DATA_CMD_MF1_WRITE_ONE_BLOCK (2009)
|
||||
#define DATA_CMD_HF14A_RAW (2010)
|
||||
#define DATA_CMD_MF1_MANIPULATE_VALUE_BLOCK (2011)
|
||||
#define DATA_CMD_MF1_CHECK_KEYS_OF_SECTORS (2012)
|
||||
#define DATA_CMD_MF1_HARDNESTED_ACQUIRE (2013)
|
||||
#define DATA_CMD_MF1_ENC_NESTED_ACQUIRE (2014)
|
||||
#define DATA_CMD_MF1_CHECK_KEYS_ON_BLOCK (2015)
|
||||
|
||||
//
|
||||
// ******************************************************************
|
||||
|
||||
|
||||
// ******************************************************************
|
||||
// CMD for lf reader
|
||||
// Range from 3000 -> 3999
|
||||
// ******************************************************************
|
||||
//
|
||||
#define DATA_CMD_EM410X_SCAN (3000)
|
||||
#define DATA_CMD_EM410X_WRITE_TO_T55XX (3001)
|
||||
#define DATA_CMD_HIDPROX_SCAN (3002)
|
||||
#define DATA_CMD_HIDPROX_WRITE_TO_T55XX (3003)
|
||||
#define DATA_CMD_VIKING_SCAN (3004)
|
||||
#define DATA_CMD_VIKING_WRITE_TO_T55XX (3005)
|
||||
#define DATA_CMD_EM410X_SCAN (3000)
|
||||
#define DATA_CMD_EM410X_WRITE_TO_T55XX (3001)
|
||||
#define DATA_CMD_HIDPROX_SCAN (3002)
|
||||
#define DATA_CMD_HIDPROX_WRITE_TO_T55XX (3003)
|
||||
#define DATA_CMD_VIKING_SCAN (3004)
|
||||
#define DATA_CMD_VIKING_WRITE_TO_T55XX (3005)
|
||||
|
||||
//
|
||||
// ******************************************************************
|
||||
|
||||
|
||||
// ******************************************************************
|
||||
// CMD for hf emulator
|
||||
// Range from 4000 -> 4999
|
||||
// ******************************************************************
|
||||
//
|
||||
#define DATA_CMD_MF1_WRITE_EMU_BLOCK_DATA (4000)
|
||||
#define DATA_CMD_HF14A_SET_ANTI_COLL_DATA (4001)
|
||||
#define DATA_CMD_MF1_SET_DETECTION_ENABLE (4004)
|
||||
#define DATA_CMD_MF1_GET_DETECTION_COUNT (4005)
|
||||
#define DATA_CMD_MF1_GET_DETECTION_LOG (4006)
|
||||
#define DATA_CMD_MF1_GET_DETECTION_ENABLE (4007)
|
||||
#define DATA_CMD_MF1_READ_EMU_BLOCK_DATA (4008)
|
||||
#define DATA_CMD_MF1_GET_EMULATOR_CONFIG (4009)
|
||||
#define DATA_CMD_MF1_GET_GEN1A_MODE (4010)
|
||||
#define DATA_CMD_MF1_SET_GEN1A_MODE (4011)
|
||||
#define DATA_CMD_MF1_GET_GEN2_MODE (4012)
|
||||
#define DATA_CMD_MF1_SET_GEN2_MODE (4013)
|
||||
#define DATA_CMD_MF1_GET_BLOCK_ANTI_COLL_MODE (4014)
|
||||
#define DATA_CMD_MF1_SET_BLOCK_ANTI_COLL_MODE (4015)
|
||||
#define DATA_CMD_MF1_GET_WRITE_MODE (4016)
|
||||
#define DATA_CMD_MF1_SET_WRITE_MODE (4017)
|
||||
#define DATA_CMD_HF14A_GET_ANTI_COLL_DATA (4018)
|
||||
#define DATA_CMD_MF0_NTAG_GET_UID_MAGIC_MODE (4019)
|
||||
#define DATA_CMD_MF0_NTAG_SET_UID_MAGIC_MODE (4020)
|
||||
#define DATA_CMD_MF0_NTAG_READ_EMU_PAGE_DATA (4021)
|
||||
#define DATA_CMD_MF0_NTAG_WRITE_EMU_PAGE_DATA (4022)
|
||||
#define DATA_CMD_MF0_NTAG_GET_VERSION_DATA (4023)
|
||||
#define DATA_CMD_MF0_NTAG_SET_VERSION_DATA (4024)
|
||||
#define DATA_CMD_MF0_NTAG_GET_SIGNATURE_DATA (4025)
|
||||
#define DATA_CMD_MF0_NTAG_SET_SIGNATURE_DATA (4026)
|
||||
#define DATA_CMD_MF0_NTAG_GET_COUNTER_DATA (4027)
|
||||
#define DATA_CMD_MF0_NTAG_SET_COUNTER_DATA (4028)
|
||||
#define DATA_CMD_MF0_NTAG_RESET_AUTH_CNT (4029)
|
||||
#define DATA_CMD_MF0_NTAG_GET_PAGE_COUNT (4030)
|
||||
#define DATA_CMD_MF0_NTAG_RESET_AUTH_CNT (4029)
|
||||
#define DATA_CMD_MF0_NTAG_GET_PAGE_COUNT (4030)
|
||||
#define DATA_CMD_MF0_NTAG_GET_WRITE_MODE (4031)
|
||||
#define DATA_CMD_MF0_NTAG_SET_WRITE_MODE (4032)
|
||||
#define DATA_CMD_MF0_NTAG_SET_DETECTION_ENABLE (4033)
|
||||
#define DATA_CMD_MF0_NTAG_GET_DETECTION_COUNT (4034)
|
||||
#define DATA_CMD_MF0_NTAG_GET_DETECTION_LOG (4035)
|
||||
#define DATA_CMD_MF0_NTAG_GET_DETECTION_ENABLE (4036)
|
||||
#define DATA_CMD_MF0_NTAG_GET_EMULATOR_CONFIG (4037)
|
||||
#define DATA_CMD_MF1_WRITE_EMU_BLOCK_DATA (4000)
|
||||
#define DATA_CMD_HF14A_SET_ANTI_COLL_DATA (4001)
|
||||
#define DATA_CMD_MF1_SET_DETECTION_ENABLE (4004)
|
||||
#define DATA_CMD_MF1_GET_DETECTION_COUNT (4005)
|
||||
#define DATA_CMD_MF1_GET_DETECTION_LOG (4006)
|
||||
#define DATA_CMD_MF1_GET_DETECTION_ENABLE (4007)
|
||||
#define DATA_CMD_MF1_READ_EMU_BLOCK_DATA (4008)
|
||||
#define DATA_CMD_MF1_GET_EMULATOR_CONFIG (4009)
|
||||
#define DATA_CMD_MF1_GET_GEN1A_MODE (4010)
|
||||
#define DATA_CMD_MF1_SET_GEN1A_MODE (4011)
|
||||
#define DATA_CMD_MF1_GET_GEN2_MODE (4012)
|
||||
#define DATA_CMD_MF1_SET_GEN2_MODE (4013)
|
||||
#define DATA_CMD_MF1_GET_BLOCK_ANTI_COLL_MODE (4014)
|
||||
#define DATA_CMD_MF1_SET_BLOCK_ANTI_COLL_MODE (4015)
|
||||
#define DATA_CMD_MF1_GET_WRITE_MODE (4016)
|
||||
#define DATA_CMD_MF1_SET_WRITE_MODE (4017)
|
||||
#define DATA_CMD_HF14A_GET_ANTI_COLL_DATA (4018)
|
||||
#define DATA_CMD_MF0_NTAG_GET_UID_MAGIC_MODE (4019)
|
||||
#define DATA_CMD_MF0_NTAG_SET_UID_MAGIC_MODE (4020)
|
||||
#define DATA_CMD_MF0_NTAG_READ_EMU_PAGE_DATA (4021)
|
||||
#define DATA_CMD_MF0_NTAG_WRITE_EMU_PAGE_DATA (4022)
|
||||
#define DATA_CMD_MF0_NTAG_GET_VERSION_DATA (4023)
|
||||
#define DATA_CMD_MF0_NTAG_SET_VERSION_DATA (4024)
|
||||
#define DATA_CMD_MF0_NTAG_GET_SIGNATURE_DATA (4025)
|
||||
#define DATA_CMD_MF0_NTAG_SET_SIGNATURE_DATA (4026)
|
||||
#define DATA_CMD_MF0_NTAG_GET_COUNTER_DATA (4027)
|
||||
#define DATA_CMD_MF0_NTAG_SET_COUNTER_DATA (4028)
|
||||
#define DATA_CMD_MF0_NTAG_RESET_AUTH_CNT (4029)
|
||||
#define DATA_CMD_MF0_NTAG_GET_PAGE_COUNT (4030)
|
||||
#define DATA_CMD_MF0_NTAG_RESET_AUTH_CNT (4029)
|
||||
#define DATA_CMD_MF0_NTAG_GET_PAGE_COUNT (4030)
|
||||
#define DATA_CMD_MF0_NTAG_GET_WRITE_MODE (4031)
|
||||
#define DATA_CMD_MF0_NTAG_SET_WRITE_MODE (4032)
|
||||
#define DATA_CMD_MF0_NTAG_SET_DETECTION_ENABLE (4033)
|
||||
#define DATA_CMD_MF0_NTAG_GET_DETECTION_COUNT (4034)
|
||||
#define DATA_CMD_MF0_NTAG_GET_DETECTION_LOG (4035)
|
||||
#define DATA_CMD_MF0_NTAG_GET_DETECTION_ENABLE (4036)
|
||||
#define DATA_CMD_MF0_NTAG_GET_EMULATOR_CONFIG (4037)
|
||||
//
|
||||
// ******************************************************************
|
||||
|
||||
|
||||
// ******************************************************************
|
||||
// CMD for lf emulator
|
||||
// Range from 5000 -> 5999
|
||||
@@ -148,11 +143,11 @@
|
||||
|
||||
//
|
||||
// ******************************************************************
|
||||
#define DATA_CMD_EM410X_SET_EMU_ID (5000)
|
||||
#define DATA_CMD_EM410X_GET_EMU_ID (5001)
|
||||
#define DATA_CMD_HIDPROX_SET_EMU_ID (5002)
|
||||
#define DATA_CMD_HIDPROX_GET_EMU_ID (5003)
|
||||
#define DATA_CMD_VIKING_SET_EMU_ID (5004)
|
||||
#define DATA_CMD_VIKING_GET_EMU_ID (5005)
|
||||
#define DATA_CMD_EM410X_SET_EMU_ID (5000)
|
||||
#define DATA_CMD_EM410X_GET_EMU_ID (5001)
|
||||
#define DATA_CMD_HIDPROX_SET_EMU_ID (5002)
|
||||
#define DATA_CMD_HIDPROX_GET_EMU_ID (5003)
|
||||
#define DATA_CMD_VIKING_SET_EMU_ID (5004)
|
||||
#define DATA_CMD_VIKING_GET_EMU_ID (5005)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,36 +2,18 @@
|
||||
|
||||
// Byte mirror
|
||||
const uint8_t byte_mirror[256] = {
|
||||
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
||||
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
||||
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
||||
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
||||
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
||||
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
||||
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
||||
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
||||
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
||||
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
||||
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
||||
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
||||
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
||||
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
||||
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
||||
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
||||
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
||||
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
||||
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
||||
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
||||
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
||||
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
||||
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
||||
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
||||
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
||||
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
||||
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
||||
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
||||
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
||||
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
||||
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
||||
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
|
||||
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48,
|
||||
0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4,
|
||||
0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c,
|
||||
0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2,
|
||||
0x32, 0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a,
|
||||
0xfa, 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e,
|
||||
0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1, 0x21,
|
||||
0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
||||
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55,
|
||||
0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd,
|
||||
0x7d, 0xfd, 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 0x0b,
|
||||
0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7,
|
||||
0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f,
|
||||
0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
|
||||
};
|
||||
@@ -1,42 +1,28 @@
|
||||
#include "crc_utils.h"
|
||||
|
||||
//CRC check table
|
||||
// CRC check table
|
||||
static uint16_t crc_table[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
|
||||
0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
|
||||
0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E,
|
||||
0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
|
||||
0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD,
|
||||
0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
|
||||
0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C,
|
||||
0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
|
||||
0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB,
|
||||
0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
|
||||
0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A,
|
||||
0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
|
||||
0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9,
|
||||
0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
|
||||
0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738,
|
||||
0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
|
||||
0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7,
|
||||
0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
|
||||
0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036,
|
||||
0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
|
||||
0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
|
||||
0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
|
||||
0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134,
|
||||
0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
|
||||
0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3,
|
||||
0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
|
||||
0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232,
|
||||
0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
|
||||
0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1,
|
||||
0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
|
||||
0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330,
|
||||
0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78,
|
||||
0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5,
|
||||
0xE97E, 0xF8F7, 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 0xAE52,
|
||||
0xDAED, 0xCB64, 0xF9FF, 0xE876, 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3,
|
||||
0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5, 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C,
|
||||
0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974, 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9,
|
||||
0x2732, 0x36BB, 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3, 0x5285, 0x430C, 0x7197, 0x601E,
|
||||
0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72, 0x6306, 0x728F,
|
||||
0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
|
||||
0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862,
|
||||
0x9AF9, 0x8B70, 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB,
|
||||
0x4E64, 0x5FED, 0x6D76, 0x7CFF, 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 0x0948,
|
||||
0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
|
||||
0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD, 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226,
|
||||
0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C, 0xC60C, 0xD785, 0xE51E, 0xF497,
|
||||
0x8028, 0x91A1, 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, 0xD68D, 0xC704,
|
||||
0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
|
||||
0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB,
|
||||
0x0E70, 0x1FF9, 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C,
|
||||
0x3DE3, 0x2C6A, 0x1EF1, 0x0F78,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Use the table check method on the MCU to calculate the CRC (CRC16) dedicated to the 144443A protocol.
|
||||
* @param data The original data of the calculated CRC
|
||||
@@ -44,11 +30,12 @@ static uint16_t crc_table[256] = {
|
||||
* @param output The output buffer must be greater than or equal to two bytes
|
||||
*
|
||||
*/
|
||||
void calc_14a_crc_lut(uint8_t *data, int length, uint8_t *output) {
|
||||
//Take the clever, compulsory pointer type conversion
|
||||
void calc_14a_crc_lut(uint8_t *data, int length, uint8_t *output)
|
||||
{
|
||||
// Take the clever, compulsory pointer type conversion
|
||||
uint16_t *crc = (uint16_t *)output;
|
||||
//Give the initial value of polynomial
|
||||
// Give the initial value of polynomial
|
||||
*crc = 0x6363;
|
||||
//Then start checking the table of each byte
|
||||
// Then start checking the table of each byte
|
||||
while (length--) *crc = (*crc >> 8) ^ crc_table[(*crc & 0xFF) ^ *data++];
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
* @retval none
|
||||
*
|
||||
*/
|
||||
void num_to_bytes(uint64_t n, uint8_t len, uint8_t *dest) {
|
||||
void num_to_bytes(uint64_t n, uint8_t len, uint8_t *dest)
|
||||
{
|
||||
while (len--) {
|
||||
dest[len] = (uint8_t)n;
|
||||
n >>= 8;
|
||||
@@ -22,7 +23,8 @@ void num_to_bytes(uint64_t n, uint8_t len, uint8_t *dest) {
|
||||
* @retval Converting result
|
||||
*
|
||||
*/
|
||||
uint64_t bytes_to_num(uint8_t *src, uint8_t len) {
|
||||
uint64_t bytes_to_num(uint8_t *src, uint8_t len)
|
||||
{
|
||||
uint64_t num = 0;
|
||||
while (len--) {
|
||||
num = (num << 8) | (*src);
|
||||
|
||||
@@ -13,67 +13,72 @@
|
||||
MA 02110-1301, US
|
||||
Copyright (C) 2008-2008 bla <blapost@gmail.com>
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include "mf1_crapto1.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "parity.h"
|
||||
|
||||
#ifdef __OPTIMIZE_SIZE__
|
||||
uint32_t filter(uint32_t const x) {
|
||||
uint32_t filter(uint32_t const x)
|
||||
{
|
||||
uint32_t f;
|
||||
|
||||
f = 0xf22c0 >> (x & 0xf) & 16;
|
||||
f |= 0x6c9c0 >> (x >> 4 & 0xf) & 8;
|
||||
f |= 0x3c8b0 >> (x >> 8 & 0xf) & 4;
|
||||
f |= 0x1e458 >> (x >> 12 & 0xf) & 2;
|
||||
f |= 0x0d938 >> (x >> 16 & 0xf) & 1;
|
||||
f = 0xf22c0 >> (x & 0xf) & 16;
|
||||
f |= 0x6c9c0 >> (x >> 4 & 0xf) & 8;
|
||||
f |= 0x3c8b0 >> (x >> 8 & 0xf) & 4;
|
||||
f |= 0x1e458 >> (x >> 12 & 0xf) & 2;
|
||||
f |= 0x0d938 >> (x >> 16 & 0xf) & 1;
|
||||
return BIT(0xEC57E80A, f);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SWAPENDIAN(x)\
|
||||
(x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
|
||||
#define SWAPENDIAN(x) (x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
|
||||
|
||||
void crypto1_init(struct Crypto1State *state, uint64_t key) {
|
||||
if (state == NULL)
|
||||
return;
|
||||
void crypto1_init(struct Crypto1State *state, uint64_t key)
|
||||
{
|
||||
if (state == NULL) return;
|
||||
state->odd = 0;
|
||||
state->even = 0;
|
||||
for (int i = 47; i > 0; i -= 2) {
|
||||
state->odd = state->odd << 1 | BIT(key, (i - 1) ^ 7);
|
||||
state->odd = state->odd << 1 | BIT(key, (i - 1) ^ 7);
|
||||
state->even = state->even << 1 | BIT(key, i ^ 7);
|
||||
}
|
||||
}
|
||||
|
||||
void inline crypto1_deinit(struct Crypto1State *state) {
|
||||
void inline crypto1_deinit(struct Crypto1State *state)
|
||||
{
|
||||
state->odd = 0;
|
||||
state->even = 0;
|
||||
}
|
||||
|
||||
#if defined(__arm__) || defined(__linux__) || defined(_WIN32) || defined(__APPLE__) // bare metal ARM Proxmark lacks calloc()/free()
|
||||
struct Crypto1State *crypto1_create(uint64_t key) {
|
||||
#if defined(__arm__) || defined(__linux__) || defined(_WIN32) \
|
||||
|| defined(__APPLE__) // bare metal ARM Proxmark lacks calloc()/free()
|
||||
struct Crypto1State *crypto1_create(uint64_t key)
|
||||
{
|
||||
struct Crypto1State *state = calloc(sizeof(*state), sizeof(uint8_t));
|
||||
if (!state) return NULL;
|
||||
crypto1_init(state, key);
|
||||
return state;
|
||||
}
|
||||
|
||||
void crypto1_destroy(struct Crypto1State *state) {
|
||||
free(state);
|
||||
}
|
||||
void crypto1_destroy(struct Crypto1State *state) { free(state); }
|
||||
#endif
|
||||
|
||||
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) {
|
||||
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr)
|
||||
{
|
||||
int i;
|
||||
for (*lfsr = 0, i = 23; i >= 0; --i) {
|
||||
*lfsr = *lfsr << 1 | BIT(state->odd, i ^ 3);
|
||||
*lfsr = *lfsr << 1 | BIT(state->even, i ^ 3);
|
||||
}
|
||||
}
|
||||
uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted) {
|
||||
uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
|
||||
{
|
||||
uint32_t feedin, t;
|
||||
uint8_t ret = filter(s->odd);
|
||||
|
||||
feedin = ret & (!!is_encrypted);
|
||||
feedin = ret & (!!is_encrypted);
|
||||
feedin ^= !!in;
|
||||
feedin ^= LF_POLY_ODD & s->odd;
|
||||
feedin ^= LF_POLY_EVEN & s->even;
|
||||
@@ -85,7 +90,8 @@ uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted) {
|
||||
uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
ret |= crypto1_bit(s, BIT(in, 0), is_encrypted) << 0;
|
||||
ret |= crypto1_bit(s, BIT(in, 1), is_encrypted) << 1;
|
||||
@@ -97,7 +103,8 @@ uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted) {
|
||||
ret |= crypto1_bit(s, BIT(in, 7), is_encrypted) << 7;
|
||||
return ret;
|
||||
}
|
||||
uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted) {
|
||||
uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
// note: xor args have been swapped because some compilers emit a warning
|
||||
// for 10^x and 2^x as possible misuses for exponentiation. No comment.
|
||||
@@ -144,12 +151,12 @@ uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted) {
|
||||
/* prng_successor
|
||||
* helper used to obscure the keystream during authentication
|
||||
*/
|
||||
uint32_t prng_successor(uint32_t x, uint32_t n) {
|
||||
uint32_t prng_successor(uint32_t x, uint32_t n)
|
||||
{
|
||||
// SWAPENDIAN(x);
|
||||
x = __REV(x);
|
||||
|
||||
while (n--)
|
||||
x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31;
|
||||
while (n--) x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31;
|
||||
|
||||
// return SWAPENDIAN(x);
|
||||
return __REV(x);
|
||||
|
||||
@@ -16,14 +16,17 @@
|
||||
#ifndef CRAPTO1_INCLUDED
|
||||
#define CRAPTO1_INCLUDED
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct Crypto1State {uint32_t odd, even;};
|
||||
struct Crypto1State {
|
||||
uint32_t odd, even;
|
||||
};
|
||||
void crypto1_init(struct Crypto1State *state, uint64_t key);
|
||||
void crypto1_deinit(struct Crypto1State *);
|
||||
#if defined(__arm__) || defined(__linux__) || defined(_WIN32) || defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
||||
#if defined(__arm__) || defined(__linux__) || defined(_WIN32) \
|
||||
|| defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
||||
struct Crypto1State *crypto1_create(uint64_t key);
|
||||
void crypto1_destroy(struct Crypto1State *);
|
||||
#endif
|
||||
@@ -37,32 +40,33 @@ uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb);
|
||||
uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb);
|
||||
uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb);
|
||||
|
||||
#define FOREACH_VALID_NONCE(N, FILTER, FSIZE)\
|
||||
uint32_t __n = 0,__M = 0, N = 0;\
|
||||
int __i;\
|
||||
for(; __n < 1 << 16; N = prng_successor(__M = ++__n, 16))\
|
||||
for(__i = FSIZE - 1; __i >= 0; __i--)\
|
||||
if(BIT(FILTER, __i) ^ evenparity32(__M & 0xFF01))\
|
||||
break;\
|
||||
else if(__i)\
|
||||
__M = prng_successor(__M, (__i == 7) ? 48 : 8);\
|
||||
#define FOREACH_VALID_NONCE(N, FILTER, FSIZE) \
|
||||
uint32_t __n = 0, __M = 0, N = 0; \
|
||||
int __i; \
|
||||
for (; __n < 1 << 16; N = prng_successor(__M = ++__n, 16)) \
|
||||
for (__i = FSIZE - 1; __i >= 0; __i--) \
|
||||
if (BIT(FILTER, __i) ^ evenparity32(__M & 0xFF01)) \
|
||||
break; \
|
||||
else if (__i) \
|
||||
__M = prng_successor(__M, (__i == 7) ? 48 : 8); \
|
||||
else
|
||||
|
||||
#define LF_POLY_ODD (0x29CE5C)
|
||||
#define LF_POLY_EVEN (0x870804)
|
||||
#define BIT(x, n) ((x) >> (n) & 1)
|
||||
#define BIT(x, n) ((x) >> (n)&1)
|
||||
#define BEBIT(x, n) BIT(x, (n) ^ 24)
|
||||
#ifdef __OPTIMIZE_SIZE__
|
||||
int filter(uint32_t const x);
|
||||
#else
|
||||
static inline int filter(uint32_t const x) {
|
||||
static inline int filter(uint32_t const x)
|
||||
{
|
||||
uint32_t f;
|
||||
|
||||
f = 0xf22c0 >> (x & 0xf) & 16;
|
||||
f |= 0x6c9c0 >> (x >> 4 & 0xf) & 8;
|
||||
f |= 0x3c8b0 >> (x >> 8 & 0xf) & 4;
|
||||
f |= 0x1e458 >> (x >> 12 & 0xf) & 2;
|
||||
f |= 0x0d938 >> (x >> 16 & 0xf) & 1;
|
||||
f = 0xf22c0 >> (x & 0xf) & 16;
|
||||
f |= 0x6c9c0 >> (x >> 4 & 0xf) & 8;
|
||||
f |= 0x3c8b0 >> (x >> 8 & 0xf) & 4;
|
||||
f |= 0x1e458 >> (x >> 12 & 0xf) & 2;
|
||||
f |= 0x0d938 >> (x >> 16 & 0xf) & 1;
|
||||
return BIT(0xEC57E80A, f);
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
||||
#ifndef CRYPTO1_H
|
||||
#define CRYPTO1_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// debug to use
|
||||
void Crypto1GetState(uint8_t *pEven, uint8_t *pOdd);
|
||||
@@ -39,4 +39,4 @@ void Crypto1EncryptWithParity(uint8_t *Buffer, uint8_t BitCount);
|
||||
/* Encrypts buffer with LFSR feedback within reader nonce and considers parity bits */
|
||||
void Crypto1ReaderAuthWithParity(uint8_t PlainReaderAnswerWithParityBits[9]);
|
||||
|
||||
#endif //CRYPTO1_H
|
||||
#endif // CRYPTO1_H
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "crypto1_helper.h"
|
||||
|
||||
// crypto1 helpers
|
||||
void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out) {
|
||||
void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out)
|
||||
{
|
||||
if (len != 1) {
|
||||
for (int i = 0; i < len; i++)
|
||||
data_out[i] = crypto1_byte(pcs, 0x00, 0) ^ data_in[i];
|
||||
} else {
|
||||
for (int i = 0; i < len; i++) data_out[i] = crypto1_byte(pcs, 0x00, 0) ^ data_in[i];
|
||||
}
|
||||
else {
|
||||
uint8_t bt = 0;
|
||||
bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data_in[0], 0)) << 0;
|
||||
bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data_in[0], 1)) << 1;
|
||||
@@ -16,11 +17,14 @@ void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, u
|
||||
return;
|
||||
}
|
||||
|
||||
void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len) {
|
||||
void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len)
|
||||
{
|
||||
mf_crypto1_decryptEx(pcs, data, len, data);
|
||||
}
|
||||
|
||||
void mf_crypto1_encryptEx(struct Crypto1State *pcs, uint8_t *data_in, uint8_t *keystream, uint8_t *data_out, uint16_t len, uint8_t *par) {
|
||||
void mf_crypto1_encryptEx(struct Crypto1State *pcs, uint8_t *data_in, uint8_t *keystream, uint8_t *data_out,
|
||||
uint16_t len, uint8_t *par)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t bt = data_in[i];
|
||||
@@ -31,11 +35,13 @@ void mf_crypto1_encryptEx(struct Crypto1State *pcs, uint8_t *data_in, uint8_t *k
|
||||
}
|
||||
}
|
||||
|
||||
void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par) {
|
||||
void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par)
|
||||
{
|
||||
mf_crypto1_encryptEx(pcs, data, NULL, data, len, par);
|
||||
}
|
||||
|
||||
uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data) {
|
||||
uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data)
|
||||
{
|
||||
uint8_t bt = 0;
|
||||
bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data, 0)) << 0;
|
||||
bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data, 1)) << 1;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user