blob: 7ffcf3b785764dfc555441b17704c1bb23a1d619 [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 Hofmeyrff7074a2019-02-28 05:50:06 +01009#include <osmocom/msc/debug.h>
Andreas Eversbergf7396ea2011-10-28 04:07:07 +020010#include <osmocom/gsm/gsm0411_smc.h>
Andreas Eversbergbc6c43f2011-10-28 11:11:13 +020011#include <osmocom/gsm/gsm0411_smr.h>
Harald Welte0803b982009-07-26 14:24:11 +020012
Maxd8daaae2019-02-14 16:54:10 +070013/* Used for late TID assignment */
14#define TRANS_ID_UNASSIGNED 0xff
15
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010016#define LOG_TRANS_CAT(trans, subsys, level, fmt, args...) \
17 LOGP(subsys, level, \
18 "trans(%s %s callref-0x%x tid-%u%s) " fmt, \
19 (trans) ? gsm48_pdisc_name((trans)->protocol) : "NULL", \
20 (trans) ? ((trans)->conn ? (trans)->conn->fi->id : vlr_subscr_name((trans)->vsub)) : "NULL", \
21 (trans) ? (trans)->callref : 0, \
22 (trans) ? (trans)->transaction_id : 0, \
23 (trans) && (trans)->paging_request ? ",PAGING" : "", \
24 ##args)
25
26#define LOG_TRANS(trans, level, fmt, args...) \
27 LOG_TRANS_CAT(trans, trans_log_subsys(trans), level, fmt, ##args)
28
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020029enum bridge_state {
30 BRIDGE_STATE_NONE,
31 BRIDGE_STATE_LOOPBACK_PENDING,
32 BRIDGE_STATE_LOOPBACK_ESTABLISHED,
33 BRIDGE_STATE_BRIDGE_PENDING,
34 BRIDGE_STATE_BRIDGE_ESTABLISHED,
35};
36
Harald Welte0803b982009-07-26 14:24:11 +020037/* One transaction */
38struct gsm_trans {
39 /* Entry in list of all transactions */
40 struct llist_head entry;
41
Neels Hofmeyr8ce66fd2016-08-29 17:52:39 +020042 /* Back pointer to the network struct */
Jacob Erlbeckf07c6052014-12-02 11:58:00 +010043 struct gsm_network *net;
44
Harald Welte0803b982009-07-26 14:24:11 +020045 /* The protocol within which we live */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020046 uint8_t protocol;
Harald Welte0803b982009-07-26 14:24:11 +020047
48 /* The current transaction ID */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020049 uint8_t transaction_id;
Neels Hofmeyr8ce66fd2016-08-29 17:52:39 +020050
Harald Welte0e2fa5d2018-04-09 16:35:01 +020051 /* The DLCI (DCCH/ACCH + SAPI) of this transaction */
52 uint8_t dlci;
53
Harald Welte0803b982009-07-26 14:24:11 +020054 /* To whom we belong, unique identifier of remote MM entity */
Harald Welte2483f1b2016-06-19 18:06:02 +020055 struct vlr_subscr *vsub;
Harald Welte0803b982009-07-26 14:24:11 +020056
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +010057 /* The associated connection we are using to transmit messages */
Neels Hofmeyrc036b792018-11-29 22:37:51 +010058 struct ran_conn *conn;
Harald Welte0803b982009-07-26 14:24:11 +020059
60 /* reference from MNCC or other application */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020061 uint32_t callref;
Harald Welte0803b982009-07-26 14:24:11 +020062
Harald Welteda7ab742009-12-19 22:23:05 +010063 /* if traffic channel receive was requested */
64 int tch_recv;
65
Holger Hans Peter Freyther49b3ed22010-12-29 17:09:07 +010066 /* is thats one paging? */
Holger Hans Peter Freytherd6d7aff2015-04-06 12:03:45 +020067 struct subscr_request *paging_request;
Holger Hans Peter Freyther49b3ed22010-12-29 17:09:07 +010068
Philipp Maierfbf66102017-04-09 12:32:51 +020069 /* bearer capabilities (rate and codec) */
70 struct gsm_mncc_bearer_cap bearer_cap;
71
Philipp Maierfbf66102017-04-09 12:32:51 +020072 /* if true, TCH_RTP_CREATE is sent after the
73 * assignment is done */
74 bool tch_rtp_create;
75
Harald Welte0803b982009-07-26 14:24:11 +020076 union {
77 struct {
78
79 /* current call state */
80 int state;
81
82 /* current timer and message queue */
83 int Tcurrent; /* current CC timer */
84 int T308_second; /* used to send release again */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020085 struct osmo_timer_list timer;
Philipp Maier9ca7b312018-10-10 17:00:49 +020086 struct osmo_timer_list timer_guard;
Harald Welte0803b982009-07-26 14:24:11 +020087 struct gsm_mncc msg; /* stores setup/disconnect/release message */
Neels Hofmeyra35712d2018-12-20 03:03:44 +010088 bool assignment_started;
Harald Welte0803b982009-07-26 14:24:11 +020089 } cc;
90 struct {
Andreas Eversbergf7396ea2011-10-28 04:07:07 +020091 struct gsm411_smc_inst smc_inst;
Andreas Eversbergbc6c43f2011-10-28 11:11:13 +020092 struct gsm411_smr_inst smr_inst;
Andreas Eversbergf7396ea2011-10-28 04:07:07 +020093
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +030094 /* SM-RP-MR, Message Reference (see GSM TS 04.11, section 8.2.3) */
95 uint8_t sm_rp_mr;
96
Harald Welte76042182009-08-08 16:03:15 +020097 struct gsm_sms *sms;
Harald Welte0803b982009-07-26 14:24:11 +020098 } sms;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +070099 struct {
100 /**
101 * Stores a GSM 04.80 message to be sent to
102 * a subscriber after successful Paging Response
103 */
104 struct msgb *msg;
Vadim Yanitskiy64623e12018-11-28 23:05:51 +0700105 /* Inactivity timer, triggers transaction release */
106 struct osmo_timer_list timer_guard;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700107 } ss;
Harald Welte0803b982009-07-26 14:24:11 +0200108 };
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200109
110 struct {
111 struct gsm_trans *peer;
112 enum bridge_state state;
113 } bridge;
Harald Welte0803b982009-07-26 14:24:11 +0200114};
115
116
Harald Welte9ee48252009-07-23 21:25:08 +0200117
Max7916ca12019-01-02 11:48:14 +0100118struct gsm_trans *trans_find_by_id(const struct ran_conn *conn,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200119 uint8_t proto, uint8_t trans_id);
Max7916ca12019-01-02 11:48:14 +0100120struct gsm_trans *trans_find_by_callref(const struct gsm_network *net,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200121 uint32_t callref);
Vadim Yanitskiy36c44b22019-01-23 21:22:27 +0700122struct gsm_trans *trans_find_by_sm_rp_mr(const struct gsm_network *net,
123 const struct vlr_subscr *vsub,
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300124 uint8_t sm_rp_mr);
Harald Welte9ee48252009-07-23 21:25:08 +0200125
Jacob Erlbeckaf792d62014-12-02 14:22:53 +0100126struct gsm_trans *trans_alloc(struct gsm_network *net,
Harald Welte2483f1b2016-06-19 18:06:02 +0200127 struct vlr_subscr *vsub,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200128 uint8_t protocol, uint8_t trans_id,
129 uint32_t callref);
Harald Welte9ee48252009-07-23 21:25:08 +0200130void trans_free(struct gsm_trans *trans);
131
Max7916ca12019-01-02 11:48:14 +0100132int trans_assign_trans_id(const struct gsm_network *net, const struct vlr_subscr *vsub,
Max30fb97a2019-01-10 17:25:33 +0100133 uint8_t protocol);
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100134struct gsm_trans *trans_has_conn(const struct ran_conn *conn);
Max7916ca12019-01-02 11:48:14 +0100135void trans_conn_closed(const struct ran_conn *conn);
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100136
137static inline int trans_log_subsys(const struct gsm_trans *trans)
138{
139 if (!trans)
140 return DMSC;
141 switch (trans->protocol) {
142 case GSM48_PDISC_CC:
143 return DCC;
144 case GSM48_PDISC_SMS:
145 return DLSMS;
146 default:
147 break;
148 }
149 return DMSC;
150}