Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
smpp_pdu.h File Reference
#include "gwlib/gwlib.h"
#include "gwlib/dict.h"
#include "smpp_pdu.def"

Go to the source code of this file.

Data Structures

struct  SMPP_PDU
 

Macros

#define OPTIONAL_BEGIN
 
#define TLV_INTEGER(name, max_len)
 
#define TLV_NULTERMINATED(name, max_len)
 
#define TLV_OCTETS(name, min_len, max_len)
 
#define OPTIONAL_END
 
#define INTEGER(name, octets)
 
#define NULTERMINATED(name, max_octets)
 
#define OCTETS(name, field_giving_octets)
 
#define PDU(name, id, fields)   name = id,
 
#define OPTIONAL_BEGIN
 
#define TLV_INTEGER(name, octets)   long name;
 
#define TLV_NULTERMINATED(name, max_len)   Octstr *name;
 
#define TLV_OCTETS(name, min_len, max_len)   Octstr *name;
 
#define OPTIONAL_END   Dict *tlv;
 
#define INTEGER(name, octets)   unsigned long name;
 
#define NULTERMINATED(name, max_octets)   Octstr *name;
 
#define OCTETS(name, field_giving_octets)   Octstr *name;
 
#define PDU(name, id, fields)   struct name { fields } name;
 
#define GSM_ADDR_TON_UNKNOWN   0x00000000
 
#define GSM_ADDR_TON_INTERNATIONAL   0x00000001
 
#define GSM_ADDR_TON_NATIONAL   0x00000002
 
#define GSM_ADDR_TON_NETWORKSPECIFIC   0x00000003
 
#define GSM_ADDR_TON_SUBSCRIBER   0x00000004
 
#define GSM_ADDR_TON_ALPHANUMERIC   0x00000005 /* GSM TS 03.38 */
 
#define GSM_ADDR_TON_ABBREVIATED   0x00000006
 
#define GSM_ADDR_TON_EXTENSION   0x00000007 /* Reserved */
 
#define GSM_ADDR_NPI_UNKNOWN   0x00000000
 
#define GSM_ADDR_NPI_E164   0x00000001
 
#define GSM_ADDR_NPI_X121   0x00000003
 
#define GSM_ADDR_NPI_TELEX   0x00000004
 
#define GSM_ADDR_NPI_NATIONAL   0x00000008
 
#define GSM_ADDR_NPI_PRIVATE   0x00000009
 
#define GSM_ADDR_NPI_ERMES   0x0000000A /* ETSI DE/PS 3 01-3 */
 
#define GSM_ADDR_NPI_INTERNET   0x0000000E /* SMPP v5.0, sec. 4.7.2, page 113 */
 
#define GSM_ADDR_NPI_EXTENSION   0x0000000F /* Reserved */
 
#define GSM_ADDR_NPI_WAP_CLIENT_ID   0x00000012 /* SMPP v5.0, sec. 4.7.2, page 113 */
 
#define ESM_CLASS_SUBMIT_DEFAULT_SMSC_MODE   0x00000000
 
#define ESM_CLASS_SUBMIT_DATAGRAM_MODE   0x00000001
 
#define ESM_CLASS_SUBMIT_FORWARD_MODE   0x00000002
 
#define ESM_CLASS_SUBMIT_STORE_AND_FORWARD_MODE   0x00000003
 
#define ESM_CLASS_SUBMIT_DELIVERY_ACK   0x00000008
 
#define ESM_CLASS_SUBMIT_USER_ACK   0x00000010
 
#define ESM_CLASS_SUBMIT_UDH_INDICATOR   0x00000040
 
#define ESM_CLASS_SUBMIT_RPI   0x00000080
 
#define ESM_CLASS_SUBMIT_UDH_AND_RPI   0x000000C0
 
#define ESM_CLASS_DELIVER_DEFAULT_TYPE   0x00000000
 
#define ESM_CLASS_DELIVER_SMSC_DELIVER_ACK   0x00000004
 
#define ESM_CLASS_DELIVER_SME_DELIVER_ACK   0x00000008
 
#define ESM_CLASS_DELIVER_SME_MANULAL_ACK   0x00000010
 
#define ESM_CLASS_DELIVER_INTERM_DEL_NOTIFICATION   0x00000020
 
#define ESM_CLASS_DELIVER_UDH_INDICATOR   0x00000040
 
#define ESM_CLASS_DELIVER_RPI   0x00000080
 
#define ESM_CLASS_DELIVER_UDH_AND_RPI   0x000000C0
 

Typedefs

typedef struct SMPP_PDU SMPP_PDU
 

Enumerations

enum  { PDU, PDU }
 
enum  SMPP_ERROR_MESSAGES {
  SMPP_ESME_ROK = 0x00000000, SMPP_ESME_RINVMSGLEN = 0x00000001, SMPP_ESME_RINVCMDLEN = 0x00000002, SMPP_ESME_RINVCMDID = 0x00000003,
  SMPP_ESME_RINVBNDSTS = 0x00000004, SMPP_ESME_RALYBND = 0x00000005, SMPP_ESME_RINVPRTFLG = 0x00000006, SMPP_ESME_RINVREGDLVFLG = 0x00000007,
  SMPP_ESME_RSYSERR = 0x00000008, SMPP_ESME_RINVSRCADR = 0x0000000A, SMPP_ESME_RINVDSTADR = 0x0000000B, SMPP_ESME_RINVMSGID = 0x0000000C,
  SMPP_ESME_RBINDFAIL = 0x0000000D, SMPP_ESME_RINVPASWD = 0x0000000E, SMPP_ESME_RINVSYSID = 0x0000000F, SMPP_ESME_RCANCELFAIL = 0x00000011,
  SMPP_ESME_RREPLACEFAIL = 0x00000013, SMPP_ESME_RMSGQFUL = 0x00000014, SMPP_ESME_RINVSERTYP = 0x00000015, SMPP_ESME_RINVNUMDESTS = 0x00000033,
  SMPP_ESME_RINVDLNAME = 0x00000034, SMPP_ESME_RINVDESTFLAG = 0x00000040, SMPP_ESME_RINVSUBREP = 0x00000042, SMPP_ESME_RINVESMCLASS = 0x00000043,
  SMPP_ESME_RCNTSUBDL = 0x00000044, SMPP_ESME_RSUBMITFAIL = 0x00000045, SMPP_ESME_RINVSRCTON = 0x00000048, SMPP_ESME_RINVSRCNPI = 0x00000049,
  SMPP_ESME_RINVDSTTON = 0x00000050, SMPP_ESME_RINVDSTNPI = 0x00000051, SMPP_ESME_RINVSYSTYP = 0x00000053, SMPP_ESME_RINVREPFLAG = 0x00000054,
  SMPP_ESME_RINVNUMMSGS = 0x00000055, SMPP_ESME_RTHROTTLED = 0x00000058, SMPP_ESME_RINVSCHED = 0x00000061, SMPP_ESME_RINVEXPIRY = 0x00000062,
  SMPP_ESME_RINVDFTMSGID = 0x00000063, SMPP_ESME_RX_T_APPN = 0x00000064, SMPP_ESME_RX_P_APPN = 0x00000065, SMPP_ESME_RX_R_APPN = 0x00000066,
  SMPP_ESME_RQUERYFAIL = 0x00000067, SMPP_ESME_RINVTLVSTREAM = 0x000000C0, SMPP_ESME_RTLVNOTALLWD = 0x000000C1, SMPP_ESME_RINVTLVLEN = 0x000000C2,
  SMPP_ESME_RMISSINGTLV = 0x000000C3, SMPP_ESME_RINVTLVVAL = 0x000000C4, SMPP_ESME_RDELIVERYFAILURE = 0x000000FE, SMPP_ESME_RUNKNOWNERR = 0x000000FF,
  SMPP_ESME_RSERTYPUNAUTH = 0x00000100, SMPP_ESME_RPROHIBITED = 0x00000101, SMPP_ESME_RSERTYPUNAVAIL = 0x00000102, SMPP_ESME_RSERTYPDENIED = 0x00000103,
  SMPP_ESME_RINVDCS = 0x00000104, SMPP_ESME_RINVSRCADDRSUBUNIT = 0x00000105, SMPP_ESME_RINVDSTADDRSUBUNIT = 0x00000106, SMPP_ESME_RINVBCASTFREQINT = 0x00000107,
  SMPP_ESME_RINVBCASTALIAS_NAME = 0x00000108, SMPP_ESME_RINVBCASTAREAFMT = 0x00000109, SMPP_ESME_RINVNUMBCAST_AREAS = 0x0000010A, SMPP_ESME_RINVBCASTCNTTYPE = 0x0000010B,
  SMPP_ESME_RINVBCASTMSGCLASS = 0x0000010C, SMPP_ESME_RBCASTFAIL = 0x0000010D, SMPP_ESME_RBCASTQUERYFAIL = 0x0000010E, SMPP_ESME_RBCASTCANCELFAIL = 0x0000010F,
  SMPP_ESME_RINVBCAST_REP = 0x00000110, SMPP_ESME_RINVBCASTSRVGRP = 0x00000111, SMPP_ESME_RINVBCASTCHANIND = 0x00000112
}
 

Functions

int smpp_pdu_init (Cfg *cfg)
 
int smpp_pdu_shutdown (void)
 
SMPP_PDUsmpp_pdu_create (unsigned long type, unsigned long seq_no)
 
void smpp_pdu_destroy (SMPP_PDU *pdu)
 
int smpp_pdu_is_valid (SMPP_PDU *pdu)
 
Octstrsmpp_pdu_pack (Octstr *smsc_id, SMPP_PDU *pdu)
 
SMPP_PDUsmpp_pdu_unpack (Octstr *smsc_id, Octstr *data_without_len)
 
void smpp_pdu_dump (Octstr *smsc_id, SMPP_PDU *pdu)
 
void smpp_pdu_dump_line (Octstr *smsc_id, SMPP_PDU *pdu)
 
long smpp_pdu_read_len (Connection *conn)
 
Octstrsmpp_pdu_read_data (Connection *conn, long len)
 
const char * smpp_error_to_string (enum SMPP_ERROR_MESSAGES error)
 

Macro Definition Documentation

#define ESM_CLASS_DELIVER_DEFAULT_TYPE   0x00000000

Definition at line 146 of file smpp_pdu.h.

#define ESM_CLASS_DELIVER_INTERM_DEL_NOTIFICATION   0x00000020

Definition at line 150 of file smpp_pdu.h.

#define ESM_CLASS_DELIVER_RPI   0x00000080

Definition at line 152 of file smpp_pdu.h.

#define ESM_CLASS_DELIVER_SME_DELIVER_ACK   0x00000008

Definition at line 148 of file smpp_pdu.h.

#define ESM_CLASS_DELIVER_SME_MANULAL_ACK   0x00000010

Definition at line 149 of file smpp_pdu.h.

#define ESM_CLASS_DELIVER_SMSC_DELIVER_ACK   0x00000004

Definition at line 147 of file smpp_pdu.h.

#define ESM_CLASS_DELIVER_UDH_AND_RPI   0x000000C0

Definition at line 153 of file smpp_pdu.h.

#define ESM_CLASS_DELIVER_UDH_INDICATOR   0x00000040

Definition at line 151 of file smpp_pdu.h.

#define ESM_CLASS_SUBMIT_DATAGRAM_MODE   0x00000001

Definition at line 137 of file smpp_pdu.h.

#define ESM_CLASS_SUBMIT_DEFAULT_SMSC_MODE   0x00000000

Definition at line 136 of file smpp_pdu.h.

Referenced by smsc_smpp_create().

#define ESM_CLASS_SUBMIT_DELIVERY_ACK   0x00000008

Definition at line 140 of file smpp_pdu.h.

#define ESM_CLASS_SUBMIT_FORWARD_MODE   0x00000002

Definition at line 138 of file smpp_pdu.h.

#define ESM_CLASS_SUBMIT_RPI   0x00000080

Definition at line 143 of file smpp_pdu.h.

Referenced by data_sm_to_msg(), msg_to_pdu(), and pdu_to_msg().

#define ESM_CLASS_SUBMIT_STORE_AND_FORWARD_MODE   0x00000003

Definition at line 139 of file smpp_pdu.h.

Referenced by smsc_smpp_create().

#define ESM_CLASS_SUBMIT_UDH_AND_RPI   0x000000C0

Definition at line 144 of file smpp_pdu.h.

#define ESM_CLASS_SUBMIT_UDH_INDICATOR   0x00000040

Definition at line 142 of file smpp_pdu.h.

Referenced by data_sm_to_msg(), handle_mo_dcs(), msg_to_pdu(), and pdu_to_msg().

#define ESM_CLASS_SUBMIT_USER_ACK   0x00000010

Definition at line 141 of file smpp_pdu.h.

#define GSM_ADDR_NPI_E164   0x00000001

Definition at line 123 of file smpp_pdu.h.

#define GSM_ADDR_NPI_ERMES   0x0000000A /* ETSI DE/PS 3 01-3 */

Definition at line 128 of file smpp_pdu.h.

#define GSM_ADDR_NPI_EXTENSION   0x0000000F /* Reserved */

Definition at line 130 of file smpp_pdu.h.

#define GSM_ADDR_NPI_INTERNET   0x0000000E /* SMPP v5.0, sec. 4.7.2, page 113 */

Definition at line 129 of file smpp_pdu.h.

#define GSM_ADDR_NPI_NATIONAL   0x00000008

Definition at line 126 of file smpp_pdu.h.

#define GSM_ADDR_NPI_PRIVATE   0x00000009

Definition at line 127 of file smpp_pdu.h.

#define GSM_ADDR_NPI_TELEX   0x00000004

Definition at line 125 of file smpp_pdu.h.

#define GSM_ADDR_NPI_UNKNOWN   0x00000000

Definition at line 122 of file smpp_pdu.h.

#define GSM_ADDR_NPI_WAP_CLIENT_ID   0x00000012 /* SMPP v5.0, sec. 4.7.2, page 113 */

Definition at line 131 of file smpp_pdu.h.

#define GSM_ADDR_NPI_X121   0x00000003

Definition at line 124 of file smpp_pdu.h.

#define GSM_ADDR_TON_ABBREVIATED   0x00000006

Definition at line 119 of file smpp_pdu.h.

#define GSM_ADDR_TON_ALPHANUMERIC   0x00000005 /* GSM TS 03.38 */

Definition at line 118 of file smpp_pdu.h.

#define GSM_ADDR_TON_EXTENSION   0x00000007 /* Reserved */

Definition at line 120 of file smpp_pdu.h.

#define GSM_ADDR_TON_INTERNATIONAL   0x00000001

Definition at line 114 of file smpp_pdu.h.

#define GSM_ADDR_TON_NATIONAL   0x00000002

Definition at line 115 of file smpp_pdu.h.

#define GSM_ADDR_TON_NETWORKSPECIFIC   0x00000003

Definition at line 116 of file smpp_pdu.h.

#define GSM_ADDR_TON_SUBSCRIBER   0x00000004

Definition at line 117 of file smpp_pdu.h.

#define GSM_ADDR_TON_UNKNOWN   0x00000000

Definition at line 113 of file smpp_pdu.h.

#define INTEGER (   name,
  octets 
)

Definition at line 99 of file smpp_pdu.h.

#define INTEGER (   name,
  octets 
)    unsigned long name;

Definition at line 99 of file smpp_pdu.h.

#define NULTERMINATED (   name,
  max_octets 
)

Definition at line 100 of file smpp_pdu.h.

#define NULTERMINATED (   name,
  max_octets 
)    Octstr *name;

Definition at line 100 of file smpp_pdu.h.

#define OCTETS (   name,
  field_giving_octets 
)

Definition at line 101 of file smpp_pdu.h.

#define OCTETS (   name,
  field_giving_octets 
)    Octstr *name;

Definition at line 101 of file smpp_pdu.h.

#define OPTIONAL_BEGIN

Definition at line 94 of file smpp_pdu.h.

#define OPTIONAL_BEGIN

Definition at line 94 of file smpp_pdu.h.

#define OPTIONAL_END

Definition at line 98 of file smpp_pdu.h.

#define OPTIONAL_END   Dict *tlv;

Definition at line 98 of file smpp_pdu.h.

#define PDU (   name,
  id,
  fields 
)    name = id,

Definition at line 102 of file smpp_pdu.h.

#define PDU (   name,
  id,
  fields 
)    struct name { fields } name;

Definition at line 102 of file smpp_pdu.h.

#define TLV_INTEGER (   name,
  max_len 
)

Definition at line 95 of file smpp_pdu.h.

#define TLV_INTEGER (   name,
  octets 
)    long name;

Definition at line 95 of file smpp_pdu.h.

#define TLV_NULTERMINATED (   name,
  max_len 
)

Definition at line 96 of file smpp_pdu.h.

#define TLV_NULTERMINATED (   name,
  max_len 
)    Octstr *name;

Definition at line 96 of file smpp_pdu.h.

#define TLV_OCTETS (   name,
  min_len,
  max_len 
)

Definition at line 97 of file smpp_pdu.h.

#define TLV_OCTETS (   name,
  min_len,
  max_len 
)    Octstr *name;

Definition at line 97 of file smpp_pdu.h.

Typedef Documentation

typedef struct SMPP_PDU SMPP_PDU

Definition at line 89 of file smpp_pdu.h.

Enumeration Type Documentation

anonymous enum
Enumerator
PDU 
PDU 

Definition at line 74 of file smpp_pdu.h.

74  {
75  #define OPTIONAL_BEGIN
76  #define TLV_INTEGER(name, max_len)
77  #define TLV_NULTERMINATED(name, max_len)
78  #define TLV_OCTETS(name, min_len, max_len)
79  #define OPTIONAL_END
80  #define INTEGER(name, octets)
81  #define NULTERMINATED(name, max_octets)
82  #define OCTETS(name, field_giving_octets)
83  #define PDU(name, id, fields) name = id,
84  #include "smpp_pdu.def"
85  SMPP_PDU_DUMMY_TYPE
86 };
Enumerator
SMPP_ESME_ROK 
SMPP_ESME_RINVMSGLEN 
SMPP_ESME_RINVCMDLEN 
SMPP_ESME_RINVCMDID 
SMPP_ESME_RINVBNDSTS 
SMPP_ESME_RALYBND 
SMPP_ESME_RINVPRTFLG 
SMPP_ESME_RINVREGDLVFLG 
SMPP_ESME_RSYSERR 
SMPP_ESME_RINVSRCADR 
SMPP_ESME_RINVDSTADR 
SMPP_ESME_RINVMSGID 
SMPP_ESME_RBINDFAIL 
SMPP_ESME_RINVPASWD 
SMPP_ESME_RINVSYSID 
SMPP_ESME_RCANCELFAIL 
SMPP_ESME_RREPLACEFAIL 
SMPP_ESME_RMSGQFUL 
SMPP_ESME_RINVSERTYP 
SMPP_ESME_RINVNUMDESTS 
SMPP_ESME_RINVDLNAME 
SMPP_ESME_RINVDESTFLAG 
SMPP_ESME_RINVSUBREP 
SMPP_ESME_RINVESMCLASS 
SMPP_ESME_RCNTSUBDL 
SMPP_ESME_RSUBMITFAIL 
SMPP_ESME_RINVSRCTON 
SMPP_ESME_RINVSRCNPI 
SMPP_ESME_RINVDSTTON 
SMPP_ESME_RINVDSTNPI 
SMPP_ESME_RINVSYSTYP 
SMPP_ESME_RINVREPFLAG 
SMPP_ESME_RINVNUMMSGS 
SMPP_ESME_RTHROTTLED 
SMPP_ESME_RINVSCHED 
SMPP_ESME_RINVEXPIRY 
SMPP_ESME_RINVDFTMSGID 
SMPP_ESME_RX_T_APPN 
SMPP_ESME_RX_P_APPN 
SMPP_ESME_RX_R_APPN 
SMPP_ESME_RQUERYFAIL 
SMPP_ESME_RINVTLVSTREAM 
SMPP_ESME_RTLVNOTALLWD 
SMPP_ESME_RINVTLVLEN 
SMPP_ESME_RMISSINGTLV 
SMPP_ESME_RINVTLVVAL 
SMPP_ESME_RDELIVERYFAILURE 
SMPP_ESME_RUNKNOWNERR 
SMPP_ESME_RSERTYPUNAUTH 
SMPP_ESME_RPROHIBITED 
SMPP_ESME_RSERTYPUNAVAIL 
SMPP_ESME_RSERTYPDENIED 
SMPP_ESME_RINVDCS 
SMPP_ESME_RINVSRCADDRSUBUNIT 
SMPP_ESME_RINVDSTADDRSUBUNIT 
SMPP_ESME_RINVBCASTFREQINT 
SMPP_ESME_RINVBCASTALIAS_NAME 
SMPP_ESME_RINVBCASTAREAFMT 
SMPP_ESME_RINVNUMBCAST_AREAS 
SMPP_ESME_RINVBCASTCNTTYPE 
SMPP_ESME_RINVBCASTMSGCLASS 
SMPP_ESME_RBCASTFAIL 
SMPP_ESME_RBCASTQUERYFAIL 
SMPP_ESME_RBCASTCANCELFAIL 
SMPP_ESME_RINVBCAST_REP 
SMPP_ESME_RINVBCASTSRVGRP 
SMPP_ESME_RINVBCASTCHANIND 

Definition at line 159 of file smpp_pdu.h.

159  {
160  SMPP_ESME_ROK = 0x00000000,
161  SMPP_ESME_RINVMSGLEN = 0x00000001,
162  SMPP_ESME_RINVCMDLEN = 0x00000002,
163  SMPP_ESME_RINVCMDID = 0x00000003,
164  SMPP_ESME_RINVBNDSTS = 0x00000004,
165  SMPP_ESME_RALYBND = 0x00000005,
166  SMPP_ESME_RINVPRTFLG = 0x00000006,
167  SMPP_ESME_RINVREGDLVFLG = 0x00000007,
168  SMPP_ESME_RSYSERR = 0x00000008,
169  SMPP_ESME_RINVSRCADR = 0x0000000A,
170  SMPP_ESME_RINVDSTADR = 0x0000000B,
171  SMPP_ESME_RINVMSGID = 0x0000000C,
172  SMPP_ESME_RBINDFAIL = 0x0000000D,
173  SMPP_ESME_RINVPASWD = 0x0000000E,
174  SMPP_ESME_RINVSYSID = 0x0000000F,
175  SMPP_ESME_RCANCELFAIL = 0x00000011,
176  SMPP_ESME_RREPLACEFAIL = 0x00000013,
177  SMPP_ESME_RMSGQFUL = 0x00000014,
178  SMPP_ESME_RINVSERTYP = 0x00000015,
179  SMPP_ESME_RINVNUMDESTS = 0x00000033,
180  SMPP_ESME_RINVDLNAME = 0x00000034,
181  SMPP_ESME_RINVDESTFLAG = 0x00000040,
182  SMPP_ESME_RINVSUBREP = 0x00000042,
183  SMPP_ESME_RINVESMCLASS = 0x00000043,
184  SMPP_ESME_RCNTSUBDL = 0x00000044,
185  SMPP_ESME_RSUBMITFAIL = 0x00000045,
186  SMPP_ESME_RINVSRCTON = 0x00000048,
187  SMPP_ESME_RINVSRCNPI = 0x00000049,
188  SMPP_ESME_RINVDSTTON = 0x00000050,
189  SMPP_ESME_RINVDSTNPI = 0x00000051,
190  SMPP_ESME_RINVSYSTYP = 0x00000053,
191  SMPP_ESME_RINVREPFLAG = 0x00000054,
192  SMPP_ESME_RINVNUMMSGS = 0x00000055,
193  SMPP_ESME_RTHROTTLED = 0x00000058,
194  SMPP_ESME_RINVSCHED = 0x00000061,
195  SMPP_ESME_RINVEXPIRY = 0x00000062,
196  SMPP_ESME_RINVDFTMSGID = 0x00000063,
197  SMPP_ESME_RX_T_APPN = 0x00000064,
198  SMPP_ESME_RX_P_APPN = 0x00000065,
199  SMPP_ESME_RX_R_APPN = 0x00000066,
200  SMPP_ESME_RQUERYFAIL = 0x00000067,
201  SMPP_ESME_RINVTLVSTREAM = 0x000000C0,
202  SMPP_ESME_RTLVNOTALLWD = 0x000000C1,
203  SMPP_ESME_RINVTLVLEN = 0x000000C2,
204  SMPP_ESME_RMISSINGTLV = 0x000000C3,
205  SMPP_ESME_RINVTLVVAL = 0x000000C4,
206  SMPP_ESME_RDELIVERYFAILURE = 0x000000FE,
207  SMPP_ESME_RUNKNOWNERR = 0x000000FF,
208  SMPP_ESME_RSERTYPUNAUTH = 0x00000100,
209  SMPP_ESME_RPROHIBITED = 0x00000101,
210  SMPP_ESME_RSERTYPUNAVAIL = 0x00000102,
211  SMPP_ESME_RSERTYPDENIED = 0x00000103,
212  SMPP_ESME_RINVDCS = 0x00000104,
213  SMPP_ESME_RINVSRCADDRSUBUNIT = 0x00000105,
214  SMPP_ESME_RINVDSTADDRSUBUNIT = 0x00000106,
215  SMPP_ESME_RINVBCASTFREQINT = 0x00000107,
216  SMPP_ESME_RINVBCASTALIAS_NAME = 0x00000108,
217  SMPP_ESME_RINVBCASTAREAFMT = 0x00000109,
218  SMPP_ESME_RINVNUMBCAST_AREAS = 0x0000010A,
219  SMPP_ESME_RINVBCASTCNTTYPE = 0x0000010B,
220  SMPP_ESME_RINVBCASTMSGCLASS = 0x0000010C,
221  SMPP_ESME_RBCASTFAIL = 0x0000010D,
222  SMPP_ESME_RBCASTQUERYFAIL = 0x0000010E,
223  SMPP_ESME_RBCASTCANCELFAIL = 0x0000010F,
224  SMPP_ESME_RINVBCAST_REP = 0x00000110,
225  SMPP_ESME_RINVBCASTSRVGRP = 0x00000111,
226  SMPP_ESME_RINVBCASTCHANIND = 0x00000112,
227 };

Function Documentation

const char* smpp_error_to_string ( enum SMPP_ERROR_MESSAGES  error)

Definition at line 858 of file smpp_pdu.c.

References SMPP_ESME_RALYBND, SMPP_ESME_RBCASTCANCELFAIL, SMPP_ESME_RBCASTFAIL, SMPP_ESME_RBCASTQUERYFAIL, SMPP_ESME_RBINDFAIL, SMPP_ESME_RCANCELFAIL, SMPP_ESME_RCNTSUBDL, SMPP_ESME_RDELIVERYFAILURE, SMPP_ESME_RINVBCAST_REP, SMPP_ESME_RINVBCASTALIAS_NAME, SMPP_ESME_RINVBCASTAREAFMT, SMPP_ESME_RINVBCASTCHANIND, SMPP_ESME_RINVBCASTCNTTYPE, SMPP_ESME_RINVBCASTFREQINT, SMPP_ESME_RINVBCASTMSGCLASS, SMPP_ESME_RINVBCASTSRVGRP, SMPP_ESME_RINVBNDSTS, SMPP_ESME_RINVCMDID, SMPP_ESME_RINVCMDLEN, SMPP_ESME_RINVDCS, SMPP_ESME_RINVDESTFLAG, SMPP_ESME_RINVDFTMSGID, SMPP_ESME_RINVDLNAME, SMPP_ESME_RINVDSTADDRSUBUNIT, SMPP_ESME_RINVDSTADR, SMPP_ESME_RINVDSTNPI, SMPP_ESME_RINVDSTTON, SMPP_ESME_RINVESMCLASS, SMPP_ESME_RINVEXPIRY, SMPP_ESME_RINVMSGLEN, SMPP_ESME_RINVNUMBCAST_AREAS, SMPP_ESME_RINVNUMDESTS, SMPP_ESME_RINVNUMMSGS, SMPP_ESME_RINVPASWD, SMPP_ESME_RINVPRTFLG, SMPP_ESME_RINVREGDLVFLG, SMPP_ESME_RINVREPFLAG, SMPP_ESME_RINVSCHED, SMPP_ESME_RINVSERTYP, SMPP_ESME_RINVSRCADDRSUBUNIT, SMPP_ESME_RINVSRCADR, SMPP_ESME_RINVSRCNPI, SMPP_ESME_RINVSRCTON, SMPP_ESME_RINVSUBREP, SMPP_ESME_RINVSYSID, SMPP_ESME_RINVSYSTYP, SMPP_ESME_RINVTLVLEN, SMPP_ESME_RINVTLVSTREAM, SMPP_ESME_RINVTLVVAL, SMPP_ESME_RMISSINGTLV, SMPP_ESME_RMSGQFUL, SMPP_ESME_ROK, SMPP_ESME_RPROHIBITED, SMPP_ESME_RQUERYFAIL, SMPP_ESME_RREPLACEFAIL, SMPP_ESME_RSERTYPDENIED, SMPP_ESME_RSERTYPUNAUTH, SMPP_ESME_RSERTYPUNAVAIL, SMPP_ESME_RSUBMITFAIL, SMPP_ESME_RSYSERR, SMPP_ESME_RTHROTTLED, SMPP_ESME_RTLVNOTALLWD, SMPP_ESME_RUNKNOWNERR, SMPP_ESME_RX_P_APPN, SMPP_ESME_RX_R_APPN, and SMPP_ESME_RX_T_APPN.

Referenced by handle_pdu().

859 {
860  switch (error) {
861  case SMPP_ESME_ROK:
862  return "OK";
864  return "Message Length is invalid";
866  return "Command Length is invalid";
867  case SMPP_ESME_RINVCMDID:
868  return "Invalid Command ID";
870  return "Incorrect BIND Status for given command";
871  case SMPP_ESME_RALYBND:
872  return "ESME Already in Bound State";
874  return "Invalid Priority Flag";
876  return "Invalid Registered Delivery Flag";
877  case SMPP_ESME_RSYSERR:
878  return "System Error";
880  return "Invalid Source Address";
882  return "Invalid Destination Address";
883  case SMPP_ESME_RBINDFAIL:
884  return "Bind Failed";
885  case SMPP_ESME_RINVPASWD:
886  return "Invalid Password";
887  case SMPP_ESME_RINVSYSID:
888  return "Invalid System ID";
890  return "Cancel SM Failed";
892  return "Replace SM Failed";
893  case SMPP_ESME_RMSGQFUL:
894  return "Message Queue Full";
896  return "Invalid Service Type";
898  return "Invalid number of destinations";
900  return "Invalid Distribution List Name";
902  return "Destination flag is invalid";
904  return "Submit w/replace not supported/allowed";
906  return "Invalid esm_class field data";
907  case SMPP_ESME_RCNTSUBDL:
908  return "Cannot Submit to Distribution List";
910  return "Submit failed";
912  return "Invalid Source address TON";
914  return "Invalid Source address NPI";
916  return "Invalid Destination address TON";
918  return "Invalid Destination address NPI";
920  return "Invalid system_type field";
922  return "Invalid replace_if_present flag";
924  return "Invalid number of messages";
926  return "Throttling error";
927  case SMPP_ESME_RINVSCHED:
928  return "Invalid Scheduled Delivery Time";
930  return "Invalid message validity period";
932  return "Predefined Message ID is Invalid or specific predefined message was not found";
933  case SMPP_ESME_RX_T_APPN:
934  return "ESME Receiver Temporary App Error Code";
935  case SMPP_ESME_RX_P_APPN:
936  return "ESME Receiver Permanent App Error Code";
937  case SMPP_ESME_RX_R_APPN:
938  return "ESME Receiver Reject Message Error Code";
940  return "query_sm request failed";
942  return "Error in optional part of the PDU Body";
944  return "TLV not allowed";
946  return "Invalid Parameter Length";
948  return "Expected TLV missing";
950  return "Invalid TLV value";
952  return "Transaction Delivery Failure";
954  return "Unknown Error";
956  return "ESME Not authorized to use specified service_type";
958  return "ESME Prohibited from using specified operation";
960  return "Specified service_type is unavailable";
962  return "Specified service_type is denied";
963  case SMPP_ESME_RINVDCS:
964  return "Invalid Data Coding Scheme";
966  return "Source Address Sub unit is invalid";
968  return "Destination Address Sub unit is invalid";
970  return "Broadcast Frequency Interval is invalid";
972  return "Broadcast Alias Name is invalid";
974  return "Broadcast Area Format is invalid";
976  return "Number of Broadcast Areas is invalid";
978  return "Broadcast Content Type is invalid";
980  return "Broadcast Message Class is invalid";
982  return "broadcast_sm operation failed";
984  return "broadcast_query_sm operation failed";
986  return "broadcast_cancel_sm operation failed";
988  return "Number of Repeated Broadcasts is invalid";
990  return "Broadcast Service Group is invalid";
992  return "Broadcast Channel Indicator is invalid";
993 
994  default:
995  /* tell the user that we have a vendor-specific beast here */
996  if (error >= 0x0400 && error <= 0x04FF)
997  return "Vendor-specific error, please refer to your SMPP provider";
998  else
999  return "Unknown/Reserved";
1000  }
1001 }
void error(int err, const char *fmt,...)
Definition: log.c:612
SMPP_PDU* smpp_pdu_create ( unsigned long  type,
unsigned long  seq_no 
)

Definition at line 347 of file smpp_pdu.c.

References error(), SMPP_PDU::type, and type.

Referenced by handle_bind_receiver(), handle_bind_transmitter(), handle_enquire_link(), handle_pdu(), handle_submit_sm(), handle_unbind(), msg_to_pdu(), open_receiver(), open_transceiver(), open_transmitter(), send_enquire_link(), send_gnack(), send_smpp_thread(), send_unbind(), smpp_emu_handle_pdu(), smpp_emu_writer(), smpp_pdu_unpack(), and smsc_emu_submit_ack().

348 {
349  SMPP_PDU *pdu;
350 
351  pdu = gw_malloc(sizeof(*pdu));
352  pdu->type = type;
353 
354  switch (type) {
355  #define OPTIONAL_BEGIN
356  #define TLV_INTEGER(name, octets) p->name = -1;
357  #define TLV_NULTERMINATED(name, max_len) p->name = NULL;
358  #define TLV_OCTETS(name, min_len, max_len) p->name = NULL;
359  #define OPTIONAL_END p->tlv = dict_create(1024, octstr_destroy_item);
360  #define INTEGER(name, octets) p->name = 0;
361  #define NULTERMINATED(name, max_octets) p->name = NULL;
362  #define OCTETS(name, field_giving_octetst) p->name = NULL;
363  #define PDU(name, id, fields) \
364  case id: { \
365  struct name *p = &pdu->u.name; \
366  pdu->type_name = #name; \
367  fields \
368  p->command_id = type; \
369  p->sequence_number = seq_no; \
370  } break;
371  #include "smpp_pdu.def"
372  default:
373  error(0, "Unknown SMPP_PDU type, internal error.");
374  gw_free(pdu);
375  return NULL;
376  }
377 
378  return pdu;
379 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int type
Definition: smsc_cimd2.c:215
unsigned long type
Definition: smpp_pdu.h:91
void smpp_pdu_destroy ( SMPP_PDU pdu)

Definition at line 381 of file smpp_pdu.c.

References error(), and SMPP_PDU::type.

Referenced by handle_pdu(), io_thread(), msg_to_pdu(), open_receiver(), open_transceiver(), open_transmitter(), receive_smpp_thread(), send_enquire_link(), send_gnack(), send_messages(), send_smpp_thread(), send_unbind(), smpp_emu_handle_pdu(), smpp_emu_reader(), smpp_emu_writer(), smpp_pdu_unpack(), and smsc_emu_submit_ack().

382 {
383  if (pdu == NULL)
384  return;
385 
386  switch (pdu->type) {
387  #define OPTIONAL_BEGIN
388  #define TLV_INTEGER(name, octets) p->name = -1;
389  #define TLV_NULTERMINATED(name, max_octets) octstr_destroy(p->name);
390  #define TLV_OCTETS(name, min_len, max_len) octstr_destroy(p->name);
391  #define OPTIONAL_END dict_destroy(p->tlv);
392  #define INTEGER(name, octets) p->name = 0; /* Make sure "p" is used */
393  #define NULTERMINATED(name, max_octets) octstr_destroy(p->name);
394  #define OCTETS(name, field_giving_octets) octstr_destroy(p->name);
395  #define PDU(name, id, fields) \
396  case id: { struct name *p = &pdu->u.name; fields } break;
397  #include "smpp_pdu.def"
398  default:
399  error(0, "Unknown SMPP_PDU type, internal error while destroying.");
400  }
401  gw_free(pdu);
402 }
void error(int err, const char *fmt,...)
Definition: log.c:612
unsigned long type
Definition: smpp_pdu.h:91
void smpp_pdu_dump ( Octstr smsc_id,
SMPP_PDU pdu 
)

Definition at line 713 of file smpp_pdu.c.

References debug(), error(), SMPP_PDU::type, and SMPP_PDU::type_name.

Referenced by handle_pdu().

714 {
715  debug("sms.smpp", 0, "SMPP PDU %p dump:", (void *) pdu);
716  debug("sms.smpp", 0, " type_name: %s", pdu->type_name);
717  switch (pdu->type) {
718  #define OPTIONAL_BEGIN
719  #define TLV_INTEGER(name, max_len) \
720  if (p->name != -1) { \
721  INTEGER(name, max_len) \
722  }
723  #define TLV_NULTERMINATED(name, max_len) \
724  if (p->name != NULL) { \
725  NULTERMINATED(name, max_len) \
726  }
727  #define TLV_OCTETS(name, min_len, max_len) \
728  if (p->name != NULL) { \
729  OCTETS(name, max_len) \
730  }
731  #define OPTIONAL_END \
732  if (p->tlv != NULL) { \
733  List *keys; \
734  Octstr *key; \
735  struct smpp_tlv *tlv; \
736  keys = dict_keys(p->tlv); \
737  while(keys != NULL && (key = gwlist_extract_first(keys)) != NULL) { \
738  tlv = smpp_tlv_get_by_name(smsc_id, key); \
739  if (tlv != NULL) { \
740  octstr_dump_short(dict_get(p->tlv, key), 2, octstr_get_cstr(key)); \
741  } \
742  octstr_destroy(key); \
743  } \
744  gwlist_destroy(keys, octstr_destroy_item); \
745  }
746  #define INTEGER(name, octets) \
747  debug("sms.smpp", 0, " %s: %lu = 0x%08lx", #name, p->name, p->name);
748  #define NULTERMINATED(name, max_octets) \
749  octstr_dump_short(p->name, 2, #name);
750  #define OCTETS(name, field_giving_octets) \
751  octstr_dump_short(p->name, 2, #name);
752  #define PDU(name, id, fields) \
753  case id: { struct name *p = &pdu->u.name; fields } break;
754  #include "smpp_pdu.def"
755  default:
756  error(0, "Unknown SMPP_PDU type, internal error.");
757  break;
758  }
759  debug("sms.smpp", 0, "SMPP PDU dump ends.");
760 }
void error(int err, const char *fmt,...)
Definition: log.c:612
const char * type_name
Definition: smpp_pdu.h:92
unsigned long type
Definition: smpp_pdu.h:91
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void smpp_pdu_dump_line ( Octstr smsc_id,
SMPP_PDU pdu 
)

Definition at line 763 of file smpp_pdu.c.

References debug(), error(), octstr_create, octstr_destroy(), octstr_format_append(), octstr_get_cstr, SMPP_PDU::type, and SMPP_PDU::type_name.

764 {
765  Octstr *str = octstr_create("");
766 
767  octstr_format_append(str, "SMPP PDU %p dump: [type_name:%d:%s]", (void *) pdu, strlen(pdu->type_name), pdu->type_name);
768  switch (pdu->type) {
769  #define OPTIONAL_BEGIN
770  #define TLV_INTEGER(name, max_len) \
771  if (p->name != -1) { \
772  INTEGER(name, max_len) \
773  }
774  #define TLV_NULTERMINATED(name, max_len) \
775  if (p->name != NULL) { \
776  NULTERMINATED(name, max_len) \
777  }
778  #define TLV_OCTETS(name, min_len, max_len) \
779  if (p->name != NULL) { \
780  OCTETS(name, max_len) \
781  }
782  #define OPTIONAL_END \
783  if (p->tlv != NULL) { \
784  List *keys; \
785  Octstr *key; \
786  struct smpp_tlv *tlv; \
787  keys = dict_keys(p->tlv); \
788  while(keys != NULL && (key = gwlist_extract_first(keys)) != NULL) { \
789  tlv = smpp_tlv_get_by_name(smsc_id, key); \
790  if (tlv != NULL) { \
791  Octstr *val = dict_get(p->tlv, key); \
792  octstr_format_append(str, " [%E:%d:%E]", key, octstr_len(val), val); \
793  } \
794  octstr_destroy(key); \
795  } \
796  gwlist_destroy(keys, octstr_destroy_item); \
797  }
798  #define INTEGER(name, octets) \
799  octstr_format_append(str, " [%s:0:0x%08lx]", #name, p->name);
800  #define NULTERMINATED(name, max_octets) \
801  octstr_format_append(str, " [%s:%d:%E]", #name, octstr_len(p->name), (p->name != NULL ? p->name : octstr_imm("NULL")));
802  #define OCTETS(name, field_giving_octets) \
803  octstr_format_append(str, " [%s:%d:%E]", #name, octstr_len(p->name), (p->name != NULL ? p->name : octstr_imm("NULL")));
804  #define PDU(name, id, fields) \
805  case id: { struct name *p = &pdu->u.name; fields } break;
806  #include "smpp_pdu.def"
807  default:
808  error(0, "Unknown SMPP_PDU type, internal error.");
809  break;
810  }
811  debug("sms.smpp", 0, "%s", octstr_get_cstr(str));
812  octstr_destroy(str);
813 }
void error(int err, const char *fmt,...)
Definition: log.c:612
const char * type_name
Definition: smpp_pdu.h:92
unsigned long type
Definition: smpp_pdu.h:91
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2505
int smpp_pdu_init ( Cfg cfg)

Definition at line 150 of file smpp_pdu.c.

References cfg_get, cfg_get_integer(), cfg_get_multi_group(), debug(), DEFAULT_SMSC_ID, dict_create(), dict_destroy(), dict_get(), dict_put(), dict_put_once(), error(), gwlist_create, gwlist_destroy(), gwlist_extract_first(), gwlist_produce(), initialized, smpp_tlv::length, smpp_tlv::name, octstr_create, octstr_destroy(), octstr_destroy_item(), octstr_format(), octstr_get_cstr, octstr_imm(), octstr_split(), octstr_str_case_compare(), smpp_tlv_destroy(), smpp_tlv::SMPP_TLV_INTEGER, smpp_tlv::SMPP_TLV_NULTERMINATED, smpp_tlv::SMPP_TLV_OCTETS, smsc_id, smpp_tlv::tag, and smpp_tlv::type.

Referenced by main(), and smsc2_start().

151 {
152  CfgGroup *grp;
153  List *l;
154 
155  if (initialized)
156  return 0;
157 
158  l = cfg_get_multi_group(cfg, octstr_imm("smpp-tlv"));
159  tlvs = gwlist_create();
160  tlvs_by_tag = dict_create(1024, (void(*)(void*))dict_destroy);
161  tlvs_by_name = dict_create(1024, (void(*)(void*))dict_destroy);
162  while (l != NULL && (grp = gwlist_extract_first(l)) != NULL) {
163  struct smpp_tlv *tlv;
164  Octstr *tmp, *smsc_id;
165  List *l2;
166 
167  tlv = gw_malloc(sizeof(*tlv));
168  if ((tlv->name = cfg_get(grp, octstr_imm("name"))) == NULL) {
169  error(0, "SMPP: Unable to get name for smpp-tlv.");
170  smpp_tlv_destroy(tlv);
171  goto failed;
172  }
173  if (cfg_get_integer(&tlv->tag, grp, octstr_imm("tag")) == -1) {
174  error(0, "SMPP: Unable to get tag for smpp-tlv.");
175  smpp_tlv_destroy(tlv);
176  goto failed;
177  }
178  if (cfg_get_integer(&tlv->length, grp, octstr_imm("length")) == -1) {
179  error(0, "SMPP: Unable to get length for smpp-tlv.");
180  smpp_tlv_destroy(tlv);
181  goto failed;
182  }
183  if ((tmp = cfg_get(grp, octstr_imm("type"))) == NULL) {
184  error(0, "SMPP: Unable to get type for smpp-tlv.");
185  smpp_tlv_destroy(tlv);
186  goto failed;
187  }
188  if (octstr_str_case_compare(tmp, "octetstring") == 0)
189  tlv->type = SMPP_TLV_OCTETS;
190  else if (octstr_str_case_compare(tmp, "nulterminated") == 0)
192  else if (octstr_str_case_compare(tmp, "integer") == 0)
193  tlv->type = SMPP_TLV_INTEGER;
194  else {
195  error(0, "SMPP: Unknown type for smpp-tlv: `%s'", octstr_get_cstr(tmp));
196  octstr_destroy(tmp);
197  smpp_tlv_destroy(tlv);
198  goto failed;
199  }
200  octstr_destroy(tmp);
201 
202  /* put to all TLVs */
203  gwlist_produce(tlvs, tlv);
204 
205  smsc_id = cfg_get(grp, octstr_imm("smsc-id"));
206  if (smsc_id != NULL) {
207  l2 = octstr_split(smsc_id, octstr_imm(";"));
208  octstr_destroy(smsc_id);
209  } else {
210  l2 = gwlist_create();
212  }
213  while(l2 != NULL && (smsc_id = gwlist_extract_first(l2)) != NULL) {
214  Dict *tmp_dict;
215 
216  debug("sms.smpp", 0, "adding smpp-tlv for smsc-id=%s", octstr_get_cstr(smsc_id));
217 
218  tmp_dict = dict_get(tlvs_by_name, smsc_id);
219  if (tmp_dict == NULL) {
220  tmp_dict = dict_create(1024, NULL);
221  dict_put(tlvs_by_name, smsc_id, tmp_dict);
222  }
223  /* put into dict */
224  if (!dict_put_once(tmp_dict, tlv->name, tlv)) {
225  error(0, "SMPP: Double TLV name %s found.", octstr_get_cstr(tlv->name));
226  octstr_destroy(smsc_id);
227  goto failed;
228  }
229 
230  tmp_dict = dict_get(tlvs_by_tag, smsc_id);
231  if (tmp_dict == NULL) {
232  tmp_dict = dict_create(1024, NULL);
233  dict_put(tlvs_by_tag, smsc_id, tmp_dict);
234  }
235  tmp = octstr_format("%ld", tlv->tag);
236  if (!dict_put_once(tmp_dict, tmp, tlv)) {
237  error(0, "SMPP: Double TLV tag %s found.", octstr_get_cstr(tmp));
239  octstr_destroy(tmp);
240  octstr_destroy(smsc_id);
241  goto failed;
242  }
243  octstr_destroy(tmp);
244  octstr_destroy(smsc_id);
245  }
247  }
248  gwlist_destroy(l, NULL);
249 
250  initialized = 1;
251  return 0;
252 
253 failed:
254  gwlist_destroy(tlvs, (void(*)(void*))smpp_tlv_destroy);
257  return -1;
258 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
void error(int err, const char *fmt,...)
Definition: log.c:612
int octstr_str_case_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:984
static int initialized
Definition: smpp_pdu.c:87
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
void gwlist_produce(List *list, void *item)
Definition: list.c:411
#define cfg_get(grp, varname)
Definition: cfg.h:86
static Dict * tlvs_by_name
Definition: smpp_pdu.c:85
static void smpp_tlv_destroy(struct smpp_tlv *tlv)
Definition: smpp_pdu.c:90
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static Dict * tlvs_by_tag
Definition: smpp_pdu.c:83
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
void * gwlist_extract_first(List *list)
Definition: list.c:305
enum smpp_tlv::@12 type
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
long tag
Definition: smpp_pdu.c:77
Definition: dict.c:116
static Octstr * smsc_id
Definition: mtbatch.c:98
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:642
#define DEFAULT_SMSC_ID
Definition: smpp_pdu.c:73
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
void dict_destroy(Dict *dict)
Definition: dict.c:215
long length
Definition: smpp_pdu.c:78
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
Definition: cfg.c:73
#define gwlist_create()
Definition: list.h:136
int dict_put_once(Dict *dict, Octstr *key, void *value)
Definition: dict.c:271
Octstr * name
Definition: smpp_pdu.c:76
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1638
Definition: list.c:102
static List * tlvs
Definition: smpp_pdu.c:86
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
int smpp_pdu_is_valid ( SMPP_PDU pdu)
Octstr* smpp_pdu_pack ( Octstr smsc_id,
SMPP_PDU pdu 
)

Definition at line 405 of file smpp_pdu.c.

References append_encoded_integer(), error(), gw_assert(), octstr_create, octstr_destroy(), octstr_insert(), octstr_len(), and SMPP_PDU::type.

Referenced by handle_pdu(), send_enquire_link(), send_gnack(), send_pdu(), send_smpp_thread(), send_unbind(), smpp_emu_handle_pdu(), smpp_emu_writer(), and smsc_emu_submit_ack().

406 {
407  Octstr *os;
408  Octstr *temp;
409 
410  os = octstr_create("");
411 
412  gw_assert(pdu != NULL);
413 
414  /*
415  * Fix lengths of octet string fields.
416  */
417  switch (pdu->type) {
418  #define OPTIONAL_BEGIN
419  #define TLV_INTEGER(name, octets)
420  #define TLV_NULTERMINATED(name, max_len)
421  #define TLV_OCTETS(name, min_len, max_len)
422  #define OPTIONAL_END
423  #define INTEGER(name, octets) p = *(&p);
424  #define NULTERMINATED(name, max_octets) p = *(&p);
425  #define OCTETS(name, field_giving_octets) \
426  p->field_giving_octets = octstr_len(p->name);
427  #define PDU(name, id, fields) \
428  case id: { struct name *p = &pdu->u.name; fields } break;
429  #include "smpp_pdu.def"
430  default:
431  error(0, "Unknown SMPP_PDU type, internal error while packing.");
432  }
433 
434  switch (pdu->type) {
435  #define TL(name, octets) \
436  append_encoded_integer(os, SMPP_##name, 2); \
437  append_encoded_integer(os, octets, 2);
438  #define OPTIONAL_BEGIN
439  #define TLV_INTEGER(name, octets) \
440  if (p->name >= 0) { \
441  TL(name, octets); \
442  INTEGER(name, octets) \
443  }
444  #define TLV_NULTERMINATED(name, max_len) \
445  if (p->name != NULL) { \
446  TL(name, (octstr_len(p->name) > max_len ? max_len : octstr_len(p->name) + 1)); \
447  NULTERMINATED(name, max_len) \
448  }
449  #define TLV_OCTETS(name, min_len, max_len) \
450  if (p->name != NULL) { \
451  unsigned long len = octstr_len(p->name); \
452  if (len > max_len || len < min_len) { \
453  error(0, "SMPP: Optional field (%s) with invalid length (%ld) (should be %d - %d) dropped.", \
454  #name, len, min_len, max_len);\
455  } else { \
456  TL(name, len); \
457  octstr_append(os, p->name); \
458  } \
459  }
460  #define OPTIONAL_END \
461  if (p->tlv != NULL) { \
462  Octstr *key; \
463  List *keys; \
464  struct smpp_tlv *tlv; \
465  keys = dict_keys(p->tlv); \
466  while(keys != NULL && (key = gwlist_extract_first(keys)) != NULL) { \
467  tlv = smpp_tlv_get_by_name(smsc_id, key); \
468  if (tlv == NULL) { \
469  if (!is_defined_field(pdu->type, octstr_get_cstr(key))) \
470  error(0, "SMPP: Unknown TLV `%s', don't send.", octstr_get_cstr(key)); \
471  octstr_destroy(key); \
472  continue; \
473  } \
474  switch(tlv->type) { \
475  case SMPP_TLV_INTEGER: { \
476  long val = atol(octstr_get_cstr(dict_get(p->tlv, key))); \
477  append_encoded_integer(os, tlv->tag, 2); \
478  append_encoded_integer(os, tlv->length, 2); \
479  append_encoded_integer(os, val, tlv->length); \
480  break; \
481  } \
482  case SMPP_TLV_OCTETS: \
483  case SMPP_TLV_NULTERMINATED: { \
484  Octstr *val = dict_get(p->tlv, key); \
485  unsigned long len = octstr_len(val); \
486  if (len > tlv->length) { \
487  error(0, "SMPP: Optional field (%s) with invalid length (%ld) (should be %ld) dropped.", \
488  octstr_get_cstr(key), len, tlv->length);\
489  octstr_destroy(key); \
490  continue; \
491  } \
492  append_encoded_integer(os, tlv->tag, 2); \
493  if (tlv->type == SMPP_TLV_NULTERMINATED) \
494  append_encoded_integer(os, len + 1, 2); \
495  else \
496  append_encoded_integer(os, len, 2); \
497  octstr_append(os, val); \
498  if (tlv->type == SMPP_TLV_NULTERMINATED) \
499  octstr_append_char(os, '\0'); \
500  break; \
501  } \
502  default: \
503  panic(0, "SMPP: Internal error, unknown configured TLV type %d.", tlv->type); \
504  break; \
505  } \
506  octstr_destroy(key); \
507  } \
508  gwlist_destroy(keys, octstr_destroy_item); \
509  }
510  #define INTEGER(name, octets) \
511  append_encoded_integer(os, p->name, octets);
512  #define NULTERMINATED(name, max_octets) \
513  if (p->name != NULL) { \
514  if (octstr_len(p->name) >= max_octets) { \
515  warning(0, "SMPP: PDU element <%s> too long " \
516  "(length is %ld, should be %d)", \
517  #name, octstr_len(p->name), max_octets-1); \
518  temp = octstr_copy(p->name, 0, max_octets-1); \
519  } else \
520  temp = octstr_duplicate(p->name); \
521  octstr_append(os, temp); \
522  octstr_destroy(temp); \
523  } \
524  octstr_append_char(os, '\0');
525  #define OCTETS(name, field_giving_octets) \
526  if (p->name) octstr_append(os, p->name);
527  #define PDU(name, id, fields) \
528  case id: { struct name *p = &pdu->u.name; fields } break;
529  #include "smpp_pdu.def"
530  default:
531  error(0, "Unknown SMPP_PDU type 0x%08lx, internal error while packing.", pdu->type);
532  break;
533  }
534 
535  temp = octstr_create("");
536  append_encoded_integer(temp, octstr_len(os) + 4, 4);
537  octstr_insert(os, temp, 0);
538  octstr_destroy(temp);
539 
540  return os;
541 }
void error(int err, const char *fmt,...)
Definition: log.c:612
unsigned long type
Definition: smpp_pdu.h:91
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1301
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
static void append_encoded_integer(Octstr *os, unsigned long u, long octets)
Definition: smpp_pdu.c:293
Octstr* smpp_pdu_read_data ( Connection conn,
long  len 
)

Definition at line 842 of file smpp_pdu.c.

References conn_read_fixed().

Referenced by read_pdu(), receive_smpp_thread(), and smpp_emu_reader().

843 {
844  Octstr *os;
845 
846  os = conn_read_fixed(conn, len - 4); /* `len' includes itself. */
847  return os;
848 }
Definition: octstr.c:118
Octstr * conn_read_fixed(Connection *conn, long length)
Definition: conn.c:1102
long smpp_pdu_read_len ( Connection conn)

Definition at line 816 of file smpp_pdu.c.

References conn_read_fixed(), decode_network_long(), error(), MAX_SMPP_PDU_LEN, MIN_SMPP_PDU_LEN, octstr_destroy(), and octstr_get_many_chars().

Referenced by read_pdu(), receive_smpp_thread(), and smpp_emu_reader().

817 {
818  Octstr *os;
819  unsigned char buf[4]; /* The length is 4 octets. */
820  long len;
821 
822  os = conn_read_fixed(conn, sizeof(buf));
823  if (os == NULL)
824  return 0;
825  octstr_get_many_chars((char*) buf, os, 0, sizeof(buf));
826  octstr_destroy(os);
827  len = decode_network_long(buf);
828  if (len < MIN_SMPP_PDU_LEN) {
829  error(0, "SMPP: PDU length was too small (%ld, minimum is %ld).",
830  len, (long) MIN_SMPP_PDU_LEN);
831  return -1;
832  }
833  if (len > MAX_SMPP_PDU_LEN) {
834  error(0, "SMPP: PDU length was too large (%ld, maximum is %ld).",
835  len, (long) MAX_SMPP_PDU_LEN);
836  return -1;
837  }
838  return len;
839 }
void error(int err, const char *fmt,...)
Definition: log.c:612
#define MAX_SMPP_PDU_LEN
Definition: smpp_pdu.c:71
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
long decode_network_long(unsigned char *data)
Definition: utils.c:935
Definition: octstr.c:118
Octstr * conn_read_fixed(Connection *conn, long length)
Definition: conn.c:1102
#define MIN_SMPP_PDU_LEN
Definition: smpp_pdu.c:69
void octstr_get_many_chars(char *buf, Octstr *ostr, long pos, long len)
Definition: octstr.c:423
int smpp_pdu_shutdown ( void  )

Definition at line 261 of file smpp_pdu.c.

References dict_destroy(), gwlist_destroy(), initialized, and smpp_tlv_destroy().

Referenced by smsc2_shutdown().

262 {
263  if (initialized == 0)
264  return 0;
265 
266  initialized = 0;
267  gwlist_destroy(tlvs, (void(*)(void*))smpp_tlv_destroy);
268  tlvs = NULL;
271  tlvs_by_tag = tlvs_by_name = NULL;
272 
273  return 0;
274 }
static int initialized
Definition: smpp_pdu.c:87
static Dict * tlvs_by_name
Definition: smpp_pdu.c:85
static void smpp_tlv_destroy(struct smpp_tlv *tlv)
Definition: smpp_pdu.c:90
static Dict * tlvs_by_tag
Definition: smpp_pdu.c:83
void dict_destroy(Dict *dict)
Definition: dict.c:215
static List * tlvs
Definition: smpp_pdu.c:86
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
SMPP_PDU* smpp_pdu_unpack ( Octstr smsc_id,
Octstr data_without_len 
)

Definition at line 544 of file smpp_pdu.c.

References decode_integer(), error(), octstr_dump, octstr_len(), smpp_pdu_create(), smpp_pdu_destroy(), and type.

Referenced by read_pdu(), receive_smpp_thread(), and smpp_emu_reader().

545 {
546  SMPP_PDU *pdu;
547  unsigned long type;
548  long len, pos;
549 
550  len = octstr_len(data_without_len);
551 
552  if (len < 4) {
553  error(0, "SMPP: PDU was too short (%ld bytes).",
554  octstr_len(data_without_len));
555  return NULL;
556  }
557 
558  /* get the PDU type */
559  if ((type = decode_integer(data_without_len, 0, 4)) == -1)
560  return NULL;
561 
562  /* create a coresponding representation structure */
563  pdu = smpp_pdu_create(type, 0);
564  if (pdu == NULL)
565  return NULL;
566 
567  pos = 0;
568 
569  switch (type) {
570  #define OPTIONAL_BEGIN \
571  { /* Read optional parameters */ \
572  while (pos + 4 <= len) { \
573  struct smpp_tlv *tlv; \
574  unsigned long opt_tag, opt_len; \
575  opt_tag = decode_integer(data_without_len, pos, 2); pos += 2; \
576  debug("sms.smpp", 0, "Optional parameter tag (0x%04lx)", opt_tag); \
577  opt_len = decode_integer(data_without_len, pos, 2); pos += 2; \
578  debug("sms.smpp", 0, "Optional parameter length read as %ld", opt_len); \
579  /* check configured TLVs */ \
580  tlv = smpp_tlv_get_by_tag(smsc_id, opt_tag); \
581  if (tlv != NULL) debug("sms.smpp", 0, "Found configured optional parameter `%s'", octstr_get_cstr(tlv->name));
582  #define TLV_INTEGER(mname, octets) \
583  if (SMPP_##mname == opt_tag) { \
584  /* check length */ \
585  if (opt_len > octets) { \
586  error(0, "SMPP: Optional field (%s) with invalid length (%ld) dropped.", #mname, opt_len); \
587  pos += opt_len; \
588  continue; \
589  } \
590  INTEGER(mname, opt_len); \
591  if (tlv != NULL) dict_put(p->tlv, tlv->name, octstr_format("%ld", p->mname)); \
592  } else
593  #define TLV_NULTERMINATED(mname, max_len) \
594  if (SMPP_##mname == opt_tag) { \
595  /* check length */ \
596  if (opt_len > max_len || pos+opt_len > len) { \
597  error(0, "SMPP: Optional field (%s) with invalid length (%ld) dropped.", #mname, opt_len); \
598  pos += opt_len; \
599  continue; \
600  } \
601  if(p->mname != NULL) { \
602  warning(0, "SMPP: Optional field (%s) was sent more than once, overwriting", #mname); \
603  octstr_destroy(p->mname); \
604  p->mname = NULL; \
605  } \
606  copy_until_nul(#mname, data_without_len, &pos, opt_len, &p->mname); \
607  if (tlv != NULL) dict_put(p->tlv, tlv->name, octstr_duplicate(p->mname)); \
608  } else
609  #define TLV_OCTETS(mname, min_len, max_len) \
610  if (SMPP_##mname == opt_tag) { \
611  /* check length */ \
612  if (opt_len < min_len || opt_len > max_len || pos + opt_len > len) { \
613  error(0, "SMPP: Optional field (%s) with invalid length (%ld) (should be %d - %d) dropped.", \
614  #mname, opt_len, min_len, max_len); \
615  pos += opt_len; \
616  continue; \
617  } \
618  if(p->mname != NULL) { \
619  warning(0, "SMPP: Optional field (%s) was sent more than once, overwriting", #mname); \
620  octstr_destroy(p->mname); \
621  p->mname = NULL; \
622  } \
623  p->mname = octstr_copy(data_without_len, pos, opt_len); \
624  pos += opt_len; \
625  if (tlv != NULL) dict_put(p->tlv, tlv->name, octstr_duplicate(p->mname)); \
626  } else
627  #define OPTIONAL_END \
628  { \
629  Octstr *val = NULL; \
630  if (tlv != NULL) { \
631  /* found configured tlv */ \
632  /* check length */ \
633  if (opt_len > tlv->length) { \
634  error(0, "SMPP: Optional field (%s) with invalid length (%ld) (should be %ld) dropped.", \
635  octstr_get_cstr(tlv->name), opt_len, tlv->length); \
636  pos += opt_len; \
637  continue; \
638  } \
639  switch (tlv->type) { \
640  case SMPP_TLV_INTEGER: { \
641  long val_i; \
642  if ((val_i = decode_integer(data_without_len, pos, opt_len)) == -1) \
643  goto err; \
644  val = octstr_format("%ld", val_i); \
645  dict_put(p->tlv, tlv->name, val); \
646  pos += opt_len; \
647  break; \
648  } \
649  case SMPP_TLV_OCTETS: { \
650  val = octstr_copy(data_without_len, pos, opt_len); \
651  dict_put(p->tlv, tlv->name, val); \
652  pos += opt_len; \
653  break; \
654  } \
655  case SMPP_TLV_NULTERMINATED: { \
656  if (copy_until_nul(octstr_get_cstr(tlv->name), data_without_len, &pos, opt_len, &val) == 0) \
657  dict_put(p->tlv, tlv->name, val); \
658  break; \
659  } \
660  default: \
661  panic(0, "SMPP: Internal error, unknown configured TLV type %d.", tlv->type); \
662  break; \
663  } \
664  } else { \
665  val = octstr_copy(data_without_len, pos, opt_len); \
666  if (val) \
667  octstr_binary_to_hex(val, 0); \
668  else \
669  val = octstr_create(""); \
670  warning(0, "SMPP: Unknown TLV(0x%04lx,0x%04lx,%s) for PDU type (%s) received!", \
671  opt_tag, opt_len, octstr_get_cstr(val), pdu->type_name); \
672  octstr_destroy(val); \
673  pos += opt_len; \
674  } \
675  } \
676  } \
677  }
678  #define INTEGER(name, octets) \
679  if ((p->name = decode_integer(data_without_len, pos, octets)) == -1) \
680  goto err; \
681  pos += octets;
682  #define NULTERMINATED(name, max_octets) \
683  /* just warn about errors but not fail */ \
684  copy_until_nul(#name, data_without_len, &pos, max_octets, &p->name);
685  #define OCTETS(name, field_giving_octets) \
686  p->name = octstr_copy(data_without_len, pos, \
687  p->field_giving_octets); \
688  if (p->field_giving_octets != (unsigned long) octstr_len(p->name)) { \
689  error(0, "smpp_pdu: error while unpacking '" #name "', " \
690  "len is %ld but should have been %ld, dropping.", \
691  octstr_len(p->name), p->field_giving_octets); \
692  goto err; \
693  } else { \
694  pos += p->field_giving_octets; \
695  }
696  #define PDU(name, id, fields) \
697  case id: { struct name *p = &pdu->u.name; fields } break;
698  #include "smpp_pdu.def"
699  default:
700  error(0, "Unknown SMPP_PDU type 0x%08lx, internal error while unpacking.", type);
701  break;
702  }
703 
704  return pdu;
705 
706 err:
707  smpp_pdu_destroy(pdu);
708  octstr_dump(data_without_len, 0);
709  return NULL;
710 }
void smpp_pdu_destroy(SMPP_PDU *pdu)
Definition: smpp_pdu.c:381
void error(int err, const char *fmt,...)
Definition: log.c:612
int type
Definition: smsc_cimd2.c:215
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
SMPP_PDU * smpp_pdu_create(unsigned long type, unsigned long seq_no)
Definition: smpp_pdu.c:347
static long decode_integer(Octstr *os, long pos, int octets)
Definition: smpp_pdu.c:277
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.