- fix for Browser localStorage (thanks to ohmza)
[oscam.git] / csctapi / atr.h
blob5880bf59641277c1dd597129b111c976f1f532ca
1 /*
2 atr.h
3 ISO 7816 ICC's answer to reset abstract data type definitions
5 This file is part of the Unix driver for Towitoko smartcard readers
6 Copyright (C) 2000 Carlos Prados <cprados@yahoo.com>
8 This version is modified by doz21 to work in a special manner ;)
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.
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.
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
25 #ifndef _ATR_
26 #define _ATR_
29 * Exported constants definition
31 #define ATR_TIMEOUT 1000000
32 #define DEFAULT_BAUDRATE 9600
34 /* Return values */
35 #define ATR_OK 0 /* ATR could be parsed and data returned */
36 #define ATR_NOT_FOUND 1 /* Data not present in ATR */
37 #define ATR_MALFORMED 2 /* ATR could not be parsed */
38 #define ATR_IO_ERROR 2 /* I/O stream error */
40 /* Paramenters */
41 #define ATR_MAX_SIZE 33 /* Maximum size of ATR byte array */
42 #define ATR_MAX_HISTORICAL 15 /* Maximum number of historical bytes */
43 #define ATR_MAX_PROTOCOLS 7 /* Maximun number of protocols */
44 #define ATR_MAX_IB 4 /* Maximum number of interface bytes per protocol */
45 #define ATR_CONVENTION_DIRECT 0 /* Direct convention */
46 #define ATR_CONVENTION_INVERSE 1 /* Inverse convention */
47 #define ATR_PROTOCOL_TYPE_T0 0 /* Protocol type T=0 */
48 #define ATR_PROTOCOL_TYPE_T1 1 /* Protocol type T=1 */
49 #define ATR_PROTOCOL_TYPE_T2 2 /* Protocol type T=2 */
50 #define ATR_PROTOCOL_TYPE_T3 3 /* Protocol type T=3 */
51 #define ATR_PROTOCOL_TYPE_T14 14 /* Protocol type T=14 */
52 #define ATR_INTERFACE_BYTE_TA 0 /* Interface byte TAi */
53 #define ATR_INTERFACE_BYTE_TB 1 /* Interface byte TBi */
54 #define ATR_INTERFACE_BYTE_TC 2 /* Interface byte TCi */
55 #define ATR_INTERFACE_BYTE_TD 3 /* Interface byte TDi */
56 #define ATR_PARAMETER_F 0 /* Parameter F */
57 #define ATR_PARAMETER_D 1 /* Parameter D */
58 #define ATR_PARAMETER_I 2 /* Parameter I */
59 #define ATR_PARAMETER_P 3 /* Parameter P */
60 #define ATR_PARAMETER_N 4 /* Parameter N */
61 #define ATR_INTEGER_VALUE_FI 0 /* Integer value FI */
62 #define ATR_INTEGER_VALUE_DI 1 /* Integer value DI */
63 #define ATR_INTEGER_VALUE_II 2 /* Integer value II */
64 #define ATR_INTEGER_VALUE_PI1 3 /* Integer value PI1 */
65 #define ATR_INTEGER_VALUE_N 4 /* Integer value N */
66 #define ATR_INTEGER_VALUE_PI2 5 /* Integer value PI2 */
68 /* Default values for paramenters */
69 #define ATR_DEFAULT_FI 1
70 #define ATR_DEFAULT_D 1
71 #define ATR_DEFAULT_I 50
72 #define ATR_DEFAULT_N 0
73 #define ATR_DEFAULT_P 5
76 * Exported data types definition
79 typedef struct s_ATR
81 unsigned length;
82 unsigned char TS;
83 unsigned char T0;
84 struct
86 unsigned char value;
87 bool present;
89 ib[ATR_MAX_PROTOCOLS][ATR_MAX_IB], TCK;
90 unsigned pn;
91 unsigned char hb[ATR_MAX_HISTORICAL];
92 unsigned hbn;
94 ATR;
97 * Exported variables declaration
100 extern const uint32_t atr_fs_table[16];
101 extern const uint32_t atr_f_table[16];
102 extern const double atr_d_table[16];
105 * Exported functions declaraton
108 /* Initialization */
109 int32_t ATR_InitFromArray(ATR *atr, const unsigned char buffer[ATR_MAX_SIZE], uint32_t length);
111 /* General smartcard characteristics */
112 int32_t ATR_GetConvention(ATR *atr, int32_t *convention);
113 int32_t ATR_GetNumberOfProtocols(ATR *atr, uint32_t *number_protocols);
114 int32_t ATR_GetProtocolType(ATR *atr, uint32_t number_protocol, unsigned char *protocol_type);
116 /* ATR parameters and integer values */
117 int32_t ATR_GetInterfaceByte(ATR *atr, uint32_t number, int32_t character, unsigned char *ib);
118 int32_t ATR_GetIntegerValue(ATR *atr, int32_t name, unsigned char *value);
119 int32_t ATR_GetParameter(ATR *atr, int32_t name, uint32_t *parameter);
120 int32_t ATR_GetHistoricalBytes(ATR *atr, unsigned char *hist, uint32_t *length);
121 int32_t ATR_GetCheckByte(ATR *atr, unsigned char *check_byte);
122 int32_t ATR_GetFsMax(ATR *atr, uint32_t *fsmax);
124 /* Raw ATR retrieving */
125 int32_t ATR_GetRaw(ATR *atr, unsigned char *buffer, uint32_t *length);
126 int32_t ATR_GetSize(ATR *atr, uint32_t *size);
128 /* Invert order of bits in a byte: b7->b0, b0->b7 */
129 #ifndef INVERT_BYTE
130 #define INVERT_BYTE(a) ( \
131 (((a) << 7) & 0x80) | \
132 (((a) << 5) & 0x40) | \
133 (((a) << 3) & 0x20) | \
134 (((a) << 1) & 0x10) | \
135 (((a) >> 1) & 0x08) | \
136 (((a) >> 3) & 0x04) | \
137 (((a) >> 5) & 0x02) | \
138 (((a) >> 7) & 0x01) \
140 #endif
142 #endif /* _ATR_ */