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 */ |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 9 | #define MGCP_CLIENT_LOCAL_ADDR_DEFAULT "0.0.0.0" |
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 | |
| 14 | struct msgb; |
| 15 | struct vty; |
| 16 | struct mgcp_client; |
| 17 | |
| 18 | struct mgcp_client_conf { |
| 19 | const char *local_addr; |
| 20 | int local_port; |
| 21 | const char *remote_addr; |
| 22 | int remote_port; |
| 23 | uint16_t first_endpoint; |
| 24 | uint16_t last_endpoint; |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 25 | uint16_t bts_base; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | typedef unsigned int mgcp_trans_id_t; |
| 29 | |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 30 | /*! Enumeration of the codec types that mgcp_client is able to handle. */ |
| 31 | enum mgcp_codecs { |
| 32 | CODEC_PCMU_8000_1 = 0, |
| 33 | CODEC_GSM_8000_1 = 3, |
| 34 | CODEC_PCMA_8000_1 = 8, |
| 35 | CODEC_G729_8000_1 = 18, |
| 36 | CODEC_GSMEFR_8000_1 = 110, |
| 37 | CODEC_GSMHR_8000_1 = 111, |
| 38 | CODEC_AMR_8000_1 = 112, |
| 39 | CODEC_AMRWB_16000_1 = 113, |
| 40 | }; |
| 41 | /* Note: when new codec types are added, the corresponding value strings |
| 42 | * in mgcp_client.c (codec_table) must be updated as well. Enumerations |
| 43 | * in enum mgcp_codecs must correspond to a valid payload type. However, |
| 44 | * this is an internal assumption that is made to avoid lookup tables. |
| 45 | * The API-User should not rely on this coincidence! */ |
| 46 | |
| 47 | /*! Structure to build a payload type map to allow the defiition custom payload |
| 48 | * types. */ |
| 49 | struct ptmap { |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 50 | /*! codec for which a payload type number should be defined */ |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 51 | enum mgcp_codecs codec; |
| 52 | |
Neels Hofmeyr | 8838c62 | 2018-06-26 00:05:53 +0200 | [diff] [blame] | 53 | /*! payload type number (96-127) */ |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 54 | unsigned int pt; |
| 55 | }; |
| 56 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 57 | struct mgcp_response_head { |
Philipp Maier | ead2f60 | 2017-11-27 12:06:29 +0100 | [diff] [blame] | 58 | int response_code; |
| 59 | mgcp_trans_id_t trans_id; |
Philipp Maier | abe8c89 | 2018-01-20 00:15:12 +0100 | [diff] [blame] | 60 | char comment[MGCP_COMMENT_MAXLEN]; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 61 | char conn_id[MGCP_CONN_ID_LENGTH]; |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 62 | char endpoint[MGCP_ENDPOINT_MAXLEN]; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct mgcp_response { |
| 66 | char *body; |
| 67 | struct mgcp_response_head head; |
| 68 | uint16_t audio_port; |
Philipp Maier | 06da85e | 2017-10-05 18:49:24 +0200 | [diff] [blame] | 69 | char audio_ip[INET_ADDRSTRLEN]; |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 70 | unsigned int ptime; |
| 71 | enum mgcp_codecs codecs[MGCP_MAX_CODECS]; |
| 72 | unsigned int codecs_len; |
| 73 | struct ptmap ptmap[MGCP_MAX_CODECS]; |
| 74 | unsigned int ptmap_len; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 77 | enum mgcp_verb { |
| 78 | MGCP_VERB_CRCX, |
| 79 | MGCP_VERB_MDCX, |
| 80 | MGCP_VERB_DLCX, |
| 81 | MGCP_VERB_AUEP, |
| 82 | MGCP_VERB_RSIP, |
| 83 | }; |
| 84 | |
| 85 | #define MGCP_MSG_PRESENCE_ENDPOINT 0x0001 |
| 86 | #define MGCP_MSG_PRESENCE_CALL_ID 0x0002 |
| 87 | #define MGCP_MSG_PRESENCE_CONN_ID 0x0004 |
| 88 | #define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008 |
| 89 | #define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010 |
| 90 | #define MGCP_MSG_PRESENCE_CONN_MODE 0x0020 |
| 91 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 92 | struct 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 Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 98 | char *conn_id; |
Harald Welte | 9bf7c53 | 2017-11-17 14:14:31 +0100 | [diff] [blame] | 99 | uint16_t audio_port; |
| 100 | char *audio_ip; |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 101 | enum mgcp_connection_mode conn_mode; |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 102 | 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; |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 107 | }; |
| 108 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 109 | void mgcp_client_conf_init(struct mgcp_client_conf *conf); |
| 110 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf); |
| 111 | int mgcp_client_config_write(struct vty *vty, const char *indent); |
| 112 | struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp); |
| 113 | |
| 114 | struct mgcp_client *mgcp_client_init(void *ctx, |
| 115 | struct mgcp_client_conf *conf); |
| 116 | int mgcp_client_connect(struct mgcp_client *mgcp); |
| 117 | |
| 118 | const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp); |
| 119 | uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp); |
| 120 | uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp); |
| 121 | |
| 122 | int mgcp_client_next_endpoint(struct mgcp_client *client); |
| 123 | void mgcp_client_release_endpoint(uint16_t id, struct mgcp_client *client); |
| 124 | |
| 125 | /* Invoked when an MGCP response is received or sending failed. When the |
| 126 | * response is passed as NULL, this indicates failure during transmission. */ |
| 127 | typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv); |
| 128 | int mgcp_response_parse_params(struct mgcp_response *r); |
| 129 | |
| 130 | int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg, |
| 131 | mgcp_response_cb_t response_cb, void *priv); |
Neels Hofmeyr | c8f37cb | 2017-11-30 13:43:11 +0100 | [diff] [blame] | 132 | 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] | 133 | |
| 134 | enum mgcp_connection_mode; |
| 135 | |
| 136 | struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp, |
| 137 | uint16_t rtp_endpoint, unsigned int call_id, |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 138 | enum mgcp_connection_mode mode) |
| 139 | OSMO_DEPRECATED("Use mgcp_msg_gen() instead"); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 140 | |
| 141 | struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp, |
| 142 | uint16_t rtp_endpoint, const char *rtp_conn_addr, |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 143 | uint16_t rtp_port, enum mgcp_connection_mode mode) |
| 144 | OSMO_DEPRECATED("Use mgcp_msg_gen() instead"); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 145 | |
| 146 | struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint, |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 147 | unsigned int call_id) |
| 148 | OSMO_DEPRECATED("Use mgcp_msg_gen() instead"); |
| 149 | |
| 150 | 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] | 151 | mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg); |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 152 | |
| 153 | extern const struct value_string mgcp_client_connection_mode_strs[]; |
| 154 | static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode) |
| 155 | { |
| 156 | return get_value_string(mgcp_client_connection_mode_strs, mode); |
| 157 | } |
Philipp Maier | 704c4f0 | 2018-06-07 18:51:31 +0200 | [diff] [blame] | 158 | |
| 159 | enum mgcp_codecs map_str_to_codec(const char *str); |
| 160 | unsigned int map_codec_to_pt(struct ptmap *ptmap, unsigned int ptmap_len, |
| 161 | enum mgcp_codecs codec); |
| 162 | enum mgcp_codecs map_pt_to_codec(struct ptmap *ptmap, unsigned int ptmap_len, |
| 163 | unsigned int pt); |