blob: 4caf656a6e0e7507133c1d4b9c5b3a1ade1413c4 [file] [log] [blame]
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +02001#pragma once
2
3#include <stdint.h>
Philipp Maier1dc6be62017-10-05 18:25:37 +02004#include <arpa/inet.h>
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +02005
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +02006#include <osmocom/mgcp_client/mgcp_common.h>
7
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +02008#define MGCP_CLIENT_LOCAL_ADDR_DEFAULT "0.0.0.0"
9#define MGCP_CLIENT_LOCAL_PORT_DEFAULT 0
10#define MGCP_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1"
11#define MGCP_CLIENT_REMOTE_PORT_DEFAULT 2427
12
13struct msgb;
14struct vty;
15struct mgcp_client;
16
17struct mgcp_client_conf {
18 const char *local_addr;
19 int local_port;
20 const char *remote_addr;
21 int remote_port;
22 uint16_t first_endpoint;
23 uint16_t last_endpoint;
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +000024 uint16_t bts_base;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020025};
26
27typedef unsigned int mgcp_trans_id_t;
28
29struct mgcp_response_head {
Philipp Maieread2f602017-11-27 12:06:29 +010030 int response_code;
31 mgcp_trans_id_t trans_id;
32 const char *comment;
Philipp Maier01d24a32017-11-21 17:26:09 +010033 char conn_id[MGCP_CONN_ID_LENGTH];
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020034};
35
36struct mgcp_response {
37 char *body;
38 struct mgcp_response_head head;
39 uint16_t audio_port;
Philipp Maier06da85e2017-10-05 18:49:24 +020040 char audio_ip[INET_ADDRSTRLEN];
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020041};
42
Philipp Maier1dc6be62017-10-05 18:25:37 +020043enum mgcp_verb {
44 MGCP_VERB_CRCX,
45 MGCP_VERB_MDCX,
46 MGCP_VERB_DLCX,
47 MGCP_VERB_AUEP,
48 MGCP_VERB_RSIP,
49};
50
51#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
52#define MGCP_MSG_PRESENCE_CALL_ID 0x0002
53#define MGCP_MSG_PRESENCE_CONN_ID 0x0004
54#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
55#define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010
56#define MGCP_MSG_PRESENCE_CONN_MODE 0x0020
57
58/* See also RFC3435 section 3.2.1.3 */
59#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
60
61struct mgcp_msg {
62 enum mgcp_verb verb;
63 /* See MGCP_MSG_PRESENCE_* constants */
64 uint32_t presence;
65 char endpoint[MGCP_ENDPOINT_MAXLEN];
66 unsigned int call_id;
Philipp Maier01d24a32017-11-21 17:26:09 +010067 char *conn_id;
Harald Welte9bf7c532017-11-17 14:14:31 +010068 uint16_t audio_port;
69 char *audio_ip;
Philipp Maier1dc6be62017-10-05 18:25:37 +020070 enum mgcp_connection_mode conn_mode;
71};
72
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020073void mgcp_client_conf_init(struct mgcp_client_conf *conf);
74void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf);
75int mgcp_client_config_write(struct vty *vty, const char *indent);
76struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp);
77
78struct mgcp_client *mgcp_client_init(void *ctx,
79 struct mgcp_client_conf *conf);
80int mgcp_client_connect(struct mgcp_client *mgcp);
81
82const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp);
83uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp);
84uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp);
85
86int mgcp_client_next_endpoint(struct mgcp_client *client);
87void mgcp_client_release_endpoint(uint16_t id, struct mgcp_client *client);
88
89/* Invoked when an MGCP response is received or sending failed. When the
90 * response is passed as NULL, this indicates failure during transmission. */
91typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv);
92int mgcp_response_parse_params(struct mgcp_response *r);
93
94int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg,
95 mgcp_response_cb_t response_cb, void *priv);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +010096int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020097
98enum mgcp_connection_mode;
99
100struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
101 uint16_t rtp_endpoint, unsigned int call_id,
Philipp Maier1dc6be62017-10-05 18:25:37 +0200102 enum mgcp_connection_mode mode)
103OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200104
105struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
106 uint16_t rtp_endpoint, const char *rtp_conn_addr,
Philipp Maier1dc6be62017-10-05 18:25:37 +0200107 uint16_t rtp_port, enum mgcp_connection_mode mode)
108OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200109
110struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
Philipp Maier1dc6be62017-10-05 18:25:37 +0200111 unsigned int call_id)
112OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
113
114struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100115mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg);
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +0200116
117extern const struct value_string mgcp_client_connection_mode_strs[];
118static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode)
119{
120 return get_value_string(mgcp_client_connection_mode_strs, mode);
121}