mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
tabs to 4 spaces
This commit is contained in:
+102
-102
@@ -179,129 +179,129 @@ data_frame_tx_t* cmd_processor_detect_mf1_darkside(uint16_t cmd, uint16_t status
|
||||
|
||||
data_frame_tx_t* cmd_processor_mf1_darkside_acquire(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
DarksideCore dc;
|
||||
if (length == 4) {
|
||||
status = Darkside_Recover_Key(data[1], data[0], data[2], data[3], &dc);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(DarksideCore);
|
||||
data = (uint8_t *)(&dc);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
if (length == 4) {
|
||||
status = Darkside_Recover_Key(data[1], data[0], data[2], data[3], &dc);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(DarksideCore);
|
||||
data = (uint8_t *)(&dc);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
return data_frame_make(cmd, status, length, data);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_detect_nested_dist(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
NestedDist nd;
|
||||
if (length == 8) {
|
||||
status = Nested_Distacne_Detect(data[1], data[0], &data[2], &nd);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(NestedDist);
|
||||
data = (uint8_t *)(&nd);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
if (length == 8) {
|
||||
status = Nested_Distacne_Detect(data[1], data[0], &data[2], &nd);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(NestedDist);
|
||||
data = (uint8_t *)(&nd);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_mf1_nt_distance(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
NestedDist nd;
|
||||
if (length == 8) {
|
||||
status = Nested_Distacne_Detect(data[1], data[0], &data[2], &nd);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(NestedDist);
|
||||
data = (uint8_t *)(&nd);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
if (length == 8) {
|
||||
status = Nested_Distacne_Detect(data[1], data[0], &data[2], &nd);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(NestedDist);
|
||||
data = (uint8_t *)(&nd);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
return data_frame_make(cmd, status, length, data);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_mf1_nested_acquire(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
NestedCore ncs[SETS_NR];
|
||||
if (length == 10) {
|
||||
status = Nested_Recover_Key(bytes_to_num(&data[2], 6), data[1], data[0], data[9], data[8], ncs);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(ncs);
|
||||
data = (uint8_t *)(&ncs);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
if (length == 10) {
|
||||
status = Nested_Recover_Key(bytes_to_num(&data[2], 6), data[1], data[0], data[9], data[8], ncs);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(ncs);
|
||||
data = (uint8_t *)(&ncs);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
length = 0;
|
||||
}
|
||||
return data_frame_make(cmd, status, length, data);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_mf1_auth_one_key_block(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
if (length == 8) {
|
||||
status = auth_key_use_522_hw(data[1], data[0], &data[2]);
|
||||
status = auth_key_use_522_hw(data[1], data[0], &data[2]);
|
||||
pcd_14a_reader_mf1_unauth();
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_mf1_read_one_block(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
uint8_t block[16] = { 0x00 };
|
||||
if (length == 8) {
|
||||
status = auth_key_use_522_hw(data[1], data[0], &data[2]);
|
||||
if (status == HF_TAG_OK) {
|
||||
status = pcd_14a_reader_mf1_read(data[1], block);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = 16;
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
length = 0;
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
if (length == 8) {
|
||||
status = auth_key_use_522_hw(data[1], data[0], &data[2]);
|
||||
if (status == HF_TAG_OK) {
|
||||
status = pcd_14a_reader_mf1_read(data[1], block);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = 16;
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
length = 0;
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, length, block);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_mf1_write_one_block(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
if (length == 24) {
|
||||
status = auth_key_use_522_hw(data[1], data[0], &data[2]);
|
||||
if (status == HF_TAG_OK) {
|
||||
status = pcd_14a_reader_mf1_write(data[1], &data[8]);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
status = auth_key_use_522_hw(data[1], data[0], &data[2]);
|
||||
if (status == HF_TAG_OK) {
|
||||
status = pcd_14a_reader_mf1_write(data[1], &data[8]);
|
||||
} else {
|
||||
length = 0;
|
||||
}
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_em410x_scan(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
uint8_t id_buffer[5] = { 0x00 };
|
||||
status = PcdScanEM410X(id_buffer);
|
||||
status = PcdScanEM410X(id_buffer);
|
||||
return data_frame_make(cmd, status, sizeof(id_buffer), id_buffer);
|
||||
}
|
||||
|
||||
data_frame_tx_t* cmd_processor_write_em410x_2_t57(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
if (length >= 13 && (length - 9) % 4 == 0) {
|
||||
status = PcdWriteT55XX(data, data + 5, data + 9, (length - 9) / 4);
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
if (length >= 13 && (length - 9) % 4 == 0) {
|
||||
status = PcdWriteT55XX(data, data + 5, data + 9, (length - 9) / 4);
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ data_frame_tx_t* cmd_processor_set_slot_activated(uint16_t cmd, uint16_t status,
|
||||
if (length == 1 && data[0] < TAG_MAX_SLOT_NUM) {
|
||||
change_slot_auto(data[0]);
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -330,8 +330,8 @@ data_frame_tx_t* cmd_processor_set_slot_tag_type(uint16_t cmd, uint16_t status,
|
||||
uint8_t num_slot = data[0];
|
||||
uint8_t tag_type = data[1];
|
||||
tag_emulation_change_type(num_slot, (tag_specific_type_t)tag_type);
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -354,7 +354,7 @@ data_frame_tx_t* cmd_processor_set_slot_data_default(uint16_t cmd, uint16_t stat
|
||||
uint8_t num_slot = data[0];
|
||||
uint8_t tag_type = data[1];
|
||||
status = tag_emulation_factory_data(num_slot, (tag_specific_type_t)tag_type) ? STATUS_DEVICE_SUCCESS : STATUS_NOT_IMPLEMENTED;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -375,7 +375,7 @@ data_frame_tx_t* cmd_processor_set_slot_enable(uint16_t cmd, uint16_t status, ui
|
||||
}
|
||||
}
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -416,7 +416,7 @@ data_frame_tx_t* cmd_processor_set_em410x_emu_id(uint16_t cmd, uint16_t status,
|
||||
memcpy(buffer->buffer, data, LF_EM410X_TAG_ID_SIZE);
|
||||
tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false);
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -435,7 +435,7 @@ data_frame_tx_t* cmd_processor_set_mf1_detection_enable(uint16_t cmd, uint16_t s
|
||||
nfc_tag_mf1_detection_log_clear();
|
||||
nfc_tag_mf1_set_detection_enable(data[0]);
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -640,7 +640,7 @@ data_frame_tx_t* cmd_processor_set_mf1_gen1a_magic_mode(uint16_t cmd, uint16_t s
|
||||
if (length == 1 && (data[0] == 0 || data[0] == 1)) {
|
||||
nfc_tag_mf1_set_gen1a_magic_mode(data[0]);
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -659,7 +659,7 @@ data_frame_tx_t* cmd_processor_set_mf1_gen2_magic_mode(uint16_t cmd, uint16_t st
|
||||
if (length == 1 && (data[0] == 0 || data[0] == 1)) {
|
||||
nfc_tag_mf1_set_gen2_magic_mode(data[0]);
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -678,7 +678,7 @@ data_frame_tx_t* cmd_processor_set_mf1_use_coll_res(uint16_t cmd, uint16_t statu
|
||||
if (length == 1 && (data[0] == 0 || data[0] == 1)) {
|
||||
nfc_tag_mf1_set_use_mf1_coll_res(data[0]);
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -711,7 +711,7 @@ data_frame_tx_t* cmd_processor_set_mf1_write_mode(uint16_t cmd, uint16_t status,
|
||||
nfc_tag_mf1_set_write_mode(NFC_TAG_MF1_WRITE_SHADOW);
|
||||
}
|
||||
status = STATUS_DEVICE_SUCCESS;
|
||||
} else {
|
||||
} else {
|
||||
status = STATUS_PAR_ERR;
|
||||
}
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
@@ -851,15 +851,15 @@ static cmd_data_map_t m_data_cmd_map[] = {
|
||||
* @param resp data
|
||||
*/
|
||||
void auto_response_data(data_frame_tx_t* resp) {
|
||||
// TODO Please select the reply source automatically according to the message source,
|
||||
// TODO Please select the reply source automatically according to the message source,
|
||||
// and do not reply by checking the validity of the link layer by layer
|
||||
if (is_usb_working()) {
|
||||
usb_cdc_write(resp->buffer, resp->length);
|
||||
} else if (is_nus_working()) {
|
||||
nus_data_reponse(resp->buffer, resp->length);
|
||||
} else {
|
||||
NRF_LOG_ERROR("No connection valid found at response client.");
|
||||
}
|
||||
if (is_usb_working()) {
|
||||
usb_cdc_write(resp->buffer, resp->length);
|
||||
} else if (is_nus_working()) {
|
||||
nus_data_reponse(resp->buffer, resp->length);
|
||||
} else {
|
||||
NRF_LOG_ERROR("No connection valid found at response client.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -494,11 +494,11 @@ static void offline_status_blink_color(uint8_t blink_color) {
|
||||
}
|
||||
|
||||
static void offline_status_error(void) {
|
||||
offline_status_blink_color(0);
|
||||
offline_status_blink_color(0);
|
||||
}
|
||||
|
||||
static void offline_status_ok(void) {
|
||||
offline_status_blink_color(1);
|
||||
offline_status_blink_color(1);
|
||||
}
|
||||
|
||||
// fast detect a 14a tag uid to sim
|
||||
|
||||
@@ -5,38 +5,38 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// 14a status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define HF_TAG_OK (0x00) // IC卡操作成功
|
||||
#define HF_TAG_NO (0x01) // 没有发现IC卡
|
||||
#define HF_ERRSTAT (0x02) // IC卡通信异常
|
||||
#define HF_ERRCRC (0x03) // IC卡通信校验异常
|
||||
#define HF_COLLISION (0x04) // IC卡冲突
|
||||
#define HF_ERRBCC (0x05) // IC卡BCC错误
|
||||
#define MF_ERRAUTH (0x06) // MF卡验证失败
|
||||
#define HF_ERRPARITY (0x07) // IC卡奇偶校验错误
|
||||
#define HF_TAG_OK (0x00) // IC卡操作成功
|
||||
#define HF_TAG_NO (0x01) // 没有发现IC卡
|
||||
#define HF_ERRSTAT (0x02) // IC卡通信异常
|
||||
#define HF_ERRCRC (0x03) // IC卡通信校验异常
|
||||
#define HF_COLLISION (0x04) // IC卡冲突
|
||||
#define HF_ERRBCC (0x05) // IC卡BCC错误
|
||||
#define MF_ERRAUTH (0x06) // MF卡验证失败
|
||||
#define HF_ERRPARITY (0x07) // IC卡奇偶校验错误
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// MIFARE status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define DARKSIDE_CANT_FIXED_NT (0x20) // Darkside,无法固定随机数,这个情况可能出现在UID卡上
|
||||
#define DARKSIDE_LUCK_AUTH_OK (0x21) // Darkside,直接验证成功了,可能刚好密钥是空的
|
||||
#define DARKSIDE_NACK_NO_SEND (0x22) // Darkside,卡片不响应nack,可能是一张修复了nack逻辑漏洞的卡片
|
||||
#define DARKSIDE_TAG_CHANGED (0x23) // Darkside,在运行darkside的过程中出现了卡片切换,可能信号问题,或者真的是两张卡迅速切换了
|
||||
#define NESTED_TAG_IS_STATIC (0x24) // Nested,检测到卡片应答的随机数是固定的
|
||||
#define NESTED_TAG_IS_HARD (0x25) // Nested,检测到卡片应答的随机数是不可预测的
|
||||
#define DARKSIDE_CANT_FIXED_NT (0x20) // Darkside,无法固定随机数,这个情况可能出现在UID卡上
|
||||
#define DARKSIDE_LUCK_AUTH_OK (0x21) // Darkside,直接验证成功了,可能刚好密钥是空的
|
||||
#define DARKSIDE_NACK_NO_SEND (0x22) // Darkside,卡片不响应nack,可能是一张修复了nack逻辑漏洞的卡片
|
||||
#define DARKSIDE_TAG_CHANGED (0x23) // Darkside,在运行darkside的过程中出现了卡片切换,可能信号问题,或者真的是两张卡迅速切换了
|
||||
#define NESTED_TAG_IS_STATIC (0x24) // Nested,检测到卡片应答的随机数是固定的
|
||||
#define NESTED_TAG_IS_HARD (0x25) // Nested,检测到卡片应答的随机数是不可预测的
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// lf status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define LF_TAG_OK (0x40) // 低频卡的一些操作成功!
|
||||
#define EM410X_TAG_NO_FOUND (0x41) // 无法搜索到有效的EM410X标签
|
||||
#define LF_TAG_OK (0x40) // 低频卡的一些操作成功!
|
||||
#define EM410X_TAG_NO_FOUND (0x41) // 无法搜索到有效的EM410X标签
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// other status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define STATUS_PAR_ERR (0x60) // BLE指令传递的参数错误,或者是调用某些函数传递的参数错误
|
||||
#define STATUS_PAR_ERR (0x60) // BLE指令传递的参数错误,或者是调用某些函数传递的参数错误
|
||||
#define STATUS_DEVIEC_MODE_ERROR (0x66) // 当前设备所处的模式错误,无法调用对应的API
|
||||
#define STATUS_INVALID_CMD (0x67) // 无效的指令
|
||||
#define STATUS_DEVICE_SUCCESS (0x68) // 设备相关操作成功执行
|
||||
|
||||
@@ -193,81 +193,81 @@ static void nrf_qwr_error_handler(uint32_t nrf_error)
|
||||
|
||||
__INLINE uint32_t map(uint32_t x, uint32_t in_min, uint32_t in_max, uint32_t out_min, uint32_t out_max)
|
||||
{
|
||||
return (uint32_t)((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min);
|
||||
return (uint32_t)((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min);
|
||||
}
|
||||
|
||||
//电池电压到百分比计算
|
||||
uint32_t BATVOL2PERCENT(uint16_t VOL)
|
||||
{
|
||||
//100% 4.20V 1
|
||||
//90 % 4.06V 80%-100% 白
|
||||
//80 % 3.98V 1
|
||||
//70 % 3.92V 60%-80% 白
|
||||
//60 % 3.87V 1
|
||||
//50 % 3.82V 40%-60% 白
|
||||
//40 % 3.79V 1
|
||||
//30 % 3.77V 20%-40% 白
|
||||
//20 % 3.74V 1
|
||||
//10 % 3.68V 5%-20% 红
|
||||
//5 % 3.45V 1 关机
|
||||
//0 % 3.00V
|
||||
//#define P100VOL 4200
|
||||
//#define P80VOL 3980
|
||||
//#define P60VOL 3870
|
||||
//#define P40VOL 3790
|
||||
//#define P20VOL 3740
|
||||
//#define P5VOL 3450
|
||||
//100% 4.20V 1
|
||||
//90 % 4.06V 80%-100% 白
|
||||
//80 % 3.98V 1
|
||||
//70 % 3.92V 60%-80% 白
|
||||
//60 % 3.87V 1
|
||||
//50 % 3.82V 40%-60% 白
|
||||
//40 % 3.79V 1
|
||||
//30 % 3.77V 20%-40% 白
|
||||
//20 % 3.74V 1
|
||||
//10 % 3.68V 5%-20% 红
|
||||
//5 % 3.45V 1 关机
|
||||
//0 % 3.00V
|
||||
//#define P100VOL 4200
|
||||
//#define P80VOL 3980
|
||||
//#define P60VOL 3870
|
||||
//#define P40VOL 3790
|
||||
//#define P20VOL 3740
|
||||
//#define P5VOL 3450
|
||||
|
||||
//100% 4.20V 1
|
||||
//90 % 4.00V 80%-100% 白
|
||||
//80 % 3.89V 1
|
||||
//70 % 3.79V 60%-80% 白
|
||||
//60 % 3.70V 1
|
||||
//50 % 3.62V 40%-60% 白
|
||||
//40 % 3.57V 1
|
||||
//30 % 3.53V 20%-40% 白
|
||||
//20 % 3.51V 1
|
||||
//10 % 3.46V 5%-20% 红
|
||||
//5 % 3.43V 1 关机
|
||||
//0 % 3.00V
|
||||
#define P100VOL 4200
|
||||
#define P80VOL 3890
|
||||
#define P60VOL 3700
|
||||
#define P40VOL 3570
|
||||
#define P20VOL 3510
|
||||
#define P5VOL 3230
|
||||
//100% 4.20V 1
|
||||
//90 % 4.00V 80%-100% 白
|
||||
//80 % 3.89V 1
|
||||
//70 % 3.79V 60%-80% 白
|
||||
//60 % 3.70V 1
|
||||
//50 % 3.62V 40%-60% 白
|
||||
//40 % 3.57V 1
|
||||
//30 % 3.53V 20%-40% 白
|
||||
//20 % 3.51V 1
|
||||
//10 % 3.46V 5%-20% 红
|
||||
//5 % 3.43V 1 关机
|
||||
//0 % 3.00V
|
||||
#define P100VOL 4200
|
||||
#define P80VOL 3890
|
||||
#define P60VOL 3700
|
||||
#define P40VOL 3570
|
||||
#define P20VOL 3510
|
||||
#define P5VOL 3230
|
||||
|
||||
|
||||
if(VOL > P80VOL)
|
||||
{
|
||||
//80-100
|
||||
return map(VOL, P80VOL, P100VOL, 80, 100);
|
||||
}
|
||||
else if(VOL > P60VOL)
|
||||
{
|
||||
//60-80
|
||||
return map(VOL, P60VOL, P80VOL, 60, 80);
|
||||
}
|
||||
else if(VOL > P40VOL)
|
||||
{
|
||||
//40-60
|
||||
return map(VOL, P40VOL, P60VOL, 40, 60);
|
||||
}
|
||||
else if(VOL > P20VOL)
|
||||
{
|
||||
//20-60
|
||||
return map(VOL, P20VOL, P40VOL, 20, 40);
|
||||
}
|
||||
else if(VOL > P5VOL)
|
||||
{
|
||||
//5-20
|
||||
return map(VOL, P5VOL, P20VOL, 5, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
//<5
|
||||
return 0;
|
||||
}
|
||||
if(VOL > P80VOL)
|
||||
{
|
||||
//80-100
|
||||
return map(VOL, P80VOL, P100VOL, 80, 100);
|
||||
}
|
||||
else if(VOL > P60VOL)
|
||||
{
|
||||
//60-80
|
||||
return map(VOL, P60VOL, P80VOL, 60, 80);
|
||||
}
|
||||
else if(VOL > P40VOL)
|
||||
{
|
||||
//40-60
|
||||
return map(VOL, P40VOL, P60VOL, 40, 60);
|
||||
}
|
||||
else if(VOL > P20VOL)
|
||||
{
|
||||
//20-60
|
||||
return map(VOL, P20VOL, P40VOL, 20, 40);
|
||||
}
|
||||
else if(VOL > P5VOL)
|
||||
{
|
||||
//5-20
|
||||
return map(VOL, P5VOL, P20VOL, 5, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
//<5
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**@brief Function for initializing services that will be used by the application.
|
||||
|
||||
@@ -12,12 +12,12 @@ void bsp_delay_init(void)
|
||||
//注意nms的范围
|
||||
void bsp_delay_ms(uint16_t nms)
|
||||
{
|
||||
nrf_delay_us(nms * 1000);
|
||||
nrf_delay_us(nms * 1000);
|
||||
}
|
||||
|
||||
//延时nus
|
||||
//nus为要延时的us数.
|
||||
void bsp_delay_us(uint32_t nus)
|
||||
{
|
||||
nrf_delay_us(nus);
|
||||
nrf_delay_us(nus);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ autotimer* bsp_obtain_timer(uint32_t start_value) {
|
||||
if (bsptimers[i].busy == 0) {
|
||||
bsptimers[i].time = start_value;
|
||||
bsptimers[i].busy = 1;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return &bsptimers[i];
|
||||
|
||||
@@ -2,38 +2,38 @@
|
||||
|
||||
// CRC查表
|
||||
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,
|
||||
};
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@ static uint16_t crc_table[256] = {
|
||||
*
|
||||
*/
|
||||
void calc_14a_crc_lut(uint8_t* data, int length, uint8_t* output) {
|
||||
// 取巧,强制指针类型转换
|
||||
// 取巧,强制指针类型转换
|
||||
uint16_t *crc = (uint16_t *)output;
|
||||
// 赋予多项式初始值
|
||||
*crc = 0x6363;
|
||||
// 然后开始对每个字节进行查表
|
||||
// 赋予多项式初始值
|
||||
*crc = 0x6363;
|
||||
// 然后开始对每个字节进行查表
|
||||
while (length--) *crc = (*crc >> 8) ^ crc_table[(*crc & 0xFF) ^ *data++];
|
||||
}
|
||||
|
||||
@@ -2,35 +2,35 @@
|
||||
|
||||
|
||||
/**
|
||||
* @brief : 将大数字转换为HEX字节数组
|
||||
* @param :n : 将被转换的值
|
||||
* @param :len : 存放转换后的数值的字节长度
|
||||
* @param :dest : 存放转换结果的缓冲区
|
||||
* @retval : 无
|
||||
* @brief : 将大数字转换为HEX字节数组
|
||||
* @param :n : 将被转换的值
|
||||
* @param :len : 存放转换后的数值的字节长度
|
||||
* @param :dest : 存放转换结果的缓冲区
|
||||
* @retval : 无
|
||||
*
|
||||
*/
|
||||
void num_to_bytes(uint64_t n, uint8_t len, uint8_t* dest)
|
||||
{
|
||||
while (len--) {
|
||||
dest[len] = (uint8_t)n;
|
||||
n >>= 8;
|
||||
}
|
||||
while (len--) {
|
||||
dest[len] = (uint8_t)n;
|
||||
n >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief : 将字节数组转换为大数字
|
||||
* @param :len : 存放数值的缓冲区的字节长度
|
||||
* @param :src : 存放数值的字节缓冲区
|
||||
* @retval : 转换结果
|
||||
* @brief : 将字节数组转换为大数字
|
||||
* @param :len : 存放数值的缓冲区的字节长度
|
||||
* @param :src : 存放数值的字节缓冲区
|
||||
* @retval : 转换结果
|
||||
*
|
||||
*/
|
||||
uint64_t bytes_to_num(uint8_t* src, uint8_t len)
|
||||
{
|
||||
uint64_t num = 0;
|
||||
while (len--) {
|
||||
num = (num << 8) | (*src);
|
||||
src++;
|
||||
}
|
||||
return num;
|
||||
uint64_t num = 0;
|
||||
while (len--) {
|
||||
num = (num << 8) | (*src);
|
||||
src++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,11 +146,11 @@ uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted) {
|
||||
*/
|
||||
uint32_t prng_successor(uint32_t x, uint32_t n) {
|
||||
// SWAPENDIAN(x);
|
||||
x = __REV(x);
|
||||
x = __REV(x);
|
||||
|
||||
while (n--)
|
||||
x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31;
|
||||
|
||||
// return SWAPENDIAN(x);
|
||||
return __REV(x);
|
||||
return __REV(x);
|
||||
}
|
||||
|
||||
@@ -63,9 +63,9 @@
|
||||
"ror %0" "\n\t" \
|
||||
"lsr %2" "\n\t" \
|
||||
"ror %1" \
|
||||
: "+r" (__even), \
|
||||
: "+r" (__even), \
|
||||
"+r" (__odd), \
|
||||
"+r" (__byte) \
|
||||
"+r" (__byte) \
|
||||
: \
|
||||
: "r0" )
|
||||
|
||||
|
||||
@@ -142,14 +142,14 @@ bool nfc_tag_14a_checks_crc(uint8_t *pbtData, size_t szLen) {
|
||||
|
||||
/**
|
||||
* @brief :包装ISO14443A的比特帧
|
||||
* 自动进行奇偶校验位与数据的包装合并
|
||||
* 自动进行奇偶校验位与数据的包装合并
|
||||
* @param :pbtTx:将要传输的比特流
|
||||
* szTxBits:比特流的长度
|
||||
* pbtTxPar:奇偶校验位的比特流,这个数据的长度一定是 szTxBits / 8,也就是说
|
||||
* 实际上合并之后的比特流的组成结构为:
|
||||
* data(1byte) - par(1bit) - data(1byte) - par(1bit) ...
|
||||
* 00001000 - 0 - 10101110 - 1
|
||||
* 这种类似的数据结构
|
||||
* 实际上合并之后的比特流的组成结构为:
|
||||
* data(1byte) - par(1bit) - data(1byte) - par(1bit) ...
|
||||
* 00001000 - 0 - 10101110 - 1
|
||||
* 这种类似的数据结构
|
||||
* pbtFrame: 最终组装完成的数据的缓冲区
|
||||
* @retval :比特流组装结果缓冲区的长度,注意,是比特长度,换算字节请除以8再取模
|
||||
*/
|
||||
@@ -208,7 +208,7 @@ uint8_t nfc_tag_14a_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, cons
|
||||
|
||||
/**
|
||||
* @brief :解包ISO14443A的比特帧
|
||||
* 自动进行奇偶校验位与数据的解包分离
|
||||
* 自动进行奇偶校验位与数据的解包分离
|
||||
* @param :pbtFrame:将要解包的比特流
|
||||
* szFrameBits:比特流的长度
|
||||
* pbtRx:解包后的比特流的存放的缓冲区,数据区
|
||||
|
||||
@@ -723,7 +723,7 @@ void nfc_tag_mf1_state_handler(uint8_t* p_data, uint16_t szDataBits) {
|
||||
return;
|
||||
}
|
||||
case CMD_WRITE: {
|
||||
// 正常的卡不允许写block0,不然会被CUID防火墙识别到
|
||||
// 正常的卡不允许写block0,不然会被CUID防火墙识别到
|
||||
if (p_data[1] == 0x00 && !m_tag_information->config.mode_gen2_magic) {
|
||||
// 直接重置14a的状态机,让标签休眠
|
||||
nfc_tag_14a_set_state(NFC_TAG_STATE_14A_HALTED);
|
||||
|
||||
@@ -129,7 +129,7 @@ void timer_ce_handler(nrf_timer_event_t event_type, void* p_context) {
|
||||
switch (event_type) {
|
||||
// 因为我们配置的是使用CC通道2,所以事件回调
|
||||
// 函数中判断NRF_TIMER_EVENT_COMPARE0事件
|
||||
case NRF_TIMER_EVENT_COMPARE2: {
|
||||
case NRF_TIMER_EVENT_COMPARE2: {
|
||||
if (m_is_send_first_edge) {
|
||||
if (GETBIT(m_id_bit_data, m_bit_send_position)) {
|
||||
// 发送 1 的第一个沿
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,35 +8,35 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define SETS_NR 2 // 使用几组随机数探针,至少是2个能确保有两组随机数组合进行交集查询,这个值越大越容易成功
|
||||
#define DIST_NR 3 // 越多的距离值越能准确判断当前卡片的通信稳定性
|
||||
#define SETS_NR 2 // 使用几组随机数探针,至少是2个能确保有两组随机数组合进行交集查询,这个值越大越容易成功
|
||||
#define DIST_NR 3 // 越多的距离值越能准确判断当前卡片的通信稳定性
|
||||
|
||||
// mifare authentication
|
||||
#define CRYPT_NONE 0
|
||||
#define CRYPT_ALL 1
|
||||
#define CRYPT_REQUEST 2
|
||||
#define AUTH_FIRST 0
|
||||
#define AUTH_NESTED 2
|
||||
#define CRYPT_NONE 0
|
||||
#define CRYPT_ALL 1
|
||||
#define CRYPT_REQUEST 2
|
||||
#define AUTH_FIRST 0
|
||||
#define AUTH_NESTED 2
|
||||
|
||||
typedef struct { // 应答 nested 攻击需要的 距离参数
|
||||
uint8_t uid[4]; // 这个距离数据的所属UID的U32部分
|
||||
uint8_t distance[4]; // 未经加密的明文随机数
|
||||
typedef struct { // 应答 nested 攻击需要的 距离参数
|
||||
uint8_t uid[4]; // 这个距离数据的所属UID的U32部分
|
||||
uint8_t distance[4]; // 未经加密的明文随机数
|
||||
} NestedDist;
|
||||
|
||||
|
||||
typedef struct { // 应答 nested 攻击需要的 随机数参数
|
||||
uint8_t nt1[4]; // 未经加密的明文随机数
|
||||
uint8_t nt2[4]; // 嵌套验证加密的随机数
|
||||
uint8_t par; // 嵌套验证加密的通信过程的奇偶校验位,只用到了 '低3位',也就是右3位
|
||||
typedef struct { // 应答 nested 攻击需要的 随机数参数
|
||||
uint8_t nt1[4]; // 未经加密的明文随机数
|
||||
uint8_t nt2[4]; // 嵌套验证加密的随机数
|
||||
uint8_t par; // 嵌套验证加密的通信过程的奇偶校验位,只用到了 '低3位',也就是右3位
|
||||
} NestedCore;
|
||||
|
||||
typedef struct {
|
||||
uint8_t uid[4];
|
||||
uint8_t nt[4];
|
||||
uint8_t par_list[8];
|
||||
uint8_t ks_list[8];
|
||||
uint8_t nr[4];
|
||||
uint8_t ar[4];
|
||||
uint8_t uid[4];
|
||||
uint8_t nt[4];
|
||||
uint8_t par_list[8];
|
||||
uint8_t ks_list[8];
|
||||
uint8_t nr[4];
|
||||
uint8_t ar[4];
|
||||
} DarksideCore;
|
||||
|
||||
|
||||
@@ -46,17 +46,17 @@ extern "C" {
|
||||
|
||||
|
||||
uint8_t Darkside_Recover_Key(
|
||||
uint8_t targetBlk,
|
||||
uint8_t targetTyp,
|
||||
uint8_t firstRecover,
|
||||
uint8_t ntSyncMax,
|
||||
DarksideCore* dc
|
||||
uint8_t targetBlk,
|
||||
uint8_t targetTyp,
|
||||
uint8_t firstRecover,
|
||||
uint8_t ntSyncMax,
|
||||
DarksideCore* dc
|
||||
);
|
||||
uint8_t Nested_Distacne_Detect(
|
||||
uint8_t block,
|
||||
uint8_t type,
|
||||
uint8_t *key,
|
||||
NestedDist *nd
|
||||
uint8_t block,
|
||||
uint8_t type,
|
||||
uint8_t *key,
|
||||
NestedDist *nd
|
||||
);
|
||||
uint8_t Nested_Recover_Key(
|
||||
uint64_t keyKnown,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@
|
||||
#define PCD_RECEIVE 0x08 //接收数据
|
||||
#define PCD_TRANSMIT 0x04 //发送数据
|
||||
#define PCD_TRANSCEIVE 0x0C //发送并接收数据
|
||||
#define PCD_RESET 0x0F //复位
|
||||
#define PCD_RESET 0x0F //复位
|
||||
#define PCD_CALCCRC 0x03 //CRC计算
|
||||
|
||||
/*
|
||||
@@ -26,7 +26,7 @@
|
||||
#define PICC_ANTICOLL1 0x93 //防冲撞
|
||||
#define PICC_ANTICOLL2 0x95 //防冲撞
|
||||
#define PICC_ANTICOLL3 0x97 //防冲撞
|
||||
#define PICC_RATS 0xE0 //选择应答
|
||||
#define PICC_RATS 0xE0 //选择应答
|
||||
|
||||
/*
|
||||
* M1卡片命令字
|
||||
@@ -42,28 +42,28 @@
|
||||
#define PICC_HALT 0x50 //休眠
|
||||
|
||||
// GEN1A标签的命令字
|
||||
#define PICC_MAGICWUPC1 0x40 // 后门指令1
|
||||
#define PICC_MAGICWUPC2 0x43 // 后门指令2
|
||||
#define PICC_MAGICWIPEC 0x41 // 后门清卡指令
|
||||
#define PICC_MAGICWUPC1 0x40 // 后门指令1
|
||||
#define PICC_MAGICWUPC2 0x43 // 后门指令2
|
||||
#define PICC_MAGICWIPEC 0x41 // 后门清卡指令
|
||||
|
||||
/* RC522 FIFO长度定义 */
|
||||
#define DEF_FIFO_LENGTH 64 //FIFO size=64byte
|
||||
#define DEF_FIFO_LENGTH 64 //FIFO size=64byte
|
||||
|
||||
// RC522 CRC长度定义
|
||||
#define DEF_CRC_LENGTH 2
|
||||
#define DEF_CRC_LENGTH 2
|
||||
|
||||
/*
|
||||
RC522 默认定时器超时配置,这个值可以动态调整,通过 PcdSetTimeout 函数
|
||||
操作标准M1卡最大等待时间 25ms
|
||||
我们可以提高超时以兼容一些反应比较迟钝的卡
|
||||
比如某些手环模拟的卡,比如某些其他硬件模拟的卡,例如变色龙
|
||||
如果超时值太小,就有可能没办法读到UID(Gen1A)卡!
|
||||
RC522 默认定时器超时配置,这个值可以动态调整,通过 PcdSetTimeout 函数
|
||||
操作标准M1卡最大等待时间 25ms
|
||||
我们可以提高超时以兼容一些反应比较迟钝的卡
|
||||
比如某些手环模拟的卡,比如某些其他硬件模拟的卡,例如变色龙
|
||||
如果超时值太小,就有可能没办法读到UID(Gen1A)卡!
|
||||
*/
|
||||
#define DEF_COM_TIMEOUT 25
|
||||
#define DEF_COM_TIMEOUT 25
|
||||
|
||||
// 数据IO长度定义
|
||||
#define MAX_MIFARE_FRAME_SIZE 18 // biggest Mifare frame is answer to a read (one block = 16 Bytes) + 2 Bytes CRC
|
||||
#define MAX_MIFARE_PARITY_SIZE 3 // need 18 parity bits for the 18 Byte above. 3 Bytes are enough to store these
|
||||
#define MAX_MIFARE_FRAME_SIZE 18 // biggest Mifare frame is answer to a read (one block = 16 Bytes) + 2 Bytes CRC
|
||||
#define MAX_MIFARE_PARITY_SIZE 3 // need 18 parity bits for the 18 Byte above. 3 Bytes are enough to store these
|
||||
#define CARD_MEMORY_SIZE 4096
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
@@ -136,7 +136,7 @@
|
||||
#define RFU3C 0x3C //保留
|
||||
#define RFU3D 0x3D //保留
|
||||
#define RFU3E 0x3E //保留
|
||||
#define RFU3F 0x3F //保留
|
||||
#define RFU3F 0x3F //保留
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
@@ -152,84 +152,84 @@
|
||||
|
||||
// 标签信息的基本结构封装
|
||||
typedef struct {
|
||||
uint8_t uid[10]; // 卡号的字节数组,最长10字节
|
||||
uint8_t uid_len; // 卡号的长度
|
||||
uint8_t cascade; // 防冲撞等级 值为1表示 4byte,2表示7byte,3表示10byte
|
||||
uint8_t sak; // 选择确认
|
||||
uint8_t atqa[2]; // 请求应答
|
||||
uint8_t uid[10]; // 卡号的字节数组,最长10字节
|
||||
uint8_t uid_len; // 卡号的长度
|
||||
uint8_t cascade; // 防冲撞等级 值为1表示 4byte,2表示7byte,3表示10byte
|
||||
uint8_t sak; // 选择确认
|
||||
uint8_t atqa[2]; // 请求应答
|
||||
} picc_14a_tag_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
// Device control
|
||||
void pcd_14a_reader_init(void);
|
||||
// Device control
|
||||
void pcd_14a_reader_init(void);
|
||||
void pcd_14a_reader_uninit(void);
|
||||
void pcd_14a_reader_reset(void);
|
||||
void pcd_14a_reader_antenna_on(void);
|
||||
void pcd_14a_reader_antenna_off(void);
|
||||
|
||||
// Device register
|
||||
uint8_t read_register_single(uint8_t Address);
|
||||
// Device register
|
||||
uint8_t read_register_single(uint8_t Address);
|
||||
void write_register_single(uint8_t Address, uint8_t value);
|
||||
void clear_register_mask(uint8_t reg, uint8_t mask);
|
||||
void set_register_mask(uint8_t reg, uint8_t mask);
|
||||
|
||||
// Device comunication control
|
||||
uint16_t pcd_14a_reader_timeout_get(void);
|
||||
void pcd_14a_reader_timeout_set(uint16_t timeout_ms);
|
||||
// Device comunication control
|
||||
uint16_t pcd_14a_reader_timeout_get(void);
|
||||
void pcd_14a_reader_timeout_set(uint16_t timeout_ms);
|
||||
|
||||
// Device comunication interface
|
||||
// Device comunication interface
|
||||
uint8_t pcd_14a_reader_bytes_transfer(uint8_t Command,
|
||||
uint8_t* pIn,
|
||||
uint8_t InLenByte,
|
||||
uint8_t* pOut,
|
||||
uint16_t* pOutLenBit,
|
||||
uint16_t maxOutLenBit);
|
||||
uint16_t maxOutLenBit);
|
||||
uint8_t pcd_14a_reader_bits_transfer(uint8_t* pTx,
|
||||
uint16_t szTxBits,
|
||||
uint8_t* pTxPar,
|
||||
uint8_t* pRx,
|
||||
uint8_t* pRxPar,
|
||||
uint16_t* pRxLenBit,
|
||||
uint16_t szRxLenBitMax);
|
||||
uint16_t* pRxLenBit,
|
||||
uint16_t szRxLenBitMax);
|
||||
|
||||
// Device auto append and check 14443-A parity enable or disable.
|
||||
void pcd_14a_reader_parity_on(void);
|
||||
// Device auto append and check 14443-A parity enable or disable.
|
||||
void pcd_14a_reader_parity_on(void);
|
||||
void pcd_14a_reader_parity_off(void);
|
||||
|
||||
// 14443-A tag operation
|
||||
uint8_t pcd_14a_reader_scan_auto(picc_14a_tag_t *tag);
|
||||
uint8_t pcd_14a_reader_ats_request(uint8_t *pAts, uint16_t *szAts, uint16_t szAtsBitMax);
|
||||
uint8_t pcd_14a_reader_atqa_request(uint8_t *resp, uint8_t *resp_par, uint16_t resp_max_bit);
|
||||
// 14443-A tag operation
|
||||
uint8_t pcd_14a_reader_scan_auto(picc_14a_tag_t *tag);
|
||||
uint8_t pcd_14a_reader_ats_request(uint8_t *pAts, uint16_t *szAts, uint16_t szAtsBitMax);
|
||||
uint8_t pcd_14a_reader_atqa_request(uint8_t *resp, uint8_t *resp_par, uint16_t resp_max_bit);
|
||||
|
||||
// M1 tag operation
|
||||
// M1 tag operation
|
||||
uint8_t pcd_14a_reader_mf1_auth(picc_14a_tag_t *tag, uint8_t type, uint8_t addr, uint8_t* pKey);
|
||||
void pcd_14a_reader_mf1_unauth(void);
|
||||
// 写卡操作
|
||||
uint8_t pcd_14a_reader_mf1_write_by_cmd(uint8_t cmd, uint8_t addr, uint8_t* p);
|
||||
void pcd_14a_reader_mf1_unauth(void);
|
||||
// 写卡操作
|
||||
uint8_t pcd_14a_reader_mf1_write_by_cmd(uint8_t cmd, uint8_t addr, uint8_t* p);
|
||||
uint8_t pcd_14a_reader_mf1_write(uint8_t addr, uint8_t* pData);
|
||||
// 读卡操作
|
||||
uint8_t pcd_14a_reader_mf1_read_by_cmd(uint8_t cmd, uint8_t addr, uint8_t* p);
|
||||
// 读卡操作
|
||||
uint8_t pcd_14a_reader_mf1_read_by_cmd(uint8_t cmd, uint8_t addr, uint8_t* p);
|
||||
uint8_t pcd_14a_reader_mf1_read(uint8_t addr, uint8_t* pData);
|
||||
// 休眠卡操作
|
||||
uint8_t pcd_14a_reader_halt_tag(void);
|
||||
void pcd_14a_reader_fast_halt_tag(void);
|
||||
uint8_t pcd_14a_reader_halt_tag(void);
|
||||
void pcd_14a_reader_fast_halt_tag(void);
|
||||
|
||||
// UID & UFUID tag operation
|
||||
uint8_t pcd_14a_reader_gen1a_unlock(void);
|
||||
uint8_t pcd_14a_reader_gen1a_uplock(void);
|
||||
// UID & UFUID tag operation
|
||||
uint8_t pcd_14a_reader_gen1a_unlock(void);
|
||||
uint8_t pcd_14a_reader_gen1a_uplock(void);
|
||||
|
||||
// CRC calulate
|
||||
void pcd_14a_reader_calc_crc(uint8_t* pbtData, size_t szLen, uint8_t* pbtCrc);
|
||||
void crc_14a_calculate(uint8_t* pbtData, size_t szLen, uint8_t* pbtCrc);
|
||||
// CRC calulate
|
||||
void pcd_14a_reader_calc_crc(uint8_t* pbtData, size_t szLen, uint8_t* pbtCrc);
|
||||
void crc_14a_calculate(uint8_t* pbtData, size_t szLen, uint8_t* pbtCrc);
|
||||
void crc_14a_append(uint8_t* pbtData, size_t szLen);
|
||||
void pcd_14a_reader_crc_computer(uint8_t use522CalcCRC);
|
||||
void pcd_14a_reader_crc_computer(uint8_t use522CalcCRC);
|
||||
|
||||
// other
|
||||
uint8_t cascade_to_cmd(uint8_t cascade);
|
||||
uint32_t get_u32_tag_uid(picc_14a_tag_t *tag);
|
||||
uint8_t* get_4byte_tag_uid(picc_14a_tag_t *tag, uint8_t *out);
|
||||
// other
|
||||
uint8_t cascade_to_cmd(uint8_t cascade);
|
||||
uint32_t get_u32_tag_uid(picc_14a_tag_t *tag);
|
||||
uint8_t* get_4byte_tag_uid(picc_14a_tag_t *tag, uint8_t *out);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4,119 +4,119 @@
|
||||
//向raw写入2bit数据,datab存0bit,dataa存1bit
|
||||
void writebit(uint8_t *dataa, uint8_t *datab, uint8_t pos, uint8_t adata)
|
||||
{
|
||||
if (adata >= 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = pos % 8;
|
||||
getbit(adata, 1) ? setbit(dataa[aimbyte], aimbit) : clrbit(dataa[aimbyte], aimbit);
|
||||
getbit(adata, 0) ? setbit(datab[aimbyte], aimbit) : clrbit(datab[aimbyte], aimbit);
|
||||
if (adata >= 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = pos % 8;
|
||||
getbit(adata, 1) ? setbit(dataa[aimbyte], aimbit) : clrbit(dataa[aimbyte], aimbit);
|
||||
getbit(adata, 0) ? setbit(datab[aimbyte], aimbit) : clrbit(datab[aimbyte], aimbit);
|
||||
}
|
||||
|
||||
//输出raw的2bit组合数据
|
||||
uint8_t readbit(uint8_t *dataa, uint8_t *datab, uint8_t pos)
|
||||
{
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = pos % 8;
|
||||
return (
|
||||
(getbit(dataa[aimbyte], aimbit) << 1) |
|
||||
(getbit(datab[aimbyte], aimbit)));
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = pos % 8;
|
||||
return (
|
||||
(getbit(dataa[aimbyte], aimbit) << 1) |
|
||||
(getbit(datab[aimbyte], aimbit)));
|
||||
}
|
||||
|
||||
//向raw写入2bit数据(大端方法,每个byte的第8位写数据的第1位),datab存0bit,dataa存1bit
|
||||
void writebit_msb(uint8_t *dataa, uint8_t *datab, uint8_t pos, uint8_t adata)
|
||||
{
|
||||
if (adata >= 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = 7 - (pos % 8);
|
||||
getbit(adata, 1) ? setbit(dataa[aimbyte], aimbit) : clrbit(dataa[aimbyte], aimbit);
|
||||
getbit(adata, 0) ? setbit(datab[aimbyte], aimbit) : clrbit(datab[aimbyte], aimbit);
|
||||
if (adata >= 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = 7 - (pos % 8);
|
||||
getbit(adata, 1) ? setbit(dataa[aimbyte], aimbit) : clrbit(dataa[aimbyte], aimbit);
|
||||
getbit(adata, 0) ? setbit(datab[aimbyte], aimbit) : clrbit(datab[aimbyte], aimbit);
|
||||
}
|
||||
|
||||
//输出raw的2bit组合数据(大端方法,每个byte的第8位读数据的第1位)
|
||||
uint8_t readbit_msb(uint8_t *dataa, uint8_t *datab, uint8_t pos)
|
||||
{
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = 7 - (pos % 8);
|
||||
return (
|
||||
(getbit(dataa[aimbyte], aimbit) << 1) |
|
||||
(getbit(datab[aimbyte], aimbit)));
|
||||
static uint8_t aimbyte = 0;
|
||||
static uint8_t aimbit = 0;
|
||||
aimbyte = pos / 8;
|
||||
aimbit = 7 - (pos % 8);
|
||||
return (
|
||||
(getbit(dataa[aimbyte], aimbit) << 1) |
|
||||
(getbit(datab[aimbyte], aimbit)));
|
||||
}
|
||||
|
||||
//高低位翻转
|
||||
uint8_t invert_num(uint8_t num)
|
||||
{
|
||||
uint8_t temp = 0, sh = 0xf;
|
||||
uint8_t i = 0;
|
||||
for (i = 0; i < sizeof(uint8_t); i++)
|
||||
{
|
||||
temp |= (num & (sh << ((sizeof(uint8_t) - 1 - i) << 2))) << ((i << 3) + 4);
|
||||
temp |= (num & (sh << ((sizeof(uint8_t) + i) << 2))) >> ((i << 3) + 4);
|
||||
}
|
||||
num = ((temp << 2) & 0xcccccccccccccccc) | ((temp >> 2) & 0x3333333333333333);
|
||||
num = ((num << 1) & 0xaaaaaaaaaaaaaaaa) | ((num >> 1) & 0x5555555555555555);
|
||||
uint8_t temp = 0, sh = 0xf;
|
||||
uint8_t i = 0;
|
||||
for (i = 0; i < sizeof(uint8_t); i++)
|
||||
{
|
||||
temp |= (num & (sh << ((sizeof(uint8_t) - 1 - i) << 2))) << ((i << 3) + 4);
|
||||
temp |= (num & (sh << ((sizeof(uint8_t) + i) << 2))) >> ((i << 3) + 4);
|
||||
}
|
||||
num = ((temp << 2) & 0xcccccccccccccccc) | ((temp >> 2) & 0x3333333333333333);
|
||||
num = ((num << 1) & 0xaaaaaaaaaaaaaaaa) | ((num >> 1) & 0x5555555555555555);
|
||||
|
||||
return num;
|
||||
return num;
|
||||
}
|
||||
|
||||
//原始数据转换为2倍长度的hex字符数组
|
||||
void ByteToHexStr(uint8_t *source, uint8_t *dest, uint8_t sourceLen)
|
||||
{
|
||||
uint8_t i, highByte, lowByte;
|
||||
uint8_t i, highByte, lowByte;
|
||||
|
||||
for (i = 0; i < sourceLen; i++)
|
||||
{
|
||||
highByte = source[i] >> 4;
|
||||
lowByte = source[i] & 0x0f;
|
||||
for (i = 0; i < sourceLen; i++)
|
||||
{
|
||||
highByte = source[i] >> 4;
|
||||
lowByte = source[i] & 0x0f;
|
||||
|
||||
highByte += 0x30;
|
||||
highByte += 0x30;
|
||||
|
||||
if (highByte > 0x39)
|
||||
dest[i * 2] = highByte + 0x07;
|
||||
else
|
||||
dest[i * 2] = highByte;
|
||||
if (highByte > 0x39)
|
||||
dest[i * 2] = highByte + 0x07;
|
||||
else
|
||||
dest[i * 2] = highByte;
|
||||
|
||||
lowByte += 0x30;
|
||||
if (lowByte > 0x39)
|
||||
dest[i * 2 + 1] = lowByte + 0x07;
|
||||
else
|
||||
dest[i * 2 + 1] = lowByte;
|
||||
}
|
||||
return;
|
||||
lowByte += 0x30;
|
||||
if (lowByte > 0x39)
|
||||
dest[i * 2 + 1] = lowByte + 0x07;
|
||||
else
|
||||
dest[i * 2 + 1] = lowByte;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void HexStrToByte(uint8_t *source, uint8_t *dest, uint8_t sourceLen)
|
||||
{
|
||||
uint8_t i, highByte, lowByte;
|
||||
uint8_t i, highByte, lowByte;
|
||||
|
||||
for (i = 0; i < sourceLen; i += 2)
|
||||
{
|
||||
highByte = toupper(source[i]);
|
||||
lowByte = toupper(source[i + 1]);
|
||||
for (i = 0; i < sourceLen; i += 2)
|
||||
{
|
||||
highByte = toupper(source[i]);
|
||||
lowByte = toupper(source[i + 1]);
|
||||
|
||||
if (highByte > 0x39)
|
||||
highByte -= 0x37;
|
||||
else
|
||||
highByte -= 0x30;
|
||||
if (highByte > 0x39)
|
||||
highByte -= 0x37;
|
||||
else
|
||||
highByte -= 0x30;
|
||||
|
||||
if (lowByte > 0x39)
|
||||
lowByte -= 0x37;
|
||||
else
|
||||
lowByte -= 0x30;
|
||||
if (lowByte > 0x39)
|
||||
lowByte -= 0x37;
|
||||
else
|
||||
lowByte -= 0x30;
|
||||
|
||||
dest[i / 2] = (highByte << 4) | lowByte;
|
||||
}
|
||||
return;
|
||||
dest[i / 2] = (highByte << 4) | lowByte;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
uint8_t (*(WATCH))[(LENG)] = (uint8_t (*)[(LENG)])(PDATA)
|
||||
#define DEBUG_READ_BREAK(WATCH) (*(WATCH))[0] = (*(WATCH))[0]
|
||||
|
||||
#define setbit(x,y) (x|=(1<<y))
|
||||
#define clrbit(x,y) (x&=~(1<<y))
|
||||
#define reversebit(x,y) (x^=(1<<y))
|
||||
#define getbit(x,y) ((x) >> (y)&1)
|
||||
#define setbit(x,y) (x|=(1<<y))
|
||||
#define clrbit(x,y) (x&=~(1<<y))
|
||||
#define reversebit(x,y) (x^=(1<<y))
|
||||
#define getbit(x,y) ((x) >> (y)&1)
|
||||
|
||||
void writebit(uint8_t *dataa, uint8_t *datab, uint8_t pos, uint8_t adata);
|
||||
uint8_t readbit(uint8_t *dataa, uint8_t *datab, uint8_t pos);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user