FreeCalypso > hg > freecalypso-tools
annotate loadtools/simup.c @ 926:6a0aa8d36d06
rvinterf backslash escape: introduce libprint
The new helper function library named libprint is meant to replace
the badly misnamed libg23, and will soon contain functions for
printing all of the same kinds of GPF TST packets that are now handled
in libg23. However, we are also moving safe_print_trace() from libasync
to this new library, and changing it to emit our new backslash escape
format.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 23 May 2023 03:47:46 +0000 |
parents | 02490e26f53d |
children |
rev | line source |
---|---|
790
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the stage in fc-simint where the sim-up |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * command is fed to simagent and the ATR response is parsed. |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int sim_voltage_mode_1v8; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #define MAX_ATR_BYTES 33 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char sim_atr[MAX_ATR_BYTES]; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 unsigned sim_atr_len; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 sim_up_callback(line) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char *line; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char *cp; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 puts(line); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (strncmp(line, "ATR:", 4)) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 sim_atr_len = 0; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 for (cp = line + 4; *cp; cp += 3) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (cp[0] != ' ' || !isxdigit(cp[1]) || !isxdigit(cp[2])) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 "error: invalid ATR line from simagent\n"); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (sim_atr_len >= MAX_ATR_BYTES) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 fprintf(stderr, |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 "error: ATR from simagent is too long\n"); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 sim_atr[sim_atr_len++] = decode_hex_byte(cp + 1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return(0); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 void |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 do_sim_up() |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 char *targv[3]; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
793
02490e26f53d
fc-simint: cosmetic enhancements
Mychaela Falconia <falcon@freecalypso.org>
parents:
792
diff
changeset
|
51 printf("Bringing up SIM interface at %s V\n", |
02490e26f53d
fc-simint: cosmetic enhancements
Mychaela Falconia <falcon@freecalypso.org>
parents:
792
diff
changeset
|
52 sim_voltage_mode_1v8 ? "1.8" : "3.0"); |
790
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 targv[0] = "sim-up"; |
793
02490e26f53d
fc-simint: cosmetic enhancements
Mychaela Falconia <falcon@freecalypso.org>
parents:
792
diff
changeset
|
54 targv[1] = sim_voltage_mode_1v8 ? "1.8" : "3"; |
790
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 targv[2] = 0; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 tpinterf_make_cmd(targv); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (tpinterf_send_cmd() < 0) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 exit(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (tpinterf_capture_output(20, sim_up_callback)) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (!sim_atr_len) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 fprintf(stderr, "error: no ATR returned from simagent\n"); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 exit(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |