blob: b353db0a4a8135ca18f082ec5a6db95b2a35c265 [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>
6
7enum mgcp_connection_mode;
8
9struct msgb;
10struct mgcpgw_client;
11struct 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;
27};
28
29struct mgcp_response_head {
30 int response_code;
31 mgcp_trans_id_t trans_id;
32 const char *comment;
33};
34
35struct mgcp_response {
36 char *body;
37 struct mgcp_response_head head;
38 uint16_t audio_port;
39};
40
41/* Invoked when an MGCP response is received or sending failed. When the
42 * response is passed as NULL, this indicates failure during transmission. */
43typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv);
44
45struct mgcp_response_pending {
46 struct llist_head entry;
47
48 mgcp_trans_id_t trans_id;
49 mgcp_response_cb_t response_cb;
50 void *priv;
51};
52
53
54void mgcpgw_client_conf_init(struct mgcpgw_client_conf *conf);
55
56struct mgcpgw_client *mgcpgw_client_init(void *ctx,
57 struct mgcpgw_client_conf *conf);
58int mgcpgw_client_connect(struct mgcpgw_client *mgcp);
59
60const char *mgcpgw_client_remote_addr_str(struct mgcpgw_client *mgcp);
61uint16_t mgcpgw_client_remote_port(struct mgcpgw_client *mgcp);
62uint32_t mgcpgw_client_remote_addr_n(struct mgcpgw_client *mgcp);
63
64unsigned int mgcpgw_client_next_endpoint(struct mgcpgw_client *client);
65
66int mgcp_response_parse_params(struct mgcp_response *r);
67
68int mgcpgw_client_tx(struct mgcpgw_client *mgcp, struct msgb *msg,
69 mgcp_response_cb_t response_cb, void *priv);
70
71struct msgb *mgcp_msg_crcx(struct mgcpgw_client *mgcp,
72 uint16_t rtp_endpoint, unsigned int call_id,
73 enum mgcp_connection_mode mode);
74
75struct msgb *mgcp_msg_mdcx(struct mgcpgw_client *mgcp,
76 uint16_t rtp_endpoint, const char *rtp_conn_addr,
77 uint16_t rtp_port, enum mgcp_connection_mode mode);
78
79void mgcpgw_client_vty_init(int node, struct mgcpgw_client_conf *conf);
80int mgcpgw_client_config_write(struct vty *vty, const char *indent);
81
82struct mgcp_response_pending * mgcpgw_client_pending_add(
83 struct mgcpgw_client *mgcp,
84 mgcp_trans_id_t trans_id,
85 mgcp_response_cb_t response_cb,
86 void *priv);
87int mgcpgw_client_rx(struct mgcpgw_client *mgcp, struct msgb *msg);