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> |
| 7 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 8 | struct ipa_server_link { |
| 9 | struct e1inp_line *line; |
| 10 | struct osmo_fd ofd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 11 | const char *addr; |
| 12 | uint16_t port; |
| 13 | int (*accept_cb)(struct ipa_server_link *link, int fd); |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 14 | void *data; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 15 | }; |
| 16 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 17 | struct ipa_server_link * |
| 18 | ipa_server_link_create(void *ctx, struct e1inp_line *line, const char *addr, |
| 19 | uint16_t port, |
| 20 | int (*accept_cb)(struct ipa_server_link *link, int fd), |
| 21 | void *data); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 22 | void ipa_server_link_destroy(struct ipa_server_link *link); |
| 23 | |
| 24 | int ipa_server_link_open(struct ipa_server_link *link); |
| 25 | void ipa_server_link_close(struct ipa_server_link *link); |
| 26 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 27 | struct ipa_server_conn { |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 28 | struct ipa_server_link *server; |
| 29 | struct osmo_fd ofd; |
| 30 | struct llist_head tx_queue; |
Daniel Willmann | a0d9331 | 2011-09-15 12:56:58 +0200 | [diff] [blame] | 31 | int (*closed_cb)(struct ipa_server_conn *peer); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 32 | int (*cb)(struct ipa_server_conn *peer, struct msgb *msg); |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 33 | void *data; |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 34 | struct msgb *pending_msg; |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 37 | struct ipa_server_conn * |
| 38 | ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd, |
| 39 | int (*cb)(struct ipa_server_conn *peer, struct msgb *msg), |
| 40 | int (*closed_cb)(struct ipa_server_conn *peer), |
| 41 | void *data); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 42 | void ipa_server_conn_destroy(struct ipa_server_conn *peer); |
Pablo Neira Ayuso | 6af9b61 | 2011-06-23 14:07:47 +0200 | [diff] [blame] | 43 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 44 | void ipa_server_conn_send(struct ipa_server_conn *peer, struct msgb *msg); |
Pablo Neira Ayuso | af3fed9 | 2011-06-23 20:42:19 +0200 | [diff] [blame] | 45 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 46 | enum ipa_client_conn_state { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 47 | IPA_CLIENT_LINK_STATE_NONE = 0, |
| 48 | IPA_CLIENT_LINK_STATE_CONNECTING = 1, |
| 49 | IPA_CLIENT_LINK_STATE_CONNECTED = 2, |
| 50 | IPA_CLIENT_LINK_STATE_MAX |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 53 | struct ipa_client_conn { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 54 | struct e1inp_line *line; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 55 | struct osmo_fd *ofd; |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 56 | struct llist_head tx_queue; |
| 57 | struct osmo_timer_list timer; |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 58 | enum ipa_client_conn_state state; |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 59 | const char *addr; |
| 60 | uint16_t port; |
Harald Welte | 51de9ca | 2013-06-30 20:13:16 +0200 | [diff] [blame] | 61 | void (*updown_cb)(struct ipa_client_conn *link, int up); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 62 | int (*read_cb)(struct ipa_client_conn *link, struct msgb *msg); |
| 63 | int (*write_cb)(struct ipa_client_conn *link); |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 64 | void *data; |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 65 | struct msgb *pending_msg; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Harald Welte | 205e903 | 2014-08-17 11:48:44 +0200 | [diff] [blame] | 68 | struct ipa_client_conn * |
| 69 | ipa_client_conn_create(void *ctx, struct e1inp_ts *ts, int priv_nr, |
| 70 | const char *addr, uint16_t port, |
| 71 | void (*updown)(struct ipa_client_conn *link, int), |
| 72 | int (*read_cb)(struct ipa_client_conn *link, struct msgb *msgb), |
| 73 | int (*write_cb)(struct ipa_client_conn *link), |
| 74 | void *data); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 75 | void ipa_client_conn_destroy(struct ipa_client_conn *link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 76 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 77 | int ipa_client_conn_open(struct ipa_client_conn *link); |
| 78 | void ipa_client_conn_close(struct ipa_client_conn *link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 79 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 80 | void ipa_client_conn_send(struct ipa_client_conn *link, struct msgb *msg); |
Pablo Neira Ayuso | af3fed9 | 2011-06-23 20:42:19 +0200 | [diff] [blame] | 81 | |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 82 | int ipa_msg_recv(int fd, struct msgb **rmsg); |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 83 | int ipa_msg_recv_buffered(int fd, struct msgb **rmsg, struct msgb **tmp_msg); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 84 | |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 85 | int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd); |
| 86 | |
Holger Hans Peter Freyther | d67f3f0 | 2014-05-06 06:59:52 +0200 | [diff] [blame] | 87 | void ipaccess_prepend_header(struct msgb *msg, int proto); |
| 88 | void ipaccess_prepend_header_ext(struct msgb *msg, int proto); |
| 89 | |
Harald Welte | 3091e17 | 2014-08-18 14:53:05 +0200 | [diff] [blame] | 90 | 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] | 91 | |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 92 | #endif |