annotate decode/sms-pdu-decode.c @ 31:19476164c54d

doc/SMS-PDU-decoding: document imported utilities
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 Jun 2024 18:48:58 +0000
parents aae078d9eaa6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdlib.h>
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <string.h>
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <strings.h>
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <unistd.h>
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 extern int ascii_ext_mode, global_hexdump_mode;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 extern u_char pdu[176];
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern unsigned pdu_length;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static char *infname;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static FILE *inf;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static int keep_raw_pdu, pdu_has_sca = 1;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static char input_line[1024];
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 process_cmdline(argc, argv)
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char **argv;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int c;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern int optind;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 while ((c = getopt(argc, argv, "ehnpu")) != EOF)
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 switch (c) {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 case 'e':
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 ascii_ext_mode = 1;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 continue;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 case 'h':
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 global_hexdump_mode = 1;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 continue;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 case 'n':
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 pdu_has_sca = 0;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 continue;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 case 'p':
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 keep_raw_pdu = 1;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 continue;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 case 'u':
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ascii_ext_mode = 2;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 continue;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 default:
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fprintf(stderr, "%s: invalid option\n", argv[0]);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (argc > optind)
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 infname = argv[optind];
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 static
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 swallow_empty_line()
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 int c;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 c = getc(inf);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (c != '\n')
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 ungetc(c, inf);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 main(argc, argv)
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 char **argv;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 char *nl;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 int lineno, cc;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 process_cmdline(argc, argv);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (infname) {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 inf = fopen(infname, "r");
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!inf) {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 perror(infname);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 exit(1);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 } else {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 inf = stdin;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 infname = "stdin";
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 for (lineno = 1; fgets(input_line, sizeof input_line, inf); lineno++) {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 nl = index(input_line, '\n');
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (!nl) {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 fprintf(stderr, "%s line %d: no newline\n",
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 infname, lineno);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 exit(1);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 *nl = '\0';
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 cc = decode_hex_line(input_line, pdu, sizeof pdu);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (cc <= 0) {
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 puts(input_line);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 continue;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 pdu_length = cc;
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (keep_raw_pdu)
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 printf("%s\n\n", input_line);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 process_pdu(1, pdu_has_sca);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 putchar('\n');
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 swallow_empty_line();
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(0);
aae078d9eaa6 immigrate sms-pdu-decode and pcm-sms-decode here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }