1 |
2f730c90
|
henryk
|
#ifndef ISO14443_H_
|
2 |
|
|
#define ISO14443_H_
|
3 |
|
|
|
4 |
|
|
/******************** RX ************************************/
|
5 |
|
|
#define ISO14443_BITS_PER_SSC_TRANSFER 4
|
6 |
|
|
|
7 |
|
|
#ifdef FOUR_TIMES_OVERSAMPLING
|
8 |
|
|
/* definitions for four-times oversampling */
|
9 |
|
|
#define ISO14443A_SAMPLE_LEN 4
|
10 |
|
|
/* Sample values for the REQA and WUPA short frames */
|
11 |
|
|
#define REQA 0x10410441
|
12 |
|
|
#define WUPA 0x04041041
|
13 |
|
|
|
14 |
|
|
/* Start of frame sample for SSC compare 0 */
|
15 |
|
|
#define ISO14443A_SOF_SAMPLE 0x01
|
16 |
|
|
#define ISO14443A_SOF_LEN 4
|
17 |
|
|
/* Length in samples of a short frame */
|
18 |
|
|
#define ISO14443A_SHORT_LEN 32
|
19 |
|
|
/* This is wrong: a short frame is 1 start bit, 7 data bits, 1 stop bit
|
20 |
|
|
* followed by no modulation for one bit period. The start bit is 'eaten' in
|
21 |
|
|
* SSC Compare 0, but the remaining 7+1+1 bit durations must be sampled and
|
22 |
|
|
* compared. At four times oversampling this would be 9*4=36 samples, which is
|
23 |
|
|
* more than one SSC transfer. You'd have to use two transfers of 18 samples
|
24 |
|
|
* each and modify the comparison code accordingly.
|
25 |
|
|
* Since four times oversampling doesn't work reliably anyway (every second
|
26 |
|
|
* sample is near an edge and might sample 0 or 1) this doesn't matter for now.*/
|
27 |
|
|
#error Four times oversampling is broken, see comments in code
|
28 |
|
|
|
29 |
|
|
#else
|
30 |
|
|
/* definitions for two-times oversampling */
|
31 |
|
|
#define ISO14443A_SAMPLE_LEN 2
|
32 |
|
|
|
33 |
|
|
/* For SSC_MODE_ISO14443A_SHORT */
|
34 |
|
|
#define ISO14443A_SHORT_LEN 18
|
35 |
|
|
#define REQA 0x4929
|
36 |
|
|
#define WUPA 0x2249
|
37 |
|
|
|
38 |
|
|
#define ISO14443A_SOF_SAMPLE 0x01
|
39 |
|
|
#define ISO14443A_SOF_LEN 2
|
40 |
|
|
|
41 |
|
|
#define ISO14443A_EOF_SAMPLE 0x00
|
42 |
|
|
#define ISO14443A_EOF_LEN 7
|
43 |
|
|
|
44 |
|
|
/* For SSC_MODE_ISO14443A */
|
45 |
|
|
#define ISO14443A_SHORT_FRAME_COMPARE_LENGTH 2
|
46 |
|
|
#define _ISO14443A_SHORT_FRAME_REQA { 0x29, 0x49 }
|
47 |
|
|
#define _ISO14443A_SHORT_FRAME_WUPA { 0x49, 0x22 }
|
48 |
|
|
// FIXME not correct. This should be compare_length == 3 (which is 9 samples at 4 per compare), but this
|
49 |
|
|
// needs enhanced ssc irq code to transfer the last read (incomplete) data from the ssc holding
|
50 |
|
|
// register to the buffer
|
51 |
|
|
|
52 |
|
|
#endif
|
53 |
|
|
|
54 |
|
|
/* A short frame should be received in one single SSC transfer */
|
55 |
|
|
#if (ISO14443A_SHORT_LEN <= 8)
|
56 |
|
|
/* SSC transfer size in bits */
|
57 |
|
|
#define ISO14443A_SHORT_TRANSFER_SIZE 8
|
58 |
|
|
#define ISO14443A_SHORT_TYPE u_int8_t
|
59 |
|
|
|
60 |
|
|
#elif (ISO14443A_SHORT_LEN <= 16)
|
61 |
|
|
#define ISO14443A_SHORT_TRANSFER_SIZE 16
|
62 |
|
|
#define ISO14443A_SHORT_TYPE u_int16_t
|
63 |
|
|
|
64 |
|
|
#elif (ISO14443A_SHORT_LEN <= 32)
|
65 |
|
|
#define ISO14443A_SHORT_TRANSFER_SIZE 32
|
66 |
|
|
#define ISO14443A_SHORT_TYPE u_int32_t
|
67 |
|
|
|
68 |
|
|
#else
|
69 |
|
|
#error ISO14443A_SHORT_LEN defined too big
|
70 |
|
|
#endif
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
/******************** RX and TX *****************************/
|
74 |
|
|
/* in bytes, not counting parity */
|
75 |
|
|
#define MAXIMUM_FRAME_SIZE 256
|
76 |
|
|
#define ISO14443A_MAX_RX_FRAME_SIZE_IN_BITS (MAXIMUM_FRAME_SIZE*9 +2)
|
77 |
|
|
|
78 |
e2e37bea
|
henryk
|
typedef enum {
|
79 |
|
|
FRAME_FREE=0, /* Frame is free */
|
80 |
|
|
FRAME_PENDING, /* Frame is currently filled by Rx */
|
81 |
|
|
FRAME_FULL, /* Frame has been filled by Rx */
|
82 |
|
|
FRAME_PROCESSING,/* The frame is currently processed by the consumer */
|
83 |
f7a420f2
|
henryk
|
FRAME_PREFILLED, /* The frame has been prefilled for later usage (only used for TX) */
|
84 |
e2e37bea
|
henryk
|
} iso14443_frame_state_t;
|
85 |
|
|
|
86 |
|
|
|
87 |
2f730c90
|
henryk
|
typedef struct {
|
88 |
|
|
enum { TYPE_A, TYPE_B } type;
|
89 |
e2e37bea
|
henryk
|
iso14443_frame_state_t state;
|
90 |
2f730c90
|
henryk
|
union {
|
91 |
|
|
struct {
|
92 |
|
|
enum { SHORT_FRAME, STANDARD_FRAME, AC_FRAME } format;
|
93 |
|
|
enum { PARITY, /* Calculate parity on the fly, ignore the parity field below */
|
94 |
|
|
GIVEN_PARITY, /* Use the parity bits from the parity field below */
|
95 |
|
|
NO_PARITY, /* Don't send any parity */
|
96 |
|
|
} parity;
|
97 |
|
|
enum { ISO14443A_LAST_BIT_0 = 0, ISO14443A_LAST_BIT_1 = 1, ISO14443A_LAST_BIT_NONE } last_bit;
|
98 |
6304718e
|
henryk
|
enum { CRC_UNCALCULATED = 2, CRC_OK = 1, CRC_ERROR = 0} crc;
|
99 |
2f730c90
|
henryk
|
} a;
|
100 |
|
|
} parameters;
|
101 |
|
|
u_int32_t numbytes;
|
102 |
|
|
u_int8_t numbits, bit_offset;
|
103 |
|
|
u_int8_t data[MAXIMUM_FRAME_SIZE];
|
104 |
|
|
u_int8_t parity[MAXIMUM_FRAME_SIZE/8+1]; /* parity bit for data[x] is in parity[x/8] & (1<<(x%8)) */
|
105 |
|
|
} iso14443_frame;
|
106 |
|
|
|
107 |
|
|
#endif /*ISO14443_H_*/
|