Skip to content

Commit

Permalink
Merge pull request #2220 from nvx/feature/cardhopper_usb_cdc
Browse files Browse the repository at this point in the history
Changed hf_cardhopper standalone mode to allow running over the internal PM3 USB-CDC serial port.
  • Loading branch information
iceman1001 authored Dec 29, 2023
2 parents 56c3187 + 33eaaa5 commit faedd3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 29 additions & 9 deletions armsrc/Standalone/hf_cardhopper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
cardhopper_read((uint8_t *) &packet->len, 1);

uint32_t dataReceived = 0;
while (dataReceived != packet->len) {
while (!usart_rxdata_available()) WDT_HIT();
while (!cardhopper_data_available()) WDT_HIT();

dataReceived += usart_read_ng(packet->dat + dataReceived, 255 - dataReceived);
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);
}


Expand All @@ -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;
Expand Down

0 comments on commit faedd3e

Please sign in to comment.