Skip to content

Commit

Permalink
Calculate picopass CRC dynamically (#1389)
Browse files Browse the repository at this point in the history
Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
bettse and skotopes authored Jul 17, 2022
1 parent 6ac1ed2 commit c29ab50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/ST25RFAL002/include/rfal_picopass.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
#include "platform.h"
#include "rfal_rf.h"
#include "rfal_crc.h"
#include "st_errno.h"

#define RFAL_PICOPASS_UID_LEN 8
Expand Down
24 changes: 6 additions & 18 deletions lib/ST25RFAL002/source/rfal_picopass.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,12 @@ ReturnCode rfalPicoPassPollerCheck(uint8_t* mac, rfalPicoPassCheckRes* chkRes) {

ReturnCode rfalPicoPassPollerReadBlock(uint8_t blockNum, rfalPicoPassReadBlockRes* readRes) {
ReturnCode ret;
/*
* ./reveng -w 16 -s 0c07cc47 0c064556 0c083bbf 0c09b2ae
width=16 poly=0x1021 init=0xd924 refin=true refout=true xorout=0x0000 check=0x1329 residue=0x0000 name=(none)
0c 06 45 56
0c 07 cc 47
0c 08 3b bf
0c 09 b2 ae
*/

uint8_t readCmds[4][4] = {
{RFAL_PICOPASS_CMD_READ, 6, 0x45, 0x56},
{RFAL_PICOPASS_CMD_READ, 7, 0xcc, 0x47},
{RFAL_PICOPASS_CMD_READ, 8, 0x3b, 0xbf},
{RFAL_PICOPASS_CMD_READ, 9, 0xb2, 0xae}};

uint8_t* txBuf = readCmds[blockNum - 6];

uint8_t txBuf[4] = {RFAL_PICOPASS_CMD_READ, 0, 0, 0};
txBuf[1] = blockNum;
uint16_t crc = rfalCrcCalculateCcitt(0xE012, txBuf + 1, 1);
memcpy(txBuf + 2, &crc, sizeof(uint16_t));

uint16_t recvLen = 0;
uint32_t flags = RFAL_PICOPASS_TXRX_FLAGS;
uint32_t fwt = rfalConvMsTo1fc(20);
Expand All @@ -166,7 +156,5 @@ ReturnCode rfalPicoPassPollerReadBlock(uint8_t blockNum, rfalPicoPassReadBlockRe
&recvLen,
flags,
fwt);
// printf("check rx: %d %s\n", recvLen, hex2Str(readRes->data, RFAL_PICOPASS_MAX_BLOCK_LEN));

return ret;
}

0 comments on commit c29ab50

Please sign in to comment.