FreeCalypso > hg > freecalypso-tools
comparison loadtools/simatr.c @ 790:0bbe0213812d
fc-simint put together, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 19 Mar 2021 04:40:05 +0000 |
parents | |
children | a31ae776de6e |
comparison
equal
deleted
inserted
replaced
789:464a531122ab | 790:0bbe0213812d |
---|---|
1 /* | |
2 * This module implements the stage in fc-simint where ATR bytes | |
3 * received from simagent are validated. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 | |
10 extern int sim_allow_spenh; | |
11 | |
12 extern u_char sim_atr[]; | |
13 extern unsigned sim_atr_len; | |
14 | |
15 void | |
16 sim_atr_validate() | |
17 { | |
18 unsigned b, p, y, nhist, have_tck; | |
19 | |
20 if (sim_atr_len < 2) { | |
21 too_short: fprintf(stderr, "error: ATR from simagent is too short\n"); | |
22 exit(1); | |
23 } | |
24 b = sim_atr[1]; | |
25 p = 2; | |
26 nhist = b & 0xF; | |
27 y = b & 0xF0; | |
28 have_tck = 0; | |
29 while (y) { | |
30 if (y & 0x10) { | |
31 if (p >= sim_atr_len) | |
32 goto too_short; | |
33 p++; | |
34 } | |
35 if (y & 0x20) { | |
36 if (p >= sim_atr_len) | |
37 goto too_short; | |
38 p++; | |
39 } | |
40 if (y & 0x40) { | |
41 if (p >= sim_atr_len) | |
42 goto too_short; | |
43 p++; | |
44 } | |
45 if (y & 0x80) { | |
46 if (p >= sim_atr_len) | |
47 goto too_short; | |
48 b = sim_atr[p++]; | |
49 y = b & 0xF0; | |
50 if (b & 0x0F) | |
51 have_tck = 1; | |
52 } else | |
53 y = 0; | |
54 } | |
55 p += nhist + have_tck; | |
56 if (p > sim_atr_len) | |
57 goto too_short; | |
58 if (p < sim_atr_len) { | |
59 fprintf(stderr, "error: ATR from simagent is too long\n"); | |
60 exit(1); | |
61 } | |
62 if (!have_tck) | |
63 return; | |
64 /* validate TCK */ | |
65 b = 0; | |
66 for (p = 1; p < sim_atr_len; p++) | |
67 b ^= sim_atr[p]; | |
68 if (b) { | |
69 fprintf(stderr, "error: ATR checksum is bad\n"); | |
70 exit(1); | |
71 } | |
72 } | |
73 | |
74 void | |
75 sim_spenh_logic() | |
76 { | |
77 static char *targv[2] = {"spenh", 0}; | |
78 | |
79 if (sim_atr_len < 3 || !(sim_atr[1] & 0x10) || (sim_atr[2] < 0x94)) { | |
80 printf("ATR indicates no support for speed enhancement\n"); | |
81 return; | |
82 } | |
83 if (!sim_allow_spenh) { | |
84 printf("Speed enhancement disabled with -n option\n"); | |
85 return; | |
86 } | |
87 tpinterf_make_cmd(targv); | |
88 if (tpinterf_send_cmd() < 0) | |
89 exit(1); | |
90 if (tpinterf_pass_output(10)) | |
91 exit(1); | |
92 } |