Merge branch 'RfidResearchGroup:master' into WIFI-test

This commit is contained in:
Niel Nielsen authored and GitHub committed 2026-08-27 16:58:47 +02:00
commit 63112fad75
11 files changed
+112 -26

No files matched your search

+13 -1
View File
@@ -1116,7 +1116,19 @@ static void SendCapabilities(void) {
#ifdef WITH_SMARTCARD
capabilities.compiled_with_smartcard = true;
uint8_t maj, min;
capabilities.hw_available_smartcard = I2C_get_version(&maj, &min) == PM3_SUCCESS;
// The module may still be finishing a card exchange from a previous
// session when this runs, and a single missed answer used to report the
// hardware as absent for the whole of the next one - every smartcard
// command then said it was not available in this mode.
capabilities.hw_available_smartcard = false;
for (uint8_t i = 0; i < 3; i++) {
if (I2C_get_version(&maj, &min) == PM3_SUCCESS) {
capabilities.hw_available_smartcard = true;
break;
}
SpinDelay(50);
}
#else
capabilities.compiled_with_smartcard = false;
capabilities.hw_available_smartcard = false;
+1 -1
View File
@@ -622,7 +622,7 @@ static int CmdSmartUpgrade(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "smart upgrade",
"Upgrade RDV4 sim module firmware",
"smart upgrade -f sim014.bin"
"smart upgrade -f sim017.bin"
);
void *argtable[] = {
+8
View File
@@ -138,6 +138,10 @@ void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, c
pthread_mutex_unlock(&txBufferMutex);
// and interrupt its receive, which it would otherwise sit out in full
// before looking at the send buffer at all
uart_wakeup();
//__atomic_test_and_set(&txcmd_pending, __ATOMIC_SEQ_CST);
}
@@ -202,6 +206,10 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool
pthread_mutex_unlock(&txBufferMutex);
// and interrupt its receive, which it would otherwise sit out in full
// before looking at the send buffer at all
uart_wakeup();
//__atomic_test_and_set(&txcmd_pending, __ATOMIC_SEQ_CST);
}
+10
View File
@@ -799,6 +799,16 @@ static int CmdEMVSearch(const char *Cmd) {
struct tlvdb *t = tlvdb_fixed(1, strlen(al), (const unsigned char *)al);
if (EMVSearch(channel, activateField, leaveSignalON, decodeTLV, t, false)) {
PrintAndLogEx(FAILED, "Search failed, no answer from the card");
// Without activation the ARM never reads the ATR, so it does not know
// which protocols the card offers and cannot redirect a T=0 request to
// a T=1 only card. That used to end here without a word.
if ((channel == CC_CONTACT) && (activateField == false)) {
PrintAndLogEx(HINT, "Hint: the card is activated by `" _YELLOW_("-s") "`, try `" _YELLOW_("emv search -w -s") "`");
}
tlvdb_free(t);
SetAPDULogging(false);
return PM3_ERFTRANS;
+5 -4
View File
@@ -266,6 +266,11 @@ void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv) {
ttmp = tlvdb_find_next(ttmp, 0x6f);
}
if (n == 0) {
PrintAndLogEx(INFO, "No applications found");
return;
}
size_t w_aid = strlen("AID");
size_t w_prio = strlen("Priority");
size_t w_name = strlen("Name");
@@ -289,10 +294,6 @@ void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv) {
(int)w_aid, "AID", (int)w_prio, "Priority", (int)w_name, "Name");
PrintAndLogEx(INFO, "%s", rule);
if (n == 0) {
PrintAndLogEx(INFO, "| %-*s |", (int)(w_aid + w_prio + w_name + 6), "none");
}
for (size_t i = 0; i < n; i++) {
PrintAndLogEx(INFO, "| " _YELLOW_("%-*s") " | %-*s | " _CYAN_("%-*s") " |",
(int)w_aid, rows[i].aid,
+7
View File
@@ -76,6 +76,13 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
*/
uint32_t uart_get_speed(const serial_port sp);
/* Wake a thread blocked in uart_receive() so it can get on and service a
* queued send. The comm thread receives before it transmits, so without this a
* command sits in the buffer until the receive phase times out.
* Safe to call from another thread; a no-op where it is not implemented.
*/
void uart_wakeup(void);
/* Reconfigure timeouts (ms)
*/
int uart_reconfigure_timeouts(uint32_t value);
+59 -11
View File
@@ -36,6 +36,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <pthread.h>
#ifdef HAVE_BLUEZ
#include <bluetooth/bluetooth.h>
@@ -74,6 +75,36 @@ static uint32_t newtimeout_value = 0;
static bool newtimeout_pending = false;
static uint8_t rx_empty_counter = 0;
// Self pipe used to interrupt the select() in uart_receive(). Created once, on
// first use, and never closed - two descriptors for the life of the process,
// and both ends have to stay valid for whichever thread touches them.
static int wakeup_pipe[2] = { -1, -1 };
static pthread_once_t wakeup_once = PTHREAD_ONCE_INIT;
static void uart_wakeup_create(void) {
if (pipe(wakeup_pipe) != 0) {
wakeup_pipe[0] = -1;
wakeup_pipe[1] = -1;
return;
}
// Neither end may ever block: a full pipe already means a wakeup is
// pending, which is all the reader needs to know.
fcntl(wakeup_pipe[0], F_SETFL, O_NONBLOCK);
fcntl(wakeup_pipe[1], F_SETFL, O_NONBLOCK);
}
void uart_wakeup(void) {
pthread_once(&wakeup_once, uart_wakeup_create);
if (wakeup_pipe[1] < 0) {
return;
}
const uint8_t b = 1;
ssize_t res = write(wakeup_pipe[1], &b, 1);
(void)res; // EAGAIN just means a wakeup is already queued
}
int uart_reconfigure_timeouts(uint32_t value) {
newtimeout_value = value;
newtimeout_pending = true;
@@ -616,18 +647,22 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
// Reset file descriptor
FD_ZERO(&rfds);
FD_SET(spu->fd, &rfds);
tv = timeout;
if ((*pszRxLen == 0) &&
(spu->udpBuffer == NULL) &&
(timeout.tv_sec == 0) &&
(timeout.tv_usec <= UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000)) {
// Nothing of a frame in hand yet - see the header note. Local links
// only: a network link keeps its own longer timeout, where polling
// this fast would cost more than it saves.
tv.tv_sec = 0;
tv.tv_usec = UART_USB_CLIENT_RX_IDLE_TIMEOUT_MS * 1000;
int maxfd = spu->fd;
// Only watch the wakeup while no part of a frame is in hand. Cutting a
// frame short would hand the caller a partial packet, and leaving the
// pipe readable while mid frame would spin.
pthread_once(&wakeup_once, uart_wakeup_create);
bool watch_wakeup = ((*pszRxLen == 0) && (wakeup_pipe[0] >= 0));
if (watch_wakeup) {
FD_SET(wakeup_pipe[0], &rfds);
if (wakeup_pipe[0] > maxfd) {
maxfd = wakeup_pipe[0];
}
}
res = select(spu->fd + 1, &rfds, NULL, NULL, &tv);
tv = timeout;
res = select(maxfd + 1, &rfds, NULL, NULL, &tv);
// Read error
if (res < 0) {
@@ -645,6 +680,19 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
}
}
if (watch_wakeup && FD_ISSET(wakeup_pipe[0], &rfds)) {
uint8_t drain[64];
while (read(wakeup_pipe[0], drain, sizeof(drain)) > 0) { };
// Nothing on the wire, only a send waiting. Return before the
// FIONREAD below, which counts empty reads towards declaring the
// device gone.
if (FD_ISSET(spu->fd, &rfds) == false) {
return PM3_ENODATA;
}
}
// Retrieve the count of the incoming bytes
res = ioctl(spu->fd, FIONREAD, &byteCount);
// PrintAndLogEx(ERR, "UART:: RX ioctl res %d byteCount %u", res, byteCount);
+4
View File
@@ -51,6 +51,10 @@ uint32_t newtimeout_value = 0;
bool newtimeout_pending = false;
uint8_t rx_empty_counter = 0;
// Not implemented here: the win32 receive path would need an event object in
// its wait instead of a pipe. Leaving it a no-op keeps that platform as it was.
void uart_wakeup(void) { }
int uart_reconfigure_timeouts(uint32_t value) {
newtimeout_value = value;
newtimeout_pending = true;
+4 -1
View File
@@ -272,7 +272,10 @@ void hex_to_buffer(uint8_t *buf, const uint8_t *hex_data, const size_t hex_len,
m = hex_max_len;
}
while (m--) {
// Pad up to m, the way ascii_to_buffer() above does. This used to write m
// spaces from wherever it had got to, so a padded field came out i
// characters too wide - a 7 byte AID asked to fill 16 produced 30.
for (; i < m; i++) {
*(tmp++) = ' ';
}
-7
View File
@@ -1151,13 +1151,6 @@ typedef struct {
// uart_win32.c & uart_posix.c
#define UART_FPC_CLIENT_RX_TIMEOUT_MS 200
#define UART_USB_CLIENT_RX_TIMEOUT_MS 20
// Idle poll, used only while no part of a frame is in hand. The comm thread
// transmits a queued command only after its receive phase returns, so a long
// idle wait here delays every single command by up to one full timeout.
// Returning "no data" promptly costs nothing; once part of a frame IS in hand
// the full timeout above applies, so a frame split across USB frames is never
// truncated.
#define UART_USB_CLIENT_RX_IDLE_TIMEOUT_MS 1
#define UART_NET_CLIENT_RX_TIMEOUT_MS 500
#define UART_TCP_LOCAL_CLIENT_RX_TIMEOUT_MS 40
#define UART_UDP_LOCAL_CLIENT_RX_TIMEOUT_MS 20
+1 -1
View File
@@ -358,7 +358,7 @@ while true; do
if $TESTALL || $TESTMFDAESBRUTE; then
echo -e "\n${C_BLUE}Testing mfd_aes_brute:${C_NC} ${MFDASEBRUTEBIN:=./tools/mfd_aes_brute/mfd_aes_brute}"
if ! CheckFileExist "mfd_aes_brute exists" "$MFDASEBRUTEBIN"; then break; fi
if ! CheckExecute "mfd_aes_brute test 1/2" "$MFDASEBRUTEBIN 1629394800 bb6aea729414a5b1eff7b16328ce37fd 82f5f498dbc29f7570102397a2e5ef2b6dc14a864f665b3c54d11765af81e95c" "key.................... .*261C07A23F2BC8262F69F10A5BDF3764"; then break; fi
if ! CheckExecute slow "mfd_aes_brute test 1/2" "$MFDASEBRUTEBIN 1629394800 bb6aea729414a5b1eff7b16328ce37fd 82f5f498dbc29f7570102397a2e5ef2b6dc14a864f665b3c54d11765af81e95c" "key.................... .*261C07A23F2BC8262F69F10A5BDF3764"; then break; fi
if ! CheckExecute slow "mfd_aes_brute test 2/2" "$MFDASEBRUTEBIN 1546300800 3fda933e2953ca5e6cfbbf95d1b51ddf 97fe4b5de24188458d102959b888938c988e96fb98469ce7426f50f108eaa583" "key.................... .*E757178E13516A4F3171BC6EA85E165A"; then break; fi
fi
if $TESTALL || $TESTMFULCDESBRUTE; then