FreeCalypso > hg > freecalypso-tools
annotate uptools/sms-pdu-decode/pcm-sms-decode.c @ 988:5a6019ed7e72
pln-ppb-test: implement read-id
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Dec 2023 00:04:18 +0000 |
parents | 411d1cc14326 |
children |
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; |
807
3a80bfa87496
pcm-sms-decode: add -s option for 1-based record numbering
Mychaela Falconia <falcon@freecalypso.org>
parents:
600
diff
changeset
|
15 static unsigned start_recno; |
600
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 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
|
18 "stored unsent"}; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 process_cmdline(argc, argv) |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char **argv; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int c; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 extern int optind; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
807
3a80bfa87496
pcm-sms-decode: add -s option for 1-based record numbering
Mychaela Falconia <falcon@freecalypso.org>
parents:
600
diff
changeset
|
27 while ((c = getopt(argc, argv, "ehsu")) != EOF) |
600
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 switch (c) { |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 case 'e': |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 ascii_ext_mode = 1; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 continue; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 case 'h': |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 global_hexdump_mode = 1; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 continue; |
807
3a80bfa87496
pcm-sms-decode: add -s option for 1-based record numbering
Mychaela Falconia <falcon@freecalypso.org>
parents:
600
diff
changeset
|
35 case 's': |
3a80bfa87496
pcm-sms-decode: add -s option for 1-based record numbering
Mychaela Falconia <falcon@freecalypso.org>
parents:
600
diff
changeset
|
36 start_recno = 1; |
3a80bfa87496
pcm-sms-decode: add -s option for 1-based record numbering
Mychaela Falconia <falcon@freecalypso.org>
parents:
600
diff
changeset
|
37 continue; |
600
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 case 'u': |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 ascii_ext_mode = 2; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 continue; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 default: |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 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
|
43 exit(1); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (argc != optind + 1) { |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 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
|
47 argv[0]); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 exit(1); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 infname = argv[optind]; |
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 |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 main(argc, argv) |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 char **argv; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 { |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 u_char record[176]; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 unsigned recno; |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 process_cmdline(argc, argv); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 inf = fopen(infname, "r"); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (!inf) { |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 perror(infname); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 exit(1); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 pdu_length = 176; |
807
3a80bfa87496
pcm-sms-decode: add -s option for 1-based record numbering
Mychaela Falconia <falcon@freecalypso.org>
parents:
600
diff
changeset
|
66 for (recno = start_recno; fread(record, sizeof record, 1, inf); |
3a80bfa87496
pcm-sms-decode: add -s option for 1-based record numbering
Mychaela Falconia <falcon@freecalypso.org>
parents:
600
diff
changeset
|
67 recno++) { |
600
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (record[0] & 1) { |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 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
|
70 msgtype[(record[0] >> 1) & 3]); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 bcopy(record + 1, pdu, 175); |
960
411d1cc14326
sms-pdu-decode family: prepare for SC address becoming optional
Mychaela Falconia <falcon@freecalypso.org>
parents:
807
diff
changeset
|
72 process_pdu(0, 1); |
600
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 putchar('\n'); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } else |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 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
|
76 } |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(0); |
31e219088cd6
uptools/sms-pdu-decode: pcm-sms-decode utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |