blob: 46ec21087b309d9c0e2cead7135b4a54846cce66 [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
Pau Espin Pedrol8e8d59f2023-06-13 19:41:44 +02006#include <osmocom/mgcp_client/defs.h>
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +02007#include <osmocom/mgcp_client/mgcp_common.h>
8
Philipp Maieraf8e00f2018-07-27 16:04:41 +02009/* See also: RFC 3435, chapter 3.5 Transmission over UDP */
Pau Espin Pedrolee2f33b2020-08-31 19:36:31 +020010#define MGCP_CLIENT_LOCAL_ADDR_DEFAULT NULL /* INADDR(6)_ANY */
Pau Espin Pedrol8e74c632022-10-17 19:20:45 +020011#define MGCP_CLIENT_LOCAL_PORT_DEFAULT 0
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020012#define MGCP_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1"
13#define MGCP_CLIENT_REMOTE_PORT_DEFAULT 2427
14
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020015#define MGCP_CLIENT_MGW_STR "Configure MGCP connection to Media Gateway\n"
16
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020017struct msgb;
18struct vty;
19struct mgcp_client;
20
21struct mgcp_client_conf {
22 const char *local_addr;
23 int local_port;
24 const char *remote_addr;
25 int remote_port;
Neels Hofmeyrac69ea92018-12-19 00:27:50 +010026
27 /* By default, we are always addressing the MGW with e.g. 'rtpbridge/123@mgw'.
28 * If this is nonempty, the contained name will be used instead of 'mgw'. */
29 char endpoint_domain_name[MGCP_ENDPOINT_MAXLEN];
Philipp Maier3f2c15f2021-07-22 11:53:07 +020030
31 /* The user may configure certain endpoint names that are reset via DLCX
32 * on startup. Usually this will be one wildcarded endpoint e.g.
33 * 'rtpbridge/(wildcard)' or a number of specific E1 like e.g.
34 * 'ds/e1-0/s-3/su16-4' */
35 struct llist_head reset_epnames;
Philipp Maierdf9192e2021-09-03 17:50:51 +020036
37 /* human readable name / description */
38 char *description;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020039};
40
41typedef unsigned int mgcp_trans_id_t;
42
Philipp Maier704c4f02018-06-07 18:51:31 +020043/*! Enumeration of the codec types that mgcp_client is able to handle. */
44enum mgcp_codecs {
45 CODEC_PCMU_8000_1 = 0,
46 CODEC_GSM_8000_1 = 3,
47 CODEC_PCMA_8000_1 = 8,
48 CODEC_G729_8000_1 = 18,
Philipp Maier14da3a32023-05-23 12:03:16 +020049 CODEC_GSMEFR_8000_1 = 110, /* 3GPP TS 48.103 table 5.4.2.2.1 */
50 CODEC_GSMHR_8000_1 = 111, /* 3GPP TS 48.103 table 5.4.2.2.1 */
51 CODEC_AMR_8000_1 = 112, /* 3GPP TS 48.103 table 5.4.2.2.1 */
52 CODEC_AMRWB_16000_1 = 113, /* 3GPP TS 48.103 table 5.4.2.2.1 */
Philipp Maier1de5ed62021-12-21 14:38:14 +010053 CODEC_IUFP = 96,
Philipp Maier14da3a32023-05-23 12:03:16 +020054 CODEC_CLEARMODE = 120, /* 3GPP TS 48.103 table 5.4.2.2.1 */
Philipp Maier704c4f02018-06-07 18:51:31 +020055};
56/* Note: when new codec types are added, the corresponding value strings
57 * in mgcp_client.c (codec_table) must be updated as well. Enumerations
58 * in enum mgcp_codecs must correspond to a valid payload type. However,
59 * this is an internal assumption that is made to avoid lookup tables.
60 * The API-User should not rely on this coincidence! */
61
Neels Hofmeyr47642f22019-02-27 05:56:53 +010062extern const struct value_string osmo_mgcpc_codec_names[];
63static inline const char *osmo_mgcpc_codec_name(enum mgcp_codecs val)
64{ return get_value_string(osmo_mgcpc_codec_names, val); }
65
Philipp Maier704c4f02018-06-07 18:51:31 +020066/*! Structure to build a payload type map to allow the defiition custom payload
67 * types. */
68struct ptmap {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020069 /*! codec for which a payload type number should be defined */
Philipp Maier704c4f02018-06-07 18:51:31 +020070 enum mgcp_codecs codec;
71
Neels Hofmeyr8838c622018-06-26 00:05:53 +020072 /*! payload type number (96-127) */
Philipp Maier704c4f02018-06-07 18:51:31 +020073 unsigned int pt;
74};
75
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020076struct mgcp_response_head {
Philipp Maieread2f602017-11-27 12:06:29 +010077 int response_code;
78 mgcp_trans_id_t trans_id;
Philipp Maierabe8c892018-01-20 00:15:12 +010079 char comment[MGCP_COMMENT_MAXLEN];
Neels Hofmeyr55e0dcf2018-09-03 21:36:56 +020080 char conn_id[MGCP_CONN_ID_MAXLEN];
Philipp Maier55295f72018-01-15 14:00:28 +010081 char endpoint[MGCP_ENDPOINT_MAXLEN];
Pau Espin Pedrol91088c32019-04-24 21:02:40 +020082 bool x_osmo_osmux_use;
83 uint8_t x_osmo_osmux_cid;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020084};
85
86struct mgcp_response {
87 char *body;
88 struct mgcp_response_head head;
89 uint16_t audio_port;
Pau Espin Pedrol8667d512020-08-28 19:37:08 +020090 char audio_ip[INET6_ADDRSTRLEN];
Philipp Maier704c4f02018-06-07 18:51:31 +020091 unsigned int ptime;
92 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
93 unsigned int codecs_len;
94 struct ptmap ptmap[MGCP_MAX_CODECS];
Philipp Maier228e5912019-03-05 13:56:59 +010095 unsigned int ptmap_len;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020096};
97
Philipp Maier1dc6be62017-10-05 18:25:37 +020098enum mgcp_verb {
99 MGCP_VERB_CRCX,
100 MGCP_VERB_MDCX,
101 MGCP_VERB_DLCX,
102 MGCP_VERB_AUEP,
103 MGCP_VERB_RSIP,
104};
105
106#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
107#define MGCP_MSG_PRESENCE_CALL_ID 0x0002
108#define MGCP_MSG_PRESENCE_CONN_ID 0x0004
109#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
110#define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010
111#define MGCP_MSG_PRESENCE_CONN_MODE 0x0020
Pau Espin Pedrol900cd652019-04-24 22:06:22 +0200112#define MGCP_MSG_PRESENCE_X_OSMO_OSMUX_CID 0x4000
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200113#define MGCP_MSG_PRESENCE_X_OSMO_IGN 0x8000
Philipp Maier1dc6be62017-10-05 18:25:37 +0200114
Philipp Maier1dc6be62017-10-05 18:25:37 +0200115struct mgcp_msg {
116 enum mgcp_verb verb;
117 /* See MGCP_MSG_PRESENCE_* constants */
118 uint32_t presence;
119 char endpoint[MGCP_ENDPOINT_MAXLEN];
120 unsigned int call_id;
Philipp Maier01d24a32017-11-21 17:26:09 +0100121 char *conn_id;
Harald Welte9bf7c532017-11-17 14:14:31 +0100122 uint16_t audio_port;
123 char *audio_ip;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200124 enum mgcp_connection_mode conn_mode;
Philipp Maier704c4f02018-06-07 18:51:31 +0200125 unsigned int ptime;
126 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
127 unsigned int codecs_len;
128 struct ptmap ptmap[MGCP_MAX_CODECS];
129 unsigned int ptmap_len;
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200130 uint32_t x_osmo_ign;
Pau Espin Pedrol900cd652019-04-24 22:06:22 +0200131 bool x_osmo_osmux_use;
132 int x_osmo_osmux_cid; /* -1 is wildcard */
Philipp Maier228e5912019-03-05 13:56:59 +0100133 bool param_present;
134 struct mgcp_codec_param param;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200135};
136
Pau Espin Pedrol8e8d59f2023-06-13 19:41:44 +0200137struct mgcp_client_conf *mgcp_client_conf_alloc(void *ctx);
138void mgcp_client_conf_init(struct mgcp_client_conf *conf) OSMO_DEPRECATED_OUTSIDE_LIBOSMOMGCPCLIENT("use mgcp_client_conf_alloc() (or even better, switch to the mgcp_client_pool API!)");
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200139void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf);
140int mgcp_client_config_write(struct vty *vty, const char *indent);
141struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp);
142
143struct mgcp_client *mgcp_client_init(void *ctx,
144 struct mgcp_client_conf *conf);
145int mgcp_client_connect(struct mgcp_client *mgcp);
Pau Espin Pedrol8e74c632022-10-17 19:20:45 +0200146int mgcp_client_connect2(struct mgcp_client *mgcp, unsigned int retry_n_ports) OSMO_DEPRECATED("Use mgcp_client_connect() instead");
Philipp Maier3f4a4cb2021-07-26 13:20:05 +0200147void mgcp_client_disconnect(struct mgcp_client *mgcp);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200148
149const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp);
150uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp);
Pau Espin Pedrol74d0e5c2020-09-02 17:19:20 +0200151uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp) OSMO_DEPRECATED("deprecated, returns 0");
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200152
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100153const char *mgcp_client_endpoint_domain(const struct mgcp_client *mgcp);
154const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp);
Philipp Maier48635912020-06-25 20:16:22 +0200155const char *mgcp_client_e1_epname(void *ctx, const struct mgcp_client *mgcp, uint8_t trunk_id, uint8_t ts,
156 uint8_t rate, uint8_t offset);
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100157
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200158/* Invoked when an MGCP response is received or sending failed. When the
159 * response is passed as NULL, this indicates failure during transmission. */
160typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv);
161int mgcp_response_parse_params(struct mgcp_response *r);
162
163int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg,
164 mgcp_response_cb_t response_cb, void *priv);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100165int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200166
167enum mgcp_connection_mode;
168
Philipp Maier1dc6be62017-10-05 18:25:37 +0200169struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100170mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg);
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +0200171
172extern const struct value_string mgcp_client_connection_mode_strs[];
173static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode)
174{
175 return get_value_string(mgcp_client_connection_mode_strs, mode);
176}
Philipp Maier704c4f02018-06-07 18:51:31 +0200177
178enum mgcp_codecs map_str_to_codec(const char *str);
Neels Hofmeyr84274e42019-04-27 19:08:36 +0200179unsigned int map_codec_to_pt(const struct ptmap *ptmap, unsigned int ptmap_len,
Philipp Maier704c4f02018-06-07 18:51:31 +0200180 enum mgcp_codecs codec);
181enum mgcp_codecs map_pt_to_codec(struct ptmap *ptmap, unsigned int ptmap_len,
182 unsigned int pt);
Philipp Maierdf9192e2021-09-03 17:50:51 +0200183
184const char *mgcp_client_name(const struct mgcp_client *mgcp);