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

Go to the source code of this file.

Data Structures

struct  ModemDef
 
struct  PrivAT2data
 

Macros

#define MAX_READ   1023
 
#define AT_DELIVER_SM   0
 
#define AT_SUBMIT_SM   1
 
#define AT_STATUS_REPORT_SM   2
 
#define PNT_UNKNOWN   0
 
#define PNT_INTER   1
 
#define PNT_NATIONAL   2
 
#define RETRY_WRITE   3
 
#define AT2_DEFAULT_SMS_POLL_INTERVAL   60
 
#define O_DESTROY(a)   { if(a) octstr_destroy(a); a = NULL; }
 

Typedefs

typedef struct ModemDef ModemDef
 
typedef struct PrivAT2data PrivAT2data
 

Functions

static int at2_open_device (PrivAT2data *privdata)
 
static void at2_close_device (PrivAT2data *privdata)
 
static void at2_read_buffer (PrivAT2data *privdata, double timeout)
 
static Octstrat2_wait_line (PrivAT2data *privdata, time_t timeout, int gt_flag)
 
static Octstrat2_read_line (PrivAT2data *privdata, int gt_flag, double timeout)
 
static int at2_write_line (PrivAT2data *privdata, char *line)
 
static int at2_write_ctrlz (PrivAT2data *privdata)
 
static int at2_write (PrivAT2data *privdata, char *line)
 
static void at2_flush_buffer (PrivAT2data *privdata)
 
static int at2_init_device (PrivAT2data *privdata)
 
static int at2_send_modem_command (PrivAT2data *privdata, char *cmd, time_t timeout, int greaterflag)
 
static int at2_wait_modem_command (PrivAT2data *privdata, time_t timeout, int greaterflag, int *output)
 
static void at2_set_speed (PrivAT2data *privdata, int bps)
 
static void at2_device_thread (void *arg)
 
static int at2_shutdown_cb (SMSCConn *conn, int finish_sending)
 
static long at2_queued_cb (SMSCConn *conn)
 
static void at2_start_cb (SMSCConn *conn)
 
static int at2_add_msg_cb (SMSCConn *conn, Msg *sms)
 
int smsc_at2_create (SMSCConn *conn, CfgGroup *cfg)
 
static int at2_pdu_extract (PrivAT2data *privdata, Octstr **pdu, Octstr *line, Octstr *smsc_number)
 
static int at2_hexchar (int hexc)
 
static Msgat2_pdu_decode (Octstr *data, PrivAT2data *privdata)
 
static Msgat2_pdu_decode_deliver_sm (Octstr *data, PrivAT2data *privdata)
 
static Msgat2_pdu_decode_report_sm (Octstr *data, PrivAT2data *privdata)
 
static Octstrat2_convertpdu (Octstr *pdutext)
 
static void at2_decode7bituncompressed (Octstr *input, int len, Octstr *decoded, int offset)
 
static void at2_send_messages (PrivAT2data *privdata)
 
static void at2_send_one_message (PrivAT2data *privdata, Msg *msg)
 
static Octstrat2_pdu_encode (Msg *msg, PrivAT2data *privdata)
 
static Octstrat2_encode7bituncompressed (Octstr *input, int offset)
 
static Octstrat2_encode8bituncompressed (Octstr *input)
 
static int at2_numtext (int num)
 
static int at2_detect_speed (PrivAT2data *privdata)
 
static int at2_test_speed (PrivAT2data *privdata, long speed)
 
static int at2_detect_modem_type (PrivAT2data *privdata)
 
static ModemDefat2_read_modems (PrivAT2data *privdata, Octstr *file, Octstr *id, int idnumber)
 
static void at2_destroy_modem (ModemDef *modem)
 
static int at2_read_sms_memory (PrivAT2data *privdata)
 
static int at2_check_sms_memory (PrivAT2data *privdata)
 
static int swap_nibbles (unsigned char byte)
 
static Octstrat2_format_address_field (Octstr *msisdn)
 
static void at2_read_pending_incoming_messages (PrivAT2data *privdata)
 
static int at2_set_message_storage (PrivAT2data *privdata, Octstr *memory_name)
 
static int at2_read_delete_message (PrivAT2data *privdata, int message_number)
 
static const char * at2_error_string (int code)
 

Macro Definition Documentation

#define AT2_DEFAULT_SMS_POLL_INTERVAL   60

Definition at line 94 of file smsc_at.h.

Referenced by smsc_at2_create().

#define AT_DELIVER_SM   0

Definition at line 77 of file smsc_at.h.

Referenced by at2_pdu_decode().

#define AT_STATUS_REPORT_SM   2

Definition at line 79 of file smsc_at.h.

Referenced by at2_pdu_decode().

#define AT_SUBMIT_SM   1

Definition at line 78 of file smsc_at.h.

#define MAX_READ   1023

Definition at line 74 of file smsc_at.h.

Referenced by at2_read_buffer().

#define O_DESTROY (   a)    { if(a) octstr_destroy(a); a = NULL; }

Definition at line 162 of file smsc_at.h.

#define PNT_INTER   1

Definition at line 83 of file smsc_at.h.

Referenced by at2_format_address_field().

#define PNT_NATIONAL   2

Definition at line 84 of file smsc_at.h.

#define PNT_UNKNOWN   0

Definition at line 82 of file smsc_at.h.

Referenced by at2_format_address_field().

#define RETRY_WRITE   3

Definition at line 87 of file smsc_at.h.

Referenced by at2_write(), at2_write_ctrlz(), and at2_write_line().

Typedef Documentation

typedef struct ModemDef ModemDef
typedef struct PrivAT2data PrivAT2data

Function Documentation

static int at2_add_msg_cb ( SMSCConn conn,
Msg sms 
)
static
static int at2_check_sms_memory ( PrivAT2data privdata)
static
static void at2_close_device ( PrivAT2data privdata)
static
static Octstr* at2_convertpdu ( Octstr pdutext)
static
static void at2_decode7bituncompressed ( Octstr input,
int  len,
Octstr decoded,
int  offset 
)
static
static void at2_destroy_modem ( ModemDef modem)
static
static int at2_detect_modem_type ( PrivAT2data privdata)
static
static int at2_detect_speed ( PrivAT2data privdata)
static
static void at2_device_thread ( void *  arg)
static
static Octstr* at2_encode7bituncompressed ( Octstr input,
int  offset 
)
static
static Octstr* at2_encode8bituncompressed ( Octstr input)
static
static const char* at2_error_string ( int  code)
static
static void at2_flush_buffer ( PrivAT2data privdata)
static
static Octstr* at2_format_address_field ( Octstr msisdn)
static
static int at2_hexchar ( int  hexc)
static
static int at2_init_device ( PrivAT2data privdata)
static
static int at2_numtext ( int  num)
static
static int at2_open_device ( PrivAT2data privdata)
static
static Msg* at2_pdu_decode ( Octstr data,
PrivAT2data privdata 
)
static
static Msg* at2_pdu_decode_deliver_sm ( Octstr data,
PrivAT2data privdata 
)
static
static Msg* at2_pdu_decode_report_sm ( Octstr data,
PrivAT2data privdata 
)
static
static Octstr* at2_pdu_encode ( Msg msg,
PrivAT2data privdata 
)
static
static int at2_pdu_extract ( PrivAT2data privdata,
Octstr **  pdu,
Octstr line,
Octstr smsc_number 
)
static
static long at2_queued_cb ( SMSCConn conn)
static
static void at2_read_buffer ( PrivAT2data privdata,
double  timeout 
)
static
static int at2_read_delete_message ( PrivAT2data privdata,
int  message_number 
)
static
static Octstr* at2_read_line ( PrivAT2data privdata,
int  gt_flag,
double  timeout 
)
static
static ModemDef* at2_read_modems ( PrivAT2data privdata,
Octstr file,
Octstr id,
int  idnumber 
)
static
static void at2_read_pending_incoming_messages ( PrivAT2data privdata)
static
static int at2_read_sms_memory ( PrivAT2data privdata)
static
static void at2_send_messages ( PrivAT2data privdata)
static
static int at2_send_modem_command ( PrivAT2data privdata,
char *  cmd,
time_t  timeout,
int  greaterflag 
)
static
static void at2_send_one_message ( PrivAT2data privdata,
Msg msg 
)
static
static int at2_set_message_storage ( PrivAT2data privdata,
Octstr memory_name 
)
static
static void at2_set_speed ( PrivAT2data privdata,
int  bps 
)
static
static int at2_shutdown_cb ( SMSCConn conn,
int  finish_sending 
)
static
static void at2_start_cb ( SMSCConn conn)
static
static int at2_test_speed ( PrivAT2data privdata,
long  speed 
)
static
static Octstr* at2_wait_line ( PrivAT2data privdata,
time_t  timeout,
int  gt_flag 
)
static
static int at2_wait_modem_command ( PrivAT2data privdata,
time_t  timeout,
int  greaterflag,
int *  output 
)
static
static int at2_write ( PrivAT2data privdata,
char *  line 
)
static
static int at2_write_ctrlz ( PrivAT2data privdata)
static
static int at2_write_line ( PrivAT2data privdata,
char *  line 
)
static
int smsc_at2_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 1519 of file smsc_at.c.

1520 {
1522  Octstr *modem_type_string;
1523  long portno; /* has to be long because of cfg_get_integer */
1524 
1525  privdata = gw_malloc(sizeof(PrivAT2data));
1526  memset(privdata, 0, sizeof(PrivAT2data));
1529 
1530  privdata->configfile = cfg_get_configfile(cfg);
1531 
1532  privdata->device = cfg_get(cfg, octstr_imm("device"));
1533  if (privdata->device == NULL) {
1534  error(0, "AT2[-]: 'device' missing in at2 configuration.");
1535  goto error;
1536  }
1537 
1538  if (octstr_str_compare(privdata->device, "rawtcp") == 0) {
1539  privdata->rawtcp_host = cfg_get(cfg, octstr_imm("host"));
1540  if (privdata->rawtcp_host == NULL) {
1541  error(0, "AT2[-]: 'host' missing in at2 rawtcp configuration.");
1542  goto error;
1543  }
1544  if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) {
1545  error(0, "AT2[-]: 'port' missing in at2 rawtcp configuration.");
1546  goto error;
1547  }
1548  privdata->rawtcp_port = portno;
1549  privdata->is_serial = 0;
1550  privdata->use_telnet = 0;
1551  } else if (octstr_str_compare(privdata->device, "telnet") == 0) {
1552  privdata->rawtcp_host = cfg_get(cfg, octstr_imm("host"));
1553  if (privdata->rawtcp_host == NULL) {
1554  error(0, "AT2[-]: 'host' missing in at2 telnet configuration.");
1555  goto error;
1556  }
1557  if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) {
1558  error(0, "AT2[-]: 'port' missing in at2 telnet configuration.");
1559  goto error;
1560  }
1561  privdata->rawtcp_port = portno;
1562  privdata->is_serial = 0;
1563  privdata->use_telnet = 1;
1564  } else {
1565  privdata->is_serial = 1;
1566  privdata->use_telnet = 0;
1567  }
1568 
1569  privdata->name = cfg_get(cfg, octstr_imm("smsc-id"));
1570  if (privdata->name == NULL) {
1571  privdata->name = octstr_duplicate(privdata->device);
1572  }
1573 
1574  privdata->speed = 0;
1575  cfg_get_integer(&privdata->speed, cfg, octstr_imm("speed"));
1576 
1577  privdata->keepalive = 0;
1578  cfg_get_integer(&privdata->keepalive, cfg, octstr_imm("keepalive"));
1579 
1580  cfg_get_bool(&privdata->sms_memory_poll_interval, cfg, octstr_imm("sim-buffering"));
1581  if (privdata->sms_memory_poll_interval) {
1582  if (privdata->keepalive)
1583  privdata->sms_memory_poll_interval = privdata->keepalive;
1584  else
1586  }
1587 
1588  privdata->my_number = cfg_get(cfg, octstr_imm("my-number"));
1589  privdata->sms_center = cfg_get(cfg, octstr_imm("sms-center"));
1590  privdata->username = cfg_get(cfg, octstr_imm("smsc-username"));
1591  privdata->password = cfg_get(cfg, octstr_imm("smsc-password"));
1592  privdata->login_prompt = cfg_get(cfg, octstr_imm("login-prompt"));
1593  privdata->password_prompt = cfg_get(cfg, octstr_imm("password-prompt"));
1594  modem_type_string = cfg_get(cfg, octstr_imm("modemtype"));
1595 
1596  privdata->modem = NULL;
1597 
1598  if (modem_type_string != NULL) {
1599  if (octstr_compare(modem_type_string, octstr_imm("auto")) == 0 ||
1600  octstr_compare(modem_type_string, octstr_imm("autodetect")) == 0)
1601  O_DESTROY(modem_type_string);
1602  }
1603 
1604  if (octstr_len(modem_type_string) == 0) {
1605  info(0, "AT2[%s]: configuration doesn't show modemtype. will autodetect",
1606  octstr_get_cstr(privdata->name));
1607  } else {
1608  info(0, "AT2[%s]: configuration shows modemtype <%s>",
1609  octstr_get_cstr(privdata->name),
1610  octstr_get_cstr(modem_type_string));
1611  privdata->modem = at2_read_modems(privdata, privdata->configfile,
1612  modem_type_string, 0);
1613  if (privdata->modem == NULL) {
1614  info(0, "AT2[%s]: modemtype not found, revert to autodetect",
1615  octstr_get_cstr(privdata->name));
1616  } else {
1617  info(0, "AT2[%s]: read modem definition for <%s>",
1618  octstr_get_cstr(privdata->name),
1619  octstr_get_cstr(privdata->modem->name));
1620  }
1621  O_DESTROY(modem_type_string);
1622  }
1623 
1624  privdata->ilb = octstr_create("");
1625  privdata->fd = -1;
1626  privdata->lines = NULL;
1627  privdata->pin = cfg_get(cfg, octstr_imm("pin"));
1628  privdata->pin_ready = 0;
1629  privdata->conn = conn;
1630  privdata->phase2plus = 0;
1631  privdata->validityperiod = cfg_get(cfg, octstr_imm("validityperiod"));
1632  if (cfg_get_integer((long *) &privdata->max_error_count, cfg, octstr_imm("max-error-count")) == -1)
1633  privdata->max_error_count = -1;
1634 
1635  privdata->load = load_create_real(0);
1636  load_add_interval(privdata->load, 1);
1637 
1638  conn->data = privdata;
1639  conn->name = octstr_format("AT2[%s]", octstr_get_cstr(privdata->name));
1640  conn->status = SMSCCONN_CONNECTING;
1641  conn->connect_time = time(NULL);
1642 
1643  privdata->shutdown = 0;
1644 
1645  if ((privdata->device_thread = gwthread_create(at2_device_thread, conn)) == -1) {
1646  privdata->shutdown = 1;
1647  goto error;
1648  }
1649 
1650  conn->shutdown = at2_shutdown_cb;
1651  conn->queued = at2_queued_cb;
1652  conn->start_conn = at2_start_cb;
1653  conn->send_msg = at2_add_msg_cb;
1654  return 0;
1655 
1656 error:
1657  error(0, "AT2[%s]: Failed to create at2 smsc connection",
1658  octstr_len(privdata->name) ? octstr_get_cstr(privdata->name) : "");
1659  if (privdata != NULL) {
1660  gw_prioqueue_destroy(privdata->outgoing_queue, NULL);
1661  }
1662  gw_free(privdata);
1664  conn->status = SMSCCONN_DEAD;
1665  info(0, "AT2[%s]: exiting", octstr_get_cstr(privdata->name));
1666  return -1;
1667 }
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
long device_thread
Definition: smsc_at.h:123
static void at2_device_thread(void *arg)
Definition: smsc_at.c:1282
void info(int err, const char *fmt,...)
Definition: log.c:636
Octstr * my_number
Definition: smsc_at.h:137
static long at2_queued_cb(SMSCConn *conn)
Definition: smsc_at.c:1484
Octstr * ilb
Definition: smsc_at.h:129
Octstr * password_prompt
Definition: smsc_at.h:144
gw_prioqueue_t * outgoing_queue
Definition: smsc_at.h:121
#define AT2_DEFAULT_SMS_POLL_INTERVAL
Definition: smsc_at.h:94
int use_telnet
Definition: smsc_at.h:153
void * data
Definition: smscconn_p.h:249
Octstr * cfg_get_configfile(CfgGroup *grp)
Definition: cfg.c:713
long keepalive
Definition: smsc_at.h:127
int load_add_interval(Load *load, int interval)
Definition: load.c:111
#define cfg_get(grp, varname)
Definition: cfg.h:86
Load * load_create_real(int heuristic)
Definition: load.c:97
Octstr * login_prompt
Definition: smsc_at.h:143
ModemDef * modem
Definition: smsc_at.h:122
Octstr * configfile
Definition: smsc_at.h:140
int phase2plus
Definition: smsc_at.h:134
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
Octstr * pin
Definition: smsc_at.h:131
Octstr * validityperiod
Definition: smsc_at.h:135
int shutdown
Definition: smsc_at.h:124
int sms_memory_poll_interval
Definition: smsc_at.h:145
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
int pin_ready
Definition: smsc_at.h:132
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
long speed
Definition: smsc_at.h:126
int sms_priority_compare(const void *a, const void *b)
Definition: sms.c:395
static int at2_shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_at.c:1454
int rawtcp_port
Definition: smsc_at.h:151
static ModemDef * at2_read_modems(PrivAT2data *privdata, Octstr *file, Octstr *id, int idnumber)
Definition: smsc_at.c:2758
time_t connect_time
Definition: smscconn_p.h:155
static int at2_add_msg_cb(SMSCConn *conn, Msg *sms)
Definition: smsc_at.c:1508
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
#define O_DESTROY(a)
Definition: smsbox.c:97
gw_prioqueue_t * gw_prioqueue_create(int(*cmp)(const void *, const void *))
Definition: gw-prioqueue.c:174
Octstr * sms_center
Definition: smsc_at.h:138
int is_serial
Definition: smsc_at.h:152
Octstr * name
Definition: smsc_at.h:101
long max_error_count
Definition: smsc_at.h:149
Octstr * rawtcp_host
Definition: smsc_at.h:150
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
void gw_prioqueue_destroy(gw_prioqueue_t *queue, void(*item_destroy)(void *))
Definition: gw-prioqueue.c:201
Octstr * name
Definition: smsc_at.h:139
Octstr * lines
Definition: smsc_at.h:130
Definition: octstr.c:118
List * pending_incoming_messages
Definition: smsc_at.h:148
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:971
smscconn_status_t status
Definition: smscconn_p.h:151
Octstr * password
Definition: smsc_at.h:142
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
static void at2_start_cb(SMSCConn *conn)
Definition: smsc_at.c:1495
Octstr * device
Definition: smsc_at.h:125
Octstr * username
Definition: smsc_at.h:141
Load * load
Definition: smsc_at.h:154
SMSCConn * conn
Definition: smsc_at.h:133
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
static int swap_nibbles ( unsigned char  byte)
static
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.