blob: 61107ee2a539f74f3c9bc01f71255f02e5621e29 [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
37 uint32_t parent_event_rtp_addr_available;
38 uint32_t parent_event_rtp_complete;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010039
40 /* For internal MNCC, if RTP addresses for endpoints become assigned by the MGW, implicitly notify the other
41 * call leg's RTP_TO_CN side rtp_stream with rtp_stream_remote_addr_available(). */
42 struct call_leg *local_bridge;
43
44 /* Prevent events from deallocating for certain release code paths, to prevent use-after-free problems. */
45 bool deallocating;
46};
47
48enum call_leg_event {
49 CALL_LEG_EV_RTP_STREAM_ADDR_AVAILABLE,
50 CALL_LEG_EV_RTP_STREAM_ESTABLISHED,
51 CALL_LEG_EV_RTP_STREAM_GONE,
52 CALL_LEG_EV_MGW_ENDPOINT_GONE,
53};
54
55void call_leg_init(struct gsm_network *net);
56
57struct call_leg *call_leg_alloc(struct osmo_fsm_inst *parent_fi,
58 uint32_t parent_event_term,
59 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020060 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010061
62void call_leg_reparent(struct call_leg *cl,
63 struct osmo_fsm_inst *parent_fi,
64 uint32_t parent_event_term,
65 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020066 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010067
68int call_leg_local_bridge(struct call_leg *cl1, uint32_t call_id1, struct gsm_trans *trans1,
69 struct call_leg *cl2, uint32_t call_id2, struct gsm_trans *trans2);
70
71int call_leg_ensure_rtp_alloc(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id,
72 struct gsm_trans *for_trans);
73int call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans,
74 const enum mgcp_codecs *codec_if_known, const struct osmo_sockaddr_str *remote_port_if_known);
75struct osmo_sockaddr_str *call_leg_local_ip(struct call_leg *cl, enum rtp_direction dir);
76
77void call_leg_rtp_stream_gone(struct call_leg *cl, struct rtp_stream *rtps);
78void call_leg_release(struct call_leg *cl);