blob: 084edd5e1c24448305ccf415e5032c63b68cac0a [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001/* Handle an MNCC managed call (external MNCC). */
2/*
Vadim Yanitskiy999a5932023-05-18 17:22:26 +07003 * (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01004 * All Rights Reserved
5 *
6 * SPDX-License-Identifier: AGPL-3.0+
7 *
8 * Author: Neels Hofmeyr
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
19 *
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23#pragma once
24
Neels Hofmeyr5e19b9a2019-04-27 19:09:14 +020025#include <osmocom/mgcp_client/mgcp_client.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010026#include <osmocom/msc/mncc.h>
27#include <osmocom/msc/mncc_call.h>
28
29struct osmo_fsm_inst;
30struct rtp_stream;
31
32#define LOG_MNCC_CALL(MNCC, LEVEL, FMT, ARGS...) \
33 LOGPFSML((MNCC) ? (MNCC)->fi : NULL, LEVEL, FMT, ##ARGS)
34
35enum mncc_call_fsm_event {
36 /* An MNCC message was received from the MNCC socket. The data argument is a const union mncc_msg* pointing at
37 * the message contents. */
38 MNCC_CALL_EV_RX_MNCC_MSG,
39
40 /* The user has invoked mncc_call_outgoing_start(); this event exists to ensure that the FSM is in a state that
41 * allows starting a new outgoing call. */
42 MNCC_CALL_EV_OUTGOING_START,
43 /* The MNCC server has sent an MNCC_ALERT_REQ. */
44 MNCC_CALL_EV_OUTGOING_ALERTING,
45 /* The MNCC server has confirmed call setup with an MNCC_SETUP_RSP, we have sent an MNCC_SETUP_COMPL_IND. */
46 MNCC_CALL_EV_OUTGOING_SETUP_COMPLETE,
47
48 /* The user has invoked mncc_call_incoming_start(); this event exists to ensure that the FSM is in a state that
49 * allows starting a new incoming call. */
50 MNCC_CALL_EV_INCOMING_START,
51 /* MNCC server sent an MNCC_SETUP_REQ */
52 MNCC_CALL_EV_INCOMING_SETUP,
53 /* MNCC server confirmed call setup with an MNCC_SETUP_COMPL_REQ */
54 MNCC_CALL_EV_INCOMING_SETUP_COMPLETE,
55
56 /* MNCC server requests call release (Rx MNCC_DISC_REQ) */
57 MNCC_CALL_EV_CN_RELEASE,
58 /* osmo-msc should request call release (Tx MNCC_DISC_IND) */
59 MNCC_CALL_EV_MS_RELEASE,
60};
61
62/* The typical progression of outgoing and incoming calls via MNCC is shown by doc/sequence_charts/mncc_call_fsm.msc */
63enum mncc_call_fsm_state {
64 MNCC_CALL_ST_NOT_STARTED = 0,
65
66 MNCC_CALL_ST_OUTGOING_WAIT_PROCEEDING,
67 MNCC_CALL_ST_OUTGOING_WAIT_COMPLETE,
68
69 MNCC_CALL_ST_INCOMING_WAIT_COMPLETE,
70
71 MNCC_CALL_ST_TALKING,
72
73 MNCC_CALL_ST_WAIT_RELEASE_ACK,
74};
75
76struct mncc_call_incoming_req {
77 bool bearer_cap_present;
78 struct gsm_mncc_bearer_cap bearer_cap;
79
80 bool cccap_present;
81 struct gsm_mncc_cccap cccap;
82
83 struct gsm_mncc setup_req_msg;
84};
85
86struct mncc_call;
87typedef void (* mncc_call_message_cb_t )(struct mncc_call *mncc_call, const union mncc_msg *mncc_msg, void *data);
88
89struct mncc_call {
90 struct llist_head entry;
91
92 struct osmo_fsm_inst *fi;
93 struct vlr_subscr *vsub;
94 struct gsm_network *net;
95
96 /* Details originally passed to mncc_call_outgoing_start(), if any. */
97 struct gsm_mncc outgoing_req;
98
99 uint32_t callref;
100 bool remote_msisdn_present;
101 struct gsm_mncc_number remote_msisdn;
102 bool local_msisdn_present;
103 struct gsm_mncc_number local_msisdn;
104 struct rtp_stream *rtps;
105 bool received_rtp_create;
106
107 mncc_call_message_cb_t message_cb;
108 void *forward_cb_data;
109
110 /* Event to dispatch to the FSM inst parent when the call is complete. Omit event dispatch when negative. See
111 * mncc_call_alloc()'s arg of same name. */
112 int parent_event_call_setup_complete;
113};
114
115void mncc_call_fsm_init(struct gsm_network *net);
116struct mncc_call *mncc_call_alloc(struct vlr_subscr *vsub,
117 struct osmo_fsm_inst *parent,
118 int parent_event_call_setup_complete,
119 uint32_t parent_event_call_released,
120 mncc_call_message_cb_t message_cb, void *forward_cb_data);
121void mncc_call_reparent(struct mncc_call *mncc_call,
122 struct osmo_fsm_inst *new_parent,
123 int parent_event_call_setup_complete,
124 uint32_t parent_event_call_released,
125 mncc_call_message_cb_t message_cb, void *forward_cb_data);
126
127int mncc_call_outgoing_start(struct mncc_call *mncc_call, const struct gsm_mncc *outgoing_req);
128
129int mncc_call_incoming_start(struct mncc_call *mncc_call, const struct mncc_call_incoming_req *incoming_req);
130int mncc_call_incoming_tx_setup_cnf(struct mncc_call *mncc_call, const struct gsm_mncc_number *connected_number);
131
132int mncc_call_set_rtp_stream(struct mncc_call *mncc_call, struct rtp_stream *rtps);
133void mncc_call_detach_rtp_stream(struct mncc_call *mncc_call);
134
135void mncc_call_rx(struct mncc_call *mncc_call, const union mncc_msg *mncc_msg);
136int mncc_call_tx(struct mncc_call *mncc_call, union mncc_msg *mncc_msg);
137int mncc_call_tx_msgt(struct mncc_call *mncc_call, uint32_t msg_type);
138
139struct mncc_call *mncc_call_find_by_callref(uint32_t callref);
140
141void mncc_call_release(struct mncc_call *mncc_call);
Neels Hofmeyr5e19b9a2019-04-27 19:09:14 +0200142
143uint32_t mgcp_codec_to_mncc_payload_msg_type(enum mgcp_codecs codec);