This commit is contained in:
Philippe Teuwen 2019-05-08 01:35:51 +02:00
commit 68e5b3c355
21 changed files with 106 additions and 106 deletions

View file

@ -1189,7 +1189,7 @@ static void PacketReceived(PacketCommandNG *packet) {
LED_B_ON();
uint8_t *dest = BigBuf_malloc(USART_FIFOLEN);
uint16_t available = usart_rxdata_available();
if (available > 0) {
uint16_t len = usart_read_ng(dest, available);
reply_ng(CMD_USART_RX, PM3_SUCCESS, dest, len);
@ -1212,7 +1212,7 @@ static void PacketReceived(PacketCommandNG *packet) {
WaitMS(payload->waittime);
uint8_t *dest = BigBuf_malloc(USART_FIFOLEN);
available = usart_rxdata_available();
// Dbprintf("avail (%u)", available);
if (available > 0) {
@ -1635,8 +1635,8 @@ void __attribute__((noreturn)) AppMain(void) {
if (ret == PM3_SUCCESS) {
PacketReceived(&rx);
} else if (ret != PM3_ENODATA) {
Dbprintf("Error in frame reception: %d %s", ret, (ret == PM3_EIO)?"PM3_EIO":"");
Dbprintf("Error in frame reception: %d %s", ret, (ret == PM3_EIO) ? "PM3_EIO" : "");
// TODO if error, shall we resync ?
}

View file

@ -151,7 +151,7 @@ static int CmdFlashmemSpiBaudrate(const char *Cmd) {
if (strlen(Cmd) < 1 || ctmp == 'h') {
return usage_flashmem_spibaud();
}
uint32_t baudrate = param_get32ex(Cmd, 0, 0, 10);
baudrate = baudrate * 1000000;
if (baudrate != FLASH_BAUD && baudrate != FLASH_MINBAUD) {
@ -279,7 +279,7 @@ static int CmdFlashMemLoad(const char *Cmd) {
// fast push mode
conn.block_after_ACK = true;
while (bytes_remaining > 0) {
uint32_t bytes_in_packet = MIN(FLASH_MEM_BLOCK_SIZE, bytes_remaining);
@ -300,7 +300,7 @@ static int CmdFlashMemLoad(const char *Cmd) {
uint8_t isok = resp.oldarg[0] & 0xFF;
if (!isok) {
conn.block_after_ACK = false;
conn.block_after_ACK = false;
PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent);
return PM3_EFLASH;
}

View file

@ -429,7 +429,7 @@ static int CmdSetMux(const char *Cmd) {
}
str_lower((char *)Cmd);
uint8_t arg = 0;
if (strcmp(Cmd, "lopkd") == 0) arg = 0;
else if (strcmp(Cmd, "loraw") == 0) arg = 1;
@ -438,7 +438,7 @@ static int CmdSetMux(const char *Cmd) {
else {
usage_hw_setmux();
return PM3_EINVARG;
}
}
clearCommandBuffer();
SendCommandMIX(CMD_SET_ADC_MUX, arg, 0, 0, NULL, 0);
return PM3_SUCCESS;
@ -483,9 +483,9 @@ static int CmdPing(const char *Cmd) {
bool error = false;
if (len) {
error = memcmp(data, resp.data.asBytes, len) != 0;
PrintAndLogEx((error)? ERR:SUCCESS, "Ping response " _GREEN_("received") "and content is %s", error ? _RED_("NOT ok") : _GREEN_("ok"));
PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received") "and content is %s", error ? _RED_("NOT ok") : _GREEN_("ok"));
} else {
PrintAndLogEx((error)? ERR:SUCCESS, "Ping response " _GREEN_("received"));
PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received"));
}
} else
PrintAndLogEx(WARNING, "Ping response " _RED_("timeout"));
@ -498,11 +498,11 @@ static int CmdConnect(const char *Cmd) {
return usage_hw_connect();
char *port = NULL;
// default back to previous used serial port
if (strlen(Cmd) == 0 ) {
if (strlen(Cmd) == 0) {
int len = strlen((char *)conn.serial_port_name);
if ( len == 0 ) {
if (len == 0) {
return usage_hw_connect();
}
port = (char *)conn.serial_port_name;
@ -510,10 +510,10 @@ static int CmdConnect(const char *Cmd) {
port = (char *)Cmd;
}
if ( port == NULL )
if (port == NULL)
return usage_hw_connect();
if ( session.pm3_present ) {
if (session.pm3_present) {
CloseProxmark();
}
@ -558,12 +558,12 @@ int CmdHW(const char *Cmd) {
void pm3_version(bool verbose) {
if (!verbose)
return;
PacketResponseNG resp;
clearCommandBuffer();
SendCommandNG(CMD_VERSION, NULL, 0);
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n");
PrintAndLogEx(NORMAL, "\n [ CLIENT ]");
@ -573,10 +573,10 @@ void pm3_version(bool verbose) {
PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent"));
PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 Extras ]");
PrintAndLogEx(NORMAL, " FPC USART for BT add-on support: %s", IfPm3FpcUsartHost() ? _GREEN_("present") : _YELLOW_("absent"));
if (IfPm3FpcUsartDevFromUsb())
PrintAndLogEx(NORMAL, " FPC USART for developer support: %s", _GREEN_("present"));
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, (char *)resp.data.asBytes);
lookupChipID(resp.oldarg[0], resp.oldarg[1]);

View file

@ -161,7 +161,7 @@ static int CmdUsartBtPin(const char *Cmd) {
case 'h':
return usage_usart_bt_pin();
case 'd':
if (param_getstr(Cmd, cmdp + 1, pin, sizeof(pin)) != sizeof(pin)-1) {
if (param_getstr(Cmd, cmdp + 1, pin, sizeof(pin)) != sizeof(pin) - 1) {
PrintAndLogEx(FAILED, "PIN has wrong length, must be 4 digits");
errors = true;
break;
@ -201,7 +201,7 @@ static int CmdUsartBtPin(const char *Cmd) {
return ret;
}
// PrintAndLogEx(NORMAL, "RX (%3u):%.*s", len, len, data);
if (strcmp((char*)data, "OKsetPIN") == 0) {
if (strcmp((char *)data, "OKsetPIN") == 0) {
PrintAndLogEx(NORMAL, "PIN changed " _GREEN_("successfully"));
} else {
PrintAndLogEx(WARNING, "Unexpected answer: %.*s", len, data);

View file

@ -302,7 +302,7 @@ static void PacketResponseReceived(PacketResponseNG *packet) {
// The communications thread.
// signals to main thread when a response is ready to process.
//
//
static void
#ifdef __has_attribute
#if __has_attribute(force_align_arg_pointer)
@ -329,14 +329,14 @@ __attribute__((force_align_arg_pointer))
// Signal to main thread that communications seems off.
// main thread will kill and restart this thread.
if ( commfailed ) {
if (commfailed) {
PrintAndLogEx(WARNING, "Communicating with Proxmark3 device " _RED_("failed"));
__atomic_test_and_set(&comm_thread_dead, __ATOMIC_SEQ_CST);
break;
}
pthread_mutex_lock(&spMutex);
res = uart_receive(sp, (uint8_t *)&rx_raw.pre, sizeof(PacketResponseNGPreamble), &rxlen);
if ((res == PM3_SUCCESS) && (rxlen == sizeof(PacketResponseNGPreamble))) {
rx.magic = rx_raw.pre.magic;
@ -350,9 +350,9 @@ __attribute__((force_align_arg_pointer))
error = true;
}
if ((!error) && (length > 0)) { // Get the variable length payload
res = uart_receive(sp, (uint8_t *)&rx_raw.data, length, &rxlen);
if ( (res != PM3_SUCCESS) || (rxlen != length)) {
if ((res != PM3_SUCCESS) || (rxlen != length)) {
PrintAndLogEx(WARNING, "Received packet frame error variable part too short? %d/%d", rxlen, length);
error = true;
} else {
@ -415,7 +415,7 @@ __attribute__((force_align_arg_pointer))
} else { // Old style reply
PacketResponseOLD rx_old;
memcpy(&rx_old, &rx_raw.pre, sizeof(PacketResponseNGPreamble));
res = uart_receive(sp, ((uint8_t *)&rx_old) + sizeof(PacketResponseNGPreamble), sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble), &rxlen);
if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble))) {
PrintAndLogEx(WARNING, "Received packet OLD frame payload error too short? %d/%d", rxlen, sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble));
@ -495,9 +495,9 @@ __attribute__((force_align_arg_pointer))
pthread_mutex_unlock(&spMutex);
txBuffer_pending = false;
// main thread doesn't know send failed...
// tell main thread that txBuffer is empty
pthread_cond_signal(&txBufferSig);
}
@ -512,7 +512,7 @@ __attribute__((force_align_arg_pointer))
#if defined(__MACH__) && defined(__APPLE__)
enableAppNap();
#endif
pthread_exit(NULL);
return NULL;
}
@ -551,8 +551,8 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
return false;
} else {
// start the communication thread
if ( portname != (char*)conn.serial_port_name) {
uint16_t len = MIN( strlen(portname), FILE_PATH_SIZE - 1);
if (portname != (char *)conn.serial_port_name) {
uint16_t len = MIN(strlen(portname), FILE_PATH_SIZE - 1);
memset(conn.serial_port_name, 0, FILE_PATH_SIZE);
memcpy(conn.serial_port_name, portname, len);
}
@ -582,20 +582,20 @@ int TestProxmark(void) {
uint8_t data[len];
for (uint16_t i = 0; i < len; i++)
data[i] = i & 0xFF;
SendCommandNG(CMD_PING, data, len);
uint32_t timeout = 1000;
#ifdef USART_SLOW_LINK
timeout = 10000;
// 10s timeout for slow FPC, e.g. over BT
// as this is the very first command sent to the pm3
// that initiates the BT connection
// that initiates the BT connection
#endif
if (WaitForResponseTimeoutW(CMD_PING, &resp, timeout, false)) {
bool error = false;
if (len)
error = memcmp(data, resp.data.asBytes, len) != 0;
@ -652,7 +652,7 @@ void CloseProxmark(void) {
// Clean up our state
sp = NULL;
memset(&communication_thread, 0, sizeof(pthread_t));
session.pm3_present = false;
}

View file

@ -45,7 +45,7 @@ local function parse1443b(data)
local count, uid, uidlen, atqb, chipid, cid = bin.unpack('H10CH7CC',data)
uid = uid:sub(1, 2 * uidlen)
return {
return {
uid = uid,
uidlen = uidlen,
atqb = atqb,
@ -73,7 +73,7 @@ local function read14443b(disconnect)
cmd = cmds.CMD_ISO_14443B_COMMAND,
arg1 = flags
}
local result, err = command:sendMIX()
if result then
local count,cmd,arg0,arg1,arg2 = bin.unpack('LLLL',result)

View file

@ -120,7 +120,7 @@ local function read15693(slow, dont_readresponse)
else
err = 'No response from card'
end
if err then
print(err)
return nil, err

View file

@ -54,10 +54,10 @@ static void showBanner(void) {
int check_comm(void) {
// If communications thread goes down. Device disconnected then this should hook up PM3 again.
if ( IsCommunicationThreadDead() && session.pm3_present) {
if (IsCommunicationThreadDead() && session.pm3_present) {
rl_set_prompt("[offline] "PROXPROMPT);
rl_forced_update_display ();
CloseProxmark();
rl_forced_update_display();
CloseProxmark();
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") "mode. Use \"hw connect\" to reconnect\n");
}
return 0;
@ -159,11 +159,11 @@ main_loop(char *script_cmds_file, char *script_cmd) {
} else {
rl_event_hook = check_comm;
if (session.pm3_present )
if (session.pm3_present)
cmd = readline(PROXPROMPT);
else
cmd = readline("[offline] "PROXPROMPT);
fflush(NULL);
}
}
@ -188,9 +188,9 @@ main_loop(char *script_cmds_file, char *script_cmd) {
if (cmd[0] != '\0') {
if (printprompt)
PrintAndLogEx(NORMAL, PROXPROMPT"%s", cmd);
int ret = CommandReceived(cmd);
HIST_ENTRY *entry = history_get(history_length);
if ((!entry) || (strcmp(entry->line, cmd) != 0))
add_history(cmd);

View file

@ -11,17 +11,17 @@ This is a script to allow raw 1444a commands to be sent and received.
example = [[
# 1. Connect and don't disconnect
script run 14araw -p
# 2. Send mf auth, read response (nonce)
script run 14araw -o -x 6000F57b -p
# 3. disconnect
script run 14araw -o
# All three steps in one go:
script run 14araw -x 6000F57b
]]
usage = [[
usage = [[
script run 14araw -x 6000F57b
Arguments:
@ -124,7 +124,7 @@ function main(args)
-- The actual raw payload, if any
if payload then
res, err = sendRaw(payload,{ignore_response = ignore_response, topaz_mode = topaz_mode, append_crc = append_crc})
if err then
if err then
lib14a.disconnect()
return oops(err)
end

View file

@ -118,10 +118,10 @@ local bxor = bit32.bxor
-- we need always 2 digits
local function prepend_zero(s)
if (string.len(s) == 1) then
if (string.len(s) == 1) then
return '0' .. s
else
if (string.len(s) == 0) then
if (string.len(s) == 0) then
return '00'
else
return s
@ -360,7 +360,7 @@ function displaySegments(bytes)
pld = pld..bytes[(start+4+1+Seg[5]+Seg[6]+i)-1]..' '
end
print(pld)
if (KGH) then
if (KGH) then
print("'Kaba Group Header' detected")
end
start = start+Seg[4]

View file

@ -57,7 +57,7 @@ local function help()
print(desc)
print("Example usage")
print(example)
print(usage)
print(usage)
end
--
-- Exit message

View file

@ -64,7 +64,7 @@ local function help()
print(desc)
print("Example usage")
print(example)
print(usage)
print(usage)
end
--
-- Exit message

View file

@ -118,7 +118,7 @@ local function calypso_send_cmd_raw(data, ignoreresponse )
arg1 = flags,
arg2 = #data/2, -- LEN of data, half the length of the ASCII-string hex string
data = data} -- data bytes (commands etc)
result, err = command:sendMIX(ignoreresponse)
if result then
local r = calypso_parse(result)
@ -212,7 +212,7 @@ function main(args)
end
lib14b.connect()
-- Select 14b tag.
card, err = lib14b.waitFor14443b()
if not card then return oops(err) end

View file

@ -16,13 +16,13 @@ The dump is decrypted. If a raw dump is wanted, use the -r parameter
]]
example = [[
script run didump
-- selftest
script run didump -t
-- Generate raw dump, into json.
script run didump -r
-- load file
script run didump -i dumpdata.json
]]
@ -37,7 +37,7 @@ Arguments:
e encrypt data
v validate data
i dumpdata.json load json dump file
end
end
]]
-- Some shortcuts
@ -589,7 +589,7 @@ function main(args)
-- GET TAG UID
tag, err = lib14a.read(false, true)
if err then
if err then
lib14a.disconnect()
return oops(err)
end

View file

@ -58,7 +58,7 @@ local function help()
print(desc)
print('Example usage')
print(example)
print(usage)
print(usage)
end
---
-- Exit message

View file

@ -311,14 +311,14 @@ function main(args)
-- Initialize the card using the already-present read14a library
-- Perform RATS and PPS (Protocol and Parameter Selection) check to finish the ISO 14443-4 protocol.
info,err = lib14a.read(true, false)
if not info then
if not info then
lib14a.disconnect()
return oops(err)
end
--
response = sendRaw("D01100", true, true)
if not response then
if not response then
lib14a.disconnect()
return oops("No response from PPS check")
end

View file

@ -121,7 +121,7 @@ function main(args)
-- First of all, connect
info, err = lib14a.read(true, true)
if err then
if err then
lib14a.disconnect()
return oops(err)
end
@ -137,7 +137,7 @@ function main(args)
for block = 00, endblock do
local cmd = string.format('10%02x00', block)
res, err = sendRaw(cmd , {ignore_response = ignore_response})
if err then
if err then
lib14a.disconnect()
return oops(err)
end

View file

@ -146,34 +146,34 @@ int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *d
memcpy(cmddata, arg, sizeof(arg));
if (len && data)
memcpy(cmddata + sizeof(arg), data, len);
return reply_ng_internal(cmd, status, cmddata, len + sizeof(arg), false);
}
static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *data, size_t len), bool fpc) {
PacketCommandNGRaw rx_raw;
size_t bytes = read_ng((uint8_t *)&rx_raw.pre, sizeof(PacketCommandNGPreamble));
if (bytes == 0)
return PM3_ENODATA;
if (bytes != sizeof(PacketCommandNGPreamble))
return PM3_EIO;
rx->magic = rx_raw.pre.magic;
rx->ng = rx_raw.pre.ng;
uint16_t length = rx_raw.pre.length;
rx->cmd = rx_raw.pre.cmd;
if (rx->magic == COMMANDNG_PREAMBLE_MAGIC) { // New style NG command
if (length > PM3_CMD_DATA_SIZE)
return PM3_EOVFLOW;
// Get the core and variable length payload
bytes = read_ng((uint8_t *)&rx_raw.data, length);
if (bytes != length)
return PM3_EIO;
if (rx->ng) {
memcpy(rx->data.asBytes, rx_raw.data, length);
rx->length = length;
@ -181,7 +181,7 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
uint64_t arg[3];
if (length < sizeof(arg))
return PM3_EIO;
memcpy(arg, rx_raw.data, sizeof(arg));
rx->oldarg[0] = arg[0];
rx->oldarg[1] = arg[1];
@ -193,7 +193,7 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
bytes = read_ng((uint8_t *)&rx_raw.foopost, sizeof(PacketCommandNGPostamble));
if (bytes != sizeof(PacketCommandNGPostamble))
return PM3_EIO;
// Check CRC, accept MAGIC as placeholder
rx->crc = rx_raw.foopost.crc;
if (rx->crc != COMMANDNG_POSTAMBLE_MAGIC) {
@ -209,7 +209,7 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
bytes = read_ng(((uint8_t *)&rx_old) + sizeof(PacketCommandNGPreamble), sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble));
if (bytes != sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble))
return PM3_EIO;
reply_via_fpc = fpc;
rx->ng = false;
rx->magic = 0;

View file

@ -139,30 +139,30 @@ typedef struct {
typedef struct {
uint32_t baudrate;
bool via_fpc :1;
bool via_fpc : 1;
// rdv4
bool compiled_with_flash :1;
bool compiled_with_smartcard :1;
bool compiled_with_fpc_usart :1;
bool compiled_with_fpc_usart_dev :1;
bool compiled_with_fpc_usart_host :1;
bool compiled_with_flash : 1;
bool compiled_with_smartcard : 1;
bool compiled_with_fpc_usart : 1;
bool compiled_with_fpc_usart_dev : 1;
bool compiled_with_fpc_usart_host : 1;
// lf
bool compiled_with_lf :1;
bool compiled_with_hitag :1;
bool compiled_with_lf : 1;
bool compiled_with_hitag : 1;
// hf
bool compiled_with_hfsniff :1;
bool compiled_with_iso14443a :1;
bool compiled_with_iso14443b :1;
bool compiled_with_iso15693 :1;
bool compiled_with_felica :1;
bool compiled_with_legicrf :1;
bool compiled_with_iclass :1;
bool compiled_with_hfsniff : 1;
bool compiled_with_iso14443a : 1;
bool compiled_with_iso14443b : 1;
bool compiled_with_iso15693 : 1;
bool compiled_with_felica : 1;
bool compiled_with_legicrf : 1;
bool compiled_with_iclass : 1;
// misc
bool compiled_with_lcd :1;
bool compiled_with_lcd : 1;
// rdv4
bool hw_available_flash :1;
bool hw_available_smartcard :1;
bool hw_available_flash : 1;
bool hw_available_smartcard : 1;
} PACKED capabilities_t;
extern capabilities_t pm3_capabilities;

View file

@ -323,7 +323,7 @@ int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
res = write(((serial_port_unix *)sp)->fd, pbtTx + pos, len - pos);
// Stop if the OS has some troubles sending the data
if (res <= 0)
if (res <= 0)
return PM3_EIO;
pos += res;

View file

@ -160,8 +160,8 @@ uint32_t uart_get_speed(const serial_port sp) {
}
int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) {
int res = ReadFile(((serial_port_windows *)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL);
if ( res )
int res = ReadFile(((serial_port_windows *)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL);
if (res)
return PM3_SUCCESS;
int errorcode = GetLastError();
@ -171,22 +171,22 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
return PM3_EIO;
}
printf("[!]res %d | rx errorcode == %d \n",res, errorcode);
return res;
printf("[!]res %d | rx errorcode == %d \n", res, errorcode);
return res;
}
int uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) {
DWORD txlen = 0;
int res = WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL);
if ( res )
if (res)
return PM3_SUCCESS;
int errorcode = GetLastError();
if (res == 0 && errorcode == 2) {
return PM3_EIO;
}
printf("[!!]res %d | send errorcode == %d \n",res, errorcode);
printf("[!!]res %d | send errorcode == %d \n", res, errorcode);
return PM3_ENOTTY;
}