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 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 8 | #define MGCP_CLIENT_LOCAL_ADDR_DEFAULT "0.0.0.0" |
| 9 | #define MGCP_CLIENT_LOCAL_PORT_DEFAULT 0 |
| 10 | #define MGCP_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1" |
| 11 | #define MGCP_CLIENT_REMOTE_PORT_DEFAULT 2427 |
| 12 | |
| 13 | struct msgb; |
| 14 | struct vty; |
| 15 | struct mgcp_client; |
| 16 | |
| 17 | struct mgcp_client_conf { |
| 18 | const char *local_addr; |
| 19 | int local_port; |
| 20 | const char *remote_addr; |
| 21 | int remote_port; |
| 22 | uint16_t first_endpoint; |
| 23 | uint16_t last_endpoint; |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 24 | uint16_t bts_base; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | typedef unsigned int mgcp_trans_id_t; |
| 28 | |
| 29 | struct mgcp_response_head { |
Philipp Maier | ead2f60 | 2017-11-27 12:06:29 +0100 | [diff] [blame] | 30 | int response_code; |
| 31 | mgcp_trans_id_t trans_id; |
| 32 | const char *comment; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 33 | char conn_id[MGCP_CONN_ID_LENGTH]; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct mgcp_response { |
| 37 | char *body; |
| 38 | struct mgcp_response_head head; |
| 39 | uint16_t audio_port; |
Philipp Maier | 06da85e | 2017-10-05 18:49:24 +0200 | [diff] [blame] | 40 | char audio_ip[INET_ADDRSTRLEN]; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 43 | enum mgcp_verb { |
| 44 | MGCP_VERB_CRCX, |
| 45 | MGCP_VERB_MDCX, |
| 46 | MGCP_VERB_DLCX, |
| 47 | MGCP_VERB_AUEP, |
| 48 | MGCP_VERB_RSIP, |
| 49 | }; |
| 50 | |
| 51 | #define MGCP_MSG_PRESENCE_ENDPOINT 0x0001 |
| 52 | #define MGCP_MSG_PRESENCE_CALL_ID 0x0002 |
| 53 | #define MGCP_MSG_PRESENCE_CONN_ID 0x0004 |
| 54 | #define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008 |
| 55 | #define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010 |
| 56 | #define MGCP_MSG_PRESENCE_CONN_MODE 0x0020 |
| 57 | |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 58 | struct mgcp_msg { |
| 59 | enum mgcp_verb verb; |
| 60 | /* See MGCP_MSG_PRESENCE_* constants */ |
| 61 | uint32_t presence; |
| 62 | char endpoint[MGCP_ENDPOINT_MAXLEN]; |
| 63 | unsigned int call_id; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 64 | char *conn_id; |
Harald Welte | 9bf7c53 | 2017-11-17 14:14:31 +0100 | [diff] [blame] | 65 | uint16_t audio_port; |
| 66 | char *audio_ip; |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 67 | enum mgcp_connection_mode conn_mode; |
| 68 | }; |
| 69 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 70 | void mgcp_client_conf_init(struct mgcp_client_conf *conf); |
| 71 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf); |
| 72 | int mgcp_client_config_write(struct vty *vty, const char *indent); |
| 73 | struct mgcp_client_conf *mgcp_client_conf_actual(struct mgcp_client *mgcp); |
| 74 | |
| 75 | struct mgcp_client *mgcp_client_init(void *ctx, |
| 76 | struct mgcp_client_conf *conf); |
| 77 | int mgcp_client_connect(struct mgcp_client *mgcp); |
| 78 | |
| 79 | const char *mgcp_client_remote_addr_str(struct mgcp_client *mgcp); |
| 80 | uint16_t mgcp_client_remote_port(struct mgcp_client *mgcp); |
| 81 | uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp); |
| 82 | |
| 83 | int mgcp_client_next_endpoint(struct mgcp_client *client); |
| 84 | void mgcp_client_release_endpoint(uint16_t id, struct mgcp_client *client); |
| 85 | |
| 86 | /* Invoked when an MGCP response is received or sending failed. When the |
| 87 | * response is passed as NULL, this indicates failure during transmission. */ |
| 88 | typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv); |
| 89 | int mgcp_response_parse_params(struct mgcp_response *r); |
| 90 | |
| 91 | int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg, |
| 92 | mgcp_response_cb_t response_cb, void *priv); |
Neels Hofmeyr | c8f37cb | 2017-11-30 13:43:11 +0100 | [diff] [blame] | 93 | 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] | 94 | |
| 95 | enum mgcp_connection_mode; |
| 96 | |
| 97 | struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp, |
| 98 | uint16_t rtp_endpoint, unsigned int call_id, |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 99 | enum mgcp_connection_mode mode) |
| 100 | OSMO_DEPRECATED("Use mgcp_msg_gen() instead"); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 101 | |
| 102 | struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp, |
| 103 | uint16_t rtp_endpoint, const char *rtp_conn_addr, |
Philipp Maier | 1dc6be6 | 2017-10-05 18:25:37 +0200 | [diff] [blame] | 104 | uint16_t rtp_port, enum mgcp_connection_mode mode) |
| 105 | OSMO_DEPRECATED("Use mgcp_msg_gen() instead"); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 106 | |
| 107 | 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] | 108 | unsigned int call_id) |
| 109 | OSMO_DEPRECATED("Use mgcp_msg_gen() instead"); |
| 110 | |
| 111 | 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] | 112 | mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg); |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 113 | |
| 114 | extern const struct value_string mgcp_client_connection_mode_strs[]; |
| 115 | static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode) |
| 116 | { |
| 117 | return get_value_string(mgcp_client_connection_mode_strs, mode); |
| 118 | } |