make style

This commit is contained in:
Philippe Teuwen 2019-03-10 00:00:59 +01:00
commit 0373696662
483 changed files with 56514 additions and 52451 deletions

View file

@ -44,19 +44,22 @@ static pthread_mutex_t rxBufferMutex = PTHREAD_MUTEX_INITIALIZER;
// These wrappers are required because it is not possible to access a static
// global variable outside of the context of a single file.
void SetOffline(bool value) {
void SetOffline(bool value)
{
offline = value;
}
bool IsOffline() {
bool IsOffline()
{
return offline;
}
void SendCommand(UsbCommand *c) {
void SendCommand(UsbCommand *c)
{
#ifdef COMMS_DEBUG
#ifdef COMMS_DEBUG
PrintAndLogEx(NORMAL, "Sending %d bytes | cmd %04x\n", sizeof(UsbCommand), c->cmd);
#endif
#endif
if (offline) {
PrintAndLogEx(NORMAL, "Sending bytes to proxmark failed - offline");
@ -90,7 +93,8 @@ void SendCommand(UsbCommand *c) {
* A better method could have been to have explicit command-ACKS, so we can know which ACK goes to which
* operation. Right now we'll just have to live with this.
*/
void clearCommandBuffer() {
void clearCommandBuffer()
{
//This is a very simple operation
pthread_mutex_lock(&rxBufferMutex);
cmd_tail = cmd_head;
@ -100,21 +104,22 @@ void clearCommandBuffer() {
* @brief storeCommand stores a USB command in a circular buffer
* @param UC
*/
static void storeCommand(UsbCommand *command) {
static void storeCommand(UsbCommand *command)
{
pthread_mutex_lock(&rxBufferMutex);
if ( ( cmd_head+1) % CMD_BUFFER_SIZE == cmd_tail) {
if ((cmd_head + 1) % CMD_BUFFER_SIZE == cmd_tail) {
//If these two are equal, we're about to overwrite in the
// circular buffer.
PrintAndLogEx(FAILED, "WARNING: Command buffer about to overwrite command! This needs to be fixed!");
fflush(stdout);
}
//Store the command at the 'head' location
UsbCommand* destination = &rxBuffer[cmd_head];
UsbCommand *destination = &rxBuffer[cmd_head];
memcpy(destination, command, sizeof(UsbCommand));
//increment head and wrap
cmd_head = (cmd_head +1) % CMD_BUFFER_SIZE;
//increment head and wrap
cmd_head = (cmd_head + 1) % CMD_BUFFER_SIZE;
pthread_mutex_unlock(&rxBufferMutex);
}
/**
@ -122,7 +127,8 @@ static void storeCommand(UsbCommand *command) {
* @param response location to write command
* @return 1 if response was returned, 0 if nothing has been received
*/
static int getCommand(UsbCommand* response) {
static int getCommand(UsbCommand *response)
{
pthread_mutex_lock(&rxBufferMutex);
//If head == tail, there's nothing to read, or if we just got initialized
if (cmd_head == cmd_tail) {
@ -131,11 +137,11 @@ static int getCommand(UsbCommand* response) {
}
//Pick out the next unread command
UsbCommand* last_unread = &rxBuffer[cmd_tail];
UsbCommand *last_unread = &rxBuffer[cmd_tail];
memcpy(response, last_unread, sizeof(UsbCommand));
//Increment tail - this is a circular buffer, so modulo buffer size
cmd_tail = (cmd_tail +1 ) % CMD_BUFFER_SIZE;
cmd_tail = (cmd_tail + 1) % CMD_BUFFER_SIZE;
pthread_mutex_unlock(&rxBufferMutex);
return 1;
@ -145,13 +151,14 @@ static int getCommand(UsbCommand* response) {
// Entry point into our code: called whenever we received a packet over USB
// that we weren't necessarily expecting, for example a debug print.
//-----------------------------------------------------------------------------
static void UsbCommandReceived(UsbCommand* c) {
static void UsbCommandReceived(UsbCommand *c)
{
switch(c->cmd) {
switch (c->cmd) {
// First check if we are handling a debug message
case CMD_DEBUG_PRINT_STRING: {
char s[USB_CMD_DATA_SIZE+1];
char s[USB_CMD_DATA_SIZE + 1];
memset(s, 0x00, sizeof(s));
size_t len = MIN(c->arg[0], USB_CMD_DATA_SIZE);
memcpy(s, c->d.asBytes, len);
@ -224,8 +231,9 @@ void
__attribute__((force_align_arg_pointer))
#endif
#endif
*uart_communication(void *targ) {
communication_arg_t *conn = (communication_arg_t*)targ;
*uart_communication(void *targ)
{
communication_arg_t *conn = (communication_arg_t *)targ;
size_t rxlen, totallen = 0;
UsbCommand rx;
UsbCommand *prx = ℞
@ -244,7 +252,7 @@ __attribute__((force_align_arg_pointer))
prx += rxlen;
totallen += rxlen;
if ( totallen < sizeof(UsbCommand)) {
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.
@ -273,7 +281,7 @@ __attribute__((force_align_arg_pointer))
}
if (txBuffer_pending) {
if (!uart_send(sp, (uint8_t*) &txBuffer, sizeof(UsbCommand))) {
if (!uart_send(sp, (uint8_t *) &txBuffer, sizeof(UsbCommand))) {
//counter_to_offline++;
PrintAndLogEx(WARNING, "sending bytes to proxmark failed");
}
@ -298,19 +306,21 @@ __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)
{
char *portname = (char *)port;
if (!wait_for_port) {
sp = uart_open(portname);
} else {
PrintAndLogEx(SUCCESS, "Waiting for Proxmark to appear on " _YELLOW_(%s), portname);
PrintAndLogEx(SUCCESS, "Waiting for Proxmark to appear on " _YELLOW_( % s), portname);
fflush(stdout);
int openCount = 0;
do {
sp = uart_open(portname);
msleep(500);
printf("."); fflush(stdout);
printf(".");
fflush(stdout);
} while (++openCount < timeout && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT));
//PrintAndLogEx(NORMAL, "\n");
}
@ -341,7 +351,8 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode)
}
}
void CloseProxmark(void) {
void CloseProxmark(void)
{
conn.run = false;
@ -383,7 +394,8 @@ void CloseProxmark(void) {
* @param show_warning display message after 3 seconds
* @return true if command was returned, otherwise false
*/
bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand* response, size_t ms_timeout, bool show_warning) {
bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeout, bool show_warning)
{
UsbCommand resp;
@ -395,7 +407,7 @@ bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand* response, size_t ms_timeo
// Wait until the command is received
while (true) {
while ( getCommand(response) ) {
while (getCommand(response)) {
if (cmd == CMD_UNKNOWN || response->cmd == cmd)
return true;
}
@ -413,11 +425,13 @@ bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand* response, size_t ms_timeo
return false;
}
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout) {
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand *response, size_t ms_timeout)
{
return WaitForResponseTimeoutW(cmd, response, ms_timeout, true);
}
bool WaitForResponse(uint32_t cmd, UsbCommand* response) {
bool WaitForResponse(uint32_t cmd, UsbCommand *response)
{
return WaitForResponseTimeoutW(cmd, response, -1, true);
}
@ -434,7 +448,8 @@ bool WaitForResponse(uint32_t cmd, UsbCommand* response) {
* @param show_warning display message after 2 seconds
* @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) {
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;
@ -472,7 +487,8 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
return false;
}
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) {
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();
@ -496,8 +512,8 @@ bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *resp
copy_bytes = MIN(copy_bytes, USB_CMD_DATA_SIZE);
// 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);
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;
}