blob: c7d3b97396c2c3cf8e5cc984bbde817fe38eab84 [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;
Neels Hofmeyr62bfa372022-10-31 18:51:07 +010015struct sdp_audio_codecs;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010016
17extern struct osmo_tdef g_mgw_tdefs[];
18
19/* All sides of an MGW endpoint, connecting remote RTP peers via the MGW.
20 *
21 * BSC MGW PBX
22 * CI CI
23 * [MGW-endpoint]
24 * [--rtp_stream--] [--rtp_stream--]
25 * [----------------call_leg----------------]
26 *
27 */
28struct call_leg {
29 struct osmo_fsm_inst *fi;
30
31 struct osmo_mgcpc_ep *mgw_endpoint;
32
33 /* Array indexed by enum rtp_direction. */
34 struct rtp_stream *rtp[2];
35 /* Array indexed by enum rtp_direction. */
36 enum mgcp_connection_mode crcx_conn_mode[2];
37
Neels Hofmeyrf50d1302019-05-09 16:23:11 +020038 /* Events dispatched to the parent fi, see call_leg_alloc() doc. */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010039 uint32_t parent_event_rtp_addr_available;
40 uint32_t parent_event_rtp_complete;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010041
42 /* For internal MNCC, if RTP addresses for endpoints become assigned by the MGW, implicitly notify the other
43 * call leg's RTP_TO_CN side rtp_stream with rtp_stream_remote_addr_available(). */
44 struct call_leg *local_bridge;
45
46 /* Prevent events from deallocating for certain release code paths, to prevent use-after-free problems. */
47 bool deallocating;
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +020048
49 bool ran_peer_supports_osmux;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010050};
51
52enum call_leg_event {
53 CALL_LEG_EV_RTP_STREAM_ADDR_AVAILABLE,
54 CALL_LEG_EV_RTP_STREAM_ESTABLISHED,
55 CALL_LEG_EV_RTP_STREAM_GONE,
56 CALL_LEG_EV_MGW_ENDPOINT_GONE,
57};
58
59void call_leg_init(struct gsm_network *net);
60
61struct call_leg *call_leg_alloc(struct osmo_fsm_inst *parent_fi,
62 uint32_t parent_event_term,
63 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020064 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010065
66void call_leg_reparent(struct call_leg *cl,
67 struct osmo_fsm_inst *parent_fi,
68 uint32_t parent_event_term,
69 uint32_t parent_event_rtp_addr_available,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +020070 uint32_t parent_event_rtp_complete);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010071
72int call_leg_local_bridge(struct call_leg *cl1, uint32_t call_id1, struct gsm_trans *trans1,
73 struct call_leg *cl2, uint32_t call_id2, struct gsm_trans *trans2);
74
75int call_leg_ensure_rtp_alloc(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id,
76 struct gsm_trans *for_trans);
77int call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans,
Neels Hofmeyr62bfa372022-10-31 18:51:07 +010078 const struct sdp_audio_codecs *codecs_if_known,
79 const struct osmo_sockaddr_str *remote_addr_if_known);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010080struct osmo_sockaddr_str *call_leg_local_ip(struct call_leg *cl, enum rtp_direction dir);
81
82void call_leg_rtp_stream_gone(struct call_leg *cl, struct rtp_stream *rtps);
83void call_leg_release(struct call_leg *cl);