mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
typos & style
This commit is contained in:
@@ -185,24 +185,24 @@ data_frame_tx_t *cmd_processor_14a_scan(uint16_t cmd, uint16_t status, uint16_t
|
||||
}
|
||||
|
||||
data_frame_tx_t *cmd_processor_detect_mf1_support(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
status = Check_STDMifareNT_Support();
|
||||
status = check_std_mifare_nt_support();
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
}
|
||||
|
||||
data_frame_tx_t *cmd_processor_detect_mf1_nt_level(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
status = Check_WeakNested_Support();
|
||||
status = check_weak_nested_support();
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
}
|
||||
|
||||
data_frame_tx_t *cmd_processor_detect_mf1_darkside(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
status = Check_Darkside_Support();
|
||||
status = check_darkside_support();
|
||||
return data_frame_make(cmd, status, 0, NULL);
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
@@ -219,7 +219,7 @@ data_frame_tx_t *cmd_processor_mf1_darkside_acquire(uint16_t cmd, uint16_t statu
|
||||
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);
|
||||
status = nested_distance_detect(data[1], data[0], &data[2], &nd);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(NestedDist);
|
||||
data = (uint8_t *)(&nd);
|
||||
@@ -236,7 +236,7 @@ data_frame_tx_t *cmd_processor_detect_nested_dist(uint16_t cmd, uint16_t status,
|
||||
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);
|
||||
status = nested_distance_detect(data[1], data[0], &data[2], &nd);
|
||||
if (status == HF_TAG_OK) {
|
||||
length = sizeof(NestedDist);
|
||||
data = (uint8_t *)(&nd);
|
||||
@@ -253,7 +253,7 @@ data_frame_tx_t *cmd_processor_mf1_nt_distance(uint16_t cmd, uint16_t status, ui
|
||||
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);
|
||||
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);
|
||||
@@ -563,7 +563,7 @@ data_frame_tx_t *cmd_processor_set_mf1_anti_collision_res(uint16_t cmd, uint16_t
|
||||
} else {
|
||||
uint8_t uid_length = length - 3;
|
||||
if (is_valid_uid_size(uid_length)) {
|
||||
nfc_tag_14a_coll_res_referen_t *info = get_mifare_coll_res();
|
||||
nfc_tag_14a_coll_res_reference_t *info = get_mifare_coll_res();
|
||||
// copy sak
|
||||
info->sak[0] = data[0];
|
||||
// copy atqa
|
||||
@@ -758,7 +758,7 @@ data_frame_tx_t *before_reader_run(uint16_t cmd, uint16_t status, uint16_t lengt
|
||||
if (mode == DEVICE_MODE_READER) {
|
||||
return NULL;
|
||||
} else {
|
||||
return data_frame_make(cmd, STATUS_DEVIEC_MODE_ERROR, 0, NULL);
|
||||
return data_frame_make(cmd, STATUS_DEVICE_MODE_ERROR, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -878,14 +878,14 @@ void auto_response_data(data_frame_tx_t *resp) {
|
||||
if (is_usb_working()) {
|
||||
usb_cdc_write(resp->buffer, resp->length);
|
||||
} else if (is_nus_working()) {
|
||||
nus_data_reponse(resp->buffer, resp->length);
|
||||
nus_data_response(resp->buffer, resp->length);
|
||||
} else {
|
||||
NRF_LOG_ERROR("No connection valid found at response client.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for prcoess data frame(cmd)
|
||||
/**@brief Function to process data frame(cmd)
|
||||
*/
|
||||
void on_data_frame_received(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
data_frame_tx_t *response = NULL;
|
||||
@@ -922,7 +922,7 @@ void on_data_frame_received(uint16_t cmd, uint16_t status, uint16_t length, uint
|
||||
auto_response_data(response);
|
||||
}
|
||||
} else {
|
||||
// response cmd unsupport.
|
||||
// response cmd unsupported.
|
||||
response = data_frame_make(cmd, STATUS_INVALID_CMD, 0, NULL);
|
||||
auto_response_data(response);
|
||||
NRF_LOG_INFO("Data frame cmd invalid: %d,", cmd);
|
||||
|
||||
@@ -309,7 +309,7 @@ static void system_off_enter(void) {
|
||||
APP_ERROR_CHECK(ret);
|
||||
|
||||
// IOs that need to be configured as floating analog inputs ==> no pull-up or pull-down
|
||||
uint32_t gpio_cfg_default_nopull[] = {
|
||||
uint32_t gpio_cfg_default_no_pull[] = {
|
||||
#if defined(PROJECT_CHAMELEON_ULTRA)
|
||||
HF_SPI_SELECT,
|
||||
HF_SPI_MISO,
|
||||
@@ -319,8 +319,8 @@ static void system_off_enter(void) {
|
||||
#endif
|
||||
BAT_SENSE_PIN,
|
||||
};
|
||||
for (int i = 0; i < ARRAY_SIZE(gpio_cfg_default_nopull); i++) {
|
||||
nrf_gpio_cfg_default(gpio_cfg_default_nopull[i]);
|
||||
for (int i = 0; i < ARRAY_SIZE(gpio_cfg_default_no_pull); i++) {
|
||||
nrf_gpio_cfg_default(gpio_cfg_default_no_pull[i]);
|
||||
}
|
||||
|
||||
// IO that needs to be configured as a push-pull output and pulled high
|
||||
@@ -501,7 +501,7 @@ static void check_wakeup_src(void) {
|
||||
// usb plugged in can broadcast BLE at will
|
||||
advertising_start();
|
||||
} else {
|
||||
sleep_timer_start(SLEEP_DELAY_MS_FRIST_POWER); // Wait a while and go straight to hibernation, do nothing
|
||||
sleep_timer_start(SLEEP_DELAY_MS_FIRST_POWER); // Wait a while and go straight to hibernation, do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// 14a status
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#define HF_TAG_OK (0x00) // IC card operation successfully
|
||||
#define HF_TAG_OK (0x00) // IC card operation successful
|
||||
#define HF_TAG_NO (0x01) // No IC card found
|
||||
#define HF_ERR_STAT (0x02) // IC cartoon letter abnormal
|
||||
#define HF_ERR_CRC (0x03) // IC Card communication verification abnormality
|
||||
#define HF_ERR_STAT (0x02) // IC Card communication error
|
||||
#define HF_ERR_CRC (0x03) // IC Card communication verification error
|
||||
#define HF_COLLISION (0x04) // IC card conflict
|
||||
#define HF_ERR_BCC (0x05) // IC card BCC error
|
||||
#define MF_ERR_AUTH (0x06) // MF card verification failed
|
||||
#define HF_ERR_PARITY (0x07) // ica Kazi even verification error
|
||||
#define HF_ERR_BCC (0x05) // IC card BCC error
|
||||
#define MF_ERR_AUTH (0x06) // MF card verification failed
|
||||
#define HF_ERR_PARITY (0x07) // IC card parity error
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
@@ -37,7 +37,7 @@
|
||||
// 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_DEVIEC_MODE_ERROR (0x66) // The mode of the current device is wrong, and the corresponding API cannot be called
|
||||
#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_DEVICE_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
|
||||
|
||||
@@ -142,7 +142,7 @@ static void nus_data_handler(ble_nus_evt_t *p_evt) {
|
||||
}
|
||||
/**@snippet [Handling the data received over BLE] */
|
||||
|
||||
void nus_data_reponse(uint8_t *p_data, uint16_t length) {
|
||||
void nus_data_response(uint8_t *p_data, uint16_t length) {
|
||||
NRF_LOG_INFO("BLE nus service response data length: %d", length);
|
||||
NRF_LOG_HEXDUMP_DEBUG(p_data, length);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ extern uint8_t percentage_batt_lvl;
|
||||
|
||||
void ble_slave_init(void);
|
||||
void advertising_start(void);
|
||||
void nus_data_reponse(uint8_t *p_data, uint16_t length);
|
||||
void nus_data_response(uint8_t *p_data, uint16_t length);
|
||||
bool is_nus_working(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
/* End AVR specific */
|
||||
#else
|
||||
|
||||
/* Plattform independend code */
|
||||
/* Platform independent code */
|
||||
|
||||
#define SPLIT_BYTE(__even, __odd, __byte) \
|
||||
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
|
||||
@@ -143,9 +143,9 @@
|
||||
|
||||
#endif
|
||||
|
||||
/* Space/speed tradoff. */
|
||||
/* Space/speed trade-off. */
|
||||
/* We want speed, so we have to pay with size. */
|
||||
/* If we combine the A und B Filtertables and precalculate the values */
|
||||
/* If we combine the A and B filter tables and precalculate the values */
|
||||
/* for each state byte, we get the following tables which gives a */
|
||||
/* faster calculation of the filter output */
|
||||
/* Table of the filter A/B output per byte */
|
||||
@@ -314,7 +314,7 @@ static const uint8_t TableC3[32] = {
|
||||
|
||||
/* Split Crypto1 state into even and odd bits */
|
||||
/* to speed up the output filter network */
|
||||
/* Put both into one struct to enable relative adressing */
|
||||
/* Put both into one struct to enable relative addressing */
|
||||
typedef struct {
|
||||
uint8_t Even[LFSR_SIZE / 2];
|
||||
uint8_t Odd[LFSR_SIZE / 2];
|
||||
@@ -519,7 +519,7 @@ void Crypto1Setup(uint8_t Key[6], uint8_t Uid[4], uint8_t CardNonce[4]) {
|
||||
}
|
||||
|
||||
/* Setup LFSR split into odd and even states, feed in uid ^nonce */
|
||||
/* Vesion for nested authentication. */
|
||||
/* Version for nested authentication. */
|
||||
/* Also generates encrypted parity bits at CardNonce[4]..[7] */
|
||||
/* Use: Decrypt = false for the tag, Decrypt = true for the reader */
|
||||
void Crypto1SetupNested(uint8_t Key[6], uint8_t Uid[4], uint8_t CardNonce[4], uint8_t NonceParity[4], bool Decrypt) {
|
||||
@@ -722,7 +722,7 @@ void Crypto1Auth(uint8_t EncryptedReaderNonce[NONCE_SIZE]) {
|
||||
State.Odd[2] = Odd2;
|
||||
}
|
||||
|
||||
/* Crypto1Nibble generates keystrem for a nibble (4 bit) */
|
||||
/* Crypto1Nibble generates keystream for a nibble (4 bit) */
|
||||
/* no input to the LFSR */
|
||||
uint8_t Crypto1Nibble(void) {
|
||||
/* state registers */
|
||||
@@ -772,7 +772,7 @@ uint8_t Crypto1Nibble(void) {
|
||||
return (KeyStream);
|
||||
}
|
||||
|
||||
/* Crypto1Byte generates keystrem for a byte (8 bit) */
|
||||
/* Crypto1Byte generates keystream for a byte (8 bit) */
|
||||
/* no input to the LFSR */
|
||||
uint8_t Crypto1Byte(void) {
|
||||
/* state registers */
|
||||
@@ -850,10 +850,10 @@ uint8_t Crypto1Byte(void) {
|
||||
return (KeyStream);
|
||||
}
|
||||
|
||||
/* Crypto1ByteArray transcrypts array of bytes */
|
||||
/* No input to the LFSR */
|
||||
/* Avoids load/store of the LFSR-state for each byte! */
|
||||
/* Enhacement for the original function Crypto1Byte() */
|
||||
/* Crypto1ByteArray transcripts array of bytes */
|
||||
/* No input to the LFSR */
|
||||
/* Avoids load/store of the LFSR-state for each byte! */
|
||||
/* Enhancement for the original function Crypto1Byte() */
|
||||
void Crypto1ByteArray(uint8_t *Buffer, uint8_t Count) {
|
||||
/* state registers */
|
||||
register uint8_t Even0, Even1, Even2;
|
||||
@@ -920,7 +920,7 @@ void Crypto1ByteArray(uint8_t *Buffer, uint8_t Count) {
|
||||
Feedback = Crypto1LFSRbyteFeedback(Odd0, Odd1, Odd2, Even0, Even1, Even2);
|
||||
SHIFT24(Odd0, Odd1, Odd2, Feedback);
|
||||
|
||||
/* Transcrypt and increment buffer address */
|
||||
/* Transcript and increment buffer address */
|
||||
*Buffer++ ^= KeyStream;
|
||||
}
|
||||
|
||||
@@ -1128,10 +1128,10 @@ void Crypto1ByteArrayWithParityHasIn(uint8_t *Buffer, uint8_t *Parity, uint8_t C
|
||||
}
|
||||
|
||||
/* Function Crypto1PRNG */
|
||||
/* New version of the PRNG wich can calculate multiple */
|
||||
/* New version of the PRNG which can calculate multiple */
|
||||
/* feedback bits at once! */
|
||||
/* Feedback mask = 0x2d = 101101 binary */
|
||||
/* Because pattern 101 is repeated, only 2 shifts are neccessary! */
|
||||
/* Because pattern 101 is repeated, only 2 shifts are necessary! */
|
||||
/* Feedback ^= Feedback >> 3; folds 101 101 to 101 */
|
||||
/* Feedback ^= Feedback >> 2; folds 101 => 1 */
|
||||
/* With these two lines not only bit 0 is calculated, */
|
||||
|
||||
@@ -41,7 +41,7 @@ nfc_tag_14a_state_t m_tag_state_14a = NFC_TAG_STATE_14A_IDLE;
|
||||
|
||||
// 14443A protocol processor
|
||||
nfc_tag_14a_handler_t m_tag_handler = {
|
||||
.cb_reset = NULL, // Tag Resetback
|
||||
.cb_reset = NULL, // Tag Reset callback
|
||||
.cb_state = NULL, // Label status machine callback
|
||||
.get_coll_res = NULL, // Obtain packaging of anti -conflict resources of labels
|
||||
};
|
||||
@@ -143,15 +143,15 @@ bool nfc_tag_14a_checks_crc(uint8_t *pbtData, size_t szLen) {
|
||||
/**
|
||||
* @brief : Bit frames for packaging ISO14443A
|
||||
* Automatically conduct the merger of the parity of the coupling school and the data of the data
|
||||
* @param pbtTx: Bit flow to be transmitted
|
||||
* szTxBits: The length of the bandwing
|
||||
* pbtTxPar: Bit flow of the puppet school inspection, the length of this data must be sztxbits / 8, that is,
|
||||
* In fact, the composition of the bit flow after the merger is:
|
||||
* @param pbtTx: bitstream to be transmitted
|
||||
* szTxBits: The length of the buffer
|
||||
* pbtTxPar: bitstream of the puppet school inspection, the length of this data must be szTxBits / 8, that is,
|
||||
* In fact, the composition of the bitstream after the merger is:
|
||||
* data(1byte) - par(1bit) - data(1byte) - par(1bit) ...
|
||||
* 00001000 - 0 - 10101110 - 1
|
||||
* This similar data structure
|
||||
* pbtFrame: The final assembled data buffer
|
||||
* @retval :The length of the bit flow assembly results buffer. Note that it is the length of the bit.
|
||||
* @retval :The length of the bitstream assembly results buffer. Note that it is the length of the bit.
|
||||
*/
|
||||
uint8_t nfc_tag_14a_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtFrame) {
|
||||
uint8_t btData;
|
||||
@@ -209,11 +209,11 @@ uint8_t nfc_tag_14a_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, cons
|
||||
/**
|
||||
* @brief :Bit frame of ISO14443A
|
||||
* Automatically perform the unpacking of the puppet school inspection and the data
|
||||
* @param :pbtFrame:Bit flow that will be dismissed
|
||||
* szFrameBits:The length of the bandwing
|
||||
* @param :pbtFrame: bitstream that will be dismissed
|
||||
* szFrameBits:The length of the buffer
|
||||
* pbtRx:Caps, data areas, data areas, data areas, data areas, data areas.
|
||||
* pbtRxPar: The buffer of the Bitflow Store after the packaging, the coupling school inspection area
|
||||
* @retval :The data length of the Bit flow packaging, note that the length of the data area is the length of the data area.retval / 8
|
||||
* pbtRxPar: The buffer of the bitstream Store after the packaging, the coupling school inspection area
|
||||
* @retval :The data length of the bitstream packaging, note that the length of the data area is the length of the data area.retval / 8
|
||||
*/
|
||||
uint8_t nfc_tag_14a_unwrap_frame(const uint8_t *pbtFrame, const size_t szFrameBits, uint8_t *pbtRx, uint8_t *pbtRxPar) {
|
||||
uint8_t btFrame;
|
||||
@@ -262,7 +262,7 @@ uint8_t nfc_tag_14a_unwrap_frame(const uint8_t *pbtFrame, const size_t szFrameBi
|
||||
}
|
||||
|
||||
/**
|
||||
* @briedf: Function for response reader core implemented
|
||||
* @brief: Function for response reader core implemented
|
||||
* @param[in] data Send data buffer
|
||||
* @param[in] bytes Send data length
|
||||
* @param[in] appendCrc Auto append crc
|
||||
@@ -309,7 +309,7 @@ void nfc_tag_14a_tx_bytes_delay_freerun(uint8_t *data, uint32_t bytes, bool appe
|
||||
}
|
||||
|
||||
/**
|
||||
* @briedf: Function for response reader core implemented
|
||||
* @brief: Function for response reader core implemented
|
||||
* @param[in] bits Send bits length
|
||||
* @param[in] mode communication mode
|
||||
*
|
||||
@@ -361,10 +361,10 @@ void nfc_tag_14a_tx_nbit_delay_window(uint8_t data, uint32_t bits) {
|
||||
* 14A monitoring the packaging function of data processing from PCD
|
||||
*/
|
||||
void nfc_tag_14a_data_process(uint8_t *p_data) {
|
||||
// Statistize the number of bit currently received
|
||||
// Compute the number of bits currently received
|
||||
uint16_t szDataBits = (NRF_NFCT->RXD.AMOUNT & (NFCT_RXD_AMOUNT_RXDATABITS_Msk | NFCT_RXD_AMOUNT_RXDATABYTES_Msk));
|
||||
// The resource that may be used in anti -collision
|
||||
nfc_tag_14a_coll_res_referen_t *auto_coll_res = m_tag_handler.get_coll_res != NULL ? m_tag_handler.get_coll_res() : NULL;
|
||||
nfc_tag_14a_coll_res_reference_t *auto_coll_res = m_tag_handler.get_coll_res != NULL ? m_tag_handler.get_coll_res() : NULL;
|
||||
|
||||
// I don't know why, here the CPU must run empty for a period of time before the data can be received normally.
|
||||
// If you have any problems with the receiving data, please try to restore this. This is a problem found in 2021, but it disappeared again in 2022
|
||||
@@ -391,7 +391,7 @@ void nfc_tag_14a_data_process(uint8_t *p_data) {
|
||||
// We may receive a Wupa or REQA instruction, or other special instructions
|
||||
bool isREQA = (p_data[0] == NFC_TAG_14A_CMD_REQA);
|
||||
bool isWUPA = (p_data[0] == NFC_TAG_14A_CMD_WUPA);
|
||||
// The trigger conditions are: Reqa response in non -Halt mode
|
||||
// The trigger conditions are: REQA response in non -Halt mode
|
||||
// Temporary through: Wupa response in non -choice state, no matter what state is in the state, you can use the Wupa instruction to wake up
|
||||
if ((szDataBits == 7) && ((isREQA && m_tag_state_14a != NFC_TAG_STATE_14A_HALTED) || isWUPA)) {
|
||||
// The receiver of the 14A communication is notified, the internal state machine is reset
|
||||
@@ -414,7 +414,7 @@ void nfc_tag_14a_data_process(uint8_t *p_data) {
|
||||
// TODOHere you can match some other instructions, call back some registered processing functions to handle this logic separately
|
||||
// Normal communication process will not have N bits of frames, because it is the anti -conflict frame used in the 14A protocol for BIT
|
||||
// So you can handle this protocol frame separately here to realize the tag similar to the UID back door card (Chinese Magic)
|
||||
// Note that if we find Reqa or wupa, we will not repeat the processing (only the special ratio special frame)
|
||||
// Note that if we find REQA or WUPA, we will not repeat the processing (only the special ratio special frame)
|
||||
if ((!isREQA && !isWUPA) && m_tag_handler.cb_state != NULL) {
|
||||
// If the 7bit processor is registered and successfully processed this command, the state machine update is completed
|
||||
m_tag_handler.cb_state(p_data, szDataBits);
|
||||
@@ -542,7 +542,7 @@ void nfc_tag_14a_data_process(uint8_t *p_data) {
|
||||
// NRF_LOG_INFO("[MFEMUL_SELECT] Unknown selection procedure");
|
||||
break;
|
||||
}
|
||||
// Activation status, repost processing of any message
|
||||
// Activation status, re-post processing of any message
|
||||
case NFC_TAG_STATE_14A_ACTIVE: {
|
||||
// You need to judge whether you have received instructions that need to be handled directly without forwarding
|
||||
if (szDataBits == 32) {
|
||||
@@ -569,7 +569,7 @@ void nfc_tag_14a_data_process(uint8_t *p_data) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// No processing is successful, it may be some other data. You need to repost processing
|
||||
// No processing is successful, it may be some other data. You need to re-post processing
|
||||
if (m_tag_handler.cb_state != NULL) { //Activation status, transfer the message to other registered processor processing
|
||||
m_tag_handler.cb_state(p_data, szDataBits);
|
||||
break;
|
||||
@@ -639,7 +639,7 @@ void nfc_tag_14a_event_callback(nrfx_nfct_evt_t const *p_event) {
|
||||
|
||||
// NRF_LOG_INFO("RX FRAMEEND.\n");
|
||||
// TODO Remember a bug, if you do not reply to the message after receiving the message, you need to manually enable you
|
||||
// Otherwise, the nrfx_nfct_evt_tx_framend conditions above will not be triggered, and nrfx_nfct_rx_bytes will not be called
|
||||
// Otherwise, the nrfx_nfct_evt_tx_frameend conditions above will not be triggered, and nrfx_nfct_rx_bytes will not be called
|
||||
// All the next communication will have problems. How can I play if there is a problem? Play an egg.
|
||||
m_is_responded = false;
|
||||
// One more layer of pressure stack, but it seems to have little effect on performance
|
||||
@@ -671,7 +671,7 @@ void nfc_tag_14a_event_callback(nrfx_nfct_evt_t const *p_event) {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
NRF_LOG_INFO("No NFCT Event processer: %d\n", p_event->evt_id);
|
||||
NRF_LOG_INFO("No NFCT Event processor: %d\n", p_event->evt_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ typedef enum {
|
||||
NFC_TAG_STATE_14A_HALTED, // The label stops working status and can only be awakened by Halt or other special instructions (non -labels)
|
||||
} nfc_tag_14a_state_t;
|
||||
|
||||
//UID of the length in the enumeration specification
|
||||
// UID of the length in the enumeration specification
|
||||
typedef enum {
|
||||
NFC_TAG_14A_UID_SINGLE_SIZE = 4u, ///< Length of single-size NFCID1.
|
||||
NFC_TAG_14A_UID_DOUBLE_SIZE = 7u, ///< Length of double-size NFCID1.
|
||||
NFC_TAG_14A_UID_TRIPLE_SIZE = 10u, ///< Length of triple-size NFCID1.
|
||||
} nfc_tag_14a_uid_size;
|
||||
|
||||
// Extraordinarian level level level level level
|
||||
// Cascade levels
|
||||
typedef enum {
|
||||
NFC_TAG_14A_CASCADE_LEVEL_1,
|
||||
NFC_TAG_14A_CASCADE_LEVEL_2,
|
||||
@@ -78,12 +78,12 @@ typedef struct {
|
||||
uint8_t *sak;
|
||||
uint8_t *uid;
|
||||
nfc_14a_ats_t *ats;
|
||||
} nfc_tag_14a_coll_res_referen_t;
|
||||
} nfc_tag_14a_coll_res_reference_t;
|
||||
|
||||
// Communication reception function that needs to be implemented
|
||||
typedef void (*nfc_tag_14a_reset_handler_t)(void);
|
||||
typedef void (*nfc_tag_14a_state_handler_t)(uint8_t *data, uint16_t szBits);
|
||||
typedef nfc_tag_14a_coll_res_referen_t *(*nfc_tag_14a_coll_handler_t)(void);
|
||||
typedef nfc_tag_14a_coll_res_reference_t *(*nfc_tag_14a_coll_handler_t)(void);
|
||||
|
||||
// The interface that 14A communication receiver needs to be implemented
|
||||
typedef struct {
|
||||
|
||||
@@ -32,7 +32,7 @@ NRF_LOG_MODULE_REGISTER();
|
||||
/* NXP Originality check */
|
||||
/* Sector 18/Block 68..71 is used to store signature data for NXP originality check */
|
||||
#define MEM_EV1_SIGNATURE_BLOCK 68
|
||||
#define MEM_EV1_SIGNATURE_TRAILOR ((MEM_EV1_SIGNATURE_BLOCK + 3 ) * MEM_BYTES_PER_BLOCK)
|
||||
#define MEM_EV1_SIGNATURE_TRAILER ((MEM_EV1_SIGNATURE_BLOCK + 3 ) * MEM_BYTES_PER_BLOCK)
|
||||
|
||||
|
||||
#define CMD_AUTH_A 0x60
|
||||
@@ -81,12 +81,12 @@ C1 C2 C3 read write read write read write
|
||||
|
||||
[1] For this access condition key B is readable and may be used for data
|
||||
*/
|
||||
#define ACC_TRAILOR_READ_KEYA 0x01
|
||||
#define ACC_TRAILOR_WRITE_KEYA 0x02
|
||||
#define ACC_TRAILOR_READ_ACC 0x04
|
||||
#define ACC_TRAILOR_WRITE_ACC 0x08
|
||||
#define ACC_TRAILOR_READ_KEYB 0x10
|
||||
#define ACC_TRAILOR_WRITE_KEYB 0x20
|
||||
#define ACC_TRAILER_READ_KEYA 0x01
|
||||
#define ACC_TRAILER_WRITE_KEYA 0x02
|
||||
#define ACC_TRAILER_READ_ACC 0x04
|
||||
#define ACC_TRAILER_WRITE_ACC 0x08
|
||||
#define ACC_TRAILER_READ_KEYB 0x10
|
||||
#define ACC_TRAILER_WRITE_KEYB 0x20
|
||||
|
||||
|
||||
|
||||
@@ -116,74 +116,74 @@ C1 C2 C3 read write increment decrement,
|
||||
#define KEY_B 1
|
||||
|
||||
|
||||
/* Decoding table for Access conditions of the sector trailor */
|
||||
static const uint8_t abTrailorAccessConditions[8][2] = {
|
||||
/* Decoding table for Access conditions of the sector trailer */
|
||||
static const uint8_t abTrailerAccessConditions[8][2] = {
|
||||
/* 0 0 0 RdKA:never WrKA:key A RdAcc:key A WrAcc:never RdKB:key A WrKB:key A Key B may be read[1] */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_WRITE_KEYA | ACC_TRAILOR_READ_ACC | ACC_TRAILOR_WRITE_ACC | ACC_TRAILOR_READ_KEYB | ACC_TRAILOR_WRITE_KEYB,
|
||||
ACC_TRAILER_WRITE_KEYA | ACC_TRAILER_READ_ACC | ACC_TRAILER_WRITE_ACC | ACC_TRAILER_READ_KEYB | ACC_TRAILER_WRITE_KEYB,
|
||||
/* Access with Key B */
|
||||
0
|
||||
},
|
||||
/* 1 0 0 RdKA:never WrKA:key B RdAcc:keyA|B WrAcc:never RdKB:never WrKB:key B */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_READ_ACC,
|
||||
ACC_TRAILER_READ_ACC,
|
||||
/* Access with Key B */
|
||||
ACC_TRAILOR_WRITE_KEYA | ACC_TRAILOR_READ_ACC | ACC_TRAILOR_WRITE_KEYB
|
||||
ACC_TRAILER_WRITE_KEYA | ACC_TRAILER_READ_ACC | ACC_TRAILER_WRITE_KEYB
|
||||
},
|
||||
/* 0 1 0 RdKA:never WrKA:never RdAcc:key A WrAcc:never RdKB:key A WrKB:never Key B may be read[1] */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_READ_ACC | ACC_TRAILOR_READ_KEYB,
|
||||
ACC_TRAILER_READ_ACC | ACC_TRAILER_READ_KEYB,
|
||||
/* Access with Key B */
|
||||
0
|
||||
},
|
||||
/* 1 1 0 never never keyA|B never never never */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_READ_ACC,
|
||||
ACC_TRAILER_READ_ACC,
|
||||
/* Access with Key B */
|
||||
ACC_TRAILOR_READ_ACC
|
||||
ACC_TRAILER_READ_ACC
|
||||
},
|
||||
/* 0 0 1 never key A key A key A key A key A Key B may be read,transport configuration[1] */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_WRITE_KEYA | ACC_TRAILOR_READ_ACC | ACC_TRAILOR_WRITE_ACC | ACC_TRAILOR_READ_KEYB | ACC_TRAILOR_WRITE_KEYB,
|
||||
ACC_TRAILER_WRITE_KEYA | ACC_TRAILER_READ_ACC | ACC_TRAILER_WRITE_ACC | ACC_TRAILER_READ_KEYB | ACC_TRAILER_WRITE_KEYB,
|
||||
/* Access with Key B */
|
||||
0
|
||||
},
|
||||
/* 0 1 1 never key B keyA|B key B never key B */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_READ_ACC,
|
||||
ACC_TRAILER_READ_ACC,
|
||||
/* Access with Key B */
|
||||
ACC_TRAILOR_WRITE_KEYA | ACC_TRAILOR_READ_ACC | ACC_TRAILOR_WRITE_ACC | ACC_TRAILOR_WRITE_KEYB
|
||||
ACC_TRAILER_WRITE_KEYA | ACC_TRAILER_READ_ACC | ACC_TRAILER_WRITE_ACC | ACC_TRAILER_WRITE_KEYB
|
||||
},
|
||||
/* 1 0 1 never never keyA|B key B never never */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_READ_ACC,
|
||||
ACC_TRAILER_READ_ACC,
|
||||
/* Access with Key B */
|
||||
ACC_TRAILOR_READ_ACC | ACC_TRAILOR_WRITE_ACC
|
||||
ACC_TRAILER_READ_ACC | ACC_TRAILER_WRITE_ACC
|
||||
},
|
||||
/* 1 1 1 never never keyA|B never never never */
|
||||
{
|
||||
/* Access with Key A */
|
||||
ACC_TRAILOR_READ_ACC,
|
||||
ACC_TRAILER_READ_ACC,
|
||||
/* Access with Key B */
|
||||
ACC_TRAILOR_READ_ACC
|
||||
ACC_TRAILER_READ_ACC
|
||||
},
|
||||
};
|
||||
|
||||
// Save the current MF1 standard status
|
||||
static nfc_tag_mf1_std_state_machine_t m_mf1_state = MF1_STATE_UNAUTH;
|
||||
static nfc_tag_mf1_std_state_machine_t m_mf1_state = MF1_STATE_UNAUTHENTICATED;
|
||||
// Save the current GEN1A status
|
||||
static nfc_tag_mf1_gen1a_state_machine_t m_gen1a_state = GEN1A_STATE_DISABLE;
|
||||
// Data structure pointer to the label information
|
||||
static nfc_tag_mf1_information_t *m_tag_information = NULL;
|
||||
// Define and use shadow anti -collision resources
|
||||
static nfc_tag_14a_coll_res_referen_t m_shadow_coll_res;
|
||||
static nfc_tag_14a_coll_res_reference_t m_shadow_coll_res;
|
||||
//Pind to the tail block in the label sector (control data block)
|
||||
static nfc_tag_mf1_trailer_info_t *m_tag_trailer_info = NULL;
|
||||
// Define and use MF1 special communication buffer
|
||||
@@ -344,7 +344,7 @@ void append_mf1_auth_log_step1(bool isKeyB, bool isNested, uint8_t block, uint8_
|
||||
}
|
||||
// Determine whether this card slot enables the detection log record
|
||||
if (m_tag_information->config.detection_enable) {
|
||||
m_auth_log.logs[m_auth_log.count].cmd.is_keyb = isKeyB;
|
||||
m_auth_log.logs[m_auth_log.count].cmd.is_key_b = isKeyB;
|
||||
m_auth_log.logs[m_auth_log.count].cmd.block = block;
|
||||
m_auth_log.logs[m_auth_log.count].cmd.is_nested = isNested;
|
||||
memcpy(m_auth_log.logs[m_auth_log.count].uid, UID_BY_CASCADE_LEVEL, 4);
|
||||
@@ -430,7 +430,7 @@ void mf1_prng_by_bytes(uint8_t *nonces, uint32_t n) {
|
||||
|
||||
/** @brief MF1 status machine
|
||||
* @param data From reading head data
|
||||
* @param szBits Pittering length of data
|
||||
* @param szBits length of data
|
||||
* @param state Finite State Machine
|
||||
*/
|
||||
void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
@@ -449,7 +449,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
// NRF_LOG_INFO("MIFARE_MAGICWUPC2 received.\n");
|
||||
nfc_tag_14a_set_state(NFC_TAG_STATE_14A_ACTIVE); //Update the status machine of the external 14A
|
||||
m_gen1a_state = GEN1A_STATE_UNLOCKED_RW_WAIT; // Update the Gen1A status machine
|
||||
m_mf1_state = MF1_STATE_UNAUTH; // Update MF1 status machine
|
||||
m_mf1_state = MF1_STATE_UNAUTHENTICATED; // Update MF1 status machine
|
||||
nfc_tag_14a_tx_nbit_delay_window(ACK_VALUE, 4); //Reply to the card reader Gen1a label unlock the back door success
|
||||
#ifndef NFC_MF1_FAST_SIM
|
||||
crypto1_deinit(pcs); // Reset crypto1 handler
|
||||
@@ -466,7 +466,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
|
||||
// Processing MiFare's status machine
|
||||
switch (m_mf1_state) {
|
||||
case MF1_STATE_UNAUTH: { // Unparalleled state, communication is open
|
||||
case MF1_STATE_UNAUTHENTICATED: { // Unparalleled state, communication is open
|
||||
if (szDataBits == 32) { // 32 -bit, may be instructions
|
||||
if (nfc_tag_14a_checks_crc(p_data, 4)) {
|
||||
switch (p_data[0]) {
|
||||
@@ -494,7 +494,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Set keyinuse as global use to retain information about identity verification
|
||||
// Set KeyInUse as global use to retain information about identity verification
|
||||
KeyInUse = p_data[0] & 1;
|
||||
|
||||
// Obtain the specified sector access control bytes. Here we directly take the coincidence, convert the memory into a structure, and let the compiler help us maintain the pointing of the pointer
|
||||
@@ -527,7 +527,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
append_mf1_auth_log_step1(KeyInUse, false, BlockAuth, CardNonce);
|
||||
|
||||
// Use random card random numbers to respond, and hopes to obtain further authentication from the reader in the next frame.
|
||||
m_mf1_state = MF1_STATE_AUTHING;
|
||||
m_mf1_state = MF1_STATE_AUTHENTICATING;
|
||||
|
||||
// The first verification, responding to a clear random number, without CRC
|
||||
m_tag_tx_buffer.tx_raw_buffer[0] = CardNonce[0];
|
||||
@@ -538,7 +538,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
#ifdef NFC_MF1_FAST_SIM
|
||||
Crypto1Setup(
|
||||
// Select A or B secrets based on the current instruction type
|
||||
KeyInUse ? m_tag_trailer_info->keyb : m_tag_trailer_info->keya,
|
||||
KeyInUse ? m_tag_trailer_info->key_b : m_tag_trailer_info->key_a,
|
||||
// Passing the current anti -collision UID
|
||||
UID_BY_CASCADE_LEVEL,
|
||||
// Passing into a clear random number, this random number will be used to decrypt subsequent communication
|
||||
@@ -550,7 +550,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
// Load key flow
|
||||
crypto1_init(pcs,
|
||||
// Select A or B secrets based on the current instruction type
|
||||
bytes_to_num(KeyInUse ? m_tag_trailer_info->keyb : m_tag_trailer_info->keya, 6)
|
||||
bytes_to_num(KeyInUse ? m_tag_trailer_info->key_b : m_tag_trailer_info->key_a, 6)
|
||||
);
|
||||
// Set key flow
|
||||
crypto1_word(pcs, bytes_to_num(UID_BY_CASCADE_LEVEL, 4) ^ bytes_to_num(CardNonce, 4), 0);
|
||||
@@ -618,7 +618,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MF1_STATE_AUTHING: {
|
||||
case MF1_STATE_AUTHENTICATING: {
|
||||
if (szDataBits == 64) {
|
||||
//NR + AR responded to the card reader
|
||||
append_mf1_auth_log_step2(p_data, &p_data[4]);
|
||||
@@ -649,7 +649,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
mf_crypto1_encrypt(pcs, m_tag_tx_buffer.tx_raw_buffer, 4, m_tag_tx_buffer.tx_bit_parity);
|
||||
#endif
|
||||
// The verification is successful, and you need to enter the state that has been successfully verified
|
||||
m_mf1_state = MF1_STATE_AUTHED;
|
||||
m_mf1_state = MF1_STATE_AUTHENTICATED;
|
||||
// Package, stitch the Qiqi school inspection, return
|
||||
m_tag_tx_buffer.tx_frame_bit_size = nfc_tag_14a_wrap_frame(m_tag_tx_buffer.tx_raw_buffer, 32, m_tag_tx_buffer.tx_bit_parity, m_tag_tx_buffer.tx_warp_frame);
|
||||
nfc_tag_14a_tx_bits(m_tag_tx_buffer.tx_warp_frame, m_tag_tx_buffer.tx_frame_bit_size);
|
||||
@@ -667,7 +667,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MF1_STATE_AUTHED: {
|
||||
case MF1_STATE_AUTHENTICATED: {
|
||||
if (szDataBits == 32) {
|
||||
// In this state, all communication is encrypted.Therefore, we must first decrypt the data sent by the read head.
|
||||
#ifdef NFC_MF1_FAST_SIM
|
||||
@@ -682,7 +682,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
// Save the block address of the current operation
|
||||
CurrentAddress = p_data[1];
|
||||
// Generate access control, for data access control below
|
||||
uint8_t Acc = abTrailorAccessConditions[ GetAccessCondition(CurrentAddress) ][ KeyInUse ];
|
||||
uint8_t Acc = abTrailerAccessConditions[ GetAccessCondition(CurrentAddress) ][ KeyInUse ];
|
||||
// Read the command.Read data from memory and add CRCA.Note: Reading operations are limited by the control bit, but at present we only restrict the reading of the control bit
|
||||
if ((CurrentAddress < 128 && (CurrentAddress & 3) == 3) || ((CurrentAddress & 15) == 15)) {
|
||||
// Clear the buffer to avoid the cache data that affect the follow -up operation
|
||||
@@ -695,14 +695,14 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
// 3. Make the restrictions of the control position reading according to the access conditions of the read during authentication!
|
||||
respTrailerInfo->acs[3] = m_tag_trailer_info->acs[3];
|
||||
// Determine whether the control position itself allows reading
|
||||
if (Acc & ACC_TRAILOR_READ_ACC) {
|
||||
if (Acc & ACC_TRAILER_READ_ACC) {
|
||||
respTrailerInfo->acs[0] = m_tag_trailer_info->acs[0];
|
||||
respTrailerInfo->acs[1] = m_tag_trailer_info->acs[1];
|
||||
respTrailerInfo->acs[2] = m_tag_trailer_info->acs[2];
|
||||
}
|
||||
// In a few cases, the Secret B is readable
|
||||
if (Acc & ACC_TRAILOR_READ_KEYB) {
|
||||
memcpy(respTrailerInfo->keyb, m_tag_trailer_info->keyb, 6);
|
||||
if (Acc & ACC_TRAILER_READ_KEYB) {
|
||||
memcpy(respTrailerInfo->key_b, m_tag_trailer_info->key_b, 6);
|
||||
}
|
||||
} else {
|
||||
// For data, just return to the corresponding location sector
|
||||
@@ -823,7 +823,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Set keyinuse as global use to retain information about identity verification
|
||||
// Set KeyInUse as global use to retain information about identity verification
|
||||
KeyInUse = p_data[0] & 1;
|
||||
|
||||
// Obtain the specified sector access control bytes. Here we directly take the coincidence, convert the memory into a structure, and let the compiler help us maintain the pointing of the pointer
|
||||
@@ -856,7 +856,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
append_mf1_auth_log_step1(KeyInUse, true, BlockAuth, CardNonce);
|
||||
|
||||
//Use random card random numbers to respond, and hopes to obtain further authentication from the reader in the next frame.
|
||||
m_mf1_state = MF1_STATE_AUTHING;
|
||||
m_mf1_state = MF1_STATE_AUTHENTICATING;
|
||||
|
||||
// Copy a random number of a label to the buffer area
|
||||
m_tag_tx_buffer.tx_raw_buffer[0] = CardNonce[0];
|
||||
@@ -868,7 +868,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
/* Setup crypto1 cipher. Discard in-place encrypted CardNonce. */
|
||||
Crypto1SetupNested(
|
||||
// Select A or B secrets based on the current instruction type
|
||||
KeyInUse ? m_tag_trailer_info->keyb : m_tag_trailer_info->keya,
|
||||
KeyInUse ? m_tag_trailer_info->key_b : m_tag_trailer_info->key_a,
|
||||
// Passing the current anti -collision UID
|
||||
UID_BY_CASCADE_LEVEL,
|
||||
// Passing into a clear random number, this random number will be encrypted and passed through this buffer area
|
||||
@@ -885,7 +885,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
//Load key flow
|
||||
crypto1_init(pcs,
|
||||
// Select A or B secrets based on the current instruction type
|
||||
bytes_to_num(KeyInUse ? m_tag_trailer_info->keyb : m_tag_trailer_info->keya, 6)
|
||||
bytes_to_num(KeyInUse ? m_tag_trailer_info->key_b : m_tag_trailer_info->key_a, 6)
|
||||
);
|
||||
// Random number encryption
|
||||
uint8_t m_auth_nt_keystream[4];
|
||||
@@ -971,7 +971,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
status = NAK_CRC_PARITY_ERROR_TBIV;
|
||||
}
|
||||
// In any case, after the operation, the label will be allowed to return to the verification idle state
|
||||
m_mf1_state = MF1_STATE_AUTHED;
|
||||
m_mf1_state = MF1_STATE_AUTHENTICATED;
|
||||
#ifdef NFC_MF1_FAST_SIM
|
||||
nfc_tag_14a_tx_nbit(status ^ Crypto1Nibble(), 4);
|
||||
#else
|
||||
@@ -1028,7 +1028,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
// The length is wrong, but it is counted in the CRC error
|
||||
status = NAK_CRC_PARITY_ERROR_TBIV;
|
||||
}
|
||||
m_mf1_state = MF1_STATE_AUTHED;
|
||||
m_mf1_state = MF1_STATE_AUTHENTICATED;
|
||||
#ifdef NFC_MF1_FAST_SIM
|
||||
nfc_tag_14a_tx_nbit(status ^ Crypto1Nibble(), 4);
|
||||
#else
|
||||
@@ -1048,7 +1048,7 @@ void nfc_tag_mf1_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
/**
|
||||
* @brief Provide the necessary anti -conflict resources for the MiFare label (only pointer provides pointers)
|
||||
*/
|
||||
nfc_tag_14a_coll_res_referen_t *get_mifare_coll_res() {
|
||||
nfc_tag_14a_coll_res_reference_t *get_mifare_coll_res() {
|
||||
//According to the current interoperability configuration, selectively return the configuration data to selectively, assuming that the data interoperability is turned on, then we also need to ensure that the current simulation card is 4BYTE
|
||||
if (m_tag_information->config.use_mf1_coll_res && m_tag_information->res_coll.size == NFC_TAG_14A_UID_SINGLE_SIZE) {
|
||||
// Manufacturer information obtained by the data area
|
||||
@@ -1074,7 +1074,7 @@ nfc_tag_14a_coll_res_referen_t *get_mifare_coll_res() {
|
||||
* @brief Reconcile when the parameter label needs to be reset
|
||||
*/
|
||||
void nfc_tag_mf1_reset_handler() {
|
||||
m_mf1_state = MF1_STATE_UNAUTH;
|
||||
m_mf1_state = MF1_STATE_UNAUTHENTICATED;
|
||||
m_gen1a_state = GEN1A_STATE_DISABLE;
|
||||
|
||||
#ifndef NFC_MF1_FAST_SIM
|
||||
|
||||
@@ -31,9 +31,9 @@ typedef enum {
|
||||
// MF1 label standard mode state machine
|
||||
typedef enum {
|
||||
// Verification state machine
|
||||
MF1_STATE_UNAUTH,
|
||||
MF1_STATE_AUTHING,
|
||||
MF1_STATE_AUTHED,
|
||||
MF1_STATE_UNAUTHENTICATED,
|
||||
MF1_STATE_AUTHENTICATING,
|
||||
MF1_STATE_AUTHENTICATED,
|
||||
|
||||
// Operating state machine
|
||||
MF1_STATE_WRITE,
|
||||
@@ -86,7 +86,7 @@ typedef struct __attribute__((aligned(4))) {
|
||||
}
|
||||
nfc_tag_mf1_information_t;
|
||||
|
||||
// 4 -earte card's 0 block structure of factory solidification
|
||||
// Manufacturer block structure
|
||||
typedef struct {
|
||||
// For example:
|
||||
// 30928E04 28 08 0400 0177A2CC35AFA51D
|
||||
@@ -99,9 +99,9 @@ typedef struct {
|
||||
|
||||
// General MF1 sector rear block data structure
|
||||
typedef struct {
|
||||
uint8_t keya[6]; // Secret A
|
||||
uint8_t key_a[6]; // Secret A
|
||||
uint8_t acs[4]; // Control position
|
||||
uint8_t keyb[6]; // Secret B
|
||||
uint8_t key_b[6]; // Secret B
|
||||
} nfc_tag_mf1_trailer_info_t;
|
||||
|
||||
// Send buffer dedicated to miFare communication
|
||||
@@ -123,12 +123,12 @@ typedef struct {
|
||||
// Basic information of verification
|
||||
struct {
|
||||
uint8_t block;
|
||||
uint8_t is_keyb: 1;
|
||||
uint8_t is_key_b: 1;
|
||||
uint8_t is_nested: 1;
|
||||
// Airspace, occupying positions
|
||||
uint8_t : 6;
|
||||
} cmd;
|
||||
// MFKEY32 necessary parametersessary parameters
|
||||
// MFKEY32 necessary parameters
|
||||
uint8_t uid[4];
|
||||
uint8_t nt[4];
|
||||
uint8_t nr[4];
|
||||
@@ -144,7 +144,7 @@ void nfc_tag_mf1_set_detection_enable(bool enable);
|
||||
bool nfc_tag_mf1_is_detection_enable(void);
|
||||
void nfc_tag_mf1_detection_log_clear(void);
|
||||
uint32_t nfc_tag_mf1_detection_log_count(void);
|
||||
nfc_tag_14a_coll_res_referen_t *get_mifare_coll_res(void);
|
||||
nfc_tag_14a_coll_res_reference_t *get_mifare_coll_res(void);
|
||||
void nfc_tag_mf1_set_gen1a_magic_mode(bool enable);
|
||||
bool nfc_tag_mf1_is_gen1a_magic_mode(void);
|
||||
void nfc_tag_mf1_set_gen2_magic_mode(bool enable);
|
||||
|
||||
@@ -54,11 +54,11 @@ NRF_LOG_MODULE_REGISTER();
|
||||
// CONFIG masks to check individual needed bits
|
||||
#define CONF_ACCESS_PROT 0x80
|
||||
|
||||
#define VERSION_INFO_LENGTH 8 //8 bytes info lenght + crc
|
||||
#define VERSION_INFO_LENGTH 8 //8 bytes info length + crc
|
||||
|
||||
#define BYTES_PER_READ 16
|
||||
|
||||
// SIGNATURE Lenght
|
||||
// SIGNATURE Length
|
||||
#define SIGNATURE_LENGTH 32
|
||||
|
||||
// NTAG215_Version[7] mean:
|
||||
@@ -72,7 +72,7 @@ uint8_t ntagPwdOK[2] = {0x80, 0x80};
|
||||
// Data structure pointer to the label information
|
||||
static nfc_tag_ntag_information_t *m_tag_information = NULL;
|
||||
// Define and use shadow anti -collision resources
|
||||
static nfc_tag_14a_coll_res_referen_t m_shadow_coll_res;
|
||||
static nfc_tag_14a_coll_res_reference_t m_shadow_coll_res;
|
||||
//Define and use NTAG special communication buffer
|
||||
static nfc_tag_ntag_tx_buffer_t m_tag_tx_buffer;
|
||||
// Save the specific type of NTAG currently being simulated
|
||||
@@ -189,7 +189,7 @@ void nfc_tag_ntag_state_handler(uint8_t *p_data, uint16_t szDataBits) {
|
||||
return;
|
||||
}
|
||||
|
||||
nfc_tag_14a_coll_res_referen_t *get_ntag_coll_res() {
|
||||
nfc_tag_14a_coll_res_reference_t *get_ntag_coll_res() {
|
||||
// Use a separate anti -conflict information instead of using the information in the sector
|
||||
m_shadow_coll_res.sak = m_tag_information->res_coll.sak;
|
||||
m_shadow_coll_res.atqa = m_tag_information->res_coll.atqa;
|
||||
|
||||
@@ -239,7 +239,7 @@ void timer_ce_handler(nrf_timer_event_t event_type, void *p_context) {
|
||||
// measure field only during no-mod half of last bit of last broadcast
|
||||
if ((! mod) &&
|
||||
(m_bit_send_position + 1 >= LF_125KHZ_EM410X_BIT_SIZE) &&
|
||||
(m_send_id_count + 1 >= LF_125KHZ_BORADCAST_MAX)) {
|
||||
(m_send_id_count + 1 >= LF_125KHZ_BROADCAST_MAX)) {
|
||||
nrfx_timer_disable(&m_timer_send_id); // Close the timer of the broadcast venue
|
||||
// We don't need any events, but only need to detect the state of the field
|
||||
NRF_LPCOMP->INTENCLR = LPCOMP_INTENCLR_CROSS_Msk | LPCOMP_INTENCLR_UP_Msk | LPCOMP_INTENCLR_DOWN_Msk | LPCOMP_INTENCLR_READY_Msk;
|
||||
@@ -261,7 +261,7 @@ void timer_ce_handler(nrf_timer_event_t event_type, void *p_context) {
|
||||
if (m_is_send_first_edge == true) { // The first edge of the next sends next time
|
||||
if (++m_bit_send_position >= LF_125KHZ_EM410X_BIT_SIZE) {
|
||||
m_bit_send_position = 0; // The broadcast is successful once, and the BIT position is zero
|
||||
if (++m_send_id_count >= LF_125KHZ_BORADCAST_MAX) {
|
||||
if (++m_send_id_count >= LF_125KHZ_BROADCAST_MAX) {
|
||||
m_send_id_count = 0; //The number of broadcasts reaches the upper limit, re -identifies the status of the field and re -statistically count the number of broadcast times
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* The definition of the packaging tool macro only needs to be modulated 0 and 1
|
||||
*/
|
||||
#define LF_125KHZ_EM410X_BIT_SIZE 64
|
||||
#define LF_125KHZ_BORADCAST_MAX 3 // 32.768ms once, about 31 times in one second
|
||||
#define LF_125KHZ_BROADCAST_MAX 3 // 32.768ms once, about 31 times in one second
|
||||
#define LF_125KHZ_EM410X_BIT_CLOCK 256
|
||||
#define LF_EM410X_TAG_ID_SIZE 5
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
/*
|
||||
* A card slot can simulate up to two cards at the same time, one ID 125kHz EM410X, and one IC 13.56MHz 14A.(May be able to support more in the future)
|
||||
* When starting, you should start the startup listener on demand (there is no simulatory card when there is no data, but you need to monitor the state on demand)
|
||||
* When starting, you should start the startup listener on demand (there is no emulated card when there is no data, but you need to monitor the state on demand)
|
||||
* If the retrieved card slot configuration has a specified type of card, then loading the specified type of data should be carried out, and the necessary parameters of initialization should be performed.
|
||||
* When the on -site entry is detected, in addition to the relevant LED, you also need to start the simulation card according to whether the current data is loaded.
|
||||
* When the on-field entry is detected, in addition to the relevant LED, you also need to start the simulation card according to whether the current data is loaded.
|
||||
* In the simulation card, all operations should be carried out based on the data loaded in RAM. After the analog card is over, the modified data should be preserved to Flash
|
||||
*
|
||||
*
|
||||
@@ -267,12 +267,12 @@ static void delete_data_by_tag_type(uint8_t slot, tag_sense_type_t sense_type) {
|
||||
fds_slot_record_map_t map_info;
|
||||
get_fds_map_by_slot_sense_type_for_dump(slot, sense_type, &map_info);
|
||||
int count = fds_delete_sync(map_info.id, map_info.key);
|
||||
NRF_LOG_INFO("Slot %d delete senese type %d data, record count: %d", slot, sense_type, count);
|
||||
NRF_LOG_INFO("Slot %d delete sense type %d data, record count: %d", slot, sense_type, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the simulation card data data. Note that loading is just data operation,
|
||||
* Start the analog card, please call tag_emuration_sense_run function, otherwise you will not sensor the field event
|
||||
* Start the analog card, please call tag_emulation_sense_run function, otherwise you will not sensor the field event
|
||||
*/
|
||||
void tag_emulation_load_data(void) {
|
||||
uint8_t slot = tag_emulation_get_slot();
|
||||
@@ -281,7 +281,7 @@ void tag_emulation_load_data(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
*Save the simulatory card configuration data. At the right time, this function should be called for data preservation of data
|
||||
*Save the emulated card configuration data. At the right time, this function should be called for data preservation of data
|
||||
*/
|
||||
void tag_emulation_save_data(void) {
|
||||
uint8_t slot = tag_emulation_get_slot();
|
||||
@@ -381,7 +381,7 @@ void tag_emulation_sense_switch(tag_sense_type_t type, bool enable) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the simulatory card configuration data, note that loading is just a card slot configuration
|
||||
* Load the emulated card configuration data, note that loading is just a card slot configuration
|
||||
*/
|
||||
void tag_emulation_load_config(void) {
|
||||
// Read the card slot configuration data
|
||||
@@ -396,7 +396,7 @@ void tag_emulation_load_config(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
*Save the simulatory card configuration data
|
||||
*Save the emulated card configuration data
|
||||
*/
|
||||
void tag_emulation_save_config(void) {
|
||||
// We are configured the card slot configuration, and we need to calculate the current card slot configuration CRC code to judge whether the data below is updated
|
||||
@@ -437,7 +437,7 @@ void tag_emulation_sense_end(void) {
|
||||
*/
|
||||
void tag_emulation_init(void) {
|
||||
tag_emulation_load_config(); // Configuration of loading the card slot of the simulation card
|
||||
tag_emulation_load_data(); // Load the data of the simulatory card
|
||||
tag_emulation_load_data(); // Load the data of the emulated card
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,7 +587,7 @@ void tag_emulation_factory_init(void) {
|
||||
}
|
||||
|
||||
if (slotConfig.group[2].enable && slotConfig.group[2].tag_lf != TAG_TYPE_UNKNOWN) {
|
||||
// Initialize a low -frequency EM410X card at Card Glip 3, if it does not exist.
|
||||
// Initialize a low -frequency EM410X card in slot 3, if it does not exist.
|
||||
get_fds_map_by_slot_sense_type_for_dump(2, TAG_SENSE_LF, &map_info);
|
||||
bool is_slot3_lf_data_exists = fds_is_exists(map_info.id, map_info.key);
|
||||
if (!is_slot3_lf_data_exists) {
|
||||
|
||||
@@ -58,7 +58,7 @@ void nonce_distance_notable(uint32_t *msb, uint32_t *lsb) {
|
||||
* And may support Nested attack
|
||||
* @param :nonce : Measured random number
|
||||
* @retval : true = weak prng
|
||||
* false = hardend prng
|
||||
* false = hardened prng
|
||||
*
|
||||
*/
|
||||
bool validate_prng_nonce_notable(uint32_t nonce) {
|
||||
@@ -74,7 +74,7 @@ bool validate_prng_nonce_notable(uint32_t nonce) {
|
||||
* @brief : Re -set the field, restart the field after a certain delay
|
||||
*
|
||||
*/
|
||||
static inline void ResetRadioFieldWithDelay(void) {
|
||||
static inline void reset_radio_field_with_delay(void) {
|
||||
pcd_14a_reader_antenna_off();
|
||||
bsp_delay_ms(g_ant_reset_delay);
|
||||
pcd_14a_reader_antenna_on();
|
||||
@@ -83,7 +83,7 @@ static inline void ResetRadioFieldWithDelay(void) {
|
||||
/**
|
||||
* @brief : Send the MiFare instruction
|
||||
* @param :pcs : crypto1st handle
|
||||
* @param :crypted : Whether these data need to be encrypted by Crypto1
|
||||
* @param :encrypted : Whether these data need to be encrypted by Crypto1
|
||||
* @param :cmd : The instructions that will be sent, for example, 0x60 indicates verification A key
|
||||
* @param :data : The data that will be sent, such as 0x03 indicates verification 1 sector
|
||||
* @param :answer : Card response data stored array
|
||||
@@ -91,7 +91,7 @@ static inline void ResetRadioFieldWithDelay(void) {
|
||||
* @retval : The length of the card response data, this length is the length of the bit, not the length of Byte
|
||||
*
|
||||
*/
|
||||
uint8_t sendcmd(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *status, uint8_t *answer, uint8_t *answer_parity, uint16_t answer_max_bit) {
|
||||
uint8_t send_cmd(struct Crypto1State *pcs, uint8_t encrypted, uint8_t cmd, uint8_t data, uint8_t *status, uint8_t *answer, uint8_t *answer_parity, uint16_t answer_max_bit) {
|
||||
// Here we set directly to static
|
||||
static uint8_t pos;
|
||||
static uint16_t len;
|
||||
@@ -109,7 +109,7 @@ uint8_t sendcmd(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t
|
||||
|
||||
len = 0;
|
||||
|
||||
if (pcs && crypted) {
|
||||
if (pcs && encrypted) {
|
||||
for (pos = 0; pos < 4; pos++) {
|
||||
ecmd[pos] = crypto1_byte(pcs, 0x00, 0) ^ dcmd[pos];
|
||||
par[pos] = filter(pcs->odd) ^ oddparity8(dcmd[pos]);
|
||||
@@ -139,7 +139,7 @@ uint8_t sendcmd(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t
|
||||
return len;
|
||||
}
|
||||
|
||||
if (crypted == CRYPT_ALL) {
|
||||
if (encrypted == CRYPT_ALL) {
|
||||
if (len == 8) {
|
||||
uint16_t res = 0;
|
||||
res |= (crypto1_bit(pcs, 0, 0) ^ BIT(answer[0], 0)) << 0;
|
||||
@@ -169,8 +169,8 @@ uint8_t sendcmd(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t
|
||||
*
|
||||
*/
|
||||
int authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr) {
|
||||
static uint8_t status; // tag resonse status
|
||||
static uint16_t len; // tag resonse length
|
||||
static uint8_t status; // tag response status
|
||||
static uint16_t len; // tag response length
|
||||
static uint32_t pos, nt, ntpp; // Supplied tag nonce
|
||||
static const uint8_t nr[] = { 0x12, 0x34, 0x56, 0x78 }; // Use a fixed card to random NR, which is Nonce Reader.
|
||||
uint8_t par[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
@@ -178,9 +178,9 @@ int authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyT
|
||||
uint8_t answer[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
uint8_t parity[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
len = sendcmd(pcs, isNested, keyType, blockNo, &status, answer, parity, U8ARR_BIT_LEN(answer));
|
||||
len = send_cmd(pcs, isNested, keyType, blockNo, &status, answer, parity, U8ARR_BIT_LEN(answer));
|
||||
if (len != 32) {
|
||||
NRF_LOG_INFO("No 32 data recv on sendcmd: %d\r\n", len);
|
||||
NRF_LOG_INFO("No 32 data recv on send_cmd: %d\r\n", len);
|
||||
return HF_ERR_STAT;
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ int authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyT
|
||||
* As a result, the CPU cannot complete the replay attack within the same time.
|
||||
* There is basically no solution in this situation. It is recommended to close the non -critical interruption and task scheduling outside this code
|
||||
*/
|
||||
uint8_t Darkside_Select_Nonces(picc_14a_tag_t *tag, uint8_t block, uint8_t keytype, uint32_t *nt) {
|
||||
uint8_t darkside_select_nonces(picc_14a_tag_t *tag, uint8_t block, uint8_t keytype, uint32_t *nt) {
|
||||
#define NT_COUNT 15
|
||||
uint8_t tag_auth[4] = { keytype, block, 0x00, 0x00 };
|
||||
uint8_t tag_resp[4] = { 0x00 };
|
||||
@@ -272,7 +272,7 @@ uint8_t Darkside_Select_Nonces(picc_14a_tag_t *tag, uint8_t block, uint8_t keyty
|
||||
//When the antenna is reset, we must make sure
|
||||
// 1. The antenna is powered off for a long time to ensure that the card is completely powered off, otherwise the pseudo -random number generator of the card cannot be reset
|
||||
// 2. Moderate power -off time, don't be too long, it will affect efficiency, and don't be too short.
|
||||
ResetRadioFieldWithDelay();
|
||||
reset_radio_field_with_delay();
|
||||
// After the power is completely disconnected, we will select the card quickly and compress the verification time as much as possible.
|
||||
if (pcd_14a_reader_scan_auto(tag) != HF_TAG_OK) {
|
||||
NRF_LOG_INFO("Tag can't select!\n");
|
||||
@@ -331,7 +331,7 @@ uint8_t Darkside_Select_Nonces(picc_14a_tag_t *tag, uint8_t block, uint8_t keyty
|
||||
* @retval : Collect successfully returning hf_tag_ok, verify that the corresponding abnormal code is not successfully returned
|
||||
*
|
||||
*/
|
||||
uint8_t Darkside_Recover_Key(uint8_t targetBlk, uint8_t targetTyp,
|
||||
uint8_t darkside_recover_key(uint8_t targetBlk, uint8_t targetTyp,
|
||||
uint8_t firstRecover, uint8_t ntSyncMax, DarksideCore *dc) {
|
||||
|
||||
// Card information for fixed use
|
||||
@@ -385,7 +385,7 @@ uint8_t Darkside_Recover_Key(uint8_t targetBlk, uint8_t targetTyp,
|
||||
uid_ori = get_u32_tag_uid(p_tag_info);
|
||||
|
||||
// Then you need to fix a random number that may appear
|
||||
status = Darkside_Select_Nonces(p_tag_info, targetBlk, targetTyp, &nt_ori);
|
||||
status = darkside_select_nonces(p_tag_info, targetBlk, targetTyp, &nt_ori);
|
||||
if (status != HF_TAG_OK) {
|
||||
//The fixed random number failed, and the next step cannot be performed
|
||||
return status;
|
||||
@@ -410,7 +410,7 @@ uint8_t Darkside_Recover_Key(uint8_t targetBlk, uint8_t targetTyp,
|
||||
//When the antenna is reset, we must make sure
|
||||
// 1. The antenna is powered off for a long time to ensure that the card is completely powered off, otherwise the pseudo -random number generator of the card cannot be reset
|
||||
// 2. Moderate power -off time, don't be too long, it will affect efficiency, and don't be too short.
|
||||
ResetRadioFieldWithDelay();
|
||||
reset_radio_field_with_delay();
|
||||
|
||||
//After the power is completely disconnected, we will select the card quickly and compress the verification time as much as possible.
|
||||
if (pcd_14a_reader_scan_auto(p_tag_info) != HF_TAG_OK) {
|
||||
@@ -470,7 +470,7 @@ uint8_t Darkside_Recover_Key(uint8_t targetBlk, uint8_t targetTyp,
|
||||
// NRF_LOG_INFO("NACK get: 0x%x\r\n", receivedAnswer[0]);
|
||||
received_nack = 1;
|
||||
} else if (len == 32) {
|
||||
// did we get lucky and got our dummykey to be valid?
|
||||
// did we get lucky and got our dummy key to be valid?
|
||||
// however we dont feed key w uid it the prng..
|
||||
NRF_LOG_INFO("Auth Ok, you are so lucky!\n");
|
||||
return DARKSIDE_LUCK_AUTH_OK;
|
||||
@@ -533,7 +533,7 @@ uint8_t Darkside_Recover_Key(uint8_t targetBlk, uint8_t targetTyp,
|
||||
* @retval : none
|
||||
*
|
||||
*/
|
||||
void Atenna_Switch_Delay(uint32_t delay_ms) {
|
||||
void antenna_switch_delay(uint32_t delay_ms) {
|
||||
g_ant_reset_delay = delay_ms;
|
||||
}
|
||||
|
||||
@@ -547,11 +547,11 @@ void Atenna_Switch_Delay(uint32_t delay_ms) {
|
||||
* Or other card -related communication errors, the most common is loss card HF_TAG_NO
|
||||
*
|
||||
*/
|
||||
uint8_t Check_Darkside_Support() {
|
||||
uint8_t check_darkside_support() {
|
||||
// Instantiated parameter
|
||||
DarksideCore dc;
|
||||
//Determine and return the result directly
|
||||
return Darkside_Recover_Key(0x03, PICC_AUTHENT1A, true, 0x15, &dc);
|
||||
return darkside_recover_key(0x03, PICC_AUTHENT1A, true, 0x15, &dc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,7 +560,7 @@ uint8_t Check_Darkside_Support() {
|
||||
* If it is not supported, returns the corresponding error code
|
||||
*
|
||||
*/
|
||||
uint8_t Check_Tag_Response_NT(picc_14a_tag_t *tag, uint32_t *nt) {
|
||||
uint8_t check_tag_response_nt(picc_14a_tag_t *tag, uint32_t *nt) {
|
||||
struct Crypto1State mpcs = { 0, 0 };
|
||||
struct Crypto1State *pcs = &mpcs;
|
||||
uint8_t par_recv[4] = { 0x00 };
|
||||
@@ -577,9 +577,9 @@ uint8_t Check_Tag_Response_NT(picc_14a_tag_t *tag, uint32_t *nt) {
|
||||
}
|
||||
|
||||
// Send instructions and get NT return
|
||||
*nt = sendcmd(pcs, AUTH_FIRST, PICC_AUTHENT1A, 0x03, &status, dat_recv, par_recv, U8ARR_BIT_LEN(dat_recv));
|
||||
*nt = send_cmd(pcs, AUTH_FIRST, PICC_AUTHENT1A, 0x03, &status, dat_recv, par_recv, U8ARR_BIT_LEN(dat_recv));
|
||||
if (*nt != 32) {
|
||||
// dbg_block_printf("No 32 data recv on sendcmd: %d\n", *nt);
|
||||
// dbg_block_printf("No 32 data recv on send_cmd: %d\n", *nt);
|
||||
return HF_ERR_STAT;
|
||||
}
|
||||
*nt = bytes_to_num(dat_recv, 4);
|
||||
@@ -594,7 +594,7 @@ uint8_t Check_Tag_Response_NT(picc_14a_tag_t *tag, uint32_t *nt) {
|
||||
* Lost card hf_tag_no and wrong status hf_errstat
|
||||
*
|
||||
*/
|
||||
uint8_t Check_STDMifareNT_Support() {
|
||||
uint8_t check_std_mifare_nt_support() {
|
||||
uint32_t nt1 = 0;
|
||||
|
||||
// Find card, search on the field
|
||||
@@ -603,7 +603,7 @@ uint8_t Check_STDMifareNT_Support() {
|
||||
}
|
||||
|
||||
// Get NT
|
||||
return Check_Tag_Response_NT(p_tag_info, &nt1);
|
||||
return check_tag_response_nt(p_tag_info, &nt1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -612,7 +612,7 @@ uint8_t Check_STDMifareNT_Support() {
|
||||
* If support, return nested_tag_is_static, if not support,
|
||||
*
|
||||
*/
|
||||
uint8_t Check_StaticNested_Support() {
|
||||
uint8_t check_static_nested_support() {
|
||||
uint32_t nt1, nt2;
|
||||
uint8_t status;
|
||||
|
||||
@@ -622,7 +622,7 @@ uint8_t Check_StaticNested_Support() {
|
||||
}
|
||||
|
||||
// Get NT in the first wave
|
||||
status = Check_Tag_Response_NT(p_tag_info, &nt1);
|
||||
status = check_tag_response_nt(p_tag_info, &nt1);
|
||||
if (status != HF_TAG_OK) {
|
||||
return status;
|
||||
}
|
||||
@@ -630,10 +630,10 @@ uint8_t Check_StaticNested_Support() {
|
||||
// Remember to reset the place after getting completed
|
||||
// If you do not re -set the field, some cards will always provide a static NT when maintaining the function in the field
|
||||
// Therefore, resetting here is very important.
|
||||
ResetRadioFieldWithDelay();
|
||||
reset_radio_field_with_delay();
|
||||
|
||||
// Get NT in the second wave
|
||||
status = Check_Tag_Response_NT(p_tag_info, &nt2);
|
||||
status = check_tag_response_nt(p_tag_info, &nt2);
|
||||
if (status != HF_TAG_OK) {
|
||||
return status;
|
||||
}
|
||||
@@ -647,17 +647,17 @@ uint8_t Check_StaticNested_Support() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief : Determine whether this card supports the most common, weaker, and easiest Prite attack
|
||||
* @brief : Determine whether this card supports the most common, weaker, and easiest nested attack
|
||||
* @retval : critical result
|
||||
*
|
||||
*/
|
||||
uint8_t Check_WeakNested_Support() {
|
||||
uint8_t check_weak_nested_support() {
|
||||
uint8_t status;
|
||||
uint32_t nt1;
|
||||
|
||||
status = Check_StaticNested_Support();
|
||||
status = check_static_nested_support();
|
||||
|
||||
// If the judgment process is found, it is found that the Staticnested detection cannot be completed
|
||||
// If the judgment process is found, it is found that the StaticNested detection cannot be completed
|
||||
// Then return the state directly, no need to perform the following judgment logic.
|
||||
if (status != HF_TAG_OK) {
|
||||
return status;
|
||||
@@ -676,7 +676,7 @@ uint8_t Check_WeakNested_Support() {
|
||||
}
|
||||
|
||||
//Get NT, just get it once
|
||||
status = Check_Tag_Response_NT(p_tag_info, &nt1);
|
||||
status = check_tag_response_nt(p_tag_info, &nt1);
|
||||
if (status != HF_TAG_OK) {
|
||||
return status;
|
||||
}
|
||||
@@ -718,7 +718,7 @@ uint32_t measure_nonces(uint32_t from, uint32_t to) {
|
||||
* @retval : Median
|
||||
*
|
||||
*/
|
||||
uint32_t measure_medin(uint32_t *src, uint32_t length) {
|
||||
uint32_t measure_median(uint32_t *src, uint32_t length) {
|
||||
uint32_t len = length;
|
||||
uint32_t minIndex;
|
||||
uint32_t temp, i;
|
||||
@@ -753,7 +753,7 @@ uint32_t measure_medin(uint32_t *src, uint32_t length) {
|
||||
* @retval : Operating result
|
||||
*
|
||||
*/
|
||||
uint8_t Measure_Distance(uint64_t u64Key, uint8_t block, uint8_t type, uint32_t *distance) {
|
||||
uint8_t measure_distance(uint64_t u64Key, uint8_t block, uint8_t type, uint32_t *distance) {
|
||||
struct Crypto1State mpcs = {0, 0};
|
||||
struct Crypto1State *pcs = &mpcs;
|
||||
uint32_t distances[DIST_NR] = { 0x00 };
|
||||
@@ -792,7 +792,7 @@ uint8_t Measure_Distance(uint64_t u64Key, uint8_t block, uint8_t type, uint32_t
|
||||
} while (index < DIST_NR);
|
||||
|
||||
//The final calculation of the distance between the two NTs and spread it directly
|
||||
*distance = measure_medin(distances, DIST_NR);
|
||||
*distance = measure_median(distances, DIST_NR);
|
||||
// You need to return the OK value to successfully log in
|
||||
return HF_TAG_OK;
|
||||
}
|
||||
@@ -808,7 +808,7 @@ uint8_t Measure_Distance(uint64_t u64Key, uint8_t block, uint8_t type, uint32_t
|
||||
* @retval : Successfully return hf_tag_ok, verify the unsuccessful return of the non -hf_tag_ok value
|
||||
*
|
||||
*/
|
||||
uint8_t Nested_Recover_Core(NestedCore *pnc, uint64_t keyKnown, uint8_t blkKnown, uint8_t typKnown, uint8_t targetBlock, uint8_t targetType) {
|
||||
uint8_t nested_recover_core(NestedCore *pnc, uint64_t keyKnown, uint8_t blkKnown, uint8_t typKnown, uint8_t targetBlock, uint8_t targetType) {
|
||||
struct Crypto1State mpcs = {0, 0};
|
||||
struct Crypto1State *pcs = &mpcs;
|
||||
uint8_t status;
|
||||
@@ -828,7 +828,7 @@ uint8_t Nested_Recover_Core(NestedCore *pnc, uint64_t keyKnown, uint8_t blkKnown
|
||||
return MF_ERR_AUTH;
|
||||
}
|
||||
// Then there is nested verification
|
||||
if (sendcmd(pcs, AUTH_NESTED, targetType, targetBlock, &status, answer, parity, U8ARR_BIT_LEN(answer)) != 32) {
|
||||
if (send_cmd(pcs, AUTH_NESTED, targetType, targetBlock, &status, answer, parity, U8ARR_BIT_LEN(answer)) != 32) {
|
||||
return HF_ERR_STAT;
|
||||
};
|
||||
// The first verified explicitly random number
|
||||
@@ -854,16 +854,16 @@ uint8_t Nested_Recover_Core(NestedCore *pnc, uint64_t keyKnown, uint8_t blkKnown
|
||||
* @retval :The attack returns hf_tag_ok, the attack is unsuccessful to return the non -hf_tag_ok value
|
||||
*
|
||||
*/
|
||||
uint8_t Nested_Recover_Key(uint64_t keyKnown, uint8_t blkKnown, uint8_t typKnown, uint8_t targetBlock, uint8_t targetType, NestedCore ncs[SETS_NR]) {
|
||||
uint8_t nested_recover_key(uint64_t keyKnown, uint8_t blkKnown, uint8_t typKnown, uint8_t targetBlock, uint8_t targetType, NestedCore ncs[SETS_NR]) {
|
||||
uint8_t m, res;
|
||||
// Survening card, all operations must be based on the card
|
||||
// all operations must be based on the card
|
||||
res = pcd_14a_reader_scan_auto(p_tag_info);
|
||||
if (res != HF_TAG_OK) {
|
||||
return res;
|
||||
}
|
||||
//Then collect the specified number of random array
|
||||
for (m = 0; m < SETS_NR; m++) {
|
||||
res = Nested_Recover_Core(
|
||||
res = nested_recover_core(
|
||||
&(ncs[m]),
|
||||
keyKnown,
|
||||
blkKnown,
|
||||
@@ -887,7 +887,7 @@ uint8_t Nested_Recover_Key(uint64_t keyKnown, uint8_t blkKnown, uint8_t typKnown
|
||||
* @retval : Operating status value
|
||||
*
|
||||
*/
|
||||
uint8_t Nested_Distacne_Detect(uint8_t block, uint8_t type, uint8_t *key, NestedDist *nd) {
|
||||
uint8_t nested_distance_detect(uint8_t block, uint8_t type, uint8_t *key, NestedDist *nd) {
|
||||
uint8_t status = HF_TAG_OK;
|
||||
uint32_t distance = 0;
|
||||
//Must ensure that there is a card on the court
|
||||
@@ -899,7 +899,7 @@ uint8_t Nested_Distacne_Detect(uint8_t block, uint8_t type, uint8_t *key, Nested
|
||||
get_4byte_tag_uid(p_tag_info, nd->uid);
|
||||
}
|
||||
// Get distance, prepare for the next attack
|
||||
status = Measure_Distance(
|
||||
status = measure_distance(
|
||||
bytes_to_num(key, 6),
|
||||
block,
|
||||
type,
|
||||
|
||||
@@ -45,20 +45,20 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t Darkside_Recover_Key(
|
||||
uint8_t darkside_recover_key(
|
||||
uint8_t targetBlk,
|
||||
uint8_t targetTyp,
|
||||
uint8_t firstRecover,
|
||||
uint8_t ntSyncMax,
|
||||
DarksideCore *dc
|
||||
);
|
||||
uint8_t Nested_Distacne_Detect(
|
||||
uint8_t nested_distance_detect(
|
||||
uint8_t block,
|
||||
uint8_t type,
|
||||
uint8_t *key,
|
||||
NestedDist *nd
|
||||
);
|
||||
uint8_t Nested_Recover_Key(
|
||||
uint8_t nested_recover_key(
|
||||
uint64_t keyKnown,
|
||||
uint8_t blkKnown,
|
||||
uint8_t typKnown,
|
||||
@@ -66,10 +66,10 @@ uint8_t Nested_Recover_Key(
|
||||
uint8_t targetType,
|
||||
NestedCore ncs[SETS_NR]
|
||||
);
|
||||
uint8_t Check_Darkside_Support(void);
|
||||
uint8_t Check_WeakNested_Support(void);
|
||||
uint8_t Check_STDMifareNT_Support(void);
|
||||
void Atenna_Switch_Delay(uint32_t delay_ms);
|
||||
uint8_t check_darkside_support(void);
|
||||
uint8_t check_weak_nested_support(void);
|
||||
uint8_t check_std_mifare_nt_support(void);
|
||||
void antenna_switch_delay(uint32_t delay_ms);
|
||||
uint8_t auth_key_use_522_hw(uint8_t block, uint8_t type, uint8_t *key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -190,7 +190,7 @@ void pcd_14a_reader_init(void) {
|
||||
* @retval : Status value hf_tag_ok, success
|
||||
*/
|
||||
void pcd_14a_reader_reset(void) {
|
||||
// Make sure you have initialized and then communicate with soft reworting
|
||||
// Make sure it has been initialized before communicating and soft reset
|
||||
if (m_reader_is_init) {
|
||||
// Softening 522
|
||||
write_register_single(CommandReg, PCD_IDLE);
|
||||
|
||||
@@ -175,11 +175,11 @@ 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
|
||||
// Device communication control
|
||||
uint16_t pcd_14a_reader_timeout_get(void);
|
||||
void pcd_14a_reader_timeout_set(uint16_t timeout_ms);
|
||||
|
||||
// Device comunication interface
|
||||
// Device communication interface
|
||||
uint8_t pcd_14a_reader_bytes_transfer(uint8_t Command,
|
||||
uint8_t *pIn,
|
||||
uint8_t InLenByte,
|
||||
@@ -220,7 +220,7 @@ void pcd_14a_reader_fast_halt_tag(void);
|
||||
uint8_t pcd_14a_reader_gen1a_unlock(void);
|
||||
uint8_t pcd_14a_reader_gen1a_uplock(void);
|
||||
|
||||
// CRC calulate
|
||||
// CRC calculate
|
||||
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);
|
||||
|
||||
@@ -17,7 +17,7 @@ NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
static RAWBUF_TYPE_S carddata;
|
||||
static volatile uint8_t dataindex = 0; //Record changes along the number of times
|
||||
uint8_t cardbufbyte[cardbufbytesize]; //Card data
|
||||
uint8_t cardbufbyte[CARD_BUF_BYTES_SIZE]; //Card data
|
||||
|
||||
#ifdef debug410x
|
||||
uint8_t datatest[256] = { 0x00 };
|
||||
@@ -30,7 +30,7 @@ uint8_t datatest[256] = { 0x00 };
|
||||
uint8_t mcst(RAWBUF_TYPE_S *Pdata) {
|
||||
uint8_t sync = 1; //After the current interval process is processed, is it on the judgment line
|
||||
uint8_t cardindex = 0; //Record change number
|
||||
for (int i = Pdata->startbit; i < rawbufsize * 8; i++) {
|
||||
for (int i = Pdata->startbit; i < RAW_BUF_SIZE * 8; i++) {
|
||||
uint8_t thisbit = readbit(Pdata->rawa, Pdata->rawb, i);
|
||||
switch (sync) {
|
||||
case 1: //Synchronous state
|
||||
@@ -74,7 +74,7 @@ uint8_t mcst(RAWBUF_TYPE_S *Pdata) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (cardindex >= cardbufsize * 8)
|
||||
if (cardindex >= CARD_BUF_SIZE * 8)
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
@@ -266,14 +266,14 @@ void em410x_encoder(uint8_t *pData, uint8_t *pOut) {
|
||||
|
||||
// Reading the card function, you need to stop calling, return 0 to read the card, 1 is to read
|
||||
uint8_t em410x_acquire(void) {
|
||||
if (dataindex >= rawbufsize * 8) {
|
||||
if (dataindex >= RAW_BUF_SIZE * 8) {
|
||||
#ifdef debug410x
|
||||
{
|
||||
for (int i = 0; i < rawbufsize * 8; i++) {
|
||||
for (int i = 0; i < RAW_BUF_SIZE * 8; i++) {
|
||||
NRF_LOG_INFO("%d ", readbit(carddata.rawa, carddata.rawb, i));
|
||||
}
|
||||
NRF_LOG_INFO("///raw data\r\n");
|
||||
for (int i = 0; i < rawbufsize * 8; i++) {
|
||||
for (int i = 0; i < RAW_BUF_SIZE * 8; i++) {
|
||||
NRF_LOG_INFO("%d ", datatest[i]);
|
||||
}
|
||||
NRF_LOG_INFO("///time data\r\n");
|
||||
@@ -281,7 +281,7 @@ uint8_t em410x_acquire(void) {
|
||||
#endif
|
||||
//Looking for goals 0 1111 1111
|
||||
carddata.startbit = 255;
|
||||
for (int i = 0; i < (rawbufsize * 8) - 8; i++) {
|
||||
for (int i = 0; i < (RAW_BUF_SIZE * 8) - 8; i++) {
|
||||
if (readbit(carddata.rawa, carddata.rawb, i) == 1) {
|
||||
carddata.startbit = 0;
|
||||
for (int j = 1; j < 8; j++) {
|
||||
@@ -296,20 +296,20 @@ uint8_t em410x_acquire(void) {
|
||||
}
|
||||
}
|
||||
// If you find the right beginning to deal with it
|
||||
if (carddata.startbit != 255 && carddata.startbit < (rawbufsize * 8) - 64) {
|
||||
if (carddata.startbit != 255 && carddata.startbit < (RAW_BUF_SIZE * 8) - 64) {
|
||||
//Guarantee card data can be fully analyzed
|
||||
//NRF_LOG_INFO("do mac,start: %d\r\n",startbit);
|
||||
if (mcst(&carddata) == 1) {
|
||||
//Card normal analysis
|
||||
#ifdef debug410x
|
||||
{
|
||||
for (int i = 0; i < cardbufsize; i++) {
|
||||
for (int i = 0; i < CARD_BUF_SIZE; i++) {
|
||||
NRF_LOG_INFO("%02X", carddata.hexbuf[i]);
|
||||
}
|
||||
NRF_LOG_INFO("///card data\r\n");
|
||||
}
|
||||
#endif
|
||||
if (em410x_decoder(carddata.hexbuf, cardbufsize, cardbufbyte)) {
|
||||
if (em410x_decoder(carddata.hexbuf, CARD_BUF_SIZE, cardbufbyte)) {
|
||||
//Card data check passes
|
||||
#ifdef debug410x
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -334,7 +334,7 @@ void GPIO_INT0_callback(void) {
|
||||
thistimelen = get_lf_counter_value();
|
||||
if (thistimelen > 47) {
|
||||
static uint8_t cons_temp = 0;
|
||||
if (dataindex < rawbufsize * 8) {
|
||||
if (dataindex < RAW_BUF_SIZE * 8) {
|
||||
if (48 <= thistimelen && thistimelen <= 80) {
|
||||
cons_temp = 0;
|
||||
} else if (80 <= thistimelen && thistimelen <= 112) {
|
||||
|
||||
@@ -10,20 +10,20 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define cardbufbytesize 5 // Card byte buffer size
|
||||
#define CARD_BUF_BYTES_SIZE 5 // Card byte buffer size
|
||||
|
||||
#define rawbufsize 24 // The maximum record buffer
|
||||
#define cardbufsize 8 // Card size
|
||||
#define RAW_BUF_SIZE 24 // The maximum record buffer
|
||||
#define CARD_BUF_SIZE 8 // Card size
|
||||
|
||||
typedef struct {
|
||||
uint8_t rawa[rawbufsize]; // The time difference between recording changes
|
||||
uint8_t rawb[rawbufsize]; // The time difference between recording changes
|
||||
uint8_t hexbuf[cardbufsize]; // Patriotic card data
|
||||
uint8_t rawa[RAW_BUF_SIZE]; // The time difference between recording changes
|
||||
uint8_t rawb[RAW_BUF_SIZE]; // The time difference between recording changes
|
||||
uint8_t hexbuf[CARD_BUF_SIZE]; // Patriotic card data
|
||||
uint8_t startbit;
|
||||
} RAWBUF_TYPE_S;
|
||||
|
||||
//Card data
|
||||
extern uint8_t cardbufbyte[cardbufbytesize];
|
||||
extern uint8_t cardbufbyte[CARD_BUF_BYTES_SIZE];
|
||||
|
||||
|
||||
void init_em410x_hw(void);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user