Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <stdbool.h> |
| 5 | |
| 6 | #include <osmocom/core/tdef.h> |
| 7 | |
| 8 | struct osmo_fsm_inst; |
| 9 | struct osmo_sockaddr_str; |
| 10 | struct osmo_mgcpc_ep; |
| 11 | struct gsm_network; |
| 12 | struct gsm_trans; |
| 13 | struct rtp_stream; |
| 14 | enum rtp_direction; |
Neels Hofmeyr | 62bfa37 | 2022-10-31 18:51:07 +0100 | [diff] [blame] | 15 | struct sdp_audio_codecs; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 16 | |
| 17 | extern 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 | */ |
| 28 | struct 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 Hofmeyr | f50d130 | 2019-05-09 16:23:11 +0200 | [diff] [blame] | 38 | /* Events dispatched to the parent fi, see call_leg_alloc() doc. */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 39 | uint32_t parent_event_rtp_addr_available; |
| 40 | uint32_t parent_event_rtp_complete; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 41 | |
| 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 Pedrol | a3cdab4 | 2019-05-09 17:54:08 +0200 | [diff] [blame] | 48 | |
| 49 | bool ran_peer_supports_osmux; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | enum 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 | |
| 59 | void call_leg_init(struct gsm_network *net); |
| 60 | |
| 61 | struct 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 Hofmeyr | 265a4c7 | 2019-05-09 16:20:51 +0200 | [diff] [blame] | 64 | uint32_t parent_event_rtp_complete); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 65 | |
| 66 | void 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 Hofmeyr | 265a4c7 | 2019-05-09 16:20:51 +0200 | [diff] [blame] | 70 | uint32_t parent_event_rtp_complete); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 71 | |
| 72 | int 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 | |
| 75 | int call_leg_ensure_rtp_alloc(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, |
| 76 | struct gsm_trans *for_trans); |
| 77 | int call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans, |
Neels Hofmeyr | 62bfa37 | 2022-10-31 18:51:07 +0100 | [diff] [blame] | 78 | const struct sdp_audio_codecs *codecs_if_known, |
| 79 | const struct osmo_sockaddr_str *remote_addr_if_known); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 80 | struct osmo_sockaddr_str *call_leg_local_ip(struct call_leg *cl, enum rtp_direction dir); |
| 81 | |
| 82 | void call_leg_rtp_stream_gone(struct call_leg *cl, struct rtp_stream *rtps); |
| 83 | void call_leg_release(struct call_leg *cl); |