Vadim Yanitskiy | 2eaee70 | 2019-02-14 16:44:45 +0700 | [diff] [blame] | 1 | #pragma once |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 2 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 3 | #include <osmocom/msc/gsm_data.h> |
| 4 | #include <osmocom/msc/gsm_subscriber.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 5 | #include <osmocom/core/linuxlist.h> |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 6 | #include <osmocom/core/fsm.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 7 | #include <osmocom/msc/gsm_04_11.h> |
| 8 | #include <osmocom/msc/mncc.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 9 | #include <osmocom/msc/msc_a.h> |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 10 | #include <osmocom/msc/debug.h> |
Neels Hofmeyr | 4c57bb0 | 2022-01-13 18:53:10 +0100 | [diff] [blame] | 11 | #include <osmocom/msc/codec_filter.h> |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 12 | #include <osmocom/gsm/gsm0411_smc.h> |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 13 | #include <osmocom/gsm/gsm0411_smr.h> |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 14 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 15 | struct vty; |
| 16 | |
Max | d8daaae | 2019-02-14 16:54:10 +0700 | [diff] [blame] | 17 | /* Used for late TID assignment */ |
| 18 | #define TRANS_ID_UNASSIGNED 0xff |
| 19 | |
Neels Hofmeyr | 1c06507 | 2022-08-07 02:43:15 +0200 | [diff] [blame] | 20 | #define LOG_TRANS_CAT_SRC(trans, subsys, level, file, line, fmt, args...) \ |
| 21 | LOGPSRC(subsys, level, file, line, \ |
| 22 | "trans(%s %s callref-0x%x tid-%u%s) " fmt, \ |
| 23 | (trans) ? trans_name(trans) : "NULL", \ |
| 24 | (trans) ? ((trans)->msc_a ? (trans)->msc_a->c.fi->id : vlr_subscr_name((trans)->vsub)) : "NULL", \ |
| 25 | (trans) ? (trans)->callref : 0, \ |
| 26 | (trans) ? (trans)->transaction_id : 0, \ |
| 27 | (trans) && (trans)->paging_request ? ",PAGING" : "", \ |
| 28 | ##args) |
| 29 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 30 | #define LOG_TRANS_CAT(trans, subsys, level, fmt, args...) \ |
Neels Hofmeyr | 1c06507 | 2022-08-07 02:43:15 +0200 | [diff] [blame] | 31 | LOG_TRANS_CAT_SRC(trans, subsys, level, __FILE__, __LINE__, fmt, ##args) |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 32 | |
| 33 | #define LOG_TRANS(trans, level, fmt, args...) \ |
Sylvain Munaut | 762bb04 | 2019-05-10 11:56:02 +0200 | [diff] [blame] | 34 | LOG_TRANS_CAT(trans, (trans) ? (trans)->log_subsys : DMSC, level, fmt, ##args) |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 35 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 36 | enum bridge_state { |
| 37 | BRIDGE_STATE_NONE, |
| 38 | BRIDGE_STATE_LOOPBACK_PENDING, |
| 39 | BRIDGE_STATE_LOOPBACK_ESTABLISHED, |
| 40 | BRIDGE_STATE_BRIDGE_PENDING, |
| 41 | BRIDGE_STATE_BRIDGE_ESTABLISHED, |
| 42 | }; |
| 43 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 44 | enum trans_type { |
| 45 | TRANS_CC = GSM48_PDISC_CC, |
| 46 | TRANS_SMS = GSM48_PDISC_SMS, |
| 47 | TRANS_USSD = GSM48_PDISC_NC_SS, |
| 48 | TRANS_SILENT_CALL, |
| 49 | }; |
| 50 | |
| 51 | extern const struct value_string trans_type_names[]; |
| 52 | static inline const char *trans_type_name(enum trans_type val) |
| 53 | { return get_value_string(trans_type_names, val); } |
| 54 | |
| 55 | uint8_t trans_type_to_gsm48_proto(enum trans_type type); |
| 56 | |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 57 | /* One transaction */ |
| 58 | struct gsm_trans { |
| 59 | /* Entry in list of all transactions */ |
| 60 | struct llist_head entry; |
| 61 | |
Neels Hofmeyr | 8ce66fd | 2016-08-29 17:52:39 +0200 | [diff] [blame] | 62 | /* Back pointer to the network struct */ |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 63 | struct gsm_network *net; |
| 64 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 65 | /* What kind of transaction */ |
| 66 | enum trans_type type; |
Neels Hofmeyr | 7f85ace | 2019-05-09 15:12:34 +0200 | [diff] [blame] | 67 | /* Which category to log on, for LOG_TRANS(). */ |
| 68 | int log_subsys; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 69 | |
| 70 | /* The current transaction ID */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 71 | uint8_t transaction_id; |
Neels Hofmeyr | 8ce66fd | 2016-08-29 17:52:39 +0200 | [diff] [blame] | 72 | |
Harald Welte | 0e2fa5d | 2018-04-09 16:35:01 +0200 | [diff] [blame] | 73 | /* The DLCI (DCCH/ACCH + SAPI) of this transaction */ |
| 74 | uint8_t dlci; |
| 75 | |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 76 | /* To whom we belong, unique identifier of remote MM entity */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 77 | struct vlr_subscr *vsub; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 78 | |
Holger Hans Peter Freyther | e95d482 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 79 | /* The associated connection we are using to transmit messages */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 80 | struct msc_a *msc_a; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 81 | |
| 82 | /* reference from MNCC or other application */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 83 | uint32_t callref; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 84 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 85 | /* if traffic channel receive was requested */ |
| 86 | int tch_recv; |
| 87 | |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 88 | /* is thats one paging? */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 89 | struct paging_request *paging_request; |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 90 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 91 | /* bearer capabilities (rate and codec) */ |
| 92 | struct gsm_mncc_bearer_cap bearer_cap; |
| 93 | |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 94 | 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 Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 103 | struct osmo_timer_list timer; |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 104 | struct osmo_timer_list timer_guard; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 105 | struct gsm_mncc msg; /* stores setup/disconnect/release message */ |
Neels Hofmeyr | cf90bdb | 2019-10-01 19:47:26 +0200 | [diff] [blame] | 106 | bool mncc_initiated; /* Whether an MNCC Release is necessary on failure */ |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 107 | struct osmo_lcls *lcls; |
Neels Hofmeyr | 4c57bb0 | 2022-01-13 18:53:10 +0100 | [diff] [blame] | 108 | /* Track codec choices from BSS and remote call leg */ |
| 109 | struct codec_filter codecs; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 110 | } cc; |
| 111 | struct { |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 112 | struct gsm411_smc_inst smc_inst; |
Andreas Eversberg | bc6c43f | 2011-10-28 11:11:13 +0200 | [diff] [blame] | 113 | struct gsm411_smr_inst smr_inst; |
Andreas Eversberg | f7396ea | 2011-10-28 04:07:07 +0200 | [diff] [blame] | 114 | |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 115 | /* SM-RP-MR, Message Reference (see GSM TS 04.11, section 8.2.3) */ |
| 116 | uint8_t sm_rp_mr; |
Vadim Yanitskiy | 643270f | 2019-05-12 05:38:41 +0700 | [diff] [blame] | 117 | /* More Messages to Send (see 3GPP TS 29.002, section 7.6.8.7) */ |
| 118 | bool sm_rp_mmts_ind; |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 119 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 120 | struct gsm_sms *sms; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 121 | } sms; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 122 | struct { |
| 123 | /** |
| 124 | * Stores a GSM 04.80 message to be sent to |
| 125 | * a subscriber after successful Paging Response |
| 126 | */ |
| 127 | struct msgb *msg; |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 128 | /* Inactivity timer, triggers transaction release */ |
| 129 | struct osmo_timer_list timer_guard; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 130 | } ss; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 131 | struct { |
| 132 | struct gsm0808_channel_type ct; |
| 133 | struct osmo_sockaddr_str rtp_cn; |
| 134 | struct vty *from_vty; |
| 135 | } silent_call; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 136 | }; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 137 | |
| 138 | struct { |
| 139 | struct gsm_trans *peer; |
| 140 | enum bridge_state state; |
| 141 | } bridge; |
Harald Welte | 0803b98 | 2009-07-26 14:24:11 +0200 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 145 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 146 | struct gsm_trans *trans_find_by_type(const struct msc_a *msc_a, enum trans_type type); |
| 147 | struct gsm_trans *trans_find_by_id(const struct msc_a *msc_a, |
| 148 | enum trans_type type, uint8_t trans_id); |
Max | 7916ca1 | 2019-01-02 11:48:14 +0100 | [diff] [blame] | 149 | struct gsm_trans *trans_find_by_callref(const struct gsm_network *net, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 150 | uint32_t callref); |
Vadim Yanitskiy | 36c44b2 | 2019-01-23 21:22:27 +0700 | [diff] [blame] | 151 | struct gsm_trans *trans_find_by_sm_rp_mr(const struct gsm_network *net, |
| 152 | const struct vlr_subscr *vsub, |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 153 | uint8_t sm_rp_mr); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 154 | |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 155 | struct osmo_lcls *trans_lcls_compose(const struct gsm_trans *trans, bool use_lac); |
| 156 | |
Jacob Erlbeck | af792d6 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 157 | struct gsm_trans *trans_alloc(struct gsm_network *net, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 158 | struct vlr_subscr *vsub, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 159 | enum trans_type type, uint8_t trans_id, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 160 | uint32_t callref); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 161 | void trans_free(struct gsm_trans *trans); |
| 162 | |
Max | 7916ca1 | 2019-01-02 11:48:14 +0100 | [diff] [blame] | 163 | int trans_assign_trans_id(const struct gsm_network *net, const struct vlr_subscr *vsub, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 164 | enum trans_type type); |
| 165 | struct gsm_trans *trans_has_conn(const struct msc_a *msc_a); |
| 166 | void trans_conn_closed(const struct msc_a *msc_a); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 167 | |
Vadim Yanitskiy | b683dcf | 2019-05-11 02:17:16 +0700 | [diff] [blame] | 168 | static inline int trans_log_subsys(enum trans_type type) |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 169 | { |
Vadim Yanitskiy | b683dcf | 2019-05-11 02:17:16 +0700 | [diff] [blame] | 170 | switch (type) { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 171 | case TRANS_CC: |
Neels Hofmeyr | 7f85ace | 2019-05-09 15:12:34 +0200 | [diff] [blame] | 172 | case TRANS_SILENT_CALL: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 173 | return DCC; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 174 | case TRANS_SMS: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 175 | return DLSMS; |
Neels Hofmeyr | 7f85ace | 2019-05-09 15:12:34 +0200 | [diff] [blame] | 176 | case TRANS_USSD: |
Neels Hofmeyr | 979b057 | 2019-05-09 15:24:49 +0200 | [diff] [blame] | 177 | return DSS; |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 178 | default: |
| 179 | break; |
| 180 | } |
| 181 | return DMSC; |
| 182 | } |
Neels Hofmeyr | f636e6c | 2019-10-07 21:20:43 +0200 | [diff] [blame] | 183 | |
| 184 | const char *trans_name(const struct gsm_trans *trans); |