blob: 7e13a6dff42e8367fbf0956f503d8a17b475949d [file] [log] [blame]
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001#ifndef _OSMO_IPA_H_
2#define _OSMO_IPA_H_
3
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +02004#include <stdint.h>
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02005#include <osmocom/core/linuxlist.h>
6#include <osmocom/core/timer.h>
Jacob Erlbeck1acf4cb2014-12-22 11:14:34 +01007#include <osmocom/core/select.h>
Harald Welte3d60dbd2019-03-08 15:10:30 +01008#include <osmocom/core/fsm.h>
Harald Welteb65f58f2014-08-20 22:04:11 +02009#include <osmocom/gsm/ipa.h>
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020010
Jacob Erlbeck1acf4cb2014-12-22 11:14:34 +010011struct e1inp_line;
12struct e1inp_ts;
13struct msgb;
14
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020015struct ipa_server_link {
16 struct e1inp_line *line;
17 struct osmo_fd ofd;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020018 const char *addr;
19 uint16_t port;
20 int (*accept_cb)(struct ipa_server_link *link, int fd);
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +020021 void *data;
Harald Welte6bcc32b2021-04-28 14:40:59 +020022 uint8_t dscp;
23 uint8_t priority;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020024};
25
Harald Welte205e9032014-08-17 11:48:44 +020026struct ipa_server_link *
27ipa_server_link_create(void *ctx, struct e1inp_line *line, const char *addr,
28 uint16_t port,
29 int (*accept_cb)(struct ipa_server_link *link, int fd),
30 void *data);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020031void ipa_server_link_destroy(struct ipa_server_link *link);
32
33int ipa_server_link_open(struct ipa_server_link *link);
34void ipa_server_link_close(struct ipa_server_link *link);
35
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020036struct ipa_server_conn {
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020037 struct ipa_server_link *server;
38 struct osmo_fd ofd;
39 struct llist_head tx_queue;
Daniel Willmanna0d93312011-09-15 12:56:58 +020040 int (*closed_cb)(struct ipa_server_conn *peer);
Harald Welte12814b92016-04-28 07:54:31 +020041 int (*ccm_cb)(struct ipa_server_conn *peer, struct msgb *msg,
42 struct tlv_parsed *tlvp, struct ipaccess_unit *ud);
Pau Espin Pedrol082876b2018-08-28 17:53:38 +020043 /* Callback when ofd has something to be read. -EBADF must be returned if the osmo_fd is destroyed. */
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020044 int (*cb)(struct ipa_server_conn *peer, struct msgb *msg);
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020045 void *data;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +020046 struct msgb *pending_msg;
Harald Welteb2d727a2016-04-28 07:53:49 +020047 /* remote address information */
48 const char *addr;
49 uint16_t port;
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020050};
51
Harald Welte205e9032014-08-17 11:48:44 +020052struct ipa_server_conn *
53ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd,
54 int (*cb)(struct ipa_server_conn *peer, struct msgb *msg),
55 int (*closed_cb)(struct ipa_server_conn *peer),
56 void *data);
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020057void ipa_server_conn_destroy(struct ipa_server_conn *peer);
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020058
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020059void ipa_server_conn_send(struct ipa_server_conn *peer, struct msgb *msg);
Harald Welte12814b92016-04-28 07:54:31 +020060int ipa_server_conn_ccm(struct ipa_server_conn *conn, struct msgb *msg);
Pablo Neira Ayusoaf3fed92011-06-23 20:42:19 +020061
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020062enum ipa_client_conn_state {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020063 IPA_CLIENT_LINK_STATE_NONE = 0,
64 IPA_CLIENT_LINK_STATE_CONNECTING = 1,
65 IPA_CLIENT_LINK_STATE_CONNECTED = 2,
66 IPA_CLIENT_LINK_STATE_MAX
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020067};
68
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020069struct ipa_client_conn {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020070 struct e1inp_line *line;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020071 struct osmo_fd *ofd;
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020072 struct llist_head tx_queue;
73 struct osmo_timer_list timer;
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020074 enum ipa_client_conn_state state;
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020075 const char *addr;
76 uint16_t port;
Harald Welte51de9ca2013-06-30 20:13:16 +020077 void (*updown_cb)(struct ipa_client_conn *link, int up);
Pau Espin Pedrol27757982018-08-28 17:32:29 +020078 /* Callback when ofd has something to be read. -EBADF must be returned if the osmo_fd is destroyed. */
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020079 int (*read_cb)(struct ipa_client_conn *link, struct msgb *msg);
80 int (*write_cb)(struct ipa_client_conn *link);
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +020081 void *data;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +020082 struct msgb *pending_msg;
Pau Espin Pedrolb6e28bf2019-11-08 17:30:28 +010083 const char *local_addr;
84 uint16_t local_port;
Harald Welte6bcc32b2021-04-28 14:40:59 +020085 uint8_t dscp;
86 uint8_t priority;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020087};
88
Harald Welte205e9032014-08-17 11:48:44 +020089struct ipa_client_conn *
90ipa_client_conn_create(void *ctx, struct e1inp_ts *ts, int priv_nr,
91 const char *addr, uint16_t port,
92 void (*updown)(struct ipa_client_conn *link, int),
93 int (*read_cb)(struct ipa_client_conn *link, struct msgb *msgb),
94 int (*write_cb)(struct ipa_client_conn *link),
Pau Espin Pedrolb6e28bf2019-11-08 17:30:28 +010095 void *data) OSMO_DEPRECATED("Use ipa_client_conn_create2() instead");
96struct ipa_client_conn *
97ipa_client_conn_create2(void *ctx, struct e1inp_ts *ts,
98 int priv_nr, const char *loc_addr, uint16_t loc_port,
99 const char *rem_addr, uint16_t rem_port,
100 void (*updown_cb)(struct ipa_client_conn *link, int up),
101 int (*read_cb)(struct ipa_client_conn *link,
102 struct msgb *msgb),
103 int (*write_cb)(struct ipa_client_conn *link),
104 void *data);
Pablo Neira Ayusof0995672011-09-08 12:58:38 +0200105void ipa_client_conn_destroy(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200106
Pablo Neira Ayusof0995672011-09-08 12:58:38 +0200107int ipa_client_conn_open(struct ipa_client_conn *link);
108void ipa_client_conn_close(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200109
Pablo Neira Ayusof0995672011-09-08 12:58:38 +0200110void ipa_client_conn_send(struct ipa_client_conn *link, struct msgb *msg);
Holger Hans Peter Freyther90878592015-01-18 17:50:05 +0100111size_t ipa_client_conn_clear_queue(struct ipa_client_conn *link);
Pablo Neira Ayusoaf3fed92011-06-23 20:42:19 +0200112
Harald Welte783715b2014-08-17 18:24:51 +0200113int ipaccess_bts_handle_ccm(struct ipa_client_conn *link,
114 struct ipaccess_unit *dev, struct msgb *msg);
Harald Weltebc25bca2011-08-19 22:32:38 +0200115
Harald Welte3091e172014-08-18 14:53:05 +0200116void ipa_msg_push_header(struct msgb *msg, uint8_t proto);
Holger Hans Peter Freytherd67f3f02014-05-06 06:59:52 +0200117
Harald Welte3d60dbd2019-03-08 15:10:30 +0100118
119/***********************************************************************
120 * IPA Keep-Alive FSM
121 ***********************************************************************/
122
123/*! parameters describing the keep-alive FSM (timeouts). */
124struct ipa_keepalive_params {
125 /*! interval in which to send IPA CCM PING requests to the peer. */
126 unsigned int interval;
127 /*! time to wait for an IPA CCM PONG in response to a IPA CCM PING before giving up. */
128 unsigned int wait_for_resp;
129};
130
Eric Wild51b61002019-07-09 13:48:06 +0200131typedef int ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn);
132
133typedef void ipa_keepalive_send_cb_t(struct osmo_fsm_inst *fi, void *conn, struct msgb *msg);
Harald Welte3d60dbd2019-03-08 15:10:30 +0100134
135struct osmo_fsm_inst *ipa_client_conn_alloc_keepalive_fsm(struct ipa_client_conn *client,
136 const struct ipa_keepalive_params *params,
137 const char *id);
138
139struct osmo_fsm_inst *ipa_server_conn_alloc_keepalive_fsm(struct ipa_server_conn *server,
140 const struct ipa_keepalive_params *params,
141 const char *id);
142
Eric Wild51b61002019-07-09 13:48:06 +0200143struct osmo_fsm_inst *ipa_generic_conn_alloc_keepalive_fsm(void *ctx, void* data,
144 const struct ipa_keepalive_params *params,
145 const char *id);
Harald Welte3d60dbd2019-03-08 15:10:30 +0100146
147void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb);
148
Eric Wild51b61002019-07-09 13:48:06 +0200149void ipa_keepalive_fsm_set_send_cb(struct osmo_fsm_inst *fi, ipa_keepalive_send_cb_t *fn);
150
Harald Welte3d60dbd2019-03-08 15:10:30 +0100151void ipa_keepalive_fsm_start(struct osmo_fsm_inst *fi);
152
153void ipa_keepalive_fsm_stop(struct osmo_fsm_inst *fi);
154
155void ipa_keepalive_fsm_pong_received(struct osmo_fsm_inst *fi);
156
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200157#endif