blob: be72a0c7caadd0bcd1d239e1a3e271a96d72c23e [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>
10
11#include <smpp34.h>
12#include <smpp34_structs.h>
13#include <smpp34_params.h>
14
Harald Welte338e3b32012-11-20 22:22:04 +010015#define SMPP_SYS_ID_LEN 16
16#define SMPP_PASSWD_LEN 16
17
Harald Weltef1033cc2012-11-08 16:14:37 +010018enum esme_read_state {
19 READ_ST_IN_LEN = 0,
20 READ_ST_IN_MSG = 1,
21};
22
Harald Welte338e3b32012-11-20 22:22:04 +010023struct osmo_smpp_acl;
24
Harald Weltee07b6a72012-11-23 19:02:37 +010025struct osmo_smpp_addr {
26 uint8_t ton;
27 uint8_t npi;
28 char addr[21+1];
29};
30
Harald Weltef1033cc2012-11-08 16:14:37 +010031struct osmo_esme {
32 struct llist_head list;
33 struct smsc *smsc;
Harald Welte338e3b32012-11-20 22:22:04 +010034 struct osmo_smpp_acl *acl;
Harald Weltee94db492012-11-08 20:11:05 +010035 int use;
36
Harald Welte8a1b0562012-11-09 12:51:44 +010037 uint32_t own_seq_nr;
38
Harald Weltef1033cc2012-11-08 16:14:37 +010039 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 Welte338e3b32012-11-20 22:22:04 +010049 char system_id[SMPP_SYS_ID_LEN+1];
Harald Weltef1033cc2012-11-08 16:14:37 +010050
51 uint8_t bind_flags;
52};
53
Harald Welte338e3b32012-11-20 22:22:04 +010054struct osmo_smpp_acl {
55 struct llist_head list;
56 struct smsc *smsc;
Harald Weltee07b6a72012-11-23 19:02:37 +010057 struct osmo_esme *esme;
Harald Welte338e3b32012-11-20 22:22:04 +010058 char *description;
59 char system_id[SMPP_SYS_ID_LEN+1];
60 char passwd[SMPP_PASSWD_LEN+1];
61 int default_route;
Harald Weltee07b6a72012-11-23 19:02:37 +010062 int deliver_src_imsi;
63 struct llist_head route_list;
Harald Welte338e3b32012-11-20 22:22:04 +010064};
65
Harald Weltee07b6a72012-11-23 19:02:37 +010066enum osmo_smpp_rtype {
67 SMPP_ROUTE_NONE,
68 SMPP_ROUTE_PREFIX,
69};
70
71struct osmo_smpp_route {
72 struct llist_head list; /*!< in acl.route_list */
73 struct llist_head global_list; /*!< in smsc->route_list */
74 struct osmo_smpp_acl *acl;
75 enum osmo_smpp_rtype type;
76 union {
77 struct osmo_smpp_addr prefix;
78 } u;
79};
80
81
Harald Weltef1033cc2012-11-08 16:14:37 +010082struct smsc {
83 struct osmo_fd listen_ofd;
84 struct llist_head esme_list;
Harald Welte338e3b32012-11-20 22:22:04 +010085 struct llist_head acl_list;
Harald Weltee07b6a72012-11-23 19:02:37 +010086 struct llist_head route_list;
Harald Welte338e3b32012-11-20 22:22:04 +010087 uint16_t listen_port;
88 char system_id[SMPP_SYS_ID_LEN+1];
89 int accept_all;
Harald Weltee07b6a72012-11-23 19:02:37 +010090 struct osmo_smpp_acl *def_route;
Harald Weltef1033cc2012-11-08 16:14:37 +010091 void *priv;
92};
93
Harald Weltee07b6a72012-11-23 19:02:37 +010094int smpp_addr_eq(const struct osmo_smpp_addr *a,
95 const struct osmo_smpp_addr *b);
Harald Weltef1033cc2012-11-08 16:14:37 +010096
97int smpp_smsc_init(struct smsc *smsc, uint16_t port);
98
Harald Weltee94db492012-11-08 20:11:05 +010099void smpp_esme_get(struct osmo_esme *esme);
100void smpp_esme_put(struct osmo_esme *esme);
101
Harald Weltee07b6a72012-11-23 19:02:37 +0100102struct osmo_esme *
103smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest);
104
Harald Welte338e3b32012-11-20 22:22:04 +0100105struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id);
106struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc,
107 const char *sys_id);
108void smpp_acl_delete(struct osmo_smpp_acl *acl);
109
Harald Welted4bdee72012-11-08 19:44:08 +0100110int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr,
111 uint32_t command_status, char *msg_id);
112
Harald Welte8a1b0562012-11-09 12:51:44 +0100113int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi,
114 const char *addr, uint8_t avail_status);
115
Harald Weltee07b6a72012-11-23 19:02:37 +0100116int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver);
117
Harald Weltef1033cc2012-11-08 16:14:37 +0100118int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
119 struct submit_sm_resp_t *submit_r);
120
Harald Weltee07b6a72012-11-23 19:02:37 +0100121int smpp_route_pfx_add(struct osmo_smpp_acl *acl,
122 const struct osmo_smpp_addr *pfx);
123int smpp_route_pfx_del(struct osmo_smpp_acl *acl,
124 const struct osmo_smpp_addr *pfx);
Harald Weltef1033cc2012-11-08 16:14:37 +0100125#endif