1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* Return text for a given pair of sw1/sw2 status bytes
*
* See copyright notice at end of file
*/
static char *rcsid = "$Id: r1r2.c,v 1.2 2001/06/07 16:10:00 rees Exp $";
#ifdef __palmos__
#define NULL 0
#define printf palmprintf
#else
#include <stdio.h>
#endif
#include "sectok.h"
struct r1r2s {
int r1, r2;
char *s;
} r1r2s[] = {
{0x90, 0x00, "ok"},
{0x61, 0xff, "ok; response available %x"},
{0x62, 0x34, "no such method"},
{0x62, 0x39, "out of memory"},
{0x62, 0x55, "null pointer"},
{0x62, 0x57, "array index out of bounds"},
{0x62, 0x58, "index out of bounds"},
{0x62, 0x81, "rec is corrupt"},
{0x62, 0x83, "invalid file"},
{0x63, 0x00, "auth failed"},
{0x63, 0x81, "invalid key"},
{0x67, 0xff, "invalid length; should be %x"},
{0x69, 0x80, "bad param"},
{0x69, 0x82, "unreadable"},
{0x69, 0x83, "auth method blocked"},
{0x69, 0x84, "data invalid"},
{0x69, 0x85, "no file selected"},
{0x69, 0x87, "busy/SM missing"},
{0x69, 0x88, "SM wrong"},
{0x6a, 0x80, "invalid file type"},
{0x6a, 0x81, "function not supported"},
{0x6a, 0x82, "file not found"},
{0x6a, 0x83, "no such rec"},
{0x6b, 0x00, "wrong mode"},
{0x6c, 0xff, "wrong length; should be %x"},
{0x6d, 0x00, "unknown instruction"},
{0x6e, 0x00, "wrong class"},
{0x6f, 0x14, "invalid applet state"},
{0x6f, 0x15, "invalid state"},
{0x6f, 0x19, "applet already running"},
{0x6f, 0xb0, "uninitialized key"},
{0x94, 0x81, "bad state"},
{0x00, 0x00, NULL}
};
#ifdef TEST
main(int ac, char *av[])
{
int r1, r2;
char *s;
if (ac != 3) {
fprintf(stderr, "usage: %s sw1 sw2 (in hex, please)\n", av[0]);
exit(1);
}
sscanf(av[1], "%x", &r1);
sscanf(av[2], "%x", &r2);
print_r1r2(r1, r2);
exit(0);
}
#endif
void
print_r1r2(int r1, int r2)
{
printf("%s\n", get_r1r2s(r1, r2));
}
char *
get_r1r2s(int r1, int r2)
{
char *s;
static char buf[64];
s = scr1r2s(r1, r2);
if (s)
sprintf(buf, "%02x %02x %s", r1, r2, s);
else
sprintf(buf, "%02x %02x", r1, r2);
return buf;
}
char *
scr1r2s(int r1, int r2)
{
int i;
static char buf[64];
for (i = 0; r1r2s[i].s; i++)
if (r1r2s[i].r1 == r1 && (r1r2s[i].r2 == r2 || r1r2s[i].r2 == 0xff))
break;
if (r1r2s[i].r2 != 0xff)
return r1r2s[i].s;
sprintf(buf, r1r2s[i].s, r2);
return buf;
}
#ifndef __palmos__
int
fdump_reply(FILE *f, unsigned char *p, int n, int r1, int r2)
{
int i;
for (i = 0; i < n; i++)
fprintf(f, "%d:%x ", i + 1, p[i]);
if (n)
fprintf(f, "\n");
if (r1)
fprintf(f, "%s\n", get_r1r2s(r1, r2));
return n;
}
int
dump_reply(unsigned char *p, int n, int r1, int r2)
{
return fdump_reply(stdout, p, n, r1, r2);
}
#endif
/*
copyright 1999
the regents of the university of michigan
all rights reserved
permission is granted to use, copy, create derivative works
and redistribute this software and such derivative works
for any purpose, so long as the name of the university of
michigan is not used in any advertising or publicity
pertaining to the use or distribution of this software
without specific, written prior authorization. if the
above copyright notice or any other identification of the
university of michigan is included in any copy of any
portion of this software, then the disclaimer below must
also be included.
this software is provided as is, without representation
from the university of michigan as to its fitness for any
purpose, and without warranty by the university of
michigan of any kind, either express or implied, including
without limitation the implied warranties of
merchantability and fitness for a particular purpose. the
regents of the university of michigan shall not be liable
for any damages, including special, indirect, incidental, or
consequential damages, with respect to any claim arising
out of or in connection with the use of the software, even
if it has been or is hereafter advised of the possibility of
such damages.
*/
|