blob: bc34ca3fa5d8e1b78044f2ddd94e51eb997028a3 [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>
7
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02008struct ipa_server_link {
9 struct e1inp_line *line;
10 struct osmo_fd ofd;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020011 const char *addr;
12 uint16_t port;
13 int (*accept_cb)(struct ipa_server_link *link, int fd);
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +020014 void *data;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +020015};
16
Harald Welte205e9032014-08-17 11:48:44 +020017struct ipa_server_link *
18ipa_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 Ayuso986191f2011-06-21 19:56:26 +020022void ipa_server_link_destroy(struct ipa_server_link *link);
23
24int ipa_server_link_open(struct ipa_server_link *link);
25void ipa_server_link_close(struct ipa_server_link *link);
26
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020027struct ipa_server_conn {
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020028 struct ipa_server_link *server;
29 struct osmo_fd ofd;
30 struct llist_head tx_queue;
Daniel Willmanna0d93312011-09-15 12:56:58 +020031 int (*closed_cb)(struct ipa_server_conn *peer);
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020032 int (*cb)(struct ipa_server_conn *peer, struct msgb *msg);
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020033 void *data;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +020034 struct msgb *pending_msg;
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020035};
36
Harald Welte205e9032014-08-17 11:48:44 +020037struct ipa_server_conn *
38ipa_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 Ayusof0995672011-09-08 12:58:38 +020042void ipa_server_conn_destroy(struct ipa_server_conn *peer);
Pablo Neira Ayuso6af9b612011-06-23 14:07:47 +020043
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020044void ipa_server_conn_send(struct ipa_server_conn *peer, struct msgb *msg);
Pablo Neira Ayusoaf3fed92011-06-23 20:42:19 +020045
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020046enum ipa_client_conn_state {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020047 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 Ayuso96e81282011-06-09 15:06:11 +020051};
52
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020053struct ipa_client_conn {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020054 struct e1inp_line *line;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020055 struct osmo_fd *ofd;
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020056 struct llist_head tx_queue;
57 struct osmo_timer_list timer;
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020058 enum ipa_client_conn_state state;
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +020059 const char *addr;
60 uint16_t port;
Harald Welte51de9ca2013-06-30 20:13:16 +020061 void (*updown_cb)(struct ipa_client_conn *link, int up);
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020062 int (*read_cb)(struct ipa_client_conn *link, struct msgb *msg);
63 int (*write_cb)(struct ipa_client_conn *link);
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +020064 void *data;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +020065 struct msgb *pending_msg;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020066};
67
Harald Welte205e9032014-08-17 11:48:44 +020068struct ipa_client_conn *
69ipa_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 Ayusof0995672011-09-08 12:58:38 +020075void ipa_client_conn_destroy(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020076
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020077int ipa_client_conn_open(struct ipa_client_conn *link);
78void ipa_client_conn_close(struct ipa_client_conn *link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020079
Pablo Neira Ayusof0995672011-09-08 12:58:38 +020080void ipa_client_conn_send(struct ipa_client_conn *link, struct msgb *msg);
Pablo Neira Ayusoaf3fed92011-06-23 20:42:19 +020081
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020082int ipa_msg_recv(int fd, struct msgb **rmsg);
Jacob Erlbeck98af3c32014-03-31 10:53:32 +020083int ipa_msg_recv_buffered(int fd, struct msgb **rmsg, struct msgb **tmp_msg);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020084
Harald Weltebc25bca2011-08-19 22:32:38 +020085int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd);
86
Holger Hans Peter Freytherd67f3f02014-05-06 06:59:52 +020087void ipaccess_prepend_header(struct msgb *msg, int proto);
88void ipaccess_prepend_header_ext(struct msgb *msg, int proto);
89
Harald Welte3091e172014-08-18 14:53:05 +020090void ipa_msg_push_header(struct msgb *msg, uint8_t proto);
Holger Hans Peter Freytherd67f3f02014-05-06 06:59:52 +020091
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020092#endif