blob: d8380f52b2c84219eba30f605c6cf46a5c32aa6c [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;
47};
48
49enum call_leg_event {
50 CALL_LEG_EV_RTP_STREAM_ADDR_AVAILABLE,
51 CALL_LEG_EV_RTP_STREAM_ESTABLISHED,
52 CALL_LEG_EV_RTP_STREAM_GONE,
53 CALL_LEG_EV_MGW_ENDPOINT_GONE,
54};
55
56void call_leg_init(struct gsm_network *net);
57
58struct call_leg *call_leg_alloc(struct osmo_fsm_inst *parent_fi,
59 uint32_t parent_event_term,
60 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020061 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010062
63void call_leg_reparent(struct call_leg *cl,
64 struct osmo_fsm_inst *parent_fi,
65 uint32_t parent_event_term,
66 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020067 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010068
69int call_leg_local_bridge(struct call_leg *cl1, uint32_t call_id1, struct gsm_trans *trans1,
70 struct call_leg *cl2, uint32_t call_id2, struct gsm_trans *trans2);
71
72int call_leg_ensure_rtp_alloc(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id,
73 struct gsm_trans *for_trans);
74int call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans,
75 const enum mgcp_codecs *codec_if_known, const struct osmo_sockaddr_str *remote_port_if_known);
76struct osmo_sockaddr_str *call_leg_local_ip(struct call_leg *cl, enum rtp_direction dir);
77
78void call_leg_rtp_stream_gone(struct call_leg *cl, struct rtp_stream *rtps);
79void call_leg_release(struct call_leg *cl);