1/* 2 proto-t1.h: header file for proto-t1.c 3 Copyright (C) 2004 Ludovic Rousseau 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public License 16 along with this library; if not, write to the Free Software Foundation, 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18*/ 19 20/* $Id: proto-t1.h 3292 2009-01-26 13:02:58Z rousseau $ */ 21 22#ifndef __PROTO_T1_H__ 23#define __PROTO_T1_H__ 24 25#include "config.h" 26#ifdef HAVE_STDINT_H 27#include <stdint.h> 28#endif 29#include <unistd.h> 30 31#include "buffer.h" 32 33/* T=1 protocol constants */ 34#define T1_I_BLOCK 0x00 35#define T1_R_BLOCK 0x80 36#define T1_S_BLOCK 0xC0 37#define T1_MORE_BLOCKS 0x20 38 39enum { 40 IFD_PROTOCOL_RECV_TIMEOUT = 0x0000, 41 IFD_PROTOCOL_T1_BLOCKSIZE, 42 IFD_PROTOCOL_T1_CHECKSUM_CRC, 43 IFD_PROTOCOL_T1_CHECKSUM_LRC, 44 IFD_PROTOCOL_T1_IFSC, 45 IFD_PROTOCOL_T1_IFSD, 46 IFD_PROTOCOL_T1_STATE, 47 IFD_PROTOCOL_T1_MORE 48}; 49 50#define T1_BUFFER_SIZE (3 + 254 + 2) 51 52/* see /usr/include/PCSC/ifdhandler.h for other values 53 * this one is for internal use only */ 54#define IFD_PARITY_ERROR 699 55 56typedef struct { 57 int lun; 58 int state; 59 60 unsigned char ns; /* reader side */ 61 unsigned char nr; /* card side */ 62 unsigned int ifsc; 63 unsigned int ifsd; 64 65 unsigned char wtx; 66 unsigned int retries; 67 unsigned int rc_bytes; 68 69 unsigned int (*checksum)(const uint8_t *, size_t, unsigned char *); 70 71 char more; /* more data bit */ 72 unsigned char previous_block[4]; /* to store the last R-block */ 73} t1_state_t; 74 75int t1_transceive(t1_state_t *t1, unsigned int dad, 76 const void *snd_buf, size_t snd_len, 77 void *rcv_buf, size_t rcv_len); 78int t1_init(t1_state_t *t1, int lun); 79void t1_release(t1_state_t *t1); 80int t1_set_param(t1_state_t *t1, int type, long value); 81int t1_negotiate_ifsd(t1_state_t *t1, unsigned int dad, int ifsd); 82unsigned int t1_build(t1_state_t *, unsigned char *, 83 unsigned char, unsigned char, ct_buf_t *, size_t *); 84 85#endif 86 87