Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | #include <osmocom/core/linuxlist.h> |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 6 | #include <osmocom/core/write_queue.h> |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 7 | |
| 8 | enum mgcp_connection_mode; |
| 9 | |
| 10 | struct msgb; |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 11 | struct vty; |
| 12 | |
| 13 | #define MGCPGW_CLIENT_LOCAL_ADDR_DEFAULT "0.0.0.0" |
| 14 | #define MGCPGW_CLIENT_LOCAL_PORT_DEFAULT 0 |
| 15 | #define MGCPGW_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1" |
| 16 | #define MGCPGW_CLIENT_REMOTE_PORT_DEFAULT 2427 |
| 17 | |
| 18 | #define MSGB_CB_MGCP_TRANS_ID 0 |
| 19 | |
| 20 | typedef unsigned int mgcp_trans_id_t; |
| 21 | |
| 22 | struct mgcpgw_client_conf { |
| 23 | const char *local_addr; |
| 24 | int local_port; |
| 25 | const char *remote_addr; |
| 26 | int remote_port; |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 27 | uint16_t first_endpoint; |
| 28 | uint16_t last_endpoint; |
| 29 | uint16_t bts_base; |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | struct mgcp_response_head { |
| 33 | int response_code; |
| 34 | mgcp_trans_id_t trans_id; |
| 35 | const char *comment; |
| 36 | }; |
| 37 | |
| 38 | struct mgcp_response { |
| 39 | char *body; |
| 40 | struct mgcp_response_head head; |
| 41 | uint16_t audio_port; |
| 42 | }; |
| 43 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 44 | struct mgcpgw_client { |
| 45 | struct mgcpgw_client_conf actual; |
| 46 | uint32_t remote_addr; |
| 47 | struct osmo_wqueue wq; |
| 48 | mgcp_trans_id_t next_trans_id; |
| 49 | struct llist_head responses_pending; |
| 50 | struct llist_head inuse_endpoints; |
| 51 | }; |
| 52 | |
| 53 | struct mgcp_inuse_endpoint { |
| 54 | struct llist_head entry; |
| 55 | uint16_t id; |
| 56 | }; |
| 57 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 58 | /* Invoked when an MGCP response is received or sending failed. When the |
| 59 | * response is passed as NULL, this indicates failure during transmission. */ |
| 60 | typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv); |
| 61 | |
| 62 | struct mgcp_response_pending { |
| 63 | struct llist_head entry; |
| 64 | |
| 65 | mgcp_trans_id_t trans_id; |
| 66 | mgcp_response_cb_t response_cb; |
| 67 | void *priv; |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | void mgcpgw_client_conf_init(struct mgcpgw_client_conf *conf); |
| 72 | |
| 73 | struct mgcpgw_client *mgcpgw_client_init(void *ctx, |
| 74 | struct mgcpgw_client_conf *conf); |
| 75 | int mgcpgw_client_connect(struct mgcpgw_client *mgcp); |
| 76 | |
| 77 | const char *mgcpgw_client_remote_addr_str(struct mgcpgw_client *mgcp); |
| 78 | uint16_t mgcpgw_client_remote_port(struct mgcpgw_client *mgcp); |
| 79 | uint32_t mgcpgw_client_remote_addr_n(struct mgcpgw_client *mgcp); |
| 80 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 81 | /* Find and seize an unsused endpoint id */ |
| 82 | int mgcpgw_client_next_endpoint(struct mgcpgw_client *client); |
| 83 | |
| 84 | /* Release a seized endpoint id to make it available again for other calls */ |
| 85 | void mgcpgw_client_release_endpoint(uint16_t id, struct mgcpgw_client *client); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 86 | |
| 87 | int mgcp_response_parse_params(struct mgcp_response *r); |
| 88 | |
| 89 | int mgcpgw_client_tx(struct mgcpgw_client *mgcp, struct msgb *msg, |
| 90 | mgcp_response_cb_t response_cb, void *priv); |
| 91 | |
| 92 | struct msgb *mgcp_msg_crcx(struct mgcpgw_client *mgcp, |
| 93 | uint16_t rtp_endpoint, unsigned int call_id, |
| 94 | enum mgcp_connection_mode mode); |
| 95 | |
| 96 | struct msgb *mgcp_msg_mdcx(struct mgcpgw_client *mgcp, |
| 97 | uint16_t rtp_endpoint, const char *rtp_conn_addr, |
| 98 | uint16_t rtp_port, enum mgcp_connection_mode mode); |
| 99 | |
Philipp Maier | 4b60d07 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 100 | struct msgb *mgcp_msg_dlcx(struct mgcpgw_client *mgcp, uint16_t rtp_endpoint, |
| 101 | unsigned int call_id); |
| 102 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 103 | void mgcpgw_client_vty_init(int node, struct mgcpgw_client_conf *conf); |
| 104 | int mgcpgw_client_config_write(struct vty *vty, const char *indent); |
| 105 | |
| 106 | struct mgcp_response_pending * mgcpgw_client_pending_add( |
| 107 | struct mgcpgw_client *mgcp, |
| 108 | mgcp_trans_id_t trans_id, |
| 109 | mgcp_response_cb_t response_cb, |
| 110 | void *priv); |
| 111 | int mgcpgw_client_rx(struct mgcpgw_client *mgcp, struct msgb *msg); |