blob: ad0f0f841fc695e12a38c9d60e7bf9afdf6e7c25 [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001/* Handle an MNCC managed call (external MNCC). */
2/*
3 * (C) 2019 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de>
4 * 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
25#include <osmocom/msc/mncc.h>
26#include <osmocom/msc/mncc_call.h>
27
28struct osmo_fsm_inst;
29struct rtp_stream;
30
31#define LOG_MNCC_CALL(MNCC, LEVEL, FMT, ARGS...) \
32 LOGPFSML((MNCC) ? (MNCC)->fi : NULL, LEVEL, FMT, ##ARGS)
33
34enum mncc_call_fsm_event {
35 /* An MNCC message was received from the MNCC socket. The data argument is a const union mncc_msg* pointing at
36 * the message contents. */
37 MNCC_CALL_EV_RX_MNCC_MSG,
38
39 /* The user has invoked mncc_call_outgoing_start(); this event exists to ensure that the FSM is in a state that
40 * allows starting a new outgoing call. */
41 MNCC_CALL_EV_OUTGOING_START,
42 /* The MNCC server has sent an MNCC_ALERT_REQ. */
43 MNCC_CALL_EV_OUTGOING_ALERTING,
44 /* The MNCC server has confirmed call setup with an MNCC_SETUP_RSP, we have sent an MNCC_SETUP_COMPL_IND. */
45 MNCC_CALL_EV_OUTGOING_SETUP_COMPLETE,
46
47 /* The user has invoked mncc_call_incoming_start(); this event exists to ensure that the FSM is in a state that
48 * allows starting a new incoming call. */
49 MNCC_CALL_EV_INCOMING_START,
50 /* MNCC server sent an MNCC_SETUP_REQ */
51 MNCC_CALL_EV_INCOMING_SETUP,
52 /* MNCC server confirmed call setup with an MNCC_SETUP_COMPL_REQ */
53 MNCC_CALL_EV_INCOMING_SETUP_COMPLETE,
54
55 /* MNCC server requests call release (Rx MNCC_DISC_REQ) */
56 MNCC_CALL_EV_CN_RELEASE,
57 /* osmo-msc should request call release (Tx MNCC_DISC_IND) */
58 MNCC_CALL_EV_MS_RELEASE,
59};
60
61/* The typical progression of outgoing and incoming calls via MNCC is shown by doc/sequence_charts/mncc_call_fsm.msc */
62enum mncc_call_fsm_state {
63 MNCC_CALL_ST_NOT_STARTED = 0,
64
65 MNCC_CALL_ST_OUTGOING_WAIT_PROCEEDING,
66 MNCC_CALL_ST_OUTGOING_WAIT_COMPLETE,
67
68 MNCC_CALL_ST_INCOMING_WAIT_COMPLETE,
69
70 MNCC_CALL_ST_TALKING,
71
72 MNCC_CALL_ST_WAIT_RELEASE_ACK,
73};
74
75struct mncc_call_incoming_req {
76 bool bearer_cap_present;
77 struct gsm_mncc_bearer_cap bearer_cap;
78
79 bool cccap_present;
80 struct gsm_mncc_cccap cccap;
81
82 struct gsm_mncc setup_req_msg;
83};
84
85struct mncc_call;
86typedef void (* mncc_call_message_cb_t )(struct mncc_call *mncc_call, const union mncc_msg *mncc_msg, void *data);
87
88struct mncc_call {
89 struct llist_head entry;
90
91 struct osmo_fsm_inst *fi;
92 struct vlr_subscr *vsub;
93 struct gsm_network *net;
94
95 /* Details originally passed to mncc_call_outgoing_start(), if any. */
96 struct gsm_mncc outgoing_req;
97
98 uint32_t callref;
99 bool remote_msisdn_present;
100 struct gsm_mncc_number remote_msisdn;
101 bool local_msisdn_present;
102 struct gsm_mncc_number local_msisdn;
103 struct rtp_stream *rtps;
104 bool received_rtp_create;
105
106 mncc_call_message_cb_t message_cb;
107 void *forward_cb_data;
108
109 /* Event to dispatch to the FSM inst parent when the call is complete. Omit event dispatch when negative. See
110 * mncc_call_alloc()'s arg of same name. */
111 int parent_event_call_setup_complete;
112};
113
114void mncc_call_fsm_init(struct gsm_network *net);
115struct mncc_call *mncc_call_alloc(struct vlr_subscr *vsub,
116 struct osmo_fsm_inst *parent,
117 int parent_event_call_setup_complete,
118 uint32_t parent_event_call_released,
119 mncc_call_message_cb_t message_cb, void *forward_cb_data);
120void mncc_call_reparent(struct mncc_call *mncc_call,
121 struct osmo_fsm_inst *new_parent,
122 int parent_event_call_setup_complete,
123 uint32_t parent_event_call_released,
124 mncc_call_message_cb_t message_cb, void *forward_cb_data);
125
126int mncc_call_outgoing_start(struct mncc_call *mncc_call, const struct gsm_mncc *outgoing_req);
127
128int mncc_call_incoming_start(struct mncc_call *mncc_call, const struct mncc_call_incoming_req *incoming_req);
129int mncc_call_incoming_tx_setup_cnf(struct mncc_call *mncc_call, const struct gsm_mncc_number *connected_number);
130
131int mncc_call_set_rtp_stream(struct mncc_call *mncc_call, struct rtp_stream *rtps);
132void mncc_call_detach_rtp_stream(struct mncc_call *mncc_call);
133
134void mncc_call_rx(struct mncc_call *mncc_call, const union mncc_msg *mncc_msg);
135int mncc_call_tx(struct mncc_call *mncc_call, union mncc_msg *mncc_msg);
136int mncc_call_tx_msgt(struct mncc_call *mncc_call, uint32_t msg_type);
137
138struct mncc_call *mncc_call_find_by_callref(uint32_t callref);
139
140void mncc_call_release(struct mncc_call *mncc_call);