Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

smsc_sema.h

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 #ifndef SMSC_SEMA_H
00058 #define SMSC_SEMA_H
00059 
00060 #include "gwlib/gwlib.h"
00061 #include "smsc.h"
00062 #include "smsc_p.h"
00063 
00064 #define SM_RESULT_SUCCESS 0
00065 #define SM_RESULT_FAIL_ARGS 1
00066 #define SM_RESLUT_FAIL_SMSC_DB 2
00067 #define SM_RESULT_FAIL_SMSC_BUSY 3
00068 #define SM_RESULT_FAIL_SM_NOTFOUND 4
00069 #define SM_RESULT_FAIL_SM_DUPLICATE 5
00070 
00071 #define SME_RESULT_SUCCESS 0
00072 #define SME_RESULT_INVALIDDATA 1
00073 #define SME_RESULT_DBFULL 2
00074 #define SME_RESULT_SMEBUSY 3
00075 #define SME_RESULT_NOTUSED 4
00076 #define SME_RESULT_DUPLICATESM 5
00077 #define SME_RESULT_DESTUNAVAILABLE 6
00078 #define SME_RESULT_CALLBARREDUSER 7
00079 #define SME_RESULT_TRANSMISSION 21
00080 #define SME_RESULT_FACILITYNOTSUPPORT 22
00081 #define SME_RESULT_ERRORINSME 23
00082 #define SME_RESULT_UNKNOWNSUBSCRIBER 24
00083 #define SME_RESULT_CALLBARREDOPERATOR 25
00084 #define SME_RESULT_CUGVIOLATION 26
00085 #define SME_RESULT_NETWORKFAIL 120
00086 
00087 #define ENCODE_IA5 15
00088 #define ENCODE_GSM 0
00089 
00090 
00091 /*internal definition*/
00092 #define LINE_ENCODE_IA5 1
00093 #define LINE_ENCODE_HEX 2
00094 #define LINE_ENCODE_BIN 3
00095 
00096 #define X28_COMMAND_MODE 0
00097 #define X28_MT_DATA_MODE 1
00098 #define X28_MO_DATA_MODE 2
00099 
00100 #define INTERNAL_DISCONNECT_TIMEVAL 3
00101 #define INTERNAL_READFD_TIMEVAL 1
00102 #define INTERNAL_CONNECT_TIMEVAL 5
00103 #define INTERNAL_SESSION_MT_TIMEVAL 20
00104 
00105 #define SESSION_MT_RECEIVE_ERR 0
00106 #define SESSION_MT_RECEIVE_TIMEOUT 1
00107 #define SESSION_MT_RECEIVE_SUCCESS 2
00108 
00109 
00110 typedef struct msg_hash{
00111   int key;
00112   Octstr* content;
00113 } msg_hash;
00114 
00115 
00116 
00117 typedef struct sema_msg{
00118   unsigned char type; /*1 byte */
00119   unsigned char continuebyte; /* 1 byte */
00120   unsigned char optref[4]; /*4 byte int */
00121   int encodetype; /* 1 byte ,0 is IA5, 1 is hex, 2 is bin */
00122   time_t logtime;
00123 
00124   void *msgbody; /* the actual message structure */ 
00125  
00126   struct sema_msg *prev, *next; 
00127 } sema_msg;
00128 
00129 
00130 typedef struct sema_msglist{
00131     int count;
00132     sema_msg* first;
00133     sema_msg* last;
00134 
00135 }sema_msglist;
00136 
00137 
00138 
00139 typedef struct sm_statusreport_result{
00140     unsigned int smeresult; /*see spec*/
00141 }sm_statusreport_result;
00142 
00143 typedef struct sm_statusreport_invoke{
00144     unsigned int msisdnlen; /*1 byte*/
00145     Octstr* msisdn; /* string */
00146     unsigned int smetype; /* 1byte, 0-sme, 1-smsc */
00147     unsigned char smerefnum[4]; /* 4 byte integer */
00148     unsigned char smscrefnum[4]; /* 4 byte int */
00149     char accepttime[14]; /*absolute format*/
00150     unsigned int status; 
00151     char completetime[14]; /*absolute format*/
00152     char intermediatime[14]; /*absolute format*/
00153     unsigned int failreason; /*see spec*/
00154     unsigned int origaddlen; /*1 byte;*/
00155     Octstr* origadd; /*1 byte; */
00156     char invoketime[14]; /*absolute format */
00157 }sm_statusreport_invoke;
00158 
00159 
00160 
00161 typedef struct sm_submit_result{ 
00162     unsigned int smeresult; 
00163   /*0- ok, 1-reject for rg problem, 2-db is full or db crash
00164   3-fail for smsc busy, 4- sm is not in db. 5- fail for already
00165   there(smsc ref or {sme ref, msdnid */
00166 
00167     unsigned char smscrefnum[4]; /* 4 byte int*/
00168     char accepttime[14]; /*YYMMDDHHMMSSZZ*/
00169 } sm_submit_result;
00170 
00171 typedef struct sm_submit_invoke{
00172     unsigned int msisdnlen; /*1 byte*/
00173     Octstr* msisdn; /* string */
00174     unsigned int smereftype; /* 1btype 1 key, 0 not key */
00175     unsigned char smerefnum[4]; /* 4 byte integer */
00176     unsigned int priority; /* 1 byte, 0 means high, 2normal */
00177     unsigned int origaddlen; /* 1 byte; */
00178     Octstr* origadd; /* in X25 it will b overwritten by NUA,
00179                 if user login, it will home NUA */
00180     unsigned int validperiodtype; /* 0-none, 1-absolute, 2-relative */
00181     char validperiodabs[14]; 
00182     unsigned int validperiodrela; /*1 byte ,usage see sema spec.*/
00183 
00184     unsigned int DCS; /* 1 byte */
00185     unsigned int statusreportrequest; 
00186     /* 1 byte, 0-failed(abondon), 1-expire, 2-delivered, 3-delete by sme,
00187        4-delete by smsc operator 5 retry*/
00188     unsigned int protocal; /*1 byte */
00189     unsigned int replypath; /* 0 mean can not use sender smsc, 1 means can*/
00190     unsigned int textsizeseptet; /*1byte, in gsm format, it's 7 bits*/
00191     unsigned int textsizeoctect; /* 1 byte in 8 bits */
00192     Octstr* shortmsg;
00193   
00194         unsigned char smscrefnum[4];
00195 }sm_submit_invoke;
00196 
00197 
00198 typedef struct sm_deliver_result{ /* if ok, must return */
00199     unsigned int smeresult; /* 0- ok, 1-reject for rg problem, 2-db is
00200                    full or db crash*/
00201 } sm_deliver_result;
00202 
00203 typedef struct sm_deliver_invoke{
00204     unsigned int destaddlen; /*1 byte*/
00205     Octstr* destadd; /*string*/
00206     unsigned char smscrefnum[4]; /*4 byte integer*/
00207     unsigned int origaddlen; /*1 byte*/
00208     Octstr* origadd; /* note, in X25 it will b overwritten by NUA,
00209                 if user login, it will home NUA*/
00210 
00211     unsigned int DCS; /*1 byte*/
00212     unsigned int protocal; /*1 byte*/
00213     unsigned int replypath; /* 0 mean can not use sender smsc, 1 means can*/
00214     unsigned int textsizeseptet; /* 1byte, in gsm format, it's 7 bits */
00215     unsigned int textsizeoctect; /* 1 byte in 8 bits */
00216     Octstr* shortmsg;
00217     char accepttime[14];
00218     char invoketime[14];
00219    
00220   /*note in X25 sublogical number is omit*/
00221     
00222 }sm_deliver_invoke;
00223 
00224 
00225 /********************** unimplemted msg here
00226 typedef struct sm_login_result{ 
00227     unsigned int result; 
00228 } sm_login_result;
00229 
00230 typedef struct sm_login{
00231     unsigned int homenualen;
00232     Octstr* homenua;
00233     unsigned char pim[2]; 
00234     unsigned int result;
00235 } sm_login;
00236 
00237 typedef struct sm_delete_invoke_result{
00238     unsigned int result; 
00239 } sm_delete_invoke_result;
00240 
00241 typedef struct sm_delete_invoke{
00242     unsigned int smtype;
00243     unsigned char smscrefnum[4];
00244     unsigned char smerefnum[4]; 
00245     unsigned int msisdnlen; 
00246     Octstr* msisdn; 
00247     unsigned int origaddlen; 
00248     Octstr* origadd;
00249 
00250 }sm_delete_invoke;
00251 
00252 typedef struct sm_deleteall_invoke{
00253     unsigned int msisdnlen;
00254     Octstr* msisdn; 
00255     unsigned int origaddlen; 
00256     Octstr* origadd;
00257     unsigned int nostatusreport;
00258 
00259 }sm_deleteall_invoke;
00260 
00261 
00262 typedef struct sm_replace_result{
00263     unsigned int delete_result;
00264     unsigned int add_result;
00265     unsigned char smscrefnum[4];
00266     char accepttime[14];
00267 } sm_replace_result;
00268 
00269 typedef struct sm_replace_invoke{
00270     unsigned int smtype; 
00271     unsigned char smscrefnum[4];
00272     unsigned char smerefnum[4];
00273     unsigned int msisdnlen;
00274     Octstr* msisdn;
00275     unsigned int new_smereftype;
00276     unsigned char new_smerefnum[4];
00277     unsigned int new_priority;
00278     unsigned int new_origaddlen;
00279     Octstr* new_origadd;
00280     unsigned int new_validperiodtype;
00281     unsigned char new_validperiodabs[14];
00282     unsigned int new_validperiodrela;
00283     unsigned int new_DCS;
00284     unsigned int new_statusreportrequest;
00285     unsigned int new_protocal;
00286     unsigned int new_replypath;
00287     unsigned int new_textsizechar;
00288     unsigned int new_textsizebyte;
00289     Octstr* new_shortmsg;
00290 
00291 }sm_replace_invoke;
00292 
00293 
00294 typedef struct 2K_ENQUIRE_INVOKE{
00295     int smtype;
00296     int smscrefnum;
00297     int smerefnum;
00298     int msisdnlen;
00299     Octstrr* msisdn;
00300     int origaddlen;
00301     Octstr* origadd;
00302     int enquiretype;
00303 
00304 }sm_enqire_invoke;
00305 
00306 
00307 typedef struct 2K_ENQUIRE_RESULT{
00308     int result;
00309     int enquiretype;
00310     int status;
00311     char[15] completetime;
00312     int failreason;
00313     int priority;
00314     int origaddlen;
00315     char* origadd;
00316     char[15] accepttime;
00317     char[15] exipretime;
00318     int DCS;
00319     int statusreportrequest;
00320     int protocalid;
00321     int replypath;
00322     int textsizechar;
00323     int textsizebyte;
00324     char* shortmsg;
00325 
00326 }sm_enqire_result;
00327 
00328 other msg type ...******************************
00329 */
00330 
00331 
00332 /* function definition */
00333 static int sema_submit_result(SMSCenter*, sema_msg*, int);
00334 
00335 static int X28_open_data_link(char*);
00336 
00337 static int X28_reopen_data_link(int,char*);
00338 
00339 static int X28_close_send_link(int);
00340 
00341 static int X28_open_send_link(int,char*);
00342 
00343 static int X28_data_read(int, char*);
00344 
00345 static int X28_data_send(int, char*, int);
00346 
00347 static int X28_msg_pop(char *, char *);
00348 
00349 static int sema_msg_session_mt(SMSCenter*, sema_msg*);
00350 
00351 static int sema_msg_session_mo(SMSCenter*, char*);
00352 
00353 static sema_msg* sema_msg_new(void);
00354 
00355 static int sema_msg_free(sema_msg *msg);
00356 
00357 static sema_msglist* sema_msglist_new(void);
00358 
00359 static void sema_msglist_free(sema_msglist*);
00360 
00361 static int sema_msglist_push(sema_msglist*, sema_msg*);
00362 
00363 static int sema_msglist_pop(sema_msglist*, sema_msg**);
00364 
00365 /* static int sema_msgbuffer_pop(Octstr *, Octstr **); */
00366 
00367 static int sema_decode_msg(sema_msg**, char*);
00368 
00369 static int sema_encode_msg(sema_msg*, char*);
00370 
00371 static int line_append_hex_IA5(Octstr* , unsigned char*, int);
00372 
00373 static int line_scan_IA5_hex(char*, int, unsigned char*);
00374 
00375 static int line_scan_hex_GSM7(unsigned char*,int,int,unsigned char*);
00376 
00377 static int internal_char_IA5_to_hex(char *, unsigned char *);
00378 
00379 static int internal_char_hex_to_IA5(unsigned char, unsigned char *);
00380 
00381 static unsigned char internal_char_hex_to_gsm(unsigned char from);
00382 
00383 static int unpack_continous_byte(unsigned char, int *, int * , int *);
00384 
00385 static unsigned char pack_continous_byte(int, int, int);
00386 
00387 static void increment_counter(void);
00388 
00389 #endif
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.