blob: c3619bbc6f6d0d651a44145505c4734cbd6f0bb6 [file] [log] [blame]
Neels Hofmeyre9920f22017-07-10 15:07:22 +02001#pragma once
2
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +02003#include <osmocom/core/write_queue.h>
Pau Espin Pedrol563386e2023-06-14 12:20:49 +02004#include <osmocom/core/timer.h>
Neels Hofmeyrd95ab1e2017-09-22 00:52:54 +02005
Neels Hofmeyre9920f22017-07-10 15:07:22 +02006#define MSGB_CB_MGCP_TRANS_ID 0
7
Philipp Maier3f2c15f2021-07-22 11:53:07 +02008/* Struct that holds one endpoint name */
9struct reset_ep {
10 struct llist_head list;
11 char name[MGCP_ENDPOINT_MAXLEN];
12};
13
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020014struct mgcp_client {
15 struct mgcp_client_conf actual;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020016 struct osmo_wqueue wq;
17 mgcp_trans_id_t next_trans_id;
18 struct llist_head responses_pending;
Pau Espin Pedrol35bd2522022-10-13 17:26:33 +020019 struct mgcp_client_pool_member *pool_member;
Pau Espin Pedrol563386e2023-06-14 12:20:49 +020020 struct osmo_timer_list keepalive_tx_timer;
21 struct osmo_timer_list keepalive_rx_timer;
22 bool conn_up;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020023};
24
Neels Hofmeyr18717f52023-12-07 02:32:00 +010025struct 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
35struct 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;
41 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
42 unsigned int codecs_len;
43 struct ptmap ptmap[MGCP_MAX_CODECS];
44 unsigned int ptmap_len;
45};
46
47/* Invoked when an MGCP response is received or sending failed. When the
48 * response is passed as NULL, this indicates failure during transmission. */
49typedef void (*mgcp_response_cb_t)(struct mgcp_response *response, void *priv);
50
Neels Hofmeyre9920f22017-07-10 15:07:22 +020051struct mgcp_response_pending {
52 struct llist_head entry;
53
54 mgcp_trans_id_t trans_id;
55 mgcp_response_cb_t response_cb;
56 void *priv;
57};
58
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020059int mgcp_client_rx(struct mgcp_client *mgcp, struct msgb *msg);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020060
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020061struct mgcp_response_pending * mgcp_client_pending_add(
62 struct mgcp_client *mgcp,
Neels Hofmeyre9920f22017-07-10 15:07:22 +020063 mgcp_trans_id_t trans_id,
64 mgcp_response_cb_t response_cb,
65 void *priv);
Neels Hofmeyr18717f52023-12-07 02:32:00 +010066
67#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
68#define MGCP_MSG_PRESENCE_CALL_ID 0x0002
69#define MGCP_MSG_PRESENCE_CONN_ID 0x0004
70#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
71#define MGCP_MSG_PRESENCE_AUDIO_PORT 0x0010
72#define MGCP_MSG_PRESENCE_CONN_MODE 0x0020
73#define MGCP_MSG_PRESENCE_X_OSMO_OSMUX_CID 0x4000
74#define MGCP_MSG_PRESENCE_X_OSMO_IGN 0x8000
75
76struct mgcp_msg {
77 enum mgcp_verb verb;
78 /* See MGCP_MSG_PRESENCE_* constants */
79 uint32_t presence;
80 char endpoint[MGCP_ENDPOINT_MAXLEN];
81 unsigned int call_id;
82 char *conn_id;
83 uint16_t audio_port;
84 char *audio_ip;
85 enum mgcp_connection_mode conn_mode;
86 unsigned int ptime;
87 enum mgcp_codecs codecs[MGCP_MAX_CODECS];
88 unsigned int codecs_len;
89 struct ptmap ptmap[MGCP_MAX_CODECS];
90 unsigned int ptmap_len;
91 uint32_t x_osmo_ign;
92 bool x_osmo_osmux_use;
93 int x_osmo_osmux_cid; /* -1 is wildcard */
94 bool param_present;
95 struct mgcp_codec_param param;
96};
97
98int mgcp_response_parse_params(struct mgcp_response *r);
99
100int mgcp_client_tx(struct mgcp_client *mgcp, struct msgb *msg,
101 mgcp_response_cb_t response_cb, void *priv);
102int mgcp_client_cancel(struct mgcp_client *mgcp, mgcp_trans_id_t trans_id);
103
104struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
105mgcp_trans_id_t mgcp_msg_trans_id(struct msgb *msg);