From f087591d5921b64f2c589ea9c608cfea61decd31 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Feb 2016 21:11:56 +0100 Subject: [PATCH] FIX: calcs wiegand correct, adds wiegand parity correct, adds checksum correct, add even parity to blocks correct. - when ran it clones nice, the "lf search" finds a pyramid och checksom is ok. However, the wiegand decode is wrong. Something about where in bitarray to put the startformat bit and wiegand bits... --- client/cmdlfpyramid.c | 69 ++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index 23c44059..c1c23729 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -48,29 +48,35 @@ int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) { uint8_t pre[128]; memset(pre, 0x00, sizeof(pre)); - // add preamble - pyramidBits[7]=1; - num_to_bytebits(26, 8, pre); - - // get wiegand - uint8_t wiegand[24]; + // format start bit + + // Get 26 wiegand from FacilityCode, CardNumber + uint8_t wiegand[26]; num_to_bytebits(fc, 8, wiegand); num_to_bytebits(cn, 16, wiegand+8); - // add wiegand parity bits - wiegand_add_parity(pre+8, wiegand, 24); + // add wiegand parity bits (dest, source, len) + wiegand_add_parity(pre+71, wiegand, 26); - // add paritybits - addParity(pre, pyramidBits+8, 66, 4, 1); + // add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,) + addParity(pre+8, pyramidBits+8, 112, 8, 1); // add checksum - // this is wrong. - uint32_t crc = CRC8Maxim(wiegand, 13); - num_to_bytebits(crc, 8, pre+120); - + uint8_t csBuff[13]; + for (uint8_t i = 0; i < 13; i++) + csBuff[i] = bytebits_to_byte(pyramidBits + 16 + (i*8), 8); + + uint32_t crc = CRC8Maxim(csBuff, 13); + num_to_bytebits(crc, 8, pyramidBits+120); return 1; } +/* +9 - 00001001 +33278 - 1000000111111110 + 10000100110000001 +000101010101010101010101082602 +*/ int CmdPyramidRead(const char *Cmd) { // read lf silently CmdLFRead("s"); @@ -85,28 +91,25 @@ int CmdPyramidClone(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_clone(); - uint32_t facilitycode=0, cardnumber=0; + uint32_t facilitycode=0, cardnumber=0, fc = 0, cn = 0; + uint8_t bits[128]; uint8_t *bs = bits; - memset(bs,0,sizeof(bits)); + memset(bs, 0x00, sizeof(bits)); + //Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks uint32_t blocks[5] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4<