annotate gen-pdu/settings.c @ 10:17dd30989c0b

sms-gen-tpdu: fix bug in GSM7 data source
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 07:47:22 +0000
parents 003660a57f99
children 5854e48d0ef7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements functions for various settings that come before
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * msg or msg-udh lines.
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "error.h"
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int dir_mo, include_sca;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern u_char sc_addr[12], user_addr[12];
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern u_char mr_byte, pid_byte, dcs_byte;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern u_char scts_buf[7];
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern int is_septet, scts_is_set;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern int input_lineno;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 void
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 set_sc_addr(argc, argv)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 char **argv;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 int rc;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (!include_sca) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fprintf(stderr, ERR_PREFIX
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 "sc-addr is not allowed in bare TPDU mode\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 rc = encode_phone_number_arg(argv[1], sc_addr, 0);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (rc < 0) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr, ERR_PREFIX "invalid phone number argument\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 void
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 set_user_addr(argc, argv)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 char **argv;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 int rc;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 rc = encode_phone_number_arg(argv[1], user_addr, 1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (rc < 0) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, ERR_PREFIX "invalid phone number argument\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 void
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 set_mr_byte(argc, argv)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 char **argv;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 char *endp;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (!dir_mo) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 fprintf(stderr, ERR_PREFIX "mr is not allowed in MT mode\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 mr_byte = strtoul(argv[1], &endp, 0);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (*endp) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 fprintf(stderr, ERR_PREFIX "invalid byte value argument\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 void
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 set_pid_byte(argc, argv)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 char **argv;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 char *endp;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 pid_byte = strtoul(argv[1], &endp, 0);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (*endp) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 fprintf(stderr, ERR_PREFIX "invalid byte value argument\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 void
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 set_dcs(argc, argv)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 char **argv;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 char *endp;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 dcs_byte = strtoul(argv[1], &endp, 0);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (*endp) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 fprintf(stderr, ERR_PREFIX "invalid byte value argument\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (!strcmp(argv[2], "septet"))
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 is_septet = 1;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 else if (!strcmp(argv[2], "octet"))
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 is_septet = 0;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 else {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 fprintf(stderr, ERR_PREFIX "invalid septet/octet mode kw\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 void
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 set_scts(argc, argv)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 char **argv;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 int rc;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (dir_mo) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 fprintf(stderr, ERR_PREFIX "sc-ts is not allowed in MO mode\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 rc = encode_gsm_sms_abstime(argv[1], scts_buf);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if (rc < 0) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 fprintf(stderr, ERR_PREFIX "invalid timestamp argument\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 scts_is_set = 1;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }