style
This commit is contained in:
1 parent
185da09e62
commit
1f3cf80898
16 files changed
+139
-107
No files matched your search
@@ -4472,17 +4472,17 @@ static int CmdHFiClassSAM(const char *Cmd) {
|
||||
// CSN, config, epurse, NR/MAC, AIA
|
||||
// PACS
|
||||
// first byte skip
|
||||
// second byte length
|
||||
// third padded
|
||||
// second byte length
|
||||
// third padded
|
||||
// fourth ..
|
||||
uint8_t *d = resp.data.asBytes;
|
||||
uint8_t n = d[1] - 1; // skip length byte
|
||||
uint8_t pad = d[2];
|
||||
char *binstr = (char*)calloc((n * 8) + 1 , sizeof(uint8_t));
|
||||
char *binstr = (char *)calloc((n * 8) + 1, sizeof(uint8_t));
|
||||
if (binstr == NULL) {
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
|
||||
byte_2_binstr(binstr, d + 3, n);
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
@@ -4494,7 +4494,7 @@ static int CmdHFiClassSAM(const char *Cmd) {
|
||||
|
||||
size_t hexlen = 0;
|
||||
uint8_t hex[16] = {0};
|
||||
binstr_2_bytes(hex, &hexlen,binstr);
|
||||
binstr_2_bytes(hex, &hexlen, binstr);
|
||||
PrintAndLogEx(SUCCESS, "hex.......... " _GREEN_("%s"), sprint_hex_inrow(hex, hexlen));
|
||||
|
||||
uint32_t top = 0, mid = 0, bot = 0;
|
||||
|
||||
@@ -42,8 +42,9 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 1, "prefs help" },
|
||||
{ 1, "prefs show" },
|
||||
{ 1, "prefs get barmode" },
|
||||
{ 1, "prefs get clientdebug" },
|
||||
{ 1, "prefs get clientdelay" },
|
||||
{ 1, "prefs get client.debug" },
|
||||
{ 1, "prefs get client.delay" },
|
||||
{ 1, "prefs get client.timeout" },
|
||||
{ 1, "prefs get color" },
|
||||
{ 1, "prefs get savepaths" },
|
||||
{ 1, "prefs get emoji" },
|
||||
@@ -52,8 +53,9 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 1, "prefs get plotsliders" },
|
||||
{ 1, "prefs set help" },
|
||||
{ 1, "prefs set barmode" },
|
||||
{ 1, "prefs set clientdebug" },
|
||||
{ 1, "prefs set clientdelay" },
|
||||
{ 1, "prefs set client.debug" },
|
||||
{ 1, "prefs set client.delay" },
|
||||
{ 1, "prefs set client.timeout" },
|
||||
{ 1, "prefs set color" },
|
||||
{ 1, "prefs set emoji" },
|
||||
{ 1, "prefs set hints" },
|
||||
|
||||
@@ -852,7 +852,7 @@ static int setClientTimeout(const char *Cmd) {
|
||||
uint32_t new_value = (uint32_t)arg_get_int_def(ctx, 1, 0);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// UART_USB_CLIENT_RX_TIMEOUT_MS is considered as the minimum required timeout.
|
||||
// UART_USB_CLIENT_RX_TIMEOUT_MS is considered as the minimum required timeout.
|
||||
if (new_value < UART_USB_CLIENT_RX_TIMEOUT_MS) {
|
||||
PrintAndLogEx(WARNING, "Timeout less than %u ms might cause errors.", UART_USB_CLIENT_RX_TIMEOUT_MS);
|
||||
} else if (new_value > 5000) {
|
||||
@@ -1268,7 +1268,7 @@ static command_t CommandTableSet[] = {
|
||||
{"client.debug", setCmdDebug, AlwaysAvailable, "Set client debug level"},
|
||||
{"client.delay", setCmdExeDelay, AlwaysAvailable, "Set client execution delay"},
|
||||
{"client.timeout", setClientTimeout, AlwaysAvailable, "Set client communication timeout"},
|
||||
|
||||
|
||||
{"color", setCmdColor, AlwaysAvailable, "Set color support"},
|
||||
{"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"},
|
||||
{"hints", setCmdHint, AlwaysAvailable, "Set hint display"},
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "ringbuffer.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
RingBuffer* RingBuf_create(int capacity) {
|
||||
RingBuffer* buffer = (RingBuffer*)malloc(sizeof(RingBuffer));
|
||||
RingBuffer *RingBuf_create(int capacity) {
|
||||
RingBuffer *buffer = (RingBuffer *)malloc(sizeof(RingBuffer));
|
||||
if (!buffer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer->data = (uint8_t*)calloc(capacity, sizeof(uint8_t));
|
||||
buffer->data = (uint8_t *)calloc(capacity, sizeof(uint8_t));
|
||||
if (!buffer->data) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
@@ -21,15 +21,15 @@ RingBuffer* RingBuf_create(int capacity) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline bool RingBuf_isFull(RingBuffer* buffer) {
|
||||
inline bool RingBuf_isFull(RingBuffer *buffer) {
|
||||
return buffer->size == buffer->capacity;
|
||||
}
|
||||
|
||||
inline bool RingBuf_isEmpty(RingBuffer* buffer) {
|
||||
inline bool RingBuf_isEmpty(RingBuffer *buffer) {
|
||||
return buffer->size == 0;
|
||||
}
|
||||
|
||||
bool RingBuf_enqueue(RingBuffer* buffer, uint8_t value) {
|
||||
bool RingBuf_enqueue(RingBuffer *buffer, uint8_t value) {
|
||||
if (RingBuf_isFull(buffer)) {
|
||||
return false;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ bool RingBuf_enqueue(RingBuffer* buffer, uint8_t value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RingBuf_dequeue(RingBuffer* buffer, uint8_t* value) {
|
||||
bool RingBuf_dequeue(RingBuffer *buffer, uint8_t *value) {
|
||||
if (RingBuf_isEmpty(buffer)) {
|
||||
return false;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ bool RingBuf_dequeue(RingBuffer* buffer, uint8_t* value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int RingBuf_enqueueBatch(RingBuffer* buffer, const uint8_t* values, int count) {
|
||||
int RingBuf_enqueueBatch(RingBuffer *buffer, const uint8_t *values, int count) {
|
||||
int processed = 0;
|
||||
|
||||
if (RingBuf_getAvailableSize(buffer) < count) {
|
||||
@@ -69,7 +69,7 @@ int RingBuf_enqueueBatch(RingBuffer* buffer, const uint8_t* values, int count) {
|
||||
return processed;
|
||||
}
|
||||
|
||||
int RingBuf_dequeueBatch(RingBuffer* buffer, uint8_t* values, int count) {
|
||||
int RingBuf_dequeueBatch(RingBuffer *buffer, uint8_t *values, int count) {
|
||||
int processed = 0;
|
||||
|
||||
if (buffer->size < count) {
|
||||
@@ -87,32 +87,32 @@ int RingBuf_dequeueBatch(RingBuffer* buffer, uint8_t* values, int count) {
|
||||
return processed;
|
||||
}
|
||||
|
||||
inline int RingBuf_getUsedSize(RingBuffer* buffer) {
|
||||
inline int RingBuf_getUsedSize(RingBuffer *buffer) {
|
||||
return buffer->size;
|
||||
}
|
||||
|
||||
inline int RingBuf_getAvailableSize(RingBuffer* buffer) {
|
||||
inline int RingBuf_getAvailableSize(RingBuffer *buffer) {
|
||||
return (buffer->capacity) - (buffer->size);
|
||||
}
|
||||
|
||||
void RingBuf_destroy(RingBuffer* buffer) {
|
||||
void RingBuf_destroy(RingBuffer *buffer) {
|
||||
if (buffer != NULL)
|
||||
free(buffer->data);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
inline int RingBuf_getContinousAvailableSize(RingBuffer* buffer) {
|
||||
inline int RingBuf_getContinousAvailableSize(RingBuffer *buffer) {
|
||||
const int availableSize = RingBuf_getAvailableSize(buffer);
|
||||
const int continousSize = (buffer->capacity) - (buffer->rear);
|
||||
return (availableSize < continousSize) ? availableSize : continousSize;
|
||||
}
|
||||
|
||||
inline void RingBuf_postEnqueueBatch(RingBuffer* buffer, int count) {
|
||||
inline void RingBuf_postEnqueueBatch(RingBuffer *buffer, int count) {
|
||||
// no check there
|
||||
buffer->rear = (buffer->rear + count) % buffer->capacity;
|
||||
buffer->size += count;
|
||||
}
|
||||
|
||||
inline uint8_t* RingBuf_getRearPtr(RingBuffer* buffer) {
|
||||
inline uint8_t *RingBuf_getRearPtr(RingBuffer *buffer) {
|
||||
return buffer->data + buffer->rear;
|
||||
}
|
||||
@@ -5,27 +5,27 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t* data;
|
||||
uint8_t *data;
|
||||
int capacity;
|
||||
int size;
|
||||
int front;
|
||||
int rear;
|
||||
} RingBuffer;
|
||||
|
||||
RingBuffer* RingBuf_create(int capacity);
|
||||
bool RingBuf_isFull(RingBuffer* buffer);
|
||||
bool RingBuf_isEmpty(RingBuffer* buffer);
|
||||
bool RingBuf_enqueue(RingBuffer* buffer, uint8_t value);
|
||||
bool RingBuf_dequeue(RingBuffer* buffer, uint8_t* value);
|
||||
int RingBuf_enqueueBatch(RingBuffer* buffer, const uint8_t* values, int count);
|
||||
int RingBuf_dequeueBatch(RingBuffer* buffer, uint8_t* values, int count);
|
||||
int RingBuf_getUsedSize(RingBuffer* buffer);
|
||||
int RingBuf_getAvailableSize(RingBuffer* buffer);
|
||||
void RingBuf_destroy(RingBuffer* buffer);
|
||||
RingBuffer *RingBuf_create(int capacity);
|
||||
bool RingBuf_isFull(RingBuffer *buffer);
|
||||
bool RingBuf_isEmpty(RingBuffer *buffer);
|
||||
bool RingBuf_enqueue(RingBuffer *buffer, uint8_t value);
|
||||
bool RingBuf_dequeue(RingBuffer *buffer, uint8_t *value);
|
||||
int RingBuf_enqueueBatch(RingBuffer *buffer, const uint8_t *values, int count);
|
||||
int RingBuf_dequeueBatch(RingBuffer *buffer, uint8_t *values, int count);
|
||||
int RingBuf_getUsedSize(RingBuffer *buffer);
|
||||
int RingBuf_getAvailableSize(RingBuffer *buffer);
|
||||
void RingBuf_destroy(RingBuffer *buffer);
|
||||
|
||||
// for direct write
|
||||
int RingBuf_getContinousAvailableSize(RingBuffer* buffer);
|
||||
void RingBuf_postEnqueueBatch(RingBuffer* buffer, int count);
|
||||
uint8_t* RingBuf_getRearPtr(RingBuffer* buffer);
|
||||
int RingBuf_getContinousAvailableSize(RingBuffer *buffer);
|
||||
void RingBuf_postEnqueueBatch(RingBuffer *buffer, int count);
|
||||
uint8_t *RingBuf_getRearPtr(RingBuffer *buffer);
|
||||
|
||||
#endif
|
||||
@@ -56,7 +56,7 @@ typedef struct {
|
||||
int fd; // Serial port file descriptor
|
||||
term_info tiOld; // Terminal info before using the port
|
||||
term_info tiNew; // Terminal info during the transaction
|
||||
RingBuffer* udpBuffer;
|
||||
RingBuffer *udpBuffer;
|
||||
} serial_port_unix_t_t;
|
||||
|
||||
// see pm3_cmd.h
|
||||
@@ -150,7 +150,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
portstr = rColon + 1;
|
||||
} else {
|
||||
portstr = "18888";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle the end of the address
|
||||
@@ -261,7 +261,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
portstr = rColon + 1;
|
||||
} else {
|
||||
portstr = "18888";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle the end of the address
|
||||
@@ -519,9 +519,9 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
||||
*pszRxLen = 0;
|
||||
do {
|
||||
int res;
|
||||
if(spu->udpBuffer != NULL) {
|
||||
if (spu->udpBuffer != NULL) {
|
||||
// for UDP connection, try to use the data from the buffer
|
||||
|
||||
|
||||
byteCount = RingBuf_getAvailableSize(spu->udpBuffer);
|
||||
// Cap the number of bytes, so we don't overrun the buffer
|
||||
if (pszMaxRxLen - (*pszRxLen) < byteCount) {
|
||||
@@ -536,7 +536,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reset file descriptor
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(spu->fd, &rfds);
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef struct {
|
||||
DCB dcb; // Device control settings
|
||||
COMMTIMEOUTS ct; // Serial port time-out configuration
|
||||
SOCKET hSocket; // Socket handle
|
||||
RingBuffer* udpBuffer; // Buffer for UDP
|
||||
RingBuffer *udpBuffer; // Buffer for UDP
|
||||
} serial_port_windows_t;
|
||||
|
||||
// this is for TCP connection
|
||||
@@ -473,7 +473,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
||||
*pszRxLen = 0;
|
||||
do {
|
||||
int res;
|
||||
if(spw->udpBuffer != NULL) {
|
||||
if (spw->udpBuffer != NULL) {
|
||||
// for UDP connection, try to use the data from the buffer
|
||||
|
||||
byteCount = RingBuf_getAvailableSize(spw->udpBuffer);
|
||||
|
||||
Reference in new issue
Block a user