Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1 | #ifndef _OSMO_IPA_H_ |
| 2 | #define _OSMO_IPA_H_ |
| 3 | |
Pablo Neira Ayuso | 9b3a33c | 2011-06-21 13:52:41 +0200 | [diff] [blame] | 4 | #include <stdint.h> |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 5 | #include <osmocom/core/linuxlist.h> |
| 6 | #include <osmocom/core/timer.h> |
Jacob Erlbeck | 1acf4cb | 2014-12-22 11:14:34 +0100 | [diff] [blame] | 7 | #include <osmocom/core/select.h> |
Harald Welte | 3d60dbd | 2019-03-08 15:10:30 +0100 | [diff] [blame] | 8 | #include <osmocom/core/fsm.h> |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 9 | #include <osmocom/gsm/ipa.h> |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 10 | |
Jacob Erlbeck | 1acf4cb | 2014-12-22 11:14:34 +0100 | [diff] [blame] | 11 | struct e1inp_line; |
| 12 | struct e1inp_ts; |
| 13 | struct msgb; |
| 14 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 15 | struct ipa_server_link { |
| 16 | struct e1inp_line *line; |
| 17 | struct osmo_fd ofd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 18 | const char *addr; |
| 19 | uint16_t port; |
| 20 | int (*accept_cb)(struct ipa_server_link *link, int fd); |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 21 | void *data; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 22 | }; |
| 23 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 24 | struct ipa_server_link * |
| 25 | ipa_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 Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 29 | void ipa_server_link_destroy(struct ipa_server_link *link); |
| 30 | |
| 31 | int ipa_server_link_open(struct ipa_server_link *link); |
| 32 | void ipa_server_link_close(struct ipa_server_link *link); |
| 33 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 34 | struct ipa_server_conn { |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 35 | struct ipa_server_link *server; |
| 36 | struct osmo_fd ofd; |
| 37 | struct llist_head tx_queue; |
Daniel Willmann | a0d9331 | 2011-09-15 12:56:58 +0200 | [diff] [blame] | 38 | int (*closed_cb)(struct ipa_server_conn *peer); |
Harald Welte | 12814b9 | 2016-04-28 07:54:31 +0200 | [diff] [blame] | 39 | int (*ccm_cb)(struct ipa_server_conn *peer, struct msgb *msg, |
| 40 | struct tlv_parsed *tlvp, struct ipaccess_unit *ud); |
Pau Espin Pedrol | 082876b | 2018-08-28 17:53:38 +0200 | [diff] [blame] | 41 | /* Callback when ofd has something to be read. -EBADF must be returned if the osmo_fd is destroyed. */ |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 42 | int (*cb)(struct ipa_server_conn *peer, struct msgb *msg); |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 43 | void *data; |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 44 | struct msgb *pending_msg; |
Harald Welte | b2d727a | 2016-04-28 07:53:49 +0200 | [diff] [blame] | 45 | /* remote address information */ |
| 46 | const char *addr; |
| 47 | uint16_t port; |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 50 | struct ipa_server_conn * |
| 51 | ipa_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 Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 55 | void ipa_server_conn_destroy(struct ipa_server_conn *peer); |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 56 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 57 | void ipa_server_conn_send(struct ipa_server_conn *peer, struct msgb *msg); |
Harald Welte | 12814b9 | 2016-04-28 07:54:31 +0200 | [diff] [blame] | 58 | int ipa_server_conn_ccm(struct ipa_server_conn *conn, struct msgb *msg); |
Pablo Neira Ayuso | af3fed9 | 2011-06-23 20:42:19 +0200 | [diff] [blame] | 59 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 60 | enum ipa_client_conn_state { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 61 | 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 Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 67 | struct ipa_client_conn { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 68 | struct e1inp_line *line; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 69 | struct osmo_fd *ofd; |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 70 | struct llist_head tx_queue; |
| 71 | struct osmo_timer_list timer; |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 72 | enum ipa_client_conn_state state; |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 73 | const char *addr; |
| 74 | uint16_t port; |
Harald Welte | 51de9ca | 2013-06-30 20:13:16 +0200 | [diff] [blame] | 75 | void (*updown_cb)(struct ipa_client_conn *link, int up); |
Pau Espin Pedrol | 2775798 | 2018-08-28 17:32:29 +0200 | [diff] [blame] | 76 | /* Callback when ofd has something to be read. -EBADF must be returned if the osmo_fd is destroyed. */ |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 77 | int (*read_cb)(struct ipa_client_conn *link, struct msgb *msg); |
| 78 | int (*write_cb)(struct ipa_client_conn *link); |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 79 | void *data; |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 80 | struct msgb *pending_msg; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 83 | struct ipa_client_conn * |
| 84 | ipa_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 Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 90 | void ipa_client_conn_destroy(struct ipa_client_conn *link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 91 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 92 | int ipa_client_conn_open(struct ipa_client_conn *link); |
| 93 | void ipa_client_conn_close(struct ipa_client_conn *link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 94 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 95 | void ipa_client_conn_send(struct ipa_client_conn *link, struct msgb *msg); |
Holger Hans Peter Freyther | 9087859 | 2015-01-18 17:50:05 +0100 | [diff] [blame] | 96 | size_t ipa_client_conn_clear_queue(struct ipa_client_conn *link); |
Pablo Neira Ayuso | af3fed9 | 2011-06-23 20:42:19 +0200 | [diff] [blame] | 97 | |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 98 | int ipaccess_bts_handle_ccm(struct ipa_client_conn *link, |
| 99 | struct ipaccess_unit *dev, struct msgb *msg); |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 100 | |
Harald Welte | 3091e17 | 2014-08-18 14:53:05 +0200 | [diff] [blame] | 101 | void ipa_msg_push_header(struct msgb *msg, uint8_t proto); |
Holger Hans Peter Freyther | d67f3f0 | 2014-05-06 06:59:52 +0200 | [diff] [blame] | 102 | |
Harald Welte | 3d60dbd | 2019-03-08 15:10:30 +0100 | [diff] [blame] | 103 | |
| 104 | /*********************************************************************** |
| 105 | * IPA Keep-Alive FSM |
| 106 | ***********************************************************************/ |
| 107 | |
| 108 | /*! parameters describing the keep-alive FSM (timeouts). */ |
| 109 | struct 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 | |
| 116 | typedef void ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn); |
| 117 | |
| 118 | struct 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 | |
| 122 | struct 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 | |
| 126 | struct osmo_fsm_inst *ipa_keepalive_alloc_server(struct ipa_server_conn *server, |
| 127 | const struct ipa_keepalive_params *params, |
| 128 | const char *id); |
| 129 | |
| 130 | void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb); |
| 131 | |
| 132 | void ipa_keepalive_fsm_start(struct osmo_fsm_inst *fi); |
| 133 | |
| 134 | void ipa_keepalive_fsm_stop(struct osmo_fsm_inst *fi); |
| 135 | |
| 136 | void ipa_keepalive_fsm_pong_received(struct osmo_fsm_inst *fi); |
| 137 | |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 138 | #endif |