blob: 4764a95772ee104f44e64ac8a26149b11bdb3f95 [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;
Pau Espin Pedrolb6e28bf2019-11-08 17:30:28 +010081 const char *local_addr;
82 uint16_t local_port;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020083};
84
Harald Welte205e9032014-08-17 11:48:44 +020085struct ipa_client_conn *
86ipa_client_conn_create(void *ctx, struct e1inp_ts *ts, int priv_nr,
87 const char *addr, uint16_t port,
88 void (*updown)(struct ipa_client_conn *link, int),
89 int (*read_cb)(struct ipa_client_conn *link, struct msgb *msgb),
90 int (*write_cb)(struct ipa_client_conn *link),
Pau Espin Pedrolb6e28bf2019-11-08 17:30:28 +010091 void *data) OSMO_DEPRECATED("Use ipa_client_conn_create2() instead");
92struct ipa_client_conn *
93ipa_client_conn_create2(void *ctx, struct e1inp_ts *ts,
94 int priv_nr, const char *loc_addr, uint16_t loc_port,
95 const char *rem_addr, uint16_t rem_port,
96 void (*updown_cb)(struct ipa_client_conn *link, int up),
97 int (*read_cb)(struct ipa_client_conn *link,
98 struct msgb *msgb),
99 int (*write_cb)(struct ipa_client_conn *link),
100 void *data);
Pablo Neira Ayusof0995672011-09-08 12:58:38 +0200101void ipa_client_conn_destroy(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200102
Pablo Neira Ayusof0995672011-09-08 12:58:38 +0200103int ipa_client_conn_open(struct ipa_client_conn *link);
104void ipa_client_conn_close(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200105
Pablo Neira Ayusof0995672011-09-08 12:58:38 +0200106void ipa_client_conn_send(struct ipa_client_conn *link, struct msgb *msg);
Holger Hans Peter Freyther90878592015-01-18 17:50:05 +0100107size_t ipa_client_conn_clear_queue(struct ipa_client_conn *link);
Pablo Neira Ayusoaf3fed92011-06-23 20:42:19 +0200108
Harald Welte783715b2014-08-17 18:24:51 +0200109int ipaccess_bts_handle_ccm(struct ipa_client_conn *link,
110 struct ipaccess_unit *dev, struct msgb *msg);
Harald Weltebc25bca2011-08-19 22:32:38 +0200111
Harald Welte3091e172014-08-18 14:53:05 +0200112void ipa_msg_push_header(struct msgb *msg, uint8_t proto);
Holger Hans Peter Freytherd67f3f02014-05-06 06:59:52 +0200113
Harald Welte3d60dbd2019-03-08 15:10:30 +0100114
115/***********************************************************************
116 * IPA Keep-Alive FSM
117 ***********************************************************************/
118
119/*! parameters describing the keep-alive FSM (timeouts). */
120struct ipa_keepalive_params {
121 /*! interval in which to send IPA CCM PING requests to the peer. */
122 unsigned int interval;
123 /*! time to wait for an IPA CCM PONG in response to a IPA CCM PING before giving up. */
124 unsigned int wait_for_resp;
125};
126
Eric Wild51b61002019-07-09 13:48:06 +0200127typedef int ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn);
128
129typedef void ipa_keepalive_send_cb_t(struct osmo_fsm_inst *fi, void *conn, struct msgb *msg);
Harald Welte3d60dbd2019-03-08 15:10:30 +0100130
131struct osmo_fsm_inst *ipa_client_conn_alloc_keepalive_fsm(struct ipa_client_conn *client,
132 const struct ipa_keepalive_params *params,
133 const char *id);
134
135struct osmo_fsm_inst *ipa_server_conn_alloc_keepalive_fsm(struct ipa_server_conn *server,
136 const struct ipa_keepalive_params *params,
137 const char *id);
138
Eric Wild51b61002019-07-09 13:48:06 +0200139struct osmo_fsm_inst *ipa_generic_conn_alloc_keepalive_fsm(void *ctx, void* data,
140 const struct ipa_keepalive_params *params,
141 const char *id);
Harald Welte3d60dbd2019-03-08 15:10:30 +0100142
143void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb);
144
Eric Wild51b61002019-07-09 13:48:06 +0200145void ipa_keepalive_fsm_set_send_cb(struct osmo_fsm_inst *fi, ipa_keepalive_send_cb_t *fn);
146
Harald Welte3d60dbd2019-03-08 15:10:30 +0100147void ipa_keepalive_fsm_start(struct osmo_fsm_inst *fi);
148
149void ipa_keepalive_fsm_stop(struct osmo_fsm_inst *fi);
150
151void ipa_keepalive_fsm_pong_received(struct osmo_fsm_inst *fi);
152
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200153#endif