Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Harald Welte | 28fd236 | 2024-03-02 11:09:58 +0100 | [diff] [blame] | 3 | #include <osmocom/core/osmo_io.h> |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 4 | #include <osmocom/core/timer.h> |
Neels Hofmeyr | d95ab1e | 2017-09-22 00:52:54 +0200 | [diff] [blame] | 5 | |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 6 | #define MSGB_CB_MGCP_TRANS_ID 0 |
| 7 | |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 8 | /* Struct that holds one endpoint name */ |
| 9 | struct reset_ep { |
| 10 | struct llist_head list; |
| 11 | char name[MGCP_ENDPOINT_MAXLEN]; |
| 12 | }; |
| 13 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 14 | struct mgcp_client { |
| 15 | struct mgcp_client_conf actual; |
Harald Welte | 28fd236 | 2024-03-02 11:09:58 +0100 | [diff] [blame] | 16 | struct osmo_io_fd *iofd; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 17 | mgcp_trans_id_t next_trans_id; |
| 18 | struct llist_head responses_pending; |
Pau Espin Pedrol | 35bd252 | 2022-10-13 17:26:33 +0200 | [diff] [blame] | 19 | struct mgcp_client_pool_member *pool_member; |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 20 | struct osmo_timer_list keepalive_tx_timer; |
| 21 | struct osmo_timer_list keepalive_rx_timer; |
| 22 | bool conn_up; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 23 | }; |
| 24 | |
Neels Hofmeyr | 18717f5 | 2023-12-07 02:32:00 +0100 | [diff] [blame] | 25 | struct mgcp_response_head { |
| 26 | int response_code; |
| 27 | mgcp_trans_id_t trans_id; |
| 28 | char comment[MGCP_COMMENT_MAXLEN]; |
| 29 | char conn_id[MGCP_CONN_ID_MAXLEN]; |
| 30 | char endpoint[MGCP_ENDPOINT_MAXLEN]; |
| 31 | bool x_osmo_osmux_use; |
| 32 | uint8_t x_osmo_osmux_cid; |
| 33 | }; |
| 34 | |
| 35 | struct mgcp_response { |
| 36 | char *body; |
| 37 | struct mgcp_response_head head; |
| 38 | uint16_t audio_port; |
| 39 | char audio_ip[INET6_ADDRSTRLEN]; |
| 40 | unsigned int ptime; |
Neels Hofmeyr | 18717f5 | 2023-12-07 02:32:00 +0100 | [diff] [blame] | 41 | struct ptmap ptmap[MGCP_MAX_CODECS]; |
| 42 | unsigned int ptmap_len; |
| 43 | }; |
| 44 | |
| 45 | /* Invoked when an MGCP response is received or sending failed. When the |
| 46 | * response is passed as NULL, this indicates failure during transmission. */ |
| 47 | typedef void (*mgcp_response_cb_t)(struct mgcp_response *response, void *priv); |
| 48 | |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 49 | struct mgcp_response_pending { |
| 50 | struct llist_head entry; |
| 51 | |
| 52 | mgcp_trans_id_t trans_id; |
| 53 | mgcp_response_cb_t response_cb; |
| 54 | void *priv; |
| 55 | }; |
| 56 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 57 | int mgcp_client_rx(struct mgcp_client *mgcp, struct msgb *msg); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 58 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 59 | struct mgcp_response_pending * mgcp_client_pending_add( |
| 60 | struct mgcp_client *mgcp, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 61 | mgcp_trans_id_t trans_id, |
| 62 | mgcp_response_cb_t response_cb, |
| 63 | void *priv); |
Neels Hofmeyr | 18717f5 | 2023-12-07 02:32:00 +0100 | [diff] [blame] | 64 | |
| 65 | #define MGCP_MSG_PRESENCE_ENDPOINT 0x0001 |
| 66 | #define MGCP_MSG_PRESENCE_CALL_ID 0x0002 |
| 67 | #define MGCP_MSG_PRESENCE_CONN_ID 0x0004 |
| 68 | #define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008 |
| 69 | #define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010 |
| 70 | #define MGCP_MSG_PRESENCE_CONN_MODE 0x0020 |
| 71 | #define MGCP_MSG_PRESENCE_X_OSMO_OSMUX_CID 0x4000 |
| 72 | #define MGCP_MSG_PRESENCE_X_OSMO_IGN 0x8000 |
| 73 | |
| 74 | struct mgcp_msg { |
| 75 | enum mgcp_verb verb; |
| 76 | /* See MGCP_MSG_PRESENCE_* constants */ |
| 77 | uint32_t presence; |
| 78 | char endpoint[MGCP_ENDPOINT_MAXLEN]; |
| 79 | unsigned int call_id; |
| 80 | char *conn_id; |
| 81 | uint16_t audio_port; |
| 82 | char *audio_ip; |
| 83 | enum mgcp_connection_mode conn_mode; |
| 84 | unsigned int ptime; |
Neels Hofmeyr | 18717f5 | 2023-12-07 02:32:00 +0100 | [diff] [blame] | 85 | struct ptmap ptmap[MGCP_MAX_CODECS]; |
| 86 | unsigned int ptmap_len; |
| 87 | uint32_t x_osmo_ign; |
| 88 | bool x_osmo_osmux_use; |
| 89 | int x_osmo_osmux_cid; /* -1 is wildcard */ |
| 90 | bool param_present; |
| 91 | struct mgcp_codec_param param; |
| 92 | }; |
| 93 | |
| 94 | int mgcp_response_parse_params(struct mgcp_response *r); |
| 95 | |
| 96 | int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg, |
| 97 | mgcp_response_cb_t response_cb, void *priv); |
| 98 | int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id); |
| 99 | |
| 100 | struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg); |
| 101 | mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg); |