/
proto_smpp.h
238 lines (209 loc) · 7.13 KB
/
proto_smpp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* Copyright (C) 2019 - OpenSIPS Project
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef _PROTO_SMPP_H_
#define _PROTO_SMPP_H_
#define SMPP_UNKNOWN 0
#define SMPP_OPEN 1
#define SMPP_BOUND_TX 2
#define SMPP_BOUND_RX 4
#define SMPP_BOUND_TRX 6
#define SMPP_CLOSED 7
#define SMPP_BIND_TRANSCEIVER 0
#define SMPP_BIND_TRANSMITTER 1
#define SMPP_BIND_RECEIVER 2
#define SMPP_OUTBIND 3
#define SMPP_VERSION 0x34
#define HEADER_SZ 16
#define BIND_RECEIVER_BODY_MAX_SZ 82
#define BIND_TRANSMITTER_BODY_MAZ_SZ BIND_RECEIVER_RESP_BODY_MAX_SZ
#define BIND_TRANSCEIVER_BODY_MAZ_SZ BIND_RECEIVER_RESP_BODY_MAX_SZ
#define BIND_RECEIVER_RESP_BODY_MAX_SZ 16
#define BIND_TRANSMITTER_RESP_BODY_MAX_SZ BIND_RECEIVER_RESP_BODY_MAX_SZ
#define BIND_TRANSCEIVER_RESP_BODY_MAX_SZ BIND_RECEIVER_RESP_BODY_MAX_SZ
#define SUBMIT_SM_BODY_MAX_SZ 348
#define DELIVER_SM_RESP_BODY_MAX_SZ 1
#define SUBMIT_SM_RESP_BODY_MAX_SZ 1
#define ENQUIRE_LINK_BODY_MAX_SZ 0
#define REQ_MAX_SZ(_name) (HEADER_SZ + _name ## _BODY_MAX_SZ)
#define ESME_ROK 0x00000000
#define ESME_RBINDFAIL 0x0000000D
#define GENERIC_NACK_CID 0x80000000
#define BIND_RECEIVER_CID 0x00000001
#define BIND_RECEIVER_RESP_CID 0x80000001
#define BIND_TRANSMITTER_CID 0x00000002
#define BIND_TRANSMITTER_RESP_CID 0x80000002
#define QUERY_SM_CID 0x00000003
#define QUERY_SM_RESP_CID 0x80000003
#define SUBMIT_SM_CID 0x00000004
#define SUBMIT_SM_RESP_CID 0x80000004
#define DELIVER_SM_CID 0x00000005
#define DELIVER_SM_RESP_CID 0x80000005
#define UNBIND_CID 0x00000006
#define UNBIND_RESP_CID 0x80000006
#define REPLACE_SM_CID 0x00000007
#define REPLACE_SM_RESP_CID 0x80000007
#define CANCEL_SM_CID 0x00000008
#define CANCEL_SM_RESP_CID 0x80000008
#define BIND_TRANSCEIVER_CID 0x00000009
#define BIND_TRANSCEIVER_RESP_CID 0x80000009
#define OUTBIND_CID 0x0000000B
#define ENQUIRE_LINK_CID 0x00000015
#define ENQUIRE_LINK_RESP_CID 0x80000015
#define SUBMIT_MULTI_CID 0x00000021
#define SUBMIT_MULTI_RESP_CID 0x80000021
#define ALERT_NOTIFICATION_CID 0x00000102
#define DATA_SM_CID 0x00000103
#define DATA_SM_RESP_CID 0x80000103
#define GENERIC_NACK_CID_STR "generic_nack"
#define BIND_RECEIVER_CID_STR "bind_receiver"
#define BIND_RECEIVER_RESP_CID_STR "bind_receiver_resp"
#define BIND_TRANSMITTER_CID_STR "bind_transmitter"
#define BIND_TRANSMITTER_RESP_CID_STR "bind_transmitter_resp"
#define QUERY_SM_CID_STR "query_sm"
#define QUERY_SM_RESP_CID_STR "query_sm_resp"
#define SUBMIT_SM_CID_STR "submit_sm"
#define SUBMIT_SM_RESP_CID_STR "submit_sm_resp"
#define DELIVER_SM_CID_STR "deliver_sm"
#define DELIVER_SM_RESP_CID_STR "deliver_sm_resp"
#define UNBIND_CID_STR "unbind"
#define UNBIND_RESP_CID_STR "unbind_resp"
#define REPLACE_SM_CID_STR "replace_sm"
#define REPLACE_SM_RESP_CID_STR "replace_sm_resp"
#define CANCEL_SM_CID_STR "cancel_sm"
#define CANCEL_SM_RESP_CID_STR "cancel_sm_resp"
#define BIND_TRANSCEIVER_CID_STR "bind_transceiver"
#define BIND_TRANSCEIVER_RESP_CID_STR "bind_transceiver_resp"
#define OUTBIND_CID_STR "outbind"
#define ENQUIRE_LINK_CID_STR "enquire_link"
#define ENQUIRE_LINK_RESP_CID_STR "enquire_link_resp"
#define SUBMIT_MULTI_CID_STR "submit_multi"
#define SUBMIT_MULTI_RESP_CID_STR "submit_multi_resp"
#define ALERT_NOTIFICATION_CID_STR "alert_notification"
#define DATA_SM_CID_STR "data_sm"
#define DATA_SM_RESP_CID_STR "data_sm_resp"
typedef struct {
uint32_t command_length;
uint32_t command_id;
uint32_t command_status;
uint32_t sequence_number;
} smpp_header_t;
typedef struct smpp_optional{
uint16_t parameter_tag;
uint16_t length;
void *value;
struct smpp_optional *next;
} smpp_optional_t;
#define MAX_SYSTEM_ID_LEN 16
#define MAX_PASSWORD_LEN 9
#define MAX_SYSTEM_TYPE_LEN 13
#define MAX_ADDRESS_RANGE_LEN 41
typedef struct {
char system_id[MAX_SYSTEM_ID_LEN];
char password[MAX_PASSWORD_LEN];
char system_type[MAX_SYSTEM_TYPE_LEN];
uint8_t interface_version;
uint8_t addr_ton;
uint8_t addr_npi;
char address_range[MAX_ADDRESS_RANGE_LEN];
} smpp_bind_receiver_t;
typedef struct {
char system_id[MAX_SYSTEM_ID_LEN];
} smpp_bind_receiver_resp_t;
typedef smpp_bind_receiver_t smpp_bind_transmitter_t;
typedef smpp_bind_receiver_resp_t smpp_bind_transmitter_resp_t;
typedef smpp_bind_receiver_t smpp_bind_transceiver_t;
typedef smpp_bind_receiver_resp_t smpp_bind_transceiver_resp_t;
typedef struct {
char system_id[MAX_SYSTEM_ID_LEN];
char password[MAX_PASSWORD_LEN];
} smpp_outbind_t;
typedef struct {
char service_type[6];
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[21];
uint8_t dest_addr_ton;
uint8_t dest_addr_npi;
char destination_addr[21];
uint8_t esm_class;
uint8_t protocol_id;
uint8_t protocol_flag;
char schedule_delivery_time[1];
char validity_period[1];
uint8_t registered_delivery;
uint8_t replace_if_present_flag;
uint8_t data_coding;
uint8_t sm_default_msg_id;
uint8_t sm_length;
char short_message[254];
} smpp_submit_sm_t;
typedef struct {
char message_id[65];
} smpp_submit_sm_resp_t;
typedef smpp_submit_sm_t smpp_deliver_sm_t;
typedef smpp_submit_sm_resp_t smpp_deliver_sm_resp_t;
#define TYPEDEF_SMPP_REQUEST(_name) \
typedef struct { \
smpp_header_t *header; \
_name ## _t *body; \
smpp_optional_t *optionals; \
str payload; \
} _name ## _req_t
#define TYPEDEF_SIMPLE_SMPP_REQUEST(_name) \
typedef struct { \
smpp_header_t *header; \
smpp_optional_t *optionals; \
str payload; \
} _name ## _req_t
TYPEDEF_SMPP_REQUEST(smpp_bind_receiver);
TYPEDEF_SMPP_REQUEST(smpp_bind_receiver_resp);
TYPEDEF_SMPP_REQUEST(smpp_bind_transmitter);
TYPEDEF_SMPP_REQUEST(smpp_bind_transmitter_resp);
TYPEDEF_SMPP_REQUEST(smpp_bind_transceiver);
TYPEDEF_SMPP_REQUEST(smpp_bind_transceiver_resp);
TYPEDEF_SMPP_REQUEST(smpp_deliver_sm);
TYPEDEF_SMPP_REQUEST(smpp_deliver_sm_resp);
TYPEDEF_SMPP_REQUEST(smpp_submit_sm);
TYPEDEF_SMPP_REQUEST(smpp_submit_sm_resp);
TYPEDEF_SIMPLE_SMPP_REQUEST(smpp_enquire_link);
TYPEDEF_SIMPLE_SMPP_REQUEST(smpp_enquire_link_resp);
typedef struct smpp_session {
uint32_t id;
uint8_t session_status;
uint8_t session_type;
gen_lock_t sequence_number_lock;
uint32_t sequence_number;
struct ip_addr *ip;
int port;
struct tcp_connection *conn;
union {
smpp_bind_receiver_t receiver;
smpp_bind_transmitter_t trasmitter;
smpp_bind_transceiver_t transceiver;
smpp_outbind_t outbind;
} bind;
uint8_t source_addr_ton;
uint8_t source_addr_npi;
uint8_t dest_addr_ton;
uint8_t dest_addr_npi;
struct smpp_session *next;
} smpp_session_t;
#endif