blob: ac3e2b1be3de8383def75d78e4ba49fd8dbb679f [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;
Neels Hofmeyrac69ea92018-12-19 00:27:50 +010025
26 /* By default, we are always addressing the MGW with e.g. 'rtpbridge/123@mgw'.
27 * If this is nonempty, the contained name will be used instead of 'mgw'. */
28 char endpoint_domain_name[MGCP_ENDPOINT_MAXLEN];
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020029};
30
31typedef unsigned int mgcp_trans_id_t;
32
Philipp Maier704c4f02018-06-07 18:51:31 +020033/*! Enumeration of the codec types that mgcp_client is able to handle. */
34enum mgcp_codecs {
35 CODEC_PCMU_8000_1 = 0,
36 CODEC_GSM_8000_1 = 3,
37 CODEC_PCMA_8000_1 = 8,
38 CODEC_G729_8000_1 = 18,
39 CODEC_GSMEFR_8000_1 = 110,
Philipp Maierdbe09dd2019-03-07 13:48:12 +010040 CODEC_GSMHR_8000_1 = 111,
Philipp Maier704c4f02018-06-07 18:51:31 +020041 CODEC_AMR_8000_1 = 112,
42 CODEC_AMRWB_16000_1 = 113,
43};
44/* Note: when new codec types are added, the corresponding value strings
45 * in mgcp_client.c (codec_table) must be updated as well. Enumerations
46 * in enum mgcp_codecs must correspond to a valid payload type. However,
47 * this is an internal assumption that is made to avoid lookup tables.
48 * The API-User should not rely on this coincidence! */
49
Neels Hofmeyr47642f22019-02-27 05:56:53 +010050extern const struct value_string osmo_mgcpc_codec_names[];
51static inline const char *osmo_mgcpc_codec_name(enum mgcp_codecs val)
52{ return get_value_string(osmo_mgcpc_codec_names, val); }
53
Philipp Maier704c4f02018-06-07 18:51:31 +020054/*! Structure to build a payload type map to allow the defiition custom payload
55 * types. */
56struct ptmap {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020057 /*! codec for which a payload type number should be defined */
Philipp Maier704c4f02018-06-07 18:51:31 +020058 enum mgcp_codecs codec;
59
Neels Hofmeyr8838c622018-06-26 00:05:53 +020060 /*! payload type number (96-127) */
Philipp Maier704c4f02018-06-07 18:51:31 +020061 unsigned int pt;
62};
63
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020064struct mgcp_response_head {
Philipp Maieread2f602017-11-27 12:06:29 +010065 int response_code;
66 mgcp_trans_id_t trans_id;
Philipp Maierabe8c892018-01-20 00:15:12 +010067 char comment[MGCP_COMMENT_MAXLEN];
Neels Hofmeyr55e0dcf2018-09-03 21:36:56 +020068 char conn_id[MGCP_CONN_ID_MAXLEN];
Philipp Maier55295f72018-01-15 14:00:28 +010069 char endpoint[MGCP_ENDPOINT_MAXLEN];
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020070};
71
72struct mgcp_response {
73 char *body;
74 struct mgcp_response_head head;
75 uint16_t audio_port;
Philipp Maier06da85e2017-10-05 18:49:24 +020076 char audio_ip[INET_ADDRSTRLEN];
Philipp Maier704c4f02018-06-07 18:51:31 +020077 unsigned int ptime;
78 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
79 unsigned int codecs_len;
80 struct ptmap ptmap[MGCP_MAX_CODECS];
Philipp Maier228e5912019-03-05 13:56:59 +010081 unsigned int ptmap_len;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020082};
83
Philipp Maier1dc6be62017-10-05 18:25:37 +020084enum mgcp_verb {
85 MGCP_VERB_CRCX,
86 MGCP_VERB_MDCX,
87 MGCP_VERB_DLCX,
88 MGCP_VERB_AUEP,
89 MGCP_VERB_RSIP,
90};
91
92#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
93#define MGCP_MSG_PRESENCE_CALL_ID 0x0002
94#define MGCP_MSG_PRESENCE_CONN_ID 0x0004
95#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
96#define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010
97#define MGCP_MSG_PRESENCE_CONN_MODE 0x0020
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020098#define MGCP_MSG_PRESENCE_X_OSMO_IGN 0x8000
Philipp Maier1dc6be62017-10-05 18:25:37 +020099
Philipp Maier1dc6be62017-10-05 18:25:37 +0200100struct mgcp_msg {
101 enum mgcp_verb verb;
102 /* See MGCP_MSG_PRESENCE_* constants */
103 uint32_t presence;
104 char endpoint[MGCP_ENDPOINT_MAXLEN];
105 unsigned int call_id;
Philipp Maier01d24a32017-11-21 17:26:09 +0100106 char *conn_id;
Harald Welte9bf7c532017-11-17 14:14:31 +0100107 uint16_t audio_port;
108 char *audio_ip;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200109 enum mgcp_connection_mode conn_mode;
Philipp Maier704c4f02018-06-07 18:51:31 +0200110 unsigned int ptime;
111 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
112 unsigned int codecs_len;
113 struct ptmap ptmap[MGCP_MAX_CODECS];
114 unsigned int ptmap_len;
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200115 uint32_t x_osmo_ign;
Philipp Maier228e5912019-03-05 13:56:59 +0100116 bool param_present;
117 struct mgcp_codec_param param;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200118};
119
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200120void mgcp_client_conf_init(struct mgcp_client_conf *conf);
121void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf);
122int mgcp_client_config_write(struct vty *vty, const char *indent);
123struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp);
124
125struct mgcp_client *mgcp_client_init(void *ctx,
126 struct mgcp_client_conf *conf);
127int mgcp_client_connect(struct mgcp_client *mgcp);
128
129const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp);
130uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp);
131uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp);
132
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100133const char *mgcp_client_endpoint_domain(const struct mgcp_client *mgcp);
134const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp);
135
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200136/* Invoked when an MGCP response is received or sending failed. When the
137 * response is passed as NULL, this indicates failure during transmission. */
138typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv);
139int mgcp_response_parse_params(struct mgcp_response *r);
140
141int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg,
142 mgcp_response_cb_t response_cb, void *priv);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100143int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200144
145enum mgcp_connection_mode;
146
Philipp Maier1dc6be62017-10-05 18:25:37 +0200147struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100148mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg);
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +0200149
150extern const struct value_string mgcp_client_connection_mode_strs[];
151static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode)
152{
153 return get_value_string(mgcp_client_connection_mode_strs, mode);
154}
Philipp Maier704c4f02018-06-07 18:51:31 +0200155
156enum mgcp_codecs map_str_to_codec(const char *str);
157unsigned int map_codec_to_pt(struct ptmap *ptmap, unsigned int ptmap_len,
158 enum mgcp_codecs codec);
159enum mgcp_codecs map_pt_to_codec(struct ptmap *ptmap, unsigned int ptmap_len,
160 unsigned int pt);