blob: f35816c47d99e46312d64f1a43795d13e5a57258 [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5
6#include <osmocom/core/tdef.h>
7
8struct osmo_fsm_inst;
9struct osmo_sockaddr_str;
10struct osmo_mgcpc_ep;
11struct gsm_network;
12struct gsm_trans;
13struct rtp_stream;
14enum rtp_direction;
15
16extern struct osmo_tdef g_mgw_tdefs[];
17
18/* All sides of an MGW endpoint, connecting remote RTP peers via the MGW.
19 *
20 * BSC MGW PBX
21 * CI CI
22 * [MGW-endpoint]
23 * [--rtp_stream--] [--rtp_stream--]
24 * [----------------call_leg----------------]
25 *
26 */
27struct call_leg {
28 struct osmo_fsm_inst *fi;
29
30 struct osmo_mgcpc_ep *mgw_endpoint;
31
32 /* Array indexed by enum rtp_direction. */
33 struct rtp_stream *rtp[2];
34 /* Array indexed by enum rtp_direction. */
35 enum mgcp_connection_mode crcx_conn_mode[2];
36
Neels Hofmeyrf50d1302019-05-09 16:23:11 +020037 /* Events dispatched to the parent fi, see call_leg_alloc() doc. */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010038 uint32_t parent_event_rtp_addr_available;
39 uint32_t parent_event_rtp_complete;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010040
41 /* For internal MNCC, if RTP addresses for endpoints become assigned by the MGW, implicitly notify the other
42 * call leg's RTP_TO_CN side rtp_stream with rtp_stream_remote_addr_available(). */
43 struct call_leg *local_bridge;
44
45 /* Prevent events from deallocating for certain release code paths, to prevent use-after-free problems. */
46 bool deallocating;
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +020047
48 bool ran_peer_supports_osmux;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010049};
50
51enum call_leg_event {
52 CALL_LEG_EV_RTP_STREAM_ADDR_AVAILABLE,
53 CALL_LEG_EV_RTP_STREAM_ESTABLISHED,
54 CALL_LEG_EV_RTP_STREAM_GONE,
55 CALL_LEG_EV_MGW_ENDPOINT_GONE,
56};
57
58void call_leg_init(struct gsm_network *net);
59
60struct call_leg *call_leg_alloc(struct osmo_fsm_inst *parent_fi,
61 uint32_t parent_event_term,
62 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020063 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010064
65void call_leg_reparent(struct call_leg *cl,
66 struct osmo_fsm_inst *parent_fi,
67 uint32_t parent_event_term,
68 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020069 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010070
71int call_leg_local_bridge(struct call_leg *cl1, uint32_t call_id1, struct gsm_trans *trans1,
72 struct call_leg *cl2, uint32_t call_id2, struct gsm_trans *trans2);
73
74int call_leg_ensure_rtp_alloc(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id,
75 struct gsm_trans *for_trans);
76int call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans,
77 const enum mgcp_codecs *codec_if_known, const struct osmo_sockaddr_str *remote_port_if_known);
78struct osmo_sockaddr_str *call_leg_local_ip(struct call_leg *cl, enum rtp_direction dir);
79
80void call_leg_rtp_stream_gone(struct call_leg *cl, struct rtp_stream *rtps);
81void call_leg_release(struct call_leg *cl);