Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lf read From merlokk #216

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions firmware/application/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,20 @@ ifeq (${CURRENT_DEVICE_TYPE}, ${CHAMELEON_ULTRA})
$(PROJ_DIR)/rfid/reader/lf/lf_reader_data.c \
$(PROJ_DIR)/rfid/reader/lf/lf_reader_main.c \
$(PROJ_DIR)/rfid/reader/lf/lf_t55xx_data.c \
$(PROJ_DIR)/rfid/reader/lf/lf_read.c \
$(PROJ_DIR)/rfid/reader/lf/utils/bitarray.c \
$(PROJ_DIR)/rfid/reader/lf/utils/bit_buffer.c \
$(PROJ_DIR)/rfid/reader/lf/utils/spstring.c \
$(PROJ_DIR)/rfid/reader/lf/utils/t5577.c \
$(PROJ_DIR)/rfid/reader/lf/utils/manchester_decoder.c \
$(PROJ_DIR)/rfid/reader/lf/protocols/lfrfid_protocols.c \
$(PROJ_DIR)/rfid/reader/lf/protocols/protocol_em4100.c \

INC_FOLDERS +=\
${PROJ_DIR}/rfid/reader/ \
${PROJ_DIR}/rfid/reader/hf \
${PROJ_DIR}/rfid/reader/lf \
${PROJ_DIR}/rfid/reader/lf/utils \

CFLAGS += -DPROJECT_CHAMELEON_ULTRA

Expand Down
10 changes: 10 additions & 0 deletions firmware/application/src/app_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ static data_frame_tx_t *cmd_processor_em410x_write_to_t55XX(uint16_t cmd, uint16
return data_frame_make(cmd, status, 0, NULL);
}

static data_frame_tx_t *cmd_processor_lf_read(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
uint8_t card_buffer[64] = { 0x00 };
status = lf_reader_read(card_buffer, sizeof(card_buffer));
if (status != STATUS_LF_TAG_OK) {
return data_frame_make(cmd, status, 0, NULL);
}
return data_frame_make(cmd, STATUS_LF_TAG_OK, sizeof(card_buffer), card_buffer);
}

#endif


Expand Down Expand Up @@ -1298,6 +1307,7 @@ static cmd_data_map_t m_data_cmd_map[] = {

{ DATA_CMD_EM410X_SCAN, before_reader_run, cmd_processor_em410x_scan, NULL },
{ DATA_CMD_EM410X_WRITE_TO_T55XX, before_reader_run, cmd_processor_em410x_write_to_t55XX, NULL },
{ DATA_CMD_LF_READ, before_reader_run, cmd_processor_lf_read, NULL },

#endif

Expand Down
1 change: 1 addition & 0 deletions firmware/application/src/app_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/////////////////////////////////////////////////////////////////////
#define STATUS_LF_TAG_OK (0x40) // Some of the low -frequency cards are successful!
#define STATUS_EM410X_TAG_NO_FOUND (0x41) // Can't search for valid EM410X tags
#define STATUS_LF_TAG_NO_FOUND (0x42) // Can't search for valid LF tag


/////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions firmware/application/src/data_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
//
#define DATA_CMD_EM410X_SCAN (3000)
#define DATA_CMD_EM410X_WRITE_TO_T55XX (3001)
#define DATA_CMD_LF_READ (3010)
//
// ******************************************************************

Expand Down
218 changes: 218 additions & 0 deletions firmware/application/src/rfid/reader/lf/lf_read.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
#ifdef debug410x
#include <stdio.h>
#endif

#include "lf_read.h"

#include "bsp_time.h"
#include "bsp_delay.h"
#include "lf_reader_data.h"
#include "lf_em410x_data.h"
#include "lf_125khz_radio.h"
#include "protocols/lfrfid_protocols.h"

#define NRF_LOG_MODULE_NAME lf_read
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
NRF_LOG_MODULE_REGISTER();


static RAWBUF_TYPE_S carddata;
uint8_t lf_cardbuf[LF_CARD_BUF_SIZE];

static volatile uint32_t dataindex = 0;
uint8_t databuf[512] = { 0x00 };


//Process card data, enter raw Buffer's starting position 2 position (21111 ...)
//After processing the card data, put cardbuf, return 5 normal analysis
//pdata is rawbuffer
uint8_t mcst2(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 < RAW_BUF_SIZE * 8; i++) {
uint8_t thisbit = readbit(Pdata->rawa, Pdata->rawb, i);
switch (sync) {
case 1: //Synchronous state
switch (thisbit) {
case 0: //TheSynchronousState1T,Add1Digit0,StillSynchronize
writebit(Pdata->hexbuf, Pdata->hexbuf, cardindex, 0);
cardindex++;
break;
case 1: // Synchronous status 1.5T, add 1 digit 1, switch to non -synchronized state
writebit(Pdata->hexbuf, Pdata->hexbuf, cardindex, 1);
cardindex++;
sync = 0;
break;
case 2: //Synchronous2T,Add2Digits10,StillSynchronize
writebit(Pdata->hexbuf, Pdata->hexbuf, cardindex, 1);
cardindex++;
writebit(Pdata->hexbuf, Pdata->hexbuf, cardindex, 0);
cardindex++;
break;
default:
return 0;
}
break;
case 0: //Non -synchronous state
switch (thisbit) {
case 0: //1TInNonSynchronousState,Add1Digit1,StillNonSynchronous
writebit(Pdata->hexbuf, Pdata->hexbuf, cardindex, 1);
cardindex++;
break;
case 1: // In non -synchronous status 1.5T, add 2 digits 10, switch to the synchronous state
writebit(Pdata->hexbuf, Pdata->hexbuf, cardindex, 1);
cardindex++;
writebit(Pdata->hexbuf, Pdata->hexbuf, cardindex, 0);
cardindex++;
sync = 1;
break;
case 2: //The2TOfTheNonSynchronousState,ItIsImpossibleToOccur,ReportAnError
return 0;
default:
return 0;
}
break;
}
if (cardindex >= CARD_BUF_SIZE * 8)
break;
}
return 1;
}

uint8_t lf_read_decoder(uint8_t *pData, uint8_t size, uint8_t *pOut) {
return 0;
}

void lf_read_encoder(uint8_t *pData, uint8_t *pOut) {
#ifdef EM410X_Encoder_NRF_LOG_INFO
NRF_LOG_INFO("%d ", count1 % 2);
NRF_LOG_INFO(" <- Qi Dian verification : Tail code -> 0\n\n");
#endif // EM410X_Encoder_NRF_LOG_INFO
}

// Reading the card function, you need to stop calling, return 0 to read the card, 1 is to read
uint8_t em410x_acquire2(void) {
if (dataindex >= RAW_BUF_SIZE * 8) {
#ifdef debug410x
{
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 < RAW_BUF_SIZE * 8; i++) {
NRF_LOG_INFO("%d ", databuf[i]);
}
NRF_LOG_INFO("///time data\r\n");
}
#endif
//Looking for goals 0 1111 1111
carddata.startbit = 255;
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++) {
carddata.startbit += (uint8_t)readbit(carddata.rawa, carddata.rawb, i + j);
}
if (carddata.startbit == 0) {
carddata.startbit = i;
break;
} else {
carddata.startbit = 255;
}
}
}
// If you find the right beginning to deal with it
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 (mcst2(&carddata) == 1) {
//Card normal analysis
#ifdef debug410x
{
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, CARD_BUF_SIZE, lf_cardbuf)) {
//Card data check passes
#ifdef debug410x
for (int i = 0; i < 5; i++) {
NRF_LOG_INFO("%02X", (int)lf_cardbuf[i]);
}
NRF_LOG_INFO("///card dataBYTE\r\n");
#endif
dataindex = 0;
return 1;
}
}
}
// Start a new cycle
dataindex = 0;
}
return 0;
}

//GPIO interrupt recovery function is used to detect the descending edge
void GPIO_INT0_cb(void) {
if (dataindex < sizeof(databuf)) {
uint32_t cntr = get_lf_counter_value();
if (cntr > 0xff)
databuf[dataindex] = 0xff;
else
databuf[dataindex] = cntr & 0xff;
dataindex++;
}

clear_lf_counter_value();
}

void lf_read_init_hw(void) {
register_rio_callback(GPIO_INT0_cb);
}

uint8_t lf_read_reader(uint8_t *uid, uint32_t timeout_ms) {
dataindex = 0;
memset(databuf, 0, sizeof(databuf));

lf_read_init_hw();
start_lf_125khz_radio();

autotimer *p_at = bsp_obtain_timer(0);
while (NO_TIMEOUT_1MS(p_at, 500)) {
if (dataindex >= sizeof(databuf)) {

break;
}

}

stop_lf_125khz_radio();

bsp_return_timer(p_at);
p_at = NULL;

if (dataindex > 0) {
NRF_LOG_INFO("--> data [%d]", dataindex);
NRF_LOG_HEXDUMP_INFO(databuf, dataindex - 1);
} else {
NRF_LOG_INFO("--> data empty");
}

NRF_LOG_INFO("--> protocols count: %d", lfrfid_protocols_size);
for (int i = 0; i < lfrfid_protocols_size; i++) {
void* data = lfrfid_protocols[i]->alloc();
NRF_LOG_INFO("-- protocol: %s %s", lfrfid_protocols[i]->manufacturer, lfrfid_protocols[i]->name);

lfrfid_protocols[i]->decoder.decode(data, databuf, dataindex - 1);

lfrfid_protocols[i]->free(data);
}

NRF_LOG_INFO("--> read done.");

return 0;
}
25 changes: 25 additions & 0 deletions firmware/application/src/rfid/reader/lf/lf_read.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef __LF_READ_H__
#define __LF_READ_H__


#include "data_utils.h"
#include "bsp_time.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define LF_CARD_BUF_SIZE (512)

void lf_read_init_hw(void);
void lf_read_encoder(uint8_t *pData, uint8_t *pOut);
uint8_t lf_read_decoder(uint8_t *pData, uint8_t size, uint8_t *pOut);
uint8_t lf_read_reader(uint8_t *uid, uint32_t timeout_ms);


#ifdef __cplusplus
}
#endif

#endif
9 changes: 9 additions & 0 deletions firmware/application/src/rfid/reader/lf/lf_reader_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "bsp_delay.h"
#include "lf_reader_main.h"
#include "lf_125khz_radio.h"
#include "lf_read.h"


#define NRF_LOG_MODULE_NAME lf_main
Expand Down Expand Up @@ -105,6 +106,14 @@ uint8_t PcdWriteT55XX(uint8_t *uid, uint8_t *newkey, uint8_t *old_keys, uint8_t
return STATUS_LF_TAG_OK;
}

uint8_t lf_reader_read(uint8_t *data, size_t buffer_len) {
uint8_t ret = STATUS_LF_TAG_NO_FOUND;
if (lf_read_reader(data, g_timeout_readem_ms) == 1) {
ret = STATUS_LF_TAG_OK;
}
return ret;
}

/**
* Set the time value of the card search timeout of the EM card
*/
Expand Down
3 changes: 3 additions & 0 deletions firmware/application/src/rfid/reader/lf/lf_reader_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _LFCOPIER_H_

#include <stdint.h>
#include <stddef.h>


#include "lf_em410x_data.h"
Expand All @@ -15,4 +16,6 @@ void SetEMScanTagTimeout(uint32_t ms);
uint8_t PcdScanEM410X(uint8_t *uid);
uint8_t PcdWriteT55XX(uint8_t *uid, uint8_t *newkey, uint8_t *old_keys, uint8_t old_key_count);

uint8_t lf_reader_read(uint8_t *data, size_t buffer_len);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <nordic_common.h>
#include "lfrfid_protocols.h"
#include "protocol_em4100.h"
/*#include "protocol_h10301.h"
#include "protocol_idteck.h"
#include "protocol_indala26.h"
#include "protocol_io_prox_xsf.h"
#include "protocol_awid.h"
#include "protocol_fdx_a.h"
#include "protocol_fdx_b.h"
#include "protocol_hid_generic.h"
#include "protocol_hid_ex_generic.h"
#include "protocol_pyramid.h"
#include "protocol_viking.h"
#include "protocol_jablotron.h"
#include "protocol_paradox.h"
#include "protocol_pac_stanley.h"
#include "protocol_keri.h"
#include "protocol_gallagher.h"
#include "protocol_nexwatch.h"*/

const ProtocolBase* lfrfid_protocols[] = {
[LFRFIDProtocolEM4100] = &protocol_em4100,
[LFRFIDProtocolEM410032] = &protocol_em4100_32,
[LFRFIDProtocolEM410016] = &protocol_em4100_16,
/* [LFRFIDProtocolH10301] = &protocol_h10301,
[LFRFIDProtocolIdteck] = &protocol_idteck,
[LFRFIDProtocolIndala26] = &protocol_indala26,
[LFRFIDProtocolIOProxXSF] = &protocol_io_prox_xsf,
[LFRFIDProtocolAwid] = &protocol_awid,
[LFRFIDProtocolFDXA] = &protocol_fdx_a,
[LFRFIDProtocolFDXB] = &protocol_fdx_b,
[LFRFIDProtocolHidGeneric] = &protocol_hid_generic,
[LFRFIDProtocolHidExGeneric] = &protocol_hid_ex_generic,
[LFRFIDProtocolPyramid] = &protocol_pyramid,
[LFRFIDProtocolViking] = &protocol_viking,
[LFRFIDProtocolJablotron] = &protocol_jablotron,
[LFRFIDProtocolParadox] = &protocol_paradox,
[LFRFIDProtocolPACStanley] = &protocol_pac_stanley,
[LFRFIDProtocolKeri] = &protocol_keri,
[LFRFIDProtocolGallagher] = &protocol_gallagher,
[LFRFIDProtocolNexwatch] = &protocol_nexwatch,*/
};

size_t lfrfid_protocols_size = ARRAY_SIZE(lfrfid_protocols);
Loading
Loading