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; |
Harald Welte | 6bcc32b | 2021-04-28 14:40:59 +0200 | [diff] [blame] | 22 | uint8_t dscp; |
| 23 | uint8_t priority; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 24 | }; |
| 25 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 26 | struct ipa_server_link * |
| 27 | ipa_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 Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 31 | void ipa_server_link_destroy(struct ipa_server_link *link); |
| 32 | |
| 33 | int ipa_server_link_open(struct ipa_server_link *link); |
| 34 | void ipa_server_link_close(struct ipa_server_link *link); |
| 35 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 36 | struct ipa_server_conn { |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 37 | struct ipa_server_link *server; |
| 38 | struct osmo_fd ofd; |
| 39 | struct llist_head tx_queue; |
Daniel Willmann | a0d9331 | 2011-09-15 12:56:58 +0200 | [diff] [blame] | 40 | int (*closed_cb)(struct ipa_server_conn *peer); |
Harald Welte | 12814b9 | 2016-04-28 07:54:31 +0200 | [diff] [blame] | 41 | int (*ccm_cb)(struct ipa_server_conn *peer, struct msgb *msg, |
| 42 | struct tlv_parsed *tlvp, struct ipaccess_unit *ud); |
Pau Espin Pedrol | 082876b | 2018-08-28 17:53:38 +0200 | [diff] [blame] | 43 | /* 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] | 44 | int (*cb)(struct ipa_server_conn *peer, struct msgb *msg); |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 45 | void *data; |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 46 | struct msgb *pending_msg; |
Harald Welte | b2d727a | 2016-04-28 07:53:49 +0200 | [diff] [blame] | 47 | /* remote address information */ |
| 48 | const char *addr; |
| 49 | uint16_t port; |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 52 | struct ipa_server_conn * |
| 53 | ipa_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 Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 57 | void ipa_server_conn_destroy(struct ipa_server_conn *peer); |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 58 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 59 | 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] | 60 | 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] | 61 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 62 | enum ipa_client_conn_state { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 63 | 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 Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 69 | struct ipa_client_conn { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 70 | struct e1inp_line *line; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 71 | struct osmo_fd *ofd; |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 72 | struct llist_head tx_queue; |
| 73 | struct osmo_timer_list timer; |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 74 | enum ipa_client_conn_state state; |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 75 | const char *addr; |
| 76 | uint16_t port; |
Harald Welte | 51de9ca | 2013-06-30 20:13:16 +0200 | [diff] [blame] | 77 | void (*updown_cb)(struct ipa_client_conn *link, int up); |
Pau Espin Pedrol | 2775798 | 2018-08-28 17:32:29 +0200 | [diff] [blame] | 78 | /* 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] | 79 | int (*read_cb)(struct ipa_client_conn *link, struct msgb *msg); |
| 80 | int (*write_cb)(struct ipa_client_conn *link); |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 81 | void *data; |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 82 | struct msgb *pending_msg; |
Pau Espin Pedrol | b6e28bf | 2019-11-08 17:30:28 +0100 | [diff] [blame] | 83 | const char *local_addr; |
| 84 | uint16_t local_port; |
Harald Welte | 6bcc32b | 2021-04-28 14:40:59 +0200 | [diff] [blame] | 85 | uint8_t dscp; |
| 86 | uint8_t priority; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 87 | }; |
| 88 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 89 | struct ipa_client_conn * |
| 90 | ipa_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 Pedrol | b6e28bf | 2019-11-08 17:30:28 +0100 | [diff] [blame] | 95 | void *data) OSMO_DEPRECATED("Use ipa_client_conn_create2() instead"); |
| 96 | struct ipa_client_conn * |
| 97 | ipa_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 Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 105 | void ipa_client_conn_destroy(struct ipa_client_conn *link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 106 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 107 | int ipa_client_conn_open(struct ipa_client_conn *link); |
| 108 | void ipa_client_conn_close(struct ipa_client_conn *link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 109 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 110 | 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] | 111 | 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] | 112 | |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 113 | int ipaccess_bts_handle_ccm(struct ipa_client_conn *link, |
| 114 | struct ipaccess_unit *dev, struct msgb *msg); |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 115 | |
Harald Welte | 3091e17 | 2014-08-18 14:53:05 +0200 | [diff] [blame] | 116 | 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] | 117 | |
Harald Welte | 3d60dbd | 2019-03-08 15:10:30 +0100 | [diff] [blame] | 118 | |
| 119 | /*********************************************************************** |
| 120 | * IPA Keep-Alive FSM |
| 121 | ***********************************************************************/ |
| 122 | |
| 123 | /*! parameters describing the keep-alive FSM (timeouts). */ |
| 124 | struct 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 Wild | 51b6100 | 2019-07-09 13:48:06 +0200 | [diff] [blame] | 131 | typedef int ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn); |
| 132 | |
| 133 | typedef void ipa_keepalive_send_cb_t(struct osmo_fsm_inst *fi, void *conn, struct msgb *msg); |
Harald Welte | 3d60dbd | 2019-03-08 15:10:30 +0100 | [diff] [blame] | 134 | |
| 135 | struct 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 | |
| 139 | struct 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 Wild | 51b6100 | 2019-07-09 13:48:06 +0200 | [diff] [blame] | 143 | struct 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 Welte | 3d60dbd | 2019-03-08 15:10:30 +0100 | [diff] [blame] | 146 | |
| 147 | void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb); |
| 148 | |
Eric Wild | 51b6100 | 2019-07-09 13:48:06 +0200 | [diff] [blame] | 149 | void ipa_keepalive_fsm_set_send_cb(struct osmo_fsm_inst *fi, ipa_keepalive_send_cb_t *fn); |
| 150 | |
Harald Welte | 3d60dbd | 2019-03-08 15:10:30 +0100 | [diff] [blame] | 151 | void ipa_keepalive_fsm_start(struct osmo_fsm_inst *fi); |
| 152 | |
| 153 | void ipa_keepalive_fsm_stop(struct osmo_fsm_inst *fi); |
| 154 | |
| 155 | void ipa_keepalive_fsm_pong_received(struct osmo_fsm_inst *fi); |
| 156 | |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 157 | #endif |