annotate uptools/sms-pdu-decode/pcm-sms-decode.c @ 712:a167d7b376b7

fc-loadtool code: flprotreg.c factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 05 Jun 2020 07:29:59 +0000
parents 31e219088cd6
children 3a80bfa87496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
600
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdlib.h>
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <string.h>
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <strings.h>
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <unistd.h>
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 extern int ascii_ext_mode, global_hexdump_mode;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 extern u_char pdu[176];
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern unsigned pdu_length;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static char *infname;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static FILE *inf;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static char *msgtype[4] = {"received", "received unread", "sent",
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 "stored unsent"};
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 process_cmdline(argc, argv)
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char **argv;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int c;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern int optind;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 while ((c = getopt(argc, argv, "ehu")) != EOF)
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 switch (c) {
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 case 'e':
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 ascii_ext_mode = 1;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 continue;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 case 'h':
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 global_hexdump_mode = 1;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 continue;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 case 'u':
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 ascii_ext_mode = 2;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 continue;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 default:
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 fprintf(stderr, "%s: invalid option\n", argv[0]);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (argc != optind + 1) {
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr, "usage: %s [options] pcm-sms-binfile\n",
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 argv[0]);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 infname = argv[optind];
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 main(argc, argv)
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 char **argv;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 u_char record[176];
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 unsigned recno;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 process_cmdline(argc, argv);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 inf = fopen(infname, "r");
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (!inf) {
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 perror(infname);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 exit(1);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 pdu_length = 176;
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 for (recno = 0; fread(record, sizeof record, 1, inf); recno++) {
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (record[0] & 1) {
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 printf("Record #%u is %s message:\n", recno,
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 msgtype[(record[0] >> 1) & 3]);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 bcopy(record + 1, pdu, 175);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 process_pdu(0);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 putchar('\n');
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 } else
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 printf("Record #%u is empty\n\n", recno);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 exit(0);
31e219088cd6 uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }