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 | |
Pau Espin Pedrol | 8e8d59f | 2023-06-13 19:41:44 +0200 | [diff] [blame] | 6 | #include <osmocom/mgcp_client/defs.h> |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 7 | #include <osmocom/mgcp_client/mgcp_common.h> |
| 8 | |
Philipp Maier | af8e00f | 2018-07-27 16:04:41 +0200 | [diff] [blame] | 9 | /* See also: RFC 3435, chapter 3.5 Transmission over UDP */ |
Pau Espin Pedrol | ee2f33b | 2020-08-31 19:36:31 +0200 | [diff] [blame] | 10 | #define MGCP_CLIENT_LOCAL_ADDR_DEFAULT NULL /* INADDR(6)_ANY */ |
Pau Espin Pedrol | 8e74c63 | 2022-10-17 19:20:45 +0200 | [diff] [blame] | 11 | #define MGCP_CLIENT_LOCAL_PORT_DEFAULT 0 |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 12 | #define MGCP_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1" |
| 13 | #define MGCP_CLIENT_REMOTE_PORT_DEFAULT 2427 |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 14 | #define MGCP_CLIENT_KEEPALIVE_DEFAULT_ENDP "null" |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 15 | #define MGCP_CLIENT_MGW_STR "Configure MGCP connection to Media Gateway\n" |
| 16 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 17 | struct msgb; |
| 18 | struct vty; |
| 19 | struct mgcp_client; |
| 20 | |
| 21 | struct mgcp_client_conf { |
| 22 | const char *local_addr; |
| 23 | int local_port; |
| 24 | const char *remote_addr; |
| 25 | int remote_port; |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 26 | |
| 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 Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 30 | |
| 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 Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 36 | |
| 37 | /* human readable name / description */ |
| 38 | char *description; |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 39 | |
| 40 | struct { |
| 41 | uint32_t timeout_sec; |
| 42 | uint32_t req_interval_sec; |
| 43 | char req_endpoint_name[MGCP_ENDPOINT_MAXLEN]; |
| 44 | } keepalive; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | typedef unsigned int mgcp_trans_id_t; |
| 48 | |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 49 | /*! Enumeration of the codec types that mgcp_client is able to handle. */ |
| 50 | enum mgcp_codecs { |
| 51 | CODEC_PCMU_8000_1 = 0, |
| 52 | CODEC_GSM_8000_1 = 3, |
| 53 | CODEC_PCMA_8000_1 = 8, |
| 54 | CODEC_G729_8000_1 = 18, |
Philipp Maier | 14da3a3 | 2023-05-23 12:03:16 +0200 | [diff] [blame] | 55 | CODEC_GSMEFR_8000_1 = 110, /* 3GPP TS 48.103 table 5.4.2.2.1 */ |
| 56 | CODEC_GSMHR_8000_1 = 111, /* 3GPP TS 48.103 table 5.4.2.2.1 */ |
| 57 | CODEC_AMR_8000_1 = 112, /* 3GPP TS 48.103 table 5.4.2.2.1 */ |
| 58 | CODEC_AMRWB_16000_1 = 113, /* 3GPP TS 48.103 table 5.4.2.2.1 */ |
Philipp Maier | 1de5ed6 | 2021-12-21 14:38:14 +0100 | [diff] [blame] | 59 | CODEC_IUFP = 96, |
Philipp Maier | 14da3a3 | 2023-05-23 12:03:16 +0200 | [diff] [blame] | 60 | CODEC_CLEARMODE = 120, /* 3GPP TS 48.103 table 5.4.2.2.1 */ |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 61 | }; |
| 62 | /* Note: when new codec types are added, the corresponding value strings |
| 63 | * in mgcp_client.c (codec_table) must be updated as well. Enumerations |
| 64 | * in enum mgcp_codecs must correspond to a valid payload type. However, |
| 65 | * this is an internal assumption that is made to avoid lookup tables. |
| 66 | * The API-User should not rely on this coincidence! */ |
| 67 | |
Neels Hofmeyr | 47642f2 | 2019-02-27 05:56:53 +0100 | [diff] [blame] | 68 | extern const struct value_string osmo_mgcpc_codec_names[]; |
| 69 | static inline const char *osmo_mgcpc_codec_name(enum mgcp_codecs val) |
| 70 | { return get_value_string(osmo_mgcpc_codec_names, val); } |
| 71 | |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 72 | /*! Structure to build a payload type map to allow the defiition custom payload |
| 73 | * types. */ |
| 74 | struct ptmap { |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 75 | /*! codec for which a payload type number should be defined */ |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 76 | enum mgcp_codecs codec; |
| 77 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 78 | /*! payload type number (96-127) */ |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 79 | unsigned int pt; |
| 80 | }; |
| 81 | |
Neels Hofmeyr | cc2f793 | 2023-12-07 03:46:46 +0100 | [diff] [blame^] | 82 | int ptmap_cmp(const struct ptmap *a, const struct ptmap *b); |
| 83 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 84 | enum mgcp_verb { |
| 85 | MGCP_VERB_CRCX, |
| 86 | MGCP_VERB_MDCX, |
| 87 | MGCP_VERB_DLCX, |
| 88 | MGCP_VERB_AUEP, |
| 89 | MGCP_VERB_RSIP, |
| 90 | }; |
| 91 | |
Pau Espin Pedrol | 8e8d59f | 2023-06-13 19:41:44 +0200 | [diff] [blame] | 92 | struct mgcp_client_conf *mgcp_client_conf_alloc(void *ctx); |
| 93 | void 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 Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 94 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf); |
| 95 | int mgcp_client_config_write(struct vty *vty, const char *indent); |
| 96 | struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp); |
| 97 | |
| 98 | struct mgcp_client *mgcp_client_init(void *ctx, |
| 99 | struct mgcp_client_conf *conf); |
| 100 | int mgcp_client_connect(struct mgcp_client *mgcp); |
Pau Espin Pedrol | 8e74c63 | 2022-10-17 19:20:45 +0200 | [diff] [blame] | 101 | int mgcp_client_connect2(struct mgcp_client *mgcp, unsigned int retry_n_ports) OSMO_DEPRECATED("Use mgcp_client_connect() instead"); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 102 | void mgcp_client_disconnect(struct mgcp_client *mgcp); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 103 | |
| 104 | const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp); |
| 105 | uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp); |
Pau Espin Pedrol | 74d0e5c | 2020-09-02 17:19:20 +0200 | [diff] [blame] | 106 | 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] | 107 | |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 108 | const char *mgcp_client_endpoint_domain(const struct mgcp_client *mgcp); |
| 109 | const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp); |
Philipp Maier | 4863591 | 2020-06-25 20:16:22 +0200 | [diff] [blame] | 110 | const char *mgcp_client_e1_epname(void *ctx, const struct mgcp_client *mgcp, uint8_t trunk_id, uint8_t ts, |
| 111 | uint8_t rate, uint8_t offset); |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 112 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 113 | enum mgcp_connection_mode; |
| 114 | |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 115 | extern const struct value_string mgcp_client_connection_mode_strs[]; |
| 116 | static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode) |
| 117 | { |
| 118 | return get_value_string(mgcp_client_connection_mode_strs, mode); |
| 119 | } |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 120 | |
| 121 | enum mgcp_codecs map_str_to_codec(const char *str); |
Neels Hofmeyr | 84274e4 | 2019-04-27 19:08:36 +0200 | [diff] [blame] | 122 | 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] | 123 | enum mgcp_codecs codec); |
| 124 | enum mgcp_codecs map_pt_to_codec(struct ptmap *ptmap, unsigned int ptmap_len, |
| 125 | unsigned int pt); |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 126 | |
| 127 | const char *mgcp_client_name(const struct mgcp_client *mgcp); |