1 /* $Id: sectok.h,v 1.3 2001/08/01 21:51:52 rees Exp $ */
2 
3 /*
4 copyright 2001
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 /* Open flags */
34 #define STONOWAIT	0x1	/* don't wait for card present */
35 #define STOHUP		0x4	/* send signal on card removal */
36 
37 /* Reset flags */
38 #define STRV		0x1	/* be verbose */
39 #define STRLEN		0x2	/* determine length by examing atr */
40 #define STRFORCE	0x8	/* Talk to card even if atr is bad */
41 
42 /* Errors */
43 #define STEOK		0x9000
44 #define STENOTTY	0x0601	/* no such tty */
45 #define STENOMEM	0x0602	/* malloc (or similar) failed */
46 #define STTIMEO		0x0603	/* time out */
47 #define STESLAG		0x0604	/* slag (no atr) */
48 #define STENOSUPP	0x0605	/* card type not supported */
49 #define STENOCARD	0x0606	/* no card in reader */
50 #define STENOIMPL	0x0607
51 #define STEDRVR 	0x0608
52 #define STECOMM 	0x0609
53 #define STECLOSED	0x060a
54 #define STECNFFILES     0x060c      /* both config path and driver path are
55 				   specified.  thus conflict. */
56 #define STEUNKNOWN	0x060d
57 #define STENOFILE	0x6a82
58 
59 /* Useful macros */
60 #define sectok_r1(sw) (((sw) >> 8) & 0xff)
61 #define sectok_r2(sw) ((sw) & 0xff)
62 #define sectok_mksw(r1, r2) (((r1) << 8) | (r2))
63 #define sectok_swOK(sw) (sectok_r1(sw) == 0x90 || sectok_r1(sw) == 0x61)
64 
65 struct scparam {
66     int t, etu, cwt, bwt, n;
67 };
68 
69 extern unsigned char root_fid[];
70 
71 /* Common card functions */
72 int sectok_open(int rn, int flags, int *swp);
73 int sectok_friendly_open(const char *rn, int flags, int *swp);
74 int sectok_xopen(int rn, int flags, char *config_path, char *driver_path, int *swp);
75 int sectok_reset(int fd, int flags, unsigned char *atr, int *swp);
76 int sectok_apdu(int fd, int cla, int ins, int p1, int p2,
77 		int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *swp);
78 int sectok_cardpresent(int fd);
79 int sectok_close(int fd);
80 int sectok_selectfile(int fd, int cla, unsigned char *fid, int *swp);
81 
82 /* Convenience functions */
83 void sectok_fmt_fid(char *fname, unsigned char *fid);
84 int sectok_parse_atr(int fd, int flags, unsigned char *atr, int len, struct scparam *param);
85 void sectok_parse_fname(char *buf, unsigned char *fid);
86 int sectok_parse_input(char *ibuf, unsigned char *obuf, int olen);
87 #ifndef __palmos__
88 int sectok_get_input(FILE *f, unsigned char *obuf, int omin, int olen);
89 int sectok_fdump_reply(FILE *f, unsigned char *p, int n, int sw);
90 #endif
91 int sectok_dump_reply(unsigned char *p, int n, int sw);
92 void sectok_print_sw(int sw);
93 char *sectok_get_sw(int sw);
94 char *sectok_get_ins(int ins);
95 
96 /* Cyberflex functions */
97 int cyberflex_create_file(int fd, int cla, unsigned char *fid, int size, int ftype, int *swp);
98 int cyberflex_create_file_acl(int fd, int cla, unsigned char *fid, int size, int ftype, unsigned char *acl, int *swp);
99 int cyberflex_delete_file(int fd, int cla, unsigned char *fid, int *swp);
100 int cyberflex_load_rsa_pub(int fd, int cla, unsigned char *key_fid,
101 			   int key_len, unsigned char *key_data, int *swp);
102 int cyberflex_load_rsa_priv(int fd, int cla, unsigned char *key_fid,
103 			    int nkey_elems, int key_len, unsigned char *key_elems[],
104 			    int *swp);
105 int cyberflex_verify_AUT0(int fd, int cla, unsigned char *aut0, int aut0len);
106 int cyberflex_inq_class(int fd);
107 void cyberflex_fill_key_block (unsigned char *dst, int key_num,
108 			       int alg_num, unsigned char *key);
109