mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
remove spurious spaces & tabs at end of lines
This commit is contained in:
parent
edc19f202a
commit
60f292b18e
249 changed files with 8481 additions and 8481 deletions
|
@ -40,7 +40,7 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
|
|||
// Compose the outgoing command frame
|
||||
txcmd.cmd = cmd;
|
||||
txcmd.arg[0] = arg0;
|
||||
txcmd.arg[1] = arg1;
|
||||
txcmd.arg[1] = arg1;
|
||||
txcmd.arg[2] = arg2;
|
||||
|
||||
// Add the (optional) content to the frame, with a maximum size of USB_CMD_DATA_SIZE
|
||||
|
@ -50,7 +50,7 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
|
|||
txcmd.d.asBytes[i] = ((uint8_t*)data)[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t sendlen = 0;
|
||||
// Send frame and make sure all bytes are transmitted
|
||||
sendlen = usb_write( (uint8_t*)&txcmd, sizeof(UsbCommand) );
|
||||
|
@ -59,6 +59,6 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
|
|||
// usart_init();
|
||||
// usart_writebuffer( (uint8_t*)&txcmd, sizeof(UsbCommand) );
|
||||
#endif
|
||||
|
||||
|
||||
return sendlen;
|
||||
}
|
|
@ -61,7 +61,7 @@ extern bool validate_prng_nonce(uint32_t nonce);
|
|||
break;\
|
||||
else if(__i)\
|
||||
__M = prng_successor(__M, (__i == 7) ? 48 : 8);\
|
||||
else
|
||||
else
|
||||
|
||||
#define LF_POLY_ODD (0x29CE5C)
|
||||
#define LF_POLY_EVEN (0x870804)
|
||||
|
|
26
common/crc.c
26
common/crc.c
|
@ -5,7 +5,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Generic CRC calculation code.
|
||||
//-----------------------------------------------------------------------------
|
||||
// the Check value below in the comments is CRC of the string '123456789'
|
||||
// the Check value below in the comments is CRC of the string '123456789'
|
||||
//
|
||||
#include "crc.h"
|
||||
|
||||
|
@ -29,21 +29,21 @@ void crc_init(crc_t *crc, int order, uint32_t polynom, uint32_t initial_value, u
|
|||
}
|
||||
|
||||
void crc_clear(crc_t *crc) {
|
||||
|
||||
|
||||
crc->state = crc->initial_value & crc->mask;
|
||||
if (crc->refin)
|
||||
if (crc->refin)
|
||||
crc->state = reflect(crc->state, crc->order);
|
||||
}
|
||||
|
||||
void crc_update2(crc_t *crc, uint32_t data, int data_width){
|
||||
|
||||
if (crc->refin)
|
||||
|
||||
if (crc->refin)
|
||||
data = reflect(data, data_width);
|
||||
|
||||
|
||||
// Bring the next byte into the remainder.
|
||||
crc->state ^= data << (crc->order - data_width);
|
||||
|
||||
for( uint8_t bit = data_width; bit > 0; --bit) {
|
||||
|
||||
for( uint8_t bit = data_width; bit > 0; --bit) {
|
||||
|
||||
if (crc->state & crc->topbit)
|
||||
crc->state = (crc->state << 1) ^ crc->polynom;
|
||||
|
@ -54,9 +54,9 @@ void crc_update2(crc_t *crc, uint32_t data, int data_width){
|
|||
|
||||
void crc_update(crc_t *crc, uint32_t data, int data_width)
|
||||
{
|
||||
if (crc->refin)
|
||||
if (crc->refin)
|
||||
data = reflect(data, data_width);
|
||||
|
||||
|
||||
int i;
|
||||
for(i=0; i<data_width; i++) {
|
||||
int oldstate = crc->state;
|
||||
|
@ -70,7 +70,7 @@ void crc_update(crc_t *crc, uint32_t data, int data_width)
|
|||
|
||||
uint32_t crc_finish(crc_t *crc) {
|
||||
uint32_t val = crc->state;
|
||||
if (crc->refout)
|
||||
if (crc->refout)
|
||||
val = reflect(val, crc->order);
|
||||
return ( val ^ crc->final_xor ) & crc->mask;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ static void print_crc(crc_t *crc) {
|
|||
// width=8 poly=0x31 init=0x00 refin=true refout=true xorout=0x00 check=0xA1 name="CRC-8/MAXIM"
|
||||
uint32_t CRC8Maxim(uint8_t *buff, size_t size) {
|
||||
crc_t crc;
|
||||
crc_init_ref(&crc, 8, 0x31, 0, 0, true, true);
|
||||
crc_init_ref(&crc, 8, 0x31, 0, 0, true, true);
|
||||
for ( int i=0; i < size; ++i)
|
||||
crc_update2(&crc, buff[i], 8);
|
||||
return crc_finish(&crc);
|
||||
|
@ -114,7 +114,7 @@ uint32_t CRC4Legic(uint8_t *cmd, size_t size) {
|
|||
crc_update2(&crc, 1, 1); /* CMD_READ */
|
||||
crc_update2(&crc, cmd[0], 8);
|
||||
crc_update2(&crc, cmd[1], 8);
|
||||
return reflect(crc_finish(&crc), 4);
|
||||
return reflect(crc_finish(&crc), 4);
|
||||
}
|
||||
// width=8 poly=0x63, reversed poly=0x8D init=0x55 refin=true refout=true xorout=0x0000 check=0xC6 name="CRC-8/LEGIC"
|
||||
// the CRC needs to be reversed before returned.
|
||||
|
|
|
@ -26,12 +26,12 @@ typedef struct crc {
|
|||
|
||||
/* Initialize a crc structure. order is the order of the polynom, e.g. 32 for a CRC-32
|
||||
* polynom is the CRC polynom. initial_value is the initial value of a clean state.
|
||||
* final_xor is XORed onto the state before returning it from crc_result().
|
||||
* final_xor is XORed onto the state before returning it from crc_result().
|
||||
* refin is the setting for reversing (bitwise) the bytes during crc
|
||||
* refot is the setting for reversing (bitwise) the crc byte before returning it.
|
||||
*/
|
||||
extern void crc_init_ref(crc_t *crc, int order, uint32_t polynom, uint32_t initial_value, uint32_t final_xor, bool refin, bool refout);
|
||||
|
||||
|
||||
/* Initialize a crc structure. order is the order of the polynom, e.g. 32 for a CRC-32
|
||||
* polynom is the CRC polynom. initial_value is the initial value of a clean state.
|
||||
* final_xor is XORed onto the state before returning it from crc_result(). */
|
||||
|
|
|
@ -12,17 +12,17 @@ static bool crc_table_init = false;
|
|||
static CrcType_t crc_type = CRC_NONE;
|
||||
|
||||
void init_table(CrcType_t ct) {
|
||||
|
||||
|
||||
// same crc algo, and initialised already
|
||||
if ( ct == crc_type && crc_table_init)
|
||||
if ( ct == crc_type && crc_table_init)
|
||||
return;
|
||||
|
||||
|
||||
// not the same crc algo. reset table.
|
||||
if ( ct != crc_type)
|
||||
reset_table();
|
||||
|
||||
|
||||
crc_type = ct;
|
||||
|
||||
|
||||
switch (ct) {
|
||||
case CRC_14443_A:
|
||||
case CRC_14443_B:
|
||||
|
@ -59,9 +59,9 @@ void generate_table( uint16_t polynomial, bool refin) {
|
|||
|
||||
c = c << 1;
|
||||
}
|
||||
if (refin)
|
||||
if (refin)
|
||||
crc = reflect16(crc);
|
||||
|
||||
|
||||
crc_table[i] = crc;
|
||||
}
|
||||
crc_table_init = true;
|
||||
|
@ -80,20 +80,20 @@ uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bo
|
|||
// only usable with polynom orders of 8, 16, 24 or 32.
|
||||
if (n == 0)
|
||||
return (~initval);
|
||||
|
||||
|
||||
uint16_t crc = initval;
|
||||
|
||||
if (refin)
|
||||
if (refin)
|
||||
crc = reflect16(crc);
|
||||
|
||||
if (!refin)
|
||||
if (!refin)
|
||||
while (n--) crc = (crc << 8) ^ crc_table[ ((crc >> 8) ^ *d++) & 0xFF ];
|
||||
else
|
||||
else
|
||||
while (n--) crc = (crc >> 8) ^ crc_table[ (crc & 0xFF) ^ *d++];
|
||||
|
||||
if (refout^refin)
|
||||
if (refout^refin)
|
||||
crc = reflect16(crc);
|
||||
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
@ -102,14 +102,14 @@ uint16_t update_crc16_ex( uint16_t crc, uint8_t c, uint16_t polynomial ) {
|
|||
uint16_t i, v, tmp = 0;
|
||||
|
||||
v = (crc ^ c) & 0xff;
|
||||
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
|
||||
|
||||
if ( (tmp ^ v) & 1 )
|
||||
tmp = ( tmp >> 1 ) ^ polynomial;
|
||||
else
|
||||
tmp >>= 1;
|
||||
|
||||
|
||||
v >>= 1;
|
||||
}
|
||||
return ((crc >> 8) ^ tmp) & 0xffff;
|
||||
|
@ -130,19 +130,19 @@ uint16_t crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t pol
|
|||
|
||||
// xor in at msb
|
||||
remainder ^= (c << 8);
|
||||
|
||||
// 8 iteration loop
|
||||
|
||||
// 8 iteration loop
|
||||
for (uint8_t j = 8; j; --j) {
|
||||
if (remainder & 0x8000) {
|
||||
remainder = (remainder << 1) ^ polynomial;
|
||||
} else {
|
||||
remainder <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (refout)
|
||||
if (refout)
|
||||
remainder = reflect16(remainder);
|
||||
|
||||
|
||||
return remainder;
|
||||
}
|
||||
|
||||
|
@ -150,9 +150,9 @@ void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8
|
|||
|
||||
// can't calc a crc on less than 1 byte
|
||||
if ( n == 0 ) return;
|
||||
|
||||
|
||||
init_table(ct);
|
||||
|
||||
|
||||
uint16_t crc = 0;
|
||||
switch (ct) {
|
||||
case CRC_14443_A: crc = crc16_a(d, n); break;
|
||||
|
@ -172,7 +172,7 @@ uint16_t crc(CrcType_t ct, const uint8_t *d, size_t n) {
|
|||
|
||||
// can't calc a crc on less than 3 byte. (1byte + 2 crc bytes)
|
||||
if ( n < 3 ) return 0;
|
||||
|
||||
|
||||
init_table(ct);
|
||||
switch (ct) {
|
||||
case CRC_14443_A: return crc16_a(d, n);
|
||||
|
@ -192,7 +192,7 @@ uint16_t crc(CrcType_t ct, const uint8_t *d, size_t n) {
|
|||
// ct crc type
|
||||
// d buffer with data
|
||||
// n length (including crc)
|
||||
//
|
||||
//
|
||||
// This function uses the message + crc bytes in order to compare the "residue" afterwards.
|
||||
// crc16 algos like CRC-A become 0x000
|
||||
// while CRC-15693 become 0x0F47
|
||||
|
@ -201,14 +201,14 @@ bool check_crc(CrcType_t ct, const uint8_t *d, size_t n) {
|
|||
|
||||
// can't calc a crc on less than 3 byte. (1byte + 2 crc bytes)
|
||||
if ( n < 3 ) return false;
|
||||
|
||||
|
||||
init_table(ct);
|
||||
|
||||
|
||||
switch (ct) {
|
||||
case CRC_14443_A: return (crc16_a(d, n) == 0);
|
||||
case CRC_14443_B: return (crc16_x25(d, n) == X25_CRC_CHECK);
|
||||
case CRC_15693: return (crc16_x25(d, n) == X25_CRC_CHECK);
|
||||
case CRC_ICLASS: return (crc16_iclass(d, n) == 0);
|
||||
case CRC_ICLASS: return (crc16_iclass(d, n) == 0);
|
||||
case CRC_FELICA: return (crc16_xmodem(d, n) == 0);
|
||||
//case CRC_LEGIC:
|
||||
case CRC_CCITT: return (crc16_ccitt(d, n) == 0);
|
||||
|
@ -222,7 +222,7 @@ uint16_t crc16_ccitt(uint8_t const *d, size_t n) {
|
|||
return crc16_fast(d, n, 0xffff, false, false);
|
||||
}
|
||||
|
||||
// FDX-B ISO11784/85) uses KERMIT
|
||||
// FDX-B ISO11784/85) uses KERMIT
|
||||
// poly=0x1021 init=0x0000 refin=true refout=true xorout=0x0000 name="KERMIT"
|
||||
uint16_t crc16_kermit(uint8_t const *d, size_t n) {
|
||||
return crc16_fast(d, n, 0x0000, true, true);
|
||||
|
@ -231,7 +231,7 @@ uint16_t crc16_kermit(uint8_t const *d, size_t n) {
|
|||
// FeliCa uses XMODEM
|
||||
// poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0000 name="XMODEM"
|
||||
uint16_t crc16_xmodem(uint8_t const *d, size_t n) {
|
||||
return crc16_fast(d, n, 0x0000, false, false);
|
||||
return crc16_fast(d, n, 0x0000, false, false);
|
||||
}
|
||||
|
||||
// Following standards uses X-25
|
||||
|
@ -239,14 +239,14 @@ uint16_t crc16_xmodem(uint8_t const *d, size_t n) {
|
|||
// ISO 14443 CRC-B
|
||||
// ISO/IEC 13239 (formerly ISO/IEC 3309)
|
||||
// poly=0x1021 init=0xffff refin=true refout=true xorout=0xffff name="X-25"
|
||||
uint16_t crc16_x25(uint8_t const *d, size_t n) {
|
||||
uint16_t crc16_x25(uint8_t const *d, size_t n) {
|
||||
uint16_t crc = crc16_fast(d, n, 0xffff, true, true);
|
||||
crc = ~crc;
|
||||
return crc;
|
||||
}
|
||||
// CRC-A (14443-3)
|
||||
// poly=0x1021 init=0xc6c6 refin=true refout=true xorout=0x0000 name="CRC-A"
|
||||
uint16_t crc16_a(uint8_t const *d, size_t n) {
|
||||
uint16_t crc16_a(uint8_t const *d, size_t n) {
|
||||
return crc16_fast(d, n, 0xC6C6, true, true);
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ uint16_t crc16_iclass(uint8_t const *d, size_t n) {
|
|||
return crc16_fast(d, n, 0x4807, true, true);
|
||||
}
|
||||
|
||||
// This CRC-16 is used in Legic Advant systems.
|
||||
// This CRC-16 is used in Legic Advant systems.
|
||||
// poly=0xB400, init=depends refin=true refout=true xorout=0x0000 check= name="CRC-16/LEGIC"
|
||||
uint16_t crc16_legic(uint8_t const *d, size_t n, uint8_t uidcrc) {
|
||||
uint16_t initial = uidcrc << 8 | uidcrc;
|
||||
|
|
|
@ -47,7 +47,7 @@ uint16_t crc16_kermit(uint8_t const *d, size_t n);
|
|||
// Calculate CRC-16/XMODEM (FeliCa)
|
||||
uint16_t crc16_xmodem(uint8_t const *d, size_t n);
|
||||
|
||||
// Calculate CRC-16/X25 (ISO15693, ISO14443 CRC-B,ISO/IEC 13239)
|
||||
// Calculate CRC-16/X25 (ISO15693, ISO14443 CRC-B,ISO/IEC 13239)
|
||||
uint16_t crc16_x25(uint8_t const *d, size_t n);
|
||||
|
||||
// Calculate CRC-16/CRC-A (ISO14443 CRC-A)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "proxmark3.h"
|
||||
/* This is the default version.c file that Makefile.common falls back to if perl is not available */
|
||||
const struct version_information __attribute__((section(".version_information"))) version_information = {
|
||||
VERSION_INFORMATION_MAGIC,
|
||||
const struct version_information __attribute__((section(".version_information"))) version_information = {
|
||||
VERSION_INFORMATION_MAGIC,
|
||||
1, /* version 1 */
|
||||
0, /* version information not present */
|
||||
2, /* cleanliness couldn't be determined */
|
||||
/* Remaining fields: zero */
|
||||
};
|
||||
};
|
||||
|
|
|
@ -91,7 +91,7 @@ struct desfire_tag {
|
|||
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;
|
||||
|
|
230
common/emvtags.h
230
common/emvtags.h
|
@ -1,13 +1,13 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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
|
||||
// structure to hold EMV card and terminal parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __EMVCARD_H
|
||||
#define __EMVCARD_H
|
||||
|
@ -16,133 +16,133 @@
|
|||
#include <stddef.h>
|
||||
|
||||
//structure to hold received/set tag values
|
||||
//variable data inputs have length specifiers
|
||||
//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 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 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
|
||||
//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
|
||||
//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_len; //track1 length
|
||||
uint8_t tag_56[76]; //Track 1 Data
|
||||
uint8_t tag_57_len; //track2 equiv len
|
||||
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_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_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_len;
|
||||
uint8_t tag_84[16]; //DF Name
|
||||
uint8_t tag_86_len;
|
||||
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_len;
|
||||
uint8_t tag_8C[252]; //CDOL1
|
||||
uint8_t tag_8D_len;
|
||||
uint8_t tag_8D_len;
|
||||
uint8_t tag_8D[252]; //CDOL2
|
||||
uint8_t tag_8E_len;
|
||||
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_len;
|
||||
uint8_t tag_90[255]; //ssuer Public Key Certificate
|
||||
uint8_t tag_92_len;
|
||||
uint8_t tag_92_len;
|
||||
uint8_t tag_92[255]; //Issuer Public Key Remainder
|
||||
uint8_t tag_93_len;
|
||||
uint8_t tag_93_len;
|
||||
uint8_t tag_93[255]; //Signed Static Application Data
|
||||
uint8_t tag_94_len;
|
||||
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_len;
|
||||
uint8_t tag_97[252]; //Transaction Certificate Data Object List (TDOL)
|
||||
uint8_t tag_98[20]; //Transaction Certificate (TC) Hash Value
|
||||
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_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_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_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_5F28[2]; //Issuer Country Code
|
||||
uint8_t tag_5F2A[2]; //Transaction Currency Code
|
||||
uint8_t tag_5F2D_len;
|
||||
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_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_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_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_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_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_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_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_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
|
||||
|
@ -150,41 +150,41 @@ typedef struct {
|
|||
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_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_9F1F[255]; //Track 1 Discretionary Data
|
||||
uint8_t tag_9F20_len;
|
||||
uint8_t tag_9F20[255]; //Track 2 DD
|
||||
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_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_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_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_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_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_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
|
||||
|
@ -192,21 +192,21 @@ typedef struct {
|
|||
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_len;
|
||||
uint8_t tag_9F46[255]; //ICC Public Key Certificate
|
||||
uint8_t tag_9F47_len;
|
||||
uint8_t tag_9F47_len;
|
||||
uint8_t tag_9F47[3]; //ICC Public Key Exponent
|
||||
uint8_t tag_9F48_len;
|
||||
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_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_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
|
||||
//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)
|
||||
|
@ -215,33 +215,33 @@ typedef struct {
|
|||
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_len;
|
||||
uint8_t tag_9F68[252]; //Mag Stripe CVM List
|
||||
uint8_t tag_9F69_len;
|
||||
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_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_len;
|
||||
uint8_t tag_61[255]; //Application template
|
||||
uint8_t tag_6F_len;
|
||||
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_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_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_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;
|
||||
|
|
186
common/i2c.c
186
common/i2c.c
|
@ -22,7 +22,7 @@
|
|||
#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"
|
||||
#define I2C_ERROR "I2C_WaitAck Error"
|
||||
|
||||
volatile unsigned long c;
|
||||
|
||||
|
@ -42,24 +42,24 @@ void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
|
|||
|
||||
// try i2c bus recovery at 100kHz = 5uS high, 5uS low
|
||||
void I2C_recovery(void) {
|
||||
|
||||
DbpString("Performing i2c bus recovery");
|
||||
|
||||
|
||||
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)
|
||||
|
||||
//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);
|
||||
|
||||
bool isok = (SCL_read && SDA_read);
|
||||
if (!SDA_read)
|
||||
DbpString("I2C bus recovery error: SDA still LOW");
|
||||
if (!SCL_read)
|
||||
|
@ -72,7 +72,7 @@ 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);
|
||||
|
@ -82,12 +82,12 @@ void I2C_init(void) {
|
|||
|
||||
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);
|
||||
|
||||
|
||||
bool isok = (SCL_read && SDA_read);
|
||||
if ( !isok )
|
||||
I2C_recovery();
|
||||
|
||||
|
||||
}
|
||||
|
||||
// set the reset state
|
||||
|
@ -132,7 +132,7 @@ void I2C_Reset_EnterBootloader(void) {
|
|||
WaitMS(10);
|
||||
}
|
||||
|
||||
// Wait for the clock to go High.
|
||||
// Wait for the clock to go High.
|
||||
bool WaitSCL_H_delay(uint32_t delay) {
|
||||
while (delay--) {
|
||||
if (SCL_read) {
|
||||
|
@ -154,9 +154,9 @@ bool WaitSCL_L_delay(uint32_t delay) {
|
|||
if (!SCL_read) {
|
||||
return true;
|
||||
}
|
||||
I2C_DELAY_1CLK;
|
||||
I2C_DELAY_1CLK;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
// 5000 * 3.07us = 15350us. 15.35ms
|
||||
bool WaitSCL_L(void) {
|
||||
|
@ -168,25 +168,25 @@ bool WaitSCL_L(void) {
|
|||
// Which ever comes first
|
||||
bool WaitSCL_L_timeout(void){
|
||||
volatile uint16_t delay = 1800;
|
||||
while ( delay-- ) {
|
||||
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;
|
||||
SCL_H;
|
||||
if (!WaitSCL_H()) return false;
|
||||
|
||||
I2C_DELAY_2CLK;
|
||||
|
||||
|
||||
if (!SCL_read) return false;
|
||||
if (!SDA_read) return false;
|
||||
|
||||
|
@ -224,7 +224,7 @@ void I2C_Ack(void) {
|
|||
SCL_L; I2C_DELAY_2CLK;
|
||||
SDA_L; I2C_DELAY_2CLK;
|
||||
SCL_H; I2C_DELAY_2CLK;
|
||||
if (!WaitSCL_H()) return;
|
||||
if (!WaitSCL_H()) return;
|
||||
SCL_L; I2C_DELAY_2CLK;
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ void I2C_NoAck(void) {
|
|||
SCL_L; I2C_DELAY_2CLK;
|
||||
SDA_H; I2C_DELAY_2CLK;
|
||||
SCL_H; I2C_DELAY_2CLK;
|
||||
if (!WaitSCL_H()) return;
|
||||
if (!WaitSCL_H()) return;
|
||||
SCL_L; I2C_DELAY_2CLK;
|
||||
}
|
||||
|
||||
|
@ -259,16 +259,16 @@ void I2C_SendByte(uint8_t data) {
|
|||
|
||||
while (bits--) {
|
||||
SCL_L;
|
||||
|
||||
|
||||
I2C_DELAY_1CLK;
|
||||
|
||||
|
||||
if (data & 0x80)
|
||||
SDA_H;
|
||||
else
|
||||
SDA_L;
|
||||
|
||||
|
||||
data <<= 1;
|
||||
|
||||
|
||||
I2C_DELAY_1CLK;
|
||||
|
||||
SCL_H;
|
||||
|
@ -286,11 +286,11 @@ int16_t I2C_ReadByte(void) {
|
|||
SDA_H;
|
||||
while (bits--) {
|
||||
b <<= 1;
|
||||
SCL_L;
|
||||
SCL_L;
|
||||
if (!WaitSCL_L()) return -2;
|
||||
|
||||
|
||||
I2C_DELAY_1CLK;
|
||||
|
||||
|
||||
SCL_H;
|
||||
if (!WaitSCL_H()) return -1;
|
||||
|
||||
|
@ -375,13 +375,13 @@ bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t dev
|
|||
break;
|
||||
|
||||
while (len) {
|
||||
|
||||
|
||||
I2C_SendByte(*data);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
len--;
|
||||
data++;
|
||||
data++;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
|
@ -393,7 +393,7 @@ bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t dev
|
|||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// read one array of data (Data array, Readout length, command to be written , SlaveDevice address ).
|
||||
|
@ -408,7 +408,7 @@ int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
|||
WaitUS(600);
|
||||
bool bBreak = true;
|
||||
uint16_t readcount = 0;
|
||||
|
||||
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return 0;
|
||||
|
@ -421,7 +421,7 @@ int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
|||
I2C_SendByte(device_cmd);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
|
||||
// 0xB1 / 0xC1 == i2c read
|
||||
I2C_Start();
|
||||
I2C_SendByte(device_address | 1);
|
||||
|
@ -442,35 +442,35 @@ int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
|||
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++;
|
||||
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
|
||||
//START, 0xB0, 0x00, 0x00, START, 0xB1, xx, yy, zz, ......, STOP
|
||||
bool bBreak = true;
|
||||
uint8_t readcount = 0;
|
||||
|
||||
|
@ -491,7 +491,7 @@ int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t
|
|||
I2C_SendByte(lsb);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
|
||||
// 0xB1 / 0xC1 i2c read
|
||||
I2C_Start();
|
||||
I2C_SendByte(device_address | 1);
|
||||
|
@ -509,30 +509,30 @@ int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t
|
|||
|
||||
// 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.
|
||||
// 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
|
||||
//START, 0xB0, 0x00, 0x00, xx, yy, zz, ......, STOP
|
||||
bool bBreak = true;
|
||||
|
||||
do {
|
||||
|
@ -543,7 +543,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
|
|||
I2C_SendByte(device_address & 0xFE);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
||||
|
||||
I2C_SendByte(msb);
|
||||
if (!I2C_WaitAck())
|
||||
break;
|
||||
|
@ -558,7 +558,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
|
|||
break;
|
||||
|
||||
len--;
|
||||
data++;
|
||||
data++;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
|
@ -570,7 +570,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
|
|||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void I2C_print_status(void) {
|
||||
|
@ -581,7 +581,7 @@ void I2C_print_status(void) {
|
|||
if ( len > 0 )
|
||||
Dbprintf(" version.................v%x.%02d", resp[0], resp[1]);
|
||||
else
|
||||
DbpString(" version.................FAILED");
|
||||
DbpString(" version.................FAILED");
|
||||
}
|
||||
|
||||
// Will read response from smart card module, retries 3 times to get the data.
|
||||
|
@ -590,46 +590,46 @@ 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;
|
||||
}
|
||||
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())
|
||||
if (!I2C_WaitForSim())
|
||||
return false;
|
||||
|
||||
|
||||
// read bytes from module
|
||||
uint8_t len = sizeof(card_ptr->atr);
|
||||
if ( !sc_rx_bytes(card_ptr->atr, &len) )
|
||||
|
@ -639,12 +639,12 @@ bool GetATR(smart_card_atr_t *card_ptr) {
|
|||
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) {
|
||||
|
||||
|
@ -683,16 +683,16 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
|
|||
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)) {
|
||||
|
||||
if ((flags & SC_CONNECT)) {
|
||||
|
||||
I2C_Reset_EnterMainProgram();
|
||||
|
||||
|
||||
if ((flags & SC_SELECT)) {
|
||||
smart_card_atr_t card;
|
||||
bool gotATR = GetATR( &card );
|
||||
|
@ -703,15 +703,15 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
|
|||
}
|
||||
|
||||
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 && MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||
|
||||
if ( !res && MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||
|
||||
// read bytes from module
|
||||
len = ISO7618_MAX_FRAME;
|
||||
res = sc_rx_bytes(resp, &len);
|
||||
|
@ -721,11 +721,11 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
|
|||
len = 0;
|
||||
}
|
||||
}
|
||||
OUT:
|
||||
OUT:
|
||||
cmd_send(CMD_ACK, len, 0, 0, resp, len);
|
||||
BigBuf_free();
|
||||
set_tracing(false);
|
||||
LEDsoff();
|
||||
LEDsoff();
|
||||
}
|
||||
|
||||
void SmartCardUpgrade(uint64_t arg0) {
|
||||
|
@ -735,8 +735,8 @@ void SmartCardUpgrade(uint64_t arg0) {
|
|||
#define I2C_BLOCK_SIZE 128
|
||||
// write. Sector0, with 11,22,33,44
|
||||
// erase is 128bytes, and takes 50ms to execute
|
||||
|
||||
I2C_Reset_EnterBootloader();
|
||||
|
||||
I2C_Reset_EnterBootloader();
|
||||
|
||||
bool isOK = true;
|
||||
int16_t res = 0;
|
||||
|
@ -744,16 +744,16 @@ void SmartCardUpgrade(uint64_t arg0) {
|
|||
uint16_t 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
|
||||
res = I2C_WriteFW(fwdata+pos, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
|
||||
if ( !res ) {
|
||||
|
@ -761,7 +761,7 @@ void SmartCardUpgrade(uint64_t arg0) {
|
|||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// writing takes time.
|
||||
WaitMS(50);
|
||||
|
||||
|
@ -769,23 +769,23 @@ void SmartCardUpgrade(uint64_t arg0) {
|
|||
res = I2C_ReadFW(verfiydata, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
|
||||
if ( res <= 0) {
|
||||
DbpString("Reading back failed");
|
||||
isOK = false;
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// cmp
|
||||
if ( 0 != memcmp(fwdata+pos, verfiydata, size)) {
|
||||
DbpString("not equal data");
|
||||
isOK = false;
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
length -= size;
|
||||
pos += size;
|
||||
}
|
||||
}
|
||||
cmd_send(CMD_ACK, isOK, pos, 0, 0, 0);
|
||||
LED_C_OFF();
|
||||
BigBuf_free();
|
||||
BigBuf_free();
|
||||
}
|
||||
|
||||
void SmartCardSetBaud(uint64_t arg0) {
|
||||
|
@ -793,13 +793,13 @@ void SmartCardSetBaud(uint64_t arg0) {
|
|||
|
||||
void SmartCardSetClock(uint64_t arg0) {
|
||||
LED_D_ON();
|
||||
set_tracing(true);
|
||||
I2C_Reset_EnterMainProgram();
|
||||
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);
|
||||
|
||||
|
||||
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
|
||||
set_tracing(false);
|
||||
LEDsoff();
|
||||
|
|
|
@ -39,7 +39,7 @@ bool CheckCrc14443(uint16_t CrcType, const uint8_t *data, int length) {
|
|||
if (length < 3) return false;
|
||||
uint8_t b1, b2;
|
||||
ComputeCrc14443(CrcType, data, length - 2, &b1, &b2);
|
||||
if ((b1 == data[length - 2]) && (b2 == data[length - 1]))
|
||||
if ((b1 == data[length - 2]) && (b2 == data[length - 1]))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
char* Iso15693sprintUID(char *target, uint8_t *uid) {
|
||||
|
||||
static char tempbuf[2*8+1] = {0};
|
||||
if (target == NULL)
|
||||
if (target == NULL)
|
||||
target = tempbuf;
|
||||
sprintf(target, "%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
uid[7], uid[6], uid[5], uid[4],
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
//RESPONSE FLAGS
|
||||
#define ISO15_RES_ERROR 0x01
|
||||
#define ISO15_RES_EXT 0x08 // Protocol Extention
|
||||
#define ISO15_RES_EXT 0x08 // Protocol Extention
|
||||
|
||||
// RESPONSE ERROR CODES
|
||||
#define ISO15_NOERROR 0x00
|
||||
|
@ -47,7 +47,7 @@
|
|||
#define ISO15_ERROR_CMD_NOT_REC 0x02 // Command not recognized (eg. parameter error)
|
||||
#define ISO15_ERROR_CMD_OPTION 0x03 // Command option not supported
|
||||
#define ISO15_ERROR_GENERIC 0x0F // No additional Info about this error
|
||||
#define ISO15_ERROR_BLOCK_UNAVAILABLE 0x10
|
||||
#define ISO15_ERROR_BLOCK_UNAVAILABLE 0x10
|
||||
#define ISO15_ERROR_BLOCK_LOCKED_ALREADY 0x11 // cannot lock again
|
||||
#define ISO15_ERROR_BLOCK_LOCKED 0x12 // cannot be changed
|
||||
#define ISO15_ERROR_BLOCK_WRITE 0x13 // Writing was unsuccessful
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// a is 7bit lsfr
|
||||
// b is 8bit lsfr
|
||||
// c keeps track on which step the prng is.
|
||||
// legic_prng_get_bit() = gets a bit muxed from a and b.
|
||||
// legic_prng_get_bit() = gets a bit muxed from a and b.
|
||||
struct lfsr {
|
||||
uint8_t a;
|
||||
uint8_t b;
|
||||
|
@ -26,10 +26,10 @@ struct lfsr {
|
|||
// Now we have a special case with iv == 0
|
||||
// it sets b to 0 aswell to make sure we get a all zero keystream out
|
||||
// which is used in the initialisation phase sending the IV
|
||||
//
|
||||
//
|
||||
void legic_prng_init(uint8_t iv) {
|
||||
lfsr.a = iv;
|
||||
lfsr.b = 0; // hack to get a always 0 keystream
|
||||
lfsr.b = 0; // hack to get a always 0 keystream
|
||||
lfsr.c = 0;
|
||||
if(iv)
|
||||
lfsr.b = (iv << 1) | 1;
|
||||
|
@ -37,7 +37,7 @@ void legic_prng_init(uint8_t iv) {
|
|||
|
||||
void legic_prng_forward(int count) {
|
||||
if (count == 0) return;
|
||||
|
||||
|
||||
lfsr.c += count;
|
||||
while(count--) {
|
||||
// According: http://www.proxmark.org/forum/viewtopic.php?pid=5437#p5437
|
||||
|
|
420
common/lfdemod.c
420
common/lfdemod.c
File diff suppressed because it is too large
Load diff
|
@ -7,8 +7,8 @@
|
|||
// Low frequency demod related commands
|
||||
// marshmellow
|
||||
// note that many of these demods are not the slickest code and they often rely
|
||||
// on peaks and clock instead of converting to clean signal.
|
||||
//
|
||||
// on peaks and clock instead of converting to clean signal.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef LFDEMOD_H__
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// Parity functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// all functions defined in header file by purpose. Allows compiler optimizations.
|
||||
// all functions defined in header file by purpose. Allows compiler optimizations.
|
||||
|
||||
#ifndef __PARITY_H
|
||||
#define __PARITY_H
|
||||
|
@ -31,7 +31,7 @@ static inline bool evenparity8(const uint8_t x) {
|
|||
}
|
||||
|
||||
|
||||
static inline bool evenparity32(uint32_t x)
|
||||
static inline bool evenparity32(uint32_t x)
|
||||
{
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
|
@ -43,7 +43,7 @@ static inline bool evenparity32(uint32_t x)
|
|||
}
|
||||
|
||||
|
||||
static inline bool oddparity32(uint32_t x)
|
||||
static inline bool oddparity32(uint32_t x)
|
||||
{
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
|
|
|
@ -24,7 +24,7 @@ void burtle_init_mod(prng_ctx *x, uint32_t seed ) {
|
|||
}
|
||||
|
||||
void burtle_init(prng_ctx *x, uint32_t seed ) {
|
||||
uint32_t i;
|
||||
uint32_t i;
|
||||
x->a = 0xf1ea5eed, x->b = x->c = x->d = seed;
|
||||
for (i=0; i < 20; ++i) {
|
||||
(void)burtle_get_mod(x);
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
#define __PRNG_H
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
typedef struct prng_ctx {
|
||||
uint32_t a;
|
||||
uint32_t b;
|
||||
uint32_t c;
|
||||
uint32_t d;
|
||||
typedef struct prng_ctx {
|
||||
uint32_t a;
|
||||
uint32_t b;
|
||||
uint32_t c;
|
||||
uint32_t d;
|
||||
} prng_ctx;
|
||||
|
||||
//uint32_t burtle_get( prng_ctx *x );
|
||||
|
|
|
@ -30,17 +30,17 @@ uint8_t notset(uint8_t val, uint8_t mask){
|
|||
void fuse_config(const picopass_hdr *hdr) {
|
||||
uint8_t fuses = hdr->conf.fuses;
|
||||
|
||||
if (isset(fuses,FUSE_FPERS))
|
||||
if (isset(fuses,FUSE_FPERS))
|
||||
PrintAndLogDevice(SUCCESS, "\tMode: Personalization [Programmable]");
|
||||
else
|
||||
else
|
||||
PrintAndLogDevice(NORMAL, "\tMode: Application [Locked]");
|
||||
|
||||
if (isset(fuses, FUSE_CODING1)) {
|
||||
PrintAndLogDevice(NORMAL, "\tCoding: RFU");
|
||||
} else {
|
||||
if( isset( fuses , FUSE_CODING0))
|
||||
if( isset( fuses , FUSE_CODING0))
|
||||
PrintAndLogDevice(NORMAL, "\tCoding: ISO 14443-2 B/ISO 15693");
|
||||
else
|
||||
else
|
||||
PrintAndLogDevice(NORMAL, "\tCoding: ISO 14443B only");
|
||||
}
|
||||
// 1 1
|
||||
|
@ -54,7 +54,7 @@ void fuse_config(const picopass_hdr *hdr) {
|
|||
|
||||
if( isset( fuses, FUSE_RA))
|
||||
PrintAndLogDevice(NORMAL, "\tRA: Read access enabled");
|
||||
else
|
||||
else
|
||||
PrintAndLogDevice(WARNING, "\tRA: Read access not enabled");
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t *
|
|||
uint8_t k16 = isset(mem_cfg, 0x80);
|
||||
//uint8_t k2 = isset(mem_cfg, 0x08);
|
||||
uint8_t book = isset(mem_cfg, 0x20);
|
||||
|
||||
|
||||
if(isset(chip_cfg, 0x10) && !k16 && !book) {
|
||||
*kb = 2;
|
||||
*app_areas = 2;
|
||||
|
@ -100,10 +100,10 @@ void mem_app_config(const picopass_hdr *hdr) {
|
|||
uint8_t max_blk = 31;
|
||||
|
||||
getMemConfig(mem, chip, &max_blk, &app_areas, &kb);
|
||||
|
||||
|
||||
if (applimit < 6) applimit = 26;
|
||||
if (kb == 2 && (applimit > 0x1f) ) applimit = 26;
|
||||
|
||||
|
||||
PrintAndLogDevice(NORMAL, " Mem: %u KBits/%u App Areas (%u * 8 bytes) [%02X]", kb, app_areas, max_blk, mem);
|
||||
PrintAndLogDevice(NORMAL, "\tAA1: blocks 06-%02X", applimit);
|
||||
PrintAndLogDevice(NORMAL, "\tAA2: blocks %02X-%02X", applimit+1, max_blk);
|
||||
|
|
|
@ -36,7 +36,7 @@ ISO14443B
|
|||
05 = REQB
|
||||
1D = ATTRIB
|
||||
50 = HALT
|
||||
|
||||
|
||||
BA = PING (reader -> tag)
|
||||
AB = PONG (tag -> reader)
|
||||
SRIX4K (tag does not respond to 05)
|
||||
|
@ -132,7 +132,7 @@ ISO 7816-4 Basic interindustry commands. For command APDU's.
|
|||
#define ICLASS_CMD_READ4 0x06
|
||||
#define ICLASS_CMD_READ_OR_IDENTIFY 0x0C
|
||||
|
||||
#define ICLASS_CMD_SELECT 0x81
|
||||
#define ICLASS_CMD_SELECT 0x81
|
||||
#define ICLASS_CMD_PAGESEL 0x84
|
||||
#define ICLASS_CMD_UPDATE 0x87
|
||||
#define ICLASS_CMD_READCHECK_KC 0x18
|
||||
|
@ -309,7 +309,7 @@ ISO 7816-4 Basic interindustry commands. For command APDU's.
|
|||
// ISO7816-4 For response APDU's
|
||||
#define ISO7816_OK 0x9000
|
||||
// 6x xx = ERROR
|
||||
|
||||
|
||||
// MIFARE DESFire command set:
|
||||
#define MFDES_CREATE_APPLICATION 0xca
|
||||
#define MFDES_DELETE_APPLICATION 0xda
|
||||
|
@ -417,7 +417,7 @@ void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t *
|
|||
#define T55XX_WRITE_TIMEOUT 1500
|
||||
|
||||
uint32_t GetT55xxClockBit(uint32_t clock);
|
||||
|
||||
|
||||
|
||||
// em4x05 & em4x69 chip configuration register definitions
|
||||
#define EM4x05_GET_BITRATE(x) (((x & 0x3F)*2)+2)
|
||||
|
@ -515,7 +515,7 @@ uint32_t GetT55xxClockBit(uint32_t clock);
|
|||
#define SYSTEMCODE_CYBERNE 0x0003 // Cyberne
|
||||
#define SYSTEMCODE_SUICA 0x0003 // Suica
|
||||
#define SYSTEMCODE_PASMO 0x0003 // Pasmo
|
||||
|
||||
|
||||
//FeliCa Service list Suica/pasmo (little endian)
|
||||
#define SERVICE_SUICA_INOUT 0x108f // SUICA/PASMO
|
||||
#define SERVICE_SUICA_HISTORY 0x090f // SUICA/PASMO
|
||||
|
@ -569,5 +569,5 @@ typedef struct {
|
|||
} picopass_hdr;
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
// PROTOCOLS_H
|
||||
|
|
|
@ -44,13 +44,13 @@ uint64_t * radixSort(uint64_t * array, uint32_t size) {
|
|||
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;
|
||||
o8 = t8;
|
||||
o7 = t7;
|
||||
o6 = t6;
|
||||
o5 = t5;
|
||||
o4 = t4;
|
||||
o3 = t3;
|
||||
o2 = t2;
|
||||
o1 = t1;
|
||||
}
|
||||
// radix
|
||||
|
|
|
@ -6,20 +6,20 @@ static uint32_t g_nextrandom;
|
|||
*
|
||||
* We don't have an implementation of the "rand" function. Instead we use a
|
||||
* method of seeding with the time it took to call "autoseed" from first run.
|
||||
*
|
||||
*
|
||||
* https://github.com/Proxmark/proxmark3/pull/209/commits/f9c1dcd9f6e68a8c07cffed697a9c4c8caed6015
|
||||
*
|
||||
* Iceman, rand needs to be fast.
|
||||
* https://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/
|
||||
*/
|
||||
|
||||
|
||||
inline void fast_prand(){
|
||||
fast_prandEx(GetTickCount());
|
||||
}
|
||||
inline void fast_prandEx(uint32_t seed) {
|
||||
g_nextrandom = seed;
|
||||
}
|
||||
|
||||
|
||||
uint32_t prand() {
|
||||
// g_nextrandom *= 6364136223846793005;
|
||||
// g_nextrandom += 1;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// pseudo rng generator. To be used when PM3 simulates Mifare tag.
|
||||
// i.e. 'hf mf sim'
|
||||
// i.e. 'hf mf sim'
|
||||
// 'hf 14a sim'
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -16,17 +16,17 @@ void tea_encrypt(uint8_t *v, uint8_t *key) {
|
|||
uint32_t a=0,b=0,c=0,d=0,y=0,z=0;
|
||||
uint32_t sum = 0;
|
||||
uint8_t n = ROUNDS;
|
||||
|
||||
|
||||
//key
|
||||
a = bytes_to_num(key, 4);
|
||||
b = bytes_to_num(key+4, 4);
|
||||
c = bytes_to_num(key+8, 4);
|
||||
d = bytes_to_num(key+12, 4);
|
||||
|
||||
|
||||
//input
|
||||
y = bytes_to_num(v, 4);
|
||||
z = bytes_to_num(v+4, 4);
|
||||
|
||||
|
||||
while ( n-- > 0 ) {
|
||||
sum += DELTA;
|
||||
y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
|
||||
|
@ -48,7 +48,7 @@ void tea_decrypt(uint8_t *v, uint8_t *key) {
|
|||
b = bytes_to_num(key+4, 4);
|
||||
c = bytes_to_num(key+8, 4);
|
||||
d = bytes_to_num(key+12, 4);
|
||||
|
||||
|
||||
//input
|
||||
y = bytes_to_num(v, 4);
|
||||
z = bytes_to_num(v+4, 4);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Iceman, July 2018
|
||||
// edits by - Anticat, August 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.
|
||||
|
@ -24,7 +24,7 @@ void usart_close(void) {
|
|||
|
||||
// Reset the baud rate divisor register
|
||||
pUS1->US_BRGR = 0;
|
||||
|
||||
|
||||
// Reset the Timeguard Register
|
||||
pUS1->US_TTGR = 0;
|
||||
|
||||
|
@ -96,20 +96,20 @@ void usart_init(void) {
|
|||
|
||||
// disable & reset receiver / transmitter for configuration
|
||||
pUS1->US_CR = (AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS);
|
||||
|
||||
|
||||
//enable the USART1 Peripheral clock
|
||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US1);
|
||||
|
||||
// disable PIO control of receive / transmit pins
|
||||
pPIO->PIO_PDR |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
|
||||
pPIO->PIO_PDR |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
|
||||
// enable peripheral mode A on receive / transmit pins
|
||||
pPIO->PIO_ASR |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
pPIO->PIO_BSR = 0;
|
||||
|
||||
// enable pull-up on receive / transmit pins (see 31.5.1 I/O Lines)
|
||||
pPIO->PIO_PPUER |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
|
||||
|
||||
// set mode
|
||||
pUS1->US_MR = AT91C_US_USMODE_NORMAL | // normal mode
|
||||
AT91C_US_CLKS_CLOCK | // MCK (48MHz)
|
||||
|
@ -126,18 +126,18 @@ void usart_init(void) {
|
|||
// For a nice detailed sample, interrupt driven but still relevant.
|
||||
// See https://www.sparkfun.com/datasheets/DevTools/SAM7/at91sam7%20serial%20communications.pdf
|
||||
|
||||
// set baudrate to 115200
|
||||
// set baudrate to 115200
|
||||
// 115200 * 16 == 1843200
|
||||
//
|
||||
//pUS1->US_BRGR = (48UL*1000*1000) / (9600*16);
|
||||
pUS1->US_BRGR = 48054841 / (9600 << 4);
|
||||
|
||||
|
||||
// Write the Timeguard Register
|
||||
pUS1->US_TTGR = 0;
|
||||
pUS1->US_RTOR = 0;
|
||||
pUS1->US_FIDI = 0;
|
||||
pUS1->US_IF = 0;
|
||||
|
||||
|
||||
// re-enable receiver / transmitter
|
||||
pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN);
|
||||
}
|
142
common/usb_cdc.c
142
common/usb_cdc.c
|
@ -36,14 +36,14 @@
|
|||
/*
|
||||
AT91SAM7S256 USB Device Port
|
||||
• Embedded 328-byte dual-port RAM for endpoints
|
||||
• Four endpoints
|
||||
• Four endpoints
|
||||
– Endpoint 0: 8 bytes
|
||||
– Endpoint 1 and 2: 64 bytes ping-pong
|
||||
– Endpoint 3: 64 bytes
|
||||
– Ping-pong Mode (two memory banks) for bulk endpoints
|
||||
*/
|
||||
|
||||
//
|
||||
//
|
||||
#define AT91C_EP_CONTROL 0
|
||||
#define AT91C_EP_OUT 1 // cfg bulk out
|
||||
#define AT91C_EP_IN 2 // cfg bulk in
|
||||
|
@ -79,7 +79,7 @@ AT91SAM7S256 USB Device Port
|
|||
#define _ISO 0x01 //Isochronous Transfer
|
||||
#define _BULK 0x02 //Bulk Transfer
|
||||
#define _INTERRUPT 0x03 //Interrupt Transfer
|
||||
|
||||
|
||||
// (bit7 | 0 = OUT, 1 = IN)
|
||||
#define _EP_IN 0x80
|
||||
#define _EP_OUT 0x00
|
||||
|
@ -92,7 +92,7 @@ AT91SAM7S256 USB Device Port
|
|||
|
||||
|
||||
/* WCID specific Request Code */
|
||||
#define MS_OS_DESCRIPTOR_INDEX 0xEE
|
||||
#define MS_OS_DESCRIPTOR_INDEX 0xEE
|
||||
#define MS_VENDOR_CODE 0x1C
|
||||
#define MS_EXTENDED_COMPAT_ID 0x04
|
||||
#define MS_EXTENDED_PROPERTIES 0x05
|
||||
|
@ -143,10 +143,10 @@ static const char devDescriptor[] = {
|
|||
0xc4,0x9a, // Vendor ID [0x9ac4 = J. Westhues]
|
||||
0x8f,0x4b, // Product ID [0x4b8f = Proxmark-3 RFID Instrument]
|
||||
0x00,0x01, // BCD Device release number (1.00)
|
||||
1, // index Manufacturer
|
||||
1, // index Manufacturer
|
||||
2, // index Product
|
||||
3, // index SerialNumber
|
||||
1 // Number of Configs
|
||||
1 // Number of Configs
|
||||
};
|
||||
|
||||
static const char cfgDescriptor[] = {
|
||||
|
@ -154,8 +154,8 @@ static const char cfgDescriptor[] = {
|
|||
/* Configuration 1 descriptor */
|
||||
// -----------------------------
|
||||
9, // Length
|
||||
USB_DESCRIPTOR_CONFIGURATION, // Descriptor Type
|
||||
(9+9+5+5+4+5+7+9+7+7), 0, // Total Length 2 EP + Control
|
||||
USB_DESCRIPTOR_CONFIGURATION, // Descriptor Type
|
||||
(9+9+5+5+4+5+7+9+7+7), 0, // Total Length 2 EP + Control
|
||||
2, // Number of Interfaces
|
||||
1, // Index value of this Configuration (used in SetConfiguration from Host)
|
||||
0, // Configuration string index
|
||||
|
@ -174,7 +174,7 @@ static const char cfgDescriptor[] = {
|
|||
1, // Function Protocol: v.25term
|
||||
0, // iInterface
|
||||
*/
|
||||
|
||||
|
||||
/* Interface 0 Descriptor */
|
||||
/* CDC Communication Class Interface Descriptor Requirement for Notification*/
|
||||
// -----------------------------------------------------------
|
||||
|
@ -192,7 +192,7 @@ static const char cfgDescriptor[] = {
|
|||
5, // Function Length
|
||||
0x24, // Descriptor type: CS_INTERFACE
|
||||
0, // Descriptor subtype: Header Functional Descriptor
|
||||
0x10,0x01, // bcd CDC:1.1
|
||||
0x10,0x01, // bcd CDC:1.1
|
||||
|
||||
/* ACM Functional Descriptor */
|
||||
4, // Function Length
|
||||
|
@ -206,23 +206,23 @@ static const char cfgDescriptor[] = {
|
|||
6, // Descriptor Subtype: Union Functional Descriptor
|
||||
0, // MasterInterface: Communication Class Interface
|
||||
1, // SlaveInterface0: Data Class Interface
|
||||
|
||||
|
||||
/* Call Management Functional Descriptor */
|
||||
5, // Function Length
|
||||
0x24, // Descriptor Type: CS_INTERFACE
|
||||
1, // Descriptor Subtype: Call Management Functional Descriptor
|
||||
1, // Descriptor Subtype: Call Management Functional Descriptor
|
||||
0, // Capabilities: Device sends/receives call management information only over the Communication Class interface. Device does not handle call management itself
|
||||
1, // Data Interface: Data Class Interface
|
||||
|
||||
|
||||
/* Protocol Functional Descriptor */
|
||||
/*
|
||||
6,
|
||||
0x24, // Descriptor Type: CS_INTERFACE
|
||||
0x0B, // Descriptor Subtype: Protocol Unit functional Descriptor
|
||||
0xDD, // constant uniq ID of unit
|
||||
0xFE, // protocol
|
||||
0xFE, // protocol
|
||||
*/
|
||||
|
||||
|
||||
/* CDC Notification Endpoint descriptor */
|
||||
// ---------------------------------------
|
||||
7, // Length
|
||||
|
@ -232,7 +232,7 @@ static const char cfgDescriptor[] = {
|
|||
AT91C_EP_CONTROL_SIZE, 0x00, // MaxPacket Size: EP0 - 8
|
||||
0xFF, // Interval polling
|
||||
|
||||
|
||||
|
||||
/* Interface 1 Descriptor */
|
||||
/* CDC Data Class Interface 1 Descriptor Requirement */
|
||||
9, // Length
|
||||
|
@ -283,10 +283,10 @@ static const char bosDescriptor[] = {
|
|||
static const char CompatIDFeatureDescriptor[] = {
|
||||
0x28, 0x00, 0x00, 0x00, // Descriptor Length 40bytes (0x28)
|
||||
0x00, 0x01, // Version ('1.0')
|
||||
MS_EXTENDED_COMPAT_ID, 0x00, // Compatibility ID Descriptor Index 0x0004
|
||||
MS_EXTENDED_COMPAT_ID, 0x00, // Compatibility ID Descriptor Index 0x0004
|
||||
0x01, // Number of sections. 0x1
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved (7bytes)
|
||||
//-----function section 1------
|
||||
//-----function section 1------
|
||||
0x00, // Interface Number #0
|
||||
0x01, // reserved (0x1)
|
||||
0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00, // Compatible ID ('WINUSB\0\0') (8bytes)
|
||||
|
@ -306,7 +306,7 @@ static const char OSprop[] = {
|
|||
MS_EXTENDED_PROPERTIES, 0,
|
||||
// u16 wCount -- three section
|
||||
3, 0,
|
||||
|
||||
|
||||
//-----property section 1------
|
||||
// u32 size ( 14+40+78 == 132)
|
||||
132, 0, 0, 0,
|
||||
|
@ -321,7 +321,7 @@ static const char OSprop[] = {
|
|||
// data {4D36E978-E325-11CE-BFC1-08002BE10318}
|
||||
'{',0,'4',0,'d',0,'3',0,'6',0,'e',0,'9',0,'7',0,'8',0,'-',0,'e',0,'3',0,'2',0,'5',0,
|
||||
'-',0,'1',0,'1',0,'c',0,'e',0,'-',0,'b',0,'f',0,'c',0,'1',0,'-',0,'0',0,'8',0,'0',0,
|
||||
'0',0,'2',0,'b',0,'e',0,'1',0,'0',0,'3',0,'1',0,'8',0,'}',0,0,0,
|
||||
'0',0,'2',0,'b',0,'e',0,'1',0,'0',0,'3',0,'1',0,'8',0,'}',0,0,0,
|
||||
|
||||
//-----property section 2------
|
||||
// u32 size ( 14+12+38 == 64)
|
||||
|
@ -343,7 +343,7 @@ static const char OSprop[] = {
|
|||
// u32 type
|
||||
2, 0, 0, 0, //Unicode string with environment variables
|
||||
// u16 namelen (12)
|
||||
12, 0,
|
||||
12, 0,
|
||||
// name Icons
|
||||
'I',0,'c',0,'o',0,'n',0,'s',0,0,0,
|
||||
// u32 datalen ( 38*2 == 76)
|
||||
|
@ -393,12 +393,12 @@ static const char StrMS_OSDescriptor[] = {
|
|||
|
||||
const char* getStringDescriptor(uint8_t idx) {
|
||||
switch(idx) {
|
||||
case 0: return StrLanguageCodes;
|
||||
case 0: return StrLanguageCodes;
|
||||
case 1: return StrManufacturer;
|
||||
case 2: return StrProduct;
|
||||
case 3: return StrSerialNumber;
|
||||
case MS_OS_DESCRIPTOR_INDEX: return StrMS_OSDescriptor;
|
||||
default:
|
||||
default:
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ static void SpinDelay(int ms) {
|
|||
|
||||
// Borrow a PWM unit for my real-time clock
|
||||
AT91C_BASE_PWMC->PWMC_ENA = PWM_CHANNEL(0);
|
||||
|
||||
|
||||
// 48 MHz / 1024 gives 46.875 kHz
|
||||
AT91C_BASE_PWMC_CH0->PWMC_CMR = PWM_CH_MODE_PRESCALER(10);
|
||||
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0;
|
||||
|
@ -489,7 +489,7 @@ void usb_enable() {
|
|||
// Enables the 48MHz USB clock UDPCK and System Peripheral USB Clock
|
||||
AT91C_BASE_PMC->PMC_SCER |= AT91C_PMC_UDP;
|
||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDP);
|
||||
|
||||
|
||||
AT91C_BASE_UDP->UDP_FADDR = 0;
|
||||
AT91C_BASE_UDP->UDP_GLBSTATE = 0;
|
||||
|
||||
|
@ -507,7 +507,7 @@ void usb_enable() {
|
|||
SpinDelay(100);
|
||||
// Wait for a short while
|
||||
//for (volatile size_t i=0; i<0x100000; i++) {};
|
||||
|
||||
|
||||
// Reconnect USB reconnect
|
||||
AT91C_BASE_PIOA->PIO_SODR = GPIO_USB_PU;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_USB_PU;
|
||||
|
@ -533,23 +533,23 @@ int GetUSBconfigured(void){
|
|||
}
|
||||
|
||||
bool usb_check() {
|
||||
|
||||
|
||||
/*
|
||||
// reconnected ONCE and
|
||||
// reconnected ONCE and
|
||||
if ( !USB_ATTACHED() ){
|
||||
usb_reconnect = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// only one time after USB been disengaged and re-engaged
|
||||
|
||||
// only one time after USB been disengaged and re-engaged
|
||||
if ( USB_ATTACHED() && usb_reconnect == 1 ) {
|
||||
|
||||
if ( usb_configured == 0) {
|
||||
|
||||
if ( usb_configured == 0) {
|
||||
usb_disable();
|
||||
usb_enable();
|
||||
usb_enable();
|
||||
|
||||
AT91F_CDC_Enumerate();
|
||||
|
||||
|
||||
usb_configured = 1;
|
||||
return false;
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ bool usb_check() {
|
|||
else if (isr & AT91C_UDP_EPINT0) {
|
||||
pUdp->UDP_ICR = AT91C_UDP_EPINT0;
|
||||
AT91F_CDC_Enumerate();
|
||||
}
|
||||
}
|
||||
/*
|
||||
else if (isr & AT91C_UDP_EPINT3 ) {
|
||||
pUdp->UDP_ICR = AT91C_UDP_EPINT3;
|
||||
|
@ -608,20 +608,20 @@ bool usb_poll_validate_length() {
|
|||
//* \brief Read available data from Endpoint 1 OUT (host to device)
|
||||
//*----------------------------------------------------------------------------
|
||||
uint32_t usb_read(byte_t* data, size_t len) {
|
||||
|
||||
|
||||
if ( len == 0 ) return 0;
|
||||
|
||||
|
||||
uint8_t bank = btReceiveBank;
|
||||
uint32_t packetSize, nbBytesRcv = 0;
|
||||
uint32_t time_out = 0;
|
||||
|
||||
|
||||
while (len) {
|
||||
if (!usb_check()) break;
|
||||
|
||||
if ( pUdp->UDP_CSR[AT91C_EP_OUT] & bank ) {
|
||||
|
||||
|
||||
packetSize = (pUdp->UDP_CSR[AT91C_EP_OUT] & AT91C_UDP_RXBYTECNT) >> 16;
|
||||
packetSize = MIN( packetSize, len);
|
||||
packetSize = MIN( packetSize, len);
|
||||
len -= packetSize;
|
||||
while (packetSize--)
|
||||
data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT];
|
||||
|
@ -632,7 +632,7 @@ uint32_t usb_read(byte_t* data, size_t len) {
|
|||
if (bank == AT91C_UDP_RX_DATA_BK0)
|
||||
bank = AT91C_UDP_RX_DATA_BK1;
|
||||
else
|
||||
bank = AT91C_UDP_RX_DATA_BK0;
|
||||
bank = AT91C_UDP_RX_DATA_BK0;
|
||||
}
|
||||
if (time_out++ == 0x1fff) break;
|
||||
}
|
||||
|
@ -652,20 +652,20 @@ uint32_t usb_write(const byte_t* data, const size_t len) {
|
|||
|
||||
// can we write?
|
||||
if ( (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY) != 0 ) return 0;
|
||||
|
||||
|
||||
size_t length = len;
|
||||
uint32_t cpt = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
// send first chunk
|
||||
cpt = MIN(length, AT91C_EP_IN_SIZE);
|
||||
length -= cpt;
|
||||
while (cpt--) {
|
||||
pUdp->UDP_FDR[AT91C_EP_IN] = *data++;
|
||||
}
|
||||
|
||||
|
||||
UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
|
||||
|
||||
|
||||
while (length) {
|
||||
// Send next chunk
|
||||
cpt = MIN(length, AT91C_EP_IN_SIZE);
|
||||
|
@ -673,19 +673,19 @@ uint32_t usb_write(const byte_t* data, const size_t len) {
|
|||
while (cpt--) {
|
||||
pUdp->UDP_FDR[AT91C_EP_IN] = *data++;
|
||||
}
|
||||
|
||||
|
||||
// Wait for previous chunk to be sent
|
||||
// (iceman) when is the bankswapping done?
|
||||
while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) {
|
||||
if (!usb_check()) return length;
|
||||
}
|
||||
|
||||
|
||||
UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP);
|
||||
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP);
|
||||
UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Wait for the end of transfer
|
||||
while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) {
|
||||
if (!usb_check()) return length;
|
||||
|
@ -704,7 +704,7 @@ uint32_t usb_write(const byte_t* data, const size_t len) {
|
|||
void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length) {
|
||||
uint32_t cpt = 0;
|
||||
AT91_REG csr;
|
||||
|
||||
|
||||
do {
|
||||
cpt = MIN(length, AT91C_EP_CONTROL_SIZE);
|
||||
length -= cpt;
|
||||
|
@ -723,7 +723,7 @@ void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length) {
|
|||
csr = pUdp->UDP_CSR[AT91C_EP_CONTROL];
|
||||
// Data IN stage has been stopped by a status OUT
|
||||
if ( csr & AT91C_UDP_RX_DATA_BK0) {
|
||||
|
||||
|
||||
UDP_CLEAR_EP_FLAGS(AT91C_EP_CONTROL, AT91C_UDP_RX_DATA_BK0)
|
||||
return;
|
||||
}
|
||||
|
@ -736,14 +736,14 @@ void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length) {
|
|||
while (pUdp->UDP_CSR[AT91C_EP_CONTROL] & AT91C_UDP_TXCOMP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//*----------------------------------------------------------------------------
|
||||
//* \fn AT91F_USB_SendZlp
|
||||
//* \brief Send zero length packet through the control endpoint
|
||||
//*----------------------------------------------------------------------------
|
||||
void AT91F_USB_SendZlp(AT91PS_UDP pUdp) {
|
||||
UDP_SET_EP_FLAGS(AT91C_EP_CONTROL, AT91C_UDP_TXPKTRDY);
|
||||
UDP_SET_EP_FLAGS(AT91C_EP_CONTROL, AT91C_UDP_TXPKTRDY);
|
||||
while ( !(pUdp->UDP_CSR[AT91C_EP_CONTROL] & AT91C_UDP_TXCOMP) );
|
||||
UDP_CLEAR_EP_FLAGS(AT91C_EP_CONTROL, AT91C_UDP_TXCOMP);
|
||||
while (pUdp->UDP_CSR[AT91C_EP_CONTROL] & AT91C_UDP_TXCOMP);
|
||||
|
@ -763,7 +763,7 @@ void AT91F_USB_SendStall(AT91PS_UDP pUdp) {
|
|||
//*----------------------------------------------------------------------------
|
||||
//* \fn AT91F_CDC_Enumerate
|
||||
//* \brief This function is a callback invoked when a SETUP packet is received
|
||||
//* problem:
|
||||
//* problem:
|
||||
//* 1. this is for USB endpoint0. the control endpoint.
|
||||
//* 2. mixed with CDC ACM endpoint3 , interrupt, control endpoint
|
||||
//*----------------------------------------------------------------------------
|
||||
|
@ -796,22 +796,22 @@ void AT91F_CDC_Enumerate() {
|
|||
if ( wIndex == MS_EXTENDED_COMPAT_ID ) { // 4
|
||||
//AT91F_USB_SendData(pUdp, CompatIDFeatureDescriptor, MIN(sizeof(CompatIDFeatureDescriptor), wLength));
|
||||
//return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( bmRequestType == MS_WCID_GET_FEATURE_DESCRIPTOR ) { //C1
|
||||
// if ( wIndex == MS_EXTENDED_PROPERTIES ) { // 5 - winusb bug with wIndex == interface index, so I just send it always)
|
||||
//AT91F_USB_SendData(pUdp, OSprop, MIN(sizeof(OSprop), wLength));
|
||||
//return;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Handle supported standard device request Cf Table 9-3 in USB specification Rev 1.1
|
||||
switch ((bRequest << 8) | bmRequestType) {
|
||||
case STD_GET_DESCRIPTOR: {
|
||||
|
||||
|
||||
if ( wValue == 0x100 ) // Return Device Descriptor
|
||||
AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength));
|
||||
else if ( wValue == 0x200 ) // Return Configuration Descriptor
|
||||
|
@ -837,25 +837,25 @@ void AT91F_CDC_Enumerate() {
|
|||
pUdp->UDP_GLBSTATE = (wValue) ? AT91C_UDP_FADDEN : 0;
|
||||
break;
|
||||
case STD_SET_CONFIGURATION:
|
||||
|
||||
/*
|
||||
* Set or clear the device "configured" state.
|
||||
* The LSB of wValue is the "Configuration Number". If this value is non-zero,
|
||||
* it should be the same number as defined in the Configuration Descriptor;
|
||||
* otherwise an error must have occurred.
|
||||
* This device has only one configuration and its Config Number is CONF_NB (= 1).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set or clear the device "configured" state.
|
||||
* The LSB of wValue is the "Configuration Number". If this value is non-zero,
|
||||
* it should be the same number as defined in the Configuration Descriptor;
|
||||
* otherwise an error must have occurred.
|
||||
* This device has only one configuration and its Config Number is CONF_NB (= 1).
|
||||
*/
|
||||
AT91F_USB_SendZlp(pUdp);
|
||||
btConfiguration = wValue;
|
||||
pUdp->UDP_GLBSTATE = (wValue) ? AT91C_UDP_CONFG : AT91C_UDP_FADDEN;
|
||||
|
||||
|
||||
// make sure we are not stalled
|
||||
/*
|
||||
UDP_CLEAR_EP_FLAGS(AT91C_EP_OUT , AT91C_UDP_FORCESTALL);
|
||||
UDP_CLEAR_EP_FLAGS(AT91C_EP_IN , AT91C_UDP_FORCESTALL);
|
||||
UDP_CLEAR_EP_FLAGS(AT91C_EP_NOTIFY, AT91C_UDP_FORCESTALL);
|
||||
*/
|
||||
|
||||
|
||||
// enable endpoints
|
||||
pUdp->UDP_CSR[AT91C_EP_OUT] = (wValue) ? (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_BULK_OUT) : 0;
|
||||
pUdp->UDP_CSR[AT91C_EP_IN] = (wValue) ? (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_BULK_IN) : 0;
|
||||
|
@ -924,8 +924,8 @@ void AT91F_CDC_Enumerate() {
|
|||
// handle CDC class requests
|
||||
case SET_LINE_CODING: {
|
||||
/*
|
||||
uint8_t i;
|
||||
for ( i = 0 ; i < 7 ; i++ ) {
|
||||
uint8_t i;
|
||||
for ( i = 0 ; i < 7 ; i++ ) {
|
||||
((uint8_t*)&line)[i] = pUdp->UDP_FDR[AT91C_EP_CONTROL];
|
||||
} */
|
||||
// ignore SET_LINE_CODING...
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include <wchar.h>
|
||||
#include "at91sam7s512.h"
|
||||
#include "config_gpio.h"
|
||||
#include "config_gpio.h"
|
||||
#include "proxmark3.h" // USB_CONNECT()
|
||||
#include "common.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
uint8_t getParity( uint8_t *bits, uint8_t len, uint8_t type ) {
|
||||
uint8_t x = 0;
|
||||
for(; len > 0; --len)
|
||||
for(; len > 0; --len)
|
||||
x += bits[len - 1];
|
||||
|
||||
return (x & 1 ) ^ type;
|
||||
|
@ -35,7 +35,7 @@ uint8_t checkParity(uint32_t bits, uint8_t len, uint8_t type);
|
|||
|
||||
// by marshmellow
|
||||
// takes a array of binary values, start position, length of bits per parity (includes parity bit),
|
||||
// Parity Type (1 for odd; 0 for even; 2 for Always 1's; 3 for Always 0's), and binary Length (length to run)
|
||||
// Parity Type (1 for odd; 0 for even; 2 for Always 1's; 3 for Always 0's), and binary Length (length to run)
|
||||
size_t removeParity(uint8_t *bitstream, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen) {
|
||||
uint32_t parityWd = 0;
|
||||
size_t j = 0, bitcount = 0;
|
||||
|
@ -69,10 +69,10 @@ size_t removeParity(uint8_t *bitstream, size_t startIdx, uint8_t pLen, uint8_t p
|
|||
* @brief addParity
|
||||
* @param bits pointer to the source bitstream of binary values
|
||||
* @param dest pointer to the destination where parities together with bits are added.
|
||||
* @param sourceLen number of
|
||||
* @param sourceLen number of
|
||||
* @param pLen length bits to be checked
|
||||
* @param pType EVEN|ODD|2 (always 1's)|3 (always 0's)
|
||||
* @return
|
||||
* @return
|
||||
*/
|
||||
size_t addParity(uint8_t *bits, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType)
|
||||
{
|
||||
|
@ -83,12 +83,12 @@ size_t addParity(uint8_t *bits, uint8_t *dest, uint8_t sourceLen, uint8_t pLen,
|
|||
parityWd = (parityWd << 1) | bits[word+bit];
|
||||
dest[j++] = (bits[word+bit]);
|
||||
}
|
||||
|
||||
|
||||
// if parity fails then return 0
|
||||
switch (pType) {
|
||||
case 3: dest[j++] = 0; break; // marker bit which should be a 0
|
||||
case 2: dest[j++] = 1; break; // marker bit which should be a 1
|
||||
default:
|
||||
default:
|
||||
dest[j++] = parityTest(parityWd, pLen-1, pType) ^ 1;
|
||||
break;
|
||||
}
|
||||
|
@ -115,34 +115,34 @@ void wiegand_add_parity(uint8_t *source, uint8_t *dest, uint8_t len) {
|
|||
|
||||
// half length, Even and Odd is calculated to the middle.
|
||||
uint8_t len_h2 = length >> 1;
|
||||
|
||||
|
||||
// add EVEN parity at the beginning
|
||||
*(dest) = GetParity(source, EVEN, len_h2);
|
||||
|
||||
|
||||
dest += length + 1;
|
||||
|
||||
|
||||
// add ODD parity at the very end
|
||||
*(dest) = GetParity(source + len_h2, ODD, len_h2);
|
||||
}
|
||||
|
||||
//uint32_t bytebits_to_byte(uint8_t* src, size_t numbits);
|
||||
#define MAX_BITS_TXX55 6*4*8
|
||||
#define MAX_BYTES_TXX55 6*4
|
||||
#define MAX_BYTES_TXX55 6*4
|
||||
/*
|
||||
* @brief num_to_wiegand_bytes
|
||||
* @param oem Sometimes call FF Fixfield, SiteCode. Used in a few formats
|
||||
* @param fc Facility code
|
||||
* @param fc Facility code
|
||||
* @param cn Card number
|
||||
* @param dest pointer to the destination where wiegand bytes will be stored
|
||||
* @param formatlen
|
||||
* @param formatlen
|
||||
*/
|
||||
void num_to_wiegand_bytes(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest, uint8_t formatlen){
|
||||
|
||||
uint8_t data[MAX_BITS_TXX55] = {0};
|
||||
memset(data, 0, sizeof(data));
|
||||
|
||||
|
||||
num_to_wiegand_bits(oem, fc, cn, data, formatlen);
|
||||
|
||||
|
||||
// loop
|
||||
// (formatlen / 32 ) + 1
|
||||
// (formatlen >> 5) + 1
|
||||
|
@ -150,15 +150,15 @@ void num_to_wiegand_bytes(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest,
|
|||
uint32_t value = bytebits_to_byte( data + (i * 32), 32);
|
||||
num_to_bytes(value, 32, dest + (i*4) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* @brief num_to_wiegand_bits
|
||||
* @param oem Sometimes call FF Fixfield, SiteCode. Used in a few formats
|
||||
* @param fc Facility code
|
||||
* @param fc Facility code
|
||||
* @param cn Card number
|
||||
* @param dest pointer to the destination where wiegand bits will be stored
|
||||
* @param formatlen
|
||||
* @param formatlen
|
||||
*/
|
||||
void num_to_wiegand_bits(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest, uint8_t formatlen){
|
||||
|
||||
|
@ -166,8 +166,8 @@ void num_to_wiegand_bits(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest,
|
|||
memset(bits, 0, sizeof(bits));
|
||||
uint8_t *temp = bits;
|
||||
uint64_t value = 0;
|
||||
|
||||
switch ( formatlen ){
|
||||
|
||||
switch ( formatlen ){
|
||||
case 26 : // 26bit HID H10301
|
||||
fc &= 0xFF; // 8bits
|
||||
cn &= 0xFFFF; // 16bits
|
||||
|
@ -175,26 +175,26 @@ void num_to_wiegand_bits(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest,
|
|||
num_to_bytebits(value, 24, temp);
|
||||
wiegand_add_parity(temp, dest, 24);
|
||||
break;
|
||||
case 261: // 26bit Indala
|
||||
case 261: // 26bit Indala
|
||||
fc &= 0xFFF; // 12bits
|
||||
cn &= 0xFFF; // 12bits
|
||||
value = fc << 12 | cn;
|
||||
num_to_bytebits(value, 24, temp);
|
||||
wiegand_add_parity(temp, dest, 24);
|
||||
wiegand_add_parity(temp, dest, 24);
|
||||
break;
|
||||
case 34 : // 34bits HID
|
||||
fc &= 0xFFFF; // 16bits
|
||||
cn &= 0xFFFF; // 16bits
|
||||
value = fc << 16 | cn;
|
||||
num_to_bytebits(value, 32, temp);
|
||||
wiegand_add_parity(temp, dest, 32);
|
||||
wiegand_add_parity(temp, dest, 32);
|
||||
break;
|
||||
case 35 : // 35bits HID
|
||||
fc &= 0xFFF; // 12bits
|
||||
cn &= 0xFFFFFF; // 20bits
|
||||
value = fc << 20 | cn;
|
||||
num_to_bytebits(value, 32, temp);
|
||||
wiegand_add_parity(temp, dest, 32);
|
||||
wiegand_add_parity(temp, dest, 32);
|
||||
break;
|
||||
case 37 : // H10304
|
||||
fc &= 0xFFFF; // 16bits
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue