Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | #include <osmocom/core/linuxlist.h> |
| 6 | |
| 7 | enum mgcp_connection_mode; |
| 8 | |
| 9 | struct msgb; |
| 10 | struct mgcpgw_client; |
| 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; |
| 27 | }; |
| 28 | |
| 29 | struct mgcp_response_head { |
| 30 | int response_code; |
| 31 | mgcp_trans_id_t trans_id; |
| 32 | const char *comment; |
| 33 | }; |
| 34 | |
| 35 | struct mgcp_response { |
| 36 | char *body; |
| 37 | struct mgcp_response_head head; |
| 38 | uint16_t audio_port; |
| 39 | }; |
| 40 | |
| 41 | /* Invoked when an MGCP response is received or sending failed. When the |
| 42 | * response is passed as NULL, this indicates failure during transmission. */ |
| 43 | typedef void (* mgcp_response_cb_t )(struct mgcp_response *response, void *priv); |
| 44 | |
| 45 | struct mgcp_response_pending { |
| 46 | struct llist_head entry; |
| 47 | |
| 48 | mgcp_trans_id_t trans_id; |
| 49 | mgcp_response_cb_t response_cb; |
| 50 | void *priv; |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | void mgcpgw_client_conf_init(struct mgcpgw_client_conf *conf); |
| 55 | |
| 56 | struct mgcpgw_client *mgcpgw_client_init(void *ctx, |
| 57 | struct mgcpgw_client_conf *conf); |
| 58 | int mgcpgw_client_connect(struct mgcpgw_client *mgcp); |
| 59 | |
| 60 | const char *mgcpgw_client_remote_addr_str(struct mgcpgw_client *mgcp); |
| 61 | uint16_t mgcpgw_client_remote_port(struct mgcpgw_client *mgcp); |
| 62 | uint32_t mgcpgw_client_remote_addr_n(struct mgcpgw_client *mgcp); |
| 63 | |
| 64 | unsigned int mgcpgw_client_next_endpoint(struct mgcpgw_client *client); |
| 65 | |
| 66 | int mgcp_response_parse_params(struct mgcp_response *r); |
| 67 | |
| 68 | int mgcpgw_client_tx(struct mgcpgw_client *mgcp, struct msgb *msg, |
| 69 | mgcp_response_cb_t response_cb, void *priv); |
| 70 | |
| 71 | struct msgb *mgcp_msg_crcx(struct mgcpgw_client *mgcp, |
| 72 | uint16_t rtp_endpoint, unsigned int call_id, |
| 73 | enum mgcp_connection_mode mode); |
| 74 | |
| 75 | struct msgb *mgcp_msg_mdcx(struct mgcpgw_client *mgcp, |
| 76 | uint16_t rtp_endpoint, const char *rtp_conn_addr, |
| 77 | uint16_t rtp_port, enum mgcp_connection_mode mode); |
| 78 | |
| 79 | void mgcpgw_client_vty_init(int node, struct mgcpgw_client_conf *conf); |
| 80 | int mgcpgw_client_config_write(struct vty *vty, const char *indent); |
| 81 | |
| 82 | struct mgcp_response_pending * mgcpgw_client_pending_add( |
| 83 | struct mgcpgw_client *mgcp, |
| 84 | mgcp_trans_id_t trans_id, |
| 85 | mgcp_response_cb_t response_cb, |
| 86 | void *priv); |
| 87 | int mgcpgw_client_rx(struct mgcpgw_client *mgcp, struct msgb *msg); |