blob: 2b2f45d3105a03e8c48b26ec925d5e2409ecc372 [file] [log] [blame]
Andreas Eversberge24636c2023-04-23 12:20:55 +02001/* Handle a call via VGCS/VBCS (Voice Group/Broadcast Call Service). */
2/*
3 * (C) 2023 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * All Rights Reserved
5 *
6 * SPDX-License-Identifier: AGPL-3.0+
7 *
8 * Author: Andreas Eversberg
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/transaction.h>
26
27#define GSM44068_ALLOC_SIZE 2048
28#define GSM44068_ALLOC_HEADROOM 256
29
30static inline struct msgb *gsm44068_msgb_alloc_name(const char *name)
31{
32 return msgb_alloc_headroom(GSM44068_ALLOC_SIZE, GSM44068_ALLOC_HEADROOM, name);
33}
34
35/* VGCS/VBS "call control" connection to each BSS */
36struct vgcs_bss {
37 struct llist_head list; /* List entry */
38 struct llist_head cell_list; /* List of cells */
39 struct gsm_trans *trans; /* Back pointer to transaction */
40 struct osmo_fsm_inst *fi; /* State machine of each BSS */
41 struct ran_conn *conn; /* RAN ("SCCP") connection */
42 enum trans_type trans_type; /* Transaction type */
43 uint32_t callref; /* Callref */
44 int pc; /* Point code for debug purpose */
45};
46
47/* VGCS/VBS "resource control" connection to each cell in BSS */
48struct vgcs_bss_cell {
49 struct llist_head list_bss; /* List entry in vgcs_bss */
50 struct llist_head list_mgw; /* List entry in MGW endpoint */
51 struct vgcs_bss *bss; /* Back pointer to vgcs_bss */
52 struct vgcs_mgw_ep *mgw; /* Back pointer to vgcs_mgw_ep */
53 struct osmo_fsm_inst *fi; /* State machine of each cell */
54 int cell_id; /* Id of cell (BTS) to use */
55 struct ran_conn *conn; /* RAN ("SCCP") connection */
56 enum trans_type trans_type; /* Transaction type */
57 uint32_t callref; /* Callref */
58 int call_id; /* Id of call (used for MGW connections) */
59 int pc; /* Point code for debug purpose */
60 bool assigned; /* Flags if assignment is complete */
61 struct rtp_stream *rtps; /* MGW connection process */
62};
63
64/* VGCS/VBS MGW endpoint for each call */
65struct vgcs_mgw_ep {
66 struct llist_head cell_list; /* List of cells with connections */
67 struct llist_head list; /* List entry */
68 struct osmo_fsm_inst *fi; /* State machine of each cell */
69 struct osmo_mgcpc_ep *mgw_ep; /* MGW endpoint */
70};
71
72/* Events for the GCC/BCC state machine.
73 * There is no primitive definition like MNGCC-* oder MNBCC-* in the standard. */
74enum vgcs_gcc_fsm_event {
75 /* The network sets up a call. */
76 VGCS_GCC_EV_NET_SETUP,
77 /* The network requests termination. */
78 VGCS_GCC_EV_NET_TERM,
79 /* The user sets up a call. */
80 VGCS_GCC_EV_USER_SETUP,
81 /* The user requests termination. */
82 VGCS_GCC_EV_USER_TERM,
83 /* BSS completed call establishment (all BSCs) */
84 VGCS_GCC_EV_BSS_ESTABLISHED,
85 /* Assignment was completed. */
86 VGCS_GCC_EV_BSS_ASSIGN_CPL,
87 /* Assignment failed. */
88 VGCS_GCC_EV_BSS_ASSIGN_FAIL,
89 /* BSS released call establishment (all BSCs) */
90 VGCS_GCC_EV_BSS_RELEASED,
91 /* Inactivity timeout */
92 VGCS_GCC_EV_TIMEOUT,
93};
94
95/* 3GPP TS 44.068 6.1.2.2 States of GCC/BCC */
96enum vgcs_gcc_fsm_state {
97 /* No call. Initial state when instance is created. */
98 VGCS_GCC_ST_N0_NULL = 0,
99 /* An MS wants to establish a call. */
100 VGCS_GCC_ST_N1_CALL_INITIATED,
101 /* Call established in at least one cell. */
102 VGCS_GCC_ST_N2_CALL_ACTIVE,
103 /* Channel activation is requested, CONNECT already sent to MS. */
104 VGCS_GCC_ST_N3_CALL_EST_PROC,
105 /* Call termination is requested, waiting for all cells to confirm. */
106 VGCS_GCC_ST_N4_TERMINATION_REQ,
107};
108
109const char *vgcs_bcc_gcc_state_name(struct osmo_fsm_inst *fi);
110
111/* Events for the VGCS/VBS "call control" state machine */
112enum vgcs_bss_fsm_event {
113 /* Start a VGCS/VBS call using VGCS/VBS SETUP message */
114 VGCS_BSS_EV_SETUP,
115 /* VGCS/VBS SETUP ACK is received */
116 VGCS_BSS_EV_SETUP_ACK,
117 /* VGCS/VBS SETUP REFUSE is received */
118 VGCS_BSS_EV_SETUP_REFUSE,
119 /* VGCS/VBS ASSIGNMENT complete or failed */
120 VGCS_BSS_EV_ACTIVE_OR_FAIL,
121 /* Talker request */
122 VGCS_BSS_EV_UL_REQUEST,
123 /* Talker established uplink */
124 VGCS_BSS_EV_UL_REQUEST_CNF,
125 /* Talker send app data */
126 VGCS_BSS_EV_UL_APP_DATA,
127 /* Talker send signaling data */
128 VGCS_BSS_EV_BSS_DTAP,
129 /* Talker becomes listener */
130 VGCS_BSS_EV_UL_RELEASE,
131 /* Release channel towards BSS */
132 VGCS_BSS_EV_CLEAR,
133 /* Channel closed from BSS */
134 VGCS_BSS_EV_CLOSE,
135 /* Release is complete */
136 VGCS_BSS_EV_RELEASED,
137};
138
139/* States of the VGCS/VBS "call control" state machine */
140enum vgcs_bss_fsm_state {
141 /* No call. Initial state when instance is created. */
142 VGCS_BSS_ST_NULL = 0,
143 /* VGCS/VBS SETUP is sent towards BSC */
144 VGCS_BSS_ST_SETUP,
145 /* VGCS/VBS ASSIGNMENT REQUEST is sent towards BSC */
146 VGCS_BSS_ST_ASSIGNMENT,
147 /* VGCS/VBS is establised */
148 VGCS_BSS_ST_ACTIVE,
149 /* CLEAR COMMAND was sent */
150 VGCS_BSS_ST_RELEASE,
151};
152
153/* Events for the VGCS/VBS "resource control" state machine */
154enum vgcs_cell_fsm_event {
155 /* RTP stream gone */
156 VGCS_CELL_EV_RTP_STREAM_GONE,
157 /* RTP stream remote addr available */
158 VGCS_CELL_EV_RTP_STREAM_ADDR_AVAILABLE,
159 /* RTP stream established */
160 VGCS_CELL_EV_RTP_STREAM_ESTABLISHED,
161 /* Start a VGCS/VBS channel using VGCS/VBS ASSIGNMENT message */
162 VGCS_CELL_EV_ASSIGN,
163 /* VGCS/VBS ASSIGNMENT RESULT is received */
164 VGCS_CELL_EV_ASSIGN_RES,
165 /* VGCS/VBS ASSIGNMENT FAILURE is received */
166 VGCS_CELL_EV_ASSIGN_FAIL,
167 /* Release channel towards BSS */
168 VGCS_CELL_EV_CLEAR,
169 /* Channel closed from BSS */
170 VGCS_CELL_EV_CLOSE,
171 /* Release is complete */
172 VGCS_CELL_EV_RELEASED,
173};
174
175/* States of the VGCS/VBS "resource control" state machine */
176enum vgcs_cell_fsm_state {
177 /* No call. Initial state when instance is created. */
178 VGCS_CELL_ST_NULL = 0,
179 /* VGCS/VBS ASSIGNMENT REQUEST is sent towards BSC */
180 VGCS_CELL_ST_ASSIGNMENT,
181 /* Channel is establised */
182 VGCS_CELL_ST_ACTIVE,
183 /* CLEAR COMMAND was sent */
184 VGCS_CELL_ST_RELEASE,
185};
186
187/* Events for the VGCS/VBS MGW endpoint state machine */
188enum vgcs_mgw_ep_fsm_event {
189 /* MGW endpoint gone */
190 VGCS_MGW_EP_EV_FREE,
191 /* Destroy MGW endpoint */
192 VGCS_MGW_EP_EV_CLEAR,
193};
194
195/* States of the VGCS/VBS MGW endpoint state machine */
196enum vgcs_mgw_ep_fsm_state {
197 VGCS_MGW_EP_ST_NULL = 0,
198 /* MGW endpoint allocated */
199 VGCS_MGW_EP_ST_ACTIVE,
200};
201
202const char *gsm44068_group_id_string(uint32_t callref);
203
204struct gcr;
205
206int gsm44068_rcv_rr(struct msc_a *msc_a, struct msgb *msg);
207int gsm44068_rcv_bcc_gcc(struct msc_a *msc_a, struct gsm_trans *trans, struct msgb *msg);
208const char *vgcs_vty_initiate(struct gsm_network *gsmnet, struct gcr *gcr);
209const char *vgcs_vty_terminate(struct gsm_network *gsmnet, struct gcr *gcr);
210void gsm44068_bcc_gcc_trans_free(struct gsm_trans *trans);
211
212void vgcs_vbs_setup_ack(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
213void vgcs_vbs_setup_refuse(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
214void vgcs_vbs_assign_result(struct vgcs_bss_cell *cell, const struct ran_msg *ran_msg);
215void vgcs_vbs_assign_fail(struct vgcs_bss_cell *cell, const struct ran_msg *ran_msg);
216void vgcs_vbs_queuing_ind(struct vgcs_bss_cell *cell);
217void vgcs_uplink_request(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
218void vgcs_uplink_request_cnf(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
219void vgcs_app_data(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
220void vgcs_bss_dtap(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
221void vgcs_uplink_release_ind(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
222void vgcs_vbs_assign_status(struct vgcs_bss_cell *cell, const struct ran_msg *ran_msg);
223void vgcs_vbs_clear_req_channel(struct vgcs_bss_cell *cell, const struct ran_msg *ran_msg);
224void vgcs_vbs_clear_cpl_channel(struct vgcs_bss_cell *cell, const struct ran_msg *ran_msg);
225void vgcs_vbs_clear_req(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
226void vgcs_vbs_clear_cpl(struct vgcs_bss *bss, const struct ran_msg *ran_msg);
227void vgcs_vbs_caller_assign_cpl(struct gsm_trans *trans);
228void vgcs_vbs_caller_assign_fail(struct gsm_trans *trans);