1 /* $Id: sc7816.h,v 1.3 2001/09/28 16:20:24 rees 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 /* functions that have just been renamed */
75
76 #define scclose(fd) sectok_close(fd)
77 #define sccardpresent(fd) sectok_cardpresent(fd)
78 #define parse_input(ibuf, obuf, olen) sectok_parse_input(ibuf, obuf, olen)
79 #define get_input(f, obuf, omin, olen) sectok_get_input(ibuf, obuf, olen)
80 #define parse_atr(fd, flags, atr, len, param) sectok_parse_atr(fd, flags, atr, len, param)
81 #define lookup_cmdname(ins) sectok_get_ins(ins)
82
83 /* forward declarations */
84
85 int scopen(int rn, int flags, int *ep);
86 int scxopen(int rn, int flags, int *ep,
87 char *config_path, char *driver_path);
88 int scsetflags(int fd, int flags, int mask);
89 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);
90 int scread(int fd, int cla, int ins, int p1, int p2, int p3, unsigned char *buf, int *sw1p, int *sw2p);
91 int scwrite(int fd, int cla, int ins, int p1, int p2, int p3, unsigned char *buf, int *sw1p, int *sw2p);
92 int scdsr(int fd);
93 int screset(int fd, unsigned char *atr, int *ep);
94 int scxreset(int fd, int flags, unsigned char *atr, int *ep);
95 int scdtr(int fd, int cmd);
96 int scgetc(int fd, unsigned char *cp, int ms);
97 int scputc(int fd, int ic);
98 int scgetblk(int fd, unsigned char *bp, int n, int bwt, int cwt);
99 int scputblk(int fd, unsigned char *bp, int n);
100 void scsleep(int ms);
101 void scdrain(int fd);
102 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);
103 int scioT1Iblk(int fd, int ilen, unsigned char *ibuf, unsigned char *obuf);
104 int scioT1pkt(int fd, unsigned char *ibuf, unsigned char *obuf);
105 #ifndef __palmos__
106 int fdump_reply(FILE *f, unsigned char *p, int n, int r1, int r2);
107 int dump_reply(unsigned char *p, int n, int r1, int r2);
108 #endif
109 void print_r1r2(int r1, int r2);
110 char *get_r1r2s(int r1, int r2);
111
112 /* SCPERF - performance evaluation */
113 #ifdef SCPERF
114 #ifdef SCPERF_FIRST_APPEARANCE
115
116 #define MAX_EVENTS 1024
117
118 struct timeval perf_tv[MAX_EVENTS];
119 char *perf_buf[MAX_EVENTS];
120 int perf_num = 0;
121
print_time()122 void print_time ()
123 {
124 int i;
125
126 for (i = 0 ; i < perf_num ; i ++ ) {
127 printf ("%ld.%06ld: %s\n",
128 perf_tv[i].tv_sec, perf_tv[i].tv_usec, perf_buf[i]);
129 }
130 return;
131 }
132
133 #define SetTime(x) \
134 gettimeofday(&(perf_tv[perf_num]), NULL); \
135 perf_buf[perf_num] = x; \
136 perf_num++; \
137 if (perf_num >= MAX_EVENTS) {\
138 fprintf (stderr, "SetTime overflow %d\n", MAX_EVENTS); \
139 exit (1); \
140 }
141
142 #else /* !SCPERF_FIRST_APPEARANCE */
143 extern struct timeval perf_tv[];
144 extern char *perf_buf[];
145 extern int perf_num;
146
147 #define MAX_EVENTS 1024
148
149 #define SetTime(x) \
150 gettimeofday(&(perf_tv[perf_num]), NULL); \
151 perf_buf[perf_num] = x; \
152 perf_num++; \
153 if (perf_num >= MAX_EVENTS) {\
154 fprintf (stderr, "SetTime overflow %d\n", MAX_EVENTS); \
155 exit (1); \
156 }
157 #endif /* SCPERF_FIRST_APPEARANCE */
158 void print_time ();
159 #else /* !SCPERF */
160 #define SetTime(x)
161 #define print_time() ;
162 #endif /* SCPERF */
163
164 /* macros */
165 #ifdef SCFS
166 #define ADEBMISC 0x00000001 /* misc debugging */
167 #define MESSAGE1(x) arla_warnx (ADEBMISC,x)
168 #define MESSAGE2(x,y) arla_warnx (ADEBMISC,x,y)
169 #define MESSAGE3(x,y,z) arla_warnx (ADEBMISC,x,y,z)
170 #define MESSAGE4(x,y,z,u) arla_warnx (ADEBMISC,x,y,z,u)
171 #define MESSAGE5(x,y,z,u,v) arla_warnx (ADEBMISC,x,y,z,u,v)
172 #define MESSAGE6(x,y,z,u,v,w) arla_warnx (ADEBMISC,x,y,z,u,v,w)
173 #else
174 #define MESSAGE1(x) fprintf(stderr,x)
175 #define MESSAGE2(x,y) fprintf(stderr,x,y)
176 #define MESSAGE3(x,y,z) fprintf(stderr,x,y,z)
177 #define MESSAGE4(x,y,z,u) fprintf(stderr,x,y,z,u)
178 #define MESSAGE5(x,y,z,u,v) fprintf(stderr,x,y,z,u,v)
179 #define MESSAGE6(x,y,z,u,v,w) fprintf(stderr,x,y,z,u,v,w)
180 #endif /* SCFS */
181