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 library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public License 19 along with this library; if not, write to the Free Software Foundation, 20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21*/ 22 23#ifndef _ATR_ 24#define _ATR_ 25 26#include "defines.h" 27 28/* 29 * Exported constants definition 30 */ 31 32/* Return values */ 33#define ATR_OK 0 /* ATR could be parsed and data returned */ 34#define ATR_NOT_FOUND 1 /* Data not present in ATR */ 35#define ATR_MALFORMED 2 /* ATR could not be parsed */ 36#define ATR_IO_ERROR 3 /* I/O stream error */ 37 38/* Paramenters */ 39#define ATR_MAX_SIZE 33 /* Maximum size of ATR byte array */ 40#define ATR_MAX_HISTORICAL 15 /* Maximum number of historical bytes */ 41#define ATR_MAX_PROTOCOLS 7 /* Maximun number of protocols */ 42#define ATR_MAX_IB 4 /* Maximum number of interface bytes per protocol */ 43#define ATR_CONVENTION_DIRECT 0 /* Direct convention */ 44#define ATR_CONVENTION_INVERSE 1 /* Inverse convention */ 45#define ATR_PROTOCOL_TYPE_T0 0 /* Protocol type T=0 */ 46#define ATR_PROTOCOL_TYPE_T1 1 /* Protocol type T=1 */ 47#define ATR_PROTOCOL_TYPE_T2 2 /* Protocol type T=2 */ 48#define ATR_PROTOCOL_TYPE_T3 3 /* Protocol type T=3 */ 49#define ATR_PROTOCOL_TYPE_T14 14 /* Protocol type T=14 */ 50#define ATR_INTERFACE_BYTE_TA 0 /* Interface byte TAi */ 51#define ATR_INTERFACE_BYTE_TB 1 /* Interface byte TBi */ 52#define ATR_INTERFACE_BYTE_TC 2 /* Interface byte TCi */ 53#define ATR_INTERFACE_BYTE_TD 3 /* Interface byte TDi */ 54#define ATR_PARAMETER_F 0 /* Parameter F */ 55#define ATR_PARAMETER_D 1 /* Parameter D */ 56#define ATR_PARAMETER_I 2 /* Parameter I */ 57#define ATR_PARAMETER_P 3 /* Parameter P */ 58#define ATR_PARAMETER_N 4 /* Parameter N */ 59#define ATR_INTEGER_VALUE_FI 0 /* Integer value FI */ 60#define ATR_INTEGER_VALUE_DI 1 /* Integer value DI */ 61#define ATR_INTEGER_VALUE_II 2 /* Integer value II */ 62#define ATR_INTEGER_VALUE_PI1 3 /* Integer value PI1 */ 63#define ATR_INTEGER_VALUE_N 4 /* Integer value N */ 64#define ATR_INTEGER_VALUE_PI2 5 /* Integer value PI2 */ 65 66/* Default values for paramenters */ 67#define ATR_DEFAULT_F 372 68#define ATR_DEFAULT_D 1 69#define ATR_DEFAULT_I 50 70#define ATR_DEFAULT_N 0 71#define ATR_DEFAULT_P 5 72 73/* 74 * Exported data types definition 75 */ 76 77typedef struct 78{ 79 unsigned length; 80 BYTE TS; 81 BYTE T0; 82 struct 83 { 84 BYTE value; 85 bool present; 86 } 87 ib[ATR_MAX_PROTOCOLS][ATR_MAX_IB], TCK; 88 unsigned pn; 89 BYTE hb[ATR_MAX_HISTORICAL]; 90 unsigned hbn; 91} 92ATR_t; 93 94/* 95 * Exported functions declaraton 96 */ 97 98/* Initialization */ 99extern int ATR_InitFromArray(ATR_t * atr, const BYTE buffer[ATR_MAX_SIZE], 100 unsigned length); 101 102/* General smartcard characteristics */ 103extern int ATR_GetConvention(ATR_t * atr, /*@out@*/ int *convention); 104extern int ATR_GetDefaultProtocol(ATR_t * atr, /*@out@*/ int *protocol); 105 106/* ATR parameters and integer values */ 107extern int ATR_GetIntegerValue(ATR_t * atr, int name, BYTE * value); 108extern int ATR_GetParameter(ATR_t * atr, int name, /*@out@*/ double *parameter); 109 110#endif /* _ATR_ */ 111 112