Merge remote-tracking branch 'upstream/master' into hf_mf_sim

This commit is contained in:
vratiskol 2019-04-03 01:48:46 +02:00
commit 1c77185fb9
50 changed files with 1182 additions and 863 deletions

9
.gitattributes vendored
View file

@ -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
# 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

1
.gitignore vendored
View file

@ -20,6 +20,7 @@
*.exe
*.dsym
version.c
*.json
!client/hardnested/*.bin
!client/hardnested/tables/*.z

View file

@ -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)

View file

@ -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

View file

@ -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) {
@ -1106,28 +1105,31 @@ 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"
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
// Check is there is FPC package available
/*
usart_init();
if (usart_readbuffer(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));
*/
}
#endif
// Press button for one second to enter a possible standalone mode

View file

@ -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) {

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -19,15 +19,15 @@ void Set_t55xx_Config(t55xx_conf_block_t conf) {
}
int usage_t55xx_config() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");
PrintAndLogEx(NORMAL, "Usage: lf t55xx config [d <demodulation>] [i [0/1]] [o <offset>] [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 <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> - 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 <data> [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 <data> - 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;
}
@ -300,8 +306,13 @@ int CmdT55xxSetConfig(const char *Cmd) {
}
break;
case 'i':
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':
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++;
cmdp += 1;
}
break;
case 's':
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++;
cmdp += 1;
}
break;
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
@ -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;
// too little space to start with
if (DemodBufferLen < 32) return 1;
if (DemodBufferLen < 32 + config.offset) 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");
block0 = PackBits(config.offset, 32, DemodBuffer);
}
PrintAndLogEx(NORMAL, "");
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));
PrintAndLogEx(NORMAL, " PSK clock frequency : %d", pskcf);
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) ? _YELLOW_("Yes - Warning") : "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 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, " 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");
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;
}
@ -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;
@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;
}

View file

@ -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

View file

@ -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;

View file

@ -6,7 +6,6 @@ LDFLAGS +=
OBJS = crypto1.o crapto1.o parity.o util_posix.o bucketsort.o
EXES = mfkey32 mfkey32v2 mfkey64
WINEXES = $(patsubst %, %.exe, $(EXES))
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)

View file

@ -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' > $@

View file

@ -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.
*/

View file

@ -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;
}

View file

@ -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;
}