Merge pull request #2220 from nvx/feature/cardhopper_usb_cdc

Changed hf_cardhopper standalone mode to allow running over the internal PM3 USB-CDC serial port.
This commit is contained in:
Iceman 2023-12-29 19:37:24 +01:00 committed by GitHub
commit faedd3e19e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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...
## [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)
- Changed `uart_receive()` - Check if TCP connection is lost (@wh201906)
- Change `data detectclock` - now tries all clocks if called w/o any params (@iceman1001)

View file

@ -27,7 +27,18 @@
#include "ticks.h"
#include "util.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) {
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) {
// Ensure debug logs don't polute stream
#ifdef CARDHOPPER_USB
g_reply_via_usb = false;
#else
g_reply_via_fpc = false;
#endif
StandAloneMode();
DbpString(_CYAN_("[@]") " CardHopper has started - waiting for mode");
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -191,7 +209,7 @@ static void become_card(void) {
WDT_HIT();
if (!GetIso14443aCommandFromReaderInterruptible(fromReaderDat, parity, &fromReaderLen)) {
if (usart_rxdata_available()) {
if (cardhopper_data_available()) {
read_packet(rx);
if (memcmp(magicRSRT, rx->dat, sizeof(magicRSRT)) == 0) {
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) {
while (!usart_rxdata_available()) {
while (!cardhopper_data_available()) {
WDT_HIT();
SpinDelayUs(100);
}
uint32_t dataReceived = usart_read_ng((uint8_t *) packet, sizeof(packet_t)) - 1;
while (dataReceived != packet->len) {
while (!usart_rxdata_available()) WDT_HIT();
cardhopper_read((uint8_t *) &packet->len, 1);
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) {
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();
if (flip == 3) {
if (usart_rxdata_available())
if (cardhopper_data_available())
return false;
flip = 0;