remove spurious spaces & tabs at end of lines

This commit is contained in:
Philippe Teuwen 2019-03-09 08:59:13 +01:00
commit 60f292b18e
249 changed files with 8481 additions and 8481 deletions

View file

@ -57,7 +57,7 @@ void SendCommand(UsbCommand *c) {
#ifdef COMMS_DEBUG
PrintAndLogEx(NORMAL, "Sending %d bytes | cmd %04x\n", sizeof(UsbCommand), c->cmd);
#endif
if (offline) {
PrintAndLogEx(NORMAL, "Sending bytes to proxmark failed - offline");
return;
@ -65,22 +65,22 @@ void SendCommand(UsbCommand *c) {
pthread_mutex_lock(&txBufferMutex);
/**
This causes hangups at times, when the pm3 unit is unresponsive or disconnected. The main console thread is alive,
This causes hangups at times, when the pm3 unit is unresponsive or disconnected. The main console thread is alive,
but comm thread just spins here. Not good.../holiman
**/
while (txBuffer_pending) {
// wait for communication thread to complete sending a previous commmand
pthread_cond_wait(&txBufferSig, &txBufferMutex);
// wait for communication thread to complete sending a previous commmand
pthread_cond_wait(&txBufferSig, &txBufferMutex);
}
txBuffer = *c;
txBuffer_pending = true;
// tell communication thread that a new command can be send
// tell communication thread that a new command can be send
pthread_cond_signal(&txBufferSig);
pthread_mutex_unlock(&txBufferMutex);
//__atomic_test_and_set(&txcmd_pending, __ATOMIC_SEQ_CST);
}
@ -101,7 +101,7 @@ void clearCommandBuffer() {
* @param UC
*/
static void storeCommand(UsbCommand *command) {
pthread_mutex_lock(&rxBufferMutex);
if ( ( cmd_head+1) % CMD_BUFFER_SIZE == cmd_tail) {
//If these two are equal, we're about to overwrite in the
@ -114,7 +114,7 @@ static void storeCommand(UsbCommand *command) {
memcpy(destination, command, sizeof(UsbCommand));
//increment head and wrap
cmd_head = (cmd_head +1) % CMD_BUFFER_SIZE;
cmd_head = (cmd_head +1) % CMD_BUFFER_SIZE;
pthread_mutex_unlock(&rxBufferMutex);
}
/**
@ -129,7 +129,7 @@ static int getCommand(UsbCommand* response) {
pthread_mutex_unlock(&rxBufferMutex);
return 0;
}
//Pick out the next unread command
UsbCommand* last_unread = &rxBuffer[cmd_tail];
memcpy(response, last_unread, sizeof(UsbCommand));
@ -146,17 +146,17 @@ static int getCommand(UsbCommand* response) {
// that we weren't necessarily expecting, for example a debug print.
//-----------------------------------------------------------------------------
static void UsbCommandReceived(UsbCommand* c) {
switch(c->cmd) {
// First check if we are handling a debug message
case CMD_DEBUG_PRINT_STRING: {
char s[USB_CMD_DATA_SIZE+1];
memset(s, 0x00, sizeof(s));
memset(s, 0x00, sizeof(s));
size_t len = MIN(c->arg[0], USB_CMD_DATA_SIZE);
memcpy(s, c->d.asBytes, len);
memcpy(s, c->d.asBytes, len);
uint64_t flag = c->arg[1];
switch (flag) {
case FLAG_RAWPRINT:
printf("%s", s);
@ -183,7 +183,7 @@ static void UsbCommandReceived(UsbCommand* c) {
}
// iceman: hw status - down the path on device, runs printusbspeed which starts sending a lot of
// CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K packages which is not dealt with. I wonder if simply ignoring them will
// work. lets try it.
// work. lets try it.
default: {
storeCommand(c);
break;
@ -192,14 +192,14 @@ static void UsbCommandReceived(UsbCommand* c) {
}
/*
bool hookUpPM3() {
bool hookUpPM3() {
bool ret = false;
sp = uart_open( comport );
if (sp == INVALID_SERIAL_PORT) {
PrintAndLogEx(WARNING, "Reconnect failed, retrying... (reason: invalid serial port)\n");
sp = NULL;
serial_port_name = NULL;
serial_port_name = NULL;
ret = false;
offline = 1;
} else if (sp == CLAIMED_SERIAL_PORT) {
@ -208,7 +208,7 @@ bool hookUpPM3() {
serial_port_name = NULL;
ret = false;
offline = 1;
} else {
} else {
PrintAndLogEx(SUCCESS, "Proxmark reconnected\n");
serial_port_name = ;
ret = true;
@ -221,44 +221,44 @@ bool hookUpPM3() {
void
#ifdef __has_attribute
#if __has_attribute(force_align_arg_pointer)
__attribute__((force_align_arg_pointer))
__attribute__((force_align_arg_pointer))
#endif
#endif
*uart_communication(void *targ) {
communication_arg_t *conn = (communication_arg_t*)targ;
size_t rxlen, totallen = 0;
size_t rxlen, totallen = 0;
UsbCommand rx;
UsbCommand *prx = ℞
//int counter_to_offline = 0;
#if defined(__MACH__) && defined(__APPLE__)
disableAppNap("Proxmark3 polling UART");
#endif
while (conn->run) {
rxlen = 0;
bool ACK_received = false;
if (uart_receive(sp, (uint8_t *)prx, sizeof(UsbCommand) - (prx - &rx), &rxlen) && rxlen) {
prx += rxlen;
totallen += rxlen;
if ( totallen < sizeof(UsbCommand)) {
// iceman: this looping is no working as expected at all. The reassemble of package is nonfunctional.
// solved so far with increasing the timeouts of the serial port configuration.
PrintAndLogEx(NORMAL, "Foo %d | %d (loop)", prx - &rx, rxlen);
continue;
}
totallen = 0;
UsbCommandReceived(&rx);
if (rx.cmd == CMD_ACK) {
ACK_received = true;
}
}
prx = &rx;
pthread_mutex_lock(&txBufferMutex);
@ -274,11 +274,11 @@ __attribute__((force_align_arg_pointer))
if (txBuffer_pending) {
if (!uart_send(sp, (uint8_t*) &txBuffer, sizeof(UsbCommand))) {
//counter_to_offline++;
//counter_to_offline++;
PrintAndLogEx(WARNING, "sending bytes to proxmark failed");
}
txBuffer_pending = false;
// tell main thread that txBuffer is empty
pthread_cond_signal(&txBufferSig);
}
@ -293,13 +293,13 @@ __attribute__((force_align_arg_pointer))
#if defined(__MACH__) && defined(__APPLE__)
enableAppNap();
#endif
pthread_exit(NULL);
return NULL;
}
bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode) {
char *portname = (char *)port;
if (!wait_for_port) {
sp = uart_open(portname);
@ -331,7 +331,7 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode)
serial_port_name = portname;
conn.run = true;
conn.block_after_ACK = flash_mode;
pthread_create(&USB_communication_thread, NULL, &uart_communication, &conn);
pthread_create(&USB_communication_thread, NULL, &uart_communication, &conn);
//pthread_create(&FPC_communication_thread, NULL, &uart_communication, &conn);
fflush(stdout);
@ -350,10 +350,10 @@ void CloseProxmark(void) {
pthread_join(USB_communication_thread, NULL);
}
#else
pthread_join(USB_communication_thread, NULL);
pthread_join(USB_communication_thread, NULL);
//pthread_join(FPC_communication_thread, NULL);
#endif
if (sp) {
uart_close(sp);
}
@ -376,7 +376,7 @@ void CloseProxmark(void) {
/**
* @brief Waits for a certain response type. This method waits for a maximum of
* ms_timeout milliseconds for a specified response command.
* @param cmd command to wait for, or CMD_UNKNOWN to take any command.
* @param response struct to copy received command into.
* @param ms_timeout display message after 3 seconds
@ -384,25 +384,25 @@ void CloseProxmark(void) {
* @return true if command was returned, otherwise false
*/
bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand* response, size_t ms_timeout, bool show_warning) {
UsbCommand resp;
if (response == NULL)
response = &resp;
uint64_t start_time = msclock();
// Wait until the command is received
while (true) {
while ( getCommand(response) ) {
if (cmd == CMD_UNKNOWN || response->cmd == cmd)
return true;
return true;
}
if (msclock() - start_time > ms_timeout)
break;
if (msclock() - start_time > 3000 && show_warning) {
// 3 seconds elapsed (but this doesn't mean the timeout was exceeded)
PrintAndLogEx(NORMAL, "Waiting for a response from the proxmark...");
@ -435,7 +435,7 @@ bool WaitForResponse(uint32_t cmd, UsbCommand* response) {
* @return true if command was returned, otherwise false
*/
bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning) {
if (dest == NULL) return false;
if (bytes == 0) return true;
@ -443,9 +443,9 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
if (response == NULL)
response = &resp;
// clear
// clear
clearCommandBuffer();
switch (memtype) {
case BIG_BUF: {
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
@ -454,10 +454,10 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
}
case BIG_BUF_EML: {
UsbCommand c = {CMD_DOWNLOAD_EML_BIGBUF, {start_index, bytes, 0}};
SendCommand(&c);
SendCommand(&c);
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
}
case FLASH_MEM: {
case FLASH_MEM: {
UsbCommand c = {CMD_FLASHMEM_DOWNLOAD, {start_index, bytes, 0}};
SendCommand(&c);
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED);
@ -473,46 +473,46 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
}
bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) {
uint32_t bytes_completed = 0;
uint64_t start_time = msclock();
while (true) {
if (getCommand(response)) {
// sample_buf is a array pointer, located in data.c
// arg0 = offset in transfer. Startindex of this chunk
// arg1 = length bytes to transfer
// arg2 = bigbuff tracelength (?)
// arg2 = bigbuff tracelength (?)
if (response->cmd == rec_cmd) {
uint32_t offset = response->arg[0];
uint32_t copy_bytes = MIN(bytes - bytes_completed, response->arg[1]);
//uint32_t tracelen = c->arg[2];
// extended bounds check1. upper limit is USB_CMD_DATA_SIZE
// shouldn't happen
copy_bytes = MIN(copy_bytes, USB_CMD_DATA_SIZE);
// extended bounds check2.
// extended bounds check2.
if ( offset + copy_bytes > bytes ) {
PrintAndLogEx(FAILED, "ERROR: Out of bounds when downloading from device, offset %u | len %u | total len %u > buf_size %u", offset, copy_bytes, offset+copy_bytes, bytes);
break;
}
}
memcpy(dest + offset, response->d.asBytes, copy_bytes);
bytes_completed += copy_bytes;
} else if (response->cmd == CMD_ACK) {
return true;
}
}
if (msclock() - start_time > ms_timeout) {
PrintAndLogEx(FAILED, "Timed out while trying to download data from device");
break;
}
if (msclock() - start_time > 3000 && show_warning) {
// 3 seconds elapsed (but this doesn't mean the timeout was exceeded)
PrintAndLogEx(NORMAL, "Waiting for a response from the proxmark...");