blob: b95a1f509689b893cafd5b7b9668bc1a1a6fddc2 [file] [log] [blame]
Harald Weltef1033cc2012-11-08 16:14:37 +01001#ifndef _SMPP_SMSC_H
2#define _SMPP_SMSC_H
3
4#include <sys/socket.h>
5#include <netinet/in.h>
6
7#include <osmocom/core/utils.h>
8#include <osmocom/core/msgb.h>
9#include <osmocom/core/write_queue.h>
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +020010#include <osmocom/core/timer.h>
Harald Weltef1033cc2012-11-08 16:14:37 +010011
12#include <smpp34.h>
13#include <smpp34_structs.h>
14#include <smpp34_params.h>
15
Harald Welte338e3b32012-11-20 22:22:04 +010016#define SMPP_SYS_ID_LEN 16
17#define SMPP_PASSWD_LEN 16
18
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +020019#define MODE_7BIT 7
20#define MODE_8BIT 8
21
Harald Weltef1033cc2012-11-08 16:14:37 +010022enum esme_read_state {
23 READ_ST_IN_LEN = 0,
24 READ_ST_IN_MSG = 1,
25};
26
Harald Welte338e3b32012-11-20 22:22:04 +010027struct osmo_smpp_acl;
28
Harald Weltee07b6a72012-11-23 19:02:37 +010029struct osmo_smpp_addr {
30 uint8_t ton;
31 uint8_t npi;
32 char addr[21+1];
33};
34
Harald Weltef1033cc2012-11-08 16:14:37 +010035struct osmo_esme {
36 struct llist_head list;
37 struct smsc *smsc;
Harald Welte338e3b32012-11-20 22:22:04 +010038 struct osmo_smpp_acl *acl;
Harald Weltee94db492012-11-08 20:11:05 +010039 int use;
40
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +020041 struct llist_head smpp_cmd_list;
42
Harald Welte8a1b0562012-11-09 12:51:44 +010043 uint32_t own_seq_nr;
44
Harald Weltef1033cc2012-11-08 16:14:37 +010045 struct osmo_wqueue wqueue;
46 struct sockaddr_storage sa;
47 socklen_t sa_len;
48
49 enum esme_read_state read_state;
50 uint32_t read_len;
51 uint32_t read_idx;
52 struct msgb *read_msg;
53
54 uint8_t smpp_version;
Harald Welte338e3b32012-11-20 22:22:04 +010055 char system_id[SMPP_SYS_ID_LEN+1];
Harald Weltef1033cc2012-11-08 16:14:37 +010056
57 uint8_t bind_flags;
58};
59
Harald Welte338e3b32012-11-20 22:22:04 +010060struct osmo_smpp_acl {
61 struct llist_head list;
62 struct smsc *smsc;
Harald Weltee07b6a72012-11-23 19:02:37 +010063 struct osmo_esme *esme;
Harald Welte338e3b32012-11-20 22:22:04 +010064 char *description;
65 char system_id[SMPP_SYS_ID_LEN+1];
66 char passwd[SMPP_PASSWD_LEN+1];
67 int default_route;
Harald Weltee07b6a72012-11-23 19:02:37 +010068 int deliver_src_imsi;
Harald Welte3f786002013-03-13 15:29:27 +010069 int osmocom_ext;
Harald Weltec75ed6d2013-05-28 20:58:02 +020070 int dcs_transparent;
Harald Weltee07b6a72012-11-23 19:02:37 +010071 struct llist_head route_list;
Harald Welte338e3b32012-11-20 22:22:04 +010072};
73
Harald Weltee07b6a72012-11-23 19:02:37 +010074enum osmo_smpp_rtype {
75 SMPP_ROUTE_NONE,
76 SMPP_ROUTE_PREFIX,
77};
78
79struct osmo_smpp_route {
80 struct llist_head list; /*!< in acl.route_list */
81 struct llist_head global_list; /*!< in smsc->route_list */
82 struct osmo_smpp_acl *acl;
83 enum osmo_smpp_rtype type;
84 union {
85 struct osmo_smpp_addr prefix;
86 } u;
87};
88
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +020089struct osmo_smpp_cmd {
90 struct llist_head list;
91 struct gsm_subscriber *subscr;
92 struct gsm_sms *sms;
93 uint32_t sequence_nr;
94 struct osmo_timer_list response_timer;
95};
96
97struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct osmo_esme *esme,
98 uint32_t sequence_number);
99void smpp_cmd_ack(struct osmo_smpp_cmd *cmd);
100void smpp_cmd_err(struct osmo_smpp_cmd *cmd);
101void smpp_cmd_flush_pending(struct osmo_esme *esme);
Harald Weltee07b6a72012-11-23 19:02:37 +0100102
Harald Weltef1033cc2012-11-08 16:14:37 +0100103struct smsc {
104 struct osmo_fd listen_ofd;
105 struct llist_head esme_list;
Harald Welte338e3b32012-11-20 22:22:04 +0100106 struct llist_head acl_list;
Harald Weltee07b6a72012-11-23 19:02:37 +0100107 struct llist_head route_list;
Neels Hofmeyr1b0e5542016-02-24 19:15:39 +0100108 const char *bind_addr;
Harald Welte338e3b32012-11-20 22:22:04 +0100109 uint16_t listen_port;
110 char system_id[SMPP_SYS_ID_LEN+1];
111 int accept_all;
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200112 int smpp_first;
Harald Weltee07b6a72012-11-23 19:02:37 +0100113 struct osmo_smpp_acl *def_route;
Harald Weltef1033cc2012-11-08 16:14:37 +0100114 void *priv;
115};
116
Harald Weltee07b6a72012-11-23 19:02:37 +0100117int smpp_addr_eq(const struct osmo_smpp_addr *a,
118 const struct osmo_smpp_addr *b);
Harald Weltef1033cc2012-11-08 16:14:37 +0100119
Neels Hofmeyr1b0e5542016-02-24 19:15:39 +0100120struct smsc *smpp_smsc_alloc_init(void *ctx);
121int smpp_smsc_conf(struct smsc *smsc, const char *bind_addr, uint16_t port);
122int smpp_smsc_start(struct smsc *smsc, const char *bind_addr, uint16_t port);
123int smpp_smsc_restart(struct smsc *smsc, const char *bind_addr, uint16_t port);
124void smpp_smsc_stop(struct smsc *smsc);
Harald Weltef1033cc2012-11-08 16:14:37 +0100125
Harald Weltee94db492012-11-08 20:11:05 +0100126void smpp_esme_get(struct osmo_esme *esme);
127void smpp_esme_put(struct osmo_esme *esme);
128
Harald Weltee07b6a72012-11-23 19:02:37 +0100129struct osmo_esme *
130smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest);
131
Harald Welte338e3b32012-11-20 22:22:04 +0100132struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id);
133struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc,
134 const char *sys_id);
135void smpp_acl_delete(struct osmo_smpp_acl *acl);
136
Harald Welted4bdee72012-11-08 19:44:08 +0100137int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr,
138 uint32_t command_status, char *msg_id);
139
Harald Welte8a1b0562012-11-09 12:51:44 +0100140int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi,
141 const char *addr, uint8_t avail_status);
142
Harald Weltee07b6a72012-11-23 19:02:37 +0100143int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver);
144
Harald Weltef1033cc2012-11-08 16:14:37 +0100145int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
146 struct submit_sm_resp_t *submit_r);
147
Harald Weltee07b6a72012-11-23 19:02:37 +0100148int smpp_route_pfx_add(struct osmo_smpp_acl *acl,
149 const struct osmo_smpp_addr *pfx);
150int smpp_route_pfx_del(struct osmo_smpp_acl *acl,
151 const struct osmo_smpp_addr *pfx);
Holger Hans Peter Freyther5ecbc932013-07-27 18:39:30 +0200152
153int smpp_vty_init(void);
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +0200154
155int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode);
Holger Hans Peter Freythere3c391e2015-07-06 16:40:01 +0200156
157
158
159struct gsm_sms;
160struct gsm_subscriber_connection;
161
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200162int smpp_route_smpp_first(struct gsm_sms *sms,
163 struct gsm_subscriber_connection *conn);
Holger Hans Peter Freythere3c391e2015-07-06 16:40:01 +0200164int smpp_try_deliver(struct gsm_sms *sms,
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200165 struct gsm_subscriber_connection *conn, bool *deferred);
Harald Weltef1033cc2012-11-08 16:14:37 +0100166#endif