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