blob: b1b5fd42b9ea8c573df08bf319e2915bd58c903a [file] [log] [blame]
Neels Hofmeyr84da6b12016-05-20 21:59:55 +02001#pragma once
2
3#include <stdint.h>
4
5#include <osmocom/core/linuxlist.h>
Philipp Maierfbf66102017-04-09 12:32:51 +02006#include <osmocom/core/write_queue.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +02007
8enum mgcp_connection_mode;
9
10struct msgb;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020011struct vty;
12
13#define MGCPGW_CLIENT_LOCAL_ADDR_DEFAULT "0.0.0.0"
14#define MGCPGW_CLIENT_LOCAL_PORT_DEFAULT 0
15#define MGCPGW_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1"
16#define MGCPGW_CLIENT_REMOTE_PORT_DEFAULT 2427
17
18#define MSGB_CB_MGCP_TRANS_ID 0
19
20typedef unsigned int mgcp_trans_id_t;
21
22struct mgcpgw_client_conf {
23 const char *local_addr;
24 int local_port;
25 const char *remote_addr;
26 int remote_port;
Philipp Maierfbf66102017-04-09 12:32:51 +020027 uint16_t first_endpoint;
28 uint16_t last_endpoint;
29 uint16_t bts_base;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020030};
31
32struct mgcp_response_head {
33 int response_code;
34 mgcp_trans_id_t trans_id;
35 const char *comment;
36};
37
38struct mgcp_response {
39 char *body;
40 struct mgcp_response_head head;
41 uint16_t audio_port;
42};
43
Philipp Maierfbf66102017-04-09 12:32:51 +020044struct mgcpgw_client {
45 struct mgcpgw_client_conf actual;
46 uint32_t remote_addr;
47 struct osmo_wqueue wq;
48 mgcp_trans_id_t next_trans_id;
49 struct llist_head responses_pending;
50 struct llist_head inuse_endpoints;
51};
52
53struct mgcp_inuse_endpoint {
54 struct llist_head entry;
55 uint16_t id;
56};
57
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020058/* Invoked when an MGCP response is received or sending failed. When the
59 * response is passed as NULL, this indicates failure during transmission. */
60typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv);
61
62struct mgcp_response_pending {
63 struct llist_head entry;
64
65 mgcp_trans_id_t trans_id;
66 mgcp_response_cb_t response_cb;
67 void *priv;
68};
69
70
71void mgcpgw_client_conf_init(struct mgcpgw_client_conf *conf);
72
73struct mgcpgw_client *mgcpgw_client_init(void *ctx,
74 struct mgcpgw_client_conf *conf);
75int mgcpgw_client_connect(struct mgcpgw_client *mgcp);
76
77const char *mgcpgw_client_remote_addr_str(struct mgcpgw_client *mgcp);
78uint16_t mgcpgw_client_remote_port(struct mgcpgw_client *mgcp);
79uint32_t mgcpgw_client_remote_addr_n(struct mgcpgw_client *mgcp);
80
Philipp Maierfbf66102017-04-09 12:32:51 +020081/* Find and seize an unsused endpoint id */
82int mgcpgw_client_next_endpoint(struct mgcpgw_client *client);
83
84/* Release a seized endpoint id to make it available again for other calls */
85void mgcpgw_client_release_endpoint(uint16_t id, struct mgcpgw_client *client);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020086
87int mgcp_response_parse_params(struct mgcp_response *r);
88
89int mgcpgw_client_tx(struct mgcpgw_client *mgcp, struct msgb *msg,
90 mgcp_response_cb_t response_cb, void *priv);
91
92struct msgb *mgcp_msg_crcx(struct mgcpgw_client *mgcp,
93 uint16_t rtp_endpoint, unsigned int call_id,
94 enum mgcp_connection_mode mode);
95
96struct msgb *mgcp_msg_mdcx(struct mgcpgw_client *mgcp,
97 uint16_t rtp_endpoint, const char *rtp_conn_addr,
98 uint16_t rtp_port, enum mgcp_connection_mode mode);
99
Philipp Maierfbf66102017-04-09 12:32:51 +0200100struct msgb *mgcp_msg_dlcx(struct mgcpgw_client *mgcp, uint16_t rtp_endpoint,
101 unsigned int call_id);
102
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200103void mgcpgw_client_vty_init(int node, struct mgcpgw_client_conf *conf);
104int mgcpgw_client_config_write(struct vty *vty, const char *indent);
105
106struct mgcp_response_pending * mgcpgw_client_pending_add(
107 struct mgcpgw_client *mgcp,
108 mgcp_trans_id_t trans_id,
109 mgcp_response_cb_t response_cb,
110 void *priv);
111int mgcpgw_client_rx(struct mgcpgw_client *mgcp, struct msgb *msg);