Skip to content

Commit

Permalink
CHG: Proxmark#631 from offical repo. (piwi)
Browse files Browse the repository at this point in the history
CHG: textual adjustments
  • Loading branch information
iceman1001 committed Jul 28, 2018
1 parent 03e8d39 commit 4d8488e
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 82 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ ppls patches/*

client/lualibs/mf_default_keys.lua
client/lualibs/usb_cmd.lua

# recompiled
fpga_version_info.c
10 changes: 10 additions & 0 deletions armsrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ ARMSRC = fpgaloader.c \
# lf_proxbrute.c \
# hf_mattyrun.c \
VERSIONSRC = version.c \
fpga_version_info.c

# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
include ../common/Makefile.common
Expand All @@ -126,6 +128,14 @@ all: $(OBJS)

.DELETE_ON_ERROR:

# version.c should be remade on every compilation
.PHONY: version.c
version.c: default_version.c
perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@

fpga_version_info.c: $(FPGA_BITSTREAMS) $(FPGA_COMPRESSOR)
$(FPGA_COMPRESSOR) -v $(filter %.bit,$^) $@

$(OBJDIR)/fpga_all.o: $(OBJDIR)/fpga_all.bit.z
$(OBJCOPY) -O elf32-littlearm -I binary -B arm --prefix-sections=fpga_all_bit $^ $@

Expand Down
17 changes: 9 additions & 8 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "usb_cdc.h"
#include "proxmark3.h"
#include "apps.h"
#include "fpga.h"
#include "util.h"
#include "printf.h"
#include "string.h"
Expand Down Expand Up @@ -333,14 +334,14 @@ void SendVersion(void) {
FormatVersionInformation(temp, sizeof(temp), " os: ", &version_information);
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);

strncat(VersionString, " [ FPGA ]\n", sizeof(VersionString) - strlen(VersionString) - 1);
strncat(VersionString, "\n [ FPGA ]\n", sizeof(VersionString) - strlen(VersionString) - 1);

FpgaGatherVersion(FPGA_BITSTREAM_LF, temp, sizeof(temp));
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);

FpgaGatherVersion(FPGA_BITSTREAM_HF, temp, sizeof(temp));
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);

for (int i = 0; i < fpga_bitstream_num; i++) {
strncat(VersionString, fpga_version_information[i], sizeof(VersionString) - strlen(VersionString) - 1);
if (i < fpga_bitstream_num - 1) {
strncat(VersionString, "\n", sizeof(VersionString) - strlen(VersionString) - 1);
}
}
// Send Chip ID and used flash memory
uint32_t text_and_rodata_section_size = (uint32_t)&__data_src_start__ - (uint32_t)&_flash_start;
uint32_t compressed_data_section_size = common_area.arg1;
Expand All @@ -350,7 +351,7 @@ void SendVersion(void) {
// measure the USB Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
// Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the UsbCommand structure included.
void printUSBSpeed(void) {
Dbprintf("USB Speed:");
Dbprintf("USB Speed");
Dbprintf(" Sending USB packets to client...");

#define USB_SPEED_TEST_MIN_TIME 1500 // in milliseconds
Expand Down
26 changes: 9 additions & 17 deletions armsrc/fpgaloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@
//-----------------------------------------------------------------------------
#include "fpgaloader.h"

extern void DbpString(char *str);
extern void Dbprintf(const char *fmt, ...);

// remember which version of the bitstream we have already downloaded to the FPGA
static int downloaded_bitstream = FPGA_BITSTREAM_ERR;
static int downloaded_bitstream = 0;

// this is where the bitstreams are located in memory:
extern uint8_t _binary_obj_fpga_all_bit_z_start, _binary_obj_fpga_all_bit_z_end;

static uint8_t *fpga_image_ptr = NULL;
static uint32_t uncompressed_bytes_cnt;

static const uint8_t _bitparse_fixed_header[] = {0x00, 0x09, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x01};
#define FPGA_BITSTREAM_FIXED_HEADER_SIZE sizeof(_bitparse_fixed_header)
#define OUTPUT_BUFFER_LEN 80
#define FPGA_INTERLEAVE_SIZE 288

//-----------------------------------------------------------------------------
// Set up the Serial Peripheral Interface as master
Expand Down Expand Up @@ -205,7 +200,7 @@ static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8
// 288 bytes from FPGA file 1, followed by 288 bytes from FGPA file 2, etc.
//----------------------------------------------------------------------------
static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer) {
while((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % FPGA_BITSTREAM_MAX != (bitstream_version - 1)) {
while((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % fpga_bitstream_num != (bitstream_version - 1)) {
// skip undesired data belonging to other bitstream_versions
get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
}
Expand All @@ -232,7 +227,7 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s

// initialize z_stream structure for inflate:
compressed_fpga_stream->next_in = &_binary_obj_fpga_all_bit_z_start;
compressed_fpga_stream->avail_in = &_binary_obj_fpga_all_bit_z_start - &_binary_obj_fpga_all_bit_z_end;
compressed_fpga_stream->avail_in = &_binary_obj_fpga_all_bit_z_end - &_binary_obj_fpga_all_bit_z_start;
compressed_fpga_stream->next_out = output_buffer;
compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
compressed_fpga_stream->zalloc = &fpga_inflate_malloc;
Expand All @@ -245,8 +240,8 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s
for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++)
header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);

// Check for a valid .bit file (starts with _bitparse_fixed_header)
if (memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0)
// Check for a valid .bit file (starts with bitparse_fixed_header)
if (memcmp(bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0)
return true;

return false;
Expand Down Expand Up @@ -427,6 +422,7 @@ void FpgaDownloadAndGo(int bitstream_version) {
// free eventually allocated BigBuf memory
BigBuf_free(); BigBuf_Clear_ext(false);
}
/*
//-----------------------------------------------------------------------------
// Gather version information from FPGA image. Needs to decompress the begin
Expand Down Expand Up @@ -496,7 +492,7 @@ void FpgaGatherVersion(int bitstream_version, char *dst, int len) {
inflateEnd(&compressed_fpga_stream);
}

*/
//-----------------------------------------------------------------------------
// Send a 16 bit command/data pair to the FPGA.
// The bit format is: C3 C2 C1 C0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Expand Down Expand Up @@ -544,12 +540,8 @@ void SetAdcMuxFor(uint32_t whichGpio) {
}

void Fpga_print_status(void) {
DbpString("Fpga");
switch(downloaded_bitstream) {
case FPGA_BITSTREAM_HF: DbpString(" mode....................HF"); break;
case FPGA_BITSTREAM_LF: DbpString(" mode....................LF"); break;
default: Dbprintf(" mode....................%d", downloaded_bitstream); break;
}
Dbprintf("Currently loaded FPGA image");
Dbprintf(" mode....................%s", fpga_version_information[downloaded_bitstream-1]);
}

int FpgaGetCurrent(void) {
Expand Down
10 changes: 7 additions & 3 deletions armsrc/fpgaloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
#ifndef __FPGALOADER_H
#define __FPGALOADER_H

#include <stdint.h>
#include <stdbool.h>
#include "apps.h"
#include "fpga.h"
#include "common.h" // standard definitions
#include "proxmark3.h" // common area
#include "string.h"
#include "BigBuf.h" // bigbuf mem
#include "zlib.h" // uncompress


void FpgaSendCommand(uint16_t cmd, uint16_t v);
void FpgaWriteConfWord(uint8_t v);
void FpgaDownloadAndGo(int bitstream_version);
void FpgaGatherVersion(int bitstream_version, char *dst, int len);
// void FpgaGatherVersion(int bitstream_version, char *dst, int len);
void FpgaSetupSscExt(uint8_t clearPCER);
void FpgaSetupSsc(void);
void SetupSpi(int mode);
Expand All @@ -36,10 +41,9 @@ void SetAdcMuxFor(uint32_t whichGpio);
extern void switch_off(void);

// definitions for multiple FPGA config files support
#define FPGA_BITSTREAM_MAX 2 // the total number of FPGA bitstreams (configs)
#define FPGA_BITSTREAM_ERR 0
#define FPGA_BITSTREAM_LF 1
#define FPGA_BITSTREAM_HF 2
//#define FPGA_BITSTREAM_FELICA 3

// Definitions for the FPGA commands.
#define FPGA_CMD_SET_CONFREG (1<<12)
Expand Down
2 changes: 1 addition & 1 deletion armsrc/lfsampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Default LF config is set to:
sample_config config = { 1, 8, 1, 95, 0 } ;

void printConfig() {
Dbprintf("LF Sampling config:");
Dbprintf("LF Sampling config");
Dbprintf(" [q] divisor.............%d (%d KHz)", config.divisor, 12000 / (config.divisor+1));
Dbprintf(" [b] bps.................%d", config.bits_per_sample);
Dbprintf(" [d] decimation..........%d", config.decimation);
Expand Down
10 changes: 5 additions & 5 deletions armsrc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,23 @@ void FormatVersionInformation(char *dst, int len, const char *prefix, void *vers
struct version_information *v = (struct version_information*)version_information;
dst[0] = 0;
strncat(dst, prefix, len-1);
if(v->magic != VERSION_INFORMATION_MAGIC) {
if (v->magic != VERSION_INFORMATION_MAGIC) {
strncat(dst, "Missing/Invalid version information\n", len - strlen(dst) - 1);
return;
}
if(v->versionversion != 1) {
if (v->versionversion != 1) {
strncat(dst, "Version information not understood\n", len - strlen(dst) - 1);
return;
}
if(!v->present) {
if (!v->present) {
strncat(dst, "Version information not available\n", len - strlen(dst) - 1);
return;
}

strncat(dst, v->gitversion, len - strlen(dst) - 1);
if(v->clean == 0) {
if (v->clean == 0) {
strncat(dst, "-unclean", len - strlen(dst) - 1);
} else if(v->clean == 2) {
} else if (v->clean == 2) {
strncat(dst, "-suspect", len - strlen(dst) - 1);
}

Expand Down
5 changes: 5 additions & 0 deletions bootrom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ THUMBSRC = cmd.c \
bootrom.c

ASMSRC = ram-reset.s flash-reset.s
VERSIONSRC = version.c

## There is a strange bug with the linker: Sometimes it will not emit the glue to call
## BootROM from ARM mode. The symbol is emitted, but the section will be filled with
Expand All @@ -29,6 +30,10 @@ include ../common/Makefile.common

OBJS = $(OBJDIR)/bootrom.s19

# version.c should be remade on every compilation
version.c: default_version.c
perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@

all: $(OBJS)

tarbin: $(OBJS)
Expand Down
2 changes: 1 addition & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ all-static: proxmark3 flasher fpga_compress

proxmark3: LDLIBS+=$(LUALIB) $(QTLDLIBS)
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) lualibs/usb_cmd.lua lualibs/mf_default_keys.lua
$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) $(LDLIBS) -o $@
$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) $(LDLIBS) -o $@

flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS)
$(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@
Expand Down
49 changes: 27 additions & 22 deletions client/cmdhw.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
char asBuff[120];
memset(asBuff, 0, sizeof(asBuff));
uint32_t mem_avail = 0;
PrintAndLogEx(NORMAL, " [ Hardware ] ");
PrintAndLogEx(NORMAL, "\n [ Hardware ] ");

switch(iChipID) {
case 0x270B0A40: sprintf(asBuff,"AT91SAM7S512 Rev A"); break;
Expand Down Expand Up @@ -242,32 +242,37 @@ int CmdVersion(const char *Cmd) {
if ( silent )
return 0;

UsbCommand c = {CMD_VERSION};
static UsbCommand resp = {0, {0, 0, 0}};

if (resp.arg[0] == 0 && resp.arg[1] == 0) { // no cached information available
clearCommandBuffer();
SendCommand(&c);
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
UsbCommand c = {CMD_VERSION, {0, 0, 0}};
UsbCommand resp;
clearCommandBuffer();
SendCommand(&c);
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
#ifdef __WIN32
PrintAndLogEx(NORMAL, "\nProxmark3 RFID instrument\n");
PrintAndLogEx(NORMAL, "\nProxmark3 RFID instrument\n");
#else
PrintAndLogEx(NORMAL, "\n\e[34mProxmark3 RFID instrument\e[0m\n");
PrintAndLogEx(NORMAL, "\n\e[34mProxmark3 RFID instrument\e[0m\n");
#endif
PrintAndLogEx(NORMAL, (char*)resp.d.asBytes);
lookupChipID(resp.arg[0], resp.arg[1]);
}
} else {
PrintAndLogEx(NORMAL, "[[[ Cached information ]]]\n");
#ifdef __WIN32
PrintAndLogEx(NORMAL, "\nProxmark3 RFID instrument\n");
#else
PrintAndLogEx(NORMAL, "\n\e[33mProxmark3 RFID instrument\e[0m\n");
char s[40] = {0};
int i = 0;
#if defined(WITH_FLASH) || defined(WITH_SMARTCARD)
strncat(s, "build for RDV40 with ", 22);
i = 15;
#endif

#ifdef WITH_FLASH
strncat(s, "flashmem; ", 10);
i += 10;
#endif
#ifdef WITH_SMARTCARD
strncat(s+i, "smartcard; ", 11);
i += 11;
#endif
PrintAndLogEx(NORMAL, "\n [ CLIENT ]");
PrintAndLogEx(NORMAL, " client: iceman %s \n", s);

PrintAndLogEx(NORMAL, (char*)resp.d.asBytes);
lookupChipID(resp.arg[0], resp.arg[1]);
PrintAndLogEx(NORMAL, "");
}
lookupChipID(resp.arg[0], resp.arg[1]);
}
PrintAndLogEx(NORMAL, "\n");
return 0;
}
Expand Down
Loading

0 comments on commit 4d8488e

Please sign in to comment.