blob: aa529e494ecc53a2e7365b6364027278d6deb9de [file] [log] [blame]
Vadim Yanitskiy2eaee702019-02-14 16:44:45 +07001#pragma once
Harald Welte9ee48252009-07-23 21:25:08 +02002
Neels Hofmeyr90843962017-09-04 15:04:35 +02003#include <osmocom/msc/gsm_data.h>
4#include <osmocom/msc/gsm_subscriber.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +01005#include <osmocom/core/linuxlist.h>
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01006#include <osmocom/core/fsm.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +02007#include <osmocom/msc/gsm_04_11.h>
8#include <osmocom/msc/mncc.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01009#include <osmocom/msc/msc_a.h>
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010010#include <osmocom/msc/debug.h>
Neels Hofmeyr4c57bb02022-01-13 18:53:10 +010011#include <osmocom/msc/codec_filter.h>
Oliver Smith10632132023-05-12 12:14:22 +020012#include <osmocom/msc/csd_filter.h>
Andreas Eversbergf7396ea2011-10-28 04:07:07 +020013#include <osmocom/gsm/gsm0411_smc.h>
Andreas Eversbergbc6c43f2011-10-28 11:11:13 +020014#include <osmocom/gsm/gsm0411_smr.h>
Harald Welte0803b982009-07-26 14:24:11 +020015
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010016struct vty;
17
Maxd8daaae2019-02-14 16:54:10 +070018/* Used for late TID assignment */
19#define TRANS_ID_UNASSIGNED 0xff
20
Neels Hofmeyr1c065072022-08-07 02:43:15 +020021#define LOG_TRANS_CAT_SRC(trans, subsys, level, file, line, fmt, args...) \
22 LOGPSRC(subsys, level, file, line, \
23 "trans(%s %s callref-0x%x tid-%u%s) " fmt, \
24 (trans) ? trans_name(trans) : "NULL", \
25 (trans) ? ((trans)->msc_a ? (trans)->msc_a->c.fi->id : vlr_subscr_name((trans)->vsub)) : "NULL", \
26 (trans) ? (trans)->callref : 0, \
27 (trans) ? (trans)->transaction_id : 0, \
28 (trans) && (trans)->paging_request ? ",PAGING" : "", \
29 ##args)
30
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010031#define LOG_TRANS_CAT(trans, subsys, level, fmt, args...) \
Neels Hofmeyr1c065072022-08-07 02:43:15 +020032 LOG_TRANS_CAT_SRC(trans, subsys, level, __FILE__, __LINE__, fmt, ##args)
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010033
34#define LOG_TRANS(trans, level, fmt, args...) \
Sylvain Munaut762bb042019-05-10 11:56:02 +020035 LOG_TRANS_CAT(trans, (trans) ? (trans)->log_subsys : DMSC, level, fmt, ##args)
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010036
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020037enum bridge_state {
38 BRIDGE_STATE_NONE,
39 BRIDGE_STATE_LOOPBACK_PENDING,
40 BRIDGE_STATE_LOOPBACK_ESTABLISHED,
41 BRIDGE_STATE_BRIDGE_PENDING,
42 BRIDGE_STATE_BRIDGE_ESTABLISHED,
43};
44
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010045enum trans_type {
Andreas Eversberg456c6f72023-04-23 11:54:16 +020046 TRANS_GCC = GSM48_PDISC_GROUP_CC,
47 TRANS_BCC = GSM48_PDISC_BCAST_CC,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010048 TRANS_CC = GSM48_PDISC_CC,
49 TRANS_SMS = GSM48_PDISC_SMS,
50 TRANS_USSD = GSM48_PDISC_NC_SS,
51 TRANS_SILENT_CALL,
52};
53
54extern const struct value_string trans_type_names[];
55static inline const char *trans_type_name(enum trans_type val)
56{ return get_value_string(trans_type_names, val); }
57
58uint8_t trans_type_to_gsm48_proto(enum trans_type type);
59
Harald Welte0803b982009-07-26 14:24:11 +020060/* One transaction */
61struct gsm_trans {
62 /* Entry in list of all transactions */
63 struct llist_head entry;
64
Neels Hofmeyr8ce66fd2016-08-29 17:52:39 +020065 /* Back pointer to the network struct */
Jacob Erlbeckf07c6052014-12-02 11:58:00 +010066 struct gsm_network *net;
67
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010068 /* What kind of transaction */
69 enum trans_type type;
Neels Hofmeyr7f85ace2019-05-09 15:12:34 +020070 /* Which category to log on, for LOG_TRANS(). */
71 int log_subsys;
Harald Welte0803b982009-07-26 14:24:11 +020072
73 /* The current transaction ID */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020074 uint8_t transaction_id;
Neels Hofmeyr8ce66fd2016-08-29 17:52:39 +020075
Harald Welte0e2fa5d2018-04-09 16:35:01 +020076 /* The DLCI (DCCH/ACCH + SAPI) of this transaction */
77 uint8_t dlci;
78
Harald Welte0803b982009-07-26 14:24:11 +020079 /* To whom we belong, unique identifier of remote MM entity */
Harald Welte2483f1b2016-06-19 18:06:02 +020080 struct vlr_subscr *vsub;
Harald Welte0803b982009-07-26 14:24:11 +020081
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +010082 /* The associated connection we are using to transmit messages */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010083 struct msc_a *msc_a;
Harald Welte0803b982009-07-26 14:24:11 +020084
85 /* reference from MNCC or other application */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020086 uint32_t callref;
Harald Welte0803b982009-07-26 14:24:11 +020087
Andreas Eversberg712b28e2023-06-21 11:17:26 +020088 /* reference that may be used by MGW to identify a call */
89 uint32_t call_id;
90
Harald Welteda7ab742009-12-19 22:23:05 +010091 /* if traffic channel receive was requested */
92 int tch_recv;
93
Holger Hans Peter Freyther49b3ed22010-12-29 17:09:07 +010094 /* is thats one paging? */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010095 struct paging_request *paging_request;
Holger Hans Peter Freyther49b3ed22010-12-29 17:09:07 +010096
Philipp Maierfbf66102017-04-09 12:32:51 +020097 /* bearer capabilities (rate and codec) */
98 struct gsm_mncc_bearer_cap bearer_cap;
99
Harald Welte0803b982009-07-26 14:24:11 +0200100 union {
101 struct {
Andreas Eversberge24636c2023-04-23 12:20:55 +0200102 /* State machine of setup process towards BSS */
103 struct osmo_fsm_inst *fi;
104 /* BSS list with all VGCS/VBS calls */
105 struct llist_head bss_list;
106 /* Inactivity timeout and timer */
107 int inactivity_to;
108 struct osmo_timer_list timer_inactivity;
109 /* If talker's downlink shall be muted */
110 bool mute_talker;
111 /* Indicator, if Uplink is used in one cell */
112 bool uplink_busy;
113 /* BSS that uses the uplink */
114 struct vgcs_bss *uplink_bss;
115 /* Cell that uses the uplink */
116 struct vgcs_bss_cell *uplink_cell;
117 /* If uplink is used by the originator */
118 bool uplink_originator;
119 } gcc;
120 struct {
Harald Welte0803b982009-07-26 14:24:11 +0200121
122 /* current call state */
123 int state;
124
125 /* current timer and message queue */
126 int Tcurrent; /* current CC timer */
127 int T308_second; /* used to send release again */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200128 struct osmo_timer_list timer;
Philipp Maier9ca7b312018-10-10 17:00:49 +0200129 struct osmo_timer_list timer_guard;
Harald Welte0803b982009-07-26 14:24:11 +0200130 struct gsm_mncc msg; /* stores setup/disconnect/release message */
Neels Hofmeyrcf90bdb2019-10-01 19:47:26 +0200131 bool mncc_initiated; /* Whether an MNCC Release is necessary on failure */
Keith Whytea1a70be2021-05-16 02:59:52 +0200132 struct osmo_lcls *lcls;
Oliver Smith593cd882023-05-24 10:40:19 +0200133 /* SDP as last received from the remote call leg. */
134 struct sdp_msg remote;
Oliver Smith10632132023-05-12 12:14:22 +0200135 /* Track codec/CSD choices from BSS and remote call leg */
Neels Hofmeyr4c57bb02022-01-13 18:53:10 +0100136 struct codec_filter codecs;
Oliver Smith10632132023-05-12 12:14:22 +0200137 struct csd_filter csd;
Oliver Smithc63c3a02023-05-24 10:48:07 +0200138 /* Resulting choice from codecs/bearer services and the
139 * local RTP address to be sent to the remote call leg. */
140 struct sdp_msg local;
Harald Welte0803b982009-07-26 14:24:11 +0200141 } cc;
142 struct {
Andreas Eversbergf7396ea2011-10-28 04:07:07 +0200143 struct gsm411_smc_inst smc_inst;
Andreas Eversbergbc6c43f2011-10-28 11:11:13 +0200144 struct gsm411_smr_inst smr_inst;
Andreas Eversbergf7396ea2011-10-28 04:07:07 +0200145
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300146 /* SM-RP-MR, Message Reference (see GSM TS 04.11, section 8.2.3) */
147 uint8_t sm_rp_mr;
Vadim Yanitskiy643270f2019-05-12 05:38:41 +0700148 /* More Messages to Send (see 3GPP TS 29.002, section 7.6.8.7) */
149 bool sm_rp_mmts_ind;
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300150
Harald Welte76042182009-08-08 16:03:15 +0200151 struct gsm_sms *sms;
Mychaela N. Falconia02c49372023-09-25 05:13:49 +0000152
153 uint8_t *gsup_source_name;
154 size_t gsup_source_name_len;
Harald Welte0803b982009-07-26 14:24:11 +0200155 } sms;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700156 struct {
157 /**
158 * Stores a GSM 04.80 message to be sent to
159 * a subscriber after successful Paging Response
160 */
161 struct msgb *msg;
Vadim Yanitskiy64623e12018-11-28 23:05:51 +0700162 /* Inactivity timer, triggers transaction release */
163 struct osmo_timer_list timer_guard;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700164 } ss;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100165 struct {
166 struct gsm0808_channel_type ct;
167 struct osmo_sockaddr_str rtp_cn;
168 struct vty *from_vty;
169 } silent_call;
Harald Welte0803b982009-07-26 14:24:11 +0200170 };
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200171
172 struct {
173 struct gsm_trans *peer;
174 enum bridge_state state;
175 } bridge;
Harald Welte0803b982009-07-26 14:24:11 +0200176};
177
178
Harald Welte9ee48252009-07-23 21:25:08 +0200179
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100180struct gsm_trans *trans_find_by_type(const struct msc_a *msc_a, enum trans_type type);
181struct gsm_trans *trans_find_by_id(const struct msc_a *msc_a,
182 enum trans_type type, uint8_t trans_id);
Andreas Eversberg7e4b0322023-04-23 11:43:13 +0200183struct gsm_trans *trans_find_by_callref(const struct gsm_network *net, enum trans_type type,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200184 uint32_t callref);
Vadim Yanitskiy36c44b22019-01-23 21:22:27 +0700185struct gsm_trans *trans_find_by_sm_rp_mr(const struct gsm_network *net,
186 const struct vlr_subscr *vsub,
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300187 uint8_t sm_rp_mr);
Harald Welte9ee48252009-07-23 21:25:08 +0200188
Keith Whytea1a70be2021-05-16 02:59:52 +0200189struct osmo_lcls *trans_lcls_compose(const struct gsm_trans *trans, bool use_lac);
190
Jacob Erlbeckaf792d62014-12-02 14:22:53 +0100191struct gsm_trans *trans_alloc(struct gsm_network *net,
Harald Welte2483f1b2016-06-19 18:06:02 +0200192 struct vlr_subscr *vsub,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100193 enum trans_type type, uint8_t trans_id,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200194 uint32_t callref);
Harald Welte9ee48252009-07-23 21:25:08 +0200195void trans_free(struct gsm_trans *trans);
196
Max7916ca12019-01-02 11:48:14 +0100197int trans_assign_trans_id(const struct gsm_network *net, const struct vlr_subscr *vsub,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100198 enum trans_type type);
199struct gsm_trans *trans_has_conn(const struct msc_a *msc_a);
200void trans_conn_closed(const struct msc_a *msc_a);
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100201
Vadim Yanitskiyb683dcf2019-05-11 02:17:16 +0700202static inline int trans_log_subsys(enum trans_type type)
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100203{
Vadim Yanitskiyb683dcf2019-05-11 02:17:16 +0700204 switch (type) {
Andreas Eversberg456c6f72023-04-23 11:54:16 +0200205 case TRANS_GCC:
206 return DGCC;
207 case TRANS_BCC:
208 return DBCC;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100209 case TRANS_CC:
Neels Hofmeyr7f85ace2019-05-09 15:12:34 +0200210 case TRANS_SILENT_CALL:
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100211 return DCC;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100212 case TRANS_SMS:
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100213 return DLSMS;
Neels Hofmeyr7f85ace2019-05-09 15:12:34 +0200214 case TRANS_USSD:
Neels Hofmeyr979b0572019-05-09 15:24:49 +0200215 return DSS;
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100216 default:
217 break;
218 }
219 return DMSC;
220}
Neels Hofmeyrf636e6c2019-10-07 21:20:43 +0200221
222const char *trans_name(const struct gsm_trans *trans);