blob: 79f20780f8284c79489f835e78943652bc95da9b [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
Philipp Maieraf8e00f2018-07-27 16:04:41 +02008/* See also: RFC 3435, chapter 3.5 Transmission over UDP */
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +02009#define MGCP_CLIENT_LOCAL_ADDR_DEFAULT "0.0.0.0"
Philipp Maieraf8e00f2018-07-27 16:04:41 +020010#define MGCP_CLIENT_LOCAL_PORT_DEFAULT 2727
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020011#define MGCP_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1"
12#define MGCP_CLIENT_REMOTE_PORT_DEFAULT 2427
13
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020014#define MGCP_CLIENT_MGW_STR "Configure MGCP connection to Media Gateway\n"
15
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020016struct msgb;
17struct vty;
18struct mgcp_client;
19
20struct mgcp_client_conf {
21 const char *local_addr;
22 int local_port;
23 const char *remote_addr;
24 int remote_port;
25 uint16_t first_endpoint;
26 uint16_t last_endpoint;
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +000027 uint16_t bts_base;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020028};
29
30typedef unsigned int mgcp_trans_id_t;
31
Philipp Maier704c4f02018-06-07 18:51:31 +020032/*! Enumeration of the codec types that mgcp_client is able to handle. */
33enum mgcp_codecs {
34 CODEC_PCMU_8000_1 = 0,
35 CODEC_GSM_8000_1 = 3,
36 CODEC_PCMA_8000_1 = 8,
37 CODEC_G729_8000_1 = 18,
38 CODEC_GSMEFR_8000_1 = 110,
39 CODEC_GSMHR_8000_1 = 111,
40 CODEC_AMR_8000_1 = 112,
41 CODEC_AMRWB_16000_1 = 113,
42};
43/* Note: when new codec types are added, the corresponding value strings
44 * in mgcp_client.c (codec_table) must be updated as well. Enumerations
45 * in enum mgcp_codecs must correspond to a valid payload type. However,
46 * this is an internal assumption that is made to avoid lookup tables.
47 * The API-User should not rely on this coincidence! */
48
49/*! Structure to build a payload type map to allow the defiition custom payload
50 * types. */
51struct ptmap {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020052 /*! codec for which a payload type number should be defined */
Philipp Maier704c4f02018-06-07 18:51:31 +020053 enum mgcp_codecs codec;
54
Neels Hofmeyr8838c622018-06-26 00:05:53 +020055 /*! payload type number (96-127) */
Philipp Maier704c4f02018-06-07 18:51:31 +020056 unsigned int pt;
57};
58
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020059struct mgcp_response_head {
Philipp Maieread2f602017-11-27 12:06:29 +010060 int response_code;
61 mgcp_trans_id_t trans_id;
Philipp Maierabe8c892018-01-20 00:15:12 +010062 char comment[MGCP_COMMENT_MAXLEN];
Neels Hofmeyr55e0dcf2018-09-03 21:36:56 +020063 char conn_id[MGCP_CONN_ID_MAXLEN];
Philipp Maier55295f72018-01-15 14:00:28 +010064 char endpoint[MGCP_ENDPOINT_MAXLEN];
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020065};
66
67struct mgcp_response {
68 char *body;
69 struct mgcp_response_head head;
70 uint16_t audio_port;
Philipp Maier06da85e2017-10-05 18:49:24 +020071 char audio_ip[INET_ADDRSTRLEN];
Philipp Maier704c4f02018-06-07 18:51:31 +020072 unsigned int ptime;
73 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
74 unsigned int codecs_len;
75 struct ptmap ptmap[MGCP_MAX_CODECS];
76 unsigned int ptmap_len;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020077};
78
Philipp Maier1dc6be62017-10-05 18:25:37 +020079enum mgcp_verb {
80 MGCP_VERB_CRCX,
81 MGCP_VERB_MDCX,
82 MGCP_VERB_DLCX,
83 MGCP_VERB_AUEP,
84 MGCP_VERB_RSIP,
85};
86
87#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
88#define MGCP_MSG_PRESENCE_CALL_ID 0x0002
89#define MGCP_MSG_PRESENCE_CONN_ID 0x0004
90#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
91#define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010
92#define MGCP_MSG_PRESENCE_CONN_MODE 0x0020
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020093#define MGCP_MSG_PRESENCE_X_OSMO_IGN 0x8000
Philipp Maier1dc6be62017-10-05 18:25:37 +020094
Philipp Maier1dc6be62017-10-05 18:25:37 +020095struct mgcp_msg {
96 enum mgcp_verb verb;
97 /* See MGCP_MSG_PRESENCE_* constants */
98 uint32_t presence;
99 char endpoint[MGCP_ENDPOINT_MAXLEN];
100 unsigned int call_id;
Philipp Maier01d24a32017-11-21 17:26:09 +0100101 char *conn_id;
Harald Welte9bf7c532017-11-17 14:14:31 +0100102 uint16_t audio_port;
103 char *audio_ip;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200104 enum mgcp_connection_mode conn_mode;
Philipp Maier704c4f02018-06-07 18:51:31 +0200105 unsigned int ptime;
106 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
107 unsigned int codecs_len;
108 struct ptmap ptmap[MGCP_MAX_CODECS];
109 unsigned int ptmap_len;
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200110 uint32_t x_osmo_ign;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200111};
112
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200113void mgcp_client_conf_init(struct mgcp_client_conf *conf);
114void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf);
115int mgcp_client_config_write(struct vty *vty, const char *indent);
116struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp);
117
118struct mgcp_client *mgcp_client_init(void *ctx,
119 struct mgcp_client_conf *conf);
120int mgcp_client_connect(struct mgcp_client *mgcp);
121
122const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp);
123uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp);
124uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp);
125
126int mgcp_client_next_endpoint(struct mgcp_client *client);
127void mgcp_client_release_endpoint(uint16_t id, struct mgcp_client *client);
128
129/* Invoked when an MGCP response is received or sending failed. When the
130 * response is passed as NULL, this indicates failure during transmission. */
131typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv);
132int mgcp_response_parse_params(struct mgcp_response *r);
133
134int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg,
135 mgcp_response_cb_t response_cb, void *priv);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100136int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200137
138enum mgcp_connection_mode;
139
140struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
141 uint16_t rtp_endpoint, unsigned int call_id,
Philipp Maier1dc6be62017-10-05 18:25:37 +0200142 enum mgcp_connection_mode mode)
143OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200144
145struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
146 uint16_t rtp_endpoint, const char *rtp_conn_addr,
Philipp Maier1dc6be62017-10-05 18:25:37 +0200147 uint16_t rtp_port, enum mgcp_connection_mode mode)
148OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200149
150struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
Philipp Maier1dc6be62017-10-05 18:25:37 +0200151 unsigned int call_id)
152OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
153
154struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100155mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg);
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +0200156
157extern const struct value_string mgcp_client_connection_mode_strs[];
158static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode)
159{
160 return get_value_string(mgcp_client_connection_mode_strs, mode);
161}
Philipp Maier704c4f02018-06-07 18:51:31 +0200162
163enum mgcp_codecs map_str_to_codec(const char *str);
164unsigned int map_codec_to_pt(struct ptmap *ptmap, unsigned int ptmap_len,
165 enum mgcp_codecs codec);
166enum mgcp_codecs map_pt_to_codec(struct ptmap *ptmap, unsigned int ptmap_len,
167 unsigned int pt);