Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 1 | #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 Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 10 | #include <osmocom/core/timer.h> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 11 | |
| 12 | #include <smpp34.h> |
| 13 | #include <smpp34_structs.h> |
| 14 | #include <smpp34_params.h> |
| 15 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 16 | #define SMPP_SYS_ID_LEN 16 |
| 17 | #define SMPP_PASSWD_LEN 16 |
| 18 | |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 19 | #define MODE_7BIT 7 |
| 20 | #define MODE_8BIT 8 |
| 21 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 22 | enum esme_read_state { |
| 23 | READ_ST_IN_LEN = 0, |
| 24 | READ_ST_IN_MSG = 1, |
| 25 | }; |
| 26 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 27 | struct osmo_smpp_acl; |
| 28 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 29 | struct osmo_smpp_addr { |
| 30 | uint8_t ton; |
| 31 | uint8_t npi; |
| 32 | char addr[21+1]; |
| 33 | }; |
| 34 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 35 | struct osmo_esme { |
| 36 | struct llist_head list; |
| 37 | struct smsc *smsc; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 38 | struct osmo_smpp_acl *acl; |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 39 | int use; |
| 40 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 41 | struct llist_head smpp_cmd_list; |
| 42 | |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 43 | uint32_t own_seq_nr; |
| 44 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 45 | 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 Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 55 | char system_id[SMPP_SYS_ID_LEN+1]; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 56 | |
| 57 | uint8_t bind_flags; |
| 58 | }; |
| 59 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 60 | struct osmo_smpp_acl { |
| 61 | struct llist_head list; |
| 62 | struct smsc *smsc; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 63 | struct osmo_esme *esme; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 64 | char *description; |
| 65 | char system_id[SMPP_SYS_ID_LEN+1]; |
| 66 | char passwd[SMPP_PASSWD_LEN+1]; |
| 67 | int default_route; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 68 | int deliver_src_imsi; |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 69 | int osmocom_ext; |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 70 | int dcs_transparent; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 71 | struct llist_head route_list; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 74 | enum osmo_smpp_rtype { |
| 75 | SMPP_ROUTE_NONE, |
| 76 | SMPP_ROUTE_PREFIX, |
| 77 | }; |
| 78 | |
| 79 | struct 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 Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 89 | struct osmo_smpp_cmd { |
| 90 | struct llist_head list; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 91 | struct vlr_subscr *vsub; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 92 | uint32_t sequence_nr; |
Pablo Neira Ayuso | fdc9966 | 2017-08-07 14:01:10 +0100 | [diff] [blame] | 93 | uint32_t gsm411_msg_ref; |
| 94 | uint8_t gsm411_trans_id; |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 95 | bool is_report; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 96 | struct osmo_timer_list response_timer; |
| 97 | }; |
| 98 | |
| 99 | struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct osmo_esme *esme, |
| 100 | uint32_t sequence_number); |
| 101 | void smpp_cmd_ack(struct osmo_smpp_cmd *cmd); |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 102 | void smpp_cmd_err(struct osmo_smpp_cmd *cmd, uint32_t status); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 103 | void smpp_cmd_flush_pending(struct osmo_esme *esme); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 104 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 105 | struct smsc { |
| 106 | struct osmo_fd listen_ofd; |
| 107 | struct llist_head esme_list; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 108 | struct llist_head acl_list; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 109 | struct llist_head route_list; |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 110 | const char *bind_addr; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 111 | uint16_t listen_port; |
| 112 | char system_id[SMPP_SYS_ID_LEN+1]; |
| 113 | int accept_all; |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 114 | int smpp_first; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 115 | struct osmo_smpp_acl *def_route; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 116 | void *priv; |
| 117 | }; |
| 118 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 119 | int smpp_addr_eq(const struct osmo_smpp_addr *a, |
| 120 | const struct osmo_smpp_addr *b); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 121 | |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 122 | struct smsc *smpp_smsc_alloc_init(void *ctx); |
| 123 | int smpp_smsc_conf(struct smsc *smsc, const char *bind_addr, uint16_t port); |
| 124 | int smpp_smsc_start(struct smsc *smsc, const char *bind_addr, uint16_t port); |
| 125 | int smpp_smsc_restart(struct smsc *smsc, const char *bind_addr, uint16_t port); |
| 126 | void smpp_smsc_stop(struct smsc *smsc); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 127 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 128 | void smpp_esme_get(struct osmo_esme *esme); |
| 129 | void smpp_esme_put(struct osmo_esme *esme); |
| 130 | |
Benoit Bolsee | d34ed57 | 2017-07-05 11:46:55 +0200 | [diff] [blame] | 131 | int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct osmo_esme **emse); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 132 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 133 | struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id); |
| 134 | struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc, |
| 135 | const char *sys_id); |
| 136 | void smpp_acl_delete(struct osmo_smpp_acl *acl); |
| 137 | |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 138 | int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr, |
| 139 | uint32_t command_status, char *msg_id); |
| 140 | |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 141 | int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi, |
| 142 | const char *addr, uint8_t avail_status); |
| 143 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 144 | int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver); |
| 145 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 146 | int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit, |
| 147 | struct submit_sm_resp_t *submit_r); |
| 148 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 149 | int smpp_route_pfx_add(struct osmo_smpp_acl *acl, |
| 150 | const struct osmo_smpp_addr *pfx); |
| 151 | int smpp_route_pfx_del(struct osmo_smpp_acl *acl, |
| 152 | const struct osmo_smpp_addr *pfx); |
Holger Hans Peter Freyther | 5ecbc93 | 2013-07-27 18:39:30 +0200 | [diff] [blame] | 153 | |
| 154 | int smpp_vty_init(void); |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 155 | |
| 156 | int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode); |
Holger Hans Peter Freyther | e3c391e | 2015-07-06 16:40:01 +0200 | [diff] [blame] | 157 | |
| 158 | |
| 159 | |
| 160 | struct gsm_sms; |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 161 | struct ran_conn; |
Holger Hans Peter Freyther | e3c391e | 2015-07-06 16:40:01 +0200 | [diff] [blame] | 162 | |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 163 | int smpp_route_smpp_first(struct gsm_sms *sms, |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 164 | struct ran_conn *conn); |
Holger Hans Peter Freyther | e3c391e | 2015-07-06 16:40:01 +0200 | [diff] [blame] | 165 | int smpp_try_deliver(struct gsm_sms *sms, |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 166 | struct ran_conn *conn); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 167 | #endif |