annotate serial/hexinput.c @ 99:97ba63d9361a

scripts/fcsim1-sst: turn off STK & OTA services In the initial unprogrammed state of the cards from Grcard, SST has services 25 through 29 set to allocated and activated. However, these cards appear to not actually support OTA, ENVELOPE commands do nothing (just return SW 9000), and they were never observed issuing any proactive SIM commands, even after a feature-generous TERMINAL PROFILE. Therefore, let's list these STK & OTA services as allocated, but not activated in our FCSIM1 SST.
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 04:26:07 +0000
parents be27d1c85861
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
1 #include <sys/types.h>
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
2 #include <ctype.h>
1
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
3
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
5 static
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
6 decode_hex_digit(c)
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
7 {
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
8 if (isdigit(c))
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
9 return c - '0';
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
10 else if (islower(c))
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
11 return c - 'a' + 10;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
12 else
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
13 return c - 'A' + 10;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
14 }
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
15
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
16 parse_hex_input(inbuf, outbuf)
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
17 char *inbuf;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
18 u_char *outbuf;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
19 {
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
20 char *cp;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
21 unsigned count;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
22
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
23 count = 0;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
24 for (cp = inbuf; ; ) {
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
25 while (isspace(*cp))
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
26 cp++;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
27 if (!*cp)
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
28 break;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
29 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) {
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
30 printf("error: invalid hex APDU input\n");
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
31 return(-1);
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
32 }
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
33 if (count >= 260) {
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
34 printf("error: command APDU is too long\n");
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
35 return(-1);
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
36 }
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
37 outbuf[count++] = (decode_hex_digit(cp[0]) << 4) |
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
38 decode_hex_digit(cp[1]);
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
39 cp += 2;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
40 }
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
41 return count;
45ea06eaa9fd fc-pcsc-backend main program put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
42 }