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

Go to the source code of this file.

Data Structures

struct  SMASI_PDU
 

Macros

#define SMASI_HYPHEN_ID   0x00000010
 
#define NONTERMINATED(name)
 
#define COMATERMINATED(name)
 
#define PDU(name, id, fields)   name = id,
 
#define NONTERMINATED(name)   Octstr *name;
 
#define COMATERMINATED(name)   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_EXTENSION   0x0000000F /* Reserved */
 
#define ESM_CLASS_DEFAULT_SMSC_MODE   0x00000000
 
#define ESM_CLASS_DATAGRAM_MODE   0x00000001
 
#define ESM_CLASS_FORWARD_MODE   0x00000002
 
#define ESM_CLASS_STORE_AND_FORWARD_MODE   0x00000003
 
#define ESM_CLASS_DELIVERY_ACK   0x00000008
 
#define ESM_CLASS_USER_ACK   0x00000010
 
#define ESM_CLASS_UDH_INDICATOR   0x00000040
 
#define ESM_CLASS_RPI   0x00000080
 
#define ESM_CLASS_UDH_AND_RPI   0x000000C0
 

Typedefs

typedef struct SMASI_PDU SMASI_PDU
 

Enumerations

enum  { PDU, PDU }
 

Functions

SMASI_PDUsmasi_pdu_create (unsigned long type)
 
void smasi_pdu_destroy (SMASI_PDU *pdu)
 
int smasi_pdu_is_valid (SMASI_PDU *pdu)
 
Octstrsmasi_pdu_pack (SMASI_PDU *pdu)
 
SMASI_PDUsmasi_pdu_unpack (Octstr *data_without_len)
 
void smasi_pdu_dump (SMASI_PDU *pdu)
 
Octstrsmasi_pdu_read (Connection *conn)
 

Macro Definition Documentation

#define COMATERMINATED (   name)

Definition at line 90 of file smasi_pdu.h.

#define COMATERMINATED (   name)    Octstr *name;

Definition at line 90 of file smasi_pdu.h.

#define ESM_CLASS_DATAGRAM_MODE   0x00000001

Definition at line 124 of file smasi_pdu.h.

#define ESM_CLASS_DEFAULT_SMSC_MODE   0x00000000

Definition at line 123 of file smasi_pdu.h.

#define ESM_CLASS_DELIVERY_ACK   0x00000008

Definition at line 127 of file smasi_pdu.h.

#define ESM_CLASS_FORWARD_MODE   0x00000002

Definition at line 125 of file smasi_pdu.h.

#define ESM_CLASS_RPI   0x00000080

Definition at line 130 of file smasi_pdu.h.

#define ESM_CLASS_STORE_AND_FORWARD_MODE   0x00000003

Definition at line 126 of file smasi_pdu.h.

#define ESM_CLASS_UDH_AND_RPI   0x000000C0

Definition at line 131 of file smasi_pdu.h.

#define ESM_CLASS_UDH_INDICATOR   0x00000040

Definition at line 129 of file smasi_pdu.h.

#define ESM_CLASS_USER_ACK   0x00000010

Definition at line 128 of file smasi_pdu.h.

#define GSM_ADDR_NPI_E164   0x00000001

Definition at line 112 of file smasi_pdu.h.

Referenced by get_dest_addr_npi(), get_source_addr_npi(), and msg_to_pdu().

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

Definition at line 117 of file smasi_pdu.h.

#define GSM_ADDR_NPI_EXTENSION   0x0000000F /* Reserved */

Definition at line 118 of file smasi_pdu.h.

#define GSM_ADDR_NPI_NATIONAL   0x00000008

Definition at line 115 of file smasi_pdu.h.

#define GSM_ADDR_NPI_PRIVATE   0x00000009

Definition at line 116 of file smasi_pdu.h.

#define GSM_ADDR_NPI_TELEX   0x00000004

Definition at line 114 of file smasi_pdu.h.

#define GSM_ADDR_NPI_UNKNOWN   0x00000000

Definition at line 111 of file smasi_pdu.h.

Referenced by msg_to_pdu().

#define GSM_ADDR_NPI_X121   0x00000003

Definition at line 113 of file smasi_pdu.h.

#define GSM_ADDR_TON_ABBREVIATED   0x00000006

Definition at line 108 of file smasi_pdu.h.

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

Definition at line 107 of file smasi_pdu.h.

Referenced by convert_addr_from_pdu(), get_originator_type(), and msg_to_pdu().

#define GSM_ADDR_TON_EXTENSION   0x00000007 /* Reserved */

Definition at line 109 of file smasi_pdu.h.

#define GSM_ADDR_TON_INTERNATIONAL   0x00000001
#define GSM_ADDR_TON_NATIONAL   0x00000002

Definition at line 104 of file smasi_pdu.h.

Referenced by msg_to_pdu().

#define GSM_ADDR_TON_NETWORKSPECIFIC   0x00000003

Definition at line 105 of file smasi_pdu.h.

#define GSM_ADDR_TON_SUBSCRIBER   0x00000004

Definition at line 106 of file smasi_pdu.h.

#define GSM_ADDR_TON_UNKNOWN   0x00000000

Definition at line 102 of file smasi_pdu.h.

#define NONTERMINATED (   name)

Definition at line 89 of file smasi_pdu.h.

#define NONTERMINATED (   name)    Octstr *name;

Definition at line 89 of file smasi_pdu.h.

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

Definition at line 91 of file smasi_pdu.h.

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

Definition at line 91 of file smasi_pdu.h.

#define SMASI_HYPHEN_ID   0x00000010

Definition at line 73 of file smasi_pdu.h.

Typedef Documentation

typedef struct SMASI_PDU SMASI_PDU

Definition at line 83 of file smasi_pdu.h.

Enumeration Type Documentation

anonymous enum
Enumerator
PDU 
PDU 

Definition at line 75 of file smasi_pdu.h.

75  {
76  #define NONTERMINATED(name)
77  #define COMATERMINATED(name)
78  #define PDU(name, id, fields) name = id,
79  #include "smasi_pdu.def"
80  SMASI_PDU_DUMMY_TYPE
81 };

Function Documentation

SMASI_PDU* smasi_pdu_create ( unsigned long  type)

Definition at line 132 of file smasi_pdu.c.

References SMASI_PDU::type, type, and warning().

Referenced by handle_pdu(), msg_to_pdu(), open_connection(), send_enquire_link(), send_logoff(), and smasi_pdu_unpack().

133 {
134  SMASI_PDU *pdu;
135 
136  pdu = gw_malloc(sizeof(*pdu));
137  pdu->type = type;
138 
139  switch (type) {
140  #define NONTERMINATED(name) p->name = NULL;
141  #define COMATERMINATED(name) p->name = NULL;
142  #define PDU(name, id, fields) \
143  case id: { \
144  struct name *p = &pdu->u.name; \
145  pdu->type_name = #name; \
146  pdu->needs_hyphen = (id < SMASI_HYPHEN_ID ? 1 : 0); \
147  fields \
148  } break;
149  #include "smasi_pdu.def"
150  default:
151  warning(0, "Unknown SMASI_PDU type, internal error.");
152  gw_free(pdu);
153  return NULL;
154  }
155 
156  return pdu;
157 }
unsigned long type
Definition: smasi_pdu.h:85
int type
Definition: smsc_cimd2.c:215
void warning(int err, const char *fmt,...)
Definition: log.c:624
void smasi_pdu_destroy ( SMASI_PDU pdu)

Definition at line 160 of file smasi_pdu.c.

References error(), and SMASI_PDU::type.

Referenced by handle_pdu(), open_connection(), send_enquire_link(), send_logoff(), send_messages(), and smasi_thread().

161 {
162  if (pdu == NULL)
163  return;
164 
165  switch (pdu->type) {
166  #define NONTERMINATED(name) octstr_destroy(p->name);
167  #define COMATERMINATED(name) octstr_destroy(p->name);
168  #define PDU(name, id, fields) \
169  case id: { struct name *p = &pdu->u.name; fields } break;
170  #include "smasi_pdu.def"
171  default:
172  error(0, "Unknown SMASI_PDU type, internal error while destroying.");
173  }
174  gw_free(pdu);
175 }
void error(int err, const char *fmt,...)
Definition: log.c:612
unsigned long type
Definition: smasi_pdu.h:85
void smasi_pdu_dump ( SMASI_PDU pdu)

Definition at line 280 of file smasi_pdu.c.

References debug(), SMASI_PDU::type, SMASI_PDU::type_name, and warning().

Referenced by dump_pdu().

281 {
282  debug("sms.smasi", 0, "SMASI PDU %p dump:", (void *) pdu);
283  debug("sms.smasi", 0, " type_name: %s", pdu->type_name);
284  switch (pdu->type) {
285  #define NONTERMINATED(name) p = *(&p);
286  #define COMATERMINATED(name) \
287  octstr_dump_short(p->name, 2, #name);
288  #define PDU(name, id, fields) \
289  case id: { struct name *p = &pdu->u.name; fields } break;
290  #include "smasi_pdu.def"
291  default:
292  warning(0, "Unknown SMASI_PDU type, internal error.");
293  break;
294  }
295  debug("sms.smasi", 0, "SMASI PDU dump ends.");
296 }
const char * type_name
Definition: smasi_pdu.h:86
unsigned long type
Definition: smasi_pdu.h:85
void warning(int err, const char *fmt,...)
Definition: log.c:624
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int smasi_pdu_is_valid ( SMASI_PDU pdu)
Octstr* smasi_pdu_pack ( SMASI_PDU pdu)

Definition at line 178 of file smasi_pdu.c.

References error(), SMASI_PDU::needs_hyphen, octstr_append_char(), octstr_append_cstr(), octstr_create, octstr_destroy(), octstr_insert(), SMASI_PDU::type, and SMASI_PDU::type_name.

Referenced by send_enquire_link(), send_logoff(), and send_pdu().

179 {
180  Octstr *os;
181  Octstr *temp;
182 
183  os = octstr_create("");
184 
185  /*
186  * Fix lengths of octet string fields.
187  */
188  switch (pdu->type) {
189  #define NONTERMINATED(name) p = *(&p);
190  #define COMATERMINATED(name) p = *(&p);
191  #define PDU(name, id, fields) \
192  case id: { struct name *p = &pdu->u.name; fields } break;
193  #include "smasi_pdu.def"
194  default:
195  error(0, "Unknown SMASI_PDU type, internal error while packing.");
196  }
197 
198  switch (pdu->type) {
199  #define NONTERMINATED(name) p = *(&p);
200  #define COMATERMINATED(name) \
201  if (p->name != NULL) { octstr_append_cstr(os, #name); \
202  octstr_append_char(os, '='); \
203  octstr_append(os, p->name); \
204  octstr_append_char(os, ','); }
205  #define PDU(name, id, fields) \
206  case id: { struct name *p = &pdu->u.name; fields } break;
207  #include "smasi_pdu.def"
208  default:
209  error(0, "Unknown SMASI_PDU type, internal error while packing.");
210  }
211 
212  octstr_append_char(os, '\n');
213  temp = pdu->needs_hyphen ? octstr_create("!") : octstr_create("");
214  octstr_append_cstr(temp, pdu->type_name);
215  octstr_append_char(temp, ':');
216  octstr_insert(os, temp, 0);
217  octstr_destroy(temp);
218 
219  return os;
220 }
void error(int err, const char *fmt,...)
Definition: log.c:612
unsigned int needs_hyphen
Definition: smasi_pdu.h:87
const char * type_name
Definition: smasi_pdu.h:86
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1515
unsigned long type
Definition: smasi_pdu.h:85
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1509
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
Definition: octstr.c:118
Octstr* smasi_pdu_read ( Connection conn)

Definition at line 299 of file smasi_pdu.c.

References conn_read_line().

Referenced by read_pdu().

300 {
301  Octstr *line;
302 
303  line = conn_read_line(conn); /* read one line */
304  return line;
305 }
Octstr * conn_read_line(Connection *conn)
Definition: conn.c:1126
Definition: octstr.c:118
SMASI_PDU* smasi_pdu_unpack ( Octstr data_without_len)

Definition at line 223 of file smasi_pdu.c.

References decode_type(), octstr_destroy(), octstr_get_cstr, skip_until_after_colon(), smasi_pdu_create(), type, and warning().

Referenced by read_pdu().

224 {
225  SMASI_PDU *pdu;
226  char *type_name;
227  Octstr *temp;
228  long pos;
229  unsigned long type = 0;
230 
231  /* extract the PDU type identifier */
232  temp = decode_type(data_without_len);
233  type_name = (temp ? octstr_get_cstr(temp) : "");
234 
235  if (strcmp(type_name, "dummy") == 0) type = 0;
236  #define NONTERMINATED(name) p = *(&p);
237  #define COMATERMINATED(name) p = *(&p);
238  #define PDU(name, id, fields) \
239  else if (strcmp(type_name, #name) == 0) type = id;
240  #include "smasi_pdu.def"
241  else warning(0, "unknown SMASI PDU type");
242 
243  pdu = smasi_pdu_create(type);
244  if (pdu == NULL) return NULL;
245 
246  pos = 0;
247  skip_until_after_colon(data_without_len, &pos);
248 
249  switch (type) {
250  #define NONTERMINATED(name) p = *(&p);
251  #define COMATERMINATED(name) \
252  if (octstr_str_compare(field_name, #name) == 0 && field_value != NULL) \
253  p->name = octstr_duplicate(field_value);
254  #define PDU(name, id, fields) \
255  case id: { \
256  Octstr * field_name = NULL; \
257  Octstr * field_value = NULL; \
258  struct name *p = &pdu->u.name; \
259  while (pos < octstr_len(data_without_len)) { \
260  field_name = copy_until_assign(data_without_len, &pos); \
261  if (field_name == NULL) break; \
262  field_value = copy_until_coma(data_without_len, &pos); \
263  if (field_value == NULL) continue; \
264  fields \
265  octstr_destroy(field_name); \
266  octstr_destroy(field_value); \
267  } \
268  } break;
269  #include "smasi_pdu.def"
270  default:
271  warning(0, "Unknown SMASI_PDU type, internal error while unpacking.");
272  }
273 
274  octstr_destroy(temp);
275 
276  return pdu;
277 }
static Octstr * decode_type(Octstr *os)
Definition: smasi_pdu.c:68
int type
Definition: smsc_cimd2.c:215
SMASI_PDU * smasi_pdu_create(unsigned long type)
Definition: smasi_pdu.c:132
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static void skip_until_after_colon(Octstr *os, long *pos)
Definition: smasi_pdu.c:121
void warning(int err, const char *fmt,...)
Definition: log.c:624
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Definition: octstr.c:118
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.