Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 1 | /* GSM 04.07 Transaction handling */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 21 | #include <osmocom/msc/transaction.h> |
| 22 | #include <osmocom/msc/gsm_data.h> |
| 23 | #include <osmocom/msc/mncc.h> |
| 24 | #include <osmocom/msc/debug.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 25 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 26 | #include <osmocom/msc/gsm_04_08.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 27 | #include <osmocom/msc/vlr.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 28 | #include <osmocom/msc/msc_a.h> |
| 29 | #include <osmocom/msc/msub.h> |
| 30 | #include <osmocom/msc/paging.h> |
| 31 | #include <osmocom/msc/silent_call.h> |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 32 | |
Harald Welte (local) | d19e58b | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 33 | void *tall_trans_ctx; |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 34 | |
Holger Hans Peter Freyther | 34e9749 | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 35 | void _gsm48_cc_trans_free(struct gsm_trans *trans); |
Vadim Yanitskiy | c350c09 | 2018-11-21 20:51:51 +0700 | [diff] [blame] | 36 | void _gsm411_sms_trans_free(struct gsm_trans *trans); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 37 | void _gsm911_nc_ss_trans_free(struct gsm_trans *trans); |
Holger Hans Peter Freyther | 34e9749 | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 38 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 39 | struct gsm_trans *trans_find_by_type(const struct msc_a *msc_a, enum trans_type type) |
| 40 | { |
| 41 | struct gsm_trans *trans; |
| 42 | struct gsm_network *net = msc_a_net(msc_a); |
| 43 | struct vlr_subscr *vsub = msc_a_vsub(msc_a); |
| 44 | |
| 45 | llist_for_each_entry(trans, &net->trans_list, entry) { |
| 46 | if (trans->vsub == vsub && trans->type == type) |
| 47 | return trans; |
| 48 | } |
| 49 | return NULL; |
| 50 | } |
| 51 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 52 | /*! Find a transaction in connection for given protocol + transaction ID |
Vadim Yanitskiy | 380b219 | 2018-11-27 15:14:31 +0700 | [diff] [blame] | 53 | * \param[in] conn Connection in which we want to find transaction |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 54 | * \param[in] proto Protocol of transaction |
| 55 | * \param[in] trans_id Transaction ID of transaction |
| 56 | * \returns Matching transaction, if any |
| 57 | */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 58 | struct gsm_trans *trans_find_by_id(const struct msc_a *msc_a, |
| 59 | enum trans_type type, uint8_t trans_id) |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 60 | { |
| 61 | struct gsm_trans *trans; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 62 | struct gsm_network *net = msc_a_net(msc_a); |
| 63 | struct vlr_subscr *vsub = msc_a_vsub(msc_a); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 64 | |
| 65 | llist_for_each_entry(trans, &net->trans_list, entry) { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 66 | if (trans->vsub == vsub && |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 67 | trans->type == type && |
Harald Welte | b8b4073 | 2009-07-23 21:58:40 +0200 | [diff] [blame] | 68 | trans->transaction_id == trans_id) |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 69 | return trans; |
| 70 | } |
| 71 | return NULL; |
| 72 | } |
| 73 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 74 | /*! Find a transaction by call reference |
| 75 | * \param[in] net Network in which we should search |
| 76 | * \param[in] callref Call Reference of transaction |
| 77 | * \returns Matching transaction, if any |
| 78 | */ |
Max | 7916ca1 | 2019-01-02 11:48:14 +0100 | [diff] [blame] | 79 | 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] | 80 | uint32_t callref) |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 81 | { |
| 82 | struct gsm_trans *trans; |
| 83 | |
| 84 | llist_for_each_entry(trans, &net->trans_list, entry) { |
| 85 | if (trans->callref == callref) |
| 86 | return trans; |
| 87 | } |
| 88 | return NULL; |
| 89 | } |
| 90 | |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 91 | /*! Find a transaction by SM-RP-MR (RP Message Reference) |
Vadim Yanitskiy | 36c44b2 | 2019-01-23 21:22:27 +0700 | [diff] [blame] | 92 | * \param[in] net Network in which we should search |
| 93 | * \param[in] vsub Subscriber for which we should search |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 94 | * \param[in] sm_rp_mr RP Message Reference (see GSM TS 04.11, section 8.2.3) |
| 95 | * \returns Matching transaction, NULL otherwise |
| 96 | */ |
Vadim Yanitskiy | 36c44b2 | 2019-01-23 21:22:27 +0700 | [diff] [blame] | 97 | struct gsm_trans *trans_find_by_sm_rp_mr(const struct gsm_network *net, |
| 98 | const struct vlr_subscr *vsub, |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 99 | uint8_t sm_rp_mr) |
| 100 | { |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 101 | struct gsm_trans *trans; |
| 102 | |
| 103 | llist_for_each_entry(trans, &net->trans_list, entry) { |
| 104 | if (trans->vsub == vsub && |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 105 | trans->type == TRANS_SMS && |
Ivan Kluchnikov | 9bd4fd6 | 2015-12-21 12:05:56 +0300 | [diff] [blame] | 106 | trans->sms.sm_rp_mr == sm_rp_mr) |
| 107 | return trans; |
| 108 | } |
| 109 | |
| 110 | return NULL; |
| 111 | } |
| 112 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 113 | static const char *trans_vsub_use(enum trans_type type) |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 114 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 115 | return get_value_string_or_null(trans_type_names, type) ? : "trans-type-unknown"; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 118 | /*! Allocate a new transaction and add it to network list |
| 119 | * \param[in] net Netwokr in which we allocate transaction |
| 120 | * \param[in] subscr Subscriber for which we allocate transaction |
| 121 | * \param[in] protocol Protocol (CC/SMS/...) |
| 122 | * \param[in] callref Call Reference |
| 123 | * \returns Transaction |
| 124 | */ |
Jacob Erlbeck | af792d6 | 2014-12-02 14:22:53 +0100 | [diff] [blame] | 125 | struct gsm_trans *trans_alloc(struct gsm_network *net, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 126 | struct vlr_subscr *vsub, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 127 | enum trans_type type, uint8_t trans_id, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 128 | uint32_t callref) |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 129 | { |
Vadim Yanitskiy | b683dcf | 2019-05-11 02:17:16 +0700 | [diff] [blame] | 130 | int subsys = trans_log_subsys(type); |
| 131 | struct gsm_trans *trans; |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 132 | |
Benoit Bolsee | e7cf5e7 | 2017-07-05 12:34:18 +0200 | [diff] [blame] | 133 | /* a valid subscriber is indispensable */ |
| 134 | if (vsub == NULL) { |
Vadim Yanitskiy | b683dcf | 2019-05-11 02:17:16 +0700 | [diff] [blame] | 135 | LOGP(subsys, LOGL_ERROR, "unable to alloc transaction, invalid subscriber (NULL)\n"); |
Benoit Bolsee | e7cf5e7 | 2017-07-05 12:34:18 +0200 | [diff] [blame] | 136 | return NULL; |
| 137 | } |
| 138 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 139 | trans = talloc(tall_trans_ctx, struct gsm_trans); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 140 | if (!trans) |
| 141 | return NULL; |
| 142 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 143 | *trans = (struct gsm_trans){ |
| 144 | .vsub = vsub, |
| 145 | .type = type, |
Vadim Yanitskiy | b683dcf | 2019-05-11 02:17:16 +0700 | [diff] [blame] | 146 | .log_subsys = subsys, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 147 | .transaction_id = trans_id, |
| 148 | .callref = callref, |
| 149 | .net = net, |
Neels Hofmeyr | 85031ee | 2019-08-28 03:42:03 +0200 | [diff] [blame] | 150 | /* empty bearer_cap: make sure the speech_ver array is empty */ |
| 151 | .bearer_cap = { |
| 152 | .speech_ver = { -1 }, |
| 153 | }, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 154 | }; |
| 155 | vlr_subscr_get(vsub, trans_vsub_use(type)); |
Jacob Erlbeck | f07c605 | 2014-12-02 11:58:00 +0100 | [diff] [blame] | 156 | llist_add_tail(&trans->entry, &net->trans_list); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 157 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 158 | LOG_TRANS(trans, LOGL_DEBUG, "New transaction\n"); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 159 | return trans; |
| 160 | } |
| 161 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 162 | /*! Release a transaction |
| 163 | * \param[in] trans Transaction to be released |
| 164 | */ |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 165 | void trans_free(struct gsm_trans *trans) |
| 166 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 167 | const char *usage_token; |
| 168 | struct msc_a *msc_a; |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 169 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 170 | LOG_TRANS(trans, LOGL_DEBUG, "Freeing transaction\n"); |
| 171 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 172 | switch (trans->type) { |
| 173 | case TRANS_CC: |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 174 | _gsm48_cc_trans_free(trans); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 175 | usage_token = MSC_A_USE_CC; |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 176 | break; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 177 | case TRANS_SMS: |
Harald Welte (local) | 86b1717 | 2009-08-14 14:52:17 +0200 | [diff] [blame] | 178 | _gsm411_sms_trans_free(trans); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 179 | usage_token = MSC_A_USE_SMS; |
Harald Welte (local) | 86b1717 | 2009-08-14 14:52:17 +0200 | [diff] [blame] | 180 | break; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 181 | case TRANS_USSD: |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 182 | _gsm911_nc_ss_trans_free(trans); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 183 | usage_token = MSC_A_USE_NC_SS; |
| 184 | break; |
| 185 | case TRANS_SILENT_CALL: |
| 186 | trans_silent_call_free(trans); |
| 187 | usage_token = MSC_A_USE_SILENT_CALL; |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 188 | break; |
Vadim Yanitskiy | e4574f0 | 2019-01-25 19:23:25 +0700 | [diff] [blame] | 189 | default: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 190 | usage_token = NULL; |
Vadim Yanitskiy | e4574f0 | 2019-01-25 19:23:25 +0700 | [diff] [blame] | 191 | break; |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 194 | if (trans->paging_request) { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 195 | paging_request_remove(trans->paging_request); |
Holger Hans Peter Freyther | 49b3ed2 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 196 | trans->paging_request = NULL; |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 197 | } |
| 198 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 199 | if (trans->vsub) { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 200 | vlr_subscr_put(trans->vsub, trans_vsub_use(trans->type)); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 201 | trans->vsub = NULL; |
Holger Hans Peter Freyther | 405824c | 2012-12-22 18:16:47 +0100 | [diff] [blame] | 202 | } |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 203 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 204 | msc_a = trans->msc_a; |
| 205 | trans->msc_a = NULL; |
| 206 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 207 | llist_del(&trans->entry); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 208 | talloc_free(trans); |
Neels Hofmeyr | d6a769b | 2018-03-12 23:59:07 +0100 | [diff] [blame] | 209 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 210 | if (msc_a && usage_token) |
| 211 | msc_a_put(msc_a, usage_token); |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 214 | /*! allocate an unused transaction ID for the given subscriber |
Max | 30fb97a | 2019-01-10 17:25:33 +0100 | [diff] [blame] | 215 | * in the given protocol using TI flag = 0 (allocated by us). |
| 216 | * See GSM 04.07, section 11.2.3.1.3 "Transaction identifier". |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 217 | * \param[in] net GSM network |
Vadim Yanitskiy | baeeb90 | 2019-02-14 16:41:30 +0700 | [diff] [blame] | 218 | * \param[in] subscr Subscriber for which to assign a new TID |
| 219 | * \param[in] protocol Protocol of to be assigned TID |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 220 | */ |
Max | 7916ca1 | 2019-01-02 11:48:14 +0100 | [diff] [blame] | 221 | 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] | 222 | enum trans_type type) |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 223 | { |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 224 | struct gsm_trans *trans; |
| 225 | unsigned int used_tid_bitmask = 0; |
Sylvain Munaut | 926fcec | 2009-12-24 13:26:17 +0100 | [diff] [blame] | 226 | int i, j, h; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 227 | uint8_t proto = trans_type_to_gsm48_proto(type); |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 228 | |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 229 | /* generate bitmask of already-used TIDs for this (subscr,proto) */ |
| 230 | llist_for_each_entry(trans, &net->trans_list, entry) { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 231 | if (trans->vsub != vsub || |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 232 | proto != trans_type_to_gsm48_proto(trans->type) || |
Max | d8daaae | 2019-02-14 16:54:10 +0700 | [diff] [blame] | 233 | trans->transaction_id == TRANS_ID_UNASSIGNED) |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 234 | continue; |
| 235 | used_tid_bitmask |= (1 << trans->transaction_id); |
| 236 | } |
| 237 | |
Sylvain Munaut | 926fcec | 2009-12-24 13:26:17 +0100 | [diff] [blame] | 238 | /* find a new one, trying to go in a 'circular' pattern */ |
| 239 | for (h = 6; h > 0; h--) |
Max | 30fb97a | 2019-01-10 17:25:33 +0100 | [diff] [blame] | 240 | if (used_tid_bitmask & (1 << h)) |
Sylvain Munaut | 926fcec | 2009-12-24 13:26:17 +0100 | [diff] [blame] | 241 | break; |
Sylvain Munaut | b9f3dce | 2009-12-18 18:28:11 +0100 | [diff] [blame] | 242 | for (i = 0; i < 7; i++) { |
Max | 30fb97a | 2019-01-10 17:25:33 +0100 | [diff] [blame] | 243 | j = (h + i) % 7; |
Sylvain Munaut | 926fcec | 2009-12-24 13:26:17 +0100 | [diff] [blame] | 244 | if ((used_tid_bitmask & (1 << j)) == 0) |
| 245 | return j; |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | return -1; |
Harald Welte | 9ee4825 | 2009-07-23 21:25:08 +0200 | [diff] [blame] | 249 | } |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 250 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 251 | /*! Check if we have any transaction for given connection |
| 252 | * \param[in] conn Connection to check |
Max | c065ca3 | 2019-01-14 11:51:28 +0100 | [diff] [blame] | 253 | * \returns transaction pointer if found, NULL otherwise |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 254 | */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 255 | struct gsm_trans *trans_has_conn(const struct msc_a *msc_a) |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 256 | { |
| 257 | struct gsm_trans *trans; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 258 | struct gsm_network *net = msc_a_net(msc_a); |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 259 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 260 | llist_for_each_entry(trans, &net->trans_list, entry) |
| 261 | if (trans->msc_a == msc_a) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 262 | return trans; |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 263 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 264 | return NULL; |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 265 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 266 | |
| 267 | /*! Free all transactions associated with a connection, presumably when the |
| 268 | * conn is being closed. The transaction code will inform the CC or SMS |
| 269 | * facilities, which will then send the necessary release indications. |
| 270 | * \param[in] conn Connection that is going to be closed. |
| 271 | */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 272 | void trans_conn_closed(const struct msc_a *msc_a) |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 273 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 274 | /* As part of the CC REL_IND the remote leg might be released and this |
| 275 | * will trigger another call to trans_free. This is something the llist |
| 276 | * macro can not handle and we need to re-iterate the list every time. |
| 277 | */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 278 | struct gsm_trans *trans; |
| 279 | while ((trans = trans_has_conn(msc_a))) |
| 280 | trans_free(trans); |
| 281 | } |
| 282 | |
| 283 | const struct value_string trans_type_names[] = { |
| 284 | { TRANS_CC, "CC" }, |
| 285 | { TRANS_SMS, "SMS" }, |
| 286 | { TRANS_USSD, "NCSS" }, |
| 287 | { TRANS_SILENT_CALL, "silent-call" }, |
| 288 | {} |
| 289 | }; |
| 290 | |
| 291 | uint8_t trans_type_to_gsm48_proto(enum trans_type type) |
| 292 | { |
| 293 | switch (type) { |
| 294 | case TRANS_CC: |
| 295 | case TRANS_SILENT_CALL: |
| 296 | return GSM48_PDISC_CC; |
| 297 | case TRANS_SMS: |
| 298 | return GSM48_PDISC_SMS; |
| 299 | case TRANS_USSD: |
| 300 | return GSM48_PDISC_NC_SS; |
| 301 | default: |
| 302 | return GSM48_PDISC_TEST; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 303 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 304 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 305 | } |
Neels Hofmeyr | f636e6c | 2019-10-07 21:20:43 +0200 | [diff] [blame] | 306 | |
| 307 | const char *trans_name(const struct gsm_trans *trans) |
| 308 | { |
| 309 | static char namebuf[32]; |
| 310 | if (!trans) |
| 311 | return "NULL"; |
| 312 | switch (trans->type) { |
| 313 | case TRANS_CC: |
| 314 | snprintf(namebuf, sizeof(namebuf), "%s:%s", |
| 315 | trans_type_name(trans->type), gsm48_cc_state_name(trans->cc.state)); |
| 316 | return namebuf; |
| 317 | |
| 318 | default: |
| 319 | return trans_type_name(trans->type); |
| 320 | } |
| 321 | } |