1 /* $Id: sc7816.h,v 1.3 2003/06/02 01:29:37 deraadt Exp $ */
2
3 /*
4 copyright 1997, 2000
5 the regents of the university of michigan
6 all rights reserved
7
8 permission is granted to use, copy, create derivative works
9 and redistribute this software and such derivative works
10 for any purpose, so long as the name of the university of
11 michigan is not used in any advertising or publicity
12 pertaining to the use or distribution of this software
13 without specific, written prior authorization. if the
14 above copyright notice or any other identification of the
15 university of michigan is included in any copy of any
16 portion of this software, then the disclaimer below must
17 also be included.
18
19 this software is provided as is, without representation
20 from the university of michigan as to its fitness for any
21 purpose, and without warranty by the university of
22 michigan of any kind, either express or implied, including
23 without limitation the implied warranties of
24 merchantability and fitness for a particular purpose. the
25 regents of the university of michigan shall not be liable
26 for any damages, including special, indirect, incidental, or
27 consequential damages, with respect to any claim arising
28 out of or in connection with the use of the software, even
29 if it has been or is hereafter advised of the possibility of
30 such damages.
31 */
32
33 /* SCPERF - performance evaluation */
34 #ifdef SCPERF
35 #include <stdlib.h>
36 #include <sys/types.h>
37 #include <sys/time.h>
38 #endif /* SCPERF */
39
40 /* open flags - these must track the flags in sectok.h */
41 #define SCODSR 0x1 /* wait for dsr */
42 #define SCODCD 0x2 /* wait for dcd */
43 #define SCOHUP 0x4 /* send signal on card removal */
44 #define SCOXCTS 0x8 /* wait for no cts (todos reader) */
45 #define SCOXDTR 0x10 /* invert dtr (todos reader) */
46 #define SCOINVRT 0x20 /* inverse convention */
47
48 /* Reset flags - these must track the flags in sectok.h */
49 #define SCRV 0x1 /* be verbose */
50 #define SCRLEN 0x2 /* determine length by examing atr */
51 #define SCRTODOS 0x4 /* Todos reader */
52 #define SCRFORCE 0x8 /* Talk to card even if atr is bad */
53
54 /* error codes */
55 #define SCEOK 0
56 #define SCENOTTY 1 /* no such tty */
57 #define SCENOMEM 2 /* malloc (or similar) failed */
58 #define SCTIMEO 3 /* time out */
59 #define SCESLAG 4 /* slag (no atr) */
60 #define SCENOSUPP 5 /* card type not supported */
61 #define SCENOCARD 6 /* no card in reader */
62 #define SCENOIMPL 7
63 #define SCEDRVR 8
64 #define SCECOMM 9
65 #define SCECLOSED 10
66 #define SCENOFILE 11 /* wrong config path or driver path */
67 #define SCECNFFILES 12 /* both config path and driver path are
68 specified. thus conflict. */
69 #define SCEUNKNOWN 13
70
71 extern char *scerrtab[];
72 extern struct scparam scparam[];
73
74 /* forward declarations */
75
76 int scopen(int rn, int flags, int *ep);
77 int scxopen(int rn, int flags, int *ep,
78 char *config_path, char *driver_path);
79 int scsetflags(int fd, int flags, int mask);
80 int scrw(int fd, int cla, int ins, int p1, int p2, int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *sw1p, int *sw2p);
81 int scread(int fd, int cla, int ins, int p1, int p2, int p3, unsigned char *buf, int *sw1p, int *sw2p);
82 int scwrite(int fd, int cla, int ins, int p1, int p2, int p3, unsigned char *buf, int *sw1p, int *sw2p);
83 int sccardpresent(int fd);
84 int scdsr(int fd);
85 int scclose(int fd);
86 int screset(int fd, unsigned char *atr, int *ep);
87 int scxreset(int fd, int flags, unsigned char *atr, int *ep);
88 int scdtr(int fd, int cmd);
89 int scgetc(int fd, unsigned char *cp, int ms);
90 int scputc(int fd, int ic);
91 int scgetblk(int fd, unsigned char *bp, int n, int bwt, int cwt);
92 int scputblk(int fd, unsigned char *bp, int n);
93 void scsleep(int ms);
94 void scdrain(int fd);
95 int scioT1(int fd, int cla, int ins, int p1, int p2, int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *sw1p, int *sw2p);
96 int scioT1Iblk(int fd, int ilen, unsigned char *ibuf, unsigned char *obuf);
97 int scioT1pkt(int fd, unsigned char *ibuf, unsigned char *obuf);
98 int parse_input(char *ibuf, unsigned char *obuf, int olen);
99 #ifndef __palmos__
100 int get_input(FILE *f, unsigned char *obuf, int omin, int olen);
101 int fdump_reply(FILE *f, unsigned char *p, int n, int r1, int r2);
102 int dump_reply(unsigned char *p, int n, int r1, int r2);
103 #endif
104 void print_r1r2(int r1, int r2);
105 char *get_r1r2s(int r1, int r2);
106
107 /* SCPERF - performance evaluation */
108 #ifdef SCPERF
109 #ifdef SCPERF_FIRST_APPEARANCE
110
111 #define MAX_EVENTS 1024
112
113 struct timeval perf_tv[MAX_EVENTS];
114 char *perf_buf[MAX_EVENTS];
115 int perf_num = 0;
116
print_time()117 void print_time ()
118 {
119 int i;
120
121 for (i = 0 ; i < perf_num ; i ++ ) {
122 printf("%ld.%06ld: %s\n",
123 perf_tv[i].tv_sec, perf_tv[i].tv_usec, perf_buf[i]);
124 }
125 return;
126 }
127
128 #define SetTime(x) \
129 gettimeofday(&(perf_tv[perf_num]), NULL); \
130 perf_buf[perf_num] = x; \
131 perf_num++; \
132 if (perf_num >= MAX_EVENTS) {\
133 fprintf (stderr, "SetTime overflow %d\n", MAX_EVENTS); \
134 exit (1); \
135 }
136
137 #else /* !SCPERF_FIRST_APPEARANCE */
138 extern struct timeval perf_tv[];
139 extern char *perf_buf[];
140 extern int perf_num;
141
142 #define MAX_EVENTS 1024
143
144 #define SetTime(x) \
145 gettimeofday(&(perf_tv[perf_num]), NULL); \
146 perf_buf[perf_num] = x; \
147 perf_num++; \
148 if (perf_num >= MAX_EVENTS) {\
149 fprintf (stderr, "SetTime overflow %d\n", MAX_EVENTS); \
150 exit (1); \
151 }
152 #endif /* SCPERF_FIRST_APPEARANCE */
153 void print_time ();
154 #else /* !SCPERF */
155 #define SetTime(x)
156 #define print_time() ;
157 #endif /* SCPERF */
158