-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibSMPP.h
597 lines (459 loc) · 16.8 KB
/
libSMPP.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <semaphore.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <unistd.h>
#include <signal.h>
#include <limits.h>
#include <poll.h>
#include <sys/epoll.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <error.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <resolv.h>
#ifndef LIB_NGTFF_SMPP_H
#define LIB_NGTFF_SMPP_H
#include "jansson.h"
#define NFTFF_SMPP_BIND_TRANSMITTER 0x00000002
#define NFTFF_SMPP_BIND_TRANSMITTER_RESP 0x80000002
#define NFTFF_SMPP_BIND_RECEIVER 0x00000001
#define NFTFF_SMPP_BIND_RECEIVER_RESP 0x80000001
#define NFTFF_SMPP_BIND_TRANSCEIVER 0x00000009
#define NFTFF_SMPP_BIND_TRANSCEIVER_RESP 0x80000009
#define NFTFF_SMPP_OUTBIND 0x0000000B
#define NFTFF_SMPP_UNBIND 0x00000006
#define NFTFF_SMPP_UNBIND_RESP 0x80000006
#define NFTFF_SMPP_GENERIC_NACK 0x80000000
#define NFTFF_SMPP_SUBMIT_SM 0x00000004
#define NFTFF_SMPP_SUBMIT_SM_RESP 0x80000004
#define NFTFF_SMPP_SUBMIT_MULTI 0x00000021
#define NFTFF_SMPP_SUBMIT_MULTI_RESP 0x80000021
#define NFTFF_SMPP_DELIVER_SM 0x00000005
#define NFTFF_SMPP_DELIVER_SM_RESP 0x80000005
#define NFTFF_SMPP_DATA_SM 0x00000103
#define NFTFF_SMPP_DATA_SM_RESP 0x80000103
#define NFTFF_SMPP_QUERY_SM 0x00000003
#define NFTFF_SMPP_QUERY_SM_RESP 0x80000003
#define NFTFF_SMPP_CANCEL_SM 0x00000008
#define NFTFF_SMPP_CANCEL_SM_RESP 0x80000008
#define NFTFF_SMPP_REPLACE_SM 0x00000007
#define NFTFF_SMPP_REPLACE_SM_RESP 0x80000007
#define NFTFF_SMPP_ENQUIRE_LINK 0x00000015
#define NFTFF_SMPP_ENQUIRE_LINK_RESP 0x80000015
#define NFTFF_SMPP_ALERT_NOTIFICATION 0x00000102
typedef struct ngtff_smpp_session
{
struct ngtff_smpp_session * Next;
uint8_t * siSocket;
char system_id[17];
uint8_t interface_version;
} NGTFF__smpp_session_t;
typedef struct ngtff_smpp_sock_msg
{
uint8_t * siSocket;
u_char * data;
int len;
int pos;
int decode_sts;
} NGTFF__socket_msg_t;
typedef struct ngtff_smpp_raw_pdu
{
u_char buffer[5000];
int pos;
int len;
} NGTFF__raw_pdu_t;
typedef struct ngtff__smpp_command
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
} NGTFF_smpp_command_t;
/*
smpp pdu messages are currently same for bind_transmitter(2), bind_receiver(1), bind_transceiver(9)
*/
typedef struct ngtff__bind
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
char system_id[17]; //max 16 + 1 for NULL C-Octet-String
char password[10]; //max 9 + 1 for NULL C-Octet-String
char system_type[14]; //max 13 + 1 for NULL C-Octet-String
uint8_t interface_version; //1 byte
uint8_t addr_ton; //1 byte Type of Number of the ESME address. If not known set to NULL.
uint8_t addr_npi; //Numbering Plan Indicator for ESME address. If not known set to NULL
char address_range[42]; //max 41 + 1 for NULL C-Octet-String
} NGTFF__bind_t;
/*
smpp pdu messages are currently same for bind_transmitter_resp(0x80000002), bind_receiver_resp(0x80000001), bind_transceive_resp(0x80000009)
*/
typedef struct ngtff__bind_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
char system_id[17]; //max 16 + 1 for NULL C-Octet-String
//Optional TLVs:
//sc_interface_version TLV SMPP version supported by MC
} NGTFF__bind_resp_t;
typedef struct ngtff__outbind
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x0000000B
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
char system_id[17]; //max 16 + 1 for NULL C-Octet-String MC identifier., Identifies the MC to the ESME.
char password[10]; //max 9 + 1 for NULL C-Octet-String
/*
The password may be used by the ESME for security reasons to authenticate the MC originating the outbind
*/
} NGTFF__outbind_t;
typedef struct ngtff__unbind
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x00000006
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
} NGTFF__unbind_t;
typedef struct ngtff__unbind_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000006
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
} NGTFF__unbind_resp_t;
typedef struct ngtff__enquire_link
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x00000015
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
} NGTFF__enquire_link_t;
typedef struct ngtff__enquire_link_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000015
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
} NGTFF__enquire_link_resp_t;
typedef struct ngtff__alert_notification
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x00000102
uint32_t command_status; //4 bytes
uint32_t sequence_number; //4 bytes
uint8_t source_addr_ton; //1 byte Type of Number for alert SME.
uint8_t source_addr_npi; //1 byte Numbering Plan Indicator for alert SME.
char source_addr[66]; //max 65 Address of alert SME.
uint8_t esme_addr_ton;
uint8_t esme_addr_npi;
char esme_addr[66]; //max 65 Address of alert SME.
//Optional TLVs:
//ms_availability_status //status of the mobile station
} NGTFF__alert_notification_t;
typedef struct ngtff__generic_nack
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
} NGTFF__generic_nack_t;
typedef struct ngtff__submit_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char service_type[7]; //max 6
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22]; //max 21
uint8_t dest_addr_ton;
uint8_t dest_addr_npi;
char destination_addr[22]; //max 21
uint8_t esm_class;
uint8_t protocol_id;
uint8_t priority_flag;
char schedule_delivery_time[18]; //max 17, 1 or 17 The short message is to be scheduled by the MC for delivery.
//Set to NULL for immediate message delivery
char validity_period[18]; //max 17, 1 or 17 The validity period of this message..
//Set to NULL to request the MC default validity period
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[255]; //0-255, max 255 Up to 255 octets of short message user data.
//Message Submission TLVs
} NGTFF__submit_sm_t;
typedef struct NGTFF__submit_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66]; //max 66
//Message Submission Response TLVs
} NGTFF__submit_sm_resp_t;
typedef struct NGTFF__data_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char service_type[7]; //max 6
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22]; //max 21
uint8_t dest_addr_ton;
uint8_t dest_addr_npi;
char destination_addr[22]; //max 21
uint8_t esm_class;
uint8_t data_coding;
uint8_t sm_length;
char short_message[255]; //0-255, max 255 Up to 255 octets of short message user data.
//Message Submission TLVs
} NGTFF__data_sm_t;
typedef struct NGTFF__data_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66]; //max 66
//Message Submission Response TLVs
} NGTFF__data_sm_resp_t;
typedef struct NGTFF__submit_multi
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char service_type[7]; //max 6
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22]; //max 21
uint8_t number_of_dests;
//dest_address
uint8_t esm_class;
uint8_t protocol_id;
uint8_t priority_flag;
char schedule_delivery_time[18]; //max 17
char validity_period[18]; //max 17
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[256];
//Message Submission TLVs
} NGTFF__submit_multi_t;
typedef struct NGTFF__submit_multi_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[65]; //max 17
uint8_t no_unsuccess;
char unsuccess_sme[28]; //max 28
//Message Submission Response TLVs
} NGTFF__submit_multi_resp_t;
typedef struct NGTFF__deliver_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char service_type[7]; //max 6
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22];
uint8_t dest_addr_ton;
uint8_t dest_addr_npi;
char destination_addr[22];
uint8_t esm_class;
uint8_t protocol_id;
uint8_t priority_flag;
char schedule_delivery_time[18];
char validity_period[18];
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[256];
//Message Delivery Request TLVs
} NGTFF__deliver_sm_t;
typedef struct NGTFF__deliver_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66];
} NGTFF__deliver_sm_resp_t;
typedef struct NGTFF__broadcast_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char service_type[7];
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22];
char message_id[66];
uint8_t priority_flag;
char schedule_delivery_time[18];
char validity_period[18];
uint8_t replace_if_present_flag;
uint8_t data_coding;
uint8_t sm_default_msg_id;
//tlv
//broadcast_area_identifier
//broadcast_content_type
//broadcast_rep_num
//broadcast_frequency_interval
//Broadcast Request Optional TLVs
} NGTFF__broadcast_sm_t;
typedef struct NGTFF__broadcast_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66];
//Broadcast Request Optional TLVs
} NGTFF__broadcast_sm_resp_t;
typedef struct NGTFF__cancel_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char service_type[7];
char message_id[66];
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22];
uint8_t dest_addr_ton;
uint8_t dest_addr_npi;
char destination_addr[22];
} NGTFF__cancel_sm_t;
typedef struct NGTFF__cancel_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
} NGTFF__cancel_sm_resp_t;
typedef struct NGTFF__query_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66];
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22];
} NGTFF__query_sm_t;
typedef struct NGTFF__query_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66];
char final_date[18];
uint8_t message_state;
uint8_t error_code;
} NGTFF__query_sm_resp_t;
typedef struct NGTFF__replace_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66];
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22];
char schedule_delivery_time[18];
char validity_period[18];
uint8_t registered_delivery;
uint8_t sm_default_msg_id;
uint8_t sm_length;
char short_message[256];
} NGTFF__replace_sm_t;
typedef struct NGTFF__replace_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
} NGTFF__replace_sm_resp_t;
typedef struct NGTFF__query_broadcast_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66];
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22];
} NGTFF__query_broadcast_sm_t;
typedef struct NGTFF__query_broadcast_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char message_id[66];
//TLV
//message_state
//broadcast_area_identifier
//broadcast_area_success
//Query Broadcast Response TLVs
} NGTFF__query_broadcast_sm_resp_t;
typedef struct NGTFF__cancel_broadcast_sm
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
char service_type[7];
char message_id[66];
uint8_t source_addr_ton;
uint8_t source_addr_npi;
char source_addr[22];
} NGTFF__cancel_broadcast_sm_t;
typedef struct NGTFF__cancel_broadcast_sm_resp
{
uint32_t command_length; //4 bytes
uint32_t command_id; //4 bytes 0x80000000
uint32_t command_status; //4 bytes Error code corresponding to reason for sending the generic_nack.
uint32_t sequence_number; //4 bytes
} NGTFF__cancel_broadcast_sm_resp_t;
void ngtff__smpp_set_command_length( NGTFF__raw_pdu_t * rpdu);
void ngtff__smpp_initalize( char * jsonconfigfile);
void ngtff__smpp_start();
json_t * ngtff__smpp_get_config_object();
void ngtff__smpp_add_esme( json_t * esme);
#endif