diff --git a/.gitattributes b/.gitattributes index bae55fcce..de1ad82c8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,15 @@ # .gitattributes + # prevent binary files from CRLF handling, diff and merge: fpga/fpga.bit -crlf -diff *.bin -crlf -diff *.z -crlf -diff - \ No newline at end of file + +# Force LF +*.c text=auto eol=lf +*.cpp text=auto eol=lf +*.h text=auto eol=lf +*.lua text=auto eol=lf +*.py text=auto eol=lf +*.pl text=auto eol=lf +Makefile text=auto eol=lf diff --git a/.gitignore b/.gitignore index 9a12efbe5..38058230d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ *.exe *.dsym version.c +*.json !client/hardnested/*.bin !client/hardnested/tables/*.z diff --git a/CHANGELOG.md b/CHANGELOG.md index 95c590a52..bbdb1e03c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,29 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - *WIP* Add FPC usart with pm3 client: WITH_FPC_HOST. (@doegox) + - Add '-b baudrate' option to the pm3 client. (@doegox) + - Change 'lf t55xx info': tell if known configuration block0. (@iceman) + - Fix/Add FPC usart: fix TX, bring RX, full speed. (@doegox) + - Change 'lf t55xx config' options: allow to toggle on/off i/q5/st + - Change 'lf t55xx info': support offline block0, Q5, fix extended, add warns. (@doegox) + - Avoid race condition when flasher finds the not yet closed pm3 port. (@doegox) + - Fix 'lf t55xx trace': read the proper block. (@doegox) + - Fix Indala 64 on T55xx: use PSK1. (@doegox) + - Force proper Linefeed (LF) handling in ProxSpace. (@vratiskol) + - Fix Makefiles race conditions to allow parallel compilation, e.g. 'make -j8'. (@doegox) + - Add - dictionary key file for MFU. (not in use at the moment) (@mazodude) + - Change 'lf fdx demod - better biphase maxerrors. (@MalteHillmann) + - Change 'hf mf sim' - now works better against android (@mceloff) + - Fix 'lf t55xx brute' - now works after aquiredata adaptations (@iceman) + - Fix 'lf t55xx chk' - now works after aquiredata adaptations (@iceman) + - Fix 'lf t55xx recoverpwd' - now works after aquiredata adaptations (@iceman) + - Fix 'data detect p' - reverted bad clock detection (@iceman) + - Change 'data detect a' - better clock detection (@iceman) + - Add 'hf 14a info' - now detects some magic card Gen2 (@iceman) + - Removed 'LCD' code in armsrc compilation (@iceman) + - Change - Generic fixes of codestyle (@doegox) (@iceman) + - Change 'lf indala demod' - refactoring (@iceman) - Change - handling fault bit markers (7) and partial nibbles in hex printing (@doegox) - Change - printing of fault bit markers (7) using a dot (@doegox) - Change 'sc upgrade' - firmware file integrity check (@piwi) diff --git a/Makefile b/Makefile index 327d1ab6d..2ad01ba5f 100644 --- a/Makefile +++ b/Makefile @@ -128,7 +128,7 @@ style: @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 ) # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ - -exec perl -pi -e 's/[ \t\r]+$$//' {} \; \ + -exec perl -pi -e 's/[ \t]+$$//' {} \; \ -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \ -exec sh -c "echo >> {}" \; # Apply astyle on *.c, *.h, *.cpp diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 9236df6ff..c1967663e 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -632,7 +632,6 @@ void ListenReaderField(int limit) { void UsbPacketReceived(uint8_t *packet, int len) { UsbCommand *c = (UsbCommand *)packet; - //Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d", len, c->cmd, c->arg[0], c->arg[1], c->arg[2]); switch (c->cmd) { @@ -1105,29 +1104,32 @@ void UsbPacketReceived(uint8_t *packet, int len) { */ - char dest[USB_CMD_DATA_SIZE] = { '\0' }; - static const char *welcome = "Proxmark3 Serial interface via FPC ready\n"; - strncat(dest, welcome, sizeof(dest) - strlen(dest) - 1); - sprintf(dest + strlen(dest) - 1, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x \n" + char dest[USB_CMD_DATA_SIZE] = {'\0'}; + if (usart_dataavailable()) { + Dbprintf("RX DATA!"); + uint16_t len = usart_readbuffer((uint8_t *)dest); + dest[len] = '\0'; + Dbprintf("RX: %d | %02X %02X %02X %02X %02X %02X %02X %02X ", len, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]); + } + + static const char *welcome = "Proxmark3 Serial interface via FPC ready\r\n"; + usart_writebuffer((uint8_t *)welcome, strlen(welcome)); + + sprintf(dest, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x\r\n" , c->d.asBytes[0] , c->d.asBytes[1] , c->d.asBytes[2] , c->d.asBytes[3] ); + usart_writebuffer((uint8_t *)dest, strlen(dest)); - UsbCommand txcmd = { CMD_DEBUG_PRINT_STRING, { strlen(dest), 0, 0 } }; - memcpy(txcmd.d.asBytes, dest, sizeof(dest)); LED_A_ON(); - usart_init(); - usart_writebuffer((uint8_t *)&txcmd, sizeof(UsbCommand)); //usb cmd_send(CMD_DEBUG_PRINT_STRING, strlen(dest), 0, 0, dest, strlen(dest)); LED_A_OFF(); - - /* uint8_t my_rx[sizeof(UsbCommand)]; while (!BUTTON_PRESS() && !usb_poll_validate_length()) { @@ -1136,13 +1138,12 @@ void UsbPacketReceived(uint8_t *packet, int len) { //UsbPacketReceived(my_rx, sizeof(my_rx)); UsbCommand *my = (UsbCommand *)my_rx; - if (mc->cmd > 0 ) { + if (my->cmd > 0 ) { Dbprintf("received command: 0x%04x and args: %d %d %d", my->cmd, my->arg[0], my->arg[1], my->arg[2]); } } } */ - //cmd_send(CMD_DEBUG_PRINT_STRING, strlen(dest), 0, 0, dest, strlen(dest)); cmd_send(CMD_ACK, 0, 0, 0, 0, 0); @@ -1558,17 +1559,19 @@ void __attribute__((noreturn)) AppMain(void) { // Check if there is a usb packet available if (usb_poll_validate_length()) { - if (usb_read(rx, sizeof(rx))) + if (usb_read(rx, sizeof(rx))) { +#ifdef WITH_FPC_HOST + reply_via_fpc = 0; +#endif UsbPacketReceived(rx, sizeof(rx)); + } + } +#ifdef WITH_FPC_HOST + // Check if there is a FPC packet available + if (usart_readcommand(rx) > 0) { + reply_via_fpc = 1; + UsbPacketReceived(rx, sizeof(rx)); } -#ifdef WITH_FPC - // Check is there is FPC package available - /* - usart_init(); - if (usart_readbuffer(rx, sizeof(rx)) ) - UsbPacketReceived(rx, sizeof(rx) ); - */ - #endif // Press button for one second to enter a possible standalone mode diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 0c602e00b..43c1bd831 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -138,7 +138,7 @@ static void hitag_send_bit(int bit) { static void hitag_send_frame(const uint8_t *frame, size_t frame_len) { // SOF - send start of frame - hitag_send_bit(1); + hitag_send_bit(1); hitag_send_bit(1); hitag_send_bit(1); hitag_send_bit(1); @@ -399,10 +399,10 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size break; case WRITE_STATE_PAGENUM_WRITTEN: // Check if page number was received correctly - if ( (rxlen == 10) - && (rx[0] == (0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2))) - && (rx[1] == (((blocknr & 0x3) ^ 0x3) << 6))) { - + if ((rxlen == 10) + && (rx[0] == (0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2))) + && (rx[1] == (((blocknr & 0x3) ^ 0x3) << 6))) { + *txlen = 32; memset(tx, 0, HITAG_FRAME_LEN); memcpy(tx, writedata, 4); @@ -1280,7 +1280,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) { // Receive frame, watch for at most T0*EOF periods while (AT91C_BASE_TC1->TC_CV < T0 * HITAG_T_WAIT_MAX) { - + // Check if falling edge in tag modulation is detected if (AT91C_BASE_TC1->TC_SR & AT91C_TC_LDRAS) { // Retrieve the new timing values diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index ec208de6a..ae1a22a15 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -2980,4 +2980,4 @@ void DetectNACKbug() { void AppendCrc14443a(uint8_t *data, int len) { compute_crc(CRC_14443_A, data, len, data + len, data + len + 1); -} \ No newline at end of file +} diff --git a/armsrc/lfops.c b/armsrc/lfops.c index a40e5e977..1e6f22863 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -1529,7 +1529,7 @@ void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd) { // Turn field on to read the response // 137*8 seems to get to the start of data pretty well... // but we want to go past the start and let the repeating data settle in... - TurnReadLFOn(200 * 8); + TurnReadLFOn(150 * 8); // Acquisition // Now do the acquisition @@ -1731,14 +1731,15 @@ void CopyIOtoT55x7(uint32_t hi, uint32_t lo) { // Clone Indala 64-bit tag by UID to T55x7 void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) { //Program the 2 data blocks for supplied 64bit UID - // and the Config for Indala 64 format (RF/32;PSK2 with RF/2;Maxblock=2) - uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK2 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo}; + // and the Config for Indala 64 format (RF/32;PSK1 with RF/2;Maxblock=2) + uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo}; //TODO add selection of chip for Q5 or T55x7 - // data[0] = T5555_SET_BITRATE(32 | T5555_MODULATION_PSK2 | 2 << T5555_MAXBLOCK_SHIFT; - + // data[0] = T5555_SET_BITRATE(32 | T5555_MODULATION_PSK1 | 2 << T5555_MAXBLOCK_SHIFT; + LED_D_ON(); WriteT55xx(data, 0, 3); - //Alternative config for Indala (Extended mode;RF/32;PSK2 with RF/2;Maxblock=2;Inverse data) + //Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=2;Inverse data) // T5567WriteBlock(0x603E1042,0); + LED_D_OFF(); } // Clone Indala 224-bit tag by UID to T55x7 void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7) { @@ -1749,9 +1750,11 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t data[0] = T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK2 | (7 << T55x7_MAXBLOCK_SHIFT); //TODO add selection of chip for Q5 or T55x7 // data[0] = T5555_SET_BITRATE(32 | T5555_MODULATION_PSK2 | 7 << T5555_MAXBLOCK_SHIFT; + LED_D_ON(); WriteT55xx(data, 0, 8); - //Alternative config for Indala (Extended mode;RF/32;PSK2 with RF/2;Maxblock=7;Inverse data) + //Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=7;Inverse data) // T5567WriteBlock(0x603E10E2,0); + LED_D_OFF(); } // clone viking tag to T55xx void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5) { diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 65f0bdb22..f6b7692e2 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1938,13 +1938,13 @@ void MifareCIdent() { uint8_t *buf = BigBuf_malloc(USB_CMD_DATA_SIZE); uint8_t *uid = BigBuf_malloc(10); uint32_t cuid = 0; - + iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); // Generation 1 test ReaderTransmitBitsPar(wupC1, 7, NULL, NULL); if (!ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) { - goto TEST2; + goto TEST2; }; isGen = GEN_1B; @@ -1960,10 +1960,10 @@ TEST2: FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); SpinDelay(100); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); - + int res = iso14443a_select_card(uid, NULL, &cuid, true, 0, true); - if ( res == 2 ) { - ReaderTransmit(rats, sizeof(rats), NULL); + if (res == 2) { + ReaderTransmit(rats, sizeof(rats), NULL); res = ReaderReceive(buf, par); if (memcmp(buf, "\x09\x78\x00\x91\x02\xDA\xBC\x19\x10\xF0\x05", 11) == 0) { isGen = GEN_2; @@ -1973,7 +1973,7 @@ TEST2: isGen = GEN_2; } }; - + OUT: cmd_send(CMD_ACK, isGen, 0, 0, 0, 0); // turns off diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index d0edc2698..a308853e7 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -137,15 +137,15 @@ bool IsBlock0PCF7931(uint8_t *block) { bool IsBlock1PCF7931(uint8_t *block) { // assuming all RFU bits are set to 0 if (block[10] == 0 - && block[11] == 0 - && block[12] == 0 - && block[13] == 0) { - - if ( (block[14] & 0x7f) <= 9 - && block[15] <= 9) { - return true; - } + && block[11] == 0 + && block[12] == 0 + && block[13] == 0) { + + if ((block[14] & 0x7f) <= 9 + && block[15] <= 9) { + return true; } + } return false; } diff --git a/client/Makefile b/client/Makefile index ec12dedca..bcd443219 100644 --- a/client/Makefile +++ b/client/Makefile @@ -282,8 +282,7 @@ ifeq "$(SUPPORTS_AVX512)" "True" endif BINS = proxmark3 flasher fpga_compress -WINBINS = $(patsubst %, %.exe, $(BINS)) -CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/usb_cmd.lua lualibs/mf_default_keys.lua +CLEAN = $(BINS) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/usb_cmd.lua lualibs/mf_default_keys.lua # need to assign dependancies to build these first... all: lua_build jansson_build mbedtls_build cbor_build $(BINS) @@ -347,28 +346,28 @@ cbor_build: print-%: ; @echo $* = $($*) $(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%_NOSIMD.d - $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< - $(POSTCOMPILE:%.d=%_NOSIMD.d) + $(CC) $(DEPFLAGS:%.Td=%_NOSIMD.Td) $(CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< + $(MV) -f $(OBJDIR)/$*_NOSIMD.Td $(OBJDIR)/$*_NOSIMD.d $(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%_MMX.d - $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< - $(POSTCOMPILE:%.d=%_MMX.d) + $(CC) $(DEPFLAGS:%.Td=%_MMX.Td) $(CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< + $(MV) -f $(OBJDIR)/$*_MMX.Td $(OBJDIR)/$*_MMX.d $(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%_SSE2.d - $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< - $(POSTCOMPILE:%.d=%_SSE2.d) + $(CC) $(DEPFLAGS:%.Td=%_SSE2.Td) $(CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< + $(MV) -f $(OBJDIR)/$*_SSE2.Td $(OBJDIR)/$*_SSE2.d $(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%_AVX.d - $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< - $(POSTCOMPILE:%.d=%_AVX.d) + $(CC) $(DEPFLAGS:%.Td=%_AVX.Td) $(CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< + $(MV) -f $(OBJDIR)/$*_AVX.Td $(OBJDIR)/$*_AVX.d $(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%_AVX2.d - $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< - $(POSTCOMPILE:%.d=%_AVX2.d) + $(CC) $(DEPFLAGS:%.Td=%_AVX2.Td) $(CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< + $(MV) -f $(OBJDIR)/$*_AVX2.Td $(OBJDIR)/$*_AVX2.d $(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%_AVX512.d - $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< - $(POSTCOMPILE:%.d=%_AVX512.d) + $(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< + $(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d %.o: %.c $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d diff --git a/client/cmdcrc.c b/client/cmdcrc.c index 178df6add..7b1819c0e 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -93,7 +93,7 @@ int GetModels(char *Models[], int *count, uint8_t *width) { PrintAndLogEx(WARNING, "out of memory?"); return 0; } - if ( model.name != NULL ) { + if (model.name != NULL) { memcpy(tmp, model.name, size); Models[mode] = tmp; width[mode] = plen(model.spoly); diff --git a/client/cmddata.c b/client/cmddata.c index 146d30ba7..c76ccdf93 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -459,7 +459,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &); - + if (!maxLen) maxLen = BIGBUF_SIZE; if (invert != 0 && invert != 1) { @@ -486,17 +486,17 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, if (amp == 'a') { askAmp(bits, BitLen); } - + size_t ststart = 0, stend = 0; // if (*stCheck) bool st = DetectST(bits, &BitLen, &foundclk, &ststart, &stend); - if ( clk == 0 ) { - if ( foundclk == 32 || foundclk == 64 ) { + if (clk == 0) { + if (foundclk == 32 || foundclk == 64) { clk = foundclk; } } - + if (st) { *stCheck = st; CursorCPos = ststart; @@ -615,12 +615,15 @@ int Cmdmandecoderaw(const char *Cmd) { return 1; } -//by marshmellow -//biphase decode -//take 01 or 10 = 0 and 11 or 00 = 1 -//takes 2 arguments "offset" default = 0 if 1 it will shift the decode by one bit -// and "invert" default = 0 if 1 it will invert output -// the argument offset allows us to manually shift if the output is incorrect - [EDIT: now auto detects] +/* + * @author marshmellow + * biphase decode + * decodes 01 or 10 -> ZERO + * 11 or 00 -> ONE + * param offset adjust start position + * param invert invert output + * param masxErr maximum tolerated errors + */ int CmdBiphaseDecodeRaw(const char *Cmd) { size_t size = 0; int offset = 0, invert = 0, maxErr = 20, errCnt = 0; @@ -1095,9 +1098,9 @@ int CmdFSKrawdemod(const char *Cmd) { //attempt to psk1 demod graph buffer int PSKDemod(const char *Cmd, bool verbose) { int invert = 0, clk = 0, maxErr = 100; - + sscanf(Cmd, "%i %i %i", &clk, &invert, &maxErr); - + if (clk == 1) { invert = 1; clk = 0; @@ -1112,9 +1115,9 @@ int PSKDemod(const char *Cmd, bool verbose) { uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; size_t bitlen = getFromGraphBuf(bits); - if (bitlen == 0) + if (bitlen == 0) return 0; - + int startIdx = 0; int errCnt = pskRawDemod_ext(bits, &bitlen, &clk, &invert, &startIdx); if (errCnt > maxErr) { @@ -1317,7 +1320,7 @@ int CmdRawDemod(const char *Cmd) { void setClockGrid(int clk, int offset) { g_DemodStartIdx = offset; g_DemodClock = clk; - if ( clk == 0 && offset == 0) + if (clk == 0 && offset == 0) PrintAndLogEx(DEBUG, "DEBUG: (setClockGrid) clear settings"); else PrintAndLogEx(DEBUG, "DEBUG: (setClockGrid) demodoffset %d, clk %d", offset, clk); diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 45fcbcb33..0894c578f 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -524,7 +524,7 @@ int CmdHF14AInfo(const char *Cmd) { (tb1 ? "" : " NOT"), (tc1 ? "" : " NOT"), fsci, - fsci < sizeof(atsFSC)/sizeof(atsFSC[0]) ? atsFSC[fsci] : -1 + fsci < sizeof(atsFSC) / sizeof(atsFSC[0]) ? atsFSC[fsci] : -1 ); } pos = 2; @@ -544,8 +544,8 @@ int CmdHF14AInfo(const char *Cmd) { ((card.ats[pos] & 0x80) ? " NOT" : ""), dr, ds - ); - + ); + pos++; } if (tb1) { @@ -959,7 +959,7 @@ int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) { // get frame length from ATS in data field if (resp.arg[0] > 1) { uint8_t fsci = resp.d.asBytes[1] & 0x0f; - if (fsci < sizeof(atsFSC)/sizeof(atsFSC[0])) + if (fsci < sizeof(atsFSC) / sizeof(atsFSC[0])) frameLength = atsFSC[fsci]; } } else { @@ -967,7 +967,7 @@ int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) { iso14a_card_select_t *vcard = (iso14a_card_select_t *) resp.d.asBytes; if (vcard->ats_len > 1) { uint8_t fsci = vcard->ats[1] & 0x0f; - if (fsci < sizeof(atsFSC)/sizeof(atsFSC[0])) + if (fsci < sizeof(atsFSC) / sizeof(atsFSC[0])) frameLength = atsFSC[fsci]; } @@ -1000,10 +1000,10 @@ int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activa // here length USB_CMD_DATA_SIZE=512 // timeout must be authomatically set by "get ATS" UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_APDU | ISO14A_NO_DISCONNECT | cmdc, (datainlen & 0xFFFF), 0}}; - - if ( datain ) + + if (datain) memcpy(c.d.asBytes, datain, datainlen); - + SendCommand(&c); uint8_t *recv; diff --git a/client/cmdhffelica.c b/client/cmdhffelica.c index dc9234001..39dbdbc9b 100644 --- a/client/cmdhffelica.c +++ b/client/cmdhffelica.c @@ -425,8 +425,8 @@ int CmdHFFelicaDumpLite(const char *Cmd) { } uint64_t tracelen = resp.arg[1]; - if (tracelen == 0) - return 1; + if (tracelen == 0) + return 1; uint8_t *trace = calloc(tracelen, sizeof(uint8_t)); if (trace == NULL) { @@ -444,14 +444,14 @@ int CmdHFFelicaDumpLite(const char *Cmd) { print_hex_break(trace, tracelen, 32); printSep(); - + uint16_t tracepos = 0; while (tracepos < tracelen) tracepos = PrintFliteBlock(tracepos, trace, tracelen); printSep(); - free(trace); + free(trace); return 0; } diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 4fd8b5b1f..39a25019c 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -785,7 +785,7 @@ int CmdHFiClassDecrypt(const char *Cmd) { saveFile(outfilename, "bin", decrypted, fsize); printIclassDumpContents(decrypted, 1, (fsize / 8), fsize); - free(decrypted); + free(decrypted); return 0; } diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index 7aa93f456..85920e813 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -169,7 +169,7 @@ int CmdLegicInfo(const char *Cmd) { int crc = 0, wrp = 0, wrc = 0; uint8_t stamp_len = 0; uint16_t datalen = 0; - char token_type[5] = {0, 0, 0, 0, 0}; + char token_type[6] = {0, 0, 0, 0, 0, 0}; int dcf = 0; int bIsSegmented = 0; @@ -1282,7 +1282,7 @@ int CmdLegicWipe(const char *Cmd) { } } PrintAndLogEx(SUCCESS, "ok\n"); - free(data); + free(data); return 0; } diff --git a/client/cmdhw.c b/client/cmdhw.c index d40e5db4c..4f17c682a 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -423,7 +423,7 @@ int CmdVersion(const char *Cmd) { #else PrintAndLogEx(NORMAL, "\n\e[34m [ Proxmark3 RFID instrument ]\e[0m\n"); #endif - char s[50] = {0}; + char s[60] = {0}; #if defined(WITH_FLASH) || defined(WITH_SMARTCARD) || defined(WITH_FPC) strncat(s, "build for RDV40 with ", sizeof(s) - strlen(s) - 1); #endif @@ -434,7 +434,11 @@ int CmdVersion(const char *Cmd) { strncat(s, "smartcard; ", sizeof(s) - strlen(s) - 1); #endif #ifdef WITH_FPC +#ifdef WITH_FPC_HOST + strncat(s, "fpc-host; ", sizeof(s) - strlen(s) - 1); +#else strncat(s, "fpc; ", sizeof(s) - strlen(s) - 1); +#endif #endif PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); PrintAndLogEx(NORMAL, " client: iceman %s \n", s); diff --git a/client/cmdlf.c b/client/cmdlf.c index 049edb824..263e73749 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -839,7 +839,7 @@ bool CheckChipType(bool getDeviceData) { //check for t55xx chip... if (tryDetectP1(true)) { - PrintAndLogEx(SUCCESS, "\nChipset detection : " _GREEN_("Atmel T55xx") " found"); + PrintAndLogEx(SUCCESS, "\nChipset detection : " _GREEN_("T55xx") " found"); PrintAndLogEx(SUCCESS, "Try " _YELLOW_("`lf t55xx`")" commands"); retval = true; goto out; diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index c0d24c0bb..166787ba4 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -344,7 +344,7 @@ int CmdLFHitagSim(const char *Cmd) { } static void printHitagConfiguration(uint8_t config) { - + char msg[100]; memset(msg, 0, sizeof(msg)); @@ -357,10 +357,10 @@ static void printHitagConfiguration(uint8_t config) { PrintAndLogEx(INFO, "\n\nHitag2 tag information "); PrintAndLogEx(INFO, "------------------------------------"); - + //configuration byte - PrintAndLogEx(SUCCESS, "Config byte : 0x%02X [ %s ]", config, bits); - + PrintAndLogEx(SUCCESS, "Config byte : 0x%02X [ %s ]", config, bits); + // encoding strcat(msg, "Encoding : "); if (config & 0x1) { @@ -415,7 +415,7 @@ static void printHitagConfiguration(uint8_t config) { memset(msg, 0, sizeof(msg)); // page access - strcat(msg, "Page 4,5 : "); + strcat(msg, "Page 4,5 : "); if (config & 0x20) { strcat(msg + strlen(msg), "read only"); } else { @@ -467,9 +467,9 @@ static bool getHitagUid(uint32_t *uid) { return false; } - if ( uid ) + if (uid) *uid = bytes_to_num(resp.d.asBytes, 4); - + return true; } @@ -480,18 +480,18 @@ int CmdLFHitagInfo(const char *Cmd) { char ctmp = tolower(param_getchar(Cmd, 0)); if (ctmp == 'h') return usage_hitag_info(); - + // pwd or key // read UID uint32_t uid = 0; - if ( getHitagUid( &uid ) == false ) + if (getHitagUid(&uid) == false) return 1; - + PrintAndLogEx(SUCCESS, "UID: %08X", uid); - + // how to detemine Hitag types? - + // read block3, get configuration byte. // common configurations. @@ -503,7 +503,7 @@ int CmdLFHitagInfo(const char *Cmd) { return 0; } -// TODO: iceman +// TODO: iceman // Hitag2 reader, problem is that this command mixes up stuff. So 26 give uid. 21 etc will also give you a memory dump !? // int CmdLFHitagReader(const char *Cmd) { @@ -568,8 +568,8 @@ int CmdLFHitagReader(const char *Cmd) { PrintAndLogEx(SUCCESS, "Valid Hitag2 tag found - UID: %08x", id); if (htf != RHT2F_UID_ONLY) { - - PrintAndLogEx(SUCCESS, "Dumping tag memory..." ); + + PrintAndLogEx(SUCCESS, "Dumping tag memory..."); uint8_t *data = resp.d.asBytes; char filename[FILE_PATH_SIZE]; @@ -580,9 +580,9 @@ int CmdLFHitagReader(const char *Cmd) { saveFile(filename, "bin", data, 48); saveFileEML(filename, "eml", data, 48, 4); saveFileJSON(filename, "json", jsfHitag, data, 48); - + // block3, 1 byte - printHitagConfiguration(data[4*3] ); + printHitagConfiguration(data[4 * 3]); } return 0; } diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index 64857d702..c6be8bd29 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -47,7 +47,7 @@ int usage_lf_indala_sim(void) { int usage_lf_indala_clone(void) { PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: lf indala clone [h] [Q5]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); @@ -64,27 +64,27 @@ int usage_lf_indala_clone(void) { // redesigned by marshmellow adjusted from existing decode functions // indala id decoding int detectIndala(uint8_t *dest, size_t *size, uint8_t *invert) { - - uint8_t preamble64_i[] = {0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; + + uint8_t preamble64_i[] = {0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; uint8_t preamble224_i[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; - + size_t idx = 0; size_t found_size = *size; - - // PSK1 + + // PSK1 bool res = preambleSearch(dest, preamble64, sizeof(preamble64), &found_size, &idx); - if ( res ) { + if (res) { PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK1 found 64"); goto out; } idx = 0; found_size = *size; res = preambleSearch(dest, preamble64_i, sizeof(preamble64_i), &found_size, &idx); - if ( res ) { + if (res) { PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK1 found 64 inverted preamble"); goto inv; } - + /* idx = 0; found_size = *size; @@ -93,12 +93,12 @@ int detectIndala(uint8_t *dest, size_t *size, uint8_t *invert) { PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK1 found 224"); goto out; } - + idx = 0; - found_size = *size; + found_size = *size; res = preambleSearch(dest, preamble224_i, sizeof(preamble224_i), &found_size, &idx); if ( res ) { - PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK1 found 224 inverted preamble"); + PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK1 found 224 inverted preamble"); goto inv; } */ @@ -106,41 +106,41 @@ int detectIndala(uint8_t *dest, size_t *size, uint8_t *invert) { // PSK2 psk1TOpsk2(dest, *size); PrintAndLogEx(DEBUG, "DEBUG: detectindala Converting PSK1 -> PSK2"); - + idx = 0; - found_size = *size; + found_size = *size; res = preambleSearch(dest, preamble64, sizeof(preamble64), &found_size, &idx); - if ( res ) { + if (res) { PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK2 found 64 preamble"); goto out; } - + idx = 0; found_size = *size; res = preambleSearch(dest, preamble224, sizeof(preamble224), &found_size, &idx); - if ( res ) { + if (res) { PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK2 found 224 preamble"); goto out; } - + idx = 0; - found_size = *size; + found_size = *size; res = preambleSearch(dest, preamble64_i, sizeof(preamble64_i), &found_size, &idx); - if ( res ) { + if (res) { PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK2 found 64 inverted preamble"); goto inv; } - + idx = 0; found_size = *size; res = preambleSearch(dest, preamble224_i, sizeof(preamble224_i), &found_size, &idx); - if ( res ) { + if (res) { PrintAndLogEx(DEBUG, "DEBUG: detectindala PSK2 found 224 inverted preamble"); goto inv; } - + inv: - if ( res == 0 ) { + if (res == 0) { return -4; } @@ -157,18 +157,18 @@ inv: out: *size = found_size; - + //PrintAndLogEx(INFO, "DEBUG: detectindala RES = %d | %d | %d", res, found_size, idx); - + if (found_size != 224 && found_size != 64) { - PrintAndLogEx(INFO, "DEBUG: detectindala | %d", found_size); + PrintAndLogEx(INFO, "DEBUG: detectindala | %d", found_size); return -5; } // 224 formats are typically PSK2 (afaik 2017 Marshmellow) // note loses 1 bit at beginning of transformation... - return (int) idx; - + return (int) idx; + } // this read is the "normal" read, which download lf signal and tries to demod here. @@ -210,12 +210,12 @@ int CmdIndalaDemod(const char *Cmd) { } setDemodBuf(DemodBuffer, size, idx); setClockGrid(g_DemodClock, g_DemodStartIdx + (idx * g_DemodClock)); - + //convert UID to HEX uint32_t uid1, uid2, uid3, uid4, uid5, uid6, uid7; uid1 = bytebits_to_byte(DemodBuffer, 32); uid2 = bytebits_to_byte(DemodBuffer + 32, 32); - uint64_t foo = (((uint64_t)uid1 << 32) & 0x1FFFFFFF ) | (uid2 & 0x7FFFFFFF ); + uint64_t foo = (((uint64_t)uid1 << 32) & 0x1FFFFFFF) | (uid2 & 0x7FFFFFFF); if (DemodBufferLen == 64) { PrintAndLogEx( @@ -225,40 +225,40 @@ int CmdIndalaDemod(const char *Cmd) { , uid1 , uid2 ); - + uint16_t p1 = 0; - p1 |= DemodBuffer[32+ 3] << 8; - p1 |= DemodBuffer[32+ 6] << 5; - p1 |= DemodBuffer[32+ 8] << 4; - p1 |= DemodBuffer[32+ 9] << 3; - p1 |= DemodBuffer[32+11] << 1; - p1 |= DemodBuffer[32+16] << 6; - p1 |= DemodBuffer[32+19] << 7; - p1 |= DemodBuffer[32+20] << 10; - p1 |= DemodBuffer[32+21] << 2; - p1 |= DemodBuffer[32+22] << 0; - p1 |= DemodBuffer[32+24] << 9; - -/* - uint16_t fc = 0; - fc |= DemodBuffer[32+ 1] << 0; - fc |= DemodBuffer[32+ 2] << 1; - fc |= DemodBuffer[32+ 4] << 2; - fc |= DemodBuffer[32+ 5] << 3; - fc |= DemodBuffer[32+ 7] << 4; - fc |= DemodBuffer[32+10] << 5; - fc |= DemodBuffer[32+14] << 6; - fc |= DemodBuffer[32+15] << 7; - fc |= DemodBuffer[32+17] << 8; -*/ - + p1 |= DemodBuffer[32 + 3] << 8; + p1 |= DemodBuffer[32 + 6] << 5; + p1 |= DemodBuffer[32 + 8] << 4; + p1 |= DemodBuffer[32 + 9] << 3; + p1 |= DemodBuffer[32 + 11] << 1; + p1 |= DemodBuffer[32 + 16] << 6; + p1 |= DemodBuffer[32 + 19] << 7; + p1 |= DemodBuffer[32 + 20] << 10; + p1 |= DemodBuffer[32 + 21] << 2; + p1 |= DemodBuffer[32 + 22] << 0; + p1 |= DemodBuffer[32 + 24] << 9; + + /* + uint16_t fc = 0; + fc |= DemodBuffer[32+ 1] << 0; + fc |= DemodBuffer[32+ 2] << 1; + fc |= DemodBuffer[32+ 4] << 2; + fc |= DemodBuffer[32+ 5] << 3; + fc |= DemodBuffer[32+ 7] << 4; + fc |= DemodBuffer[32+10] << 5; + fc |= DemodBuffer[32+14] << 6; + fc |= DemodBuffer[32+15] << 7; + fc |= DemodBuffer[32+17] << 8; + */ + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, "Possible de-scramble patterns"); PrintAndLogEx(SUCCESS, "\tPrinted | __%04d__ [0x%X]", p1, p1); //PrintAndLogEx(SUCCESS, "\tPrinted | __%04d__ [0x%X]", fc, fc); - PrintAndLogEx(SUCCESS, "\tInternal ID | %" PRIu64 , foo); - - + PrintAndLogEx(SUCCESS, "\tInternal ID | %" PRIu64, foo); + + } else { uid3 = bytebits_to_byte(DemodBuffer + 64, 32); uid4 = bytebits_to_byte(DemodBuffer + 96, 32); @@ -266,17 +266,17 @@ int CmdIndalaDemod(const char *Cmd) { uid6 = bytebits_to_byte(DemodBuffer + 160, 32); uid7 = bytebits_to_byte(DemodBuffer + 192, 32); PrintAndLogEx(SUCCESS, "Indala Found - bitlength %d, UID = 0x%x%08x%08x%08x%08x%08x%08x" - , DemodBufferLen - , uid1 - , uid2 - , uid3 - , uid4 - , uid5 - , uid6 - , uid7 - ); + , DemodBufferLen + , uid1 + , uid2 + , uid3 + , uid4 + , uid5 + , uid6 + , uid7 + ); } - + if (g_debugMode) { PrintAndLogEx(DEBUG, "DEBUG: Indala - printing demodbuffer"); printDemodBuff(); @@ -532,9 +532,9 @@ int CmdIndalaSim(const char *Cmd) { int CmdIndalaClone(const char *Cmd) { bool isLongUid = false; - uint8_t data[7*4]; + uint8_t data[7 * 4]; int datalen = 0; - + CLIParserInit("lf indala clone", "Enables cloning of Indala card with specified uid onto T55x7\n" "defaults to 64.\n", @@ -555,8 +555,8 @@ int CmdIndalaClone(const char *Cmd) { CLIGetHexWithReturn(2, data, &datalen); CLIParserFree(); - UsbCommand c = {0, {0,0,0}}; - + UsbCommand c = {0, {0, 0, 0}}; + if (isLongUid) { PrintAndLogEx(INFO, "Preparing to clone Indala 224bit tag with UID %s", sprint_hex(data, datalen)); c.cmd = CMD_INDALA_CLONE_TAG_L; @@ -569,11 +569,11 @@ int CmdIndalaClone(const char *Cmd) { c.d.asDwords[6] = bytes_to_num(data + 24, 4); } else { PrintAndLogEx(INFO, "Preparing to clone Indala 64bit tag with UID %s", sprint_hex(data, datalen)); - c.cmd = CMD_INDALA_CLONE_TAG; + c.cmd = CMD_INDALA_CLONE_TAG; c.d.asDwords[0] = bytes_to_num(data, 4); c.d.asDwords[1] = bytes_to_num(data + 4, 4); } - + clearCommandBuffer(); SendCommand(&c); return 0; diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 0fda6c683..199e639a9 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -41,8 +41,8 @@ int usage_lf_keri_sim(void) { // find KERI preamble in already demoded data int detectKeri(uint8_t *dest, size_t *size, bool *invert) { - uint8_t preamble[] = {1,1,1,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - uint8_t preamble_i[] = {0,0,0,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; + uint8_t preamble[] = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + uint8_t preamble_i[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; // sanity check. if (*size < sizeof(preamble) + 100) return -1; @@ -159,10 +159,10 @@ int CmdKeriClone(const char *Cmd) { // MSB is ONE internalid |= 0x80000000; - + // 3 LSB is ONE uint64_t data = ((uint64_t)internalid << 3) + 7; - PrintAndLogEx(INFO, "Preparing to clone KERI to T55x7 with Internal Id: %" PRIx64, internalid ); + PrintAndLogEx(INFO, "Preparing to clone KERI to T55x7 with Internal Id: %" PRIx64, internalid); // blocks[1] = data >> 32; diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index a2f5942ad..169c07194 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -237,11 +237,11 @@ int CmdPyramidDemod(const char *Cmd) { } PrintAndLogEx(DEBUG, "DEBUG: Pyramid: checksum : 0x%02X - %02X - %s" - , checksum - , checkCS - , (checksum == checkCS) ? _GREEN_("Passed") : _RED_("Failed") - ); - + , checksum + , checkCS + , (checksum == checkCS) ? _GREEN_("Passed") : _RED_("Failed") + ); + PrintAndLogEx(DEBUG, "DEBUG: Pyramid: idx: %d, Len: %d, Printing Demod Buffer:", idx, 128); if (g_debugMode) printDemodBuff(); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 4f187367a..3fcc4fdda 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -19,15 +19,15 @@ void Set_t55xx_Config(t55xx_conf_block_t conf) { } int usage_t55xx_config() { - PrintAndLogEx(NORMAL, "Usage: lf t55xx config [d ] [i 1] [o ] [Q5]"); + PrintAndLogEx(NORMAL, "Usage: lf t55xx config [d ] [i [0/1]] [o ] [Q5 [0/1]] [ST [0/1]]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - This help"); PrintAndLogEx(NORMAL, " b <8|16|32|40|50|64|100|128> - Set bitrate"); PrintAndLogEx(NORMAL, " d - Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A"); - PrintAndLogEx(NORMAL, " i [1] - Invert data signal, defaults to normal"); + PrintAndLogEx(NORMAL, " i [0/1] - Set/reset data signal inversion"); PrintAndLogEx(NORMAL, " o [offset] - Set offset, where data should start decode in bitstream"); - PrintAndLogEx(NORMAL, " Q5 - Set as Q5(T5555) chip instead of T55x7"); - PrintAndLogEx(NORMAL, " ST - Set Sequence Terminator on"); + PrintAndLogEx(NORMAL, " Q5 [0/1] - Set/reset as Q5(T5555) chip instead of T55x7"); + PrintAndLogEx(NORMAL, " ST [0/1] - Set/reset Sequence Terminator on"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf t55xx config d FSK - FSK demodulation"); @@ -81,13 +81,19 @@ int usage_t55xx_trace() { return 0; } int usage_t55xx_info() { - PrintAndLogEx(NORMAL, "Usage: lf t55xx info [1]"); + PrintAndLogEx(NORMAL, "Usage: lf t55xx info [1] [d [q]]"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer otherwise read data from tag."); + PrintAndLogEx(NORMAL, " (default) - read data from tag."); + PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer instead of reading tag."); + PrintAndLogEx(NORMAL, " d - 4 bytes of data (8 hex characters)"); + PrintAndLogEx(NORMAL, " if set, use these data instead of reading tag."); + PrintAndLogEx(NORMAL, " q - if set, provided data are interpreted as Q5 config."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf t55xx info"); PrintAndLogEx(NORMAL, " lf t55xx info 1"); + PrintAndLogEx(NORMAL, " lf t55xx info d 00083040"); + PrintAndLogEx(NORMAL, " lf t55xx info d 6001805A q"); PrintAndLogEx(NORMAL, ""); return 0; } @@ -144,8 +150,8 @@ int usage_t55xx_wakup() { int usage_t55xx_chk() { PrintAndLogEx(NORMAL, "This command uses a dictionary attack"); PrintAndLogEx(NORMAL, "press " _YELLOW_("'enter'") " to cancel the command"); - PrintAndLogEx(NORMAL, "WARNING: this may brick non-password protected chips!"); - PrintAndLogEx(NORMAL, "Try to reading block 7 before\n"); + PrintAndLogEx(NORMAL, "WARNING: this may brick non-password protected chips!"); + PrintAndLogEx(NORMAL, "Try to reading block 7 before\n"); PrintAndLogEx(NORMAL, "Usage: lf t55xx chk [h] [i <*.dic>]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - this help"); @@ -161,8 +167,8 @@ int usage_t55xx_chk() { int usage_t55xx_bruteforce() { PrintAndLogEx(NORMAL, "This command uses bruteforce to scan a number range"); PrintAndLogEx(NORMAL, "press " _YELLOW_("'enter'") " to cancel the command"); - PrintAndLogEx(NORMAL, "WARNING: this may brick non-password protected chips!"); - PrintAndLogEx(NORMAL, "Try to reading block 7 before\n"); + PrintAndLogEx(NORMAL, "WARNING: this may brick non-password protected chips!"); + PrintAndLogEx(NORMAL, "Try to reading block 7 before\n"); PrintAndLogEx(NORMAL, "Usage: lf t55xx bruteforce [h] "); PrintAndLogEx(NORMAL, " password must be 4 bytes (8 hex symbols)"); PrintAndLogEx(NORMAL, "Options:"); @@ -177,9 +183,9 @@ int usage_t55xx_bruteforce() { } int usage_t55xx_recoverpw() { PrintAndLogEx(NORMAL, "This command uses a few tricks to try to recover mangled password"); - PrintAndLogEx(NORMAL, "press " _YELLOW_("'enter'") " to cancel the command"); + PrintAndLogEx(NORMAL, "press " _YELLOW_("'enter'") " to cancel the command"); PrintAndLogEx(NORMAL, "WARNING: this may brick non-password protected chips!"); - PrintAndLogEx(NORMAL, "Try to reading block 7 before\n"); + PrintAndLogEx(NORMAL, "Try to reading block 7 before\n"); PrintAndLogEx(NORMAL, "Usage: lf t55xx recoverpw [password]"); PrintAndLogEx(NORMAL, " password must be 4 bytes (8 hex symbols)"); PrintAndLogEx(NORMAL, " default password is 51243648, used by many cloners"); @@ -300,8 +306,13 @@ int CmdT55xxSetConfig(const char *Cmd) { } break; case 'i': - config.inverted = param_getchar(Cmd, cmdp + 1) == '1'; - cmdp += 2; + if ((param_getchar(Cmd, cmdp + 1) == '0') || (param_getchar(Cmd, cmdp + 1) == '1')) { + config.inverted = param_getchar(Cmd, cmdp + 1) == '1'; + cmdp += 2; + } else { + config.inverted = true; + cmdp += 1; + } break; case 'o': errors |= param_getdec(Cmd, cmdp + 1, &offset); @@ -310,12 +321,22 @@ int CmdT55xxSetConfig(const char *Cmd) { cmdp += 2; break; case 'q': - config.Q5 = true; - cmdp++; + if ((param_getchar(Cmd, cmdp + 1) == '0') || (param_getchar(Cmd, cmdp + 1) == '1')) { + config.Q5 = param_getchar(Cmd, cmdp + 1) == '1'; + cmdp += 2; + } else { + config.Q5 = true; + cmdp += 1; + } break; case 's': - config.ST = true; - cmdp++; + if ((param_getchar(Cmd, cmdp + 1) == '0') || (param_getchar(Cmd, cmdp + 1) == '1')) { + config.ST = param_getchar(Cmd, cmdp + 1) == '1'; + cmdp += 2; + } else { + config.ST = true; + cmdp += 1; + } break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); @@ -1058,7 +1079,7 @@ int CmdT55xxWriteBlock(const char *Cmd) { c.arg[2] = password; c.d.asBytes[0] |= 0x1; } - + clearCommandBuffer(); SendCommand(&c); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { @@ -1079,7 +1100,7 @@ int CmdT55xxReadTrace(const char *Cmd) { // sanity check. if (!SanityOfflineCheck(false)) return 1; - if (!AquireData(T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password)) + if (!AquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, pwdmode, password)) return 1; } @@ -1251,7 +1272,72 @@ void printT5555Trace(t5555_tracedata_t data, uint8_t repeat) { */ } -//need to add Q5 info... +static void printT5x7KnownBlock0(uint32_t b0) { + + char s[40]; + memset(s, 0, sizeof(s)); + + switch (b0) { + case T55X7_DEFAULT_CONFIG_BLOCK: + snprintf(s, sizeof(s) - strlen(s), "T55x7 Default "); + break; + case T55X7_RAW_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "T55x7 Raw "); + break; + case T55X7_EM_UNIQUE_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "EM Unique "); + break; + /* + case T55X7_EM_PAXTON_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s)-strlen(s), "EM Paxton "); + break; + */ + case T55X7_FDXB_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "FDXB "); + break; + case T55X7_HID_26_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "HID 26b "); + break; + case T55X7_PYRAMID_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Pyramid "); + break; + case T55X7_INDALA_64_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Indala 64"); + break; + case T55X7_INDALA_224_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Indala 224 "); + break; + case T55X7_GUARDPROXII_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Guard Prox II "); + break; + case T55X7_VIKING_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Viking "); + break; + case T55X7_NORALYS_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Noralys "); + break; + case T55X7_IOPROX_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "IO Prox "); + break; + case T55X7_PRESCO_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Presco "); + break; + case T55X7_NEDAP_64_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Nedap 64 "); + break; + case T55X7_NEDAP_128_CONFIG_BLOCK: + snprintf(s + strlen(s), sizeof(s) - strlen(s), "Nedap 128 "); + break; + default: + break; + } + + if (strlen(s) > 0) { + PrintAndLogEx(NORMAL, " Known T55x7 Config block found : " _YELLOW_("%s"), s); + PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); + } +} + int CmdT55xxInfo(const char *Cmd) { /* Page 0 Block 0 Configuration data. @@ -1259,82 +1345,133 @@ int CmdT55xxInfo(const char *Cmd) { Extended mode */ bool pwdmode = false; + bool frombuff = false; + bool gotdata = false; + bool dataasq5 = false; uint32_t password = 0; - char cmdp = tolower(param_getchar(Cmd, 0)); + uint32_t block0 = 0; + uint8_t cmdp = 0; - if (strlen(Cmd) > 1 || cmdp == 'h') return usage_t55xx_info(); + while (param_getchar(Cmd, cmdp) != 0x00) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_info(); + case 'd': + block0 = param_get32ex(Cmd, cmdp + 1, 0, 16); + gotdata = true; + cmdp += 2; + break; + case '1': + frombuff = true; + cmdp += 2; + break; + case 'q': + dataasq5 = true; + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + return usage_t55xx_info(); + } + } - if (strlen(Cmd) == 0) { + if (gotdata && frombuff) + return usage_t55xx_info(); + + if (dataasq5 && !gotdata) + return usage_t55xx_info(); + + if (!frombuff && !gotdata) { // sanity check. if (!SanityOfflineCheck(false)) return 1; if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password)) return 1; } + if (!gotdata) { + if (!DecodeT55xxBlock()) return 1; - if (!DecodeT55xxBlock()) return 1; + // too little space to start with + if (DemodBufferLen < 32 + config.offset) return 1; - // too little space to start with - if (DemodBufferLen < 32) return 1; - - // - //PrintAndLogEx(NORMAL, "Offset+32 ==%d\n DemodLen == %d", config.offset + 32, DemodBufferLen); - - uint8_t si = config.offset; - uint32_t block0 = PackBits(si, 32, DemodBuffer); - uint32_t safer = PackBits(si, 4, DemodBuffer); - si += 4; - uint32_t resv = PackBits(si, 7, DemodBuffer); - si += 7; - uint32_t dbr = PackBits(si, 3, DemodBuffer); - si += 3; - uint32_t extend = PackBits(si, 1, DemodBuffer); - si += 1; - uint32_t datamod = PackBits(si, 5, DemodBuffer); - si += 5; - uint32_t pskcf = PackBits(si, 2, DemodBuffer); - si += 2; - uint32_t aor = PackBits(si, 1, DemodBuffer); - si += 1; - uint32_t otp = PackBits(si, 1, DemodBuffer); - si += 1; - uint32_t maxblk = PackBits(si, 3, DemodBuffer); - si += 3; - uint32_t pwd = PackBits(si, 1, DemodBuffer); - si += 1; - uint32_t sst = PackBits(si, 1, DemodBuffer); - si += 1; - uint32_t fw = PackBits(si, 1, DemodBuffer); - si += 1; - uint32_t inv = PackBits(si, 1, DemodBuffer); - si += 1; - uint32_t por = PackBits(si, 1, DemodBuffer); - si += 1; - - if (config.Q5) - PrintAndLogEx(NORMAL, _RED_("* **Warning ***") " Config Info read off a Q5 will not display as expected"); + //PrintAndLogEx(NORMAL, "Offset+32 ==%d\n DemodLen == %d", config.offset + 32, DemodBufferLen); + block0 = PackBits(config.offset, 32, DemodBuffer); + } PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "-- T55x7 Configuration & Tag Information --------------------"); - PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); - PrintAndLogEx(NORMAL, " Safer key : %s", GetSaferStr(safer)); - PrintAndLogEx(NORMAL, " reserved : %d", resv); - PrintAndLogEx(NORMAL, " Data bit rate : %s", GetBitRateStr(dbr, extend)); - PrintAndLogEx(NORMAL, " eXtended mode : %s", (extend) ? _YELLOW_("Yes - Warning") : "No"); - PrintAndLogEx(NORMAL, " Modulation : %s", GetModulationStr(datamod)); - PrintAndLogEx(NORMAL, " PSK clock frequency : %d", pskcf); - PrintAndLogEx(NORMAL, " AOR - Answer on Request : %s", (aor) ? _GREEN_("Yes") : "No"); - PrintAndLogEx(NORMAL, " OTP - One Time Pad : %s", (otp) ? _YELLOW_("Yes - Warning") : "No"); - PrintAndLogEx(NORMAL, " Max block : %d", maxblk); - PrintAndLogEx(NORMAL, " Password mode : %s", (pwd) ? _GREEN_("Yes") : "No"); - PrintAndLogEx(NORMAL, " Sequence Start Terminator : %s", (sst) ? _GREEN_("Yes") : "No"); - PrintAndLogEx(NORMAL, " Fast Write : %s", (fw) ? _GREEN_("Yes") : "No"); - PrintAndLogEx(NORMAL, " Inverse data : %s", (inv) ? _GREEN_("Yes") : "No"); - PrintAndLogEx(NORMAL, " POR-Delay : %s", (por) ? _GREEN_("Yes") : "No"); + if (((!gotdata) && config.Q5) || (gotdata && dataasq5)) { + uint32_t header = (block0 >> (32 - 12)) & 0xFFF; + uint32_t ps = (block0 >> (32 - 13)) & 0x01; + uint32_t fw = (block0 >> (32 - 14)) & 0x01; + uint32_t dbr = (block0 >> (32 - 20)) & 0x3F; + uint32_t aor = (block0 >> (32 - 21)) & 0x01; + uint32_t pwd = (block0 >> (32 - 22)) & 0x01; + uint32_t pskcf = (block0 >> (32 - 24)) & 0x03; + uint32_t inv = (block0 >> (32 - 25)) & 0x01; + uint32_t datamod = (block0 >> (32 - 28)) & 0x07; + uint32_t maxblk = (block0 >> (32 - 31)) & 0x07; + uint32_t st = (block0 >> (32 - 32)) & 0x01; + PrintAndLogEx(NORMAL, "-- Q5 Configuration & Tag Information -----------------------"); + PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); + PrintAndLogEx(NORMAL, " Header : 0x%03X%s", header, (header != 0x600) ? _RED_(" - Warning") : ""); + PrintAndLogEx(NORMAL, " Page select : %d", ps); + PrintAndLogEx(NORMAL, " Fast Write : %s", (fw) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " Data bit rate : %s", GetBitRateStr(dbr, 1)); + PrintAndLogEx(NORMAL, " AOR - Answer on Request : %s", (aor) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " Password mode : %s", (pwd) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " PSK clock frequency : %s", GetPskCfStr(pskcf, 1)); + PrintAndLogEx(NORMAL, " Inverse data : %s", (inv) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " Modulation : %s", GetQ5ModulationStr(datamod)); + PrintAndLogEx(NORMAL, " Max block : %d", maxblk); + PrintAndLogEx(NORMAL, " Sequence Terminator : %s", (st) ? _GREEN_("Yes") : "No"); + } else { + uint32_t safer = (block0 >> (32 - 4)) & 0x0F; + uint32_t extend = (block0 >> (32 - 15)) & 0x01; + uint32_t resv, dbr; + if (extend) { + resv = (block0 >> (32 - 8)) & 0x0F; + dbr = (block0 >> (32 - 14)) & 0x3F; + } else { + resv = (block0 >> (32 - 11)) & 0x7F; + dbr = (block0 >> (32 - 14)) & 0x07; + } + uint32_t datamod = (block0 >> (32 - 20)) & 0x1F; + uint32_t pskcf = (block0 >> (32 - 22)) & 0x03; + uint32_t aor = (block0 >> (32 - 23)) & 0x01; + uint32_t otp = (block0 >> (32 - 24)) & 0x01; + uint32_t maxblk = (block0 >> (32 - 27)) & 0x07; + uint32_t pwd = (block0 >> (32 - 28)) & 0x01; + uint32_t sst = (block0 >> (32 - 29)) & 0x01; + uint32_t fw = (block0 >> (32 - 30)) & 0x01; + uint32_t inv = (block0 >> (32 - 31)) & 0x01; + uint32_t por = (block0 >> (32 - 32)) & 0x01; + + PrintAndLogEx(NORMAL, "-- T55x7 Configuration & Tag Information --------------------"); + PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); + PrintAndLogEx(NORMAL, " Safer key : %s", GetSaferStr(safer)); + PrintAndLogEx(NORMAL, " reserved : %d", resv); + PrintAndLogEx(NORMAL, " Data bit rate : %s", GetBitRateStr(dbr, extend)); + PrintAndLogEx(NORMAL, " eXtended mode : %s", (extend) ? _YELLOW_("Yes - Warning") : "No"); + PrintAndLogEx(NORMAL, " Modulation : %s", GetModulationStr(datamod, extend)); + PrintAndLogEx(NORMAL, " PSK clock frequency : %s", GetPskCfStr(pskcf, 0)); + PrintAndLogEx(NORMAL, " AOR - Answer on Request : %s", (aor) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " OTP - One Time Pad : %s", (otp) ? ((extend) ? _YELLOW_("Yes - Warning") : _RED_("Yes - Warning")) : "No"); + PrintAndLogEx(NORMAL, " Max block : %d", maxblk); + PrintAndLogEx(NORMAL, " Password mode : %s", (pwd) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " Sequence %-12s : %s", (extend) ? "Start Marker" : "Terminator", (sst) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " Fast Write : %s", (fw) ? ((extend) ? _GREEN_("Yes") : _RED_("Yes - Warning")) : "No"); + PrintAndLogEx(NORMAL, " Inverse data : %s", (inv) ? ((extend) ? _GREEN_("Yes") : _RED_("Yes - Warning")) : "No"); + PrintAndLogEx(NORMAL, " POR-Delay : %s", (por) ? _GREEN_("Yes") : "No"); + } PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(NORMAL, " Raw Data - Page 0"); - PrintAndLogEx(NORMAL, " Block 0 : 0x%08X %s", block0, sprint_bin(DemodBuffer + config.offset, 32)); + if (gotdata) + PrintAndLogEx(NORMAL, " Block 0 : 0x%08X", block0); + else + PrintAndLogEx(NORMAL, " Block 0 : 0x%08X %s", block0, sprint_bin(DemodBuffer + config.offset, 32)); PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); + if (((!gotdata) && (!config.Q5)) || (gotdata && (!dataasq5))) + printT5x7KnownBlock0(block0); return 0; } @@ -1369,7 +1506,7 @@ bool AquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password) { // bit1 = page to read from // arg1: which block to read // arg2: password - uint8_t arg0 = ( page << 1 | (pwdmode) ); + uint8_t arg0 = (page << 1 | (pwdmode)); UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}}; clearCommandBuffer(); SendCommand(&c); @@ -1383,6 +1520,32 @@ bool AquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password) { return !getSignalProperties()->isnoise; } +char *GetPskCfStr(uint32_t id, bool q5) { + static char buf[25]; + char *retStr = buf; + switch (id) { + case 0: + snprintf(retStr, sizeof(buf), "%u - RF/2", id); + break; + case 1: + snprintf(retStr, sizeof(buf), "%u - RF/4", id); + break; + case 2: + snprintf(retStr, sizeof(buf), "%u - RF/8", id); + break; + case 3: + if (q5) + snprintf(retStr, sizeof(buf), "%u - RF/8", id); + else + snprintf(retStr, sizeof(buf), "%u - " _RED_("(Unknown)"), id); + break; + default: + snprintf(retStr, sizeof(buf), "%u - " _RED_("(Unknown)"), id); + break; + } + return buf; +} + char *GetBitRateStr(uint32_t id, bool xmode) { static char buf[25]; @@ -1416,7 +1579,7 @@ char *GetBitRateStr(uint32_t id, bool xmode) { snprintf(retStr, sizeof(buf), "%u - RF/128", id); break; default: - snprintf(retStr, sizeof(buf), "%u - (Unknown)", id); + snprintf(retStr, sizeof(buf), "%u - " _RED_("(Unknown)"), id); break; } } @@ -1438,7 +1601,7 @@ char *GetSaferStr(uint32_t id) { return buf; } -char *GetModulationStr(uint32_t id) { +char *GetModulationStr(uint32_t id, bool xmode) { static char buf[60]; char *retStr = buf; @@ -1462,10 +1625,10 @@ char *GetModulationStr(uint32_t id) { snprintf(retStr, sizeof(buf), "%u - FSK 2 RF/8 RF/10", id); break; case 6: - snprintf(retStr, sizeof(buf), "%u - FSK 1a RF/5 RF/8", id); + snprintf(retStr, sizeof(buf), "%u - %s RF/5 RF/8", id, (xmode) ? "FSK 1a" : _YELLOW_("FSK 1a")); break; case 7: - snprintf(retStr, sizeof(buf), "%u - FSK 2a RF/10 RF/8", id); + snprintf(retStr, sizeof(buf), "%u - %s RF/10 RF/8", id, (xmode) ? "FSK 2a" : _YELLOW_("FSK 2a")); break; case 8: snprintf(retStr, sizeof(buf), "%u - Manchester", id); @@ -1473,14 +1636,44 @@ char *GetModulationStr(uint32_t id) { case 16: snprintf(retStr, sizeof(buf), "%u - Biphase", id); break; - case 0x18: - snprintf(retStr, sizeof(buf), "%u - Biphase a - AKA Conditional Dephase Encoding(CDP)", id); - break; - case 17: - snprintf(retStr, sizeof(buf), "%u - Reserved", id); + case 24: + snprintf(retStr, sizeof(buf), "%u - %s", id, (xmode) ? "Biphase a - AKA Conditional Dephase Encoding(CDP)" : _YELLOW_("Reserved")); break; default: - snprintf(retStr, sizeof(buf), "0x%02X (Unknown)", id); + snprintf(retStr, sizeof(buf), "0x%02X " _RED_("(Unknown)"), id); + break; + } + return buf; +} + +char *GetQ5ModulationStr(uint32_t id) { + static char buf[60]; + char *retStr = buf; + + switch (id) { + case 0: + snprintf(retStr, sizeof(buf), "%u - Manchester", id); + break; + case 1: + snprintf(retStr, sizeof(buf), "%u - PSK 1 phase change when input changes", id); + break; + case 2: + snprintf(retStr, sizeof(buf), "%u - PSK 2 phase change on bitclk if input high", id); + break; + case 3: + snprintf(retStr, sizeof(buf), "%u - PSK 3 phase change on rising edge of input", id); + break; + case 4: + snprintf(retStr, sizeof(buf), "%u - FSK 1a RF/5 RF/8", id); + break; + case 5: + snprintf(retStr, sizeof(buf), "%u - FSK 2a RF/10 RF/8", id); + break; + case 6: + snprintf(retStr, sizeof(buf), "%u - Biphase", id); + break; + case 7: + snprintf(retStr, sizeof(buf), "%u - NRZ / Direct", id); break; } return buf; @@ -1539,7 +1732,7 @@ char *GetSelectedModulationStr(uint8_t id) { snprintf(retStr, sizeof(buf), "BIPHASEa - (CDP)"); break; default: - snprintf(retStr, sizeof(buf), "(Unknown)"); + snprintf(retStr, sizeof(buf), _RED_("(Unknown)")); break; } return buf; @@ -1637,7 +1830,7 @@ int CmdT55xxChkPwds(const char *Cmd) { bool found = false; uint8_t timeout = 0; uint8_t *keyBlock = NULL; - + char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) == 0 || cmdp == 'h') return usage_t55xx_chk(); @@ -1676,7 +1869,7 @@ int CmdT55xxChkPwds(const char *Cmd) { found = tryDetectModulation(); if (found) { - PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08") " ]", resp.arg[1]); + PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08") " ]", resp.arg[1]); } else { PrintAndLogEx(WARNING, "Check pwd failed"); } @@ -1688,22 +1881,22 @@ int CmdT55xxChkPwds(const char *Cmd) { } if (cmdp == 'i') { - + int len = strlen(Cmd + 2); if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; memcpy(filename, Cmd + 2, len); - + uint16_t keycount = 0; size_t datalen = 0; - + // TODO, a way of reallocating memory if file was larger - keyBlock = calloc(4*200, sizeof(uint8_t)); - if ( keyBlock == NULL ) { + keyBlock = calloc(4 * 200, sizeof(uint8_t)); + if (keyBlock == NULL) { PrintAndLogDevice(WARNING, "error, cannot allocate memory "); return 1; } - - int res = loadFileDICTIONARY(filename, "dic", keyBlock, &datalen, 4, &keycount ); + + int res = loadFileDICTIONARY(filename, "dic", keyBlock, &datalen, 4, &keycount); if (res || keycount == 0) { PrintAndLogEx(WARNING, "No keys found in file"); free(keyBlock); @@ -1728,7 +1921,7 @@ int CmdT55xxChkPwds(const char *Cmd) { curr_password = bytes_to_num(keyBlock + 4 * c, 4); PrintAndLogEx(INFO, "Testing %08X", curr_password); - + if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, curr_password)) { continue; } @@ -1776,7 +1969,7 @@ int CmdT55xxBruteForce(const char *Cmd) { PrintAndLogEx(INFO, "Search password range [%08X -> %08X]", start_password, end_password); while (!found) { - + printf("."); fflush(stdout); @@ -1788,7 +1981,7 @@ int CmdT55xxBruteForce(const char *Cmd) { if (curr == end_password) break; - + curr++; } @@ -1806,12 +1999,12 @@ int CmdT55xxBruteForce(const char *Cmd) { int tryOnePassword(uint32_t password) { PrintAndLogEx(INFO, "Trying password %08X", password); - + AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, password); if (getSignalProperties()->isnoise == false) return 0; - + if (tryDetectModulation()) return 1; else @@ -1834,12 +2027,12 @@ int CmdT55xxRecoverPW(const char *Cmd) { while (bit < 32) { curr_password = orig_password ^ (1u << bit); found = tryOnePassword(curr_password); - if ( found == 1) + if (found == 1) goto out; - + bit++; - if (IsCancelled()) + if (IsCancelled()) return 0; } @@ -1857,15 +2050,15 @@ int CmdT55xxRecoverPW(const char *Cmd) { bit++; continue; } - + found = tryOnePassword(curr_password); - if ( found == 1 ) - goto out; - + if (found == 1) + goto out; + bit++; prev_password = curr_password; - if (IsCancelled()) + if (IsCancelled()) return 0; } @@ -1881,13 +2074,13 @@ int CmdT55xxRecoverPW(const char *Cmd) { continue; } found = tryOnePassword(curr_password); - if ( found == 1 ) + if (found == 1) goto out; bit++; prev_password = curr_password; - if (IsCancelled()) + if (IsCancelled()) return 0; } @@ -1914,7 +2107,7 @@ bool tryDetectP1(bool getData) { bool st = true; if (getData) { - if (!AquireData(T55x7_PAGE1, 1, false, 0)) + if (!AquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, false, 0)) return false; } @@ -2043,7 +2236,7 @@ int CmdT55xxDetectPage1(const char *Cmd) { if (errors) return usage_t55xx_detectP1(); if (!useGB) { - if (!AquireData(T55x7_PAGE1, 1, usepwd, password)) + if (!AquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, usepwd, password)) return false; } bool success = tryDetectP1(false); diff --git a/client/cmdlft55xx.h b/client/cmdlft55xx.h index 1c1d77490..cd240e5f2 100644 --- a/client/cmdlft55xx.h +++ b/client/cmdlft55xx.h @@ -29,6 +29,8 @@ #define T55x7_CONFIGURATION_BLOCK 0x00 +#define T55x7_TRACE_BLOCK1 0x01 +#define T55x7_TRACE_BLOCK2 0x02 #define T55x7_PAGE0 0x00 #define T55x7_PAGE1 0x01 #define T55x7_PWD 0x00000010 @@ -147,9 +149,11 @@ extern int CmdT55xxDetect(const char *Cmd); extern int CmdResetRead(const char *Cmd); extern int CmdT55xxWipe(const char *Cmd); +char *GetPskCfStr(uint32_t id, bool q5); char *GetBitRateStr(uint32_t id, bool xmode); char *GetSaferStr(uint32_t id); -char *GetModulationStr(uint32_t id); +char *GetQ5ModulationStr(uint32_t id); +char *GetModulationStr(uint32_t id, bool xmode); char *GetModelStrFromCID(uint32_t cid); char *GetSelectedModulationStr(uint8_t id); uint32_t PackBits(uint8_t start, uint8_t len, uint8_t *bitstream); diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index 125475080..2a0216aa7 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -679,14 +679,14 @@ int CmdSmartUpgrade(const char *Cmd) { if (fsize < 0) { PrintAndLogEx(FAILED, "Could not determine size of SHA-512 file"); fclose(f); - free(dump); + free(dump); return 1; } if (fsize < 128) { PrintAndLogEx(FAILED, "SHA-512 file too short"); fclose(f); - free(dump); + free(dump); return 1; } @@ -700,20 +700,20 @@ int CmdSmartUpgrade(const char *Cmd) { uint8_t hash1[64]; if (bytes_read != 128 || param_gethex(hashstring, 0, hash1, 128)) { PrintAndLogEx(FAILED, "Couldn't read SHA-512 file"); - free(dump); + free(dump); return 1; } uint8_t hash2[64]; if (sha512hash(dump, firmware_size, hash2)) { PrintAndLogEx(FAILED, "Couldn't calculate SHA-512 of firmware"); - free(dump); + free(dump); return 1; } if (memcmp(hash1, hash2, 64)) { PrintAndLogEx(FAILED, "Couldn't verify integrity of firmware file " _RED_("(wrong SHA-512 hash)")); - free(dump); + free(dump); return 1; } diff --git a/client/comms.c b/client/comms.c index de6394915..9ffa37977 100644 --- a/client/comms.c +++ b/client/comms.c @@ -194,7 +194,7 @@ static void UsbCommandReceived(UsbCommand *c) { /* bool hookUpPM3() { bool ret = false; - sp = uart_open( comport ); + sp = uart_open( comport, speed ); if (sp == INVALID_SERIAL_PORT) { PrintAndLogEx(WARNING, "Reconnect failed, retrying... (reason: invalid serial port)\n"); @@ -298,17 +298,17 @@ __attribute__((force_align_arg_pointer)) return NULL; } -bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode) { +bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed) { char *portname = (char *)port; if (!wait_for_port) { - sp = uart_open(portname); + sp = uart_open(portname, speed); } else { PrintAndLogEx(SUCCESS, "Waiting for Proxmark to appear on " _YELLOW_("%s"), portname); fflush(stdout); int openCount = 0; do { - sp = uart_open(portname); + sp = uart_open(portname, speed); msleep(500); printf("."); fflush(stdout); diff --git a/client/comms.h b/client/comms.h index f56bdb57e..b0687ac60 100644 --- a/client/comms.h +++ b/client/comms.h @@ -54,7 +54,8 @@ void *uart_receiver(void *targ); void SendCommand(UsbCommand *c); void clearCommandBuffer(); -bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode); +#define FLASHMODE_SPEED 460800 +bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed); void CloseProxmark(void); bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeout, bool show_warning); diff --git a/client/flash.c b/client/flash.c index c60dfcbf1..defcd7feb 100644 --- a/client/flash.c +++ b/client/flash.c @@ -318,8 +318,10 @@ static int enter_bootloader(char *serial_port_name) { } msleep(100); CloseProxmark(); + // Let time to OS to make the port disappear + msleep(1000); - bool opened = OpenProxmark(serial_port_name, true, 60, true); + bool opened = OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED); if (opened) { fprintf(stdout, " " _GREEN_("Found") "\n"); return 0; diff --git a/client/flasher.c b/client/flasher.c index 6e79ca70c..bc744b339 100644 --- a/client/flasher.c +++ b/client/flasher.c @@ -81,7 +81,7 @@ int main(int argc, char **argv) { char *serial_port_name = argv[1]; - if (!OpenProxmark(serial_port_name, true, 60, true)) { + if (!OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) { fprintf(stderr, "Could not find Proxmark on " _RED_("%s") ".\n\n", serial_port_name); return -1; } else { diff --git a/client/fpga_compress.c b/client/fpga_compress.c index c7cd021f8..0f4220632 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -417,16 +417,16 @@ int main(int argc, char **argv) { infiles[0] = fopen(argv[2], "rb"); if (infiles[0] == NULL) { fprintf(stderr, "Error. Cannot open input file %s\n\n", argv[2]); - free(infiles); + free(infiles); return (EXIT_FAILURE); } outfile = fopen(argv[3], "wb"); if (outfile == NULL) { fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[3]); - free(infiles); + free(infiles); return (EXIT_FAILURE); } - + int ret = zlib_decompress(infiles[0], outfile); free(infiles); return (ret); @@ -466,13 +466,13 @@ int main(int argc, char **argv) { if (outfile == NULL) { fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[argc - 1]); free(infile_names); - free(infiles); + free(infiles); return (EXIT_FAILURE); } if (generate_version_file) { if (generate_fpga_version_info(infiles, infile_names, num_input_files, outfile)) { free(infile_names); - free(infiles); + free(infiles); return (EXIT_FAILURE); } } else { diff --git a/client/proxmark3.c b/client/proxmark3.c index e54f0ce74..50180a79c 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -259,6 +259,9 @@ int main(int argc, char *argv[]) { bool addLuaExec = false; char *script_cmds_file = NULL; char *script_cmd = NULL; + char *lastarg = NULL; + char *port = NULL; + uint32_t speed = 0; /* initialize history */ using_history(); @@ -272,7 +275,9 @@ int main(int argc, char *argv[]) { return 1; } - for (int i = 1; i < argc; i++) { + uint32_t i = 1; + port = argv[i++]; + for (; i < argc; i++) { // helptext if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { @@ -291,29 +296,58 @@ int main(int argc, char *argv[]) { if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "-flush") == 0) { SetFlushAfterWrite(true); PrintAndLogEx(INFO, "Output will be flushed after every print.\n"); + continue; + } + + // set baudrate + if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "-baud") == 0) { + uint32_t tmpspeed = strtoul(argv[i + 1], NULL, 10); + if ((tmpspeed == ULONG_MAX) || (tmpspeed == 0)) { + PrintAndLogEx(WARNING, "ERROR: invalid baudrate: %s %s\n", argv[i], argv[i + 1]); + return 1; + } + speed = tmpspeed; + i++; + continue; } // wait for comport if (strcmp(argv[i], "-w") == 0 || strcmp(argv[i], "-wait") == 0) { waitCOMPort = true; + continue; } // execute pm3 command if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "-command") == 0) { executeCommand = true; + continue; } // execute lua script if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "-lua") == 0) { executeCommand = true; addLuaExec = true; + continue; + } + + if (i < argc - 1) { + // We got an unknown parameter + PrintAndLogEx(WARNING, "WARNING: ignoring invalid parameter: %s\n", argv[i]); + } + + if (i == argc - 1) { + // We got presumably a command or a filename + lastarg = argv[argc - 1]; } } + if (speed == 0) + speed = 460800; + // If the user passed the filename of the 'script' to execute, get it from last parameter - if (argc > 2 && argv[argc - 1] && argv[argc - 1][0] != '-') { + if (lastarg) { if (executeCommand) { - script_cmd = argv[argc - 1]; + script_cmd = lastarg; while (script_cmd[strlen(script_cmd) - 1] == ' ') script_cmd[strlen(script_cmd) - 1] = 0x00; @@ -336,7 +370,7 @@ int main(int argc, char *argv[]) { PrintAndLogEx(SUCCESS, "execute command from commandline: %s\n", script_cmd); } } else { - script_cmds_file = argv[argc - 1]; + script_cmds_file = lastarg; } } @@ -358,7 +392,7 @@ int main(int argc, char *argv[]) { set_my_executable_path(); // try to open USB connection to Proxmark - usb_present = OpenProxmark(argv[1], waitCOMPort, 20, false); + usb_present = OpenProxmark(port, waitCOMPort, 20, false, speed); #ifdef HAVE_GUI diff --git a/client/reveng/cli.c b/client/reveng/cli.c index f715d66f7..6ecdcecab 100644 --- a/client/reveng/cli.c +++ b/client/reveng/cli.c @@ -630,7 +630,7 @@ usage(void) { "\t preset values\n" "\n" "Copyright (C)\n" - "2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Gregory Cook\n" + "2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Gregory Cook\n" "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" "Version " diff --git a/client/reveng/poly.c b/client/reveng/poly.c index 7e35be18c..0ce60aac2 100644 --- a/client/reveng/poly.c +++ b/client/reveng/poly.c @@ -988,10 +988,10 @@ pcrc(const poly_t message, const poly_t divisor, const poly_t init, const poly_t /* 0 <= ofs <= BMP_BIT, location of the first bit of the result */ pshift(&result, result, 0UL, ofs, (init.length > max + divisor.length ? init.length - max - divisor.length : 0UL) + divisor.length + ofs, 0UL); } - - if ( result.bitmap != NULL ) + + if (result.bitmap != NULL) psum(&result, xorout, 0UL); - + return (result); } diff --git a/client/reveng/preset.c b/client/reveng/preset.c index eb07f9085..6f41ac9f5 100644 --- a/client/reveng/preset.c +++ b/client/reveng/preset.c @@ -379,98 +379,98 @@ static const bmp_t b32[] = { BMP_C(0x94000000) << (BMP_BIT - 32), /* 115 -- 8, 94 */ BMP_C(0x97000000) << (BMP_BIT - 32), /* 116 -- 8, 97 */ BMP_C(0x98000000) << (BMP_BIT - 32), /* 117 -- 6, 26 */ - BMP_C(0x99000000) << (BMP_BIT - 32), /* 118 -- 8, 99 */ - BMP_C(0x9b000000) << (BMP_BIT - 32), /* 119 -- 8, 9b */ - BMP_C(0x9c000000) << (BMP_BIT - 32), /* 120 -- 6, 27 */ - BMP_C(0x9d5e4de2) << (BMP_BIT - 32), /* 121 -- 31,4eaf26f1 */ - BMP_C(0x9e000000) << (BMP_BIT - 32), /* 122 -- 7, 4f */ - BMP_C(0x9ecf0000) << (BMP_BIT - 32), /* 123 -- 16, 9ecf */ - BMP_C(0xa0660000) << (BMP_BIT - 32), /* 124 -- 16, a066 */ - BMP_C(0xa0970000) << (BMP_BIT - 32), /* 125 -- 16, a097 */ - BMP_C(0xa1000000) << (BMP_BIT - 32), /* 126 -- 8, a1 */ - BMP_C(0xa3660000) << (BMP_BIT - 32), /* 127 -- 16, a366 */ - BMP_C(0xa6000000) << (BMP_BIT - 32), /* 128 -- 7, 53 */ - BMP_C(0xa7000000) << (BMP_BIT - 32), /* 129 -- 8, a7 */ - BMP_C(0xa8000000) << (BMP_BIT - 32), /* 130 -- 5, 15 */ - BMP_C(0xa8190000) << (BMP_BIT - 32), /* 131 -- 16, a819 */ - BMP_C(0xa833982b) << (BMP_BIT - 32), /* 132 -- 32,a833982b */ - BMP_C(0xabcdef00) << (BMP_BIT - 32), /* 133 -- 24, abcdef */ - BMP_C(0xac000000) << (BMP_BIT - 32), /* 134 -- 8, ac */ - BMP_C(0xaee70000) << (BMP_BIT - 32), /* 135 -- 16, aee7 */ - BMP_C(0xb0000000) << (BMP_BIT - 32), /* 136 -- 4, b */ - BMP_C(0xb0010000) << (BMP_BIT - 32), /* 137 -- 16, b001 */ - BMP_C(0xb2aa0000) << (BMP_BIT - 32), /* 138 -- 16, b2aa */ - BMP_C(0xb3400000) << (BMP_BIT - 32), /* 139 -- 12, b34 */ - BMP_C(0xb42d8000) << (BMP_BIT - 32), /* 140 -- 17, 1685b */ - BMP_C(0xb4600000) << (BMP_BIT - 32), /* 141 -- 11, 5a3 */ - BMP_C(0xb4c80000) << (BMP_BIT - 32), /* 142 -- 16, b4c8 */ - BMP_C(0xb4f3e600) << (BMP_BIT - 32), /* 143 -- 24, b4f3e6 */ - BMP_C(0xb704ce00) << (BMP_BIT - 32), /* 144 -- 24, b704ce */ - BMP_C(0xb798b438) << (BMP_BIT - 32), /* 145 -- 32,b798b438 */ - BMP_C(0xbb3d0000) << (BMP_BIT - 32), /* 146 -- 16, bb3d */ - BMP_C(0xbc000000) << (BMP_BIT - 32), /* 147 -- 6,2f/ 8,bc */ - BMP_C(0xbd0be338) << (BMP_BIT - 32), /* 148 -- 32,bd0be338 */ - BMP_C(0xbdf40000) << (BMP_BIT - 32), /* 149 -- 16, bdf4 */ - BMP_C(0xbf050000) << (BMP_BIT - 32), /* 150 -- 16, bf05 */ - BMP_C(0xc0000000) << (BMP_BIT - 32), /* 151 -- 3, 6 */ - BMP_C(0xc2000000) << (BMP_BIT - 32), /* 152 -- 7, 61 */ - BMP_C(0xc25a5600) << (BMP_BIT - 32), /* 153 -- 24, c25a56 */ - BMP_C(0xc2b70000) << (BMP_BIT - 32), /* 154 -- 16, c2b7 */ - BMP_C(0xc2b80000) << (BMP_BIT - 32), /* 155 -- 14, 30ae */ - BMP_C(0xc4000000) << (BMP_BIT - 32), /* 156 -- 8, c4 */ - BMP_C(0xc6c60000) << (BMP_BIT - 32), /* 157 -- 16, c6c6 */ - BMP_C(0xc7000000) << (BMP_BIT - 32), /* 158 -- 8, c7 */ - BMP_C(0xc704dd7b) << (BMP_BIT - 32), /* 159 -- 32,c704dd7b */ - BMP_C(0xc8000000) << (BMP_BIT - 32), /* 160 -- 5, 19 */ - BMP_C(0xc8670000) << (BMP_BIT - 32), /* 161 -- 16, c867 */ - BMP_C(0xcbf43926) << (BMP_BIT - 32), /* 162 -- 32,cbf43926 */ - BMP_C(0xcde70300) << (BMP_BIT - 32), /* 163 -- 24, cde703 */ - BMP_C(0xce3c0000) << (BMP_BIT - 32), /* 164 -- 16, ce3c */ - BMP_C(0xd0000000) << (BMP_BIT - 32), /* 165 -- 8, d0 */ - BMP_C(0xd02a0000) << (BMP_BIT - 32), /* 166 -- 15, 6815 */ - BMP_C(0xd0db0000) << (BMP_BIT - 32), /* 167 -- 16, d0db */ - BMP_C(0xd3100000) << (BMP_BIT - 32), /* 168 -- 12, d31 */ - BMP_C(0xd3be9568) << (BMP_BIT - 32), /* 169 -- 30,34efa55a */ - BMP_C(0xd4d00000) << (BMP_BIT - 32), /* 170 -- 12, d4d */ - BMP_C(0xd5000000) << (BMP_BIT - 32), /* 171 -- 8, d5 */ - BMP_C(0xd64e0000) << (BMP_BIT - 32), /* 172 -- 16, d64e */ - BMP_C(0xda000000) << (BMP_BIT - 32), /* 173 -- 8, da */ - BMP_C(0xdaf00000) << (BMP_BIT - 32), /* 174 -- 12, daf */ - BMP_C(0xdebb20e3) << (BMP_BIT - 32), /* 175 -- 32,debb20e3 */ - BMP_C(0xdf000000) << (BMP_BIT - 32), /* 176 -- 8, df */ - BMP_C(0xe0000000) << (BMP_BIT - 32), /* 177 -- 3, 7 */ - BMP_C(0xe3069283) << (BMP_BIT - 32), /* 178 -- 32,e3069283 */ - BMP_C(0xe3940000) << (BMP_BIT - 32), /* 179 -- 16, e394 */ - BMP_C(0xe5cc0000) << (BMP_BIT - 32), /* 180 -- 16, e5cc */ - BMP_C(0xe7a80000) << (BMP_BIT - 32), /* 181 -- 13, 1cf5 */ - BMP_C(0xe8000000) << (BMP_BIT - 32), /* 182 -- 6, 3a */ - BMP_C(0xea000000) << (BMP_BIT - 32), /* 183 -- 7, 75 */ - BMP_C(0xea820000) << (BMP_BIT - 32), /* 184 -- 16, ea82 */ - BMP_C(0xec000000) << (BMP_BIT - 32), /* 185 -- 6, 3b */ - BMP_C(0xf0000000) << (BMP_BIT - 32), /* 186 -- 4, f */ - BMP_C(0xf0b80000) << (BMP_BIT - 32), /* 187 -- 16, f0b8 */ - BMP_C(0xf1300000) << (BMP_BIT - 32), /* 188 -- 12, f13 */ - BMP_C(0xf4000000) << (BMP_BIT - 32), /* 189 -- 8, f4 */ - BMP_C(0xf4acfb13) << (BMP_BIT - 32), /* 190 -- 32,f4acfb13 */ - BMP_C(0xf5b00000) << (BMP_BIT - 32), /* 191 -- 12, f5b */ - BMP_C(0xf6400000) << (BMP_BIT - 32), /* 192 -- 10, 3d9 */ - BMP_C(0xf7000000) << (BMP_BIT - 32), /* 193 -- 8, f7 */ - BMP_C(0xf8000000) << (BMP_BIT - 32), /* 194 -- 5, 1f */ - BMP_C(0xfc000000) << (BMP_BIT - 32), /* 195 -- 6, 3f */ - BMP_C(0xfc891918) << (BMP_BIT - 32), /* 196 -- 32,fc891918 */ - BMP_C(0xfd000000) << (BMP_BIT - 32), /* 197 -- 8, fd */ - BMP_C(0xfe000000) << (BMP_BIT - 32), /* 198 -- 7, 7f */ - BMP_C(0xfedcba00) << (BMP_BIT - 32), /* 199 -- 24, fedcba */ - BMP_C(0xfee80000) << (BMP_BIT - 32), /* 200 -- 16, fee8 */ - BMP_C(0xff000000) << (BMP_BIT - 32), /* 201 -- 8, ff */ - BMP_C(0xffc00000) << (BMP_BIT - 32), /* 202 -- 10, 3ff */ - BMP_C(0xfff00000) << (BMP_BIT - 32), /* 203 -- 12, fff */ - BMP_C(0xfffc0000) << (BMP_BIT - 32), /* 204 -- 14, 3fff */ - BMP_C(0xffff0000) << (BMP_BIT - 32), /* 205 -- 16, ffff */ - BMP_C(0xffffff00) << (BMP_BIT - 32), /* 206 -- 24, ffffff */ - BMP_C(0xfffffffc) << (BMP_BIT - 32), /* 207 -- 30,3fffffff */ - BMP_C(0xfffffffe) << (BMP_BIT - 32), /* 208 -- 31,7fffffff */ - BMP_C(0xffffffff) << (BMP_BIT - 32), /* 209 -- 32,ffffffff */ + BMP_C(0x99000000) << (BMP_BIT - 32), /* 118 -- 8, 99 */ + BMP_C(0x9b000000) << (BMP_BIT - 32), /* 119 -- 8, 9b */ + BMP_C(0x9c000000) << (BMP_BIT - 32), /* 120 -- 6, 27 */ + BMP_C(0x9d5e4de2) << (BMP_BIT - 32), /* 121 -- 31,4eaf26f1 */ + BMP_C(0x9e000000) << (BMP_BIT - 32), /* 122 -- 7, 4f */ + BMP_C(0x9ecf0000) << (BMP_BIT - 32), /* 123 -- 16, 9ecf */ + BMP_C(0xa0660000) << (BMP_BIT - 32), /* 124 -- 16, a066 */ + BMP_C(0xa0970000) << (BMP_BIT - 32), /* 125 -- 16, a097 */ + BMP_C(0xa1000000) << (BMP_BIT - 32), /* 126 -- 8, a1 */ + BMP_C(0xa3660000) << (BMP_BIT - 32), /* 127 -- 16, a366 */ + BMP_C(0xa6000000) << (BMP_BIT - 32), /* 128 -- 7, 53 */ + BMP_C(0xa7000000) << (BMP_BIT - 32), /* 129 -- 8, a7 */ + BMP_C(0xa8000000) << (BMP_BIT - 32), /* 130 -- 5, 15 */ + BMP_C(0xa8190000) << (BMP_BIT - 32), /* 131 -- 16, a819 */ + BMP_C(0xa833982b) << (BMP_BIT - 32), /* 132 -- 32,a833982b */ + BMP_C(0xabcdef00) << (BMP_BIT - 32), /* 133 -- 24, abcdef */ + BMP_C(0xac000000) << (BMP_BIT - 32), /* 134 -- 8, ac */ + BMP_C(0xaee70000) << (BMP_BIT - 32), /* 135 -- 16, aee7 */ + BMP_C(0xb0000000) << (BMP_BIT - 32), /* 136 -- 4, b */ + BMP_C(0xb0010000) << (BMP_BIT - 32), /* 137 -- 16, b001 */ + BMP_C(0xb2aa0000) << (BMP_BIT - 32), /* 138 -- 16, b2aa */ + BMP_C(0xb3400000) << (BMP_BIT - 32), /* 139 -- 12, b34 */ + BMP_C(0xb42d8000) << (BMP_BIT - 32), /* 140 -- 17, 1685b */ + BMP_C(0xb4600000) << (BMP_BIT - 32), /* 141 -- 11, 5a3 */ + BMP_C(0xb4c80000) << (BMP_BIT - 32), /* 142 -- 16, b4c8 */ + BMP_C(0xb4f3e600) << (BMP_BIT - 32), /* 143 -- 24, b4f3e6 */ + BMP_C(0xb704ce00) << (BMP_BIT - 32), /* 144 -- 24, b704ce */ + BMP_C(0xb798b438) << (BMP_BIT - 32), /* 145 -- 32,b798b438 */ + BMP_C(0xbb3d0000) << (BMP_BIT - 32), /* 146 -- 16, bb3d */ + BMP_C(0xbc000000) << (BMP_BIT - 32), /* 147 -- 6,2f/ 8,bc */ + BMP_C(0xbd0be338) << (BMP_BIT - 32), /* 148 -- 32,bd0be338 */ + BMP_C(0xbdf40000) << (BMP_BIT - 32), /* 149 -- 16, bdf4 */ + BMP_C(0xbf050000) << (BMP_BIT - 32), /* 150 -- 16, bf05 */ + BMP_C(0xc0000000) << (BMP_BIT - 32), /* 151 -- 3, 6 */ + BMP_C(0xc2000000) << (BMP_BIT - 32), /* 152 -- 7, 61 */ + BMP_C(0xc25a5600) << (BMP_BIT - 32), /* 153 -- 24, c25a56 */ + BMP_C(0xc2b70000) << (BMP_BIT - 32), /* 154 -- 16, c2b7 */ + BMP_C(0xc2b80000) << (BMP_BIT - 32), /* 155 -- 14, 30ae */ + BMP_C(0xc4000000) << (BMP_BIT - 32), /* 156 -- 8, c4 */ + BMP_C(0xc6c60000) << (BMP_BIT - 32), /* 157 -- 16, c6c6 */ + BMP_C(0xc7000000) << (BMP_BIT - 32), /* 158 -- 8, c7 */ + BMP_C(0xc704dd7b) << (BMP_BIT - 32), /* 159 -- 32,c704dd7b */ + BMP_C(0xc8000000) << (BMP_BIT - 32), /* 160 -- 5, 19 */ + BMP_C(0xc8670000) << (BMP_BIT - 32), /* 161 -- 16, c867 */ + BMP_C(0xcbf43926) << (BMP_BIT - 32), /* 162 -- 32,cbf43926 */ + BMP_C(0xcde70300) << (BMP_BIT - 32), /* 163 -- 24, cde703 */ + BMP_C(0xce3c0000) << (BMP_BIT - 32), /* 164 -- 16, ce3c */ + BMP_C(0xd0000000) << (BMP_BIT - 32), /* 165 -- 8, d0 */ + BMP_C(0xd02a0000) << (BMP_BIT - 32), /* 166 -- 15, 6815 */ + BMP_C(0xd0db0000) << (BMP_BIT - 32), /* 167 -- 16, d0db */ + BMP_C(0xd3100000) << (BMP_BIT - 32), /* 168 -- 12, d31 */ + BMP_C(0xd3be9568) << (BMP_BIT - 32), /* 169 -- 30,34efa55a */ + BMP_C(0xd4d00000) << (BMP_BIT - 32), /* 170 -- 12, d4d */ + BMP_C(0xd5000000) << (BMP_BIT - 32), /* 171 -- 8, d5 */ + BMP_C(0xd64e0000) << (BMP_BIT - 32), /* 172 -- 16, d64e */ + BMP_C(0xda000000) << (BMP_BIT - 32), /* 173 -- 8, da */ + BMP_C(0xdaf00000) << (BMP_BIT - 32), /* 174 -- 12, daf */ + BMP_C(0xdebb20e3) << (BMP_BIT - 32), /* 175 -- 32,debb20e3 */ + BMP_C(0xdf000000) << (BMP_BIT - 32), /* 176 -- 8, df */ + BMP_C(0xe0000000) << (BMP_BIT - 32), /* 177 -- 3, 7 */ + BMP_C(0xe3069283) << (BMP_BIT - 32), /* 178 -- 32,e3069283 */ + BMP_C(0xe3940000) << (BMP_BIT - 32), /* 179 -- 16, e394 */ + BMP_C(0xe5cc0000) << (BMP_BIT - 32), /* 180 -- 16, e5cc */ + BMP_C(0xe7a80000) << (BMP_BIT - 32), /* 181 -- 13, 1cf5 */ + BMP_C(0xe8000000) << (BMP_BIT - 32), /* 182 -- 6, 3a */ + BMP_C(0xea000000) << (BMP_BIT - 32), /* 183 -- 7, 75 */ + BMP_C(0xea820000) << (BMP_BIT - 32), /* 184 -- 16, ea82 */ + BMP_C(0xec000000) << (BMP_BIT - 32), /* 185 -- 6, 3b */ + BMP_C(0xf0000000) << (BMP_BIT - 32), /* 186 -- 4, f */ + BMP_C(0xf0b80000) << (BMP_BIT - 32), /* 187 -- 16, f0b8 */ + BMP_C(0xf1300000) << (BMP_BIT - 32), /* 188 -- 12, f13 */ + BMP_C(0xf4000000) << (BMP_BIT - 32), /* 189 -- 8, f4 */ + BMP_C(0xf4acfb13) << (BMP_BIT - 32), /* 190 -- 32,f4acfb13 */ + BMP_C(0xf5b00000) << (BMP_BIT - 32), /* 191 -- 12, f5b */ + BMP_C(0xf6400000) << (BMP_BIT - 32), /* 192 -- 10, 3d9 */ + BMP_C(0xf7000000) << (BMP_BIT - 32), /* 193 -- 8, f7 */ + BMP_C(0xf8000000) << (BMP_BIT - 32), /* 194 -- 5, 1f */ + BMP_C(0xfc000000) << (BMP_BIT - 32), /* 195 -- 6, 3f */ + BMP_C(0xfc891918) << (BMP_BIT - 32), /* 196 -- 32,fc891918 */ + BMP_C(0xfd000000) << (BMP_BIT - 32), /* 197 -- 8, fd */ + BMP_C(0xfe000000) << (BMP_BIT - 32), /* 198 -- 7, 7f */ + BMP_C(0xfedcba00) << (BMP_BIT - 32), /* 199 -- 24, fedcba */ + BMP_C(0xfee80000) << (BMP_BIT - 32), /* 200 -- 16, fee8 */ + BMP_C(0xff000000) << (BMP_BIT - 32), /* 201 -- 8, ff */ + BMP_C(0xffc00000) << (BMP_BIT - 32), /* 202 -- 10, 3ff */ + BMP_C(0xfff00000) << (BMP_BIT - 32), /* 203 -- 12, fff */ + BMP_C(0xfffc0000) << (BMP_BIT - 32), /* 204 -- 14, 3fff */ + BMP_C(0xffff0000) << (BMP_BIT - 32), /* 205 -- 16, ffff */ + BMP_C(0xffffff00) << (BMP_BIT - 32), /* 206 -- 24, ffffff */ + BMP_C(0xfffffffc) << (BMP_BIT - 32), /* 207 -- 30,3fffffff */ + BMP_C(0xfffffffe) << (BMP_BIT - 32), /* 208 -- 31,7fffffff */ + BMP_C(0xffffffff) << (BMP_BIT - 32), /* 209 -- 32,ffffffff */ }; static const struct malias aliases[]; @@ -479,297 +479,297 @@ static const struct malias aliases[]; * Sorted by left-justified polynomial for bsearch(). */ static const struct mpreset models[] = { - {64UL, b64, b64a, P_LE | P_CONFIR, b64a, b64b, b64c, aliases + 130}, /* 0 */ - {32UL, b32+ 0, 0, P_BE | P_CONFIR, 0, b32+148, 0, aliases+107}, /* 1 */ - {40UL, b40, 0, P_BE | P_ACADEM, b40a, b40b, b40c, aliases + 115}, /* 2 */ - {24UL, b32+ 3, b32+ 76, P_LE | P_ATTEST, 0, b32+153, 0, aliases+ 77}, /* 3 */ - {32UL, b32+ 8, 0, P_BE | P_ATTEST, b32+209, b32+ 92, b32+159, aliases+ 98}, /* 4 */ - {32UL, b32+ 8, b32+209, P_BE | P_ATTEST, 0, b32+ 7, 0, aliases+104}, /* 5 */ - {32UL, b32+ 8, b32+209, P_BE | P_ATTEST, b32+209, b32+196, b32+159, aliases+ 96}, /* 6 */ - {32UL, b32+ 8, b32+209, P_LE | P_CONFIR, 0, b32+ 56, 0, aliases+103}, /* 7 */ - {32UL, b32+ 8, b32+209, P_LE | P_ATTEST, b32+209, b32+162, b32+175, aliases+102}, /* 8 */ - {16UL, b32 + 9, 0, P_BE | P_ATTEST, 0, b32 + 5, 0, aliases + 36}, /* 9 */ - {16UL, b32 + 9, 0, P_BE | P_ATTEST, b32 + 1, b32 + 4, b32 + 9, aliases + 35}, /* 10 */ - { 8UL, b32+ 10, 0, P_BE | P_ATTEST, 0, b32+189, 0, aliases+158}, /* 11 */ - { 8UL, b32+ 10, 0, P_BE | P_ACADEM, b32+ 75, b32+126, b32+134, aliases+147}, /* 12 */ - { 8UL, b32+ 10, b32+201, P_LE | P_ACADEM, 0, b32+165, 0, aliases+156}, /* 13 */ - {16UL, b32+ 11, b32+205, P_LE | P_ATTEST, 0, b32+124, 0, aliases+ 58}, /* 14 */ - {31UL, b32+ 12, b32+208, P_BE | P_CONFIR, b32+208, b32+ 26, b32+121, aliases+ 88}, /* 15 */ - { 6UL, b32 + 14, 0, P_LE | P_ACADEM, 0, b32 + 25, 0, aliases + 124}, /* 16 */ - {82UL, b82, 0, P_LE | P_ATTEST, 0, b82a, 0, aliases+161}, /* 17 */ - {16UL, b32 + 18, 0, P_BE | P_ATTEST, 0, b32 + 53, 0, aliases + 73}, /* 18 */ - {16UL, b32+ 18, 0, P_BE | P_ACADEM, b32+205, b32+164, b32+ 29, aliases+ 42}, /* 19 */ - {16UL, b32 + 18, 0, P_LE | P_ATTEST, 0, b32 + 38, 0, aliases + 50}, /* 20 */ - {16UL, b32+ 18, b32+ 29, P_BE | P_ATTEST, 0, b32+180, 0, aliases+ 63}, /* 21 */ - {16UL, b32 + 18, b32 + 108, P_LE | P_ATTEST, 0, b32 + 43, 0, aliases + 66}, /* 22 */ - {16UL, b32+ 18, b32+138, P_LE | P_THIRDP, 0, b32+ 83, 0, aliases+ 62}, /* 23 */ - {16UL, b32+ 18, b32+157, P_LE | P_ATTEST, 0, b32+150, 0, aliases+ 48}, /* 24 */ - {16UL, b32+ 18, b32+205, P_BE | P_ATTEST, 0, b32+ 47, 0, aliases+ 44}, /* 25 */ - {16UL, b32+ 18, b32+205, P_BE | P_ATTEST, b32+205, b32+172, b32+ 29, aliases+ 41}, /* 26 */ - {16UL, b32+ 18, b32+205, P_LE | P_ATTEST, 0, b32+ 88, 0, aliases+ 56}, /* 27 */ - {16UL, b32+ 18, b32+205, P_LE | P_ATTEST, b32+205, b32+114, b32+187, aliases+ 45}, /* 28 */ - { 7UL, b32+ 19, 0, P_BE | P_ACADEM, 0, b32+183, 0, aliases+134}, /* 29 */ - { 6UL, b32+ 27, b32+195, P_BE | P_ACADEM, 0, b32+185, 0, aliases+122}, /* 30 */ - { 8UL, b32 + 28, 0, P_BE | P_ACADEM, 0, b32 + 57, 0, aliases + 145}, /* 31 */ - { 8UL, b32+ 28, b32+158, P_BE | P_ATTEST, 0, b32+118, 0, aliases+153}, /* 32 */ - { 8UL, b32+ 28, b32+197, P_BE | P_ATTEST, 0, b32+ 95, 0, aliases+148}, /* 33 */ - { 8UL, b32+ 28, b32+201, P_BE | P_ATTEST, b32+201, b32+ 70, b32+156, aliases+157}, /* 34 */ - { 8UL, b32+ 28, b32+201, P_LE | P_ATTEST, 0, b32+116, 0, aliases+159}, /* 35 */ - {16UL, b32+ 30, b32+205, P_BE | P_ATTEST, b32+205, b32+131, b32+179, aliases+ 61}, /* 36 */ - {32UL, b32+ 31, b32+209, P_LE | P_ATTEST, b32+209, b32+178, b32+145, aliases+101}, /* 37 */ - {14UL, b32+ 35, 0, P_LE | P_ATTEST, 0, b32+ 36, 0, aliases+ 17}, /* 38 */ - { 5UL, b32+ 46, b32+194, P_LE | P_THIRDP, b32+194, b32+160, b32+ 49, aliases+120}, /* 39 */ - { 8UL, b32+ 48, 0, P_BE | P_ATTEST, 0, b32+ 61, 0, aliases+155}, /* 40 */ - { 8UL, b32+ 48, b32+201, P_BE | P_ATTEST, b32+201, b32+176, b32+ 63, aliases+139}, /* 41 */ - { 4UL, b32+ 49, 0, P_LE | P_ACADEM, 0, b32+ 89, 0, aliases+112}, /* 42 */ - { 4UL, b32+ 49, b32+186, P_BE | P_ACADEM, b32+186, b32+136, b32+ 33, aliases+113}, /* 43 */ - { 8UL, b32+ 51, 0, P_LE | P_ATTEST, 0, b32+126, 0, aliases+152}, /* 44 */ - { 8UL, b32+ 51, b32+201, P_BE | P_ATTEST, 0, b32+193, 0, aliases+154}, /* 45 */ - {24UL, b32+ 54, b32+206, P_BE | P_ACADEM, b32+206, b32+143, b32+ 21, aliases+ 80}, /* 46 */ - { 8UL, b32+ 59, 0, P_LE | P_ATTEST, 0, b32+ 22, 0, aliases+142}, /* 47 */ - {16UL, b32+ 60, 0, P_BE | P_CONFIR, b32+205, b32+154, b32+127, aliases+ 38}, /* 48 */ - {16UL, b32+ 60, 0, P_LE | P_CONFIR, b32+205, b32+184, b32+ 86, aliases+ 37}, /* 49 */ - {64UL, b64d, 0, P_BE | P_ACADEM, 0, b64e, 0, aliases+128}, /* 50 */ - {64UL, b64d, b64a, P_BE | P_CONFIR, b64a, b64f, b64g, aliases+131}, /* 51 */ - {64UL, b64d, b64a, P_LE | P_ATTEST, b64a, b64h, b64i, aliases+132}, /* 52 */ - { 5UL, b32+ 66, b32+ 66, P_BE | P_ATTEST, 0, 0, 0, aliases+117}, /* 53 */ - { 8UL, b32+ 67, 0, P_BE | P_ACADEM, b32+201, b32+115, b32+ 74, aliases+146}, /* 54 */ - {16UL, b32+ 77, 0, P_BE | P_ATTEST, 0, b32+ 78, 0, aliases+ 59}, /* 55 */ - {10UL, b32+ 79, 0, P_BE | P_ACADEM, b32+202, b32+ 68, b32+ 52, aliases+ 6}, /* 56 */ - {24UL, b32+ 80, b32+133, P_BE | P_ATTEST, 0, b32+ 32, 0, aliases+ 79}, /* 57 */ - {24UL, b32+ 80, b32+199, P_BE | P_ATTEST, 0, b32+ 94, 0, aliases+ 78}, /* 58 */ - { 3UL, b32+ 81, 0, P_BE | P_ACADEM, b32+177, b32+ 96, b32+ 62, aliases+ 85}, /* 59 */ - { 3UL, b32+ 81, b32+177, P_LE | P_ACADEM, 0, b32+151, 0, aliases+ 86}, /* 60 */ - {11UL, b32+ 82, 0, P_BE | P_ACADEM, 0, b32+ 15, 0, aliases+ 10}, /* 61 */ - { 6UL, b32+ 84, 0, P_LE | P_ATTEST, 0, b32+117, 0, aliases+123}, /* 62 */ - {16UL, b32+ 87, 0, P_BE | P_THIRDP, 0, b32+149, 0, aliases+ 52}, /* 63 */ - {11UL, b32+ 90, b32+ 6, P_BE | P_ATTEST, 0, b32+141, 0, aliases+ 9}, /* 64 */ - {16UL, b32+ 91, 0, P_BE | P_ATTEST, 0, b32+ 37, 0, aliases+ 60}, /* 65 */ - {24UL, b32+ 97, 0, P_BE | P_ACADEM, 0, b32+ 40, 0, aliases+ 82}, /* 66 */ - {24UL, b32+ 97, b32+206, P_BE | P_ATTEST, b32+206, b32+ 34, b32+100, aliases+ 84}, /* 67 */ - {16UL, b32+ 98, 0, P_BE | P_ATTEST, 0, b32+200, 0, aliases+ 67}, /* 68 */ - {16UL, b32+ 98, 0, P_LE | P_CONFIR, 0, b32+146, 0, aliases+ 24}, /* 69 */ - {16UL, b32+ 98, 0, P_LE | P_ATTEST, b32+205, b32+ 64, b32+137, aliases+ 55}, /* 70 */ - {16UL, b32+ 98, b32+ 99, P_BE | P_ATTEST, 0, b32+123, 0, aliases+ 34}, /* 71 */ - {16UL, b32+ 98, b32+205, P_BE | P_THIRDP, 0, b32+135, 0, aliases+ 32}, /* 72 */ - {16UL, b32+ 98, b32+205, P_LE | P_ATTEST, 0, b32+ 71, 0, aliases+ 57}, /* 73 */ - {16UL, b32+ 98, b32+205, P_LE | P_THIRDP, b32+205, b32+142, b32+137, aliases+ 68}, /* 74 */ - {14UL, b32+101, 0, P_BE | P_ACADEM, b32+204, b32+155, b32+ 16, aliases+ 18}, /* 75 */ - {30UL, b32+102, b32+207, P_BE | P_ACADEM, b32+207, b32+ 20, b32+169, aliases+ 87}, /* 76 */ - {12UL, b32+103, 0, P_BE | P_ACADEM, 0, b32+191, 0, aliases+ 13}, /* 77 */ - {12UL, b32+103, 0, P_BELE | P_ACADEM, 0, b32+174, 0, aliases+ 15}, /* 78 */ - {32UL, b32+104, 0, P_BE | P_ATTEST, 0, b32+ 50, 0, aliases+ 92}, /* 79 */ - {21UL, b32+105, 0, P_BE | P_ACADEM, 0, b32+ 93, 0, aliases+ 75}, /* 80 */ - {24UL, b32+106, 0, P_BE | P_ACADEM, 0, b32+163, 0, aliases+ 81}, /* 81 */ - {24UL, b32+106, b32+144, P_BE | P_ATTEST, 0, b32+ 39, 0, aliases+ 83}, /* 82 */ - { 7UL, b32+109, 0, P_BE | P_ACADEM, 0, b32+152, 0, aliases+136}, /* 83 */ - {15UL, b32+110, 0, P_BE | P_ACADEM, 0, b32+ 13, 0, aliases+ 20}, /* 84 */ - {16UL, b32+111, 0, P_BE | P_ATTEST, 0, b32+167, 0, aliases+ 64}, /* 85 */ - {10UL, b32+112, 0, P_BE | P_ATTEST, 0, b32+ 85, 0, aliases+ 4}, /* 86 */ - { 8UL, b32+119, 0, P_BE | P_ACADEM, 0, b32+183, 0, aliases+150}, /* 87 */ - { 8UL, b32+119, 0, P_LE | P_THIRDP, 0, b32+ 41, 0, aliases+160}, /* 88 */ - { 8UL, b32+119, b32+201, P_BE | P_ACADEM, 0, b32+173, 0, aliases+141}, /* 89 */ - { 6UL, b32+120, b32+195, P_BE | P_ATTEST, 0, b32+ 55, 0, aliases+121}, /* 90 */ - { 7UL, b32+122, b32+198, P_LE | P_ACADEM, 0, b32+128, 0, aliases+135}, /* 91 */ - {16UL, b32+125, 0, P_BE | P_CONFIR, 0, b32+ 17, 0, aliases+ 65}, /* 92 */ - { 8UL, b32+129, 0, P_LE | P_ATTEST, 0, b32+ 42, 0, aliases+140}, /* 93 */ - { 5UL, b32+130, 0, P_LE | P_ACADEM, 0, b32+ 58, 0, aliases+118}, /* 94 */ - {32UL, b32+132, b32+209, P_LE | P_CONFIR, b32+209, b32+107, b32+ 65, aliases+ 95}, /* 95 */ - {17UL, b32+140, 0, P_BE | P_ACADEM, 0, b32+ 44, 0, aliases+ 74}, /* 96 */ - { 6UL, b32+147, 0, P_BE | P_ACADEM, b32+195, b32+ 72, b32+182, aliases+125}, /* 97 */ - {16UL, b32+161, b32+205, P_BE | P_ACADEM, 0, b32+ 73, 0, aliases+ 31}, /* 98 */ - {15UL, b32+166, 0, P_BE | P_ATTEST, b32+ 2, b32+ 69, b32+166, aliases+ 21}, /* 99 */ - {12UL, b32+168, 0, P_BE | P_ACADEM, b32+203, b32+139, b32+ 24, aliases+ 14}, /* 100 */ - { 8UL, b32+171, 0, P_BE | P_ACADEM, 0, b32+147, 0, aliases+143}, /* 101 */ - {13UL, b32+181, 0, P_BE | P_ATTEST, 0, b32+ 45, 0, aliases+ 16}, /* 102 */ - {12UL, b32+188, b32+203, P_BE | P_ACADEM, 0, b32+170, 0, aliases+ 12}, /* 103 */ - {32UL, b32+190, b32+209, P_LE | P_ATTEST, b32+209, b32+ 23, b32+113, aliases+ 93}, /* 104 */ - {10UL, b32+192, b32+202, P_BE | P_ACADEM, 0, b32+112, 0, aliases+ 5}, /* 105 */ - { 0UL, 0, 0, P_BE | P_UNDFCL, 0, 0, 0, NULL }, /* terminating entry */ + {64UL, b64, b64a, P_LE | P_CONFIR, b64a, b64b, b64c, aliases + 130}, /* 0 */ + {32UL, b32 + 0, 0, P_BE | P_CONFIR, 0, b32 + 148, 0, aliases + 107}, /* 1 */ + {40UL, b40, 0, P_BE | P_ACADEM, b40a, b40b, b40c, aliases + 115}, /* 2 */ + {24UL, b32 + 3, b32 + 76, P_LE | P_ATTEST, 0, b32 + 153, 0, aliases + 77}, /* 3 */ + {32UL, b32 + 8, 0, P_BE | P_ATTEST, b32 + 209, b32 + 92, b32 + 159, aliases + 98}, /* 4 */ + {32UL, b32 + 8, b32 + 209, P_BE | P_ATTEST, 0, b32 + 7, 0, aliases + 104}, /* 5 */ + {32UL, b32 + 8, b32 + 209, P_BE | P_ATTEST, b32 + 209, b32 + 196, b32 + 159, aliases + 96}, /* 6 */ + {32UL, b32 + 8, b32 + 209, P_LE | P_CONFIR, 0, b32 + 56, 0, aliases + 103}, /* 7 */ + {32UL, b32 + 8, b32 + 209, P_LE | P_ATTEST, b32 + 209, b32 + 162, b32 + 175, aliases + 102}, /* 8 */ + {16UL, b32 + 9, 0, P_BE | P_ATTEST, 0, b32 + 5, 0, aliases + 36}, /* 9 */ + {16UL, b32 + 9, 0, P_BE | P_ATTEST, b32 + 1, b32 + 4, b32 + 9, aliases + 35}, /* 10 */ + { 8UL, b32 + 10, 0, P_BE | P_ATTEST, 0, b32 + 189, 0, aliases + 158}, /* 11 */ + { 8UL, b32 + 10, 0, P_BE | P_ACADEM, b32 + 75, b32 + 126, b32 + 134, aliases + 147}, /* 12 */ + { 8UL, b32 + 10, b32 + 201, P_LE | P_ACADEM, 0, b32 + 165, 0, aliases + 156}, /* 13 */ + {16UL, b32 + 11, b32 + 205, P_LE | P_ATTEST, 0, b32 + 124, 0, aliases + 58}, /* 14 */ + {31UL, b32 + 12, b32 + 208, P_BE | P_CONFIR, b32 + 208, b32 + 26, b32 + 121, aliases + 88}, /* 15 */ + { 6UL, b32 + 14, 0, P_LE | P_ACADEM, 0, b32 + 25, 0, aliases + 124}, /* 16 */ + {82UL, b82, 0, P_LE | P_ATTEST, 0, b82a, 0, aliases + 161}, /* 17 */ + {16UL, b32 + 18, 0, P_BE | P_ATTEST, 0, b32 + 53, 0, aliases + 73}, /* 18 */ + {16UL, b32 + 18, 0, P_BE | P_ACADEM, b32 + 205, b32 + 164, b32 + 29, aliases + 42}, /* 19 */ + {16UL, b32 + 18, 0, P_LE | P_ATTEST, 0, b32 + 38, 0, aliases + 50}, /* 20 */ + {16UL, b32 + 18, b32 + 29, P_BE | P_ATTEST, 0, b32 + 180, 0, aliases + 63}, /* 21 */ + {16UL, b32 + 18, b32 + 108, P_LE | P_ATTEST, 0, b32 + 43, 0, aliases + 66}, /* 22 */ + {16UL, b32 + 18, b32 + 138, P_LE | P_THIRDP, 0, b32 + 83, 0, aliases + 62}, /* 23 */ + {16UL, b32 + 18, b32 + 157, P_LE | P_ATTEST, 0, b32 + 150, 0, aliases + 48}, /* 24 */ + {16UL, b32 + 18, b32 + 205, P_BE | P_ATTEST, 0, b32 + 47, 0, aliases + 44}, /* 25 */ + {16UL, b32 + 18, b32 + 205, P_BE | P_ATTEST, b32 + 205, b32 + 172, b32 + 29, aliases + 41}, /* 26 */ + {16UL, b32 + 18, b32 + 205, P_LE | P_ATTEST, 0, b32 + 88, 0, aliases + 56}, /* 27 */ + {16UL, b32 + 18, b32 + 205, P_LE | P_ATTEST, b32 + 205, b32 + 114, b32 + 187, aliases + 45}, /* 28 */ + { 7UL, b32 + 19, 0, P_BE | P_ACADEM, 0, b32 + 183, 0, aliases + 134}, /* 29 */ + { 6UL, b32 + 27, b32 + 195, P_BE | P_ACADEM, 0, b32 + 185, 0, aliases + 122}, /* 30 */ + { 8UL, b32 + 28, 0, P_BE | P_ACADEM, 0, b32 + 57, 0, aliases + 145}, /* 31 */ + { 8UL, b32 + 28, b32 + 158, P_BE | P_ATTEST, 0, b32 + 118, 0, aliases + 153}, /* 32 */ + { 8UL, b32 + 28, b32 + 197, P_BE | P_ATTEST, 0, b32 + 95, 0, aliases + 148}, /* 33 */ + { 8UL, b32 + 28, b32 + 201, P_BE | P_ATTEST, b32 + 201, b32 + 70, b32 + 156, aliases + 157}, /* 34 */ + { 8UL, b32 + 28, b32 + 201, P_LE | P_ATTEST, 0, b32 + 116, 0, aliases + 159}, /* 35 */ + {16UL, b32 + 30, b32 + 205, P_BE | P_ATTEST, b32 + 205, b32 + 131, b32 + 179, aliases + 61}, /* 36 */ + {32UL, b32 + 31, b32 + 209, P_LE | P_ATTEST, b32 + 209, b32 + 178, b32 + 145, aliases + 101}, /* 37 */ + {14UL, b32 + 35, 0, P_LE | P_ATTEST, 0, b32 + 36, 0, aliases + 17}, /* 38 */ + { 5UL, b32 + 46, b32 + 194, P_LE | P_THIRDP, b32 + 194, b32 + 160, b32 + 49, aliases + 120}, /* 39 */ + { 8UL, b32 + 48, 0, P_BE | P_ATTEST, 0, b32 + 61, 0, aliases + 155}, /* 40 */ + { 8UL, b32 + 48, b32 + 201, P_BE | P_ATTEST, b32 + 201, b32 + 176, b32 + 63, aliases + 139}, /* 41 */ + { 4UL, b32 + 49, 0, P_LE | P_ACADEM, 0, b32 + 89, 0, aliases + 112}, /* 42 */ + { 4UL, b32 + 49, b32 + 186, P_BE | P_ACADEM, b32 + 186, b32 + 136, b32 + 33, aliases + 113}, /* 43 */ + { 8UL, b32 + 51, 0, P_LE | P_ATTEST, 0, b32 + 126, 0, aliases + 152}, /* 44 */ + { 8UL, b32 + 51, b32 + 201, P_BE | P_ATTEST, 0, b32 + 193, 0, aliases + 154}, /* 45 */ + {24UL, b32 + 54, b32 + 206, P_BE | P_ACADEM, b32 + 206, b32 + 143, b32 + 21, aliases + 80}, /* 46 */ + { 8UL, b32 + 59, 0, P_LE | P_ATTEST, 0, b32 + 22, 0, aliases + 142}, /* 47 */ + {16UL, b32 + 60, 0, P_BE | P_CONFIR, b32 + 205, b32 + 154, b32 + 127, aliases + 38}, /* 48 */ + {16UL, b32 + 60, 0, P_LE | P_CONFIR, b32 + 205, b32 + 184, b32 + 86, aliases + 37}, /* 49 */ + {64UL, b64d, 0, P_BE | P_ACADEM, 0, b64e, 0, aliases + 128}, /* 50 */ + {64UL, b64d, b64a, P_BE | P_CONFIR, b64a, b64f, b64g, aliases + 131}, /* 51 */ + {64UL, b64d, b64a, P_LE | P_ATTEST, b64a, b64h, b64i, aliases + 132}, /* 52 */ + { 5UL, b32 + 66, b32 + 66, P_BE | P_ATTEST, 0, 0, 0, aliases + 117}, /* 53 */ + { 8UL, b32 + 67, 0, P_BE | P_ACADEM, b32 + 201, b32 + 115, b32 + 74, aliases + 146}, /* 54 */ + {16UL, b32 + 77, 0, P_BE | P_ATTEST, 0, b32 + 78, 0, aliases + 59}, /* 55 */ + {10UL, b32 + 79, 0, P_BE | P_ACADEM, b32 + 202, b32 + 68, b32 + 52, aliases + 6}, /* 56 */ + {24UL, b32 + 80, b32 + 133, P_BE | P_ATTEST, 0, b32 + 32, 0, aliases + 79}, /* 57 */ + {24UL, b32 + 80, b32 + 199, P_BE | P_ATTEST, 0, b32 + 94, 0, aliases + 78}, /* 58 */ + { 3UL, b32 + 81, 0, P_BE | P_ACADEM, b32 + 177, b32 + 96, b32 + 62, aliases + 85}, /* 59 */ + { 3UL, b32 + 81, b32 + 177, P_LE | P_ACADEM, 0, b32 + 151, 0, aliases + 86}, /* 60 */ + {11UL, b32 + 82, 0, P_BE | P_ACADEM, 0, b32 + 15, 0, aliases + 10}, /* 61 */ + { 6UL, b32 + 84, 0, P_LE | P_ATTEST, 0, b32 + 117, 0, aliases + 123}, /* 62 */ + {16UL, b32 + 87, 0, P_BE | P_THIRDP, 0, b32 + 149, 0, aliases + 52}, /* 63 */ + {11UL, b32 + 90, b32 + 6, P_BE | P_ATTEST, 0, b32 + 141, 0, aliases + 9}, /* 64 */ + {16UL, b32 + 91, 0, P_BE | P_ATTEST, 0, b32 + 37, 0, aliases + 60}, /* 65 */ + {24UL, b32 + 97, 0, P_BE | P_ACADEM, 0, b32 + 40, 0, aliases + 82}, /* 66 */ + {24UL, b32 + 97, b32 + 206, P_BE | P_ATTEST, b32 + 206, b32 + 34, b32 + 100, aliases + 84}, /* 67 */ + {16UL, b32 + 98, 0, P_BE | P_ATTEST, 0, b32 + 200, 0, aliases + 67}, /* 68 */ + {16UL, b32 + 98, 0, P_LE | P_CONFIR, 0, b32 + 146, 0, aliases + 24}, /* 69 */ + {16UL, b32 + 98, 0, P_LE | P_ATTEST, b32 + 205, b32 + 64, b32 + 137, aliases + 55}, /* 70 */ + {16UL, b32 + 98, b32 + 99, P_BE | P_ATTEST, 0, b32 + 123, 0, aliases + 34}, /* 71 */ + {16UL, b32 + 98, b32 + 205, P_BE | P_THIRDP, 0, b32 + 135, 0, aliases + 32}, /* 72 */ + {16UL, b32 + 98, b32 + 205, P_LE | P_ATTEST, 0, b32 + 71, 0, aliases + 57}, /* 73 */ + {16UL, b32 + 98, b32 + 205, P_LE | P_THIRDP, b32 + 205, b32 + 142, b32 + 137, aliases + 68}, /* 74 */ + {14UL, b32 + 101, 0, P_BE | P_ACADEM, b32 + 204, b32 + 155, b32 + 16, aliases + 18}, /* 75 */ + {30UL, b32 + 102, b32 + 207, P_BE | P_ACADEM, b32 + 207, b32 + 20, b32 + 169, aliases + 87}, /* 76 */ + {12UL, b32 + 103, 0, P_BE | P_ACADEM, 0, b32 + 191, 0, aliases + 13}, /* 77 */ + {12UL, b32 + 103, 0, P_BELE | P_ACADEM, 0, b32 + 174, 0, aliases + 15}, /* 78 */ + {32UL, b32 + 104, 0, P_BE | P_ATTEST, 0, b32 + 50, 0, aliases + 92}, /* 79 */ + {21UL, b32 + 105, 0, P_BE | P_ACADEM, 0, b32 + 93, 0, aliases + 75}, /* 80 */ + {24UL, b32 + 106, 0, P_BE | P_ACADEM, 0, b32 + 163, 0, aliases + 81}, /* 81 */ + {24UL, b32 + 106, b32 + 144, P_BE | P_ATTEST, 0, b32 + 39, 0, aliases + 83}, /* 82 */ + { 7UL, b32 + 109, 0, P_BE | P_ACADEM, 0, b32 + 152, 0, aliases + 136}, /* 83 */ + {15UL, b32 + 110, 0, P_BE | P_ACADEM, 0, b32 + 13, 0, aliases + 20}, /* 84 */ + {16UL, b32 + 111, 0, P_BE | P_ATTEST, 0, b32 + 167, 0, aliases + 64}, /* 85 */ + {10UL, b32 + 112, 0, P_BE | P_ATTEST, 0, b32 + 85, 0, aliases + 4}, /* 86 */ + { 8UL, b32 + 119, 0, P_BE | P_ACADEM, 0, b32 + 183, 0, aliases + 150}, /* 87 */ + { 8UL, b32 + 119, 0, P_LE | P_THIRDP, 0, b32 + 41, 0, aliases + 160}, /* 88 */ + { 8UL, b32 + 119, b32 + 201, P_BE | P_ACADEM, 0, b32 + 173, 0, aliases + 141}, /* 89 */ + { 6UL, b32 + 120, b32 + 195, P_BE | P_ATTEST, 0, b32 + 55, 0, aliases + 121}, /* 90 */ + { 7UL, b32 + 122, b32 + 198, P_LE | P_ACADEM, 0, b32 + 128, 0, aliases + 135}, /* 91 */ + {16UL, b32 + 125, 0, P_BE | P_CONFIR, 0, b32 + 17, 0, aliases + 65}, /* 92 */ + { 8UL, b32 + 129, 0, P_LE | P_ATTEST, 0, b32 + 42, 0, aliases + 140}, /* 93 */ + { 5UL, b32 + 130, 0, P_LE | P_ACADEM, 0, b32 + 58, 0, aliases + 118}, /* 94 */ + {32UL, b32 + 132, b32 + 209, P_LE | P_CONFIR, b32 + 209, b32 + 107, b32 + 65, aliases + 95}, /* 95 */ + {17UL, b32 + 140, 0, P_BE | P_ACADEM, 0, b32 + 44, 0, aliases + 74}, /* 96 */ + { 6UL, b32 + 147, 0, P_BE | P_ACADEM, b32 + 195, b32 + 72, b32 + 182, aliases + 125}, /* 97 */ + {16UL, b32 + 161, b32 + 205, P_BE | P_ACADEM, 0, b32 + 73, 0, aliases + 31}, /* 98 */ + {15UL, b32 + 166, 0, P_BE | P_ATTEST, b32 + 2, b32 + 69, b32 + 166, aliases + 21}, /* 99 */ + {12UL, b32 + 168, 0, P_BE | P_ACADEM, b32 + 203, b32 + 139, b32 + 24, aliases + 14}, /* 100 */ + { 8UL, b32 + 171, 0, P_BE | P_ACADEM, 0, b32 + 147, 0, aliases + 143}, /* 101 */ + {13UL, b32 + 181, 0, P_BE | P_ATTEST, 0, b32 + 45, 0, aliases + 16}, /* 102 */ + {12UL, b32 + 188, b32 + 203, P_BE | P_ACADEM, 0, b32 + 170, 0, aliases + 12}, /* 103 */ + {32UL, b32 + 190, b32 + 209, P_LE | P_ATTEST, b32 + 209, b32 + 23, b32 + 113, aliases + 93}, /* 104 */ + {10UL, b32 + 192, b32 + 202, P_BE | P_ACADEM, 0, b32 + 112, 0, aliases + 5}, /* 105 */ + { 0UL, 0, 0, P_BE | P_UNDFCL, 0, 0, 0, NULL }, /* terminating entry */ }; # define NPRESETS 106 /* List of names with pointers to models, pre-sorted for use with bsearch() */ static const struct malias aliases[] = { - {"ARC", models+ 69}, /* 0 */ - {"B-CRC-32", models + 6}, /* 1 */ - {"CKSUM", models + 4}, /* 2 */ - {"CRC-10", models+ 86}, /* 3 */ - {"CRC-10/ATM", models+ 86}, /* 4 */ - {"CRC-10/CDMA2000", models+105}, /* 5 */ - {"CRC-10/GSM", models+ 56}, /* 6 */ - {"CRC-10/I-610", models+ 86}, /* 7 */ - {"CRC-11", models+ 64}, /* 8 */ - {"CRC-11/FLEXRAY", models+ 64}, /* 9 */ - {"CRC-11/UMTS", models+ 61}, /* 10 */ - {"CRC-12/3GPP", models+ 78}, /* 11 */ - {"CRC-12/CDMA2000", models+103}, /* 12 */ - {"CRC-12/DECT", models+ 77}, /* 13 */ - {"CRC-12/GSM", models+100}, /* 14 */ - {"CRC-12/UMTS", models+ 78}, /* 15 */ - {"CRC-13/BBC", models+102}, /* 16 */ - {"CRC-14/DARC", models+ 38}, /* 17 */ - {"CRC-14/GSM", models+ 75}, /* 18 */ - {"CRC-15", models+ 84}, /* 19 */ - {"CRC-15/CAN", models+ 84}, /* 20 */ - {"CRC-15/MPT1327", models+ 99}, /* 21 */ - {"CRC-16", models+ 69}, /* 22 */ - {"CRC-16/ACORN", models + 18}, /* 23 */ - {"CRC-16/ARC", models+ 69}, /* 24 */ - {"CRC-16/AUG-CCITT", models + 21}, /* 25 */ - {"CRC-16/AUTOSAR", models + 25}, /* 26 */ - {"CRC-16/BUYPASS", models+ 68}, /* 27 */ - {"CRC-16/CCITT", models + 20}, /* 28 */ - {"CRC-16/CCITT-FALSE", models + 25}, /* 29 */ - {"CRC-16/CCITT-TRUE", models + 20}, /* 30 */ - {"CRC-16/CDMA2000", models+ 98}, /* 31 */ - {"CRC-16/CMS", models+ 72}, /* 32 */ - {"CRC-16/DARC", models + 26}, /* 33 */ - {"CRC-16/DDS-110", models+ 71}, /* 34 */ - {"CRC-16/DECT-R", models + 10}, /* 35 */ - {"CRC-16/DECT-X", models + 9}, /* 36 */ - {"CRC-16/DNP", models+ 49}, /* 37 */ - {"CRC-16/EN-13757", models+ 48}, /* 38 */ - {"CRC-16/EPC", models + 26}, /* 39 */ - {"CRC-16/EPC-C1G2", models + 26}, /* 40 */ - {"CRC-16/GENIBUS", models + 26}, /* 41 */ - {"CRC-16/GSM", models + 19}, /* 42 */ - {"CRC-16/I-CODE", models + 26}, /* 43 */ - {"CRC-16/IBM-3740", models + 25}, /* 44 */ - {"CRC-16/IBM-SDLC", models + 28}, /* 45 */ - {"CRC-16/IEC-61158-2", models+ 36}, /* 46 */ - {"CRC-16/ISO-HDLC", models + 28}, /* 47 */ - {"CRC-16/ISO-IEC-14443-3-A", models + 24}, /* 48 */ - {"CRC-16/ISO-IEC-14443-3-B", models + 28}, /* 49 */ - {"CRC-16/KERMIT", models + 20}, /* 50 */ - {"CRC-16/LHA", models+ 69}, /* 51 */ - {"CRC-16/LJ1200", models+ 63}, /* 52 */ - {"CRC-16/LTE", models + 18}, /* 53 */ - {"CRC-16/MAXIM", models+ 70}, /* 54 */ - {"CRC-16/MAXIM-DOW", models+ 70}, /* 55 */ - {"CRC-16/MCRF4XX", models + 27}, /* 56 */ - {"CRC-16/MODBUS", models+ 73}, /* 57 */ - {"CRC-16/NRSC-5", models + 14}, /* 58 */ - {"CRC-16/OPENSAFETY-A", models+ 55}, /* 59 */ - {"CRC-16/OPENSAFETY-B", models+ 65}, /* 60 */ - {"CRC-16/PROFIBUS", models+ 36}, /* 61 */ - {"CRC-16/RIELLO", models + 23}, /* 62 */ - {"CRC-16/SPI-FUJITSU", models + 21}, /* 63 */ - {"CRC-16/T10-DIF", models+ 85}, /* 64 */ - {"CRC-16/TELEDISK", models+ 92}, /* 65 */ - {"CRC-16/TMS37157", models + 22}, /* 66 */ - {"CRC-16/UMTS", models+ 68}, /* 67 */ - {"CRC-16/USB", models+ 74}, /* 68 */ - {"CRC-16/V-41-LSB", models + 20}, /* 69 */ - {"CRC-16/V-41-MSB", models + 18}, /* 70 */ - {"CRC-16/VERIFONE", models+ 68}, /* 71 */ - {"CRC-16/X-25", models + 28}, /* 72 */ - {"CRC-16/XMODEM", models + 18}, /* 73 */ - {"CRC-17/CAN-FD", models+ 96}, /* 74 */ - {"CRC-21/CAN-FD", models+ 80}, /* 75 */ - {"CRC-24", models+ 82}, /* 76 */ - {"CRC-24/BLE", models + 3}, /* 77 */ - {"CRC-24/FLEXRAY-A", models+ 58}, /* 78 */ - {"CRC-24/FLEXRAY-B", models+ 57}, /* 79 */ - {"CRC-24/INTERLAKEN", models+ 46}, /* 80 */ - {"CRC-24/LTE-A", models+ 81}, /* 81 */ - {"CRC-24/LTE-B", models+ 66}, /* 82 */ - {"CRC-24/OPENPGP", models+ 82}, /* 83 */ - {"CRC-24/OS-9", models+ 67}, /* 84 */ - {"CRC-3/GSM", models+ 59}, /* 85 */ - {"CRC-3/ROHC", models+ 60}, /* 86 */ - {"CRC-30/CDMA", models+ 76}, /* 87 */ - {"CRC-31/PHILIPS", models + 15}, /* 88 */ - {"CRC-32", models + 8}, /* 89 */ - {"CRC-32/AAL5", models + 6}, /* 90 */ - {"CRC-32/ADCCP", models + 8}, /* 91 */ - {"CRC-32/AIXM", models+ 79}, /* 92 */ - {"CRC-32/AUTOSAR", models+104}, /* 93 */ - {"CRC-32/BASE91-C", models+ 37}, /* 94 */ - {"CRC-32/BASE91-D", models+ 95}, /* 95 */ - {"CRC-32/BZIP2", models + 6}, /* 96 */ - {"CRC-32/CASTAGNOLI", models+ 37}, /* 97 */ - {"CRC-32/CKSUM", models + 4}, /* 98 */ - {"CRC-32/DECT-B", models + 6}, /* 99 */ - {"CRC-32/INTERLAKEN", models+ 37}, /* 100 */ - {"CRC-32/ISCSI", models+ 37}, /* 101 */ - {"CRC-32/ISO-HDLC", models + 8}, /* 102 */ - {"CRC-32/JAMCRC", models + 7}, /* 103 */ - {"CRC-32/MPEG-2", models + 5}, /* 104 */ - {"CRC-32/POSIX", models + 4}, /* 105 */ - {"CRC-32/V-42", models + 8}, /* 106 */ - {"CRC-32/XFER", models + 1}, /* 107 */ - {"CRC-32/XZ", models + 8}, /* 108 */ - {"CRC-32C", models+ 37}, /* 109 */ - {"CRC-32D", models+ 95}, /* 110 */ - {"CRC-32Q", models+ 79}, /* 111 */ - {"CRC-4/G-704", models+ 42}, /* 112 */ - {"CRC-4/INTERLAKEN", models+ 43}, /* 113 */ - {"CRC-4/ITU", models+ 42}, /* 114 */ - {"CRC-40/GSM", models + 2}, /* 115 */ - {"CRC-5/EPC", models+ 53}, /* 116 */ - {"CRC-5/EPC-C1G2", models+ 53}, /* 117 */ - {"CRC-5/G-704", models+ 94}, /* 118 */ - {"CRC-5/ITU", models+ 94}, /* 119 */ - {"CRC-5/USB", models+ 39}, /* 120 */ - {"CRC-6/CDMA2000-A", models+ 90}, /* 121 */ - {"CRC-6/CDMA2000-B", models + 30}, /* 122 */ - {"CRC-6/DARC", models+ 62}, /* 123 */ - {"CRC-6/G-704", models + 16}, /* 124 */ - {"CRC-6/GSM", models+ 97}, /* 125 */ - {"CRC-6/ITU", models + 16}, /* 126 */ - {"CRC-64", models+ 50}, /* 127 */ - {"CRC-64/ECMA-182", models+ 50}, /* 128 */ - {"CRC-64/GO-ECMA", models+ 52}, /* 129 */ - {"CRC-64/GO-ISO", models + 0}, /* 130 */ - {"CRC-64/WE", models+ 51}, /* 131 */ - {"CRC-64/XZ", models+ 52}, /* 132 */ - {"CRC-7", models + 29}, /* 133 */ - {"CRC-7/MMC", models + 29}, /* 134 */ - {"CRC-7/ROHC", models+ 91}, /* 135 */ - {"CRC-7/UMTS", models+ 83}, /* 136 */ - {"CRC-8", models + 11}, /* 137 */ - {"CRC-8/AES", models+ 35}, /* 138 */ - {"CRC-8/AUTOSAR", models+ 41}, /* 139 */ - {"CRC-8/BLUETOOTH", models+ 93}, /* 140 */ - {"CRC-8/CDMA2000", models+ 89}, /* 141 */ - {"CRC-8/DARC", models+ 47}, /* 142 */ - {"CRC-8/DVB-S2", models+101}, /* 143 */ - {"CRC-8/EBU", models+ 35}, /* 144 */ - {"CRC-8/GSM-A", models + 31}, /* 145 */ - {"CRC-8/GSM-B", models+ 54}, /* 146 */ - {"CRC-8/I-432-1", models + 12}, /* 147 */ - {"CRC-8/I-CODE", models+ 33}, /* 148 */ - {"CRC-8/ITU", models + 12}, /* 149 */ - {"CRC-8/LTE", models+ 87}, /* 150 */ - {"CRC-8/MAXIM", models+ 44}, /* 151 */ - {"CRC-8/MAXIM-DOW", models+ 44}, /* 152 */ - {"CRC-8/MIFARE-MAD", models+ 32}, /* 153 */ - {"CRC-8/NRSC-5", models+ 45}, /* 154 */ - {"CRC-8/OPENSAFETY", models+ 40}, /* 155 */ - {"CRC-8/ROHC", models+ 13}, /* 156 */ - {"CRC-8/SAE-J1850", models+ 34}, /* 157 */ - {"CRC-8/SMBUS", models+ 11}, /* 158 */ - {"CRC-8/TECH-3250", models+ 35}, /* 159 */ - {"CRC-8/WCDMA", models+ 88}, /* 160 */ - {"CRC-82/DARC", models+ 17}, /* 161 */ - {"CRC-A", models+ 24}, /* 162 */ - {"CRC-B", models+ 28}, /* 163 */ - {"CRC-CCITT", models+ 20}, /* 164 */ - {"CRC-IBM", models+ 69}, /* 165 */ - {"DOW-CRC", models+ 44}, /* 166 */ - {"JAMCRC", models+ 7}, /* 167 */ - {"KERMIT", models+ 20}, /* 168 */ - {"MODBUS", models+ 73}, /* 169 */ - {"PKZIP", models+ 8}, /* 170 */ - {"R-CRC-16", models+ 10}, /* 171 */ - {"X-25", models+ 28}, /* 172 */ - {"X-CRC-12", models+ 77}, /* 173 */ - {"X-CRC-16", models+ 9}, /* 174 */ - {"XFER", models+ 1}, /* 175 */ - {"XMODEM", models+ 18}, /* 176 */ - {"ZMODEM", models+ 18}, /* 177 */ - {NULL, NULL }, /* terminating entry */ + {"ARC", models + 69}, /* 0 */ + {"B-CRC-32", models + 6}, /* 1 */ + {"CKSUM", models + 4}, /* 2 */ + {"CRC-10", models + 86}, /* 3 */ + {"CRC-10/ATM", models + 86}, /* 4 */ + {"CRC-10/CDMA2000", models + 105}, /* 5 */ + {"CRC-10/GSM", models + 56}, /* 6 */ + {"CRC-10/I-610", models + 86}, /* 7 */ + {"CRC-11", models + 64}, /* 8 */ + {"CRC-11/FLEXRAY", models + 64}, /* 9 */ + {"CRC-11/UMTS", models + 61}, /* 10 */ + {"CRC-12/3GPP", models + 78}, /* 11 */ + {"CRC-12/CDMA2000", models + 103}, /* 12 */ + {"CRC-12/DECT", models + 77}, /* 13 */ + {"CRC-12/GSM", models + 100}, /* 14 */ + {"CRC-12/UMTS", models + 78}, /* 15 */ + {"CRC-13/BBC", models + 102}, /* 16 */ + {"CRC-14/DARC", models + 38}, /* 17 */ + {"CRC-14/GSM", models + 75}, /* 18 */ + {"CRC-15", models + 84}, /* 19 */ + {"CRC-15/CAN", models + 84}, /* 20 */ + {"CRC-15/MPT1327", models + 99}, /* 21 */ + {"CRC-16", models + 69}, /* 22 */ + {"CRC-16/ACORN", models + 18}, /* 23 */ + {"CRC-16/ARC", models + 69}, /* 24 */ + {"CRC-16/AUG-CCITT", models + 21}, /* 25 */ + {"CRC-16/AUTOSAR", models + 25}, /* 26 */ + {"CRC-16/BUYPASS", models + 68}, /* 27 */ + {"CRC-16/CCITT", models + 20}, /* 28 */ + {"CRC-16/CCITT-FALSE", models + 25}, /* 29 */ + {"CRC-16/CCITT-TRUE", models + 20}, /* 30 */ + {"CRC-16/CDMA2000", models + 98}, /* 31 */ + {"CRC-16/CMS", models + 72}, /* 32 */ + {"CRC-16/DARC", models + 26}, /* 33 */ + {"CRC-16/DDS-110", models + 71}, /* 34 */ + {"CRC-16/DECT-R", models + 10}, /* 35 */ + {"CRC-16/DECT-X", models + 9}, /* 36 */ + {"CRC-16/DNP", models + 49}, /* 37 */ + {"CRC-16/EN-13757", models + 48}, /* 38 */ + {"CRC-16/EPC", models + 26}, /* 39 */ + {"CRC-16/EPC-C1G2", models + 26}, /* 40 */ + {"CRC-16/GENIBUS", models + 26}, /* 41 */ + {"CRC-16/GSM", models + 19}, /* 42 */ + {"CRC-16/I-CODE", models + 26}, /* 43 */ + {"CRC-16/IBM-3740", models + 25}, /* 44 */ + {"CRC-16/IBM-SDLC", models + 28}, /* 45 */ + {"CRC-16/IEC-61158-2", models + 36}, /* 46 */ + {"CRC-16/ISO-HDLC", models + 28}, /* 47 */ + {"CRC-16/ISO-IEC-14443-3-A", models + 24}, /* 48 */ + {"CRC-16/ISO-IEC-14443-3-B", models + 28}, /* 49 */ + {"CRC-16/KERMIT", models + 20}, /* 50 */ + {"CRC-16/LHA", models + 69}, /* 51 */ + {"CRC-16/LJ1200", models + 63}, /* 52 */ + {"CRC-16/LTE", models + 18}, /* 53 */ + {"CRC-16/MAXIM", models + 70}, /* 54 */ + {"CRC-16/MAXIM-DOW", models + 70}, /* 55 */ + {"CRC-16/MCRF4XX", models + 27}, /* 56 */ + {"CRC-16/MODBUS", models + 73}, /* 57 */ + {"CRC-16/NRSC-5", models + 14}, /* 58 */ + {"CRC-16/OPENSAFETY-A", models + 55}, /* 59 */ + {"CRC-16/OPENSAFETY-B", models + 65}, /* 60 */ + {"CRC-16/PROFIBUS", models + 36}, /* 61 */ + {"CRC-16/RIELLO", models + 23}, /* 62 */ + {"CRC-16/SPI-FUJITSU", models + 21}, /* 63 */ + {"CRC-16/T10-DIF", models + 85}, /* 64 */ + {"CRC-16/TELEDISK", models + 92}, /* 65 */ + {"CRC-16/TMS37157", models + 22}, /* 66 */ + {"CRC-16/UMTS", models + 68}, /* 67 */ + {"CRC-16/USB", models + 74}, /* 68 */ + {"CRC-16/V-41-LSB", models + 20}, /* 69 */ + {"CRC-16/V-41-MSB", models + 18}, /* 70 */ + {"CRC-16/VERIFONE", models + 68}, /* 71 */ + {"CRC-16/X-25", models + 28}, /* 72 */ + {"CRC-16/XMODEM", models + 18}, /* 73 */ + {"CRC-17/CAN-FD", models + 96}, /* 74 */ + {"CRC-21/CAN-FD", models + 80}, /* 75 */ + {"CRC-24", models + 82}, /* 76 */ + {"CRC-24/BLE", models + 3}, /* 77 */ + {"CRC-24/FLEXRAY-A", models + 58}, /* 78 */ + {"CRC-24/FLEXRAY-B", models + 57}, /* 79 */ + {"CRC-24/INTERLAKEN", models + 46}, /* 80 */ + {"CRC-24/LTE-A", models + 81}, /* 81 */ + {"CRC-24/LTE-B", models + 66}, /* 82 */ + {"CRC-24/OPENPGP", models + 82}, /* 83 */ + {"CRC-24/OS-9", models + 67}, /* 84 */ + {"CRC-3/GSM", models + 59}, /* 85 */ + {"CRC-3/ROHC", models + 60}, /* 86 */ + {"CRC-30/CDMA", models + 76}, /* 87 */ + {"CRC-31/PHILIPS", models + 15}, /* 88 */ + {"CRC-32", models + 8}, /* 89 */ + {"CRC-32/AAL5", models + 6}, /* 90 */ + {"CRC-32/ADCCP", models + 8}, /* 91 */ + {"CRC-32/AIXM", models + 79}, /* 92 */ + {"CRC-32/AUTOSAR", models + 104}, /* 93 */ + {"CRC-32/BASE91-C", models + 37}, /* 94 */ + {"CRC-32/BASE91-D", models + 95}, /* 95 */ + {"CRC-32/BZIP2", models + 6}, /* 96 */ + {"CRC-32/CASTAGNOLI", models + 37}, /* 97 */ + {"CRC-32/CKSUM", models + 4}, /* 98 */ + {"CRC-32/DECT-B", models + 6}, /* 99 */ + {"CRC-32/INTERLAKEN", models + 37}, /* 100 */ + {"CRC-32/ISCSI", models + 37}, /* 101 */ + {"CRC-32/ISO-HDLC", models + 8}, /* 102 */ + {"CRC-32/JAMCRC", models + 7}, /* 103 */ + {"CRC-32/MPEG-2", models + 5}, /* 104 */ + {"CRC-32/POSIX", models + 4}, /* 105 */ + {"CRC-32/V-42", models + 8}, /* 106 */ + {"CRC-32/XFER", models + 1}, /* 107 */ + {"CRC-32/XZ", models + 8}, /* 108 */ + {"CRC-32C", models + 37}, /* 109 */ + {"CRC-32D", models + 95}, /* 110 */ + {"CRC-32Q", models + 79}, /* 111 */ + {"CRC-4/G-704", models + 42}, /* 112 */ + {"CRC-4/INTERLAKEN", models + 43}, /* 113 */ + {"CRC-4/ITU", models + 42}, /* 114 */ + {"CRC-40/GSM", models + 2}, /* 115 */ + {"CRC-5/EPC", models + 53}, /* 116 */ + {"CRC-5/EPC-C1G2", models + 53}, /* 117 */ + {"CRC-5/G-704", models + 94}, /* 118 */ + {"CRC-5/ITU", models + 94}, /* 119 */ + {"CRC-5/USB", models + 39}, /* 120 */ + {"CRC-6/CDMA2000-A", models + 90}, /* 121 */ + {"CRC-6/CDMA2000-B", models + 30}, /* 122 */ + {"CRC-6/DARC", models + 62}, /* 123 */ + {"CRC-6/G-704", models + 16}, /* 124 */ + {"CRC-6/GSM", models + 97}, /* 125 */ + {"CRC-6/ITU", models + 16}, /* 126 */ + {"CRC-64", models + 50}, /* 127 */ + {"CRC-64/ECMA-182", models + 50}, /* 128 */ + {"CRC-64/GO-ECMA", models + 52}, /* 129 */ + {"CRC-64/GO-ISO", models + 0}, /* 130 */ + {"CRC-64/WE", models + 51}, /* 131 */ + {"CRC-64/XZ", models + 52}, /* 132 */ + {"CRC-7", models + 29}, /* 133 */ + {"CRC-7/MMC", models + 29}, /* 134 */ + {"CRC-7/ROHC", models + 91}, /* 135 */ + {"CRC-7/UMTS", models + 83}, /* 136 */ + {"CRC-8", models + 11}, /* 137 */ + {"CRC-8/AES", models + 35}, /* 138 */ + {"CRC-8/AUTOSAR", models + 41}, /* 139 */ + {"CRC-8/BLUETOOTH", models + 93}, /* 140 */ + {"CRC-8/CDMA2000", models + 89}, /* 141 */ + {"CRC-8/DARC", models + 47}, /* 142 */ + {"CRC-8/DVB-S2", models + 101}, /* 143 */ + {"CRC-8/EBU", models + 35}, /* 144 */ + {"CRC-8/GSM-A", models + 31}, /* 145 */ + {"CRC-8/GSM-B", models + 54}, /* 146 */ + {"CRC-8/I-432-1", models + 12}, /* 147 */ + {"CRC-8/I-CODE", models + 33}, /* 148 */ + {"CRC-8/ITU", models + 12}, /* 149 */ + {"CRC-8/LTE", models + 87}, /* 150 */ + {"CRC-8/MAXIM", models + 44}, /* 151 */ + {"CRC-8/MAXIM-DOW", models + 44}, /* 152 */ + {"CRC-8/MIFARE-MAD", models + 32}, /* 153 */ + {"CRC-8/NRSC-5", models + 45}, /* 154 */ + {"CRC-8/OPENSAFETY", models + 40}, /* 155 */ + {"CRC-8/ROHC", models + 13}, /* 156 */ + {"CRC-8/SAE-J1850", models + 34}, /* 157 */ + {"CRC-8/SMBUS", models + 11}, /* 158 */ + {"CRC-8/TECH-3250", models + 35}, /* 159 */ + {"CRC-8/WCDMA", models + 88}, /* 160 */ + {"CRC-82/DARC", models + 17}, /* 161 */ + {"CRC-A", models + 24}, /* 162 */ + {"CRC-B", models + 28}, /* 163 */ + {"CRC-CCITT", models + 20}, /* 164 */ + {"CRC-IBM", models + 69}, /* 165 */ + {"DOW-CRC", models + 44}, /* 166 */ + {"JAMCRC", models + 7}, /* 167 */ + {"KERMIT", models + 20}, /* 168 */ + {"MODBUS", models + 73}, /* 169 */ + {"PKZIP", models + 8}, /* 170 */ + {"R-CRC-16", models + 10}, /* 171 */ + {"X-25", models + 28}, /* 172 */ + {"X-CRC-12", models + 77}, /* 173 */ + {"X-CRC-16", models + 9}, /* 174 */ + {"XFER", models + 1}, /* 175 */ + {"XMODEM", models + 18}, /* 176 */ + {"ZMODEM", models + 18}, /* 177 */ + {NULL, NULL}, /* terminating entry */ }; # define NALIASES 178 diff --git a/client/scripting.c b/client/scripting.c index e9ebe1dea..a26db0c19 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -69,12 +69,12 @@ static int l_GetFromBigBuf(lua_State *L) { startindex = luaL_checknumber(L, 1); len = luaL_checknumber(L, 2); } - - if ( len == 0 ) { + + if (len == 0) { //signal error by returning Nil, errorstring lua_pushnil(L); lua_pushstring(L, "You need to supply number of bytes larger than zero"); - return 2; // two return values + return 2; // two return values } uint8_t *data = calloc(len, sizeof(uint8_t)); @@ -125,13 +125,13 @@ static int l_GetFromFlashMem(lua_State *L) { startindex = luaL_checknumber(L, 1); len = luaL_checknumber(L, 2); } - - if ( len == 0 ) { + + if (len == 0) { //signal error by returning Nil, errorstring lua_pushnil(L); lua_pushstring(L, "You need to supply number of bytes larger than zero"); - return 2; // two return values - } + return 2; // two return values + } uint8_t *data = calloc(len, sizeof(uint8_t)); if (!data) { diff --git a/client/util.c b/client/util.c index 386e56e1e..8be1aa896 100644 --- a/client/util.c +++ b/client/util.c @@ -256,12 +256,12 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea sprintf(tmp++, "."); else sprintf(tmp++, "%u", data[in_index]); - + // check if a line break is needed and we have room to print it in our array if ((breaks > 0) && !((in_index + 1) % breaks) && (out_index + 1 != rowlen)) { sprintf(tmp++, "%s", "\n"); } - + in_index++; } diff --git a/common/Makefile.hal b/common/Makefile.hal index e34095f2d..717d59110 100644 --- a/common/Makefile.hal +++ b/common/Makefile.hal @@ -5,6 +5,8 @@ define KNOWN_PLATFORMS +--------------------------------------------------------+ | PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | +--------------------------------------------------------+ +| PM3RDV4FPC | Proxmark3 rdv4+FPC (experimental) | ++--------------------------------------------------------+ | PM3EVO | Proxmark3 EVO with AT91SAM7S512 | +--------------------------------------------------------+ | PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | @@ -31,6 +33,10 @@ ifeq ($(PLATFORM),PM3RDV4) MCU = AT91SAM7S512 PLATFORM_DEFS = -DWITH_SMARTCARD -DWITH_FLASH PLTNAME = Proxmark3 rdv4 +else ifeq ($(PLATFORM),PM3RDV4FPC) + MCU = AT91SAM7S512 + PLATFORM_DEFS = -DWITH_SMARTCARD -DWITH_FLASH -DWITH_FPC_HOST + PLTNAME = Proxmark3 rdv4 else ifeq ($(PLATFORM),PM3EVO) MCU = AT91SAM7S512 PLTNAME = Proxmark3 EVO @@ -50,6 +56,11 @@ else $(error Invalid or empty PLATFORM: $(PLATFORM). Known platforms: $(KNOWN_PLATFORMS)) endif +# Add flags dependencies +ifneq (,$(findstring WITH_FPC_,$(PLATFORM_DEFS))) + PLATFORM_DEFS += -DWITH_FPC +endif + export PLATFORM export PLTNAME export MCU diff --git a/common/cmd.c b/common/cmd.c index 3b45c08ad..73c95bcd5 100644 --- a/common/cmd.c +++ b/common/cmd.c @@ -31,6 +31,17 @@ */ #include "cmd.h" +#ifdef WITH_FPC_HOST +// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART +bool reply_via_fpc = 0; + +extern void Dbprintf(const char *fmt, ...); +#define Dbprintf_usb(...) {\ + reply_via_fpc = 0;\ + Dbprintf(__VA_ARGS__);\ + reply_via_fpc = 1;} +#endif + uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) { UsbCommand txcmd; @@ -53,11 +64,16 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void uint32_t sendlen = 0; // Send frame and make sure all bytes are transmitted - sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand)); -#ifdef WITH_FPC -// usart_init(); -// usart_writebuffer( (uint8_t*)&txcmd, sizeof(UsbCommand) ); +#ifdef WITH_FPC_HOST + if (reply_via_fpc) { + sendlen = usart_writebuffer((uint8_t *)&txcmd, sizeof(UsbCommand)); + Dbprintf_usb("Sent %i bytes over usart", len); + } else { + sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand)); + } +#else + sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand)); #endif return sendlen; diff --git a/common/lfdemod.c b/common/lfdemod.c index 02b1e5efe..0d33091a6 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -489,21 +489,21 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo if (i == size) return -1; - + // clock, numoftimes, first idx uint16_t tmpclk[10][3] = { - {8, 0, 0}, - {16, 0, 0}, - {32, 0, 0}, - {40, 0, 0}, - {50, 0, 0}, - {64, 0, 0}, - {100, 0, 0}, + {8, 0, 0}, + {16, 0, 0}, + {32, 0, 0}, + {40, 0, 0}, + {50, 0, 0}, + {64, 0, 0}, + {100, 0, 0}, {128, 0, 0}, - {256, 0, 0}, + {256, 0, 0}, {384, 0, 0}, - }; - + }; + // loop through all samples (well, we don't want to go out-of-bounds) while (i < size - 512) { // measure from low to low @@ -517,14 +517,14 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo minClk = i - startwave; shortestWaveIdx = startwave; } - + int foo = getClosestClock(minClk); - if (foo > 0 ) { + if (foo > 0) { for (uint8_t i = 0; i < 10; i++) { - if ( tmpclk[i][0] == foo ) { + if (tmpclk[i][0] == foo) { tmpclk[i][1]++; - - if ( tmpclk[i][2] == 0) { + + if (tmpclk[i][2] == 0) { tmpclk[i][2] = shortestWaveIdx; } break; @@ -538,17 +538,17 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo for (uint8_t i = 0; i < 10; i++) { if (g_debugMode == 2) { prnt("DEBUG, ASK, clocks %u | hits %u | idx %u" - , tmpclk[i][0] - , tmpclk[i][1] - , tmpclk[i][2] - ); + , tmpclk[i][0] + , tmpclk[i][1] + , tmpclk[i][2] + ); } - if ( max < tmpclk[i][1] ) { + if (max < tmpclk[i][1]) { *clock = tmpclk[i][0]; shortestWaveIdx = tmpclk[i][2]; max = tmpclk[i][1]; } - } + } if (*clock == 0) return -1; @@ -1517,10 +1517,10 @@ int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, if (g_debugMode == 2) prnt("DEBUG (askdemod_ext) just noise detected - aborting"); return -2; } - + int start = DetectASKClock(bits, *size, clk, maxErr); if (*clk == 0 || start < 0) return -3; - + if (*invert != 1) *invert = 0; // amplify signal data. diff --git a/common/usart.c b/common/usart.c index 869179091..8680d500a 100644 --- a/common/usart.c +++ b/common/usart.c @@ -10,6 +10,7 @@ //----------------------------------------------------------------------------- #include "usart.h" #include "string.h" +#include "apps.h" // for Dbprintf #define AT91_BAUD_RATE 115200 @@ -39,61 +40,63 @@ void usart_close(void) { } */ +static uint8_t us_inbuf[sizeof(UsbCommand)]; static uint8_t us_outbuf[sizeof(UsbCommand)]; -/// Reads data from an USART peripheral -/// \param data Pointer to the buffer where the received data will be stored. -/// \param len Size of the data buffer (in bytes). -inline int16_t usart_readbuffer(uint8_t *data, size_t len) { - - // Check if the first PDC bank is free - if (!(pUS1->US_RCR)) { - pUS1->US_RPR = (uint32_t)data; - pUS1->US_RCR = len; - - pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTDIS; - return 2; - } - // Check if the second PDC bank is free - else if (!(pUS1->US_RNCR)) { - pUS1->US_RNPR = (uint32_t)data; - pUS1->US_RNCR = len; - - pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTDIS; - return 1; +// transfer from client to device +inline int16_t usart_readbuffer(uint8_t *data) { + uint32_t rcr = pUS1->US_RCR; + if (rcr < sizeof(us_inbuf)) { + pUS1->US_PTCR = AT91C_PDC_RXTDIS; + memcpy(data, us_inbuf, sizeof(us_inbuf) - rcr); + // Reset DMA buffer + pUS1->US_RPR = (uint32_t)us_inbuf; + pUS1->US_RCR = sizeof(us_inbuf); + pUS1->US_PTCR = AT91C_PDC_RXTEN; + return sizeof(us_inbuf) - rcr; } else { return 0; } } +inline bool usart_dataavailable(void) { + return pUS1->US_RCR < sizeof(us_inbuf); +} + +inline int16_t usart_readcommand(uint8_t *data) { + if (pUS1->US_RCR == 0) + return usart_readbuffer(data); + else + return 0; +} + +inline bool usart_commandavailable(void) { + return pUS1->US_RCR == 0; +} // transfer from device to client inline int16_t usart_writebuffer(uint8_t *data, size_t len) { - // Check if the first PDC bank is free - if (!(pUS1->US_TCR)) { + + if (pUS1->US_CSR & AT91C_US_ENDTX) { memcpy(us_outbuf, data, len); pUS1->US_TPR = (uint32_t)us_outbuf; - pUS1->US_TCR = sizeof(us_outbuf); - - pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTDIS; - return 2; - } - // Check if the second PDC bank is free - else if (!(pUS1->US_TNCR)) { - memcpy(us_outbuf, data, len); - pUS1->US_TNPR = (uint32_t)us_outbuf; - pUS1->US_TNCR = sizeof(us_outbuf); - - pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTDIS; - return 1; + pUS1->US_TCR = len; + pUS1->US_PTCR = AT91C_PDC_TXTEN; + while (!(pUS1->US_CSR & AT91C_US_ENDTX)) {}; + pUS1->US_PTCR = AT91C_PDC_TXTDIS; + return len; } else { return 0; } } + void usart_init(void) { + // For a nice detailed sample, interrupt driven but still relevant. + // See https://www.sparkfun.com/datasheets/DevTools/SAM7/at91sam7%20serial%20communications.pdf + // disable & reset receiver / transmitter for configuration pUS1->US_CR = (AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS); @@ -113,6 +116,7 @@ void usart_init(void) { // set mode pUS1->US_MR = AT91C_US_USMODE_NORMAL | // normal mode AT91C_US_CLKS_CLOCK | // MCK (48MHz) + AT91C_US_OVER | // oversampling AT91C_US_CHRL_8_BITS | // 8 bits AT91C_US_PAR_NONE | // parity: none AT91C_US_NBSTOP_1_BIT | // 1 stop bit @@ -121,16 +125,9 @@ void usart_init(void) { // all interrupts disabled pUS1->US_IDR = 0xFFFF; - // iceman, setting 115200 doesn't work. Only speed I got to work is 9600. - // something fishy with the AT91SAM7S512 USART.. Or I missed something - // For a nice detailed sample, interrupt driven but still relevant. - // See https://www.sparkfun.com/datasheets/DevTools/SAM7/at91sam7%20serial%20communications.pdf - - // set baudrate to 115200 - // 115200 * 16 == 1843200 - // - //pUS1->US_BRGR = (48UL*1000*1000) / (9600*16); - pUS1->US_BRGR = 48054841 / (9600 << 4); + pUS1->US_BRGR = 48054841 / (115200 << 3); + // Need speed? + //pUS1->US_BRGR = 48054841 / (460800 << 3); // Write the Timeguard Register pUS1->US_TTGR = 0; @@ -138,6 +135,17 @@ void usart_init(void) { pUS1->US_FIDI = 0; pUS1->US_IF = 0; + // Disable double buffers for now + pUS1->US_TNPR = (uint32_t)0; + pUS1->US_TNCR = 0; + pUS1->US_RNPR = (uint32_t)0; + pUS1->US_RNCR = 0; + + // re-enable receiver / transmitter pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN); + // ready to receive + pUS1->US_RPR = (uint32_t)us_inbuf; + pUS1->US_RCR = sizeof(us_inbuf); + pUS1->US_PTCR = AT91C_PDC_RXTEN; } diff --git a/common/usart.h b/common/usart.h index 7e8d3eb7b..f98424841 100644 --- a/common/usart.h +++ b/common/usart.h @@ -7,6 +7,9 @@ void usart_init(void); void usart_close(void); -int16_t usart_readbuffer(uint8_t *data, size_t len); +int16_t usart_readbuffer(uint8_t *data); int16_t usart_writebuffer(uint8_t *data, size_t len); +bool usart_dataavailable(void); +int16_t usart_readcommand(uint8_t *data); +bool usart_commandavailable(void); #endif diff --git a/include/usb_cmd.h b/include/usb_cmd.h index f164b0f8d..57f2c46fd 100644 --- a/include/usb_cmd.h +++ b/include/usb_cmd.h @@ -34,6 +34,12 @@ typedef struct { uint32_t asDwords[USB_CMD_DATA_SIZE / 4]; } d; } PACKED UsbCommand; + +#ifdef WITH_FPC_HOST +// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART +extern bool reply_via_fpc; +#endif + // A struct used to send sample-configs over USB typedef struct { uint8_t decimation; diff --git a/tools/mfkey/Makefile b/tools/mfkey/Makefile index 149759cc9..ed245d02d 100644 --- a/tools/mfkey/Makefile +++ b/tools/mfkey/Makefile @@ -5,8 +5,7 @@ CFLAGS += -std=c99 -D_ISOC99_SOURCE -I../../include -I../../common -I../../clien LDFLAGS += OBJS = crypto1.o crapto1.o parity.o util_posix.o bucketsort.o -EXES = mfkey32 mfkey32v2 mfkey64 -WINEXES = $(patsubst %, %.exe, $(EXES)) +EXES = mfkey32 mfkey32v2 mfkey64 all: $(OBJS) $(EXES) @@ -17,4 +16,4 @@ all: $(OBJS) $(EXES) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $< clean: - rm -f $(OBJS) $(EXES) $(WINEXES) + rm -f $(OBJS) $(EXES) diff --git a/tools/mfkey/mfkey32.c b/tools/mfkey/mfkey32.c index 615373c83..d88c3c74d 100644 --- a/tools/mfkey/mfkey32.c +++ b/tools/mfkey/mfkey32.c @@ -4,7 +4,7 @@ #include #include #include "crapto1/crapto1.h" -#include "util_posix.h" +#include "util_posix.h" int main(int argc, char *argv[]) { struct Crypto1State *s, *t; diff --git a/tools/mfkey/mfkey32v2.c b/tools/mfkey/mfkey32v2.c index 86e528783..f5256fb1c 100644 --- a/tools/mfkey/mfkey32v2.c +++ b/tools/mfkey/mfkey32v2.c @@ -4,7 +4,7 @@ #include #include #include "crapto1/crapto1.h" -#include "util_posix.h" +#include "util_posix.h" int main(int argc, char *argv[]) { struct Crypto1State *s, *t; diff --git a/tools/nonce2key/Makefile b/tools/nonce2key/Makefile index 99f9a3598..44657419a 100644 --- a/tools/nonce2key/Makefile +++ b/tools/nonce2key/Makefile @@ -1,20 +1,23 @@ CC = gcc -LD = gcc -CFLAGS = -std=c99 -Wall -O3 -c -LDFLAGS = +CFLAGS = -std=c99 -Wall -O3 -I. +LDFLAGS = -std=c99 -Wall +SRC := $(wildcard *.c) +OBJ := $(SRC:.c=.o) +DEP := $(SRC:.c=.d) +PROG := nonce2key -OBJS = crypto1.o crapto1.o -HEADERS = crapto1.h -EXES = nonce2key -WINEXES = $(patsubst %, %.exe, $(EXES)) +all: $(PROG) -all: $(OBJS) $(EXES) - -%.o : %.c - $(CC) $(CFLAGS) -c -o $@ $< - -% : %.c - $(LD) $(LDFLAGS) -o $@ $(OBJS) $< +$(PROG): $(OBJ) + $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ clean: - rm -f $(OBJS) $(EXES) $(WINEXES) + @$(RM) $(DEP) $(OBJ) $(PROG) + +ifneq ($(filter clean,$(MAKECMDGOALS)),clean) +-include $(DEP) +endif + +%.d: %.c + $(info GEN $@) + @$(CC) -MM $(CFLAGS) $< | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@ diff --git a/uart/uart.h b/uart/uart.h index 582f394e7..714f646b9 100644 --- a/uart/uart.h +++ b/uart/uart.h @@ -71,7 +71,7 @@ typedef void *serial_port; * * On errors, this method returns INVALID_SERIAL_PORT or CLAIMED_SERIAL_PORT. */ -serial_port uart_open(const char *pcPortName); +serial_port uart_open(const char *pcPortName, uint32_t speed); /* Closes the given port. */ diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 95e9ce070..92af6774a 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -73,7 +73,7 @@ struct timeval timeout = { .tv_usec = 30000 // 30 000 micro seconds }; -serial_port uart_open(const char *pcPortName) { +serial_port uart_open(const char *pcPortName, uint32_t speed) { serial_port_unix *sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t)); if (sp == 0) return INVALID_SERIAL_PORT; @@ -194,23 +194,19 @@ serial_port uart_open(const char *pcPortName) { // Flush all lingering data that may exist tcflush(sp->fd, TCIOFLUSH); -#ifdef WITH_FPC - if (uart_set_speed(sp, 115200)) { - printf("[=] UART Setting serial baudrate 115200 [FPC enabled]\n"); - } else { - uart_set_speed(sp, 9600); - printf("[=] UART Setting serial baudrate 9600 [FPC enabled]\n"); + if (!uart_set_speed(sp, speed)) { + // trying some fallbacks automatically + speed = 115200; + if (!uart_set_speed(sp, speed)) { + speed = 9600; + if (!uart_set_speed(sp, speed)) { + uart_close(sp); + printf("[!] UART error while setting baudrate\n"); + return INVALID_SERIAL_PORT; + } + } } -#else - // set speed, works for UBUNTU 14.04 - bool success = uart_set_speed(sp, 460800); - if (success) { - printf("[=] UART Setting serial baudrate 460800\n"); - } else { - uart_set_speed(sp, 115200); - printf("[=] UART Setting serial baudrate 115200\n"); - } -#endif + printf("[=] UART Setting serial baudrate %i\n", speed); return sp; } diff --git a/uart/uart_win32.c b/uart/uart_win32.c index 6107a564e..2ed5c9bcf 100644 --- a/uart/uart_win32.c +++ b/uart/uart_win32.c @@ -48,7 +48,7 @@ typedef struct { COMMTIMEOUTS ct; // Serial port time-out configuration } serial_port_windows; -serial_port uart_open(const char *pcPortName) { +serial_port uart_open(const char *pcPortName, uint32_t speed) { char acPortName[255]; serial_port_windows *sp = calloc(sizeof(serial_port_windows), sizeof(uint8_t)); @@ -87,6 +87,7 @@ serial_port uart_open(const char *pcPortName) { // all zero's configure: no timeout for read/write used. // took settings from libnfc/buses/uart.c #ifdef WITH_FPC + // Still relevant? sp->ct.ReadIntervalTimeout = 1000; sp->ct.ReadTotalTimeoutMultiplier = 0; sp->ct.ReadTotalTimeoutConstant = 1500; @@ -108,22 +109,19 @@ serial_port uart_open(const char *pcPortName) { PurgeComm(sp->hPort, PURGE_RXABORT | PURGE_RXCLEAR); -#ifdef WITH_FPC - if (uart_set_speed(sp, 115200)) { - printf("[=] UART Setting serial baudrate 115200 [FPC enabled]\n"); - } else { - uart_set_speed(sp, 9600); - printf("[=] UART Setting serial baudrate 9600 [FPC enabled]\n"); + if (!uart_set_speed(sp, speed)) { + // trying some fallbacks automatically + speed = 115200; + if (!uart_set_speed(sp, speed)) { + speed = 9600; + if (!uart_set_speed(sp, speed)) { + uart_close(sp); + printf("[!] UART error while setting baudrate\n"); + return INVALID_SERIAL_PORT; + } + } } -#else - bool success = uart_set_speed(sp, 460800); - if (success) { - printf("[=] UART Setting serial baudrate 460800\n"); - } else { - uart_set_speed(sp, 115200); - printf("[=] UART Setting serial baudrate 115200\n"); - } -#endif + printf("[=] UART Setting serial baudrate %i\n", speed); return sp; }