blob: 61d8c1a28c1f7fe2d78d1d94c6ab7e89a29dfc23 [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>
Andreas Eversbergf7396ea2011-10-28 04:07:07 +020011#include <osmocom/gsm/gsm0411_smc.h>
Andreas Eversbergbc6c43f2011-10-28 11:11:13 +020012#include <osmocom/gsm/gsm0411_smr.h>
Harald Welte0803b982009-07-26 14:24:11 +020013
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010014struct vty;
15
Maxd8daaae2019-02-14 16:54:10 +070016/* Used for late TID assignment */
17#define TRANS_ID_UNASSIGNED 0xff
18
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010019#define LOG_TRANS_CAT(trans, subsys, level, fmt, args...) \
20 LOGP(subsys, level, \
21 "trans(%s %s callref-0x%x tid-%u%s) " fmt, \
Neels Hofmeyrf636e6c2019-10-07 21:20:43 +020022 (trans) ? trans_name(trans) : "NULL", \
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010023 (trans) ? ((trans)->msc_a ? (trans)->msc_a->c.fi->id : vlr_subscr_name((trans)->vsub)) : "NULL", \
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010024 (trans) ? (trans)->callref : 0, \
25 (trans) ? (trans)->transaction_id : 0, \
26 (trans) && (trans)->paging_request ? ",PAGING" : "", \
27 ##args)
28
29#define LOG_TRANS(trans, level, fmt, args...) \
Sylvain Munaut762bb042019-05-10 11:56:02 +020030 LOG_TRANS_CAT(trans, (trans) ? (trans)->log_subsys : DMSC, level, fmt, ##args)
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010031
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020032enum bridge_state {
33 BRIDGE_STATE_NONE,
34 BRIDGE_STATE_LOOPBACK_PENDING,
35 BRIDGE_STATE_LOOPBACK_ESTABLISHED,
36 BRIDGE_STATE_BRIDGE_PENDING,
37 BRIDGE_STATE_BRIDGE_ESTABLISHED,
38};
39
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010040enum trans_type {
41 TRANS_CC = GSM48_PDISC_CC,
42 TRANS_SMS = GSM48_PDISC_SMS,
43 TRANS_USSD = GSM48_PDISC_NC_SS,
44 TRANS_SILENT_CALL,
45};
46
47extern const struct value_string trans_type_names[];
48static inline const char *trans_type_name(enum trans_type val)
49{ return get_value_string(trans_type_names, val); }
50
51uint8_t trans_type_to_gsm48_proto(enum trans_type type);
52
Harald Welte0803b982009-07-26 14:24:11 +020053/* One transaction */
54struct gsm_trans {
55 /* Entry in list of all transactions */
56 struct llist_head entry;
57
Neels Hofmeyr8ce66fd2016-08-29 17:52:39 +020058 /* Back pointer to the network struct */
Jacob Erlbeckf07c6052014-12-02 11:58:00 +010059 struct gsm_network *net;
60
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010061 /* What kind of transaction */
62 enum trans_type type;
Neels Hofmeyr7f85ace2019-05-09 15:12:34 +020063 /* Which category to log on, for LOG_TRANS(). */
64 int log_subsys;
Harald Welte0803b982009-07-26 14:24:11 +020065
66 /* The current transaction ID */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020067 uint8_t transaction_id;
Neels Hofmeyr8ce66fd2016-08-29 17:52:39 +020068
Harald Welte0e2fa5d2018-04-09 16:35:01 +020069 /* The DLCI (DCCH/ACCH + SAPI) of this transaction */
70 uint8_t dlci;
71
Harald Welte0803b982009-07-26 14:24:11 +020072 /* To whom we belong, unique identifier of remote MM entity */
Harald Welte2483f1b2016-06-19 18:06:02 +020073 struct vlr_subscr *vsub;
Harald Welte0803b982009-07-26 14:24:11 +020074
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +010075 /* The associated connection we are using to transmit messages */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010076 struct msc_a *msc_a;
Harald Welte0803b982009-07-26 14:24:11 +020077
78 /* reference from MNCC or other application */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020079 uint32_t callref;
Harald Welte0803b982009-07-26 14:24:11 +020080
Harald Welteda7ab742009-12-19 22:23:05 +010081 /* if traffic channel receive was requested */
82 int tch_recv;
83
Holger Hans Peter Freyther49b3ed22010-12-29 17:09:07 +010084 /* is thats one paging? */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010085 struct paging_request *paging_request;
Holger Hans Peter Freyther49b3ed22010-12-29 17:09:07 +010086
Philipp Maierfbf66102017-04-09 12:32:51 +020087 /* bearer capabilities (rate and codec) */
88 struct gsm_mncc_bearer_cap bearer_cap;
89
Philipp Maierfbf66102017-04-09 12:32:51 +020090 /* if true, TCH_RTP_CREATE is sent after the
91 * assignment is done */
92 bool tch_rtp_create;
93
Harald Welte0803b982009-07-26 14:24:11 +020094 union {
95 struct {
96
97 /* current call state */
98 int state;
99
100 /* current timer and message queue */
101 int Tcurrent; /* current CC timer */
102 int T308_second; /* used to send release again */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200103 struct osmo_timer_list timer;
Philipp Maier9ca7b312018-10-10 17:00:49 +0200104 struct osmo_timer_list timer_guard;
Harald Welte0803b982009-07-26 14:24:11 +0200105 struct gsm_mncc msg; /* stores setup/disconnect/release message */
Neels Hofmeyrcf90bdb2019-10-01 19:47:26 +0200106 bool mncc_initiated; /* Whether an MNCC Release is necessary on failure */
Harald Welte0803b982009-07-26 14:24:11 +0200107 } cc;
108 struct {
Andreas Eversbergf7396ea2011-10-28 04:07:07 +0200109 struct gsm411_smc_inst smc_inst;
Andreas Eversbergbc6c43f2011-10-28 11:11:13 +0200110 struct gsm411_smr_inst smr_inst;
Andreas Eversbergf7396ea2011-10-28 04:07:07 +0200111
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300112 /* SM-RP-MR, Message Reference (see GSM TS 04.11, section 8.2.3) */
113 uint8_t sm_rp_mr;
Vadim Yanitskiy643270f2019-05-12 05:38:41 +0700114 /* More Messages to Send (see 3GPP TS 29.002, section 7.6.8.7) */
115 bool sm_rp_mmts_ind;
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300116
Harald Welte76042182009-08-08 16:03:15 +0200117 struct gsm_sms *sms;
Harald Welte0803b982009-07-26 14:24:11 +0200118 } sms;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700119 struct {
120 /**
121 * Stores a GSM 04.80 message to be sent to
122 * a subscriber after successful Paging Response
123 */
124 struct msgb *msg;
Vadim Yanitskiy64623e12018-11-28 23:05:51 +0700125 /* Inactivity timer, triggers transaction release */
126 struct osmo_timer_list timer_guard;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700127 } ss;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100128 struct {
129 struct gsm0808_channel_type ct;
130 struct osmo_sockaddr_str rtp_cn;
131 struct vty *from_vty;
132 } silent_call;
Harald Welte0803b982009-07-26 14:24:11 +0200133 };
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200134
135 struct {
136 struct gsm_trans *peer;
137 enum bridge_state state;
138 } bridge;
Harald Welte0803b982009-07-26 14:24:11 +0200139};
140
141
Harald Welte9ee48252009-07-23 21:25:08 +0200142
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100143struct gsm_trans *trans_find_by_type(const struct msc_a *msc_a, enum trans_type type);
144struct gsm_trans *trans_find_by_id(const struct msc_a *msc_a,
145 enum trans_type type, uint8_t trans_id);
Max7916ca12019-01-02 11:48:14 +0100146struct gsm_trans *trans_find_by_callref(const struct gsm_network *net,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200147 uint32_t callref);
Vadim Yanitskiy36c44b22019-01-23 21:22:27 +0700148struct gsm_trans *trans_find_by_sm_rp_mr(const struct gsm_network *net,
149 const struct vlr_subscr *vsub,
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300150 uint8_t sm_rp_mr);
Harald Welte9ee48252009-07-23 21:25:08 +0200151
Jacob Erlbeckaf792d62014-12-02 14:22:53 +0100152struct gsm_trans *trans_alloc(struct gsm_network *net,
Harald Welte2483f1b2016-06-19 18:06:02 +0200153 struct vlr_subscr *vsub,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100154 enum trans_type type, uint8_t trans_id,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200155 uint32_t callref);
Harald Welte9ee48252009-07-23 21:25:08 +0200156void trans_free(struct gsm_trans *trans);
157
Max7916ca12019-01-02 11:48:14 +0100158int trans_assign_trans_id(const struct gsm_network *net, const struct vlr_subscr *vsub,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100159 enum trans_type type);
160struct gsm_trans *trans_has_conn(const struct msc_a *msc_a);
161void trans_conn_closed(const struct msc_a *msc_a);
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100162
Vadim Yanitskiyb683dcf2019-05-11 02:17:16 +0700163static inline int trans_log_subsys(enum trans_type type)
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100164{
Vadim Yanitskiyb683dcf2019-05-11 02:17:16 +0700165 switch (type) {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100166 case TRANS_CC:
Neels Hofmeyr7f85ace2019-05-09 15:12:34 +0200167 case TRANS_SILENT_CALL:
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100168 return DCC;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100169 case TRANS_SMS:
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100170 return DLSMS;
Neels Hofmeyr7f85ace2019-05-09 15:12:34 +0200171 case TRANS_USSD:
Neels Hofmeyr979b0572019-05-09 15:24:49 +0200172 return DSS;
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100173 default:
174 break;
175 }
176 return DMSC;
177}
Neels Hofmeyrf636e6c2019-10-07 21:20:43 +0200178
179const char *trans_name(const struct gsm_trans *trans);