blob: c1fd1b02811d9bb50be56e55f9d3b3ce52ba5694 [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 Hofmeyr3a8e7232017-09-04 01:02:56 +020025};
26
27typedef unsigned int mgcp_trans_id_t;
28
Philipp Maier704c4f02018-06-07 18:51:31 +020029/*! Enumeration of the codec types that mgcp_client is able to handle. */
30enum mgcp_codecs {
31 CODEC_PCMU_8000_1 = 0,
32 CODEC_GSM_8000_1 = 3,
33 CODEC_PCMA_8000_1 = 8,
34 CODEC_G729_8000_1 = 18,
35 CODEC_GSMEFR_8000_1 = 110,
36 CODEC_GSMHR_8000_1 = 111,
37 CODEC_AMR_8000_1 = 112,
38 CODEC_AMRWB_16000_1 = 113,
39};
40/* Note: when new codec types are added, the corresponding value strings
41 * in mgcp_client.c (codec_table) must be updated as well. Enumerations
42 * in enum mgcp_codecs must correspond to a valid payload type. However,
43 * this is an internal assumption that is made to avoid lookup tables.
44 * The API-User should not rely on this coincidence! */
45
46/*! Structure to build a payload type map to allow the defiition custom payload
47 * types. */
48struct ptmap {
Neels Hofmeyr8838c622018-06-26 00:05:53 +020049 /*! codec for which a payload type number should be defined */
Philipp Maier704c4f02018-06-07 18:51:31 +020050 enum mgcp_codecs codec;
51
Neels Hofmeyr8838c622018-06-26 00:05:53 +020052 /*! payload type number (96-127) */
Philipp Maier704c4f02018-06-07 18:51:31 +020053 unsigned int pt;
54};
55
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020056struct mgcp_response_head {
Philipp Maieread2f602017-11-27 12:06:29 +010057 int response_code;
58 mgcp_trans_id_t trans_id;
Philipp Maierabe8c892018-01-20 00:15:12 +010059 char comment[MGCP_COMMENT_MAXLEN];
Neels Hofmeyr55e0dcf2018-09-03 21:36:56 +020060 char conn_id[MGCP_CONN_ID_MAXLEN];
Philipp Maier55295f72018-01-15 14:00:28 +010061 char endpoint[MGCP_ENDPOINT_MAXLEN];
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020062};
63
64struct mgcp_response {
65 char *body;
66 struct mgcp_response_head head;
67 uint16_t audio_port;
Philipp Maier06da85e2017-10-05 18:49:24 +020068 char audio_ip[INET_ADDRSTRLEN];
Philipp Maier704c4f02018-06-07 18:51:31 +020069 unsigned int ptime;
70 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
71 unsigned int codecs_len;
72 struct ptmap ptmap[MGCP_MAX_CODECS];
73 unsigned int ptmap_len;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020074};
75
Philipp Maier1dc6be62017-10-05 18:25:37 +020076enum mgcp_verb {
77 MGCP_VERB_CRCX,
78 MGCP_VERB_MDCX,
79 MGCP_VERB_DLCX,
80 MGCP_VERB_AUEP,
81 MGCP_VERB_RSIP,
82};
83
84#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
85#define MGCP_MSG_PRESENCE_CALL_ID 0x0002
86#define MGCP_MSG_PRESENCE_CONN_ID 0x0004
87#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
88#define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010
89#define MGCP_MSG_PRESENCE_CONN_MODE 0x0020
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020090#define MGCP_MSG_PRESENCE_X_OSMO_IGN 0x8000
Philipp Maier1dc6be62017-10-05 18:25:37 +020091
Philipp Maier1dc6be62017-10-05 18:25:37 +020092struct mgcp_msg {
93 enum mgcp_verb verb;
94 /* See MGCP_MSG_PRESENCE_* constants */
95 uint32_t presence;
96 char endpoint[MGCP_ENDPOINT_MAXLEN];
97 unsigned int call_id;
Philipp Maier01d24a32017-11-21 17:26:09 +010098 char *conn_id;
Harald Welte9bf7c532017-11-17 14:14:31 +010099 uint16_t audio_port;
100 char *audio_ip;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200101 enum mgcp_connection_mode conn_mode;
Philipp Maier704c4f02018-06-07 18:51:31 +0200102 unsigned int ptime;
103 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
104 unsigned int codecs_len;
105 struct ptmap ptmap[MGCP_MAX_CODECS];
106 unsigned int ptmap_len;
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200107 uint32_t x_osmo_ign;
Philipp Maier1dc6be62017-10-05 18:25:37 +0200108};
109
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200110void mgcp_client_conf_init(struct mgcp_client_conf *conf);
111void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf);
112int mgcp_client_config_write(struct vty *vty, const char *indent);
113struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp);
114
115struct mgcp_client *mgcp_client_init(void *ctx,
116 struct mgcp_client_conf *conf);
117int mgcp_client_connect(struct mgcp_client *mgcp);
118
119const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp);
120uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp);
121uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp);
122
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200123/* Invoked when an MGCP response is received or sending failed. When the
124 * response is passed as NULL, this indicates failure during transmission. */
125typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv);
126int mgcp_response_parse_params(struct mgcp_response *r);
127
128int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg,
129 mgcp_response_cb_t response_cb, void *priv);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100130int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200131
132enum mgcp_connection_mode;
133
Philipp Maier1dc6be62017-10-05 18:25:37 +0200134struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
Neels Hofmeyrc8f37cb2017-11-30 13:43:11 +0100135mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg);
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +0200136
137extern const struct value_string mgcp_client_connection_mode_strs[];
138static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode)
139{
140 return get_value_string(mgcp_client_connection_mode_strs, mode);
141}
Philipp Maier704c4f02018-06-07 18:51:31 +0200142
143enum mgcp_codecs map_str_to_codec(const char *str);
144unsigned int map_codec_to_pt(struct ptmap *ptmap, unsigned int ptmap_len,
145 enum mgcp_codecs codec);
146enum mgcp_codecs map_pt_to_codec(struct ptmap *ptmap, unsigned int ptmap_len,
147 unsigned int pt);