FreeCalypso > hg > fc-sim-tools
annotate serial/spenh.c @ 93:6041c601304d
fcsim1-mkprov: revert OTA key addition
It appears that GrcardSIM2 cards (which is what we got for FCSIM1)
do not support OTA after all, contrary to what we were previously
led to believe by some tech support emails from Grcard - apparently
those support emails and OTA descriptions referred to some other
card model(s).
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 21 Apr 2021 05:38:39 +0000 |
parents | fbedb67d234f |
children |
rev | line source |
---|---|
42
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements speed enhancement logic for our serial |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * SIM interface back end. |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern u_char atr_buf[]; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern unsigned baud_spenh, spenh_host_max; |
53
fbedb67d234f
serial: fix parity for inverse coding convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
12 extern int inverse_coding; |
42
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 void |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 spenh_logic() |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 unsigned spenh_sim_max, use_spenh; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char pts_req[4], pts_resp[4]; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int rc; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (!(atr_buf[1] & 0x10)) { |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 no_spenh: printf("X SIM does not support speed enhancement\n"); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 switch (atr_buf[2]) { |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 case 0x94: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 spenh_sim_max = 1; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 case 0x95: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 spenh_sim_max = 2; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 case 0x96: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 spenh_sim_max = 4; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 case 0x97: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 spenh_sim_max = 8; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 default: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 goto no_spenh; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 use_spenh = spenh_sim_max; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (use_spenh > spenh_host_max) |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 use_spenh = spenh_host_max; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 pts_req[0] = 0xFF; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 pts_req[1] = 0x10; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 switch (use_spenh) { |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 case 1: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 pts_req[2] = 0x94; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 case 2: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 pts_req[2] = 0x95; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 case 4: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 pts_req[2] = 0x96; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 case 8: |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 pts_req[2] = 0x97; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 break; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 pts_req[3] = pts_req[0] ^ pts_req[1] ^ pts_req[2]; |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 rc = send_bytes_to_sim(pts_req, 4); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (rc < 0) |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 exit(1); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 rc = collect_bytes_from_sim(pts_resp, 4); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (rc < 0) |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 exit(1); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (bcmp(pts_req, pts_resp, 4)) { |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(stderr, "error: PTS response does not match request\n"); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 exit(1); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
53
fbedb67d234f
serial: fix parity for inverse coding convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
71 set_serial_params(baud_spenh * use_spenh, inverse_coding); |
42
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 printf("X Using F=512 D=%u speed enhancement\n", use_spenh * 8); |
6cc3eea720cb
serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |