blob: 76772a3ee44520ce7943294f39c4731f9f00a331 [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 Weltec0847d62019-05-08 23:55:58 +020016#define SMPP_SYS_ID_LEN 15
17#define SMPP_PASSWD_LEN 8
Harald Welte338e3b32012-11-20 22:22:04 +010018
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +020019#define MODE_7BIT 7
20#define MODE_8BIT 8
21
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010022struct msc_a;
23
Harald Weltef1033cc2012-11-08 16:14:37 +010024enum esme_read_state {
25 READ_ST_IN_LEN = 0,
26 READ_ST_IN_MSG = 1,
27};
28
Harald Welte338e3b32012-11-20 22:22:04 +010029struct osmo_smpp_acl;
30
Harald Weltee07b6a72012-11-23 19:02:37 +010031struct osmo_smpp_addr {
32 uint8_t ton;
33 uint8_t npi;
34 char addr[21+1];
35};
36
Harald Weltef1033cc2012-11-08 16:14:37 +010037struct osmo_esme {
38 struct llist_head list;
39 struct smsc *smsc;
Harald Welte338e3b32012-11-20 22:22:04 +010040 struct osmo_smpp_acl *acl;
Harald Weltee94db492012-11-08 20:11:05 +010041 int use;
42
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +020043 struct llist_head smpp_cmd_list;
44
Harald Welte8a1b0562012-11-09 12:51:44 +010045 uint32_t own_seq_nr;
46
Harald Weltef1033cc2012-11-08 16:14:37 +010047 struct osmo_wqueue wqueue;
Harald Weltef1033cc2012-11-08 16:14:37 +010048
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;
Keithc6d219c2019-01-17 01:01:59 +010071 int alert_notifications;
Harald Weltee07b6a72012-11-23 19:02:37 +010072 struct llist_head route_list;
Harald Welte338e3b32012-11-20 22:22:04 +010073};
74
Harald Weltee07b6a72012-11-23 19:02:37 +010075enum osmo_smpp_rtype {
76 SMPP_ROUTE_NONE,
77 SMPP_ROUTE_PREFIX,
78};
79
80struct osmo_smpp_route {
81 struct llist_head list; /*!< in acl.route_list */
82 struct llist_head global_list; /*!< in smsc->route_list */
83 struct osmo_smpp_acl *acl;
84 enum osmo_smpp_rtype type;
85 union {
86 struct osmo_smpp_addr prefix;
87 } u;
88};
89
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +020090struct osmo_smpp_cmd {
91 struct llist_head list;
Harald Welte2483f1b2016-06-19 18:06:02 +020092 struct vlr_subscr *vsub;
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +020093 uint32_t sequence_nr;
Pablo Neira Ayusofdc99662017-08-07 14:01:10 +010094 uint32_t gsm411_msg_ref;
95 uint8_t gsm411_trans_id;
Pablo Neira Ayusoadae8592017-08-07 14:01:30 +010096 bool is_report;
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +020097 struct osmo_timer_list response_timer;
98};
99
100struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct osmo_esme *esme,
101 uint32_t sequence_number);
102void smpp_cmd_ack(struct osmo_smpp_cmd *cmd);
Keith320960c2017-05-13 23:38:52 +0200103void smpp_cmd_err(struct osmo_smpp_cmd *cmd, uint32_t status);
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200104void smpp_cmd_flush_pending(struct osmo_esme *esme);
Harald Weltee07b6a72012-11-23 19:02:37 +0100105
Harald Weltef1033cc2012-11-08 16:14:37 +0100106struct smsc {
107 struct osmo_fd listen_ofd;
108 struct llist_head esme_list;
Harald Welte338e3b32012-11-20 22:22:04 +0100109 struct llist_head acl_list;
Harald Weltee07b6a72012-11-23 19:02:37 +0100110 struct llist_head route_list;
Vadim Yanitskiy97b8e762021-10-26 00:39:11 +0300111 char *bind_addr;
Harald Welte338e3b32012-11-20 22:22:04 +0100112 uint16_t listen_port;
113 char system_id[SMPP_SYS_ID_LEN+1];
114 int accept_all;
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200115 int smpp_first;
Harald Weltee07b6a72012-11-23 19:02:37 +0100116 struct osmo_smpp_acl *def_route;
Harald Weltef1033cc2012-11-08 16:14:37 +0100117 void *priv;
118};
119
Harald Weltee07b6a72012-11-23 19:02:37 +0100120int smpp_addr_eq(const struct osmo_smpp_addr *a,
121 const struct osmo_smpp_addr *b);
Harald Weltef1033cc2012-11-08 16:14:37 +0100122
Neels Hofmeyr1b0e5542016-02-24 19:15:39 +0100123struct smsc *smpp_smsc_alloc_init(void *ctx);
124int smpp_smsc_conf(struct smsc *smsc, const char *bind_addr, uint16_t port);
125int smpp_smsc_start(struct smsc *smsc, const char *bind_addr, uint16_t port);
126int smpp_smsc_restart(struct smsc *smsc, const char *bind_addr, uint16_t port);
127void smpp_smsc_stop(struct smsc *smsc);
Harald Weltef1033cc2012-11-08 16:14:37 +0100128
Harald Weltee94db492012-11-08 20:11:05 +0100129void smpp_esme_get(struct osmo_esme *esme);
130void smpp_esme_put(struct osmo_esme *esme);
131
Benoit Bolseed34ed572017-07-05 11:46:55 +0200132int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct osmo_esme **emse);
Harald Weltee07b6a72012-11-23 19:02:37 +0100133
Harald Welte338e3b32012-11-20 22:22:04 +0100134struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id);
135struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc,
136 const char *sys_id);
137void smpp_acl_delete(struct osmo_smpp_acl *acl);
138
Harald Welted4bdee72012-11-08 19:44:08 +0100139int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr,
140 uint32_t command_status, char *msg_id);
141
Harald Welte8a1b0562012-11-09 12:51:44 +0100142int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi,
143 const char *addr, uint8_t avail_status);
144
Harald Weltee07b6a72012-11-23 19:02:37 +0100145int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver);
146
Harald Weltef1033cc2012-11-08 16:14:37 +0100147int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
148 struct submit_sm_resp_t *submit_r);
149
Harald Weltee07b6a72012-11-23 19:02:37 +0100150int smpp_route_pfx_add(struct osmo_smpp_acl *acl,
151 const struct osmo_smpp_addr *pfx);
152int smpp_route_pfx_del(struct osmo_smpp_acl *acl,
153 const struct osmo_smpp_addr *pfx);
Holger Hans Peter Freyther5ecbc932013-07-27 18:39:30 +0200154
155int smpp_vty_init(void);
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +0200156
157int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode);
Holger Hans Peter Freythere3c391e2015-07-06 16:40:01 +0200158
Harald Weltee6f11602022-05-17 18:25:14 +0200159time_t smpp_parse_time_format(const char *vp, time_t *t_now);
Holger Hans Peter Freythere3c391e2015-07-06 16:40:01 +0200160
161
162struct gsm_sms;
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100163struct ran_conn;
Holger Hans Peter Freythere3c391e2015-07-06 16:40:01 +0200164
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100165bool smpp_route_smpp_first();
166int smpp_try_deliver(struct gsm_sms *sms, struct msc_a *msc_a);
Harald Weltef1033cc2012-11-08 16:14:37 +0100167#endif