Changed hf_cardhopper standalone mode to allow running over the internal Proxmark3 USB-CDC serial port.

This functionality can be enabled by adding the following to your Makefile.platform:
STANDALONE_PLATFORM_DEFS+=-DCARDHOPPER_USB
This commit is contained in:
nvx 2023-12-29 22:06:57 +10:00
commit 33eaaa535f
2 changed files with 30 additions and 9 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased] ## [unreleased][unreleased]
- Changed `hf_cardhopper` standalone mode to allow running over the internal Proxmark3 USB-CDC serial port (@nvx)
- Fixed CLI prompt - Update connection type prompt after running `hw connect` (@wh201906) - Fixed CLI prompt - Update connection type prompt after running `hw connect` (@wh201906)
- Changed `uart_receive()` - Check if TCP connection is lost (@wh201906) - Changed `uart_receive()` - Check if TCP connection is lost (@wh201906)
- Change `data detectclock` - now tries all clocks if called w/o any params (@iceman1001) - Change `data detectclock` - now tries all clocks if called w/o any params (@iceman1001)

View file

@ -27,7 +27,18 @@
#include "ticks.h" #include "ticks.h"
#include "util.h" #include "util.h"
#include "usart.h" #include "usart.h"
#include "cmd.h"
#include "usb_cdc.h"
#ifdef CARDHOPPER_USB
#define cardhopper_write usb_write
#define cardhopper_read usb_read_ng
#define cardhopper_data_available usb_poll_validate_length
#else
#define cardhopper_write usart_writebuffer_sync
#define cardhopper_read usart_read_ng
#define cardhopper_data_available usart_rxdata_available
#endif
void ModInfo(void) { void ModInfo(void) {
DbpString(" HF - Long-range relay 14a over serial<->IP - a.k.a. CardHopper (Sam Haskins)"); DbpString(" HF - Long-range relay 14a over serial<->IP - a.k.a. CardHopper (Sam Haskins)");
@ -64,6 +75,13 @@ static bool GetIso14443aCommandFromReaderInterruptible(uint8_t *, uint8_t *, int
void RunMod(void) { void RunMod(void) {
// Ensure debug logs don't polute stream
#ifdef CARDHOPPER_USB
g_reply_via_usb = false;
#else
g_reply_via_fpc = false;
#endif
StandAloneMode(); StandAloneMode();
DbpString(_CYAN_("[@]") " CardHopper has started - waiting for mode"); DbpString(_CYAN_("[@]") " CardHopper has started - waiting for mode");
FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -191,7 +209,7 @@ static void become_card(void) {
WDT_HIT(); WDT_HIT();
if (!GetIso14443aCommandFromReaderInterruptible(fromReaderDat, parity, &fromReaderLen)) { if (!GetIso14443aCommandFromReaderInterruptible(fromReaderDat, parity, &fromReaderLen)) {
if (usart_rxdata_available()) { if (cardhopper_data_available()) {
read_packet(rx); read_packet(rx);
if (memcmp(magicRSRT, rx->dat, sizeof(magicRSRT)) == 0) { if (memcmp(magicRSRT, rx->dat, sizeof(magicRSRT)) == 0) {
DbpString(_CYAN_("[@]") " Breaking from reader loop"); DbpString(_CYAN_("[@]") " Breaking from reader loop");
@ -359,23 +377,25 @@ static void reply_with_packet(packet_t *packet) {
static void read_packet(packet_t *packet) { static void read_packet(packet_t *packet) {
while (!usart_rxdata_available()) { while (!cardhopper_data_available()) {
WDT_HIT(); WDT_HIT();
SpinDelayUs(100); SpinDelayUs(100);
} }
uint32_t dataReceived = usart_read_ng((uint8_t *) packet, sizeof(packet_t)) - 1; cardhopper_read((uint8_t *) &packet->len, 1);
while (dataReceived != packet->len) {
while (!usart_rxdata_available()) WDT_HIT();
dataReceived += usart_read_ng(packet->dat + dataReceived, 255 - dataReceived); uint32_t dataReceived = 0;
while (dataReceived != packet->len) {
while (!cardhopper_data_available()) WDT_HIT();
dataReceived += cardhopper_read(packet->dat + dataReceived, packet->len - dataReceived);
} }
usart_writebuffer_sync(magicACK, sizeof(magicACK)); cardhopper_write(magicACK, sizeof(magicACK));
} }
static void write_packet(packet_t *packet) { static void write_packet(packet_t *packet) {
usart_writebuffer_sync((uint8_t *) packet, packet->len + 1); cardhopper_write((uint8_t *) packet, packet->len + 1);
} }
@ -394,7 +414,7 @@ static bool GetIso14443aCommandFromReaderInterruptible(uint8_t *received, uint8_
WDT_HIT(); WDT_HIT();
if (flip == 3) { if (flip == 3) {
if (usart_rxdata_available()) if (cardhopper_data_available())
return false; return false;
flip = 0; flip = 0;