blob: 4f6081fbaa4ddd1abb59cc3cec5b6ee6fd76c1e3 [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;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020022};
23
Harald Welte205e9032014-08-17 11:48:44 +020024struct ipa_server_link *
25ipa_server_link_create(void *ctx, struct e1inp_line *line, const char *addr,
26 uint16_t port,
27 int (*accept_cb)(struct ipa_server_link *link, int fd),
28 void *data);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020029void ipa_server_link_destroy(struct ipa_server_link *link);
30
31int ipa_server_link_open(struct ipa_server_link *link);
32void ipa_server_link_close(struct ipa_server_link *link);
33
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020034struct ipa_server_conn {
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020035 struct ipa_server_link *server;
36 struct osmo_fd ofd;
37 struct llist_head tx_queue;
Daniel Willmanna0d93312011-09-15 12:56:58 +020038 int (*closed_cb)(struct ipa_server_conn *peer);
Harald Welte12814b92016-04-28 07:54:31 +020039 int (*ccm_cb)(struct ipa_server_conn *peer, struct msgb *msg,
40 struct tlv_parsed *tlvp, struct ipaccess_unit *ud);
Pau Espin Pedrol082876b2018-08-28 17:53:38 +020041 /* 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 +020042 int (*cb)(struct ipa_server_conn *peer, struct msgb *msg);
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020043 void *data;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +020044 struct msgb *pending_msg;
Harald Welteb2d727a2016-04-28 07:53:49 +020045 /* remote address information */
46 const char *addr;
47 uint16_t port;
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020048};
49
Harald Welte205e9032014-08-17 11:48:44 +020050struct ipa_server_conn *
51ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd,
52 int (*cb)(struct ipa_server_conn *peer, struct msgb *msg),
53 int (*closed_cb)(struct ipa_server_conn *peer),
54 void *data);
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020055void ipa_server_conn_destroy(struct ipa_server_conn *peer);
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020056
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020057void ipa_server_conn_send(struct ipa_server_conn *peer, struct msgb *msg);
Harald Welte12814b92016-04-28 07:54:31 +020058int ipa_server_conn_ccm(struct ipa_server_conn *conn, struct msgb *msg);
Pablo Neira Ayusoaf3fed92011-06-23 20:42:19 +020059
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020060enum ipa_client_conn_state {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020061 IPA_CLIENT_LINK_STATE_NONE = 0,
62 IPA_CLIENT_LINK_STATE_CONNECTING = 1,
63 IPA_CLIENT_LINK_STATE_CONNECTED = 2,
64 IPA_CLIENT_LINK_STATE_MAX
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020065};
66
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020067struct ipa_client_conn {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020068 struct e1inp_line *line;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020069 struct osmo_fd *ofd;
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020070 struct llist_head tx_queue;
71 struct osmo_timer_list timer;
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020072 enum ipa_client_conn_state state;
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020073 const char *addr;
74 uint16_t port;
Harald Welte51de9ca2013-06-30 20:13:16 +020075 void (*updown_cb)(struct ipa_client_conn *link, int up);
Pau Espin Pedrol27757982018-08-28 17:32:29 +020076 /* 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 +020077 int (*read_cb)(struct ipa_client_conn *link, struct msgb *msg);
78 int (*write_cb)(struct ipa_client_conn *link);
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +020079 void *data;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +020080 struct msgb *pending_msg;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020081};
82
Harald Welte205e9032014-08-17 11:48:44 +020083struct ipa_client_conn *
84ipa_client_conn_create(void *ctx, struct e1inp_ts *ts, int priv_nr,
85 const char *addr, uint16_t port,
86 void (*updown)(struct ipa_client_conn *link, int),
87 int (*read_cb)(struct ipa_client_conn *link, struct msgb *msgb),
88 int (*write_cb)(struct ipa_client_conn *link),
89 void *data);
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020090void ipa_client_conn_destroy(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020091
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020092int ipa_client_conn_open(struct ipa_client_conn *link);
93void ipa_client_conn_close(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020094
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020095void ipa_client_conn_send(struct ipa_client_conn *link, struct msgb *msg);
Holger Hans Peter Freyther90878592015-01-18 17:50:05 +010096size_t ipa_client_conn_clear_queue(struct ipa_client_conn *link);
Pablo Neira Ayusoaf3fed92011-06-23 20:42:19 +020097
Harald Welte783715b2014-08-17 18:24:51 +020098int ipaccess_bts_handle_ccm(struct ipa_client_conn *link,
99 struct ipaccess_unit *dev, struct msgb *msg);
Harald Weltebc25bca2011-08-19 22:32:38 +0200100
Harald Welte3091e172014-08-18 14:53:05 +0200101void ipa_msg_push_header(struct msgb *msg, uint8_t proto);
Holger Hans Peter Freytherd67f3f02014-05-06 06:59:52 +0200102
Harald Welte3d60dbd2019-03-08 15:10:30 +0100103
104/***********************************************************************
105 * IPA Keep-Alive FSM
106 ***********************************************************************/
107
108/*! parameters describing the keep-alive FSM (timeouts). */
109struct ipa_keepalive_params {
110 /*! interval in which to send IPA CCM PING requests to the peer. */
111 unsigned int interval;
112 /*! time to wait for an IPA CCM PONG in response to a IPA CCM PING before giving up. */
113 unsigned int wait_for_resp;
114};
115
116typedef void ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn);
117
118struct osmo_fsm_inst *ipa_client_conn_alloc_keepalive_fsm(struct ipa_client_conn *client,
119 const struct ipa_keepalive_params *params,
120 const char *id);
121
122struct osmo_fsm_inst *ipa_server_conn_alloc_keepalive_fsm(struct ipa_server_conn *server,
123 const struct ipa_keepalive_params *params,
124 const char *id);
125
126struct osmo_fsm_inst *ipa_keepalive_alloc_server(struct ipa_server_conn *server,
127 const struct ipa_keepalive_params *params,
128 const char *id);
129
130void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb);
131
132void ipa_keepalive_fsm_start(struct osmo_fsm_inst *fi);
133
134void ipa_keepalive_fsm_stop(struct osmo_fsm_inst *fi);
135
136void ipa_keepalive_fsm_pong_received(struct osmo_fsm_inst *fi);
137
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200138#endif