Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
smsc_sema.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 #ifndef SMSC_SEMA_H
58 #define SMSC_SEMA_H
59 
60 #include "gwlib/gwlib.h"
61 #include "smsc.h"
62 #include "smsc_p.h"
63 
64 #define SM_RESULT_SUCCESS 0
65 #define SM_RESULT_FAIL_ARGS 1
66 #define SM_RESLUT_FAIL_SMSC_DB 2
67 #define SM_RESULT_FAIL_SMSC_BUSY 3
68 #define SM_RESULT_FAIL_SM_NOTFOUND 4
69 #define SM_RESULT_FAIL_SM_DUPLICATE 5
70 
71 #define SME_RESULT_SUCCESS 0
72 #define SME_RESULT_INVALIDDATA 1
73 #define SME_RESULT_DBFULL 2
74 #define SME_RESULT_SMEBUSY 3
75 #define SME_RESULT_NOTUSED 4
76 #define SME_RESULT_DUPLICATESM 5
77 #define SME_RESULT_DESTUNAVAILABLE 6
78 #define SME_RESULT_CALLBARREDUSER 7
79 #define SME_RESULT_TRANSMISSION 21
80 #define SME_RESULT_FACILITYNOTSUPPORT 22
81 #define SME_RESULT_ERRORINSME 23
82 #define SME_RESULT_UNKNOWNSUBSCRIBER 24
83 #define SME_RESULT_CALLBARREDOPERATOR 25
84 #define SME_RESULT_CUGVIOLATION 26
85 #define SME_RESULT_NETWORKFAIL 120
86 
87 #define ENCODE_IA5 15
88 #define ENCODE_GSM 0
89 
90 
91 /*internal definition*/
92 #define LINE_ENCODE_IA5 1
93 #define LINE_ENCODE_HEX 2
94 #define LINE_ENCODE_BIN 3
95 
96 #define X28_COMMAND_MODE 0
97 #define X28_MT_DATA_MODE 1
98 #define X28_MO_DATA_MODE 2
99 
100 #define INTERNAL_DISCONNECT_TIMEVAL 3
101 #define INTERNAL_READFD_TIMEVAL 1
102 #define INTERNAL_CONNECT_TIMEVAL 5
103 #define INTERNAL_SESSION_MT_TIMEVAL 20
104 
105 #define SESSION_MT_RECEIVE_ERR 0
106 #define SESSION_MT_RECEIVE_TIMEOUT 1
107 #define SESSION_MT_RECEIVE_SUCCESS 2
108 
109 
110 typedef struct msg_hash{
111  int key;
113 } msg_hash;
114 
115 
116 
117 typedef struct sema_msg{
118  unsigned char type; /*1 byte */
119  unsigned char continuebyte; /* 1 byte */
120  unsigned char optref[4]; /*4 byte int */
121  int encodetype; /* 1 byte ,0 is IA5, 1 is hex, 2 is bin */
122  time_t logtime;
123 
124  void *msgbody; /* the actual message structure */
125 
126  struct sema_msg *prev, *next;
127 } sema_msg;
128 
129 
130 typedef struct sema_msglist{
131  int count;
134 
135 }sema_msglist;
136 
137 
138 
139 typedef struct sm_statusreport_result{
140  unsigned int smeresult; /*see spec*/
142 
143 typedef struct sm_statusreport_invoke{
144  unsigned int msisdnlen; /*1 byte*/
145  Octstr* msisdn; /* string */
146  unsigned int smetype; /* 1byte, 0-sme, 1-smsc */
147  unsigned char smerefnum[4]; /* 4 byte integer */
148  unsigned char smscrefnum[4]; /* 4 byte int */
149  char accepttime[14]; /*absolute format*/
150  unsigned int status;
151  char completetime[14]; /*absolute format*/
152  char intermediatime[14]; /*absolute format*/
153  unsigned int failreason; /*see spec*/
154  unsigned int origaddlen; /*1 byte;*/
155  Octstr* origadd; /*1 byte; */
156  char invoketime[14]; /*absolute format */
158 
159 
160 
161 typedef struct sm_submit_result{
162  unsigned int smeresult;
163  /*0- ok, 1-reject for rg problem, 2-db is full or db crash
164  3-fail for smsc busy, 4- sm is not in db. 5- fail for already
165  there(smsc ref or {sme ref, msdnid */
166 
167  unsigned char smscrefnum[4]; /* 4 byte int*/
168  char accepttime[14]; /*YYMMDDHHMMSSZZ*/
170 
171 typedef struct sm_submit_invoke{
172  unsigned int msisdnlen; /*1 byte*/
173  Octstr* msisdn; /* string */
174  unsigned int smereftype; /* 1btype 1 key, 0 not key */
175  unsigned char smerefnum[4]; /* 4 byte integer */
176  unsigned int priority; /* 1 byte, 0 means high, 2normal */
177  unsigned int origaddlen; /* 1 byte; */
178  Octstr* origadd; /* in X25 it will b overwritten by NUA,
179  if user login, it will home NUA */
180  unsigned int validperiodtype; /* 0-none, 1-absolute, 2-relative */
181  char validperiodabs[14];
182  unsigned int validperiodrela; /*1 byte ,usage see sema spec.*/
183 
184  unsigned int DCS; /* 1 byte */
185  unsigned int statusreportrequest;
186  /* 1 byte, 0-failed(abondon), 1-expire, 2-delivered, 3-delete by sme,
187  4-delete by smsc operator 5 retry*/
188  unsigned int protocal; /*1 byte */
189  unsigned int replypath; /* 0 mean can not use sender smsc, 1 means can*/
190  unsigned int textsizeseptet; /*1byte, in gsm format, it's 7 bits*/
191  unsigned int textsizeoctect; /* 1 byte in 8 bits */
193 
194  unsigned char smscrefnum[4];
196 
197 
198 typedef struct sm_deliver_result{ /* if ok, must return */
199  unsigned int smeresult; /* 0- ok, 1-reject for rg problem, 2-db is
200  full or db crash*/
202 
203 typedef struct sm_deliver_invoke{
204  unsigned int destaddlen; /*1 byte*/
205  Octstr* destadd; /*string*/
206  unsigned char smscrefnum[4]; /*4 byte integer*/
207  unsigned int origaddlen; /*1 byte*/
208  Octstr* origadd; /* note, in X25 it will b overwritten by NUA,
209  if user login, it will home NUA*/
210 
211  unsigned int DCS; /*1 byte*/
212  unsigned int protocal; /*1 byte*/
213  unsigned int replypath; /* 0 mean can not use sender smsc, 1 means can*/
214  unsigned int textsizeseptet; /* 1byte, in gsm format, it's 7 bits */
215  unsigned int textsizeoctect; /* 1 byte in 8 bits */
217  char accepttime[14];
218  char invoketime[14];
219 
220  /*note in X25 sublogical number is omit*/
221 
223 
224 
225 /********************** unimplemted msg here
226 typedef struct sm_login_result{
227  unsigned int result;
228 } sm_login_result;
229 
230 typedef struct sm_login{
231  unsigned int homenualen;
232  Octstr* homenua;
233  unsigned char pim[2];
234  unsigned int result;
235 } sm_login;
236 
237 typedef struct sm_delete_invoke_result{
238  unsigned int result;
239 } sm_delete_invoke_result;
240 
241 typedef struct sm_delete_invoke{
242  unsigned int smtype;
243  unsigned char smscrefnum[4];
244  unsigned char smerefnum[4];
245  unsigned int msisdnlen;
246  Octstr* msisdn;
247  unsigned int origaddlen;
248  Octstr* origadd;
249 
250 }sm_delete_invoke;
251 
252 typedef struct sm_deleteall_invoke{
253  unsigned int msisdnlen;
254  Octstr* msisdn;
255  unsigned int origaddlen;
256  Octstr* origadd;
257  unsigned int nostatusreport;
258 
259 }sm_deleteall_invoke;
260 
261 
262 typedef struct sm_replace_result{
263  unsigned int delete_result;
264  unsigned int add_result;
265  unsigned char smscrefnum[4];
266  char accepttime[14];
267 } sm_replace_result;
268 
269 typedef struct sm_replace_invoke{
270  unsigned int smtype;
271  unsigned char smscrefnum[4];
272  unsigned char smerefnum[4];
273  unsigned int msisdnlen;
274  Octstr* msisdn;
275  unsigned int new_smereftype;
276  unsigned char new_smerefnum[4];
277  unsigned int new_priority;
278  unsigned int new_origaddlen;
279  Octstr* new_origadd;
280  unsigned int new_validperiodtype;
281  unsigned char new_validperiodabs[14];
282  unsigned int new_validperiodrela;
283  unsigned int new_DCS;
284  unsigned int new_statusreportrequest;
285  unsigned int new_protocal;
286  unsigned int new_replypath;
287  unsigned int new_textsizechar;
288  unsigned int new_textsizebyte;
289  Octstr* new_shortmsg;
290 
291 }sm_replace_invoke;
292 
293 
294 typedef struct 2K_ENQUIRE_INVOKE{
295  int smtype;
296  int smscrefnum;
297  int smerefnum;
298  int msisdnlen;
299  Octstrr* msisdn;
300  int origaddlen;
301  Octstr* origadd;
302  int enquiretype;
303 
304 }sm_enqire_invoke;
305 
306 
307 typedef struct 2K_ENQUIRE_RESULT{
308  int result;
309  int enquiretype;
310  int status;
311  char[15] completetime;
312  int failreason;
313  int priority;
314  int origaddlen;
315  char* origadd;
316  char[15] accepttime;
317  char[15] exipretime;
318  int DCS;
319  int statusreportrequest;
320  int protocalid;
321  int replypath;
322  int textsizechar;
323  int textsizebyte;
324  char* shortmsg;
325 
326 }sm_enqire_result;
327 
328 other msg type ...******************************
329 */
330 
331 
332 /* function definition */
333 static int sema_submit_result(SMSCenter*, sema_msg*, int);
334 
335 static int X28_open_data_link(char*);
336 
337 static int X28_reopen_data_link(int,char*);
338 
339 static int X28_close_send_link(int);
340 
341 static int X28_open_send_link(int,char*);
342 
343 static int X28_data_read(int, char*);
344 
345 static int X28_data_send(int, char*, int);
346 
347 static int X28_msg_pop(char *, char *);
348 
349 static int sema_msg_session_mt(SMSCenter*, sema_msg*);
350 
351 static int sema_msg_session_mo(SMSCenter*, char*);
352 
353 static sema_msg* sema_msg_new(void);
354 
355 static int sema_msg_free(sema_msg *msg);
356 
357 static sema_msglist* sema_msglist_new(void);
358 
359 static void sema_msglist_free(sema_msglist*);
360 
362 
363 static int sema_msglist_pop(sema_msglist*, sema_msg**);
364 
365 /* static int sema_msgbuffer_pop(Octstr *, Octstr **); */
366 
367 static int sema_decode_msg(sema_msg**, char*);
368 
369 static int sema_encode_msg(sema_msg*, char*);
370 
371 static int line_append_hex_IA5(Octstr* , unsigned char*, int);
372 
373 static int line_scan_IA5_hex(char*, int, unsigned char*);
374 
375 static int line_scan_hex_GSM7(unsigned char*,int,int,unsigned char*);
376 
377 static int internal_char_IA5_to_hex(char *, unsigned char *);
378 
379 static int internal_char_hex_to_IA5(unsigned char, unsigned char *);
380 
381 static unsigned char internal_char_hex_to_gsm(unsigned char from);
382 
383 static int unpack_continous_byte(unsigned char, int *, int * , int *);
384 
385 static unsigned char pack_continous_byte(int, int, int);
386 
387 static void increment_counter(void);
388 
389 #endif
390 
391 
392 
393 
394 
395 
396 
397 
398 
399 
400 
static unsigned char internal_char_hex_to_gsm(unsigned char from)
unsigned int smeresult
Definition: smsc_sema.h:140
Octstr * shortmsg
Definition: smsc_sema.h:216
unsigned int statusreportrequest
Definition: smsc_sema.h:185
static int internal_char_hex_to_IA5(unsigned char, unsigned char *)
static sema_msg * sema_msg_new(void)
char invoketime[14]
Definition: smsc_sema.h:218
struct sema_msg * next
Definition: smsc_sema.h:126
static int sema_decode_msg(sema_msg **, char *)
unsigned int textsizeoctect
Definition: smsc_sema.h:215
static int sema_msglist_pop(sema_msglist *, sema_msg **)
static int sema_msg_session_mt(SMSCenter *, sema_msg *)
static int line_scan_IA5_hex(char *, int, unsigned char *)
unsigned int textsizeoctect
Definition: smsc_sema.h:191
Octstr * destadd
Definition: smsc_sema.h:205
static int internal_char_IA5_to_hex(char *, unsigned char *)
time_t logtime
Definition: smsc_sema.h:122
static int unpack_continous_byte(unsigned char, int *, int *, int *)
char validperiodabs[14]
Definition: smsc_sema.h:181
unsigned int origaddlen
Definition: smsc_sema.h:177
static unsigned char pack_continous_byte(int, int, int)
struct sm_submit_invoke sm_submit_invoke
unsigned int replypath
Definition: smsc_sema.h:213
unsigned int smereftype
Definition: smsc_sema.h:174
struct sm_deliver_invoke sm_deliver_invoke
unsigned char optref[4]
Definition: smsc_sema.h:120
unsigned int protocal
Definition: smsc_sema.h:212
unsigned char continuebyte
Definition: smsc_sema.h:119
unsigned int validperiodtype
Definition: smsc_sema.h:180
unsigned char smerefnum[4]
Definition: smsc_sema.h:147
unsigned char smscrefnum[4]
Definition: smsc_sema.h:194
struct sm_statusreport_invoke sm_statusreport_invoke
struct sema_msg * prev
Definition: smsc_sema.h:126
static int sema_msg_session_mo(SMSCenter *, char *)
unsigned int validperiodrela
Definition: smsc_sema.h:182
unsigned int smeresult
Definition: smsc_sema.h:162
char accepttime[14]
Definition: smsc_sema.h:217
static Octstr * from
Definition: mtbatch.c:95
unsigned int priority
Definition: smsc_sema.h:176
static int X28_msg_pop(char *, char *)
unsigned char smscrefnum[4]
Definition: smsc_sema.h:167
struct sema_msglist sema_msglist
static int sema_encode_msg(sema_msg *, char *)
unsigned char type
Definition: smsc_sema.h:118
Octstr * content
Definition: smsc_sema.h:112
struct msg_hash msg_hash
struct sm_statusreport_result sm_statusreport_result
Octstr * origadd
Definition: smsc_sema.h:208
static int X28_close_send_link(int)
unsigned int msisdnlen
Definition: smsc_sema.h:172
static sema_msglist * sema_msglist_new(void)
Octstr * msisdn
Definition: smsc_sema.h:173
static int X28_open_data_link(char *)
static int X28_open_send_link(int, char *)
int encodetype
Definition: smsc_sema.h:121
unsigned int protocal
Definition: smsc_sema.h:188
unsigned int textsizeseptet
Definition: smsc_sema.h:190
unsigned int failreason
Definition: smsc_sema.h:153
unsigned int status
Definition: smsc_sema.h:150
unsigned int DCS
Definition: smsc_sema.h:184
Octstr * origadd
Definition: smsc_sema.h:178
unsigned int textsizeseptet
Definition: smsc_sema.h:214
unsigned int origaddlen
Definition: smsc_sema.h:154
static int sema_msg_free(sema_msg *msg)
static int line_append_hex_IA5(Octstr *, unsigned char *, int)
static void increment_counter(void)
unsigned int origaddlen
Definition: smsc_sema.h:207
Definition: octstr.c:118
unsigned int replypath
Definition: smsc_sema.h:189
static int X28_data_read(int, char *)
char accepttime[14]
Definition: smsc_sema.h:168
static int line_scan_hex_GSM7(unsigned char *, int, int, unsigned char *)
unsigned int msisdnlen
Definition: smsc_sema.h:144
static void sema_msglist_free(sema_msglist *)
unsigned int DCS
Definition: smsc_sema.h:211
struct sema_msg sema_msg
unsigned char smscrefnum[4]
Definition: smsc_sema.h:148
static int X28_data_send(int, char *, int)
unsigned int destaddlen
Definition: smsc_sema.h:204
void * msgbody
Definition: smsc_sema.h:124
static int sema_msglist_push(sema_msglist *, sema_msg *)
unsigned char smerefnum[4]
Definition: smsc_sema.h:175
sema_msg * first
Definition: smsc_sema.h:132
unsigned int smetype
Definition: smsc_sema.h:146
unsigned char smscrefnum[4]
Definition: smsc_sema.h:206
static int X28_reopen_data_link(int, char *)
int key
Definition: smsc_sema.h:111
Octstr * shortmsg
Definition: smsc_sema.h:192
static int sema_submit_result(SMSCenter *, sema_msg *, int)
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
struct sm_submit_result sm_submit_result
struct sm_deliver_result sm_deliver_result
sema_msg * last
Definition: smsc_sema.h:133
unsigned int smeresult
Definition: smsc_sema.h:199
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.