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; |
| 15 | |
| 16 | extern 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 | */ |
| 27 | struct 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 Hofmeyr | f50d130 | 2019-05-09 16:23:11 +0200 | [diff] [blame] | 37 | /* Events dispatched to the parent fi, see call_leg_alloc() doc. */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 38 | uint32_t parent_event_rtp_addr_available; |
| 39 | uint32_t parent_event_rtp_complete; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 40 | |
| 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 Pedrol | a3cdab4 | 2019-05-09 17:54:08 +0200 | [diff] [blame] | 47 | |
| 48 | bool ran_peer_supports_osmux; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | enum 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 | |
| 58 | void call_leg_init(struct gsm_network *net); |
| 59 | |
| 60 | struct 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 Hofmeyr | 265a4c7 | 2019-05-09 16:20:51 +0200 | [diff] [blame] | 63 | uint32_t parent_event_rtp_complete); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 64 | |
| 65 | void 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 Hofmeyr | 265a4c7 | 2019-05-09 16:20:51 +0200 | [diff] [blame] | 69 | uint32_t parent_event_rtp_complete); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 70 | |
| 71 | int 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 | |
| 74 | int call_leg_ensure_rtp_alloc(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, |
| 75 | struct gsm_trans *for_trans); |
| 76 | int call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans, |
Neels Hofmeyr | 7c8df44 | 2019-08-30 01:05:41 +0200 | [diff] [blame] | 77 | const enum mgcp_codecs *codec_if_known, const struct osmo_sockaddr_str *remote_addr_if_known); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 78 | struct osmo_sockaddr_str *call_leg_local_ip(struct call_leg *cl, enum rtp_direction dir); |
| 79 | |
| 80 | void call_leg_rtp_stream_gone(struct call_leg *cl, struct rtp_stream *rtps); |
| 81 | void call_leg_release(struct call_leg *cl); |