Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 4 | #include <arpa/inet.h> |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 5 | |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 6 | #include <osmocom/mgcp_client/mgcp_common.h> |
| 7 | |
Philipp Maier | af8e00f | 2018-07-27 16:04:41 +0200 | [diff] [blame] | 8 | /* See also: RFC 3435, chapter 3.5 Transmission over UDP */ |
Pau Espin Pedrol | ee2f33b | 2020-08-31 19:36:31 +0200 | [diff] [blame] | 9 | #define MGCP_CLIENT_LOCAL_ADDR_DEFAULT NULL /* INADDR(6)_ANY */ |
Philipp Maier | af8e00f | 2018-07-27 16:04:41 +0200 | [diff] [blame] | 10 | #define MGCP_CLIENT_LOCAL_PORT_DEFAULT 2727 |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 11 | #define MGCP_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1" |
| 12 | #define MGCP_CLIENT_REMOTE_PORT_DEFAULT 2427 |
| 13 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 14 | #define MGCP_CLIENT_MGW_STR "Configure MGCP connection to Media Gateway\n" |
| 15 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 16 | struct msgb; |
| 17 | struct vty; |
| 18 | struct mgcp_client; |
| 19 | |
| 20 | struct mgcp_client_conf { |
| 21 | const char *local_addr; |
| 22 | int local_port; |
| 23 | const char *remote_addr; |
| 24 | int remote_port; |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 25 | |
| 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]; |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 29 | |
| 30 | /* The user may configure certain endpoint names that are reset via DLCX |
| 31 | * on startup. Usually this will be one wildcarded endpoint e.g. |
| 32 | * 'rtpbridge/(wildcard)' or a number of specific E1 like e.g. |
| 33 | * 'ds/e1-0/s-3/su16-4' */ |
| 34 | struct llist_head reset_epnames; |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 35 | |
| 36 | /* human readable name / description */ |
| 37 | char *description; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | typedef unsigned int mgcp_trans_id_t; |
| 41 | |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 42 | /*! Enumeration of the codec types that mgcp_client is able to handle. */ |
| 43 | enum mgcp_codecs { |
| 44 | CODEC_PCMU_8000_1 = 0, |
| 45 | CODEC_GSM_8000_1 = 3, |
| 46 | CODEC_PCMA_8000_1 = 8, |
| 47 | CODEC_G729_8000_1 = 18, |
| 48 | CODEC_GSMEFR_8000_1 = 110, |
Philipp Maier | dbe09dd | 2019-03-07 13:48:12 +0100 | [diff] [blame] | 49 | CODEC_GSMHR_8000_1 = 111, |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 50 | CODEC_AMR_8000_1 = 112, |
| 51 | CODEC_AMRWB_16000_1 = 113, |
Philipp Maier | 1de5ed6 | 2021-12-21 14:38:14 +0100 | [diff] [blame] | 52 | CODEC_IUFP = 96, |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 53 | }; |
| 54 | /* Note: when new codec types are added, the corresponding value strings |
| 55 | * in mgcp_client.c (codec_table) must be updated as well. Enumerations |
| 56 | * in enum mgcp_codecs must correspond to a valid payload type. However, |
| 57 | * this is an internal assumption that is made to avoid lookup tables. |
| 58 | * The API-User should not rely on this coincidence! */ |
| 59 | |
Neels Hofmeyr | 47642f2 | 2019-02-27 05:56:53 +0100 | [diff] [blame] | 60 | extern const struct value_string osmo_mgcpc_codec_names[]; |
| 61 | static inline const char *osmo_mgcpc_codec_name(enum mgcp_codecs val) |
| 62 | { return get_value_string(osmo_mgcpc_codec_names, val); } |
| 63 | |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 64 | /*! Structure to build a payload type map to allow the defiition custom payload |
| 65 | * types. */ |
| 66 | struct ptmap { |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 67 | /*! codec for which a payload type number should be defined */ |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 68 | enum mgcp_codecs codec; |
| 69 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 70 | /*! payload type number (96-127) */ |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 71 | unsigned int pt; |
| 72 | }; |
| 73 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 74 | struct mgcp_response_head { |
Philipp Maier | ead2f60 | 2017-11-27 12:06:29 +0100 | [diff] [blame] | 75 | int response_code; |
| 76 | mgcp_trans_id_t trans_id; |
Philipp Maier | abe8c89 | 2018-01-20 00:15:12 +0100 | [diff] [blame] | 77 | char comment[MGCP_COMMENT_MAXLEN]; |
Neels Hofmeyr | 55e0dcf | 2018-09-03 21:36:56 +0200 | [diff] [blame] | 78 | char conn_id[MGCP_CONN_ID_MAXLEN]; |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 79 | char endpoint[MGCP_ENDPOINT_MAXLEN]; |
Pau Espin Pedrol | 91088c3 | 2019-04-24 21:02:40 +0200 | [diff] [blame] | 80 | bool x_osmo_osmux_use; |
| 81 | uint8_t x_osmo_osmux_cid; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct mgcp_response { |
| 85 | char *body; |
| 86 | struct mgcp_response_head head; |
| 87 | uint16_t audio_port; |
Pau Espin Pedrol | 8667d51 | 2020-08-28 19:37:08 +0200 | [diff] [blame] | 88 | char audio_ip[INET6_ADDRSTRLEN]; |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 89 | unsigned int ptime; |
| 90 | enum mgcp_codecs codecs[MGCP_MAX_CODECS]; |
| 91 | unsigned int codecs_len; |
| 92 | struct ptmap ptmap[MGCP_MAX_CODECS]; |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 93 | unsigned int ptmap_len; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 96 | enum mgcp_verb { |
| 97 | MGCP_VERB_CRCX, |
| 98 | MGCP_VERB_MDCX, |
| 99 | MGCP_VERB_DLCX, |
| 100 | MGCP_VERB_AUEP, |
| 101 | MGCP_VERB_RSIP, |
| 102 | }; |
| 103 | |
| 104 | #define MGCP_MSG_PRESENCE_ENDPOINT 0x0001 |
| 105 | #define MGCP_MSG_PRESENCE_CALL_ID 0x0002 |
| 106 | #define MGCP_MSG_PRESENCE_CONN_ID 0x0004 |
| 107 | #define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008 |
| 108 | #define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010 |
| 109 | #define MGCP_MSG_PRESENCE_CONN_MODE 0x0020 |
Pau Espin Pedrol | 900cd65 | 2019-04-24 22:06:22 +0200 | [diff] [blame] | 110 | #define MGCP_MSG_PRESENCE_X_OSMO_OSMUX_CID 0x4000 |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 111 | #define MGCP_MSG_PRESENCE_X_OSMO_IGN 0x8000 |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 112 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 113 | struct mgcp_msg { |
| 114 | enum mgcp_verb verb; |
| 115 | /* See MGCP_MSG_PRESENCE_* constants */ |
| 116 | uint32_t presence; |
| 117 | char endpoint[MGCP_ENDPOINT_MAXLEN]; |
| 118 | unsigned int call_id; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 119 | char *conn_id; |
Harald Welte | 9bf7c53 | 2017-11-17 14:14:31 +0100 | [diff] [blame] | 120 | uint16_t audio_port; |
| 121 | char *audio_ip; |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 122 | enum mgcp_connection_mode conn_mode; |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 123 | unsigned int ptime; |
| 124 | enum mgcp_codecs codecs[MGCP_MAX_CODECS]; |
| 125 | unsigned int codecs_len; |
| 126 | struct ptmap ptmap[MGCP_MAX_CODECS]; |
| 127 | unsigned int ptmap_len; |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 128 | uint32_t x_osmo_ign; |
Pau Espin Pedrol | 900cd65 | 2019-04-24 22:06:22 +0200 | [diff] [blame] | 129 | bool x_osmo_osmux_use; |
| 130 | int x_osmo_osmux_cid; /* -1 is wildcard */ |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 131 | bool param_present; |
| 132 | struct mgcp_codec_param param; |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 133 | }; |
| 134 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 135 | void mgcp_client_conf_init(struct mgcp_client_conf *conf); |
| 136 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf); |
| 137 | int mgcp_client_config_write(struct vty *vty, const char *indent); |
| 138 | struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp); |
| 139 | |
| 140 | struct mgcp_client *mgcp_client_init(void *ctx, |
| 141 | struct mgcp_client_conf *conf); |
| 142 | int mgcp_client_connect(struct mgcp_client *mgcp); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 143 | int mgcp_client_connect2(struct mgcp_client *mgcp, unsigned int retry_n_ports); |
| 144 | void mgcp_client_disconnect(struct mgcp_client *mgcp); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 145 | |
| 146 | const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp); |
| 147 | uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp); |
Pau Espin Pedrol | 74d0e5c | 2020-09-02 17:19:20 +0200 | [diff] [blame] | 148 | uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp) OSMO_DEPRECATED("deprecated, returns 0"); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 149 | |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 150 | const char *mgcp_client_endpoint_domain(const struct mgcp_client *mgcp); |
| 151 | const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp); |
Philipp Maier | 4863591 | 2020-06-25 20:16:22 +0200 | [diff] [blame] | 152 | const char *mgcp_client_e1_epname(void *ctx, const struct mgcp_client *mgcp, uint8_t trunk_id, uint8_t ts, |
| 153 | uint8_t rate, uint8_t offset); |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 154 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 155 | /* Invoked when an MGCP response is received or sending failed. When the |
| 156 | * response is passed as NULL, this indicates failure during transmission. */ |
| 157 | typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv); |
| 158 | int mgcp_response_parse_params(struct mgcp_response *r); |
| 159 | |
| 160 | int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg, |
| 161 | mgcp_response_cb_t response_cb, void *priv); |
Neels Hofmeyr | c8f37cb | 2017-11-30 13:43:11 +0100 | [diff] [blame] | 162 | int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 163 | |
| 164 | enum mgcp_connection_mode; |
| 165 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 166 | struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg); |
Neels Hofmeyr | c8f37cb | 2017-11-30 13:43:11 +0100 | [diff] [blame] | 167 | mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg); |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 168 | |
| 169 | extern const struct value_string mgcp_client_connection_mode_strs[]; |
| 170 | static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode) |
| 171 | { |
| 172 | return get_value_string(mgcp_client_connection_mode_strs, mode); |
| 173 | } |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 174 | |
| 175 | enum mgcp_codecs map_str_to_codec(const char *str); |
Neels Hofmeyr | 84274e4 | 2019-04-27 19:08:36 +0200 | [diff] [blame] | 176 | unsigned int map_codec_to_pt(const struct ptmap *ptmap, unsigned int ptmap_len, |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 177 | enum mgcp_codecs codec); |
| 178 | enum mgcp_codecs map_pt_to_codec(struct ptmap *ptmap, unsigned int ptmap_len, |
| 179 | unsigned int pt); |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 180 | |
| 181 | const char *mgcp_client_name(const struct mgcp_client *mgcp); |