annotate miscprog/atsc.c @ 154:1cd11badf287

leo-obj/frame_na7_db_fl: extract ctypes info as well
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 02 May 2014 06:20:26 +0000
parents 597143ba1c37
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * It is known that some GSM devices have undocumented AT commands for
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * changing the IMEI. There is no standard syntax for such an AT command
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * (by the "proper rules" one is not supposed to exist at all), and instead
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 * there seem to be several different ad hoc syntaxes. This source file,
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 * found on a Chinese site, implements one of these numerous ad hoc
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 * IMEI-changing AT commands:
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 *
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 * ftp://ftp.ifctf.org/pub/GSM/TI_src/ati_sc.c
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 *
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 * Notice that this particular incarnation of the "set IMEI" AT command
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 * is called AT@SC; there just happens to be an identically-named AT@SC
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 * command on Openmoko's GSM modems. Might it perchance be the same
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 * IMEI changing command?
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 *
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 * This program constructs what should be a valid input to the decoding
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 * logic in the ati_sc.c source above, for the purpose of testing whether
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 * or not such a command would indeed effect an IMEI change on a GTA02 modem.
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 */
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 #include <stdio.h>
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 #include <ctype.h>
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 #include <string.h>
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 #include <strings.h>
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 #include <stdlib.h>
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 static char hexdigits[] = "0123456789abcdef";
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 main(argc, argv)
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 char **argv;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 {
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 char hexout[16];
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 unsigned n1, n2, cksum;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 int i, c;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 if (argc != 2) {
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 usage: fprintf(stderr, "usage: %s 15-IMEI-digits\n", argv[0]);
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 exit(1);
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 }
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 if (strlen(argv[1]) != 15)
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 goto usage;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 n1 = n2 = 0;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 for (i = 0; i < 15; i++) {
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 c = argv[1][i];
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 if (!isdigit(c))
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 goto usage;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 c -= '0';
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 hexout[i] = hexdigits[c ^ 5];
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (i < 7)
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 n1 = n1 * 10 + c;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 else
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 n2 = n2 * 10 + c;
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 }
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 hexout[15] = '\0';
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 cksum = (n1 + n2) % 1973;
66
39f2ccd06b57 atsc hack: apparently this AT@SC command needs double quotes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 65
diff changeset
56 printf("AT@SC=\"%s%04u\"\n", hexout, cksum);
65
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 exit(0);
3890c2672fe0 atsc hack written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 }