Rework Cmd exposed API, use more static and fix [-Wmissing-prototypes], ongoing...

This commit is contained in:
Philippe Teuwen 2019-04-12 00:38:54 +02:00
commit 7d48ad19f9
42 changed files with 865 additions and 872 deletions

View file

@ -45,63 +45,6 @@ static int usage_lf_pyramid_sim(void) {
return 0;
}
// by marshmellow
// FSK Demod then try to locate a Farpointe Data (pyramid) ID
int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx) {
//make sure buffer has data
if (*size < 128 * 50) return -1;
//test samples are not just noise
if (getSignalProperties()->isnoise) return -2;
// FSK demodulator RF/50 FSK 10,8
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // pyramid fsk2
//did we get a good demod?
if (*size < 128) return -3;
size_t startIdx = 0;
uint8_t preamble[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
// wrong size? (between to preambles)
if (*size != 128) return -5;
return (int)startIdx;
}
// Works for 26bits.
static int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
// format start bit
pre[79] = 1;
// Get 26 wiegand from FacilityCode, CardNumber
uint8_t wiegand[24];
memset(wiegand, 0x00, sizeof(wiegand));
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 16, wiegand + 8);
// add wiegand parity bits (dest, source, len)
wiegand_add_parity(pre + 80, wiegand, 24);
// add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
addParity(pre + 8, pyramidBits + 8, 102, 8, 1);
// add checksum
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;
}
//by marshmellow
//Pyramid Prox demod - FSK RF/50 with preamble of 0000000000000001 (always a 128 bit data stream)
//print full Farpointe Data/Pyramid Prox ID and some bit format details if found
@ -269,7 +212,7 @@ int CmdPyramidClone(const char *Cmd) {
facilitycode = (fc & 0x000000FF);
cardnumber = (cn & 0x0000FFFF);
if (!GetPyramidBits(facilitycode, cardnumber, bs)) {
if (!getPyramidBits(facilitycode, cardnumber, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@ -327,7 +270,7 @@ int CmdPyramidSim(const char *Cmd) {
facilitycode = (fc & 0x000000FF);
cardnumber = (cn & 0x0000FFFF);
if (!GetPyramidBits(facilitycode, cardnumber, bs)) {
if (!getPyramidBits(facilitycode, cardnumber, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@ -361,3 +304,65 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// Works for 26bits.
int getPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
// format start bit
pre[79] = 1;
// Get 26 wiegand from FacilityCode, CardNumber
uint8_t wiegand[24];
memset(wiegand, 0x00, sizeof(wiegand));
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 16, wiegand + 8);
// add wiegand parity bits (dest, source, len)
wiegand_add_parity(pre + 80, wiegand, 24);
// add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
addParity(pre + 8, pyramidBits + 8, 102, 8, 1);
// add checksum
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;
}
int demodPyramid(void) {
return CmdPyramidDemod("");
}
// by marshmellow
// FSK Demod then try to locate a Farpointe Data (pyramid) ID
int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx) {
//make sure buffer has data
if (*size < 128 * 50) return -1;
//test samples are not just noise
if (getSignalProperties()->isnoise) return -2;
// FSK demodulator RF/50 FSK 10,8
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // pyramid fsk2
//did we get a good demod?
if (*size < 128) return -3;
size_t startIdx = 0;
uint8_t preamble[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
// wrong size? (between to preambles)
if (*size != 128) return -5;
return (int)startIdx;
}