Initial commit
[platform/upstream/ccid.git] / src / openct / proto-t1.h
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 #ifndef __PROTO_T1_H__
21 #define __PROTO_T1_H__
22
23 #include <config.h>
24 #ifdef HAVE_STDINT_H
25 #include <stdint.h>
26 #endif
27
28 #include "buffer.h"
29
30 /* T=1 protocol constants */
31 #define T1_I_BLOCK              0x00
32 #define T1_R_BLOCK              0x80
33 #define T1_S_BLOCK              0xC0
34 #define T1_MORE_BLOCKS          0x20
35
36 enum {
37         IFD_PROTOCOL_RECV_TIMEOUT = 0x0000,
38         IFD_PROTOCOL_T1_BLOCKSIZE,
39         IFD_PROTOCOL_T1_CHECKSUM_CRC,
40         IFD_PROTOCOL_T1_CHECKSUM_LRC,
41         IFD_PROTOCOL_T1_IFSC,
42         IFD_PROTOCOL_T1_IFSD,
43         IFD_PROTOCOL_T1_STATE,
44         IFD_PROTOCOL_T1_MORE
45 };
46
47 #define T1_BUFFER_SIZE          (3 + 254 + 2)
48
49 /* see /usr/include/PCSC/ifdhandler.h for other values
50  * this one is for internal use only */
51 #define IFD_PARITY_ERROR 699
52
53 typedef struct {
54         int             lun;
55         int             state;
56
57         unsigned char   ns;     /* reader side */
58         unsigned char   nr;     /* card side */
59         unsigned int    ifsc;
60         unsigned int    ifsd;
61
62         unsigned char   wtx;
63         unsigned int    retries;
64         unsigned int    rc_bytes;
65
66         unsigned int    (*checksum)(const uint8_t *, size_t, unsigned char *);
67
68         char                    more;   /* more data bit */
69         unsigned char   previous_block[4];      /* to store the last R-block */
70 } t1_state_t;
71
72 int t1_transceive(t1_state_t *t1, unsigned int dad,
73                 const void *snd_buf, size_t snd_len,
74                 void *rcv_buf, size_t rcv_len);
75 int t1_init(t1_state_t *t1, int lun);
76 void t1_release(t1_state_t *t1);
77 int t1_set_param(t1_state_t *t1, int type, long value);
78 int t1_negotiate_ifsd(t1_state_t *t1, unsigned int dad, int ifsd);
79 unsigned int t1_build(t1_state_t *, unsigned char *,
80         unsigned char, unsigned char, ct_buf_t *, size_t *);
81
82 #endif
83