1 | /*
|
---|
2 | atr.h
|
---|
3 | ISO 7816 ICC's answer to reset abstract data type definitions
|
---|
4 |
|
---|
5 | This file is part of the Unix driver for Towitoko smartcard readers
|
---|
6 | Copyright (C) 2000 Carlos Prados <cprados@yahoo.com>
|
---|
7 |
|
---|
8 | This version is modified by doz21 to work in a special manner ;)
|
---|
9 |
|
---|
10 | This library is free software; you can redistribute it and/or
|
---|
11 | modify it under the terms of the GNU Lesser General Public
|
---|
12 | License as published by the Free Software Foundation; either
|
---|
13 | version 2 of the License, or (at your option) any later version.
|
---|
14 |
|
---|
15 | This library is distributed in the hope that it will be useful,
|
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | Lesser General Public License for more details.
|
---|
19 |
|
---|
20 | You should have received a copy of the GNU Lesser General Public
|
---|
21 | License along with this library; if not, write to the Free Software
|
---|
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
23 | */
|
---|
24 |
|
---|
25 | #ifndef _ATR_
|
---|
26 | #define _ATR_
|
---|
27 |
|
---|
28 | #include "defines.h"
|
---|
29 | #include "io_serial.h"
|
---|
30 |
|
---|
31 | /*
|
---|
32 | * Exported constants definition
|
---|
33 | */
|
---|
34 |
|
---|
35 | /* Return values */
|
---|
36 | #define ATR_OK 0 /* ATR could be parsed and data returned */
|
---|
37 | #define ATR_NOT_FOUND 1 /* Data not present in ATR */
|
---|
38 | #define ATR_MALFORMED 2 /* ATR could not be parsed */
|
---|
39 | #define ATR_IO_ERROR 2 /* I/O stream error */
|
---|
40 |
|
---|
41 | /* Paramenters */
|
---|
42 | #define ATR_MAX_SIZE 33 /* Maximum size of ATR byte array */
|
---|
43 | #define ATR_MAX_HISTORICAL 15 /* Maximum number of historical bytes */
|
---|
44 | #define ATR_MAX_PROTOCOLS 7 /* Maximun number of protocols */
|
---|
45 | #define ATR_MAX_IB 4 /* Maximum number of interface bytes per protocol */
|
---|
46 | #define ATR_CONVENTION_DIRECT 0 /* Direct convention */
|
---|
47 | #define ATR_CONVENTION_INVERSE 1 /* Inverse convention */
|
---|
48 | #define ATR_PROTOCOL_TYPE_T0 0 /* Protocol type T=0 */
|
---|
49 | #define ATR_PROTOCOL_TYPE_T1 1 /* Protocol type T=1 */
|
---|
50 | #define ATR_PROTOCOL_TYPE_T2 2 /* Protocol type T=2 */
|
---|
51 | #define ATR_PROTOCOL_TYPE_T3 3 /* Protocol type T=3 */
|
---|
52 | #define ATR_PROTOCOL_TYPE_T14 14 /* Protocol type T=14 */
|
---|
53 | #define ATR_INTERFACE_BYTE_TA 0 /* Interface byte TAi */
|
---|
54 | #define ATR_INTERFACE_BYTE_TB 1 /* Interface byte TBi */
|
---|
55 | #define ATR_INTERFACE_BYTE_TC 2 /* Interface byte TCi */
|
---|
56 | #define ATR_INTERFACE_BYTE_TD 3 /* Interface byte TDi */
|
---|
57 | #define ATR_PARAMETER_F 0 /* Parameter F */
|
---|
58 | #define ATR_PARAMETER_D 1 /* Parameter D */
|
---|
59 | #define ATR_PARAMETER_I 2 /* Parameter I */
|
---|
60 | #define ATR_PARAMETER_P 3 /* Parameter P */
|
---|
61 | #define ATR_PARAMETER_N 4 /* Parameter N */
|
---|
62 | #define ATR_INTEGER_VALUE_FI 0 /* Integer value FI */
|
---|
63 | #define ATR_INTEGER_VALUE_DI 1 /* Integer value DI */
|
---|
64 | #define ATR_INTEGER_VALUE_II 2 /* Integer value II */
|
---|
65 | #define ATR_INTEGER_VALUE_PI1 3 /* Integer value PI1 */
|
---|
66 | #define ATR_INTEGER_VALUE_N 4 /* Integer value N */
|
---|
67 | #define ATR_INTEGER_VALUE_PI2 5 /* Integer value PI2 */
|
---|
68 |
|
---|
69 | /* Default values for paramenters */
|
---|
70 | #define ATR_DEFAULT_FI 1
|
---|
71 | #define ATR_DEFAULT_D 1
|
---|
72 | #define ATR_DEFAULT_I 50
|
---|
73 | #define ATR_DEFAULT_N 0
|
---|
74 | #define ATR_DEFAULT_P 5
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * Exported data types definition
|
---|
78 | */
|
---|
79 |
|
---|
80 | typedef struct
|
---|
81 | {
|
---|
82 | unsigned length;
|
---|
83 | BYTE TS;
|
---|
84 | BYTE T0;
|
---|
85 | struct
|
---|
86 | {
|
---|
87 | BYTE value;
|
---|
88 | bool present;
|
---|
89 | }
|
---|
90 | ib[ATR_MAX_PROTOCOLS][ATR_MAX_IB], TCK;
|
---|
91 | unsigned pn;
|
---|
92 | BYTE hb[ATR_MAX_HISTORICAL];
|
---|
93 | unsigned hbn;
|
---|
94 | }
|
---|
95 | ATR;
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Exported variables declaration
|
---|
99 | */
|
---|
100 |
|
---|
101 | extern unsigned long atr_fs_table[16];
|
---|
102 | extern unsigned atr_f_table[16];
|
---|
103 | extern double atr_d_table[16];
|
---|
104 | extern unsigned atr_i_table[4];
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * Exported functions declaraton
|
---|
108 | */
|
---|
109 |
|
---|
110 | /* Creation and deletion */
|
---|
111 | extern ATR *ATR_New (void);
|
---|
112 | extern void ATR_Delete (ATR * atr);
|
---|
113 |
|
---|
114 | /* Initialization */
|
---|
115 | extern int ATR_InitFromArray (ATR * atr, BYTE buffer[ATR_MAX_SIZE], unsigned length);
|
---|
116 | extern int ATR_InitFromStream (ATR * atr, unsigned timeout);
|
---|
117 |
|
---|
118 | /* General smartcard characteristics */
|
---|
119 | extern int ATR_GetConvention (ATR * atr, int *convention);
|
---|
120 | extern int ATR_GetNumberOfProtocols (ATR * atr, unsigned *number_protocols);
|
---|
121 | extern int ATR_GetProtocolType (ATR * atr, unsigned number_protocol, BYTE *protocol_type);
|
---|
122 |
|
---|
123 | /* ATR parameters and integer values */
|
---|
124 | extern int ATR_GetInterfaceByte (ATR * atr, unsigned number, int character, BYTE * ib);
|
---|
125 | extern int ATR_GetIntegerValue (ATR * atr, int name, BYTE * value);
|
---|
126 | extern int ATR_GetParameter (ATR * atr, int name, double *parameter);
|
---|
127 | extern int ATR_GetHistoricalBytes (ATR * atr, BYTE * hist, unsigned *length);
|
---|
128 | extern int ATR_GetCheckByte (ATR * atr, BYTE * check_byte);
|
---|
129 | extern int ATR_GetFsMax (ATR * atr, unsigned long *fsmax);
|
---|
130 |
|
---|
131 | /* Raw ATR retrieving */
|
---|
132 | extern int ATR_GetRaw (ATR * atr, BYTE * buffer, unsigned *lenght);
|
---|
133 | extern int ATR_GetSize (ATR * atr, unsigned *size);
|
---|
134 |
|
---|
135 | #endif /* _ATR_ */
|
---|