summer restructuring:
* .h include only the strict minimum for their own parsing * this forces all files to include explicitment their needs and not count on far streched dependencies * this helps Makefile to rebuild only the minimum * according to this rule, most standalone .h are now gone * big app.h is gone * remove seldom __cplusplus, if c++ happens, everything will have to be done properly anyway * all unrequired include were removed * split common/ into common/ (client+arm) and common_arm/ (os+bootloader) * bring zlib to common/ * bring stuff not really/not yet used in common back to armsrc/ or client/ * bring liblua into client/ * bring uart into client/ * move some portions of code around (dbprint, protocols,...) * rename unused files into *_disabled.[ch] to make it explicit * rename soft Uarts between 14a, 14b and iclass, so a standalone could use several without clash * remove PrintAndLogDevice * move deprecated-hid-flasher from client to tools * Makefiles * treat deps in armsrc/ as in client/ * client: stop on warning (-Werror), same as for armsrc/ Tested on: * all standalone modes * Linux
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "BigBuf.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "dbprint.h"
|
||||
|
||||
// BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces.
|
||||
// Also used to hold various smaller buffers and the Mifare Emulator Memory.
|
||||
// declare it as uint32_t to achieve alignment to 4 Byte boundary
|
||||
|
||||
@@ -12,10 +12,7 @@
|
||||
#ifndef __BIGBUF_H
|
||||
#define __BIGBUF_H
|
||||
|
||||
#include <stdbool.h> // for bool
|
||||
#include "proxmark3.h"
|
||||
#include "string.h"
|
||||
#include "ticks.h"
|
||||
#include "common.h"
|
||||
|
||||
#define BIGBUF_SIZE 40000
|
||||
#define MAX_FRAME_SIZE 256 // maximum allowed ISO14443 frame
|
||||
@@ -43,4 +40,5 @@ void set_tracelen(uint32_t value);
|
||||
bool get_tracing(void);
|
||||
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
|
||||
uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length);
|
||||
|
||||
#endif /* __BIGBUF_H */
|
||||
|
||||
@@ -9,10 +9,6 @@
|
||||
#ifndef __LCD_H
|
||||
#define __LCD_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "fonts.h"
|
||||
|
||||
// The resolution of the LCD
|
||||
#define LCD_XRES 132
|
||||
#define LCD_YRES 132
|
||||
@@ -2,16 +2,14 @@
|
||||
# at your option, any later version. See the LICENSE.txt file for the text of
|
||||
# the license.
|
||||
#-----------------------------------------------------------------------------
|
||||
# Makefile for armsrc, see ../common/Makefile.common for common settings
|
||||
# Makefile for armsrc, see ../common_arm/Makefile.common for common settings
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
APP_INCLUDES = apps.h
|
||||
|
||||
# This Makefile might have been called directly, not via the root Makefile, so:
|
||||
ifeq ($(PLTNAME),)
|
||||
-include ../Makefile.platform
|
||||
-include ../.Makefile.options.cache
|
||||
include ../common/Makefile.hal
|
||||
include ../common_arm/Makefile.hal
|
||||
# detect if there were changes in the platform definitions, requiring a clean
|
||||
ifeq ($(PLATFORM_CHANGED), true)
|
||||
$(error platform definitions have been changed, please "make clean" at the root of the project)
|
||||
@@ -28,9 +26,10 @@ APP_CFLAGS = $(PLATFORM_DEFS) \
|
||||
SRC_LF = lfops.c lfsampling.c pcf7931.c lfdemod.c
|
||||
SRC_ISO15693 = iso15693.c iso15693tools.c
|
||||
SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c
|
||||
#UNUSED: mifaresniff.c desfire_crypto.c
|
||||
SRC_ISO14443b = iso14443b.c
|
||||
SRC_FELICA = felica.c
|
||||
SRC_CRAPTO1 = crypto1.c des.c desfire_key.c desfire_crypto.c mifaredesfire.c aes.c platform_util.c
|
||||
SRC_CRAPTO1 = crypto1.c des.c desfire_key.c mifaredesfire.c aes.c platform_util.c
|
||||
SRC_CRC = crc.c crc16.c crc32.c
|
||||
SRC_ICLASS = iclass.c optimized_cipher.c
|
||||
SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c
|
||||
@@ -83,7 +82,7 @@ SRC_ZLIB = inflate.c inffast.c inftrees.c adler32.c zutil.c
|
||||
ZLIB_CFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED
|
||||
APP_CFLAGS += $(ZLIB_CFLAGS)
|
||||
# zlib includes:
|
||||
APP_CFLAGS += -I../zlib
|
||||
APP_CFLAGS += -I../common/zlib
|
||||
|
||||
# stdint.h provided locally until GCC 4.5 becomes C99 compliant,
|
||||
# stack-protect , no-pie reduces size on Gentoo Hardened 8.2 gcc
|
||||
@@ -91,7 +90,6 @@ APP_CFLAGS += -I. -fno-stack-protector -fno-pie
|
||||
|
||||
# Compile these in thumb mode (small size)
|
||||
THUMBSRC = start.c \
|
||||
protocols.c \
|
||||
$(SRC_LCD) \
|
||||
$(SRC_ISO15693) \
|
||||
$(SRC_NFCBARCODE) \
|
||||
@@ -105,6 +103,7 @@ THUMBSRC = start.c \
|
||||
$(SRC_SPIFFS) \
|
||||
appmain.c \
|
||||
printf.c \
|
||||
dbprint.c \
|
||||
commonutil.c \
|
||||
util.c \
|
||||
string.c \
|
||||
@@ -131,7 +130,7 @@ VERSIONSRC = version.c \
|
||||
fpga_version_info.c
|
||||
|
||||
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
|
||||
include ../common/Makefile.common
|
||||
include ../common_arm/Makefile.common
|
||||
|
||||
COMMON_FLAGS = -Os
|
||||
|
||||
@@ -220,3 +219,4 @@ help:
|
||||
@echo Possible targets:
|
||||
@echo + all - Build the full image $(OBJDIR)/fullimage.s19
|
||||
@echo + clean - Clean $(OBJDIR)
|
||||
|
||||
|
||||
@@ -19,7 +19,18 @@ you can simply run 'script run read_pwd_mem' or just 'mem dump p l 256'
|
||||
from the client to view the stored quadlets.
|
||||
*/
|
||||
|
||||
#include "hf_bog.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "iso14443a.h"
|
||||
#include "protocols.h"
|
||||
#include "util.h"
|
||||
#include "spiffs.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "BigBuf.h"
|
||||
#include "string.h"
|
||||
|
||||
#define DELAY_READER_AIR2ARM_AS_SNIFFER (2 + 3 + 8)
|
||||
#define DELAY_TAG_AIR2ARM_AS_SNIFFER (3 + 14 + 8)
|
||||
@@ -62,10 +73,10 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
bool ReaderIsActive = false;
|
||||
|
||||
// Set up the demodulator for tag -> reader responses.
|
||||
DemodInit(receivedResp, receivedRespPar);
|
||||
Demod14aInit(receivedResp, receivedRespPar);
|
||||
|
||||
// Set up the demodulator for the reader -> tag commands
|
||||
UartInit(receivedCmd, receivedCmdPar);
|
||||
Uart14aInit(receivedCmd, receivedCmdPar);
|
||||
|
||||
// Setup and start DMA.
|
||||
if (!FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE)) {
|
||||
@@ -74,8 +85,8 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
return;
|
||||
}
|
||||
|
||||
tUart *uart = GetUart();
|
||||
tDemod *demod = GetDemod();
|
||||
tUart14a *uart = GetUart14a();
|
||||
tDemod14a *demod = GetDemod14a();
|
||||
|
||||
// We won't start recording the frames that we acquire until we trigger;
|
||||
// a good trigger condition to get started is probably when we see a
|
||||
@@ -153,13 +164,13 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
break;
|
||||
}
|
||||
/* ready to receive another command. */
|
||||
UartReset();
|
||||
Uart14aReset();
|
||||
/* reset the demod code, which might have been */
|
||||
/* false-triggered by the commands from the reader. */
|
||||
DemodReset();
|
||||
Demod14aReset();
|
||||
LED_B_OFF();
|
||||
}
|
||||
ReaderIsActive = (uart->state != STATE_UNSYNCD);
|
||||
ReaderIsActive = (uart->state != STATE_14A_UNSYNCD);
|
||||
}
|
||||
|
||||
// no need to try decoding tag data if the reader is sending - and we cannot afford the time
|
||||
@@ -176,13 +187,13 @@ void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
triggered = true;
|
||||
|
||||
// ready to receive another response.
|
||||
DemodReset();
|
||||
Demod14aReset();
|
||||
// reset the Miller decoder including its (now outdated) input buffer
|
||||
UartReset();
|
||||
Uart14aReset();
|
||||
// UartInit(receivedCmd, receivedCmdPar);
|
||||
LED_C_OFF();
|
||||
}
|
||||
TagIsActive = (demod->state != DEMOD_UNSYNCD);
|
||||
TagIsActive = (demod->state != DEMOD_14A_UNSYNCD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// StandAlone Mod
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __HF_BOG_H
|
||||
#define __HF_BOG_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "mifareutil.h"
|
||||
#include "iso14443a.h"
|
||||
#include "protocols.h"
|
||||
#include "util.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include <stdbool.h> // for bool
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "apps.h"
|
||||
#include "printf.h"
|
||||
#include "parity.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
|
||||
#endif /* __HF_BOG_H */
|
||||
@@ -8,8 +8,27 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// main code for HF Mifare aka ColinRun by Colin Brigato
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include <stdbool.h> // for bool
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include "hf_colin.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "BigBuf.h"
|
||||
#include "frozen.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "mifaresim.h" // mifare1ksim
|
||||
#include "mifareutil.h"
|
||||
#include "iso14443a.h"
|
||||
#include "util.h"
|
||||
#include "vtsend.h"
|
||||
#include "spiffs.h"
|
||||
#include "string.h"
|
||||
|
||||
#define MF1KSZ 1024
|
||||
#define MF1KSZSIZE 64
|
||||
|
||||
@@ -16,22 +16,6 @@
|
||||
#ifndef __HF_COLIN_H
|
||||
#define __HF_COLIN_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "mifaresim.h" // mifare1ksim
|
||||
#include "mifareutil.h"
|
||||
#include "iso14443a.h"
|
||||
#include "protocols.h"
|
||||
#include "util.h"
|
||||
#include "pmflash.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include <stdbool.h> // for bool
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "vtsend.h"
|
||||
#include "apps.h"
|
||||
#include "printf.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
#define _XRED_ "\x1b[31m"
|
||||
#define _XGREEN_ "\x1b[32m"
|
||||
#define _XYELLOW_ "\x1b[33m"
|
||||
|
||||
@@ -33,7 +33,21 @@ on a blank card.
|
||||
## Spanish full description of the project [here](http://bit.ly/2c9nZXR).
|
||||
*/
|
||||
|
||||
#include "hf_mattyrun.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "string.h"
|
||||
#include "commonutil.h"
|
||||
#include "iso14443a.h"
|
||||
#include "mifarecmd.h"
|
||||
#include "crc16.h"
|
||||
#include "BigBuf.h"
|
||||
#include "mifaresim.h" // mifare1ksim
|
||||
#include "mifareutil.h"
|
||||
|
||||
uint8_t uid[10];
|
||||
uint32_t cuid;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Matías A. Ré Medina 2016
|
||||
// Christian Herrmann, 2018
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// StandAlone Mod
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __HF_MATTYRUN_H
|
||||
#define __HF_MATTYRUN_H
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "apps.h" // debugstatements, lfops?
|
||||
#include "pm3_cmd.h" // mifare1ksim flags
|
||||
#include "mifaresim.h" // mifare1ksim
|
||||
#include "mifareutil.h"
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
#endif /* __HF_MATTYRUN_H */
|
||||
@@ -9,8 +9,21 @@
|
||||
// main code for HF standalone mode Mifare /sniff/emulation by Craig Young
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hf_young.h"
|
||||
#include "common.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include <inttypes.h>
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "string.h"
|
||||
#include "commonutil.h"
|
||||
#include "mifarecmd.h"
|
||||
#include "iso14443a.h"
|
||||
#include "protocols.h"
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
typedef struct {
|
||||
uint8_t uid[10];
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Craig Young 2014
|
||||
// Christian Herrmann, 2017
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// StandAlone Mod
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __HF_YOUNG_H
|
||||
#define __HF_YOUNG_H
|
||||
|
||||
#include <stdbool.h> // for bool
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "iso14443a.h"
|
||||
#include "protocols.h"
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
#endif /* __HF_YOUNG_H */
|
||||
@@ -24,8 +24,19 @@
|
||||
//-----------------------------------------------------------------------------------
|
||||
// main code for LF aka HID corporate brutefore by Federico Dotta & Maurizio Agazzini
|
||||
//-----------------------------------------------------------------------------------
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "lf_hidbrute.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "lfops.h"
|
||||
|
||||
#define OPTS 3
|
||||
|
||||
void ModInfo(void) {
|
||||
DbpString(" LF HID corporate 1000 bruteforce - aka Corporatebrute (Federico dotta & Maurizio Agazzini)");
|
||||
}
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
#ifndef __LF_HIDBRUTE_H
|
||||
#define __LF_HIDBRUTE_H
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "apps.h" // debugstatements, lfops?
|
||||
|
||||
#define OPTS 3
|
||||
#include <stdint.h>
|
||||
|
||||
void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc);
|
||||
|
||||
|
||||
@@ -7,7 +7,12 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// main code for skeleton aka IceRun by Iceman
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "lf_icerun.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
|
||||
void ModInfo(void) {
|
||||
DbpString(" LF skeleton mode - aka IceRun (iceman)");
|
||||
|
||||
@@ -9,7 +9,16 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// main code for LF aka Proxbrute by Brad antoniewicz
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "lf_proxbrute.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "lfops.h"
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
void ModInfo(void) {
|
||||
DbpString(" LF HID ProxII bruteforce - aka Proxbrute (Brad Antoniewicz)");
|
||||
|
||||
@@ -8,7 +8,16 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// main code for LF aka SamyRun by Samy Kamkar
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "lf_samyrun.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "lfops.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
void ModInfo(void) {
|
||||
DbpString(" LF HID26 standalone - aka SamyRun (Samy Kamkar)");
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Samy Kamkar 2012
|
||||
// Christian Herrmann, 2017
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// StandAlone Mod
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __LF_SAMYRUN_H
|
||||
#define __LF_SAMYRUN_H
|
||||
|
||||
//#include <stdbool.h> // for bool
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "apps.h" // debugstatements, lfops?
|
||||
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
#endif /* __LF_SAMYRUN_H */
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "apps.h" // debug statements
|
||||
|
||||
#include "dbprint.h"
|
||||
|
||||
void ModInfo(void) {
|
||||
DbpString(" No standalone mode present");
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
#ifndef __STANDALONE_H
|
||||
#define __STANDALONE_H
|
||||
|
||||
#include <stdbool.h> // for bool
|
||||
#include <inttypes.h> // PRIu64
|
||||
|
||||
void RunMod();
|
||||
void ModInfo();
|
||||
|
||||
|
||||
165
armsrc/appmain.c
165
armsrc/appmain.c
@@ -9,26 +9,37 @@
|
||||
// The main application code. This is the first thing called after start.c
|
||||
// executes.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <stdarg.h>
|
||||
#include <inttypes.h>
|
||||
#include "appmain.h"
|
||||
|
||||
#include "usb_cdc.h"
|
||||
#include "proxmark3.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "dbprint.h"
|
||||
#include "pmflash.h"
|
||||
#include "apps.h"
|
||||
#include "fpga.h"
|
||||
#include "util.h"
|
||||
#include "printf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "string.h"
|
||||
#include "legicrf.h"
|
||||
#include "legicrfsim.h"
|
||||
#include "lfsampling.h"
|
||||
#include "BigBuf.h"
|
||||
#include "mifareutil.h"
|
||||
#include "mifaresim.h"
|
||||
#include "hitag.h"
|
||||
#include "iso14443a.h"
|
||||
#include "iso14443b.h"
|
||||
#include "iso15693.h"
|
||||
#include "thinfilm.h"
|
||||
|
||||
#define DEBUG 1
|
||||
#include "felica.h"
|
||||
#include "hitag2.h"
|
||||
#include "hitagS.h"
|
||||
#include "iclass.h"
|
||||
#include "legicrfsim.h"
|
||||
#include "epa.h"
|
||||
#include "hfsnoop.h"
|
||||
#include "lfops.h"
|
||||
#include "lfsampling.h"
|
||||
#include "mifarecmd.h"
|
||||
#include "mifaredesfire.h"
|
||||
#include "mifaresim.h"
|
||||
#include "pcf7931.h"
|
||||
#include "Standalone/standalone.h"
|
||||
#include "util.h"
|
||||
#include "ticks.h"
|
||||
|
||||
#ifdef WITH_LCD
|
||||
#include "LCD.h"
|
||||
@@ -61,6 +72,12 @@ struct common_area common_area __attribute__((section(".commonarea")));
|
||||
int button_status = BUTTON_NO_CLICK;
|
||||
bool allow_send_wtx = false;
|
||||
|
||||
inline void send_wtx(uint16_t wtx) {
|
||||
if (allow_send_wtx) {
|
||||
reply_ng(CMD_WTX, PM3_SUCCESS, (uint8_t *)&wtx, sizeof(wtx));
|
||||
}
|
||||
}
|
||||
|
||||
void ToSendReset(void) {
|
||||
ToSendMax = -1;
|
||||
ToSendBit = 8;
|
||||
@@ -84,128 +101,6 @@ void ToSendStuffBit(int b) {
|
||||
}
|
||||
}
|
||||
|
||||
/* useful when debugging new protocol implementations like FeliCa
|
||||
void PrintToSendBuffer(void) {
|
||||
DbpString("Printing ToSendBuffer:");
|
||||
Dbhexdump(ToSendMax, ToSend, 0);
|
||||
}
|
||||
*/
|
||||
|
||||
void print_result(char *name, uint8_t *buf, size_t len) {
|
||||
|
||||
uint8_t *p = buf;
|
||||
uint16_t tmp = len & 0xFFF0;
|
||||
|
||||
for (; p - buf < tmp; p += 16) {
|
||||
Dbprintf("[%s: %02d/%02d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
|
||||
name,
|
||||
p - buf,
|
||||
len,
|
||||
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]
|
||||
);
|
||||
}
|
||||
if (len % 16 != 0) {
|
||||
char s[46] = {0};
|
||||
char *sp = s;
|
||||
for (; p - buf < len; p++) {
|
||||
sprintf(sp, "%02x ", p[0]);
|
||||
sp += 3;
|
||||
}
|
||||
Dbprintf("[%s: %02d/%02d] %s", name, p - buf, len, s);
|
||||
}
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// Debug print functions, to go out over USB, to the usual PC-side client.
|
||||
//=============================================================================
|
||||
|
||||
inline void send_wtx(uint16_t wtx) {
|
||||
if (allow_send_wtx) {
|
||||
reply_ng(CMD_WTX, PM3_SUCCESS, (uint8_t *)&wtx, sizeof(wtx));
|
||||
}
|
||||
}
|
||||
|
||||
void DbpStringEx(uint32_t flags, char *str) {
|
||||
#if DEBUG
|
||||
struct {
|
||||
uint16_t flag;
|
||||
uint8_t buf[PM3_CMD_DATA_SIZE - sizeof(uint16_t)];
|
||||
} PACKED data;
|
||||
data.flag = flags;
|
||||
uint16_t len = MIN(strlen(str), sizeof(data.buf));
|
||||
memcpy(data.buf, str, len);
|
||||
reply_ng(CMD_DEBUG_PRINT_STRING, PM3_SUCCESS, (uint8_t *)&data, sizeof(data.flag) + len);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DbpString(char *str) {
|
||||
#if DEBUG
|
||||
DbpStringEx(FLAG_LOG, str);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
void DbpIntegers(int x1, int x2, int x3) {
|
||||
reply_old(CMD_DEBUG_PRINT_INTEGERS, x1, x2, x3, 0, 0);
|
||||
}
|
||||
#endif
|
||||
void DbprintfEx(uint32_t flags, const char *fmt, ...) {
|
||||
#if DEBUG
|
||||
// should probably limit size here; oh well, let's just use a big buffer
|
||||
char output_string[128] = {0x00};
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
kvsprintf(fmt, output_string, 10, ap);
|
||||
va_end(ap);
|
||||
|
||||
DbpStringEx(flags, output_string);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dbprintf(const char *fmt, ...) {
|
||||
#if DEBUG
|
||||
// should probably limit size here; oh well, let's just use a big buffer
|
||||
char output_string[128] = {0x00};
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
kvsprintf(fmt, output_string, 10, ap);
|
||||
va_end(ap);
|
||||
|
||||
DbpString(output_string);
|
||||
#endif
|
||||
}
|
||||
|
||||
// prints HEX & ASCII
|
||||
void Dbhexdump(int len, uint8_t *d, bool bAsci) {
|
||||
#if DEBUG
|
||||
char ascii[9];
|
||||
|
||||
while (len > 0) {
|
||||
|
||||
int l = (len > 8) ? 8 : len;
|
||||
|
||||
memcpy(ascii, d, l);
|
||||
ascii[l] = 0;
|
||||
|
||||
// filter safe ascii
|
||||
for (int i = 0; i < l; i++) {
|
||||
if (ascii[i] < 32 || ascii[i] > 126) {
|
||||
ascii[i] = '.';
|
||||
}
|
||||
}
|
||||
|
||||
if (bAsci)
|
||||
Dbprintf("%-8s %*D", ascii, l, d, " ");
|
||||
else
|
||||
Dbprintf("%*D", l, d, " ");
|
||||
|
||||
len -= 8;
|
||||
d += 8;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Read an ADC channel and block till it completes, then return the result
|
||||
// in ADC units (0 to 1023). Also a routine to average 32 samples and
|
||||
|
||||
45
armsrc/appmain.h
Normal file
45
armsrc/appmain.h
Normal file
@@ -0,0 +1,45 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __APPMAIN_H
|
||||
#define __APPMAIN_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
extern const uint8_t OddByteParity[256];
|
||||
extern int rsamples; // = 0;
|
||||
extern uint8_t trigger;
|
||||
extern bool allow_send_wtx;
|
||||
|
||||
// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV
|
||||
#define MAX_ADC_HF_VOLTAGE 36300
|
||||
// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV
|
||||
#define MAX_ADC_HF_VOLTAGE_RDV40 140800
|
||||
// ADC Vref = 3300mV, and an (10000k+240k):240k voltage divider on the LF input can measure voltages up to 140800 mV
|
||||
#define MAX_ADC_LF_VOLTAGE 140800
|
||||
|
||||
extern int ToSendMax;
|
||||
extern uint8_t ToSend[];
|
||||
|
||||
void send_wtx(uint16_t wtx);
|
||||
void ReadMem(int addr);
|
||||
void __attribute__((noreturn)) AppMain(void);
|
||||
|
||||
uint16_t AvgAdc(int ch);
|
||||
|
||||
void print_result(char *name, uint8_t *buf, size_t len);
|
||||
//void PrintToSendBuffer(void);
|
||||
void ToSendStuffBit(int b);
|
||||
void ToSendReset(void);
|
||||
void ListenReaderField(uint8_t limit);
|
||||
void StandAloneMode(void);
|
||||
void printStandAloneModes(void);
|
||||
|
||||
#endif
|
||||
254
armsrc/apps.h
254
armsrc/apps.h
@@ -1,254 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __APPS_H
|
||||
#define __APPS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include "common.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "crc32.h"
|
||||
#include "lfdemod.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "hitag2.h"
|
||||
#include "hitagS.h"
|
||||
#include "mifare.h"
|
||||
#include "pcf7931.h"
|
||||
#include "desfire.h"
|
||||
#include "iso14443b.h"
|
||||
#include "Standalone/standalone.h"
|
||||
#include "flashmem.h"
|
||||
|
||||
extern const uint8_t OddByteParity[256];
|
||||
extern int rsamples; // = 0;
|
||||
extern uint8_t trigger;
|
||||
|
||||
// This may be used (sparingly) to declare a function to be copied to
|
||||
// and executed from RAM
|
||||
#define RAMFUNC __attribute((long_call, section(".ramfunc")))
|
||||
|
||||
/// appmain.h
|
||||
void ReadMem(int addr);
|
||||
void __attribute__((noreturn)) AppMain(void);
|
||||
void send_wtx(uint16_t wtx);
|
||||
//void DbpIntegers(int a, int b, int c);
|
||||
void DbpString(char *str);
|
||||
void DbpStringEx(uint32_t flags, char *str);
|
||||
void Dbprintf(const char *fmt, ...);
|
||||
void DbprintfEx(uint32_t flags, const char *fmt, ...);
|
||||
void Dbhexdump(int len, uint8_t *d, bool bAsci);
|
||||
|
||||
// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV
|
||||
#define MAX_ADC_HF_VOLTAGE 36300
|
||||
// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV
|
||||
#define MAX_ADC_HF_VOLTAGE_RDV40 140800
|
||||
// ADC Vref = 3300mV, and an (10000k+240k):240k voltage divider on the LF input can measure voltages up to 140800 mV
|
||||
#define MAX_ADC_LF_VOLTAGE 140800
|
||||
uint16_t AvgAdc(int ch);
|
||||
|
||||
void print_result(char *name, uint8_t *buf, size_t len);
|
||||
//void PrintToSendBuffer(void);
|
||||
void ToSendStuffBit(int b);
|
||||
void ToSendReset(void);
|
||||
void ListenReaderField(uint8_t limit);
|
||||
extern int ToSendMax;
|
||||
extern uint8_t ToSend[];
|
||||
|
||||
void StandAloneMode(void);
|
||||
void printStandAloneModes(void);
|
||||
|
||||
/// lfops.h
|
||||
extern uint8_t decimation;
|
||||
extern uint8_t bits_per_sample ;
|
||||
extern bool averaging;
|
||||
|
||||
void AcquireRawAdcSamples125k(int divisor);
|
||||
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command);
|
||||
void ReadTItag(void);
|
||||
void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc);
|
||||
|
||||
void AcquireTiType(void);
|
||||
void AcquireRawBitsTI(void);
|
||||
void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycles);
|
||||
void SimulateTagLowFrequency(int period, int gap, bool ledcontrol);
|
||||
void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen);
|
||||
|
||||
void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, bool ledcontrol, int numcycles);
|
||||
void CmdHIDsimTAG(uint32_t hi, uint32_t lo, bool ledcontrol);
|
||||
|
||||
void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, uint16_t bitslen, uint8_t *bits, bool ledcontrol);
|
||||
void CmdASKsimTAG(uint8_t encoding, uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol);
|
||||
void CmdPSKsimTag(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol);
|
||||
|
||||
void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol);
|
||||
void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); // Realtime demodulation mode for AWID26
|
||||
void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol);
|
||||
void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol);
|
||||
void CopyIOtoT55x7(uint32_t hi, uint32_t lo); // Clone an ioProx card to T5557/T5567
|
||||
void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT); // Clone an HID card to T5557/T5567
|
||||
void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5);
|
||||
void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo);
|
||||
void CopyIndala64toT55x7(uint32_t hi, uint32_t lo); // Clone Indala 64-bit tag by UID to T55x7
|
||||
void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7); // Clone Indala 224-bit tag by UID to T55x7
|
||||
void T55xxResetRead(uint8_t flags);
|
||||
//id T55xxWriteBlock(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags);
|
||||
void T55xxWriteBlock(uint8_t *data);
|
||||
// void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags);
|
||||
void T55xxReadBlock(uint8_t page, bool pwd_mode, bool brute_mem, uint8_t block, uint32_t pwd, uint8_t downlink_mode);
|
||||
void T55xxWakeUp(uint32_t pwd, uint8_t flags);
|
||||
void T55xx_ChkPwds(uint8_t flags);
|
||||
|
||||
void TurnReadLFOn(uint32_t delay);
|
||||
|
||||
void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd);
|
||||
void EM4xWriteWord(uint8_t addr, uint32_t data, uint32_t pwd, uint8_t usepwd);
|
||||
|
||||
void Cotag(uint32_t arg0);
|
||||
void setT55xxConfig(uint8_t arg0, t55xx_configurations_t *c);
|
||||
t55xx_configurations_t *getT55xxConfig(void);
|
||||
void printT55xxConfig(void);
|
||||
void loadT55xxConfig(void);
|
||||
|
||||
/// iso14443b.h
|
||||
void SimulateIso14443bTag(uint32_t pupi);
|
||||
void AcquireRawAdcSamplesIso14443b(uint32_t parameter);
|
||||
void ReadSTMemoryIso14443b(uint8_t numofblocks);
|
||||
void RAMFUNC SniffIso14443b(void);
|
||||
void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
|
||||
void SendRawCommand14443B_Ex(PacketCommandNG *c);
|
||||
void ClearFpgaShiftingRegisters(void);
|
||||
|
||||
// iso14443a.h
|
||||
void RAMFUNC SniffIso14443a(uint8_t param);
|
||||
void ReaderIso14443a(PacketCommandNG *c);
|
||||
|
||||
// Also used in iclass.c
|
||||
//bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t len, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
|
||||
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par);
|
||||
void iso14a_set_trigger(bool enable);
|
||||
// also used in emv
|
||||
//bool prepare_allocated_tag_modulation(tag_response_info_t *response_info);
|
||||
//int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len);
|
||||
|
||||
// epa.h
|
||||
void EPA_PACE_Collect_Nonce(PacketCommandNG *c);
|
||||
void EPA_PACE_Replay(PacketCommandNG *c);
|
||||
|
||||
// mifarecmd.h
|
||||
void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain);
|
||||
|
||||
void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes);
|
||||
void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain);
|
||||
void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
//void MifareUWriteBlockCompat(uint8_t arg0,uint8_t *datain);
|
||||
void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain);
|
||||
void MifareAcquireNonces(uint32_t arg0, uint32_t flags);
|
||||
void MifareChkKeys(uint8_t *datain);
|
||||
void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
|
||||
void MifareEMemClr(void);
|
||||
void MifareEMemSet(uint8_t blockno, uint8_t blockcnt, uint8_t blockwidth, uint8_t *datain);
|
||||
void MifareEMemGet(uint8_t blockno, uint8_t blockcnt);
|
||||
int MifareECardLoad(uint32_t arg0, uint32_t arg1);
|
||||
|
||||
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); // Work with "magic Chinese" card
|
||||
void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain);
|
||||
void MifareCIdent(); // is "magic chinese" card?
|
||||
|
||||
void MifareSetMod(uint8_t *datain);
|
||||
void MifareUSetPwd(uint8_t arg0, uint8_t *datain);
|
||||
void OnSuccessMagic();
|
||||
void OnErrorMagic(uint8_t reason);
|
||||
|
||||
int32_t dist_nt(uint32_t nt1, uint32_t nt2);
|
||||
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype);
|
||||
//void RAMFUNC SniffMifare(uint8_t param);
|
||||
|
||||
//desfire
|
||||
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain);
|
||||
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain);
|
||||
|
||||
// mifaredesfire.h
|
||||
bool InitDesfireCard();
|
||||
void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareDesfireGetInformation();
|
||||
void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
|
||||
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t *datain);
|
||||
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
|
||||
size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout);
|
||||
void OnSuccess();
|
||||
void OnError(uint8_t reason);
|
||||
|
||||
// desfire_crypto.h
|
||||
void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings);
|
||||
void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings);
|
||||
void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
|
||||
void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
|
||||
size_t key_block_size(const desfirekey_t key);
|
||||
size_t padded_data_length(const size_t nbytes, const size_t block_size);
|
||||
size_t maced_data_length(const desfirekey_t key, const size_t nbytes);
|
||||
size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings);
|
||||
void cmac_generate_subkeys(desfirekey_t key);
|
||||
void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);
|
||||
|
||||
// iso15693.h
|
||||
void RecordRawAdcSamplesIso15693(void);
|
||||
void AcquireRawAdcSamplesIso15693(void);
|
||||
void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg
|
||||
void SimTagIso15693(uint32_t parameter, uint8_t *uid); // simulate an ISO15693 tag - greg
|
||||
void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox
|
||||
void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data); // send arbitrary commands from CLI - atrox
|
||||
void Iso15693InitReader(void);
|
||||
|
||||
// iclass.h
|
||||
void RAMFUNC SniffIClass(void);
|
||||
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void ReaderIClass(uint8_t arg0);
|
||||
void ReaderIClass_Replay(uint8_t arg0, uint8_t *mac);
|
||||
void iClass_Authentication(uint8_t *mac);
|
||||
void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain);
|
||||
void iClass_WriteBlock(uint8_t blockno, uint8_t *data);
|
||||
void iClass_ReadBlk(uint8_t blockno);
|
||||
bool iClass_ReadBlock(uint8_t blockno, uint8_t *data, uint8_t len);
|
||||
void iClass_Dump(uint8_t blockno, uint8_t numblks);
|
||||
void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data);
|
||||
void iClass_ReadCheck(uint8_t blockno, uint8_t keytype);
|
||||
|
||||
// cmd.h
|
||||
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
|
||||
int receive_ng(PacketCommandNG *rx);
|
||||
|
||||
// util.h
|
||||
void HfSniff(int, int);
|
||||
|
||||
//felica.c
|
||||
void felica_sendraw(PacketCommandNG *c);
|
||||
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip);
|
||||
void felica_sim_lite(uint64_t uid);
|
||||
void felica_dump_lite_s();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -5,10 +5,7 @@
|
||||
#ifndef __BUZZER_H
|
||||
#define __BUZZER_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "common.h"
|
||||
|
||||
#define n_2_7khz 185
|
||||
#define note_1 956
|
||||
@@ -27,24 +24,3 @@ void Ring_ALL(uint16_t count);
|
||||
void Ring_Little_Star(uint16_t count);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
247
armsrc/cmd.c
Normal file
247
armsrc/cmd.c
Normal file
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Proxmark send and receive commands
|
||||
*
|
||||
* Copyright (c) 2012, Roel Verdult
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @file cmd.c
|
||||
* @brief
|
||||
*/
|
||||
#include "cmd.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "usart.h"
|
||||
#include "crc16.h"
|
||||
#include "string.h"
|
||||
|
||||
// Flags to tell where to add CRC on sent replies
|
||||
bool reply_with_crc_on_usb = false;
|
||||
bool reply_with_crc_on_fpc = true;
|
||||
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
|
||||
bool reply_via_fpc = false;
|
||||
bool reply_via_usb = false;
|
||||
|
||||
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
|
||||
PacketResponseOLD txcmd;
|
||||
|
||||
for (size_t i = 0; i < sizeof(PacketResponseOLD); i++)
|
||||
((uint8_t *)&txcmd)[i] = 0x00;
|
||||
|
||||
// Compose the outgoing command frame
|
||||
txcmd.cmd = cmd;
|
||||
txcmd.arg[0] = arg0;
|
||||
txcmd.arg[1] = arg1;
|
||||
txcmd.arg[2] = arg2;
|
||||
|
||||
// Add the (optional) content to the frame, with a maximum size of PM3_CMD_DATA_SIZE
|
||||
if (data && len) {
|
||||
len = MIN(len, PM3_CMD_DATA_SIZE);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
txcmd.d.asBytes[i] = ((uint8_t *)data)[i];
|
||||
}
|
||||
}
|
||||
|
||||
int resultfpc = PM3_EUNDEF;
|
||||
int resultusb = PM3_EUNDEF;
|
||||
// Send frame and make sure all bytes are transmitted
|
||||
|
||||
if (reply_via_usb) {
|
||||
resultusb = usb_write((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
|
||||
}
|
||||
|
||||
if (reply_via_fpc) {
|
||||
#ifdef WITH_FPC_USART_HOST
|
||||
resultfpc = usart_writebuffer_sync((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
|
||||
#else
|
||||
return PM3_EDEVNOTSUPP;
|
||||
#endif
|
||||
}
|
||||
// we got two results, let's prioritize the faulty one and USB over FPC.
|
||||
if (reply_via_usb && (resultusb != PM3_SUCCESS)) return resultusb;
|
||||
if (reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t len, bool ng) {
|
||||
PacketResponseNGRaw txBufferNG;
|
||||
size_t txBufferNGLen;
|
||||
|
||||
// Compose the outgoing command frame
|
||||
txBufferNG.pre.magic = RESPONSENG_PREAMBLE_MAGIC;
|
||||
txBufferNG.pre.cmd = cmd;
|
||||
txBufferNG.pre.status = status;
|
||||
txBufferNG.pre.ng = ng;
|
||||
if (len > PM3_CMD_DATA_SIZE) {
|
||||
len = PM3_CMD_DATA_SIZE;
|
||||
// overwrite status
|
||||
txBufferNG.pre.status = PM3_EOVFLOW;
|
||||
}
|
||||
txBufferNG.pre.length = len;
|
||||
|
||||
// Add the (optional) content to the frame, with a maximum size of PM3_CMD_DATA_SIZE
|
||||
if (data && len) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
txBufferNG.data[i] = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
PacketResponseNGPostamble *tx_post = (PacketResponseNGPostamble *)((uint8_t *)&txBufferNG + sizeof(PacketResponseNGPreamble) + len);
|
||||
// Note: if we send to both FPC & USB, we'll set CRC for both if any of them require CRC
|
||||
if ((reply_via_fpc && reply_with_crc_on_fpc) || ((reply_via_usb) && reply_with_crc_on_usb)) {
|
||||
uint8_t first, second;
|
||||
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(PacketResponseNGPreamble) + len, &first, &second);
|
||||
tx_post->crc = (first << 8) + second;
|
||||
} else {
|
||||
tx_post->crc = RESPONSENG_POSTAMBLE_MAGIC;
|
||||
}
|
||||
txBufferNGLen = sizeof(PacketResponseNGPreamble) + len + sizeof(PacketResponseNGPostamble);
|
||||
|
||||
int resultfpc = PM3_EUNDEF;
|
||||
int resultusb = PM3_EUNDEF;
|
||||
// Send frame and make sure all bytes are transmitted
|
||||
|
||||
if (reply_via_usb) {
|
||||
resultusb = usb_write((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
}
|
||||
if (reply_via_fpc) {
|
||||
#ifdef WITH_FPC_USART_HOST
|
||||
resultfpc = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
#else
|
||||
return PM3_EDEVNOTSUPP;
|
||||
#endif
|
||||
}
|
||||
// we got two results, let's prioritize the faulty one and USB over FPC.
|
||||
if (reply_via_usb && (resultusb != PM3_SUCCESS)) return resultusb;
|
||||
if (reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
|
||||
return reply_ng_internal(cmd, status, data, len, true);
|
||||
}
|
||||
|
||||
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
|
||||
uint16_t status = PM3_SUCCESS;
|
||||
uint64_t arg[3] = {arg0, arg1, arg2};
|
||||
if (len > PM3_CMD_DATA_SIZE - sizeof(arg)) {
|
||||
len = PM3_CMD_DATA_SIZE - sizeof(arg);
|
||||
status = PM3_EOVFLOW;
|
||||
}
|
||||
uint8_t cmddata[PM3_CMD_DATA_SIZE];
|
||||
memcpy(cmddata, arg, sizeof(arg));
|
||||
if (len && data)
|
||||
memcpy(cmddata + sizeof(arg), data, len);
|
||||
|
||||
return reply_ng_internal(cmd, status, cmddata, len + sizeof(arg), false);
|
||||
}
|
||||
|
||||
static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *data, size_t len), bool usb, bool fpc) {
|
||||
PacketCommandNGRaw rx_raw;
|
||||
size_t bytes = read_ng((uint8_t *)&rx_raw.pre, sizeof(PacketCommandNGPreamble));
|
||||
|
||||
if (bytes == 0)
|
||||
return PM3_ENODATA;
|
||||
|
||||
if (bytes != sizeof(PacketCommandNGPreamble))
|
||||
return PM3_EIO;
|
||||
|
||||
rx->magic = rx_raw.pre.magic;
|
||||
rx->ng = rx_raw.pre.ng;
|
||||
uint16_t length = rx_raw.pre.length;
|
||||
rx->cmd = rx_raw.pre.cmd;
|
||||
|
||||
if (rx->magic == COMMANDNG_PREAMBLE_MAGIC) { // New style NG command
|
||||
if (length > PM3_CMD_DATA_SIZE)
|
||||
return PM3_EOVFLOW;
|
||||
|
||||
// Get the core and variable length payload
|
||||
bytes = read_ng((uint8_t *)&rx_raw.data, length);
|
||||
if (bytes != length)
|
||||
return PM3_EIO;
|
||||
|
||||
if (rx->ng) {
|
||||
memcpy(rx->data.asBytes, rx_raw.data, length);
|
||||
rx->length = length;
|
||||
} else {
|
||||
uint64_t arg[3];
|
||||
if (length < sizeof(arg))
|
||||
return PM3_EIO;
|
||||
|
||||
memcpy(arg, rx_raw.data, sizeof(arg));
|
||||
rx->oldarg[0] = arg[0];
|
||||
rx->oldarg[1] = arg[1];
|
||||
rx->oldarg[2] = arg[2];
|
||||
memcpy(rx->data.asBytes, rx_raw.data + sizeof(arg), length - sizeof(arg));
|
||||
rx->length = length - sizeof(arg);
|
||||
}
|
||||
// Get the postamble
|
||||
bytes = read_ng((uint8_t *)&rx_raw.foopost, sizeof(PacketCommandNGPostamble));
|
||||
if (bytes != sizeof(PacketCommandNGPostamble))
|
||||
return PM3_EIO;
|
||||
|
||||
// Check CRC, accept MAGIC as placeholder
|
||||
rx->crc = rx_raw.foopost.crc;
|
||||
if (rx->crc != COMMANDNG_POSTAMBLE_MAGIC) {
|
||||
uint8_t first, second;
|
||||
compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(PacketCommandNGPreamble) + length, &first, &second);
|
||||
if ((first << 8) + second != rx->crc)
|
||||
return PM3_EIO;
|
||||
}
|
||||
reply_via_usb = usb;
|
||||
reply_via_fpc = fpc;
|
||||
} else { // Old style command
|
||||
PacketCommandOLD rx_old;
|
||||
memcpy(&rx_old, &rx_raw.pre, sizeof(PacketCommandNGPreamble));
|
||||
bytes = read_ng(((uint8_t *)&rx_old) + sizeof(PacketCommandNGPreamble), sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble));
|
||||
if (bytes != sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble))
|
||||
return PM3_EIO;
|
||||
|
||||
reply_via_usb = usb;
|
||||
reply_via_fpc = fpc;
|
||||
rx->ng = false;
|
||||
rx->magic = 0;
|
||||
rx->crc = 0;
|
||||
rx->cmd = rx_old.cmd;
|
||||
rx->oldarg[0] = rx_old.arg[0];
|
||||
rx->oldarg[1] = rx_old.arg[1];
|
||||
rx->oldarg[2] = rx_old.arg[2];
|
||||
rx->length = PM3_CMD_DATA_SIZE;
|
||||
memcpy(&rx->data, &rx_old.d.asBytes, rx->length);
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int receive_ng(PacketCommandNG *rx) {
|
||||
|
||||
// Check if there is a packet available
|
||||
if (usb_poll_validate_length())
|
||||
return receive_ng_internal(rx, usb_read_ng, true, false);
|
||||
|
||||
#ifdef WITH_FPC_USART_HOST
|
||||
// Check if there is a FPC packet available
|
||||
if (usart_rxdata_available() > 0)
|
||||
return receive_ng_internal(rx, usart_read_ng, false, true);
|
||||
#endif
|
||||
return PM3_ENODATA;
|
||||
}
|
||||
52
armsrc/cmd.h
Normal file
52
armsrc/cmd.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Proxmark send and receive commands
|
||||
*
|
||||
* Copyright (c) 2010, Roel Verdult
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @file cmd.h
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef _PROXMARK_CMD_H_
|
||||
#define _PROXMARK_CMD_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "pm3_cmd.h"
|
||||
|
||||
// Flags to tell where to add CRC on sent replies
|
||||
extern bool reply_with_crc_on_usb;
|
||||
extern bool reply_with_crc_on_fpc;
|
||||
// "Session" flag, to tell via which interface next msgs should be sent: USB and/or FPC USART
|
||||
extern bool reply_via_fpc;
|
||||
extern bool reply_via_usb;
|
||||
|
||||
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
|
||||
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int receive_ng(PacketCommandNG *rx);
|
||||
|
||||
#endif // _PROXMARK_CMD_H_
|
||||
|
||||
130
armsrc/dbprint.c
Normal file
130
armsrc/dbprint.c
Normal file
@@ -0,0 +1,130 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Mar 2006
|
||||
// Edits by Gerhard de Koning Gans, Sep 2007 (##)
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// The main application code. This is the first thing called after start.c
|
||||
// executes.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "dbprint.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "cmd.h"
|
||||
#include "printf.h"
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
//=============================================================================
|
||||
// Debug print functions, to go out over USB, to the usual PC-side client.
|
||||
//=============================================================================
|
||||
|
||||
void DbpStringEx(uint32_t flags, char *str) {
|
||||
#if DEBUG
|
||||
struct {
|
||||
uint16_t flag;
|
||||
uint8_t buf[PM3_CMD_DATA_SIZE - sizeof(uint16_t)];
|
||||
} PACKED data;
|
||||
data.flag = flags;
|
||||
uint16_t len = MIN(strlen(str), sizeof(data.buf));
|
||||
memcpy(data.buf, str, len);
|
||||
reply_ng(CMD_DEBUG_PRINT_STRING, PM3_SUCCESS, (uint8_t *)&data, sizeof(data.flag) + len);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DbpString(char *str) {
|
||||
#if DEBUG
|
||||
DbpStringEx(FLAG_LOG, str);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DbprintfEx(uint32_t flags, const char *fmt, ...) {
|
||||
#if DEBUG
|
||||
// should probably limit size here; oh well, let's just use a big buffer
|
||||
char output_string[128] = {0x00};
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
kvsprintf(fmt, output_string, 10, ap);
|
||||
va_end(ap);
|
||||
|
||||
DbpStringEx(flags, output_string);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dbprintf(const char *fmt, ...) {
|
||||
#if DEBUG
|
||||
// should probably limit size here; oh well, let's just use a big buffer
|
||||
char output_string[128] = {0x00};
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
kvsprintf(fmt, output_string, 10, ap);
|
||||
va_end(ap);
|
||||
|
||||
DbpString(output_string);
|
||||
#endif
|
||||
}
|
||||
|
||||
// prints HEX & ASCII
|
||||
void Dbhexdump(int len, uint8_t *d, bool bAsci) {
|
||||
#if DEBUG
|
||||
char ascii[9];
|
||||
|
||||
while (len > 0) {
|
||||
|
||||
int l = (len > 8) ? 8 : len;
|
||||
|
||||
memcpy(ascii, d, l);
|
||||
ascii[l] = 0;
|
||||
|
||||
// filter safe ascii
|
||||
for (int i = 0; i < l; i++) {
|
||||
if (ascii[i] < 32 || ascii[i] > 126) {
|
||||
ascii[i] = '.';
|
||||
}
|
||||
}
|
||||
|
||||
if (bAsci)
|
||||
Dbprintf("%-8s %*D", ascii, l, d, " ");
|
||||
else
|
||||
Dbprintf("%*D", l, d, " ");
|
||||
|
||||
len -= 8;
|
||||
d += 8;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_result(char *name, uint8_t *buf, size_t len) {
|
||||
|
||||
uint8_t *p = buf;
|
||||
uint16_t tmp = len & 0xFFF0;
|
||||
|
||||
for (; p - buf < tmp; p += 16) {
|
||||
Dbprintf("[%s: %02d/%02d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
|
||||
name,
|
||||
p - buf,
|
||||
len,
|
||||
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]
|
||||
);
|
||||
}
|
||||
if (len % 16 != 0) {
|
||||
char s[46] = {0};
|
||||
char *sp = s;
|
||||
for (; p - buf < len; p++) {
|
||||
sprintf(sp, "%02x ", p[0]);
|
||||
sp += 3;
|
||||
}
|
||||
Dbprintf("[%s: %02d/%02d] %s", name, p - buf, len, s);
|
||||
}
|
||||
}
|
||||
|
||||
/* useful when debugging new protocol implementations like FeliCa
|
||||
void PrintToSendBuffer(void) {
|
||||
DbpString("Printing ToSendBuffer:");
|
||||
Dbhexdump(ToSendMax, ToSend, 0);
|
||||
}
|
||||
*/
|
||||
53
armsrc/dbprint.h
Normal file
53
armsrc/dbprint.h
Normal file
@@ -0,0 +1,53 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __DBPRINT_H
|
||||
#define __DBPRINT_H
|
||||
|
||||
#include "common.h"
|
||||
#include "ansi.h"
|
||||
|
||||
#define Dbprintf_usb(...) {\
|
||||
bool tmpfpc = reply_via_fpc;\
|
||||
bool tmpusb = reply_via_usb;\
|
||||
reply_via_fpc = false;\
|
||||
reply_via_usb = true;\
|
||||
Dbprintf(__VA_ARGS__);\
|
||||
reply_via_fpc = tmpfpc;\
|
||||
reply_via_usb = tmpusb;}
|
||||
|
||||
#define Dbprintf_fpc(...) {\
|
||||
bool tmpfpc = reply_via_fpc;\
|
||||
bool tmpusb = reply_via_usb;\
|
||||
reply_via_fpc = true;\
|
||||
reply_via_usb = false;\
|
||||
Dbprintf(__VA_ARGS__);\
|
||||
reply_via_fpc = tmpfpc;\
|
||||
reply_via_usb = tmpusb;}
|
||||
|
||||
#define Dbprintf_all(...) {\
|
||||
bool tmpfpc = reply_via_fpc;\
|
||||
bool tmpusb = reply_via_usb;\
|
||||
reply_via_fpc = true;\
|
||||
reply_via_usb = true;\
|
||||
Dbprintf(__VA_ARGS__);\
|
||||
reply_via_fpc = tmpfpc;\
|
||||
reply_via_usb = tmpusb;}
|
||||
|
||||
|
||||
void DbpString(char *str);
|
||||
void DbpStringEx(uint32_t flags, char *str);
|
||||
void Dbprintf(const char *fmt, ...);
|
||||
void DbprintfEx(uint32_t flags, const char *fmt, ...);
|
||||
void Dbhexdump(int len, uint8_t *d, bool bAsci);
|
||||
void print_result(char *name, uint8_t *buf, size_t len);
|
||||
//void PrintToSendBuffer(void);
|
||||
|
||||
#endif
|
||||
@@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include "des.h"
|
||||
#include "string.h"
|
||||
|
||||
const uint8_t sbox[256] = {
|
||||
/* S-box 1 */
|
||||
|
||||
@@ -27,8 +27,7 @@
|
||||
#ifndef __DES_H_
|
||||
#define __DES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "common.h"
|
||||
|
||||
/* the FIPS 46-3 (1999-10-25) name for triple DES is triple data encryption algorithm so TDEA.
|
||||
* Also we only implement the three key mode */
|
||||
|
||||
171
armsrc/desfire.h
Normal file
171
armsrc/desfire.h
Normal file
@@ -0,0 +1,171 @@
|
||||
#ifndef __DESFIRE_H
|
||||
#define __DESFIRE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "mifare.h"
|
||||
|
||||
#define MAX_CRYPTO_BLOCK_SIZE 16
|
||||
/* Mifare DESFire EV1 Application crypto operations */
|
||||
#define APPLICATION_CRYPTO_DES 0x00
|
||||
#define APPLICATION_CRYPTO_3K3DES 0x40
|
||||
#define APPLICATION_CRYPTO_AES 0x80
|
||||
|
||||
#define MAC_LENGTH 4
|
||||
#define CMAC_LENGTH 8
|
||||
|
||||
typedef enum {
|
||||
MCD_SEND,
|
||||
MCD_RECEIVE
|
||||
} MifareCryptoDirection;
|
||||
|
||||
typedef enum {
|
||||
MCO_ENCYPHER,
|
||||
MCO_DECYPHER
|
||||
} MifareCryptoOperation;
|
||||
|
||||
#define MDCM_MASK 0x000F
|
||||
|
||||
#define CMAC_NONE 0
|
||||
|
||||
// Data send to the PICC is used to update the CMAC
|
||||
#define CMAC_COMMAND 0x010
|
||||
// Data received from the PICC is used to update the CMAC
|
||||
#define CMAC_VERIFY 0x020
|
||||
|
||||
// MAC the command (when MDCM_MACED)
|
||||
#define MAC_COMMAND 0x100
|
||||
// The command returns a MAC to verify (when MDCM_MACED)
|
||||
#define MAC_VERIFY 0x200
|
||||
|
||||
#define ENC_COMMAND 0x1000
|
||||
#define NO_CRC 0x2000
|
||||
|
||||
#define MAC_MASK 0x0F0
|
||||
#define CMAC_MACK 0xF00
|
||||
|
||||
/* Communication mode */
|
||||
#define MDCM_PLAIN 0x00
|
||||
#define MDCM_MACED 0x01
|
||||
#define MDCM_ENCIPHERED 0x03
|
||||
|
||||
/* Error code managed by the library */
|
||||
#define CRYPTO_ERROR 0x01
|
||||
|
||||
|
||||
enum DESFIRE_AUTH_SCHEME {
|
||||
AS_LEGACY,
|
||||
AS_NEW
|
||||
};
|
||||
|
||||
enum DESFIRE_CRYPTOALGO {
|
||||
T_DES = 0x00,
|
||||
T_3DES = 0x01,
|
||||
T_3K3DES = 0x02,
|
||||
T_AES = 0x03
|
||||
};
|
||||
|
||||
|
||||
#define DESFIRE_KEY(key) ((struct desfire_key *) key)
|
||||
struct desfire_key {
|
||||
enum DESFIRE_CRYPTOALGO type;
|
||||
uint8_t data[24];
|
||||
uint8_t cmac_sk1[24];
|
||||
uint8_t cmac_sk2[24];
|
||||
uint8_t aes_version;
|
||||
};
|
||||
typedef struct desfire_key *desfirekey_t;
|
||||
|
||||
#define DESFIRE(tag) ((struct desfire_tag *) tag)
|
||||
struct desfire_tag {
|
||||
iso14a_card_select_t info;
|
||||
int active;
|
||||
uint8_t last_picc_error;
|
||||
uint8_t last_internal_error;
|
||||
uint8_t last_pcd_error;
|
||||
desfirekey_t session_key;
|
||||
enum DESFIRE_AUTH_SCHEME authentication_scheme;
|
||||
uint8_t authenticated_key_no;
|
||||
|
||||
uint8_t ivect[MAX_CRYPTO_BLOCK_SIZE];
|
||||
uint8_t cmac[16];
|
||||
uint8_t *crypto_buffer;
|
||||
size_t crypto_buffer_size;
|
||||
uint32_t selected_application;
|
||||
};
|
||||
typedef struct desfire_tag *desfiretag_t;
|
||||
|
||||
|
||||
/* File types */
|
||||
enum DESFIRE_FILE_TYPES {
|
||||
MDFT_STANDARD_DATA_FILE = 0x00,
|
||||
MDFT_BACKUP_DATA_FILE = 0x01,
|
||||
MDFT_VALUE_FILE_WITH_BACKUP = 0x02,
|
||||
MDFT_LINEAR_RECORD_FILE_WITH_BACKUP = 0x03,
|
||||
MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP = 0x04
|
||||
};
|
||||
|
||||
enum DESFIRE_STATUS {
|
||||
OPERATION_OK = 0x00,
|
||||
NO_CHANGES = 0x0c,
|
||||
OUT_OF_EEPROM_ERROR = 0x0e,
|
||||
ILLEGAL_COMMAND_CODE = 0x1c,
|
||||
INTEGRITY_ERROR = 0x1e,
|
||||
NO_SUCH_KEY = 0x40,
|
||||
LENGTH_ERROR = 0x7e,
|
||||
PERMISSION_DENIED = 0x9d,
|
||||
PARAMETER_ERROR = 0x9e,
|
||||
APPLICATION_NOT_FOUND = 0xa0,
|
||||
APPL_INTEGRITY_ERROR = 0xa1,
|
||||
AUTHENTICATION_ERROR = 0xae,
|
||||
ADDITIONAL_FRAME = 0xaf,
|
||||
BOUNDARY_ERROR = 0xbe,
|
||||
PICC_INTEGRITY_ERROR = 0xc1,
|
||||
COMMAND_ABORTED = 0xca,
|
||||
PICC_DISABLED_ERROR = 0xcd,
|
||||
COUNT_ERROR = 0xce,
|
||||
DUPLICATE_ERROR = 0xde,
|
||||
EEPROM_ERROR = 0xee,
|
||||
FILE_NOT_FOUND = 0xf0,
|
||||
FILE_INTEGRITY_ERROR = 0xf1
|
||||
};
|
||||
|
||||
enum DESFIRE_CMD {
|
||||
CREATE_APPLICATION = 0xca,
|
||||
DELETE_APPLICATION = 0xda,
|
||||
GET_APPLICATION_IDS = 0x6a,
|
||||
SELECT_APPLICATION = 0x5a,
|
||||
FORMAT_PICC = 0xfc,
|
||||
GET_VERSION = 0x60,
|
||||
READ_DATA = 0xbd,
|
||||
WRITE_DATA = 0x3d,
|
||||
GET_VALUE = 0x6c,
|
||||
CREDIT = 0x0c,
|
||||
DEBIT = 0xdc,
|
||||
LIMITED_CREDIT = 0x1c,
|
||||
WRITE_RECORD = 0x3b,
|
||||
READ_RECORDS = 0xbb,
|
||||
CLEAR_RECORD_FILE = 0xeb,
|
||||
COMMIT_TRANSACTION = 0xc7,
|
||||
ABORT_TRANSACTION = 0xa7,
|
||||
GET_FREE_MEMORY = 0x6e,
|
||||
GET_FILE_IDS = 0x6f,
|
||||
GET_FILE_SETTINGS = 0xf5,
|
||||
CHANGE_FILE_SETTINGS = 0x5f,
|
||||
CREATE_STD_DATA_FILE = 0xcd,
|
||||
CREATE_BACKUP_DATA_FILE = 0xcb,
|
||||
CREATE_VALUE_FILE = 0xcc,
|
||||
CREATE_LINEAR_RECORD_FILE = 0xc1,
|
||||
CREATE_CYCLIC_RECORD_FILE = 0xc0,
|
||||
DELETE_FILE = 0xdf,
|
||||
AUTHENTICATE = 0x0a, // AUTHENTICATE_NATIVE
|
||||
AUTHENTICATE_ISO = 0x1a, // AUTHENTICATE_STANDARD
|
||||
AUTHENTICATE_AES = 0xaa,
|
||||
CHANGE_KEY_SETTINGS = 0x54,
|
||||
GET_KEY_SETTINGS = 0x45,
|
||||
CHANGE_KEY = 0xc4,
|
||||
GET_KEY_VERSION = 0x64,
|
||||
AUTHENTICATION_FRAME = 0xAF
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef __DESFIRE_CRYPTO_H
|
||||
#define __DESFIRE_CRYPTO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "crc32.h"
|
||||
#include "printf.h"
|
||||
#include "desfire.h"
|
||||
#include "iso14443a.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -25,8 +25,16 @@
|
||||
* Recommendation for Block Cipher Modes of Operation: The CMAC Mode for Authentication
|
||||
* May 2005
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include "desfire_crypto.h"
|
||||
|
||||
#include "crc32.h"
|
||||
#include "printf.h"
|
||||
#include "desfire.h"
|
||||
#include "iso14443a.h"
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
static void xor(const uint8_t *ivect, uint8_t *data, const size_t len);
|
||||
static size_t key_macing_length(desfirekey_t key);
|
||||
|
||||
18
armsrc/desfire_crypto_disabled.h
Normal file
18
armsrc/desfire_crypto_disabled.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __DESFIRE_CRYPTO_H
|
||||
#define __DESFIRE_CRYPTO_H
|
||||
|
||||
#include "common.h"
|
||||
#include "desfire.h"
|
||||
|
||||
void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings);
|
||||
void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings);
|
||||
void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
|
||||
void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
|
||||
size_t key_block_size(const desfirekey_t key);
|
||||
size_t padded_data_length(const size_t nbytes, const size_t block_size);
|
||||
size_t maced_data_length(const desfirekey_t key, const size_t nbytes);
|
||||
size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings);
|
||||
void cmac_generate_subkeys(desfirekey_t key);
|
||||
void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "desfire_key.h"
|
||||
#include "string.h"
|
||||
|
||||
static inline void update_key_schedules(desfirekey_t key);
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
#ifndef __DESFIRE_KEY_INCLUDED
|
||||
#define __DESFIRE_KEY_INCLUDED
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "iso14443a.h"
|
||||
#include "common.h"
|
||||
#include "desfire.h"
|
||||
//#include "mifare.h" // iso14a_card_select_t struct
|
||||
void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key);
|
||||
void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key);
|
||||
void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key);
|
||||
@@ -17,4 +14,5 @@ void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version,
|
||||
uint8_t Desfire_key_get_version(desfirekey_t key);
|
||||
void Desfire_key_set_version(desfirekey_t key, uint8_t version);
|
||||
void Desfire_session_key_new(const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key);
|
||||
|
||||
#endif
|
||||
|
||||
248
armsrc/emvtags.h
Normal file
248
armsrc/emvtags.h
Normal file
@@ -0,0 +1,248 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Peter Fillmore 2014
|
||||
// code derived off merloks mifare code
|
||||
//
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// structure to hold EMV card and terminal parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __EMVCARD_H
|
||||
#define __EMVCARD_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
//structure to hold received/set tag values
|
||||
//variable data inputs have length specifiers
|
||||
typedef struct {
|
||||
//ISO14443-A card stuff
|
||||
uint8_t ATQA[2]; //Answer to Request
|
||||
uint8_t UID_len;
|
||||
uint8_t UID[10];
|
||||
uint8_t SAK1; //SAK for UID 1
|
||||
uint8_t SAK2; //SAK for UID 2
|
||||
uint8_t ATS_len; //Answer to select
|
||||
uint8_t ATS[256];
|
||||
//ATS
|
||||
uint8_t TL;
|
||||
uint8_t T0;
|
||||
uint8_t TA1;
|
||||
uint8_t TB1;
|
||||
uint8_t TC1;
|
||||
uint8_t *historicalbytes;
|
||||
//PPS response
|
||||
uint8_t PPSS;
|
||||
//SFI 2 record 1
|
||||
uint8_t tag_4F_len; //length of AID
|
||||
uint8_t tag_4F[16]; //Application Identifier (AID)
|
||||
uint8_t tag_50_len; //length of application label
|
||||
uint8_t tag_50[16]; //Application Label
|
||||
uint8_t tag_56_len; //track1 length
|
||||
uint8_t tag_56[76]; //Track 1 Data
|
||||
uint8_t tag_57_len; //track2 equiv len
|
||||
uint8_t tag_57[19]; //Track 2 Equivalent Data
|
||||
uint8_t tag_5A_len; //PAN length
|
||||
uint8_t tag_5A[10]; //Application Primary Account Number (PAN)
|
||||
//uint8_t tag_6F[]; //File Control Information (FCI) Template
|
||||
//uint8_t tag_70[255]; //Record Template
|
||||
//uint8_t tag_77[]; //Response Message Template Format 2
|
||||
//uint8_t tag_80[]; //Response Message Template Format 1
|
||||
uint8_t tag_82[2]; //Application Interchange Profile AIP
|
||||
//uint8_t tag_83[]; //Command Template
|
||||
uint8_t tag_84_len;
|
||||
uint8_t tag_84[16]; //DF Name
|
||||
uint8_t tag_86_len;
|
||||
uint8_t tag_86[261]; //Issuer Script Command
|
||||
uint8_t tag_87[1]; //Application Priority Indicator
|
||||
uint8_t tag_88[1]; //Short File Identifier
|
||||
uint8_t tag_8A[2]; //Authorisation Response Code
|
||||
uint8_t tag_8C_len;
|
||||
uint8_t tag_8C[252]; //CDOL1
|
||||
uint8_t tag_8D_len;
|
||||
uint8_t tag_8D[252]; //CDOL2
|
||||
uint8_t tag_8E_len;
|
||||
uint8_t tag_8E[252]; //Cardholder Verification Method (CVM) List
|
||||
uint8_t tag_8F[1]; //Certification Authority Public Key Index
|
||||
uint8_t tag_90_len;
|
||||
uint8_t tag_90[255]; //ssuer Public Key Certificate
|
||||
uint8_t tag_92_len;
|
||||
uint8_t tag_92[255]; //Issuer Public Key Remainder
|
||||
uint8_t tag_93_len;
|
||||
uint8_t tag_93[255]; //Signed Static Application Data
|
||||
uint8_t tag_94_len;
|
||||
uint8_t tag_94[252]; //Application File Locator AFL
|
||||
uint8_t tag_95[5]; //Terminal Verification Results
|
||||
uint8_t tag_97_len;
|
||||
uint8_t tag_97[252]; //Transaction Certificate Data Object List (TDOL)
|
||||
uint8_t tag_98[20]; //Transaction Certificate (TC) Hash Value
|
||||
//assume 20 bytes, change after testing
|
||||
uint8_t tag_99_len;
|
||||
uint8_t tag_99[20]; //Transaction Personal Identification Number (PIN) Data
|
||||
uint8_t tag_9A[3]; //Transaction Date
|
||||
uint8_t tag_9B[2]; //Transaction Status Information
|
||||
uint8_t tag_9C[1]; //Transaction Type
|
||||
uint8_t tag_9D_len;
|
||||
uint8_t tag_9D[16]; //Directory Definition File
|
||||
|
||||
uint8_t tag_CD[3]; //Card Issuer Action Codes Paypass
|
||||
uint8_t tag_CE[3];
|
||||
uint8_t tag_CF[3];
|
||||
|
||||
uint8_t tag_D7[3]; //Application Control (PayPass)
|
||||
uint8_t tag_D8[2]; //Application Interchange Profile (PayPass)
|
||||
uint8_t tag_D9_len; //Application File Locator (PayPass)
|
||||
uint8_t tag_D9[16];
|
||||
uint8_t tag_DA[2]; //Static CVC3track1
|
||||
uint8_t tag_DB[2]; //Static CVC3track2
|
||||
uint8_t tag_DC[2]; //IVCVC3 CVC3track1
|
||||
uint8_t tag_DD[2]; //IVCVC3 CVC3track2
|
||||
|
||||
uint8_t tag_AF_len;
|
||||
uint8_t tag_AF[255]; //Proprietary Information
|
||||
|
||||
uint8_t tag_5F20_len;
|
||||
uint8_t tag_5F20[26]; //Cardholder Name
|
||||
uint8_t tag_5F24[3]; //Application Expiry Date
|
||||
uint8_t tag_5F25[3]; //Application Effective Date YYMMDD
|
||||
uint8_t tag_5F28[2]; //Issuer Country Code
|
||||
uint8_t tag_5F2A[2]; //Transaction Currency Code
|
||||
uint8_t tag_5F2D_len;
|
||||
uint8_t tag_5F2D[8]; //Language Preference
|
||||
uint8_t tag_5F30[2]; //Service Code
|
||||
uint8_t tag_5F34[1]; //Application Primary Account Number (PAN) Sequence Number
|
||||
uint8_t tag_5F36[2]; //ATC
|
||||
uint8_t tag_5F50_len;
|
||||
uint8_t tag_5F50[255]; //Issuer URL
|
||||
uint8_t tag_5F54_len;
|
||||
uint8_t tag_5F54[11]; //Bank Identifier Code (BIC)
|
||||
uint8_t tag_9F01[6]; //Acquirer Identifier
|
||||
uint8_t tag_9F02[6]; // Amount, Authorised (Numeric)
|
||||
uint8_t tag_9F03[6]; //Amount, Other (Numeric)
|
||||
uint8_t tag_9F04[4]; //Amount, Other (Binary)
|
||||
uint8_t tag_9F05_len;
|
||||
uint8_t tag_9F05[32]; //Application Discretionary Data
|
||||
uint8_t tag_9F06_len;
|
||||
uint8_t tag_9F06[16]; //AID terminal
|
||||
uint8_t tag_9F07[2]; //Application Usage Control
|
||||
uint8_t tag_9F08[2]; //Application Version Number
|
||||
uint8_t tag_9F09[2]; //Application Version Number
|
||||
//uint8_t tag_9F0A[2]
|
||||
uint8_t tag_9F0B_len;
|
||||
uint8_t tag_9F0B[45]; //Cardholder Name Extended
|
||||
uint8_t tag_9F0D[5]; //Issuer Action Code - Default
|
||||
uint8_t tag_9F0E[5]; //Issuer Action Code - Denial
|
||||
uint8_t tag_9F0F[5]; //Issuer Action Code - Online
|
||||
uint8_t tag_9F10_len; //Issuer Application Data
|
||||
uint8_t tag_9F10[32];
|
||||
uint8_t tag_9F11[1]; //Issuer Code Table Index
|
||||
uint8_t tag_9F12_len;
|
||||
uint8_t tag_9F12[255]; //Application Preferred Name
|
||||
uint8_t tag_9F13[2]; //Last Online Application Transaction Counter (ATC) Registerjk
|
||||
uint8_t tag_9F14[1]; //Lower Consecutive Offline Limit
|
||||
uint8_t tag_9F15[2]; //Merchant Category Code
|
||||
uint8_t tag_9F16[15]; //Merchant Identifier
|
||||
uint8_t tag_9F17[1]; //Personal Identification Number (PIN) Try Counter
|
||||
uint8_t tag_9F18[4]; //Issuer Script Identifier
|
||||
//uint8_t tag_9F19[]
|
||||
uint8_t tag_9F1A[2]; //Terminal Country Code
|
||||
uint8_t tag_9F1B[4]; //Terminal Floor Limit
|
||||
uint8_t tag_9F1C[8]; //Terminal Identification
|
||||
uint8_t tag_9F1D_len;
|
||||
uint8_t tag_9F1D[8]; //Terminal Risk Management Data
|
||||
uint8_t tag_9F1E[8]; //Interface Device (IFD) Serial Number
|
||||
uint8_t tag_9F1F_len;
|
||||
uint8_t tag_9F1F[255]; //Track 1 Discretionary Data
|
||||
uint8_t tag_9F20_len;
|
||||
uint8_t tag_9F20[255]; //Track 2 DD
|
||||
uint8_t tag_9F21[3]; //Transaction Time
|
||||
uint8_t tag_9F22[1]; //Certification Authority Public Key Index
|
||||
uint8_t tag_9F23[1]; //Upper Consecutive Offline Limit
|
||||
//uint8_t tag_9F24
|
||||
//uint8_t tag_9F25
|
||||
uint8_t tag_9F26[8]; //Application Cryptogram
|
||||
uint8_t tag_9F27[1]; //Cryptogram Information Data
|
||||
//uint8_t tag_9F28
|
||||
//uint8_t tag_9F29
|
||||
//uint8_t tag_9F2A
|
||||
//uint8_t tag_9F2B
|
||||
//uint8_t tag_9F2C
|
||||
uint8_t tag_9F2D_len;
|
||||
uint8_t tag_9F2D[255]; //Integrated Circuit Card (ICC) PIN Encipherment Public Key Certificate
|
||||
uint8_t tag_9F2E[3]; //Integrated Circuit Card (ICC) PIN Encipherment Public Key Exponent
|
||||
uint8_t tag_9F2F_len;
|
||||
uint8_t tag_9F2F[255]; //Integrated Circuit Card (ICC) PIN Encipherment Public Key Remainder
|
||||
//uint8_t tag_9F30
|
||||
//uint8_t tag_9F31
|
||||
uint8_t tag_9F32_len;
|
||||
uint8_t tag_9F32[3]; //Issuer Public Key Exponent
|
||||
uint8_t tag_9F33[3]; //Terminal Capabilities
|
||||
uint8_t tag_9F34[3]; //Cardholder Verification Method (CVM) Results
|
||||
uint8_t tag_9F35[1]; //Terminal Type
|
||||
uint8_t tag_9F36[2]; //Application Transaction Counter (ATC)
|
||||
uint8_t tag_9F37[8]; //Unpredictable Number
|
||||
uint8_t tag_9F38_len;
|
||||
uint8_t tag_9F38[255]; //PDOL
|
||||
uint8_t tag_9F39[1]; //Point-of-Service (POS) Entry Mode
|
||||
uint8_t tag_9F40[5]; //Additional Terminal Capabilities
|
||||
uint8_t tag_9F41[4]; //Transaction Sequence Counter
|
||||
uint8_t tag_9F42[2]; //Application Currency Code
|
||||
uint8_t tag_9F43[4]; //Application Reference Currency Exponent
|
||||
uint8_t tag_9F44[1]; //Application Currency Exponent
|
||||
uint8_t tag_9F45[2]; //Data Authentication Code
|
||||
uint8_t tag_9F46_len;
|
||||
uint8_t tag_9F46[255]; //ICC Public Key Certificate
|
||||
uint8_t tag_9F47_len;
|
||||
uint8_t tag_9F47[3]; //ICC Public Key Exponent
|
||||
uint8_t tag_9F48_len;
|
||||
uint8_t tag_9F48[255]; //ICC Public Key Remainder
|
||||
uint8_t tag_9F49_len;
|
||||
uint8_t tag_9F49[252];
|
||||
uint8_t tag_9F4A[1]; //SDA Tag list
|
||||
uint8_t tag_9F4B_len;
|
||||
uint8_t tag_9F4B[255]; //Signed Dynamic Application Data
|
||||
uint8_t tag_9F4C[8]; //ICC Dynamic Number
|
||||
uint8_t tag_9F4D[2]; //Log Entry
|
||||
uint8_t tag_9F4E[255]; //Merchant Name and Location
|
||||
//9F50-9F7F are payment system specific
|
||||
uint8_t tag_9F60[2]; //CVC3 track1
|
||||
uint8_t tag_9F61[2]; //CVC3 track2
|
||||
uint8_t tag_9F62[6]; //Track 1 Bit Map for CVC3 (PCVC3TRACK1)
|
||||
uint8_t tag_9F63[6]; //Track 1 Bit Map for UN and ATC (PUNATCTRACK1)
|
||||
uint8_t tag_9F64[1]; //Track 1 Number of ATC Digits (NATCTRACK1)
|
||||
uint8_t tag_9F65[2]; //rack 2 Bit Map for CVC3 (PCVC3TRACK2)
|
||||
uint8_t tag_9F66[4]; //Track 2 Bit Map for UN and ATC (PUNATCTRACK2), or VISA card type
|
||||
uint8_t tag_9F67[1]; //Track 2 Number of ATC Digits (NATCTRACK2)
|
||||
uint8_t tag_9F68_len;
|
||||
uint8_t tag_9F68[252]; //Mag Stripe CVM List
|
||||
uint8_t tag_9F69_len;
|
||||
uint8_t tag_9F69[255]; //Unpredictable Number Data Object List (UDOL)
|
||||
uint8_t tag_9F6A[8]; //Unpredictable Number (Numeric)
|
||||
uint8_t tag_9F6B_len;
|
||||
uint8_t tag_9F6B[19]; //track 2 data
|
||||
uint8_t tag_9F6C[2]; //Mag Stripe Application Version Number(Card)
|
||||
//template holders
|
||||
uint8_t tag_61_len;
|
||||
uint8_t tag_61[255]; //Application template
|
||||
uint8_t tag_6F_len;
|
||||
uint8_t tag_6F[255]; //6F template
|
||||
uint8_t tag_A5_len;
|
||||
uint8_t tag_A5[255]; //A5 template
|
||||
uint8_t tag_DFNAME_len;
|
||||
uint8_t tag_DFNAME[255]; //A5 template
|
||||
uint8_t tag_70_len;
|
||||
uint8_t tag_70[255]; //70 template
|
||||
uint8_t tag_77_len;
|
||||
uint8_t tag_77[255]; //77 template
|
||||
uint8_t tag_80_len;
|
||||
uint8_t tag_80[255]; //80 template
|
||||
uint8_t tag_91_len; //Issuer Authentication Data
|
||||
uint8_t tag_91[16];
|
||||
uint8_t tag_BF0C_len;
|
||||
uint8_t tag_BF0C[222]; //File Control Information (FCI) Issuer Discretionary Data
|
||||
uint8_t tag_DFName[16];
|
||||
uint8_t tag_DFName_len;
|
||||
} emvtags;
|
||||
|
||||
#endif //__EMVCARD_H
|
||||
10
armsrc/epa.c
10
armsrc/epa.c
@@ -12,6 +12,16 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "epa.h"
|
||||
|
||||
#include "cmd.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "iso14443a.h"
|
||||
#include "iso14443b.h"
|
||||
#include "string.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "commonutil.h"
|
||||
#include "ticks.h"
|
||||
|
||||
// Protocol and Parameter Selection Request for ISO 14443 type A cards
|
||||
// use regular (1x) speed in both directions
|
||||
// CRC is already included
|
||||
|
||||
10
armsrc/epa.h
10
armsrc/epa.h
@@ -11,9 +11,8 @@
|
||||
#ifndef __EPA_H
|
||||
#define __EPA_H
|
||||
|
||||
#include "cmd.h"
|
||||
#include "iso14443a.h"
|
||||
#include "iso14443b.h"
|
||||
#include "common.h"
|
||||
#include "pm3_cmd.h"
|
||||
|
||||
// this struct is used by EPA_Parse_CardAccess and contains info about the
|
||||
// PACE protocol supported by the chip
|
||||
@@ -23,8 +22,6 @@ typedef struct {
|
||||
uint8_t parameter_id;
|
||||
} pace_version_info_t;
|
||||
|
||||
// note: EPA_PACE_Collect_Nonce and EPA_PACE_Replay are declared in apps.h
|
||||
|
||||
// general functions
|
||||
void EPA_Finish();
|
||||
size_t EPA_Parse_CardAccess(uint8_t *data,
|
||||
@@ -37,4 +34,7 @@ int EPA_Setup();
|
||||
int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password);
|
||||
int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce);
|
||||
|
||||
void EPA_PACE_Collect_Nonce(PacketCommandNG *c);
|
||||
void EPA_PACE_Replay(PacketCommandNG *c);
|
||||
|
||||
#endif /* __EPA_H */
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "felica.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "util.h"
|
||||
#include "usb_cdc.h" // for usb_poll_validate_length
|
||||
#include "protocols.h"
|
||||
#include "crc16.h" // crc16 ccitt
|
||||
#include "fpgaloader.h"
|
||||
#include "string.h"
|
||||
#include "commonutil.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "mifare.h"
|
||||
|
||||
// FeliCa timings
|
||||
// minimum time between the start bits of consecutive transfers from reader to tag: 6800 carrier (13.56MHz) cycles
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Samy Kamkar, 2011, 2012
|
||||
// Brad antoniewicz 2011
|
||||
// Christian Herrmann, 2017
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// StandAlone Mod
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __FELICA_H
|
||||
#define __FELICA_H
|
||||
|
||||
#ifndef __LF_PROXBRUTE_H
|
||||
#define __LF_PROXBRUTE_H
|
||||
#include "common.h"
|
||||
#include "cmd.h"
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "apps.h" // debugstatements, lfops?
|
||||
void felica_sendraw(PacketCommandNG *c);
|
||||
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip);
|
||||
void felica_sim_lite(uint64_t uid);
|
||||
void felica_dump_lite_s();
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
#endif /* __LF_PROXBRUTE_H */
|
||||
#endif
|
||||
@@ -1,6 +1,11 @@
|
||||
#include "flashmem.h"
|
||||
#include "pmflash.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "string.h"
|
||||
|
||||
/* here: use NCPS2 @ PA10: */
|
||||
#define SPI_CSR_NUM 2
|
||||
#define SPI_PCS(npcs) ((~(1 << (npcs)) & 0xF) << 16)
|
||||
|
||||
@@ -28,9 +28,7 @@
|
||||
#ifndef __FLASHMEM_H
|
||||
#define __FLASHMEM_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "ticks.h"
|
||||
#include "common.h"
|
||||
|
||||
// Used Command
|
||||
#define ID 0x90
|
||||
@@ -111,7 +109,6 @@
|
||||
#define FASTFLASH (FLASHMEM_SPIBAUDRATE > FLASH_MINFAST)
|
||||
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
|
||||
void Dbprintf(const char *fmt, ...);
|
||||
|
||||
void FlashmemSetSpiBaudrate(uint32_t baudrate);
|
||||
bool FlashInit();
|
||||
|
||||
@@ -11,6 +11,15 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "fpgaloader.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "zlib.h"
|
||||
#include "fpga.h"
|
||||
#include "string.h"
|
||||
|
||||
// remember which version of the bitstream we have already downloaded to the FPGA
|
||||
static int downloaded_bitstream = 0;
|
||||
@@ -153,8 +162,7 @@ void FpgaSetupSsc(void) {
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set up DMA to receive samples from the FPGA. We will use the PDC, with
|
||||
// a single buffer as a circular buffer (so that we just chain back to
|
||||
// ourselves, not to another buffer). The stuff to manipulate those buffers
|
||||
// is in apps.h, because it should be inlined, for speed.
|
||||
// ourselves, not to another buffer).
|
||||
//-----------------------------------------------------------------------------
|
||||
bool FpgaSetupSscDma(uint8_t *buf, int len) {
|
||||
if (buf == NULL) return false;
|
||||
|
||||
@@ -12,32 +12,10 @@
|
||||
#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
|
||||
#include "common.h"
|
||||
|
||||
|
||||
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 FpgaSetupSsc(void);
|
||||
void SetupSpi(int mode);
|
||||
bool FpgaSetupSscDma(uint8_t *buf, int len);
|
||||
void Fpga_print_status(void);
|
||||
int FpgaGetCurrent(void);
|
||||
#define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
|
||||
#define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
|
||||
void SetAdcMuxFor(uint32_t whichGpio);
|
||||
|
||||
// extern and generel turn off the antenna method
|
||||
void switch_off(void);
|
||||
|
||||
// definitions for multiple FPGA config files support
|
||||
#define FPGA_BITSTREAM_LF 1
|
||||
@@ -97,4 +75,18 @@ void switch_off(void);
|
||||
#define FPGA_HF_ISO18092_FLAG_424K (2<<0) // 0010 should enable 414k mode (untested). No autodetect
|
||||
#define FPGA_HF_ISO18092_FLAG_READER (4<<0) // 0100 enables antenna power, to act as a reader instead of tag
|
||||
|
||||
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 FpgaSetupSsc(void);
|
||||
void SetupSpi(int mode);
|
||||
bool FpgaSetupSscDma(uint8_t *buf, int len);
|
||||
void Fpga_print_status(void);
|
||||
int FpgaGetCurrent(void);
|
||||
void SetAdcMuxFor(uint32_t whichGpio);
|
||||
|
||||
// extern and generel turn off the antenna method
|
||||
void switch_off(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
|
||||
#include "frozen.h"
|
||||
|
||||
//#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "nprintf.h"
|
||||
|
||||
@@ -19,21 +19,9 @@
|
||||
#ifndef CS_FROZEN_FROZEN_H_
|
||||
#define CS_FROZEN_FROZEN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(_WIN32) && _MSC_VER < 1700
|
||||
typedef int bool;
|
||||
enum { false = 0, true = 1 };
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
/* JSON token type */
|
||||
enum json_token_type {
|
||||
JSON_TYPE_INVALID = 0, /* memsetting to 0 should create INVALID value */
|
||||
@@ -322,8 +310,4 @@ void *json_next_elem(const char *s, int len, void *handle, const char *path,
|
||||
#define JSON_ENABLE_HEX !JSON_MINIMAL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* CS_FROZEN_FROZEN_H_ */
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "usb_cdc.h" // for usb_poll_validate_length
|
||||
|
||||
static void RAMFUNC optimizedSniff(void);
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iceman, Christian Herrmann, 2019
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// StandAlone Mod
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __HFSNOOP_H
|
||||
#define __HFSNOOP_H
|
||||
|
||||
#ifndef __LF_ICERUN_H
|
||||
#define __LF_ICERUN_H
|
||||
void HfSniff(int, int);
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "apps.h" // debugstatements, lfops?
|
||||
|
||||
#endif /* __LF_ICERUN_H */
|
||||
#endif
|
||||
@@ -20,12 +20,14 @@
|
||||
|
||||
#include "hitag2.h"
|
||||
#include "hitag2_crypto.h"
|
||||
#include "hitag.h"
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
|
||||
// Successful crypto auth
|
||||
static bool bCrypto;
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
#ifndef _HITAG2_H_
|
||||
#define _HITAG2_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "common.h"
|
||||
#include "hitag.h"
|
||||
|
||||
void SniffHitag(void);
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "hitag2_crypto.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
|
||||
/* Following is a modified version of cryptolib.com/ciphers/hitag2/ */
|
||||
// Software optimized 48-bit Philips/NXP Mifare Hitag2 PCF7936/46/47/52 stream cipher algorithm by I.C. Wiener 2006-2007.
|
||||
// For educational purposes only.
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
#ifndef __HITAG2_CRYPTO_H
|
||||
#define __HITAG2_CRYPTO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "string.h"
|
||||
#include "util.h"
|
||||
#include "common.h"
|
||||
|
||||
struct hitag2_tag {
|
||||
uint32_t uid;
|
||||
@@ -29,8 +24,5 @@ uint32_t _hitag2_byte(uint64_t *x);
|
||||
void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv);
|
||||
int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator_is);
|
||||
int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, uint16_t bytes, uint16_t bits) ;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,6 +13,17 @@
|
||||
|
||||
#include "hitagS.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "commonutil.h"
|
||||
#include "hitag2_crypto.h"
|
||||
|
||||
#define CRC_PRESET 0xFF
|
||||
#define CRC_POLYNOM 0x1D
|
||||
|
||||
|
||||
@@ -12,16 +12,9 @@
|
||||
#ifndef _HITAGS_H_
|
||||
#define _HITAGS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include "hitag2_crypto.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "hitag.h"
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data);
|
||||
void ReadHitagS(hitag_function htf, hitag_data *htd);
|
||||
|
||||
842
armsrc/i2c.c
Normal file
842
armsrc/i2c.c
Normal file
@@ -0,0 +1,842 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Willok, June 2018
|
||||
// Edits by Iceman, July 2018
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// The main i2c code, for communications with smart card module
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "i2c.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
|
||||
#define GPIO_RST AT91C_PIO_PA1
|
||||
#define GPIO_SCL AT91C_PIO_PA5
|
||||
#define GPIO_SDA AT91C_PIO_PA7
|
||||
|
||||
#define SCL_H HIGH(GPIO_SCL)
|
||||
#define SCL_L LOW(GPIO_SCL)
|
||||
#define SDA_H HIGH(GPIO_SDA)
|
||||
#define SDA_L LOW(GPIO_SDA)
|
||||
|
||||
#define SCL_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SCL)
|
||||
#define SDA_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SDA)
|
||||
|
||||
#define I2C_ERROR "I2C_WaitAck Error"
|
||||
|
||||
volatile unsigned long c;
|
||||
|
||||
// Direct use the loop to delay. 6 instructions loop, Masterclock 48MHz,
|
||||
// delay=1 is about 200kbps
|
||||
// timer.
|
||||
// I2CSpinDelayClk(4) = 12.31us
|
||||
// I2CSpinDelayClk(1) = 3.07us
|
||||
void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
|
||||
for (c = delay * 2; c; c--) {};
|
||||
}
|
||||
|
||||
#define I2C_DELAY_1CLK I2CSpinDelayClk(1)
|
||||
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
|
||||
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
|
||||
|
||||
#define ISO7618_MAX_FRAME 255
|
||||
|
||||
// try i2c bus recovery at 100kHz = 5us high, 5us low
|
||||
void I2C_recovery(void) {
|
||||
|
||||
DbpString("Performing i2c bus recovery");
|
||||
|
||||
// reset I2C
|
||||
SDA_H;
|
||||
SCL_H;
|
||||
|
||||
//9nth cycle acts as NACK
|
||||
for (int i = 0; i < 10; i++) {
|
||||
SCL_H;
|
||||
WaitUS(5);
|
||||
SCL_L;
|
||||
WaitUS(5);
|
||||
}
|
||||
|
||||
//a STOP signal (SDA from low to high while CLK is high)
|
||||
SDA_L;
|
||||
WaitUS(5);
|
||||
SCL_H;
|
||||
WaitUS(2);
|
||||
SDA_H;
|
||||
WaitUS(2);
|
||||
|
||||
bool isok = (SCL_read && SDA_read);
|
||||
if (!SDA_read)
|
||||
DbpString("I2C bus recovery error: SDA still LOW");
|
||||
if (!SCL_read)
|
||||
DbpString("I2C bus recovery error: SCL still LOW");
|
||||
if (isok)
|
||||
DbpString("I2C bus recovery complete");
|
||||
}
|
||||
|
||||
void I2C_init(void) {
|
||||
// Configure reset pin, close up pull up, push-pull output, default high
|
||||
AT91C_BASE_PIOA->PIO_PPUDR = GPIO_RST;
|
||||
AT91C_BASE_PIOA->PIO_MDDR = GPIO_RST;
|
||||
|
||||
// Configure I2C pin, open up, open leakage
|
||||
AT91C_BASE_PIOA->PIO_PPUER |= (GPIO_SCL | GPIO_SDA);
|
||||
AT91C_BASE_PIOA->PIO_MDER |= (GPIO_SCL | GPIO_SDA);
|
||||
|
||||
// default three lines all pull up
|
||||
AT91C_BASE_PIOA->PIO_SODR |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
|
||||
|
||||
AT91C_BASE_PIOA->PIO_OER |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
|
||||
AT91C_BASE_PIOA->PIO_PER |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
|
||||
|
||||
bool isok = (SCL_read && SDA_read);
|
||||
if (!isok)
|
||||
I2C_recovery();
|
||||
}
|
||||
|
||||
// set the reset state
|
||||
void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA) {
|
||||
if (LineRST)
|
||||
HIGH(GPIO_RST);
|
||||
else
|
||||
LOW(GPIO_RST);
|
||||
|
||||
if (LineSCK)
|
||||
HIGH(GPIO_SCL);
|
||||
else
|
||||
LOW(GPIO_SCL);
|
||||
|
||||
if (LineSDA)
|
||||
HIGH(GPIO_SDA);
|
||||
else
|
||||
LOW(GPIO_SDA);
|
||||
}
|
||||
|
||||
// Reset the SIM_Adapter, then enter the main program
|
||||
// Note: the SIM_Adapter will not enter the main program after power up. Please run this function before use SIM_Adapter.
|
||||
void I2C_Reset_EnterMainProgram(void) {
|
||||
StartTicks();
|
||||
I2C_init();
|
||||
I2C_SetResetStatus(0, 0, 0);
|
||||
WaitMS(30);
|
||||
I2C_SetResetStatus(1, 0, 0);
|
||||
WaitMS(30);
|
||||
I2C_SetResetStatus(1, 1, 1);
|
||||
WaitMS(10);
|
||||
}
|
||||
|
||||
// Reset the SIM_Adapter, then enter the bootloader program
|
||||
// Reserve for firmware update.
|
||||
void I2C_Reset_EnterBootloader(void) {
|
||||
StartTicks();
|
||||
I2C_init();
|
||||
I2C_SetResetStatus(0, 1, 1);
|
||||
WaitMS(100);
|
||||
I2C_SetResetStatus(1, 1, 1);
|
||||
WaitMS(10);
|
||||
}
|
||||
|
||||
// Wait for the clock to go High.
|
||||
bool WaitSCL_H_delay(uint32_t delay) {
|
||||
while (delay--) {
|
||||
if (SCL_read) {
|
||||
return true;
|
||||
}
|
||||
I2C_DELAY_1CLK;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5000 * 3.07us = 15350us. 15.35ms
|
||||
// 15000 * 3.07us = 46050us. 46.05ms
|
||||
bool WaitSCL_H(void) {
|
||||
return WaitSCL_H_delay(15000);
|
||||
}
|
||||
|
||||
bool WaitSCL_L_delay(uint32_t delay) {
|
||||
while (delay--) {
|
||||
if (!SCL_read) {
|
||||
return true;
|
||||
}
|
||||
I2C_DELAY_1CLK;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// 5000 * 3.07us = 15350us. 15.35ms
|
||||
bool WaitSCL_L(void) {
|
||||
return WaitSCL_L_delay(15000);
|
||||
}
|
||||
|
||||
// Wait max 1800ms or until SCL goes LOW.
|
||||
// It timeout reading response from card
|
||||
// Which ever comes first
|
||||
bool WaitSCL_L_timeout(void) {
|
||||
volatile uint16_t delay = 1800;
|
||||
while (delay--) {
|
||||
// exit on SCL LOW
|
||||
if (!SCL_read)
|
||||
return true;
|
||||
|
||||
WaitMS(1);
|
||||
}
|
||||
return (delay == 0);
|
||||
}
|
||||
|
||||
bool I2C_Start(void) {
|
||||
|
||||
I2C_DELAY_XCLK(4);
|
||||
SDA_H;
|
||||
I2C_DELAY_1CLK;
|
||||
SCL_H;
|
||||
if (!WaitSCL_H()) return false;
|
||||
|
||||
I2C_DELAY_2CLK;
|
||||
|
||||
if (!SCL_read) return false;
|
||||
if (!SDA_read) return false;
|
||||
|
||||
SDA_L;
|
||||
I2C_DELAY_2CLK;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2C_WaitForSim() {
|
||||
|
||||
// wait for data from card
|
||||
if (!WaitSCL_L_timeout())
|
||||
return false;
|
||||
|
||||
// 8051 speaks with smart card.
|
||||
// 1000*50*3.07 = 153.5ms
|
||||
// 1byte transfer == 1ms with max frame being 256bytes
|
||||
if (!WaitSCL_H_delay(10 * 1000 * 50))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// send i2c STOP
|
||||
void I2C_Stop(void) {
|
||||
SCL_L;
|
||||
I2C_DELAY_2CLK;
|
||||
SDA_L;
|
||||
I2C_DELAY_2CLK;
|
||||
SCL_H;
|
||||
I2C_DELAY_2CLK;
|
||||
if (!WaitSCL_H()) return;
|
||||
SDA_H;
|
||||
I2C_DELAY_XCLK(8);
|
||||
}
|
||||
|
||||
// Send i2c ACK
|
||||
void I2C_Ack(void) {
|
||||
SCL_L;
|
||||
I2C_DELAY_2CLK;
|
||||
SDA_L;
|
||||
I2C_DELAY_2CLK;
|
||||
SCL_H;
|
||||
I2C_DELAY_2CLK;
|
||||
if (!WaitSCL_H()) return;
|
||||
SCL_L;
|
||||
I2C_DELAY_2CLK;
|
||||
}
|
||||
|
||||
// Send i2c NACK
|
||||
void I2C_NoAck(void) {
|
||||
SCL_L;
|
||||
I2C_DELAY_2CLK;
|
||||
SDA_H;
|
||||
I2C_DELAY_2CLK;
|
||||
SCL_H;
|
||||
I2C_DELAY_2CLK;
|
||||
if (!WaitSCL_H()) return;
|
||||
SCL_L;
|
||||
I2C_DELAY_2CLK;
|
||||
}
|
||||
|
||||
bool I2C_WaitAck(void) {
|
||||
SCL_L;
|
||||
I2C_DELAY_1CLK;
|
||||
SDA_H;
|
||||
I2C_DELAY_1CLK;
|
||||
SCL_H;
|
||||
if (!WaitSCL_H())
|
||||
return false;
|
||||
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
if (SDA_read) {
|
||||
SCL_L;
|
||||
return false;
|
||||
}
|
||||
SCL_L;
|
||||
return true;
|
||||
}
|
||||
|
||||
void I2C_SendByte(uint8_t data) {
|
||||
uint8_t bits = 8;
|
||||
|
||||
while (bits--) {
|
||||
SCL_L;
|
||||
|
||||
I2C_DELAY_1CLK;
|
||||
|
||||
if (data & 0x80)
|
||||
SDA_H;
|
||||
else
|
||||
SDA_L;
|
||||
|
||||
data <<= 1;
|
||||
|
||||
I2C_DELAY_1CLK;
|
||||
|
||||
SCL_H;
|
||||
if (!WaitSCL_H())
|
||||
return;
|
||||
|
||||
I2C_DELAY_2CLK;
|
||||
}
|
||||
SCL_L;
|
||||
}
|
||||
|
||||
int16_t I2C_ReadByte(void) {
|
||||
uint8_t bits = 8, b = 0;
|
||||
|
||||
SDA_H;
|
||||
while (bits--) {
|
||||
b <<= 1;
|
||||
SCL_L;
|
||||
if (!WaitSCL_L()) return -2;
|
||||
|
||||
I2C_DELAY_1CLK;
|
||||
|
||||
SCL_H;
|
||||
if (!WaitSCL_H()) return -1;
|
||||
|
||||
I2C_DELAY_1CLK;
|
||||
if (SDA_read)
|
||||
b |= 0x01;
|
||||
}
|
||||
SCL_L;
|
||||
return b;
|
||||
}
|
||||
|
||||
// Sends one byte ( command to be written, SlaveDevice address)
|
||||
bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
|
||||
bool bBreak = true;
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return false;
|
||||
|
||||
I2C_SendByte(device_address & 0xFE);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(device_cmd);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
bBreak = false;
|
||||
} while (false);
|
||||
|
||||
I2C_Stop();
|
||||
if (bBreak) {
|
||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sends 1 byte data (Data to be written, command to be written , SlaveDevice address ).
|
||||
bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) {
|
||||
bool bBreak = true;
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return false;
|
||||
|
||||
I2C_SendByte(device_address & 0xFE);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(device_cmd);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(data);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
bBreak = false;
|
||||
} while (false);
|
||||
|
||||
I2C_Stop();
|
||||
if (bBreak) {
|
||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//Sends array of data (Array, length, command to be written , SlaveDevice address ).
|
||||
// len = uint8 (max buffer to write 256bytes)
|
||||
bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address) {
|
||||
bool bBreak = true;
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return false;
|
||||
|
||||
I2C_SendByte(device_address & 0xFE);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(device_cmd);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
while (len) {
|
||||
|
||||
I2C_SendByte(*data);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
len--;
|
||||
data++;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
bBreak = false;
|
||||
} while (false);
|
||||
|
||||
I2C_Stop();
|
||||
if (bBreak) {
|
||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// read one array of data (Data array, Readout length, command to be written , SlaveDevice address ).
|
||||
// len = uint8 (max buffer to read 256bytes)
|
||||
int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address) {
|
||||
|
||||
if (!data || len == 0)
|
||||
return 0;
|
||||
|
||||
// extra wait 500us (514us measured)
|
||||
// 200us (xx measured)
|
||||
WaitUS(600);
|
||||
bool bBreak = true;
|
||||
uint16_t readcount = 0;
|
||||
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return 0;
|
||||
|
||||
// 0xB0 / 0xC0 == i2c write
|
||||
I2C_SendByte(device_address & 0xFE);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(device_cmd);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
// 0xB1 / 0xC1 == i2c read
|
||||
I2C_Start();
|
||||
I2C_SendByte(device_address | 1);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
bBreak = false;
|
||||
} while (false);
|
||||
|
||||
if (bBreak) {
|
||||
I2C_Stop();
|
||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (len) {
|
||||
|
||||
int16_t tmp = I2C_ReadByte();
|
||||
if (tmp < 0)
|
||||
return tmp;
|
||||
|
||||
*data = (uint8_t)tmp & 0xFF;
|
||||
|
||||
len--;
|
||||
// 读取的第一个字节为后续长度
|
||||
// The first byte in response is the message length
|
||||
if (!readcount && (len > *data)) {
|
||||
len = *data;
|
||||
} else {
|
||||
data++;
|
||||
}
|
||||
readcount++;
|
||||
|
||||
// acknowledgements. After last byte send NACK.
|
||||
if (len == 0)
|
||||
I2C_NoAck();
|
||||
else
|
||||
I2C_Ack();
|
||||
}
|
||||
|
||||
I2C_Stop();
|
||||
|
||||
// return bytecount - first byte (which is length byte)
|
||||
return --readcount;
|
||||
}
|
||||
|
||||
int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address) {
|
||||
//START, 0xB0, 0x00, 0x00, START, 0xB1, xx, yy, zz, ......, STOP
|
||||
bool bBreak = true;
|
||||
uint8_t readcount = 0;
|
||||
|
||||
// sending
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return 0;
|
||||
|
||||
// 0xB0 / 0xC0 i2c write
|
||||
I2C_SendByte(device_address & 0xFE);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(msb);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(lsb);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
// 0xB1 / 0xC1 i2c read
|
||||
I2C_Start();
|
||||
I2C_SendByte(device_address | 1);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
bBreak = false;
|
||||
} while (false);
|
||||
|
||||
if (bBreak) {
|
||||
I2C_Stop();
|
||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// reading
|
||||
while (len) {
|
||||
|
||||
int16_t tmp = I2C_ReadByte();
|
||||
if (tmp < 0)
|
||||
return tmp;
|
||||
|
||||
*data = (uint8_t)tmp & 0xFF;
|
||||
|
||||
data++;
|
||||
readcount++;
|
||||
len--;
|
||||
|
||||
// acknowledgements. After last byte send NACK.
|
||||
if (len == 0)
|
||||
I2C_NoAck();
|
||||
else
|
||||
I2C_Ack();
|
||||
}
|
||||
|
||||
I2C_Stop();
|
||||
return readcount;
|
||||
}
|
||||
|
||||
bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address) {
|
||||
//START, 0xB0, 0x00, 0x00, xx, yy, zz, ......, STOP
|
||||
bool bBreak = true;
|
||||
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return false;
|
||||
|
||||
// 0xB0 == i2c write
|
||||
I2C_SendByte(device_address & 0xFE);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(msb);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
I2C_SendByte(lsb);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
while (len) {
|
||||
I2C_SendByte(*data);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
len--;
|
||||
data++;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
bBreak = false;
|
||||
} while (false);
|
||||
|
||||
I2C_Stop();
|
||||
if (bBreak) {
|
||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void I2C_print_status(void) {
|
||||
DbpString(_BLUE_("Smart card module (ISO 7816)"));
|
||||
uint8_t maj, min;
|
||||
if (I2C_get_version(&maj, &min) == PM3_SUCCESS)
|
||||
Dbprintf(" version................." _YELLOW_("v%x.%02d"), maj, min);
|
||||
else
|
||||
DbpString(" version................." _RED_("FAILED"));
|
||||
}
|
||||
|
||||
int I2C_get_version(uint8_t *maj, uint8_t *min) {
|
||||
uint8_t resp[] = {0, 0, 0, 0};
|
||||
I2C_Reset_EnterMainProgram();
|
||||
uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);
|
||||
if (len > 0) {
|
||||
*maj = resp[0];
|
||||
*min = resp[1];
|
||||
return PM3_SUCCESS;
|
||||
} else {
|
||||
return PM3_EDEVNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
// Will read response from smart card module, retries 3 times to get the data.
|
||||
bool sc_rx_bytes(uint8_t *dest, uint8_t *destlen) {
|
||||
|
||||
uint8_t i = 3;
|
||||
int16_t len = 0;
|
||||
while (i--) {
|
||||
|
||||
I2C_WaitForSim();
|
||||
|
||||
len = I2C_BufferRead(dest, *destlen, I2C_DEVICE_CMD_READ, I2C_DEVICE_ADDRESS_MAIN);
|
||||
|
||||
if (len > 1) {
|
||||
break;
|
||||
} else if (len == 1) {
|
||||
continue;
|
||||
} else if (len <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// after three
|
||||
if (len <= 1)
|
||||
return false;
|
||||
|
||||
*destlen = (uint8_t)len & 0xFF;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetATR(smart_card_atr_t *card_ptr) {
|
||||
|
||||
if (!card_ptr)
|
||||
return false;
|
||||
|
||||
card_ptr->atr_len = 0;
|
||||
memset(card_ptr->atr, 0, sizeof(card_ptr->atr));
|
||||
|
||||
|
||||
// Send ATR
|
||||
// start [C0 01] stop start C1 len aa bb cc stop]
|
||||
I2C_WriteCmd(I2C_DEVICE_CMD_GENERATE_ATR, I2C_DEVICE_ADDRESS_MAIN);
|
||||
|
||||
//wait for sim card to answer.
|
||||
// 1byte = 1ms , max frame 256bytes. SHould wait 256ms atleast just in case.
|
||||
if (!I2C_WaitForSim())
|
||||
return false;
|
||||
|
||||
// read bytes from module
|
||||
uint8_t len = sizeof(card_ptr->atr);
|
||||
if (!sc_rx_bytes(card_ptr->atr, &len))
|
||||
return false;
|
||||
|
||||
uint8_t pos_td = 1;
|
||||
if ((card_ptr->atr[1] & 0x10) == 0x10) pos_td++;
|
||||
if ((card_ptr->atr[1] & 0x20) == 0x20) pos_td++;
|
||||
if ((card_ptr->atr[1] & 0x40) == 0x40) pos_td++;
|
||||
|
||||
// T0 indicate presence T=0 vs T=1. T=1 has checksum TCK
|
||||
if ((card_ptr->atr[1] & 0x80) == 0x80) {
|
||||
|
||||
pos_td++;
|
||||
|
||||
// 1 == T1 , presence of checksum TCK
|
||||
if ((card_ptr->atr[pos_td] & 0x01) == 0x01) {
|
||||
|
||||
uint8_t chksum = 0;
|
||||
// xor property. will be zero when xored with chksum.
|
||||
for (uint8_t i = 1; i < len; ++i)
|
||||
chksum ^= card_ptr->atr[i];
|
||||
|
||||
if (chksum) {
|
||||
if (DBGLEVEL > 2) DbpString("Wrong ATR checksum");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
card_ptr->atr_len = len;
|
||||
LogTrace(card_ptr->atr, card_ptr->atr_len, 0, 0, NULL, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SmartCardAtr(void) {
|
||||
smart_card_atr_t card;
|
||||
LED_D_ON();
|
||||
clear_trace();
|
||||
set_tracing(true);
|
||||
I2C_Reset_EnterMainProgram();
|
||||
bool isOK = GetATR(&card);
|
||||
reply_old(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
|
||||
set_tracing(false);
|
||||
LEDsoff();
|
||||
}
|
||||
|
||||
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data) {
|
||||
|
||||
LED_D_ON();
|
||||
|
||||
uint8_t len = 0;
|
||||
uint8_t *resp = BigBuf_malloc(ISO7618_MAX_FRAME);
|
||||
smartcard_command_t flags = arg0;
|
||||
|
||||
if ((flags & SC_CONNECT))
|
||||
clear_trace();
|
||||
|
||||
set_tracing(true);
|
||||
|
||||
if ((flags & SC_CONNECT)) {
|
||||
|
||||
I2C_Reset_EnterMainProgram();
|
||||
|
||||
if ((flags & SC_SELECT)) {
|
||||
smart_card_atr_t card;
|
||||
bool gotATR = GetATR(&card);
|
||||
//reply_old(CMD_ACK, gotATR, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
|
||||
if (!gotATR)
|
||||
goto OUT;
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & SC_RAW) || (flags & SC_RAW_T0)) {
|
||||
|
||||
LogTrace(data, arg1, 0, 0, NULL, true);
|
||||
|
||||
// Send raw bytes
|
||||
// asBytes = A0 A4 00 00 02
|
||||
// arg1 = len 5
|
||||
bool res = I2C_BufferWrite(data, arg1, ((flags & SC_RAW_T0) ? I2C_DEVICE_CMD_SEND_T0 : I2C_DEVICE_CMD_SEND), I2C_DEVICE_ADDRESS_MAIN);
|
||||
if (!res && DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
|
||||
// read bytes from module
|
||||
len = ISO7618_MAX_FRAME;
|
||||
res = sc_rx_bytes(resp, &len);
|
||||
if (res) {
|
||||
LogTrace(resp, len, 0, 0, NULL, false);
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
OUT:
|
||||
reply_old(CMD_ACK, len, 0, 0, resp, len);
|
||||
BigBuf_free();
|
||||
set_tracing(false);
|
||||
LEDsoff();
|
||||
}
|
||||
|
||||
void SmartCardUpgrade(uint64_t arg0) {
|
||||
|
||||
LED_C_ON();
|
||||
|
||||
#define I2C_BLOCK_SIZE 128
|
||||
// write. Sector0, with 11,22,33,44
|
||||
// erase is 128bytes, and takes 50ms to execute
|
||||
|
||||
I2C_Reset_EnterBootloader();
|
||||
|
||||
bool isOK = true;
|
||||
uint16_t length = arg0, pos = 0;
|
||||
uint8_t *fwdata = BigBuf_get_addr();
|
||||
uint8_t *verfiydata = BigBuf_malloc(I2C_BLOCK_SIZE);
|
||||
|
||||
while (length) {
|
||||
|
||||
uint8_t msb = (pos >> 8) & 0xFF;
|
||||
uint8_t lsb = pos & 0xFF;
|
||||
|
||||
Dbprintf("FW %02X%02X", msb, lsb);
|
||||
|
||||
size_t size = MIN(I2C_BLOCK_SIZE, length);
|
||||
|
||||
// write
|
||||
int16_t res = I2C_WriteFW(fwdata + pos, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
|
||||
if (!res) {
|
||||
DbpString("Writing failed");
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// writing takes time.
|
||||
WaitMS(50);
|
||||
|
||||
// read
|
||||
res = I2C_ReadFW(verfiydata, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
|
||||
if (res <= 0) {
|
||||
DbpString("Reading back failed");
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// cmp
|
||||
if (0 != memcmp(fwdata + pos, verfiydata, size)) {
|
||||
DbpString("not equal data");
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
length -= size;
|
||||
pos += size;
|
||||
}
|
||||
reply_mix(CMD_ACK, isOK, pos, 0, 0, 0);
|
||||
LED_C_OFF();
|
||||
BigBuf_free();
|
||||
}
|
||||
|
||||
void SmartCardSetBaud(uint64_t arg0) {
|
||||
}
|
||||
|
||||
void SmartCardSetClock(uint64_t arg0) {
|
||||
LED_D_ON();
|
||||
set_tracing(true);
|
||||
I2C_Reset_EnterMainProgram();
|
||||
|
||||
// Send SIM CLC
|
||||
// start [C0 05 xx] stop
|
||||
I2C_WriteByte(arg0, I2C_DEVICE_CMD_SIM_CLC, I2C_DEVICE_ADDRESS_MAIN);
|
||||
|
||||
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
|
||||
set_tracing(false);
|
||||
LEDsoff();
|
||||
}
|
||||
48
armsrc/i2c.h
Normal file
48
armsrc/i2c.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef __I2C_H
|
||||
#define __I2C_H
|
||||
|
||||
#include "common.h"
|
||||
#include "mifare.h"
|
||||
|
||||
#define I2C_DEVICE_ADDRESS_BOOT 0xB0
|
||||
#define I2C_DEVICE_ADDRESS_MAIN 0xC0
|
||||
|
||||
#define I2C_DEVICE_CMD_GENERATE_ATR 0x01
|
||||
#define I2C_DEVICE_CMD_SEND 0x02
|
||||
#define I2C_DEVICE_CMD_READ 0x03
|
||||
#define I2C_DEVICE_CMD_SETBAUD 0x04
|
||||
#define I2C_DEVICE_CMD_SIM_CLC 0x05
|
||||
#define I2C_DEVICE_CMD_GETVERSION 0x06
|
||||
#define I2C_DEVICE_CMD_SEND_T0 0x07
|
||||
|
||||
void I2C_recovery(void);
|
||||
void I2C_init(void);
|
||||
void I2C_Reset(void);
|
||||
void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA);
|
||||
|
||||
void I2C_Reset_EnterMainProgram(void);
|
||||
void I2C_Reset_EnterBootloader(void);
|
||||
|
||||
bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address);
|
||||
|
||||
bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address);
|
||||
bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address);
|
||||
int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address);
|
||||
|
||||
// for firmware
|
||||
int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
||||
bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
||||
|
||||
//
|
||||
bool GetATR(smart_card_atr_t *card_ptr);
|
||||
|
||||
// generice functions
|
||||
void SmartCardAtr(void);
|
||||
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data);
|
||||
void SmartCardUpgrade(uint64_t arg0);
|
||||
void SmartCardSetBaud(uint64_t arg0);
|
||||
void SmartCardSetClock(uint64_t arg0);
|
||||
void I2C_print_status(void);
|
||||
int I2C_get_version(uint8_t *maj, uint8_t *min);
|
||||
|
||||
#endif
|
||||
130
armsrc/iclass.c
130
armsrc/iclass.c
@@ -36,15 +36,24 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "apps.h"
|
||||
#include "iclass.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
// Needed for CRC in emulation mode;
|
||||
// same construction as in ISO 14443;
|
||||
// different initial value (CRC_ICLASS)
|
||||
#include "crc16.h"
|
||||
#include "protocols.h"
|
||||
#include "optimized_cipher.h"
|
||||
#include "usb_cdc.h" // for usb_poll_validate_length
|
||||
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "string.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "protocols.h"
|
||||
#include "ticks.h"
|
||||
|
||||
static int timeout = 4096;
|
||||
static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay);
|
||||
@@ -92,21 +101,21 @@ typedef struct {
|
||||
int bitBuffer;
|
||||
int dropPosition;
|
||||
uint8_t *output;
|
||||
} tUart;
|
||||
} tUartIc;
|
||||
*/
|
||||
typedef struct {
|
||||
enum {
|
||||
DEMOD_UNSYNCD,
|
||||
DEMOD_START_OF_COMMUNICATION,
|
||||
DEMOD_START_OF_COMMUNICATION2,
|
||||
DEMOD_START_OF_COMMUNICATION3,
|
||||
DEMOD_SOF_COMPLETE,
|
||||
DEMOD_MANCHESTER_D,
|
||||
DEMOD_MANCHESTER_E,
|
||||
DEMOD_END_OF_COMMUNICATION,
|
||||
DEMOD_END_OF_COMMUNICATION2,
|
||||
DEMOD_MANCHESTER_F,
|
||||
DEMOD_ERROR_WAIT
|
||||
DEMOD_IC_UNSYNCD,
|
||||
DEMOD_IC_START_OF_COMMUNICATION,
|
||||
DEMOD_IC_START_OF_COMMUNICATION2,
|
||||
DEMOD_IC_START_OF_COMMUNICATION3,
|
||||
DEMOD_IC_SOF_COMPLETE,
|
||||
DEMOD_IC_MANCHESTER_D,
|
||||
DEMOD_IC_MANCHESTER_E,
|
||||
DEMOD_IC_END_OF_COMMUNICATION,
|
||||
DEMOD_IC_END_OF_COMMUNICATION2,
|
||||
DEMOD_IC_MANCHESTER_F,
|
||||
DEMOD_IC_ERROR_WAIT
|
||||
} state;
|
||||
int bitCount;
|
||||
int posCount;
|
||||
@@ -125,7 +134,7 @@ typedef struct {
|
||||
SUB_BOTH
|
||||
} sub;
|
||||
uint8_t *output;
|
||||
} tDemod;
|
||||
} tDemodIc;
|
||||
|
||||
/*
|
||||
* Abrasive's uart implementation
|
||||
@@ -138,8 +147,13 @@ typedef struct {
|
||||
bool frame_done;
|
||||
uint8_t *buf;
|
||||
int len;
|
||||
} tUart;
|
||||
static tUart Uart;
|
||||
} tUartIc;
|
||||
static tUartIc Uart;
|
||||
|
||||
static void OnError(uint8_t reason) {
|
||||
reply_old(CMD_ACK, 0, reason, 0, 0, 0);
|
||||
switch_off();
|
||||
}
|
||||
|
||||
static void uart_reset(void) {
|
||||
Uart.frame_done = false;
|
||||
@@ -499,8 +513,8 @@ static RAMFUNC int OutOfNDecoding(int bit) {
|
||||
//=============================================================================
|
||||
// Manchester
|
||||
//=============================================================================
|
||||
static tDemod Demod;
|
||||
static void DemodReset() {
|
||||
static tDemodIc Demod;
|
||||
static void DemodIcReset() {
|
||||
Demod.bitCount = 0;
|
||||
Demod.posCount = 0;
|
||||
Demod.syncBit = 0;
|
||||
@@ -512,11 +526,11 @@ static void DemodReset() {
|
||||
Demod.samples = 0;
|
||||
Demod.len = 0;
|
||||
Demod.sub = SUB_NONE;
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
Demod.state = DEMOD_IC_UNSYNCD;
|
||||
}
|
||||
static void DemodInit(uint8_t *data) {
|
||||
static void DemodIcInit(uint8_t *data) {
|
||||
Demod.output = data;
|
||||
DemodReset();
|
||||
DemodIcReset();
|
||||
}
|
||||
|
||||
// UART debug
|
||||
@@ -592,7 +606,7 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Demod.state == DEMOD_UNSYNCD) {
|
||||
if (Demod.state == DEMOD_IC_UNSYNCD) {
|
||||
Demod.output[Demod.len] = 0xfa;
|
||||
Demod.syncBit = 0;
|
||||
//Demod.samples = 0;
|
||||
@@ -620,7 +634,7 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) {
|
||||
|
||||
if (Demod.syncBit) {
|
||||
Demod.len = 0;
|
||||
Demod.state = DEMOD_START_OF_COMMUNICATION;
|
||||
Demod.state = DEMOD_IC_START_OF_COMMUNICATION;
|
||||
Demod.sub = SUB_FIRST_HALF;
|
||||
Demod.bitCount = 0;
|
||||
Demod.shiftReg = 0;
|
||||
@@ -644,12 +658,12 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) {
|
||||
}
|
||||
// SOF must be long burst... otherwise stay unsynced!!!
|
||||
if (!(Demod.buffer & Demod.syncBit) || !(Demod.buffer2 & Demod.syncBit))
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
Demod.state = DEMOD_IC_UNSYNCD;
|
||||
|
||||
} else {
|
||||
// SOF must be long burst... otherwise stay unsynced!!!
|
||||
if (!(Demod.buffer2 & Demod.syncBit) || !(Demod.buffer3 & Demod.syncBit)) {
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
Demod.state = DEMOD_IC_UNSYNCD;
|
||||
error = 0x88;
|
||||
uart_debug(error, bit);
|
||||
return false;
|
||||
@@ -682,74 +696,74 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) {
|
||||
}
|
||||
|
||||
if (Demod.sub == SUB_NONE) {
|
||||
if (Demod.state == DEMOD_SOF_COMPLETE) {
|
||||
if (Demod.state == DEMOD_IC_SOF_COMPLETE) {
|
||||
Demod.output[Demod.len] = 0x0f;
|
||||
Demod.len++;
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
Demod.state = DEMOD_IC_UNSYNCD;
|
||||
return true;
|
||||
} else {
|
||||
Demod.state = DEMOD_ERROR_WAIT;
|
||||
Demod.state = DEMOD_IC_ERROR_WAIT;
|
||||
error = 0x33;
|
||||
}
|
||||
}
|
||||
|
||||
switch (Demod.state) {
|
||||
|
||||
case DEMOD_START_OF_COMMUNICATION:
|
||||
case DEMOD_IC_START_OF_COMMUNICATION:
|
||||
if (Demod.sub == SUB_BOTH) {
|
||||
|
||||
Demod.state = DEMOD_START_OF_COMMUNICATION2;
|
||||
Demod.state = DEMOD_IC_START_OF_COMMUNICATION2;
|
||||
Demod.posCount = 1;
|
||||
Demod.sub = SUB_NONE;
|
||||
} else {
|
||||
Demod.output[Demod.len] = 0xab;
|
||||
Demod.state = DEMOD_ERROR_WAIT;
|
||||
Demod.state = DEMOD_IC_ERROR_WAIT;
|
||||
error = 0xd2;
|
||||
}
|
||||
break;
|
||||
|
||||
case DEMOD_START_OF_COMMUNICATION2:
|
||||
case DEMOD_IC_START_OF_COMMUNICATION2:
|
||||
if (Demod.sub == SUB_SECOND_HALF) {
|
||||
Demod.state = DEMOD_START_OF_COMMUNICATION3;
|
||||
Demod.state = DEMOD_IC_START_OF_COMMUNICATION3;
|
||||
} else {
|
||||
Demod.output[Demod.len] = 0xab;
|
||||
Demod.state = DEMOD_ERROR_WAIT;
|
||||
Demod.state = DEMOD_IC_ERROR_WAIT;
|
||||
error = 0xd3;
|
||||
}
|
||||
break;
|
||||
|
||||
case DEMOD_START_OF_COMMUNICATION3:
|
||||
case DEMOD_IC_START_OF_COMMUNICATION3:
|
||||
if (Demod.sub == SUB_SECOND_HALF) {
|
||||
Demod.state = DEMOD_SOF_COMPLETE;
|
||||
Demod.state = DEMOD_IC_SOF_COMPLETE;
|
||||
} else {
|
||||
Demod.output[Demod.len] = 0xab;
|
||||
Demod.state = DEMOD_ERROR_WAIT;
|
||||
Demod.state = DEMOD_IC_ERROR_WAIT;
|
||||
error = 0xd4;
|
||||
}
|
||||
break;
|
||||
|
||||
case DEMOD_SOF_COMPLETE:
|
||||
case DEMOD_MANCHESTER_D:
|
||||
case DEMOD_MANCHESTER_E:
|
||||
case DEMOD_IC_SOF_COMPLETE:
|
||||
case DEMOD_IC_MANCHESTER_D:
|
||||
case DEMOD_IC_MANCHESTER_E:
|
||||
// OPPOSITE FROM ISO14443 - 11110000 = 0 (1 in 14443)
|
||||
// 00001111 = 1 (0 in 14443)
|
||||
if (Demod.sub == SUB_SECOND_HALF) { // SUB_FIRST_HALF
|
||||
Demod.bitCount++;
|
||||
Demod.shiftReg = (Demod.shiftReg >> 1) ^ 0x100;
|
||||
Demod.state = DEMOD_MANCHESTER_D;
|
||||
Demod.state = DEMOD_IC_MANCHESTER_D;
|
||||
} else if (Demod.sub == SUB_FIRST_HALF) { // SUB_SECOND_HALF
|
||||
Demod.bitCount++;
|
||||
Demod.shiftReg >>= 1;
|
||||
Demod.state = DEMOD_MANCHESTER_E;
|
||||
Demod.state = DEMOD_IC_MANCHESTER_E;
|
||||
} else if (Demod.sub == SUB_BOTH) {
|
||||
Demod.state = DEMOD_MANCHESTER_F;
|
||||
Demod.state = DEMOD_IC_MANCHESTER_F;
|
||||
} else {
|
||||
Demod.state = DEMOD_ERROR_WAIT;
|
||||
Demod.state = DEMOD_IC_ERROR_WAIT;
|
||||
error = 0x55;
|
||||
}
|
||||
break;
|
||||
|
||||
case DEMOD_MANCHESTER_F:
|
||||
case DEMOD_IC_MANCHESTER_F:
|
||||
// Tag response does not need to be a complete byte!
|
||||
if (Demod.len > 0 || Demod.bitCount > 0) {
|
||||
if (Demod.bitCount > 1) { // was > 0, do not interpret last closing bit, is part of EOF
|
||||
@@ -758,22 +772,22 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) {
|
||||
Demod.len++;
|
||||
}
|
||||
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
Demod.state = DEMOD_IC_UNSYNCD;
|
||||
return true;
|
||||
} else {
|
||||
Demod.output[Demod.len] = 0xad;
|
||||
Demod.state = DEMOD_ERROR_WAIT;
|
||||
Demod.state = DEMOD_IC_ERROR_WAIT;
|
||||
error = 0x03;
|
||||
}
|
||||
break;
|
||||
|
||||
case DEMOD_ERROR_WAIT:
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
case DEMOD_IC_ERROR_WAIT:
|
||||
Demod.state = DEMOD_IC_UNSYNCD;
|
||||
break;
|
||||
|
||||
default:
|
||||
Demod.output[Demod.len] = 0xdd;
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
Demod.state = DEMOD_IC_UNSYNCD;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -818,10 +832,10 @@ static void iclass_setup_sniff(void) {
|
||||
set_tracing(true);
|
||||
|
||||
// Initialize Demod and Uart structs
|
||||
DemodInit(BigBuf_malloc(ICLASS_BUFFER_SIZE));
|
||||
DemodIcInit(BigBuf_malloc(ICLASS_BUFFER_SIZE));
|
||||
|
||||
uart_init(BigBuf_malloc(ICLASS_BUFFER_SIZE));
|
||||
//UartInit(BigBuf_malloc(ICLASS_BUFFER_SIZE));
|
||||
//UartIcInit(BigBuf_malloc(ICLASS_BUFFER_SIZE));
|
||||
|
||||
if (DBGLEVEL > 1) {
|
||||
// Print debug information about the buffer sizes
|
||||
@@ -927,7 +941,7 @@ void RAMFUNC SniffIClass(void) {
|
||||
if (Uart.frame_done) {
|
||||
time_stop = GetCountSspClk() - time_0;
|
||||
LogTrace(Uart.buf, Uart.len, time_start, time_stop, NULL, true);
|
||||
DemodReset();
|
||||
DemodIcReset();
|
||||
uart_reset();
|
||||
} else {
|
||||
time_start = GetCountSspClk() - time_0;
|
||||
@@ -959,12 +973,12 @@ void RAMFUNC SniffIClass(void) {
|
||||
if (ManchesterDecoding_iclass(foo)) {
|
||||
time_stop = GetCountSspClk() - time_0;
|
||||
LogTrace(Demod.output, Demod.len, time_start, time_stop, NULL, false);
|
||||
DemodReset();
|
||||
DemodIcReset();
|
||||
uart_reset();
|
||||
} else {
|
||||
time_start = GetCountSspClk() - time_0;
|
||||
}
|
||||
TagIsActive = (Demod.state != DEMOD_UNSYNCD);
|
||||
TagIsActive = (Demod.state != DEMOD_IC_UNSYNCD);
|
||||
}
|
||||
tag_byte = 0;
|
||||
foo = 0;
|
||||
@@ -1821,7 +1835,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples,
|
||||
bool skip = false;
|
||||
|
||||
// Setup UART/DEMOD to receive
|
||||
DemodInit(receivedResponse);
|
||||
DemodIcInit(receivedResponse);
|
||||
|
||||
if (elapsed) *elapsed = 0;
|
||||
|
||||
|
||||
29
armsrc/iclass.h
Normal file
29
armsrc/iclass.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __ICLASS_H
|
||||
#define __ICLASS_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void RAMFUNC SniffIClass(void);
|
||||
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void ReaderIClass(uint8_t arg0);
|
||||
void ReaderIClass_Replay(uint8_t arg0, uint8_t *mac);
|
||||
void iClass_Authentication(uint8_t *mac);
|
||||
void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain);
|
||||
void iClass_WriteBlock(uint8_t blockno, uint8_t *data);
|
||||
void iClass_ReadBlk(uint8_t blockno);
|
||||
bool iClass_ReadBlock(uint8_t blockno, uint8_t *data, uint8_t len);
|
||||
void iClass_Dump(uint8_t blockno, uint8_t numblks);
|
||||
void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data);
|
||||
void iClass_ReadCheck(uint8_t blockno, uint8_t keytype);
|
||||
|
||||
#endif
|
||||
@@ -11,6 +11,21 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "iso14443a.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "parity.h"
|
||||
#include "mifareutil.h"
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "protocols.h"
|
||||
|
||||
#define MAX_ISO14A_TIMEOUT 524288
|
||||
static uint32_t iso14a_timeout;
|
||||
// if iso14443a not active - transmit/receive dont try to execute
|
||||
@@ -161,7 +176,7 @@ void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par) {
|
||||
// Note 1: the bitstream may start at any time. We therefore need to sync.
|
||||
// Note 2: the interpretation of Sequence Y and Z depends on the preceding sequence.
|
||||
//-----------------------------------------------------------------------------
|
||||
static tUart Uart;
|
||||
static tUart14a Uart;
|
||||
|
||||
// Lookup-Table to decide if 4 raw bits are a modulation.
|
||||
// We accept the following:
|
||||
@@ -176,12 +191,12 @@ const bool Mod_Miller_LUT[] = {
|
||||
#define IsMillerModulationNibble1(b) (Mod_Miller_LUT[(b & 0x000000F0) >> 4])
|
||||
#define IsMillerModulationNibble2(b) (Mod_Miller_LUT[(b & 0x0000000F)])
|
||||
|
||||
tUart *GetUart() {
|
||||
tUart14a *GetUart14a() {
|
||||
return &Uart;
|
||||
}
|
||||
|
||||
void UartReset(void) {
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
void Uart14aReset(void) {
|
||||
Uart.state = STATE_14A_UNSYNCD;
|
||||
Uart.bitCount = 0;
|
||||
Uart.len = 0; // number of decoded data bytes
|
||||
Uart.parityLen = 0; // number of decoded parity bytes
|
||||
@@ -194,17 +209,17 @@ void UartReset(void) {
|
||||
Uart.syncBit = 9999;
|
||||
}
|
||||
|
||||
void UartInit(uint8_t *data, uint8_t *par) {
|
||||
void Uart14aInit(uint8_t *data, uint8_t *par) {
|
||||
Uart.output = data;
|
||||
Uart.parity = par;
|
||||
UartReset();
|
||||
Uart14aReset();
|
||||
}
|
||||
|
||||
// use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time
|
||||
RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) {
|
||||
Uart.fourBits = (Uart.fourBits << 8) | bit;
|
||||
|
||||
if (Uart.state == STATE_UNSYNCD) { // not yet synced
|
||||
if (Uart.state == STATE_14A_UNSYNCD) { // not yet synced
|
||||
Uart.syncBit = 9999; // not set
|
||||
|
||||
// 00x11111 2|3 ticks pause followed by 6|5 ticks unmodulated Sequence Z (a "0" or "start of communication")
|
||||
@@ -230,20 +245,20 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) {
|
||||
Uart.startTime = non_real_time ? non_real_time : (GetCountSspClk() & 0xfffffff8);
|
||||
Uart.startTime -= Uart.syncBit;
|
||||
Uart.endTime = Uart.startTime;
|
||||
Uart.state = STATE_START_OF_COMMUNICATION;
|
||||
Uart.state = STATE_14A_START_OF_COMMUNICATION;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (IsMillerModulationNibble1(Uart.fourBits >> Uart.syncBit)) {
|
||||
if (IsMillerModulationNibble2(Uart.fourBits >> Uart.syncBit)) { // Modulation in both halves - error
|
||||
UartReset();
|
||||
Uart14aReset();
|
||||
} else { // Modulation in first half = Sequence Z = logic "0"
|
||||
if (Uart.state == STATE_MILLER_X) { // error - must not follow after X
|
||||
UartReset();
|
||||
if (Uart.state == STATE_14A_MILLER_X) { // error - must not follow after X
|
||||
Uart14aReset();
|
||||
} else {
|
||||
Uart.bitCount++;
|
||||
Uart.shiftReg = (Uart.shiftReg >> 1); // add a 0 to the shiftreg
|
||||
Uart.state = STATE_MILLER_Z;
|
||||
Uart.state = STATE_14A_MILLER_Z;
|
||||
Uart.endTime = Uart.startTime + 8 * (9 * Uart.len + Uart.bitCount + 1) - 6;
|
||||
if (Uart.bitCount >= 9) { // if we decoded a full byte (including parity)
|
||||
Uart.output[Uart.len++] = (Uart.shiftReg & 0xff);
|
||||
@@ -262,7 +277,7 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) {
|
||||
if (IsMillerModulationNibble2(Uart.fourBits >> Uart.syncBit)) { // Modulation second half = Sequence X = logic "1"
|
||||
Uart.bitCount++;
|
||||
Uart.shiftReg = (Uart.shiftReg >> 1) | 0x100; // add a 1 to the shiftreg
|
||||
Uart.state = STATE_MILLER_X;
|
||||
Uart.state = STATE_14A_MILLER_X;
|
||||
Uart.endTime = Uart.startTime + 8 * (9 * Uart.len + Uart.bitCount + 1) - 2;
|
||||
if (Uart.bitCount >= 9) { // if we decoded a full byte (including parity)
|
||||
Uart.output[Uart.len++] = (Uart.shiftReg & 0xff);
|
||||
@@ -276,8 +291,8 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) {
|
||||
}
|
||||
}
|
||||
} else { // no modulation in both halves - Sequence Y
|
||||
if (Uart.state == STATE_MILLER_Z || Uart.state == STATE_MILLER_Y) { // Y after logic "0" - End of Communication
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
if (Uart.state == STATE_14A_MILLER_Z || Uart.state == STATE_14A_MILLER_Y) { // Y after logic "0" - End of Communication
|
||||
Uart.state = STATE_14A_UNSYNCD;
|
||||
Uart.bitCount--; // last "0" was part of EOC sequence
|
||||
Uart.shiftReg <<= 1; // drop it
|
||||
if (Uart.bitCount > 0) { // if we decoded some bits
|
||||
@@ -294,15 +309,15 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) {
|
||||
if (Uart.len) {
|
||||
return true; // we are finished with decoding the raw data sequence
|
||||
} else {
|
||||
UartReset(); // Nothing received - start over
|
||||
Uart14aReset(); // Nothing received - start over
|
||||
}
|
||||
}
|
||||
if (Uart.state == STATE_START_OF_COMMUNICATION) { // error - must not follow directly after SOC
|
||||
UartReset();
|
||||
if (Uart.state == STATE_14A_START_OF_COMMUNICATION) { // error - must not follow directly after SOC
|
||||
Uart14aReset();
|
||||
} else { // a logic "0"
|
||||
Uart.bitCount++;
|
||||
Uart.shiftReg = (Uart.shiftReg >> 1); // add a 0 to the shiftreg
|
||||
Uart.state = STATE_MILLER_Y;
|
||||
Uart.state = STATE_14A_MILLER_Y;
|
||||
if (Uart.bitCount >= 9) { // if we decoded a full byte (including parity)
|
||||
Uart.output[Uart.len++] = (Uart.shiftReg & 0xff);
|
||||
Uart.parityBits <<= 1; // make room for the parity bit
|
||||
@@ -336,7 +351,7 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) {
|
||||
// 8 ticks modulated: A collision. Save the collision position and treat as Sequence D
|
||||
// Note 1: the bitstream may start at any time. We therefore need to sync.
|
||||
// Note 2: parameter offset is used to determine the position of the parity bits (required for the anticollision command only)
|
||||
tDemod Demod;
|
||||
tDemod14a Demod;
|
||||
|
||||
// Lookup-Table to decide if 4 raw bits are a modulation.
|
||||
// We accept three or four "1" in any position
|
||||
@@ -348,11 +363,11 @@ const bool Mod_Manchester_LUT[] = {
|
||||
#define IsManchesterModulationNibble1(b) (Mod_Manchester_LUT[(b & 0x00F0) >> 4])
|
||||
#define IsManchesterModulationNibble2(b) (Mod_Manchester_LUT[(b & 0x000F)])
|
||||
|
||||
tDemod *GetDemod() {
|
||||
tDemod14a *GetDemod14a() {
|
||||
return &Demod;
|
||||
}
|
||||
void DemodReset(void) {
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
void Demod14aReset(void) {
|
||||
Demod.state = DEMOD_14A_UNSYNCD;
|
||||
Demod.len = 0; // number of decoded data bytes
|
||||
Demod.parityLen = 0;
|
||||
Demod.shiftReg = 0; // shiftreg to hold decoded data bits
|
||||
@@ -367,17 +382,17 @@ void DemodReset(void) {
|
||||
Demod.samples = 0;
|
||||
}
|
||||
|
||||
void DemodInit(uint8_t *data, uint8_t *par) {
|
||||
void Demod14aInit(uint8_t *data, uint8_t *par) {
|
||||
Demod.output = data;
|
||||
Demod.parity = par;
|
||||
DemodReset();
|
||||
Demod14aReset();
|
||||
}
|
||||
|
||||
// use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time
|
||||
RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time) {
|
||||
Demod.twoBits = (Demod.twoBits << 8) | bit;
|
||||
|
||||
if (Demod.state == DEMOD_UNSYNCD) {
|
||||
if (Demod.state == DEMOD_14A_UNSYNCD) {
|
||||
|
||||
if (Demod.highCnt < 2) { // wait for a stable unmodulated signal
|
||||
if (Demod.twoBits == 0x0000) {
|
||||
@@ -399,7 +414,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t
|
||||
Demod.startTime = non_real_time ? non_real_time : (GetCountSspClk() & 0xfffffff8);
|
||||
Demod.startTime -= Demod.syncBit;
|
||||
Demod.bitCount = offset; // number of decoded data bits
|
||||
Demod.state = DEMOD_MANCHESTER_DATA;
|
||||
Demod.state = DEMOD_14A_MANCHESTER_DATA;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -455,7 +470,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t
|
||||
if (Demod.len) {
|
||||
return true; // we are finished with decoding the raw data sequence
|
||||
} else { // nothing received. Start over
|
||||
DemodReset();
|
||||
Demod14aReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -468,7 +483,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t
|
||||
RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) {
|
||||
Demod.twoBits = (Demod.twoBits << 8) | bit;
|
||||
|
||||
if (Demod.state == DEMOD_UNSYNCD) {
|
||||
if (Demod.state == DEMOD_14A_UNSYNCD) {
|
||||
|
||||
if (Demod.highCnt < 2) { // wait for a stable unmodulated signal
|
||||
if (Demod.twoBits == 0x0000) {
|
||||
@@ -491,7 +506,7 @@ RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) {
|
||||
Demod.startTime -= Demod.syncBit;
|
||||
Demod.bitCount = 1; // number of decoded data bits
|
||||
Demod.shiftReg = 1;
|
||||
Demod.state = DEMOD_MANCHESTER_DATA;
|
||||
Demod.state = DEMOD_14A_MANCHESTER_DATA;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -529,7 +544,7 @@ RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) {
|
||||
if (Demod.len) {
|
||||
return true; // we are finished with decoding the raw data sequence
|
||||
} else { // nothing received. Start over
|
||||
DemodReset();
|
||||
Demod14aReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -582,10 +597,10 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
bool ReaderIsActive = false;
|
||||
|
||||
// Set up the demodulator for tag -> reader responses.
|
||||
DemodInit(receivedResp, receivedRespPar);
|
||||
Demod14aInit(receivedResp, receivedRespPar);
|
||||
|
||||
// Set up the demodulator for the reader -> tag commands
|
||||
UartInit(receivedCmd, receivedCmdPar);
|
||||
Uart14aInit(receivedCmd, receivedCmdPar);
|
||||
|
||||
DbpString("Starting to sniff");
|
||||
|
||||
@@ -659,13 +674,13 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
true)) break;
|
||||
}
|
||||
/* ready to receive another command. */
|
||||
UartReset();
|
||||
Uart14aReset();
|
||||
/* reset the demod code, which might have been */
|
||||
/* false-triggered by the commands from the reader. */
|
||||
DemodReset();
|
||||
Demod14aReset();
|
||||
LED_B_OFF();
|
||||
}
|
||||
ReaderIsActive = (Uart.state != STATE_UNSYNCD);
|
||||
ReaderIsActive = (Uart.state != STATE_14A_UNSYNCD);
|
||||
}
|
||||
|
||||
// no need to try decoding tag data if the reader is sending - and we cannot afford the time
|
||||
@@ -684,13 +699,13 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
if ((!triggered) && (param & 0x01)) triggered = true;
|
||||
|
||||
// ready to receive another response.
|
||||
DemodReset();
|
||||
Demod14aReset();
|
||||
// reset the Miller decoder including its (now outdated) input buffer
|
||||
UartReset();
|
||||
//UartInit(receivedCmd, receivedCmdPar);
|
||||
Uart14aReset();
|
||||
//Uart14aInit(receivedCmd, receivedCmdPar);
|
||||
LED_C_OFF();
|
||||
}
|
||||
TagIsActive = (Demod.state != DEMOD_UNSYNCD);
|
||||
TagIsActive = (Demod.state != DEMOD_14A_UNSYNCD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -830,7 +845,7 @@ static bool GetIso14443aCommandFromReader(uint8_t *received, uint8_t *par, int *
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
||||
|
||||
// Now run a `software UART` on the stream of incoming samples.
|
||||
UartInit(received, par);
|
||||
Uart14aInit(received, par);
|
||||
|
||||
// clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
@@ -1795,7 +1810,7 @@ int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *par) {
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
||||
|
||||
// Now run a 'software UART' on the stream of incoming samples.
|
||||
UartInit(received, par);
|
||||
Uart14aInit(received, par);
|
||||
|
||||
// Clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
@@ -2024,7 +2039,7 @@ bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint8_t *rec
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN);
|
||||
|
||||
// Now get the answer from the card
|
||||
DemodInit(receivedResponse, NULL);
|
||||
Demod14aInit(receivedResponse, NULL);
|
||||
|
||||
// clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
@@ -2073,7 +2088,7 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receive
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN);
|
||||
|
||||
// Now get the answer from the card
|
||||
DemodInit(receivedResponse, receivedResponsePar);
|
||||
Demod14aInit(receivedResponse, receivedResponsePar);
|
||||
|
||||
// clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
@@ -2089,7 +2104,7 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receive
|
||||
if (ManchesterDecoding(b, offset, 0)) {
|
||||
NextTransferTime = MAX(NextTransferTime, Demod.endTime - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / 16 + FRAME_DELAY_TIME_PICC_TO_PCD);
|
||||
return true;
|
||||
} else if (c++ > timeout && Demod.state == DEMOD_UNSYNCD) {
|
||||
} else if (c++ > timeout && Demod.state == DEMOD_14A_UNSYNCD) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2499,8 +2514,8 @@ void iso14443a_setup(uint8_t fpga_minor_mode) {
|
||||
StartCountSspClk();
|
||||
|
||||
// Prepare the demodulation functions
|
||||
DemodReset();
|
||||
UartReset();
|
||||
Demod14aReset();
|
||||
Uart14aReset();
|
||||
NextTransferTime = 2 * DELAY_ARM2AIR_AS_READER;
|
||||
iso14a_set_timeout(1060); // 106 * 10ms default
|
||||
|
||||
|
||||
@@ -13,21 +13,9 @@
|
||||
#ifndef __ISO14443A_H
|
||||
#define __ISO14443A_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include "mifare.h" // struct
|
||||
#include "pm3_cmd.h"
|
||||
#include "cmd.h"
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "crc16.h"
|
||||
#include "mifaresniff.h"
|
||||
#include "crapto1/crapto1.h"
|
||||
#include "mifareutil.h"
|
||||
#include "parity.h"
|
||||
#include "mifare.h" // structs
|
||||
|
||||
// When the PM acts as tag and is receiving it takes
|
||||
// 2 ticks delay in the RF part (for the first falling edge),
|
||||
@@ -42,11 +30,11 @@ extern "C" {
|
||||
|
||||
typedef struct {
|
||||
enum {
|
||||
DEMOD_UNSYNCD,
|
||||
// DEMOD_HALF_SYNCD,
|
||||
// DEMOD_MOD_FIRST_HALF,
|
||||
// DEMOD_NOMOD_FIRST_HALF,
|
||||
DEMOD_MANCHESTER_DATA
|
||||
DEMOD_14A_UNSYNCD,
|
||||
// DEMOD_14A_HALF_SYNCD,
|
||||
// DEMOD_14A_MOD_FIRST_HALF,
|
||||
// DEMOD_14A_NOMOD_FIRST_HALF,
|
||||
DEMOD_14A_MANCHESTER_DATA
|
||||
} state;
|
||||
uint16_t twoBits;
|
||||
uint16_t highCnt;
|
||||
@@ -61,7 +49,7 @@ typedef struct {
|
||||
uint32_t startTime, endTime;
|
||||
uint8_t *output;
|
||||
uint8_t *parity;
|
||||
} tDemod;
|
||||
} tDemod14a;
|
||||
/*
|
||||
typedef enum {
|
||||
MOD_NOMOD = 0,
|
||||
@@ -73,11 +61,11 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
enum {
|
||||
STATE_UNSYNCD,
|
||||
STATE_START_OF_COMMUNICATION,
|
||||
STATE_MILLER_X,
|
||||
STATE_MILLER_Y,
|
||||
STATE_MILLER_Z,
|
||||
STATE_14A_UNSYNCD,
|
||||
STATE_14A_START_OF_COMMUNICATION,
|
||||
STATE_14A_MILLER_X,
|
||||
STATE_14A_MILLER_Y,
|
||||
STATE_14A_MILLER_Z,
|
||||
// DROP_NONE,
|
||||
// DROP_FIRST_HALF,
|
||||
} state;
|
||||
@@ -93,7 +81,7 @@ typedef struct {
|
||||
uint32_t startTime, endTime;
|
||||
uint8_t *output;
|
||||
uint8_t *parity;
|
||||
} tUart;
|
||||
} tUart14a;
|
||||
|
||||
#ifndef AddCrc14A
|
||||
# define AddCrc14A(data, len) compute_crc(CRC_14443_A, (data), (len), (data)+(len), (data)+(len)+1)
|
||||
@@ -109,12 +97,12 @@ typedef struct {
|
||||
|
||||
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par);
|
||||
|
||||
tDemod *GetDemod(void);
|
||||
void DemodReset(void);
|
||||
void DemodInit(uint8_t *data, uint8_t *par);
|
||||
tUart *GetUart(void);
|
||||
void UartReset(void);
|
||||
void UartInit(uint8_t *data, uint8_t *par);
|
||||
tDemod14a *GetDemod14a(void);
|
||||
void Demod14aReset(void);
|
||||
void Demod14aInit(uint8_t *data, uint8_t *par);
|
||||
tUart14a *GetUart14a(void);
|
||||
void Uart14aReset(void);
|
||||
void Uart14aInit(uint8_t *data, uint8_t *par);
|
||||
RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time);
|
||||
RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time);
|
||||
|
||||
@@ -153,8 +141,4 @@ void DetectNACKbug(void);
|
||||
|
||||
bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint8_t *received_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ISO14443A_H */
|
||||
|
||||
@@ -10,6 +10,20 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "iso14443b.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "common.h" // access to global variable: DBGLEVEL
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "crc16.h"
|
||||
#include "protocols.h"
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "cmd.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "commonutil.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
|
||||
#ifndef FWT_TIMEOUT_14B
|
||||
// defaults to 2000ms
|
||||
# define FWT_TIMEOUT_14B 35312
|
||||
@@ -52,7 +66,7 @@ static uint32_t iso14b_timeout = FWT_TIMEOUT_14B;
|
||||
|
||||
//=============================================================================
|
||||
// An ISO 14443 Type B tag. We listen for commands from the reader, using
|
||||
// a UART kind of thing that's implemented in software. When we get a
|
||||
// a kind of thing that's implemented in software. When we get a
|
||||
// frame (i.e., a group of bytes between SOF and EOF), we check the CRC.
|
||||
// If it's good, then we can do something appropriate with it, and send
|
||||
// a response.
|
||||
@@ -60,14 +74,14 @@ static uint32_t iso14b_timeout = FWT_TIMEOUT_14B;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The software UART that receives commands from the reader, and its state variables.
|
||||
// The software that receives commands from the reader, and its state variables.
|
||||
//-----------------------------------------------------------------------------
|
||||
static struct {
|
||||
enum {
|
||||
STATE_UNSYNCD,
|
||||
STATE_GOT_FALLING_EDGE_OF_SOF,
|
||||
STATE_AWAITING_START_BIT,
|
||||
STATE_RECEIVING_DATA
|
||||
STATE_14B_UNSYNCD,
|
||||
STATE_14B_GOT_FALLING_EDGE_OF_SOF,
|
||||
STATE_14B_AWAITING_START_BIT,
|
||||
STATE_14B_RECEIVING_DATA
|
||||
} state;
|
||||
uint16_t shiftReg;
|
||||
int bitCnt;
|
||||
@@ -77,8 +91,8 @@ static struct {
|
||||
uint8_t *output;
|
||||
} Uart;
|
||||
|
||||
static void UartReset() {
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
static void Uart14bReset() {
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
Uart.shiftReg = 0;
|
||||
Uart.bitCnt = 0;
|
||||
Uart.byteCnt = 0;
|
||||
@@ -86,9 +100,9 @@ static void UartReset() {
|
||||
Uart.posCnt = 0;
|
||||
}
|
||||
|
||||
static void UartInit(uint8_t *data) {
|
||||
static void Uart14bInit(uint8_t *data) {
|
||||
Uart.output = data;
|
||||
UartReset();
|
||||
Uart14bReset();
|
||||
// memset(Uart.output, 0x00, MAX_FRAME_SIZE);
|
||||
}
|
||||
|
||||
@@ -120,7 +134,7 @@ static struct {
|
||||
} Demod;
|
||||
|
||||
// Clear out the state of the "UART" that receives from the tag.
|
||||
static void DemodReset() {
|
||||
static void Demod14bReset() {
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
Demod.bitCount = 0;
|
||||
Demod.posCount = 0;
|
||||
@@ -133,9 +147,9 @@ static void DemodReset() {
|
||||
Demod.endTime = 0;
|
||||
}
|
||||
|
||||
static void DemodInit(uint8_t *data) {
|
||||
static void Demod14bInit(uint8_t *data) {
|
||||
Demod.output = data;
|
||||
DemodReset();
|
||||
Demod14bReset();
|
||||
// memset(Demod.output, 0x00, MAX_FRAME_SIZE);
|
||||
}
|
||||
|
||||
@@ -315,16 +329,16 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
|
||||
*/
|
||||
static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) {
|
||||
switch (Uart.state) {
|
||||
case STATE_UNSYNCD:
|
||||
case STATE_14B_UNSYNCD:
|
||||
if (!bit) {
|
||||
// we went low, so this could be the beginning of an SOF
|
||||
Uart.state = STATE_GOT_FALLING_EDGE_OF_SOF;
|
||||
Uart.state = STATE_14B_GOT_FALLING_EDGE_OF_SOF;
|
||||
Uart.posCnt = 0;
|
||||
Uart.bitCnt = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_GOT_FALLING_EDGE_OF_SOF:
|
||||
case STATE_14B_GOT_FALLING_EDGE_OF_SOF:
|
||||
Uart.posCnt++;
|
||||
if (Uart.posCnt == 2) { // sample every 4 1/fs in the middle of a bit
|
||||
if (bit) {
|
||||
@@ -333,11 +347,11 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) {
|
||||
// zeros that it's a valid SOF
|
||||
Uart.posCnt = 0;
|
||||
Uart.byteCnt = 0;
|
||||
Uart.state = STATE_AWAITING_START_BIT;
|
||||
Uart.state = STATE_14B_AWAITING_START_BIT;
|
||||
LED_A_ON(); // Indicate we got a valid SOF
|
||||
} else {
|
||||
// didn't stay down long enough before going high, error
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
}
|
||||
} else {
|
||||
// do nothing, keep waiting
|
||||
@@ -348,27 +362,27 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) {
|
||||
if (Uart.bitCnt > 12) {
|
||||
// Give up if we see too many zeros without a one, too.
|
||||
LED_A_OFF();
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_AWAITING_START_BIT:
|
||||
case STATE_14B_AWAITING_START_BIT:
|
||||
Uart.posCnt++;
|
||||
if (bit) {
|
||||
if (Uart.posCnt > 50 / 2) { // max 57us between characters = 49 1/fs, max 3 etus after low phase of SOF = 24 1/fs
|
||||
// stayed high for too long between characters, error
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
}
|
||||
} else {
|
||||
// falling edge, this starts the data byte
|
||||
Uart.posCnt = 0;
|
||||
Uart.bitCnt = 0;
|
||||
Uart.shiftReg = 0;
|
||||
Uart.state = STATE_RECEIVING_DATA;
|
||||
Uart.state = STATE_14B_RECEIVING_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_RECEIVING_DATA:
|
||||
case STATE_14B_RECEIVING_DATA:
|
||||
Uart.posCnt++;
|
||||
if (Uart.posCnt == 2) {
|
||||
// time to sample a bit
|
||||
@@ -391,30 +405,30 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) {
|
||||
if (Uart.byteCnt >= Uart.byteCntMax) {
|
||||
// Buffer overflowed, give up
|
||||
LED_A_OFF();
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
} else {
|
||||
// so get the next byte now
|
||||
Uart.posCnt = 0;
|
||||
Uart.state = STATE_AWAITING_START_BIT;
|
||||
Uart.state = STATE_14B_AWAITING_START_BIT;
|
||||
}
|
||||
} else if (Uart.shiftReg == 0x000) {
|
||||
// this is an EOF byte
|
||||
LED_A_OFF(); // Finished receiving
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
if (Uart.byteCnt != 0)
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// this is an error
|
||||
LED_A_OFF();
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
LED_A_OFF();
|
||||
Uart.state = STATE_UNSYNCD;
|
||||
Uart.state = STATE_14B_UNSYNCD;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
@@ -454,7 +468,7 @@ static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) {
|
||||
}
|
||||
*/
|
||||
// Now run a `software UART' on the stream of incoming samples.
|
||||
UartInit(received);
|
||||
Uart14bInit(received);
|
||||
|
||||
uint8_t mask;
|
||||
while (!BUTTON_PRESS()) {
|
||||
@@ -949,7 +963,7 @@ static void GetTagSamplesFor14443bDemod() {
|
||||
BigBuf_free();
|
||||
|
||||
// Set up the demodulator for tag -> reader responses.
|
||||
DemodInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
Demod14bInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
|
||||
// The DMA buffer, used to stream samples from the FPGA
|
||||
int8_t *dmaBuf = (int8_t *) BigBuf_malloc(ISO14443B_DMA_BUFFER_SIZE);
|
||||
@@ -1306,8 +1320,8 @@ void iso14443b_setup() {
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
// Initialize Demod and Uart structs
|
||||
DemodInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
UartInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
Demod14bInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
Uart14bInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
@@ -1411,8 +1425,8 @@ static void iso1444b_setup_sniff(void) {
|
||||
set_tracing(true);
|
||||
|
||||
// Initialize Demod and Uart structs
|
||||
DemodInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
UartInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
Demod14bInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
Uart14bInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
|
||||
if (DBGLEVEL > 1) {
|
||||
// Print debug information about the buffer sizes
|
||||
@@ -1502,8 +1516,8 @@ void RAMFUNC SniffIso14443b(void) {
|
||||
if (Handle14443bReaderUartBit(ci & 0x01)) {
|
||||
time_stop = GetCountSspClk() - time_0;
|
||||
LogTrace(Uart.output, Uart.byteCnt, time_start, time_stop, NULL, true);
|
||||
UartReset();
|
||||
DemodReset();
|
||||
Uart14bReset();
|
||||
Demod14bReset();
|
||||
} else {
|
||||
time_start = GetCountSspClk() - time_0;
|
||||
}
|
||||
@@ -1511,12 +1525,12 @@ void RAMFUNC SniffIso14443b(void) {
|
||||
if (Handle14443bReaderUartBit(cq & 0x01)) {
|
||||
time_stop = GetCountSspClk() - time_0;
|
||||
LogTrace(Uart.output, Uart.byteCnt, time_start, time_stop, NULL, true);
|
||||
UartReset();
|
||||
DemodReset();
|
||||
Uart14bReset();
|
||||
Demod14bReset();
|
||||
} else {
|
||||
time_start = GetCountSspClk() - time_0;
|
||||
}
|
||||
ReaderIsActive = (Uart.state > STATE_GOT_FALLING_EDGE_OF_SOF);
|
||||
ReaderIsActive = (Uart.state > STATE_14B_GOT_FALLING_EDGE_OF_SOF);
|
||||
}
|
||||
|
||||
// no need to try decoding tag data if the reader is sending - and we cannot afford the time
|
||||
@@ -1527,8 +1541,8 @@ void RAMFUNC SniffIso14443b(void) {
|
||||
if (Handle14443bTagSamplesDemod(ci, cq)) {
|
||||
time_stop = GetCountSspClk() - time_0;
|
||||
LogTrace(Demod.output, Demod.len, time_start, time_stop, NULL, false);
|
||||
UartReset();
|
||||
DemodReset();
|
||||
Uart14bReset();
|
||||
Demod14bReset();
|
||||
} else {
|
||||
time_start = GetCountSspClk() - time_0;
|
||||
}
|
||||
|
||||
@@ -13,18 +13,10 @@
|
||||
#ifndef __ISO14443B_H
|
||||
#define __ISO14443B_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "common.h"
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "common.h" // access to global variable: DBGLEVEL
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "crc16.h"
|
||||
#include "mifare.h"
|
||||
#include "protocols.h"
|
||||
#include "pm3_cmd.h"
|
||||
|
||||
#ifndef AddCrc14A
|
||||
# define AddCrc14A(data, len) compute_crc(CRC_14443_A, (data), (len), (data)+(len), (data)+(len)+1)
|
||||
@@ -34,12 +26,18 @@ extern "C" {
|
||||
# define AddCrc14B(data, len) compute_crc(CRC_14443_B, (data), (len), (data)+(len), (data)+(len)+1)
|
||||
#endif
|
||||
|
||||
void SendRawCommand14443B_Ex(PacketCommandNG *c);
|
||||
void iso14443b_setup();
|
||||
uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response);
|
||||
uint8_t iso14443b_select_card(iso14b_card_select_t *card);
|
||||
uint8_t iso14443b_select_card_srx(iso14b_card_select_t *card);
|
||||
|
||||
void SimulateIso14443bTag(uint32_t pupi);
|
||||
void AcquireRawAdcSamplesIso14443b(uint32_t parameter);
|
||||
void ReadSTMemoryIso14443b(uint8_t numofblocks);
|
||||
void RAMFUNC SniffIso14443b(void);
|
||||
void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
|
||||
void SendRawCommand14443B_Ex(PacketCommandNG *c);
|
||||
|
||||
// testfunctions
|
||||
void WaitForFpgaDelayQueueIsEmpty(uint16_t delay);
|
||||
void ClearFpgaShiftingRegisters(void);
|
||||
@@ -53,8 +51,4 @@ void ClearFpgaShiftingRegisters(void);
|
||||
#define SIM_ACKNOWLEDGE 5
|
||||
#define SIM_WORK 6
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ISO14443B_H */
|
||||
|
||||
@@ -58,12 +58,20 @@
|
||||
// *) remove or refactor code under "depricated"
|
||||
// *) document all the functions
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "iso15693.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "util.h"
|
||||
#include "apps.h"
|
||||
#include "string.h"
|
||||
#include "iso15693tools.h"
|
||||
#include "cmd.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "commonutil.h"
|
||||
#include "ticks.h"
|
||||
#include "BigBuf.h"
|
||||
#include "crc16.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// ISO 15693 Part 2 - Air Interface
|
||||
|
||||
26
armsrc/iso15693.h
Normal file
26
armsrc/iso15693.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __ISO15693_H
|
||||
#define __ISO15693_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "pm3_cmd.h" // struct
|
||||
|
||||
void RecordRawAdcSamplesIso15693(void);
|
||||
void AcquireRawAdcSamplesIso15693(void);
|
||||
void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg
|
||||
void SimTagIso15693(uint32_t parameter, uint8_t *uid); // simulate an ISO15693 tag - greg
|
||||
void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox
|
||||
void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data); // send arbitrary commands from CLI - atrox
|
||||
void Iso15693InitReader(void);
|
||||
|
||||
#endif
|
||||
@@ -7,7 +7,7 @@
|
||||
Linker script for the ARM binary
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
INCLUDE ../common/ldscript.common
|
||||
INCLUDE ../common_arm/ldscript.common
|
||||
|
||||
PHDRS
|
||||
{
|
||||
|
||||
@@ -11,11 +11,20 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "legicrf.h"
|
||||
|
||||
#include "ticks.h" /* timers */
|
||||
#include "crc.h" /* legic crc-4 */
|
||||
#include "legic_prng.h" /* legic PRNG impl */
|
||||
#include "legic.h" /* legic_card_select_t struct */
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "protocols.h"
|
||||
|
||||
static uint8_t *legic_mem; /* card memory, used for read, write */
|
||||
static legic_card_select_t card;/* metadata of currently selected card */
|
||||
static crc_t legic_crc;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef __LEGICRF_H
|
||||
#define __LEGICRF_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "common.h"
|
||||
|
||||
void LegicRfInfo(void);
|
||||
void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv);
|
||||
|
||||
@@ -11,11 +11,17 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "legicrf.h"
|
||||
|
||||
#include "ticks.h" /* timers */
|
||||
#include "crc.h" /* legic crc-4 */
|
||||
#include "legic_prng.h" /* legic PRNG impl */
|
||||
#include "legic.h" /* legic_card_select_t struct */
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
|
||||
static uint8_t *legic_mem; /* card memory, used for sim */
|
||||
static legic_card_select_t card;/* metadata of currently selected card */
|
||||
static crc_t legic_crc;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef __LEGICRFSIM_H
|
||||
#define __LEGICRFSIM_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "common.h"
|
||||
|
||||
void LegicRfSimulate(uint8_t tagtype);
|
||||
|
||||
|
||||
@@ -8,18 +8,23 @@
|
||||
// Also routines for raw mode reading/simulating of LF waveform
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "lfops.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "hitag2.h"
|
||||
#include "commonutil.h"
|
||||
|
||||
#include "crc16.h"
|
||||
#include "string.h"
|
||||
#include "printf.h"
|
||||
#include "lfdemod.h"
|
||||
#include "lfsampling.h"
|
||||
#include "protocols.h"
|
||||
#include "usb_cdc.h" // for usb_poll_validate_length
|
||||
#include "common.h"
|
||||
#include "pmflash.h"
|
||||
#include "flashmem.h" // persistence on flash
|
||||
|
||||
@@ -154,6 +159,30 @@ t55xx_configurations_t T55xx_Timing = {
|
||||
#define T55XX_DLMODE_1OF4 3 // 1 of 4
|
||||
#define T55XX_LONGLEADINGREFERENCE 4 // Value to tell Write Bit to send long reference
|
||||
|
||||
// ATA55xx shared presets & routines
|
||||
static uint32_t GetT55xxClockBit(uint32_t clock) {
|
||||
switch (clock) {
|
||||
case 128:
|
||||
return T55x7_BITRATE_RF_128;
|
||||
case 100:
|
||||
return T55x7_BITRATE_RF_100;
|
||||
case 64:
|
||||
return T55x7_BITRATE_RF_64;
|
||||
case 50:
|
||||
return T55x7_BITRATE_RF_50;
|
||||
case 40:
|
||||
return T55x7_BITRATE_RF_40;
|
||||
case 32:
|
||||
return T55x7_BITRATE_RF_32;
|
||||
case 16:
|
||||
return T55x7_BITRATE_RF_16;
|
||||
case 8:
|
||||
return T55x7_BITRATE_RF_8;
|
||||
default :
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void printT55xxConfig(void) {
|
||||
|
||||
#define PRN_NA sprintf(s + strlen(s), _RED_("N/A") "| ");
|
||||
|
||||
69
armsrc/lfops.h
Normal file
69
armsrc/lfops.h
Normal file
@@ -0,0 +1,69 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __LFOPS_H
|
||||
#define __LFOPS_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "pm3_cmd.h" // struct
|
||||
|
||||
extern uint8_t decimation;
|
||||
extern uint8_t bits_per_sample ;
|
||||
extern bool averaging;
|
||||
|
||||
void AcquireRawAdcSamples125k(int divisor);
|
||||
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command);
|
||||
void ReadTItag(void);
|
||||
void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc);
|
||||
|
||||
void AcquireTiType(void);
|
||||
void AcquireRawBitsTI(void);
|
||||
void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycles);
|
||||
void SimulateTagLowFrequency(int period, int gap, bool ledcontrol);
|
||||
void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen);
|
||||
|
||||
void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, bool ledcontrol, int numcycles);
|
||||
void CmdHIDsimTAG(uint32_t hi, uint32_t lo, bool ledcontrol);
|
||||
|
||||
void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, uint16_t bitslen, uint8_t *bits, bool ledcontrol);
|
||||
void CmdASKsimTAG(uint8_t encoding, uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol);
|
||||
void CmdPSKsimTag(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol);
|
||||
|
||||
void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol);
|
||||
void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); // Realtime demodulation mode for AWID26
|
||||
void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol);
|
||||
void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol);
|
||||
void CopyIOtoT55x7(uint32_t hi, uint32_t lo); // Clone an ioProx card to T5557/T5567
|
||||
void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT); // Clone an HID card to T5557/T5567
|
||||
void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5);
|
||||
void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo);
|
||||
void CopyIndala64toT55x7(uint32_t hi, uint32_t lo); // Clone Indala 64-bit tag by UID to T55x7
|
||||
void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7); // Clone Indala 224-bit tag by UID to T55x7
|
||||
void T55xxResetRead(uint8_t flags);
|
||||
//id T55xxWriteBlock(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags);
|
||||
void T55xxWriteBlock(uint8_t *data);
|
||||
// void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags);
|
||||
void T55xxReadBlock(uint8_t page, bool pwd_mode, bool brute_mem, uint8_t block, uint32_t pwd, uint8_t downlink_mode);
|
||||
void T55xxWakeUp(uint32_t pwd, uint8_t flags);
|
||||
void T55xx_ChkPwds(uint8_t flags);
|
||||
|
||||
void TurnReadLFOn(uint32_t delay);
|
||||
|
||||
void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd);
|
||||
void EM4xWriteWord(uint8_t addr, uint32_t data, uint32_t pwd, uint8_t usepwd);
|
||||
|
||||
void Cotag(uint32_t arg0);
|
||||
void setT55xxConfig(uint8_t arg0, t55xx_configurations_t *c);
|
||||
t55xx_configurations_t *getT55xxConfig(void);
|
||||
void printT55xxConfig(void);
|
||||
void loadT55xxConfig(void);
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,14 @@
|
||||
|
||||
#include "lfsampling.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "lfdemod.h"
|
||||
|
||||
/*
|
||||
Default LF config is set to:
|
||||
decimation = 1 (we keep 1 out of 1 samples)
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
#ifndef __LFSAMPLING_H
|
||||
#define __LFSAMPLING_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "usb_cdc.h" // for usb_poll_validate_length
|
||||
#include "ticks.h" // for StartTicks
|
||||
#include "common.h"
|
||||
#include "pm3_cmd.h"
|
||||
|
||||
typedef struct BitstreamOut BitstreamOut;
|
||||
|
||||
@@ -82,5 +78,4 @@ sample_config *getSamplingConfig();
|
||||
|
||||
void printConfig();
|
||||
|
||||
|
||||
#endif // __LFSAMPLING_H
|
||||
|
||||
@@ -15,9 +15,23 @@
|
||||
|
||||
#include "mifarecmd.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "pmflash.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "string.h"
|
||||
#include "mifareutil.h"
|
||||
#include "protocols.h"
|
||||
#include "parity.h"
|
||||
#include "BigBuf.h"
|
||||
#include "cmd.h"
|
||||
#include "flashmem.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "iso14443a.h"
|
||||
#include "mifaredesfire.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
|
||||
#ifndef HARDNESTED_AUTHENTICATION_TIMEOUT
|
||||
# define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation)
|
||||
|
||||
@@ -1,27 +1,52 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Merlok - June 2011
|
||||
// Gerhard de Koning Gans - May 2008
|
||||
// Hagen Fritsch - June 2010
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Routines to support ISO 14443 type A.
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __MIFARECMD_H
|
||||
#define __MIFARECMD_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "iso14443a.h"
|
||||
#include "crapto1/crapto1.h"
|
||||
#include "mifareutil.h"
|
||||
#include "common.h"
|
||||
#include "crc.h"
|
||||
#include "protocols.h"
|
||||
#include "parity.h"
|
||||
|
||||
void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain);
|
||||
|
||||
void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes);
|
||||
void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain);
|
||||
void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
//void MifareUWriteBlockCompat(uint8_t arg0,uint8_t *datain);
|
||||
void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain);
|
||||
void MifareAcquireNonces(uint32_t arg0, uint32_t flags);
|
||||
void MifareChkKeys(uint8_t *datain);
|
||||
void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
|
||||
void MifareEMemClr(void);
|
||||
void MifareEMemSet(uint8_t blockno, uint8_t blockcnt, uint8_t blockwidth, uint8_t *datain);
|
||||
void MifareEMemGet(uint8_t blockno, uint8_t blockcnt);
|
||||
int MifareECardLoad(uint32_t arg0, uint32_t arg1);
|
||||
|
||||
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); // Work with "magic Chinese" card
|
||||
void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain);
|
||||
void MifareCIdent(); // is "magic chinese" card?
|
||||
|
||||
void MifareSetMod(uint8_t *datain);
|
||||
void MifareUSetPwd(uint8_t arg0, uint8_t *datain);
|
||||
void OnSuccessMagic();
|
||||
void OnErrorMagic(uint8_t reason);
|
||||
|
||||
int32_t dist_nt(uint32_t nt1, uint32_t nt2);
|
||||
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype);
|
||||
//void RAMFUNC SniffMifare(uint8_t param);
|
||||
|
||||
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain);
|
||||
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
#include "mifaredesfire.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "desfire_key.h"
|
||||
#include "mifareutil.h"
|
||||
#include "des.h"
|
||||
#include "cmd.h"
|
||||
#include "dbprint.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "iso14443a.h"
|
||||
#include "crc16.h"
|
||||
#include "mbedtls/aes.h"
|
||||
#include "commonutil.h"
|
||||
|
||||
#define MAX_APPLICATION_COUNT 28
|
||||
#define MAX_FILE_COUNT 16
|
||||
#define MAX_DESFIRE_FRAME_SIZE 60
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Jonathan Westhues, Aug 2005
|
||||
// Gerhard de Koning Gans, April 2008, May 2011
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions internal to the app source.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __MIFAREDESFIRE_H
|
||||
#define __MIFAREDESFIRE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "iso14443a.h"
|
||||
#include "desfire_key.h"
|
||||
#include "mifareutil.h"
|
||||
#include "des.h"
|
||||
|
||||
bool InitDesfireCard();
|
||||
void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain);
|
||||
void MifareDesfireGetInformation();
|
||||
void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
|
||||
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t *datain);
|
||||
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
|
||||
size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout);
|
||||
void OnSuccess();
|
||||
void OnError(uint8_t reason);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,19 +20,24 @@
|
||||
// /!\ Printing Debug message is disrupting emulation,
|
||||
// Only use with caution during debugging
|
||||
|
||||
#include "mifaresim.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "iso14443a.h"
|
||||
#include "mifaresim.h"
|
||||
#include "crapto1/crapto1.h"
|
||||
#include "BigBuf.h"
|
||||
#include "string.h"
|
||||
#include "mifareutil.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "proxmark3.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "protocols.h"
|
||||
#include "apps.h"
|
||||
#include "appmain.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
|
||||
static bool IsTrailerAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action) {
|
||||
uint8_t sector_trailer[16];
|
||||
@@ -506,7 +511,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||
uint8_t rAUTH_NT_keystream[4];
|
||||
uint32_t nonce = 0;
|
||||
|
||||
tUart *uart = GetUart();
|
||||
tUart14a *uart = GetUart14a();
|
||||
|
||||
// free eventually allocated BigBuf memory but keep Emulator Memory
|
||||
BigBuf_free_keep_EM();
|
||||
|
||||
@@ -13,14 +13,12 @@
|
||||
#ifndef __MIFARESIM_H
|
||||
#define __MIFARESIM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
#ifndef CheckCrc14A
|
||||
# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len))
|
||||
#endif
|
||||
|
||||
void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint16_t atqa, uint8_t sak);
|
||||
|
||||
#define AC_DATA_READ 0
|
||||
#define AC_DATA_WRITE 1
|
||||
#define AC_DATA_INC 2
|
||||
@@ -36,4 +34,6 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||
#define AUTHKEYB 1
|
||||
#define AUTHKEYNONE 0xff
|
||||
|
||||
void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint16_t atqa, uint8_t sak);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -68,10 +68,10 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||
|
||||
|
||||
// Set up the demodulator for tag -> reader responses.
|
||||
DemodInit(receivedResp, receivedRespPar);
|
||||
Demod14aInit(receivedResp, receivedRespPar);
|
||||
|
||||
// Set up the demodulator for the reader -> tag commands
|
||||
UartInit(receivedCmd, receivedCmdPar);
|
||||
Uart14aInit(receivedCmd, receivedCmdPar);
|
||||
|
||||
// Setup and start DMA.
|
||||
// set transfer address and number of bytes. Start transfer.
|
||||
@@ -80,8 +80,8 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||
return;
|
||||
}
|
||||
|
||||
tUart *uart = GetUart();
|
||||
tDemod *demod = GetDemod();
|
||||
tUart14a *uart = GetUart14a();
|
||||
tDemod14a *demod = GetDemod14a();
|
||||
|
||||
MfSniffInit();
|
||||
|
||||
@@ -149,10 +149,10 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||
uint8_t readerbyte = (previous_data & 0xF0) | (*data >> 4);
|
||||
if (MillerDecoding(readerbyte, (sniffCounter - 1) * 4)) {
|
||||
LogTrace(receivedCmd, uart->len, 0, 0, NULL, true);
|
||||
DemodReset();
|
||||
UartReset();
|
||||
Demod14aReset();
|
||||
Uart14aReset();
|
||||
}
|
||||
ReaderIsActive = (uart->state != STATE_UNSYNCD);
|
||||
ReaderIsActive = (uart->state != STATE_14A_UNSYNCD);
|
||||
}
|
||||
|
||||
// no need to try decoding tag data if the reader is sending
|
||||
@@ -160,10 +160,10 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||
uint8_t tagbyte = (previous_data << 4) | (*data & 0x0F);
|
||||
if (ManchesterDecoding(tagbyte, 0, (sniffCounter - 1) * 4)) {
|
||||
LogTrace(receivedResp, demod->len, 0, 0, NULL, false);
|
||||
DemodReset();
|
||||
UartReset();
|
||||
Demod14aReset();
|
||||
Uart14aReset();
|
||||
}
|
||||
TagIsActive = (demod->state != DEMOD_UNSYNCD);
|
||||
TagIsActive = (demod->state != DEMOD_14A_UNSYNCD);
|
||||
}
|
||||
}
|
||||
previous_data = *data;
|
||||
@@ -11,13 +11,6 @@
|
||||
#ifndef __MIFARESNIFF_H
|
||||
#define __MIFARESNIFF_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "iso14443a.h"
|
||||
#include "crapto1/crapto1.h"
|
||||
#include "mifareutil.h"
|
||||
#include "common.h"
|
||||
|
||||
#define SNF_INIT 0
|
||||
@@ -9,6 +9,17 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "mifareutil.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "iso14443a.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "parity.h"
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "protocols.h"
|
||||
#include "des.h"
|
||||
|
||||
int DBGLEVEL = DBG_ERROR;
|
||||
|
||||
// crypto1 helpers
|
||||
|
||||
@@ -12,14 +12,8 @@
|
||||
#ifndef __MIFAREUTIL_H
|
||||
#define __MIFAREUTIL_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "parity.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
#include "iso14443a.h"
|
||||
#include "common.h"
|
||||
#include "crapto1/crapto1.h"
|
||||
#include "des.h"
|
||||
|
||||
// mifare authentication
|
||||
#define CRYPT_NONE 0
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "nprintf.h"
|
||||
|
||||
|
||||
|
||||
@@ -32,14 +32,10 @@
|
||||
#ifndef _PRINTF_H_
|
||||
#define _PRINTF_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/**
|
||||
* Output a character to a custom device like UART, used by the printf() function
|
||||
@@ -108,10 +104,4 @@ int vprintf_(const char *format, va_list va);
|
||||
*/
|
||||
int fctprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _PRINTF_H_
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#ifndef OPTIMIZED_CIPHER_H
|
||||
#define OPTIMIZED_CIPHER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Definition 1 (Cipher state). A cipher state of iClass s is an element of F 40/2
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
#include "pcf7931.h"
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "lfsampling.h"
|
||||
#include "string.h"
|
||||
|
||||
#define T0_PCF 8 //period for the pcf7931 in us
|
||||
#define ALLOC 16
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#ifndef __PCF7931_H
|
||||
#define __PCF7931_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "lfsampling.h"
|
||||
#include "pcf7931.h"
|
||||
#include "string.h"
|
||||
#include "common.h"
|
||||
|
||||
size_t DemodPCF7931(uint8_t **outBlocks);
|
||||
bool IsBlock0PCF7931(uint8_t *block);
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
*/
|
||||
#include "printf.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned long long u_quad_t;
|
||||
|
||||
@@ -11,9 +11,8 @@
|
||||
#ifndef __PRINTF_H
|
||||
#define __PRINTF_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include "string.h"
|
||||
#include "common.h"
|
||||
#include <stdarg.h> // va_list
|
||||
|
||||
int kvsprintf(const char *fmt, void *arg, int radix, va_list ap) __attribute__((format(printf, 1, 0)));
|
||||
int vsprintf(char *dest, const char *fmt, va_list ap) __attribute__((format(printf, 2, 0)));
|
||||
|
||||
99
armsrc/radixsort.c
Normal file
99
armsrc/radixsort.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "radixsort.h"
|
||||
|
||||
uint64_t *radixSort(uint64_t *array, uint32_t size) {
|
||||
rscounts_t counts;
|
||||
memset(&counts, 0, 256 * 8 * sizeof(uint32_t));
|
||||
uint64_t *cpy = (uint64_t *)calloc(size * sizeof(uint64_t), sizeof(uint8_t));
|
||||
uint32_t o8 = 0, o7 = 0, o6 = 0, o5 = 0, o4 = 0, o3 = 0, o2 = 0, o1 = 0;
|
||||
uint32_t t8, t7, t6, t5, t4, t3, t2, t1;
|
||||
uint32_t x;
|
||||
// calculate counts
|
||||
for (x = 0; x < size; ++x) {
|
||||
t8 = array[x] & 0xff;
|
||||
t7 = (array[x] >> 8) & 0xff;
|
||||
t6 = (array[x] >> 16) & 0xff;
|
||||
t5 = (array[x] >> 24) & 0xff;
|
||||
t4 = (array[x] >> 32) & 0xff;
|
||||
t3 = (array[x] >> 40) & 0xff;
|
||||
t2 = (array[x] >> 48) & 0xff;
|
||||
t1 = (array[x] >> 56) & 0xff;
|
||||
counts.c8[t8]++;
|
||||
counts.c7[t7]++;
|
||||
counts.c6[t6]++;
|
||||
counts.c5[t5]++;
|
||||
counts.c4[t4]++;
|
||||
counts.c3[t3]++;
|
||||
counts.c2[t2]++;
|
||||
counts.c1[t1]++;
|
||||
}
|
||||
// convert counts to offsets
|
||||
for (x = 0; x < 256; ++x) {
|
||||
t8 = o8 + counts.c8[x];
|
||||
t7 = o7 + counts.c7[x];
|
||||
t6 = o6 + counts.c6[x];
|
||||
t5 = o5 + counts.c5[x];
|
||||
t4 = o4 + counts.c4[x];
|
||||
t3 = o3 + counts.c3[x];
|
||||
t2 = o2 + counts.c2[x];
|
||||
t1 = o1 + counts.c1[x];
|
||||
counts.c8[x] = o8;
|
||||
counts.c7[x] = o7;
|
||||
counts.c6[x] = o6;
|
||||
counts.c5[x] = o5;
|
||||
counts.c4[x] = o4;
|
||||
counts.c3[x] = o3;
|
||||
counts.c2[x] = o2;
|
||||
counts.c1[x] = o1;
|
||||
o8 = t8;
|
||||
o7 = t7;
|
||||
o6 = t6;
|
||||
o5 = t5;
|
||||
o4 = t4;
|
||||
o3 = t3;
|
||||
o2 = t2;
|
||||
o1 = t1;
|
||||
}
|
||||
// radix
|
||||
for (x = 0; x < size; ++x) {
|
||||
t8 = array[x] & 0xff;
|
||||
cpy[counts.c8[t8]] = array[x];
|
||||
counts.c8[t8]++;
|
||||
}
|
||||
for (x = 0; x < size; ++x) {
|
||||
t7 = (cpy[x] >> 8) & 0xff;
|
||||
array[counts.c7[t7]] = cpy[x];
|
||||
counts.c7[t7]++;
|
||||
}
|
||||
for (x = 0; x < size; ++x) {
|
||||
t6 = (array[x] >> 16) & 0xff;
|
||||
cpy[counts.c6[t6]] = array[x];
|
||||
counts.c6[t6]++;
|
||||
}
|
||||
for (x = 0; x < size; ++x) {
|
||||
t5 = (cpy[x] >> 24) & 0xff;
|
||||
array[counts.c5[t5]] = cpy[x];
|
||||
counts.c5[t5]++;
|
||||
}
|
||||
for (x = 0; x < size; ++x) {
|
||||
t4 = (array[x] >> 32) & 0xff;
|
||||
cpy[counts.c4[t4]] = array[x];
|
||||
counts.c4[t4]++;
|
||||
}
|
||||
for (x = 0; x < size; ++x) {
|
||||
t3 = (cpy[x] >> 40) & 0xff;
|
||||
array[counts.c3[t3]] = cpy[x];
|
||||
counts.c3[t3]++;
|
||||
}
|
||||
for (x = 0; x < size; ++x) {
|
||||
t2 = (array[x] >> 48) & 0xff;
|
||||
cpy[counts.c2[t2]] = array[x];
|
||||
counts.c2[t2]++;
|
||||
}
|
||||
for (x = 0; x < size; ++x) {
|
||||
t1 = (cpy[x] >> 56) & 0xff;
|
||||
array[counts.c1[t1]] = cpy[x];
|
||||
counts.c1[t1]++;
|
||||
}
|
||||
free(cpy);
|
||||
return array;
|
||||
}
|
||||
22
armsrc/radixsort.h
Normal file
22
armsrc/radixsort.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef RADIXSORT_H__
|
||||
#define RADIXSORT_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint32_t c8[256];
|
||||
uint32_t c7[256];
|
||||
uint32_t c6[256];
|
||||
uint32_t c5[256];
|
||||
uint32_t c4[256];
|
||||
uint32_t c3[256];
|
||||
uint32_t c2[256];
|
||||
uint32_t c1[256];
|
||||
};
|
||||
uint32_t counts[256 * 8];
|
||||
} rscounts_t;
|
||||
|
||||
uint64_t *radixSort(uint64_t *array, uint32_t size);
|
||||
|
||||
#endif // RADIXSORT_H__
|
||||
@@ -43,6 +43,12 @@
|
||||
RDV40_SPIFFS_SAFE_FOOTER
|
||||
|
||||
#include "spiffs.h"
|
||||
#include "flashmem.h"
|
||||
#include "dbprint.h"
|
||||
#include "printf.h"
|
||||
#include "common.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
///// FLASH LEVEL R/W/E operations for feeding SPIFFS Driver/////////////////
|
||||
static s32_t rdv40_spiffs_llread(u32_t addr, u32_t size, u8_t *dst) {
|
||||
|
||||
@@ -7,9 +7,8 @@
|
||||
|
||||
#ifndef SPIFFS_H_
|
||||
#define SPIFFS_H_
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "spiffs_config.h"
|
||||
|
||||
@@ -854,8 +853,5 @@ u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages);
|
||||
|
||||
#if SPIFFS_CACHE
|
||||
#endif
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SPIFFS_H_ */
|
||||
|
||||
@@ -8,22 +8,7 @@
|
||||
#ifndef SPIFFS_CONFIG_H_
|
||||
#define SPIFFS_CONFIG_H_
|
||||
|
||||
// ----------- 8< ------------
|
||||
// Following includes are for the linux test build of spiffs
|
||||
// These may/should/must be removed/altered/replaced in your target
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//
|
||||
#include "printf.h"
|
||||
#include "string.h"
|
||||
#include "flashmem.h"
|
||||
|
||||
void Dbprintf(const char *fmt, ...);
|
||||
|
||||
//#include <stddef.h>
|
||||
//#include <unistd.h>
|
||||
// ----------- >8 ------------
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef int s32_t;
|
||||
typedef uint32_t u32_t;
|
||||
|
||||
@@ -110,6 +110,11 @@
|
||||
#ifndef SPIFFS_NUCLEUS_H_
|
||||
#define SPIFFS_NUCLEUS_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
#define _SPIFFS_ERR_CHECK_FIRST (SPIFFS_ERR_INTERNAL - 1)
|
||||
#define SPIFFS_ERR_CHECK_OBJ_ID_MISM (SPIFFS_ERR_INTERNAL - 1)
|
||||
#define SPIFFS_ERR_CHECK_SPIX_MISM (SPIFFS_ERR_INTERNAL - 2)
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#ifndef __START_H
|
||||
#define __START_H
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "apps.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "zlib.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user