FreeCalypso > hg > themwi-system-sw
annotate smpp-send/build_pdu.c @ 264:cdc807117841
*/Makefile: change INSTBIN to /opt/themwi/bin (was /usr/local/bin)
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 05 Nov 2023 16:07:14 -0800 |
parents | 243ed87880a1 |
children |
rev | line source |
---|---|
223
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The function in this module constructs SMPP submit_sm PDUs |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * from input messages. |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "error.h" |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern char src_addr[21], dest_addr[21]; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern u_char src_ton, src_npi, dest_ton, dest_npi; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern u_char esm_class, pid_byte, dcs_byte; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern u_char prio_flag, reg_deliv, replace_flag; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern int input_lineno; |
225
243ed87880a1
smpp-send: implement sending via local socket
Mychaela Falconia <falcon@freecalypso.org>
parents:
223
diff
changeset
|
19 extern char *trx_socket; |
223
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 void |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 build_submit_sm(payload, payload_len, udhi) |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 u_char *payload; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned payload_len; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 { |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 u_char pdu[512], *dp, esm_class_inst; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 unsigned pdu_len, slen; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 /* sanity checks first */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (!src_addr[0]) { |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fprintf(stderr, ERR_PREFIX "src address is not set\n", |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 input_lineno); |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (!dest_addr[0]) { |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fprintf(stderr, ERR_PREFIX "dest address is not set\n", |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 input_lineno); |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 /* proceed */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 dp = pdu + 4; /* length will be filled last */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 /* command_id */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 *dp++ = 0x04; /* submit_sm */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 /* empty command_status */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 /* dummy sequence_number (will be overwritten by smpp-trx-sa) */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 *dp++ = 0; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 /* mandatory params */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 *dp++ = 0; /* empty service_type */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 *dp++ = src_ton; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 *dp++ = src_npi; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 slen = strlen(src_addr) + 1; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 bcopy(src_addr, dp, slen); |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 dp += slen; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 *dp++ = dest_ton; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 *dp++ = dest_npi; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 slen = strlen(dest_addr) + 1; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 bcopy(dest_addr, dp, slen); |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 dp += slen; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 esm_class_inst = esm_class; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (udhi) |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 esm_class_inst |= 0x40; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 *dp++ = esm_class_inst; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 *dp++ = pid_byte; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *dp++ = prio_flag; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 *dp++ = 0; /* empty schedule_delivery_time */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 *dp++ = 0; /* empty validity_period */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 *dp++ = reg_deliv; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 *dp++ = replace_flag; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 *dp++ = dcs_byte; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 *dp++ = 0; /* no canned messages */ |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 *dp++ = payload_len; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 bcopy(payload, dp, payload_len); |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 dp += payload_len; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 pdu_len = dp - pdu; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 pdu[0] = pdu_len >> 24; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 pdu[1] = pdu_len >> 16; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 pdu[2] = pdu_len >> 8; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 pdu[3] = pdu_len; |
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 /* local datagram socket output to be implemented */ |
225
243ed87880a1
smpp-send: implement sending via local socket
Mychaela Falconia <falcon@freecalypso.org>
parents:
223
diff
changeset
|
90 if (trx_socket) |
243ed87880a1
smpp-send: implement sending via local socket
Mychaela Falconia <falcon@freecalypso.org>
parents:
223
diff
changeset
|
91 send_pdu_via_socket(pdu, pdu_len); |
243ed87880a1
smpp-send: implement sending via local socket
Mychaela Falconia <falcon@freecalypso.org>
parents:
223
diff
changeset
|
92 else |
243ed87880a1
smpp-send: implement sending via local socket
Mychaela Falconia <falcon@freecalypso.org>
parents:
223
diff
changeset
|
93 hex_dump_output(pdu, pdu_len); |
223
f11c3e40c87a
new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |