annotate smpp-send/build_pdu.c @ 224:62184b971c8e

smpp-send/input.c: copy-n-paste error
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 12:27:36 -0800
parents f11c3e40c87a
children 243ed87880a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 void
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 build_submit_sm(payload, payload_len, udhi)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 u_char *payload;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 unsigned payload_len;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 u_char pdu[512], *dp, esm_class_inst;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned pdu_len, slen;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 /* sanity checks first */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (!src_addr[0]) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 fprintf(stderr, ERR_PREFIX "src address is not set\n",
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (!dest_addr[0]) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr, ERR_PREFIX "dest address is not set\n",
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /* proceed */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 dp = pdu + 4; /* length will be filled last */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 /* command_id */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 *dp++ = 0;
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++ = 0x04; /* submit_sm */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 /* empty command_status */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *dp++ = 0;
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 /* dummy sequence_number (will be overwritten by smpp-trx-sa) */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *dp++ = 0;
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 /* mandatory params */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 *dp++ = 0; /* empty service_type */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 *dp++ = src_ton;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 *dp++ = src_npi;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 slen = strlen(src_addr) + 1;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 bcopy(src_addr, dp, slen);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 dp += slen;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 *dp++ = dest_ton;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 *dp++ = dest_npi;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 slen = strlen(dest_addr) + 1;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 bcopy(dest_addr, dp, slen);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 dp += slen;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 esm_class_inst = esm_class;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (udhi)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 esm_class_inst |= 0x40;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 *dp++ = esm_class_inst;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 *dp++ = pid_byte;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 *dp++ = prio_flag;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 *dp++ = 0; /* empty schedule_delivery_time */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 *dp++ = 0; /* empty validity_period */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 *dp++ = reg_deliv;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 *dp++ = replace_flag;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *dp++ = dcs_byte;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 *dp++ = 0; /* no canned messages */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 *dp++ = payload_len;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 bcopy(payload, dp, payload_len);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 dp += payload_len;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 pdu_len = dp - pdu;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 pdu[0] = pdu_len >> 24;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 pdu[1] = pdu_len >> 16;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 pdu[2] = pdu_len >> 8;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 pdu[3] = pdu_len;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 /* local datagram socket output to be implemented */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 hex_dump_output(pdu, pdu_len);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }