Max | 5346f69 | 2022-07-28 14:19:22 +0700 | [diff] [blame] | 1 | #pragma once |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 2 | |
| 3 | #include <sys/socket.h> |
| 4 | #include <netinet/in.h> |
| 5 | |
| 6 | #include <osmocom/core/utils.h> |
| 7 | #include <osmocom/core/msgb.h> |
| 8 | #include <osmocom/core/write_queue.h> |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 9 | #include <osmocom/core/timer.h> |
Max | 5346f69 | 2022-07-28 14:19:22 +0700 | [diff] [blame] | 10 | #include <osmocom/smpp/smpp.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 | |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 16 | #define MODE_7BIT 7 |
| 17 | #define MODE_8BIT 8 |
| 18 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 19 | struct msc_a; |
| 20 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 21 | struct osmo_smpp_acl; |
| 22 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 23 | struct osmo_smpp_addr { |
| 24 | uint8_t ton; |
| 25 | uint8_t npi; |
| 26 | char addr[21+1]; |
| 27 | }; |
| 28 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 29 | /* struct wrapping ESME struct with additional SMSC-specific things like ACL, command list etc */ |
| 30 | struct smpp_esme { |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 31 | struct llist_head list; |
| 32 | struct smsc *smsc; |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 33 | struct esme *esme; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 34 | struct osmo_smpp_acl *acl; |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 35 | int use; |
| 36 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 37 | struct llist_head smpp_cmd_list; |
| 38 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 39 | uint8_t smpp_version; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 40 | uint8_t bind_flags; |
| 41 | }; |
| 42 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 43 | struct osmo_smpp_acl { |
| 44 | struct llist_head list; |
| 45 | struct smsc *smsc; |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 46 | struct smpp_esme *esme; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 47 | char *description; |
| 48 | char system_id[SMPP_SYS_ID_LEN+1]; |
| 49 | char passwd[SMPP_PASSWD_LEN+1]; |
| 50 | int default_route; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 51 | int deliver_src_imsi; |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 52 | int osmocom_ext; |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 53 | int dcs_transparent; |
Keith | c6d219c | 2019-01-17 01:01:59 +0100 | [diff] [blame] | 54 | int alert_notifications; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 55 | struct llist_head route_list; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 58 | enum osmo_smpp_rtype { |
| 59 | SMPP_ROUTE_NONE, |
| 60 | SMPP_ROUTE_PREFIX, |
| 61 | }; |
| 62 | |
| 63 | struct osmo_smpp_route { |
| 64 | struct llist_head list; /*!< in acl.route_list */ |
| 65 | struct llist_head global_list; /*!< in smsc->route_list */ |
| 66 | struct osmo_smpp_acl *acl; |
| 67 | enum osmo_smpp_rtype type; |
| 68 | union { |
| 69 | struct osmo_smpp_addr prefix; |
| 70 | } u; |
| 71 | }; |
| 72 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 73 | struct osmo_smpp_cmd { |
| 74 | struct llist_head list; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 75 | struct vlr_subscr *vsub; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 76 | uint32_t sequence_nr; |
Pablo Neira Ayuso | fdc9966 | 2017-08-07 14:01:10 +0100 | [diff] [blame] | 77 | uint32_t gsm411_msg_ref; |
| 78 | uint8_t gsm411_trans_id; |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 79 | bool is_report; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 80 | struct osmo_timer_list response_timer; |
| 81 | }; |
| 82 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 83 | struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct smpp_esme *esme, |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 84 | uint32_t sequence_number); |
| 85 | void smpp_cmd_ack(struct osmo_smpp_cmd *cmd); |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 86 | void smpp_cmd_err(struct osmo_smpp_cmd *cmd, uint32_t status); |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 87 | void smpp_cmd_flush_pending(struct smpp_esme *esme); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 88 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 89 | struct smsc { |
| 90 | struct osmo_fd listen_ofd; |
| 91 | struct llist_head esme_list; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 92 | struct llist_head acl_list; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 93 | struct llist_head route_list; |
Vadim Yanitskiy | 97b8e76 | 2021-10-26 00:39:11 +0300 | [diff] [blame] | 94 | char *bind_addr; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 95 | uint16_t listen_port; |
| 96 | char system_id[SMPP_SYS_ID_LEN+1]; |
| 97 | int accept_all; |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 98 | int smpp_first; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 99 | struct osmo_smpp_acl *def_route; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 100 | void *priv; |
| 101 | }; |
| 102 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 103 | int smpp_addr_eq(const struct osmo_smpp_addr *a, |
| 104 | const struct osmo_smpp_addr *b); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 105 | |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 106 | struct smsc *smpp_smsc_alloc_init(void *ctx); |
| 107 | int smpp_smsc_conf(struct smsc *smsc, const char *bind_addr, uint16_t port); |
| 108 | int smpp_smsc_start(struct smsc *smsc, const char *bind_addr, uint16_t port); |
| 109 | int smpp_smsc_restart(struct smsc *smsc, const char *bind_addr, uint16_t port); |
| 110 | void smpp_smsc_stop(struct smsc *smsc); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 111 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 112 | void smpp_esme_get(struct smpp_esme *esme); |
| 113 | void smpp_esme_put(struct smpp_esme *esme); |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 114 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 115 | int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct smpp_esme **emse); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 116 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 117 | struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id); |
| 118 | struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc, |
| 119 | const char *sys_id); |
| 120 | void smpp_acl_delete(struct osmo_smpp_acl *acl); |
| 121 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 122 | int smpp_tx_submit_r(struct smpp_esme *esme, uint32_t sequence_nr, |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 123 | uint32_t command_status, char *msg_id); |
| 124 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 125 | int smpp_tx_alert(struct smpp_esme *esme, uint8_t ton, uint8_t npi, |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 126 | const char *addr, uint8_t avail_status); |
| 127 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 128 | int smpp_tx_deliver(struct smpp_esme *esme, struct deliver_sm_t *deliver); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 129 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 130 | int handle_smpp_submit(struct smpp_esme *esme, struct submit_sm_t *submit, |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 131 | struct submit_sm_resp_t *submit_r); |
| 132 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 133 | int smpp_route_pfx_add(struct osmo_smpp_acl *acl, |
| 134 | const struct osmo_smpp_addr *pfx); |
| 135 | int smpp_route_pfx_del(struct osmo_smpp_acl *acl, |
| 136 | const struct osmo_smpp_addr *pfx); |
Holger Hans Peter Freyther | 5ecbc93 | 2013-07-27 18:39:30 +0200 | [diff] [blame] | 137 | |
| 138 | int smpp_vty_init(void); |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 139 | |
| 140 | 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] | 141 | |
Harald Welte | e6f1160 | 2022-05-17 18:25:14 +0200 | [diff] [blame] | 142 | time_t smpp_parse_time_format(const char *vp, time_t *t_now); |
Holger Hans Peter Freyther | e3c391e | 2015-07-06 16:40:01 +0200 | [diff] [blame] | 143 | |
| 144 | |
| 145 | struct gsm_sms; |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 146 | struct ran_conn; |
Holger Hans Peter Freyther | e3c391e | 2015-07-06 16:40:01 +0200 | [diff] [blame] | 147 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 148 | bool smpp_route_smpp_first(); |
| 149 | int smpp_try_deliver(struct gsm_sms *sms, struct msc_a *msc_a); |