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> |
| 10 | |
| 11 | #include <smpp34.h> |
| 12 | #include <smpp34_structs.h> |
| 13 | #include <smpp34_params.h> |
| 14 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 15 | #define SMPP_SYS_ID_LEN 16 |
| 16 | #define SMPP_PASSWD_LEN 16 |
| 17 | |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 18 | #define MODE_7BIT 7 |
| 19 | #define MODE_8BIT 8 |
| 20 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 21 | enum esme_read_state { |
| 22 | READ_ST_IN_LEN = 0, |
| 23 | READ_ST_IN_MSG = 1, |
| 24 | }; |
| 25 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 26 | struct osmo_smpp_acl; |
| 27 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 28 | struct osmo_smpp_addr { |
| 29 | uint8_t ton; |
| 30 | uint8_t npi; |
| 31 | char addr[21+1]; |
| 32 | }; |
| 33 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 34 | struct osmo_esme { |
| 35 | struct llist_head list; |
| 36 | struct smsc *smsc; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 37 | struct osmo_smpp_acl *acl; |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 38 | int use; |
| 39 | |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 40 | uint32_t own_seq_nr; |
| 41 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 42 | struct osmo_wqueue wqueue; |
| 43 | struct sockaddr_storage sa; |
| 44 | socklen_t sa_len; |
| 45 | |
| 46 | enum esme_read_state read_state; |
| 47 | uint32_t read_len; |
| 48 | uint32_t read_idx; |
| 49 | struct msgb *read_msg; |
| 50 | |
| 51 | uint8_t smpp_version; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 52 | char system_id[SMPP_SYS_ID_LEN+1]; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 53 | |
| 54 | uint8_t bind_flags; |
| 55 | }; |
| 56 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 57 | struct osmo_smpp_acl { |
| 58 | struct llist_head list; |
| 59 | struct smsc *smsc; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 60 | struct osmo_esme *esme; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 61 | char *description; |
| 62 | char system_id[SMPP_SYS_ID_LEN+1]; |
| 63 | char passwd[SMPP_PASSWD_LEN+1]; |
| 64 | int default_route; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 65 | int deliver_src_imsi; |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 66 | int osmocom_ext; |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 67 | int dcs_transparent; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 68 | struct llist_head route_list; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 71 | enum osmo_smpp_rtype { |
| 72 | SMPP_ROUTE_NONE, |
| 73 | SMPP_ROUTE_PREFIX, |
| 74 | }; |
| 75 | |
| 76 | struct osmo_smpp_route { |
| 77 | struct llist_head list; /*!< in acl.route_list */ |
| 78 | struct llist_head global_list; /*!< in smsc->route_list */ |
| 79 | struct osmo_smpp_acl *acl; |
| 80 | enum osmo_smpp_rtype type; |
| 81 | union { |
| 82 | struct osmo_smpp_addr prefix; |
| 83 | } u; |
| 84 | }; |
| 85 | |
| 86 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 87 | struct smsc { |
| 88 | struct osmo_fd listen_ofd; |
| 89 | struct llist_head esme_list; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 90 | struct llist_head acl_list; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 91 | struct llist_head route_list; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 92 | uint16_t listen_port; |
| 93 | char system_id[SMPP_SYS_ID_LEN+1]; |
| 94 | int accept_all; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 95 | struct osmo_smpp_acl *def_route; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 96 | void *priv; |
| 97 | }; |
| 98 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 99 | int smpp_addr_eq(const struct osmo_smpp_addr *a, |
| 100 | const struct osmo_smpp_addr *b); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 101 | |
| 102 | int smpp_smsc_init(struct smsc *smsc, uint16_t port); |
| 103 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 104 | void smpp_esme_get(struct osmo_esme *esme); |
| 105 | void smpp_esme_put(struct osmo_esme *esme); |
| 106 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 107 | struct osmo_esme * |
| 108 | smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest); |
| 109 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 110 | struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id); |
| 111 | struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc, |
| 112 | const char *sys_id); |
| 113 | void smpp_acl_delete(struct osmo_smpp_acl *acl); |
| 114 | |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 115 | int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr, |
| 116 | uint32_t command_status, char *msg_id); |
| 117 | |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 118 | int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi, |
| 119 | const char *addr, uint8_t avail_status); |
| 120 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 121 | int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver); |
| 122 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 123 | int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit, |
| 124 | struct submit_sm_resp_t *submit_r); |
| 125 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 126 | int smpp_route_pfx_add(struct osmo_smpp_acl *acl, |
| 127 | const struct osmo_smpp_addr *pfx); |
| 128 | int smpp_route_pfx_del(struct osmo_smpp_acl *acl, |
| 129 | const struct osmo_smpp_addr *pfx); |
Holger Hans Peter Freyther | 5ecbc93 | 2013-07-27 18:39:30 +0200 | [diff] [blame] | 130 | |
| 131 | int smpp_vty_init(void); |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 132 | |
| 133 | int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 134 | #endif |