blob: 21f0b8b082a88f253539a13aa2adc222ebac9cc2 [file] [log] [blame]
Harald Welte9ee48252009-07-23 21:25:08 +02001/* 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 Welte9af6ddf2011-01-01 15:25:50 +01007 * 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 Welte9ee48252009-07-23 21:25:08 +02009 * (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 Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Harald Welte9ee48252009-07-23 21:25:08 +020015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * 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 Welte9ee48252009-07-23 21:25:08 +020018 *
19 */
20
Neels Hofmeyr90843962017-09-04 15:04:35 +020021#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 Ayuso136f4532011-03-22 16:47:59 +010025#include <osmocom/core/talloc.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020026#include <osmocom/msc/gsm_04_08.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020027#include <osmocom/msc/vlr.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010028#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 Welte9ee48252009-07-23 21:25:08 +020032
Harald Welte (local)d19e58b2009-08-15 02:30:58 +020033void *tall_trans_ctx;
Harald Welte9ee48252009-07-23 21:25:08 +020034
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +020035void _gsm48_cc_trans_free(struct gsm_trans *trans);
Vadim Yanitskiyc350c092018-11-21 20:51:51 +070036void _gsm411_sms_trans_free(struct gsm_trans *trans);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +070037void _gsm911_nc_ss_trans_free(struct gsm_trans *trans);
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +020038
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010039struct 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 Welte2483f1b2016-06-19 18:06:02 +020052/*! Find a transaction in connection for given protocol + transaction ID
Vadim Yanitskiy380b2192018-11-27 15:14:31 +070053 * \param[in] conn Connection in which we want to find transaction
Harald Welte2483f1b2016-06-19 18:06:02 +020054 * \param[in] proto Protocol of transaction
55 * \param[in] trans_id Transaction ID of transaction
56 * \returns Matching transaction, if any
57 */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010058struct gsm_trans *trans_find_by_id(const struct msc_a *msc_a,
59 enum trans_type type, uint8_t trans_id)
Harald Welte9ee48252009-07-23 21:25:08 +020060{
61 struct gsm_trans *trans;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010062 struct gsm_network *net = msc_a_net(msc_a);
63 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
Harald Welte9ee48252009-07-23 21:25:08 +020064
65 llist_for_each_entry(trans, &net->trans_list, entry) {
Harald Welte2483f1b2016-06-19 18:06:02 +020066 if (trans->vsub == vsub &&
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010067 trans->type == type &&
Harald Welteb8b40732009-07-23 21:58:40 +020068 trans->transaction_id == trans_id)
Harald Welte9ee48252009-07-23 21:25:08 +020069 return trans;
70 }
71 return NULL;
72}
73
Harald Welte2483f1b2016-06-19 18:06:02 +020074/*! Find a transaction by call reference
75 * \param[in] net Network in which we should search
Andreas Eversberg7e4b0322023-04-23 11:43:13 +020076 * \param[in] type Transaction type (e.g. TRANS_CC)
Harald Welte2483f1b2016-06-19 18:06:02 +020077 * \param[in] callref Call Reference of transaction
78 * \returns Matching transaction, if any
79 */
Andreas Eversberg7e4b0322023-04-23 11:43:13 +020080struct gsm_trans *trans_find_by_callref(const struct gsm_network *net, enum trans_type type,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020081 uint32_t callref)
Harald Welte9ee48252009-07-23 21:25:08 +020082{
83 struct gsm_trans *trans;
84
85 llist_for_each_entry(trans, &net->trans_list, entry) {
Andreas Eversberg7e4b0322023-04-23 11:43:13 +020086 if (trans->callref == callref && trans->type == type)
Harald Welte9ee48252009-07-23 21:25:08 +020087 return trans;
88 }
89 return NULL;
90}
91
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +030092/*! Find a transaction by SM-RP-MR (RP Message Reference)
Vadim Yanitskiy36c44b22019-01-23 21:22:27 +070093 * \param[in] net Network in which we should search
94 * \param[in] vsub Subscriber for which we should search
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +030095 * \param[in] sm_rp_mr RP Message Reference (see GSM TS 04.11, section 8.2.3)
96 * \returns Matching transaction, NULL otherwise
97 */
Vadim Yanitskiy36c44b22019-01-23 21:22:27 +070098struct gsm_trans *trans_find_by_sm_rp_mr(const struct gsm_network *net,
99 const struct vlr_subscr *vsub,
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300100 uint8_t sm_rp_mr)
101{
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300102 struct gsm_trans *trans;
103
104 llist_for_each_entry(trans, &net->trans_list, entry) {
105 if (trans->vsub == vsub &&
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100106 trans->type == TRANS_SMS &&
Ivan Kluchnikov9bd4fd62015-12-21 12:05:56 +0300107 trans->sms.sm_rp_mr == sm_rp_mr)
108 return trans;
109 }
110
111 return NULL;
112}
113
Keith Whytea1a70be2021-05-16 02:59:52 +0200114struct osmo_lcls *trans_lcls_compose(const struct gsm_trans *trans, bool use_lac)
115{
Vadim Yanitskiy583883b2021-10-26 10:25:36 +0300116 if (!trans) {
117 LOGP(DCC, LOGL_ERROR, "LCLS: unable to fill parameters for unallocated transaction\n");
118 return NULL;
119 }
120
Keith Whytea1a70be2021-05-16 02:59:52 +0200121 if (!trans->net->a.sri->sccp)
122 return NULL;
123
124 struct osmo_ss7_instance *ss7 = osmo_sccp_get_ss7(trans->net->a.sri->sccp);
125 struct osmo_lcls *lcls;
126 uint8_t w = osmo_ss7_pc_width(&ss7->cfg.pc_fmt);
127
Keith Whytea1a70be2021-05-16 02:59:52 +0200128 if (!trans->net->lcls_permitted) {
129 LOGP(DCC, LOGL_NOTICE, "LCLS disabled globally\n");
130 return NULL;
131 }
132
133 if (!trans->msc_a) {
134 LOGP(DCC, LOGL_ERROR, "LCLS: unable to fill parameters for transaction without connection\n");
135 return NULL;
136 }
137
138 if (trans->msc_a->c.ran->type != OSMO_RAT_GERAN_A) {
139 LOGP(DCC, LOGL_ERROR, "LCLS: only A interface is supported at the moment\n");
140 return NULL;
141 }
142
143 lcls = talloc_zero(trans, struct osmo_lcls);
144 if (!lcls) {
145 LOGP(DCC, LOGL_ERROR, "LCLS: failed to allocate osmo_lcls\n");
146 return NULL;
147 }
148
149 LOGP(DCC, LOGL_INFO, "LCLS: using %u bits (%u bytes) for node ID\n", w, w / 8);
150
151 lcls->gcr.net_len = 3;
152 lcls->gcr.node = ss7->cfg.primary_pc;
153
154 /* net id from Q.1902.3 3-5 bytes, this function gives 3 bytes exactly */
155 osmo_plmn_to_bcd(lcls->gcr.net, &trans->net->plmn);
156
Keith Whytea1a70be2021-05-16 02:59:52 +0200157
Keith Whyte404fb1b2023-01-31 20:09:31 +0100158 /* TS 29.205 Table B.2.1.9.2 Call Reference ID
159 * 3 octets Call ID + 2 octets BSS ID
160 */
161 lcls->gcr.cr[2] = (trans->callref >> 0) & 0xff;
162 lcls->gcr.cr[1] = (trans->callref >> 8) & 0xff;
163 lcls->gcr.cr[0] = (trans->callref >> 16) & 0xff;
164 osmo_store16be(use_lac ? trans->msc_a->via_cell.lai.lac : trans->msc_a->via_cell.cell_identity, &lcls->gcr.cr[3]);
165
166 LOGP(DCC, LOGL_INFO, "LCLS: allocated %s-based CR-ID %sfor callref 0x%04x\n", use_lac ? "LAC" : "CI",
167 osmo_hexdump(lcls->gcr.cr, 5), trans->callref);
Keith Whytea1a70be2021-05-16 02:59:52 +0200168
169 lcls->config = GSM0808_LCLS_CFG_BOTH_WAY;
170 lcls->control = GSM0808_LCLS_CSC_CONNECT;
171 lcls->corr_needed = true;
172 lcls->gcr_available = true;
173
174 LOGP(DCC, LOGL_DEBUG, "Filled %s\n", osmo_lcls_dump(lcls));
175 LOGP(DCC, LOGL_DEBUG, "Filled %s\n", osmo_gcr_dump(lcls));
176
177 return lcls;
178}
179
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100180static const char *trans_vsub_use(enum trans_type type)
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100181{
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100182 return get_value_string_or_null(trans_type_names, type) ? : "trans-type-unknown";
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100183}
184
Andreas Eversberg712b28e2023-06-21 11:17:26 +0200185static uint32_t new_call_id = 1;
186
Harald Welte2483f1b2016-06-19 18:06:02 +0200187/*! Allocate a new transaction and add it to network list
188 * \param[in] net Netwokr in which we allocate transaction
189 * \param[in] subscr Subscriber for which we allocate transaction
190 * \param[in] protocol Protocol (CC/SMS/...)
191 * \param[in] callref Call Reference
192 * \returns Transaction
193 */
Jacob Erlbeckaf792d62014-12-02 14:22:53 +0100194struct gsm_trans *trans_alloc(struct gsm_network *net,
Harald Welte2483f1b2016-06-19 18:06:02 +0200195 struct vlr_subscr *vsub,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100196 enum trans_type type, uint8_t trans_id,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200197 uint32_t callref)
Harald Welte9ee48252009-07-23 21:25:08 +0200198{
Vadim Yanitskiyb683dcf2019-05-11 02:17:16 +0700199 int subsys = trans_log_subsys(type);
200 struct gsm_trans *trans;
Harald Welte9ee48252009-07-23 21:25:08 +0200201
Benoit Bolseee7cf5e72017-07-05 12:34:18 +0200202 /* a valid subscriber is indispensable */
203 if (vsub == NULL) {
Vadim Yanitskiyb683dcf2019-05-11 02:17:16 +0700204 LOGP(subsys, LOGL_ERROR, "unable to alloc transaction, invalid subscriber (NULL)\n");
Benoit Bolseee7cf5e72017-07-05 12:34:18 +0200205 return NULL;
206 }
207
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100208 trans = talloc(tall_trans_ctx, struct gsm_trans);
Harald Welte9ee48252009-07-23 21:25:08 +0200209 if (!trans)
210 return NULL;
211
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100212 *trans = (struct gsm_trans){
213 .vsub = vsub,
214 .type = type,
Vadim Yanitskiyb683dcf2019-05-11 02:17:16 +0700215 .log_subsys = subsys,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100216 .transaction_id = trans_id,
217 .callref = callref,
Andreas Eversberg712b28e2023-06-21 11:17:26 +0200218 .call_id = new_call_id++,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100219 .net = net,
Neels Hofmeyr85031ee2019-08-28 03:42:03 +0200220 /* empty bearer_cap: make sure the speech_ver array is empty */
221 .bearer_cap = {
222 .speech_ver = { -1 },
223 },
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100224 };
225 vlr_subscr_get(vsub, trans_vsub_use(type));
Jacob Erlbeckf07c6052014-12-02 11:58:00 +0100226 llist_add_tail(&trans->entry, &net->trans_list);
Harald Welte9ee48252009-07-23 21:25:08 +0200227
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100228 LOG_TRANS(trans, LOGL_DEBUG, "New transaction\n");
Harald Welte9ee48252009-07-23 21:25:08 +0200229 return trans;
230}
231
Harald Welte2483f1b2016-06-19 18:06:02 +0200232/*! Release a transaction
233 * \param[in] trans Transaction to be released
234 */
Harald Welte9ee48252009-07-23 21:25:08 +0200235void trans_free(struct gsm_trans *trans)
236{
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100237 const char *usage_token;
238 struct msc_a *msc_a;
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100239
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100240 LOG_TRANS(trans, LOGL_DEBUG, "Freeing transaction\n");
241
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100242 switch (trans->type) {
243 case TRANS_CC:
Harald Welte9ee48252009-07-23 21:25:08 +0200244 _gsm48_cc_trans_free(trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100245 usage_token = MSC_A_USE_CC;
Harald Welte9ee48252009-07-23 21:25:08 +0200246 break;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100247 case TRANS_SMS:
Harald Welte (local)86b17172009-08-14 14:52:17 +0200248 _gsm411_sms_trans_free(trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100249 usage_token = MSC_A_USE_SMS;
Harald Welte (local)86b17172009-08-14 14:52:17 +0200250 break;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100251 case TRANS_USSD:
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700252 _gsm911_nc_ss_trans_free(trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100253 usage_token = MSC_A_USE_NC_SS;
254 break;
255 case TRANS_SILENT_CALL:
256 trans_silent_call_free(trans);
257 usage_token = MSC_A_USE_SILENT_CALL;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700258 break;
Vadim Yanitskiye4574f02019-01-25 19:23:25 +0700259 default:
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100260 usage_token = NULL;
Vadim Yanitskiye4574f02019-01-25 19:23:25 +0700261 break;
Harald Welte9ee48252009-07-23 21:25:08 +0200262 }
263
Holger Hans Peter Freytherd6d7aff2015-04-06 12:03:45 +0200264 if (trans->paging_request) {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100265 paging_request_remove(trans->paging_request);
Holger Hans Peter Freyther49b3ed22010-12-29 17:09:07 +0100266 trans->paging_request = NULL;
Harald Welte9ee48252009-07-23 21:25:08 +0200267 }
268
Harald Welte2483f1b2016-06-19 18:06:02 +0200269 if (trans->vsub) {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100270 vlr_subscr_put(trans->vsub, trans_vsub_use(trans->type));
Harald Welte2483f1b2016-06-19 18:06:02 +0200271 trans->vsub = NULL;
Holger Hans Peter Freyther405824c2012-12-22 18:16:47 +0100272 }
Harald Welte9ee48252009-07-23 21:25:08 +0200273
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100274 msc_a = trans->msc_a;
275 trans->msc_a = NULL;
276
Neels Hofmeyre3d3dc62018-03-31 00:02:14 +0200277 llist_del(&trans->entry);
Harald Welte9ee48252009-07-23 21:25:08 +0200278 talloc_free(trans);
Neels Hofmeyrd6a769b2018-03-12 23:59:07 +0100279
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100280 if (msc_a && usage_token)
281 msc_a_put(msc_a, usage_token);
Harald Welte9ee48252009-07-23 21:25:08 +0200282}
283
Harald Welte2483f1b2016-06-19 18:06:02 +0200284/*! allocate an unused transaction ID for the given subscriber
Max30fb97a2019-01-10 17:25:33 +0100285 * in the given protocol using TI flag = 0 (allocated by us).
286 * See GSM 04.07, section 11.2.3.1.3 "Transaction identifier".
Harald Welte2483f1b2016-06-19 18:06:02 +0200287 * \param[in] net GSM network
Vadim Yanitskiybaeeb902019-02-14 16:41:30 +0700288 * \param[in] subscr Subscriber for which to assign a new TID
289 * \param[in] protocol Protocol of to be assigned TID
Harald Welte2483f1b2016-06-19 18:06:02 +0200290 */
Max7916ca12019-01-02 11:48:14 +0100291int trans_assign_trans_id(const struct gsm_network *net, const struct vlr_subscr *vsub,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100292 enum trans_type type)
Harald Welte9ee48252009-07-23 21:25:08 +0200293{
Harald Welte9ee48252009-07-23 21:25:08 +0200294 struct gsm_trans *trans;
295 unsigned int used_tid_bitmask = 0;
Sylvain Munaut926fcec2009-12-24 13:26:17 +0100296 int i, j, h;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100297 uint8_t proto = trans_type_to_gsm48_proto(type);
Harald Welte78283ef2009-07-23 21:36:44 +0200298
Harald Welte9ee48252009-07-23 21:25:08 +0200299 /* generate bitmask of already-used TIDs for this (subscr,proto) */
300 llist_for_each_entry(trans, &net->trans_list, entry) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200301 if (trans->vsub != vsub ||
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100302 proto != trans_type_to_gsm48_proto(trans->type) ||
Maxd8daaae2019-02-14 16:54:10 +0700303 trans->transaction_id == TRANS_ID_UNASSIGNED)
Harald Welte9ee48252009-07-23 21:25:08 +0200304 continue;
305 used_tid_bitmask |= (1 << trans->transaction_id);
306 }
307
Sylvain Munaut926fcec2009-12-24 13:26:17 +0100308 /* find a new one, trying to go in a 'circular' pattern */
309 for (h = 6; h > 0; h--)
Max30fb97a2019-01-10 17:25:33 +0100310 if (used_tid_bitmask & (1 << h))
Sylvain Munaut926fcec2009-12-24 13:26:17 +0100311 break;
Sylvain Munautb9f3dce2009-12-18 18:28:11 +0100312 for (i = 0; i < 7; i++) {
Max30fb97a2019-01-10 17:25:33 +0100313 j = (h + i) % 7;
Sylvain Munaut926fcec2009-12-24 13:26:17 +0100314 if ((used_tid_bitmask & (1 << j)) == 0)
315 return j;
Harald Welte78283ef2009-07-23 21:36:44 +0200316 }
317
318 return -1;
Harald Welte9ee48252009-07-23 21:25:08 +0200319}
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +0100320
Harald Welte2483f1b2016-06-19 18:06:02 +0200321/*! Check if we have any transaction for given connection
322 * \param[in] conn Connection to check
Maxc065ca32019-01-14 11:51:28 +0100323 * \returns transaction pointer if found, NULL otherwise
Harald Welte2483f1b2016-06-19 18:06:02 +0200324 */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100325struct gsm_trans *trans_has_conn(const struct msc_a *msc_a)
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +0100326{
327 struct gsm_trans *trans;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100328 struct gsm_network *net = msc_a_net(msc_a);
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +0100329
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100330 llist_for_each_entry(trans, &net->trans_list, entry)
331 if (trans->msc_a == msc_a)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200332 return trans;
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +0100333
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200334 return NULL;
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +0100335}
Harald Welte2483f1b2016-06-19 18:06:02 +0200336
337/*! Free all transactions associated with a connection, presumably when the
338 * conn is being closed. The transaction code will inform the CC or SMS
339 * facilities, which will then send the necessary release indications.
340 * \param[in] conn Connection that is going to be closed.
341 */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100342void trans_conn_closed(const struct msc_a *msc_a)
Harald Welte2483f1b2016-06-19 18:06:02 +0200343{
Harald Welte2483f1b2016-06-19 18:06:02 +0200344 /* As part of the CC REL_IND the remote leg might be released and this
345 * will trigger another call to trans_free. This is something the llist
346 * macro can not handle and we need to re-iterate the list every time.
347 */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100348 struct gsm_trans *trans;
349 while ((trans = trans_has_conn(msc_a)))
350 trans_free(trans);
351}
352
353const struct value_string trans_type_names[] = {
354 { TRANS_CC, "CC" },
355 { TRANS_SMS, "SMS" },
356 { TRANS_USSD, "NCSS" },
357 { TRANS_SILENT_CALL, "silent-call" },
358 {}
359};
360
361uint8_t trans_type_to_gsm48_proto(enum trans_type type)
362{
363 switch (type) {
364 case TRANS_CC:
365 case TRANS_SILENT_CALL:
366 return GSM48_PDISC_CC;
367 case TRANS_SMS:
368 return GSM48_PDISC_SMS;
369 case TRANS_USSD:
370 return GSM48_PDISC_NC_SS;
371 default:
372 return GSM48_PDISC_TEST;
Harald Welte2483f1b2016-06-19 18:06:02 +0200373 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100374
Harald Welte2483f1b2016-06-19 18:06:02 +0200375}
Neels Hofmeyrf636e6c2019-10-07 21:20:43 +0200376
377const char *trans_name(const struct gsm_trans *trans)
378{
379 static char namebuf[32];
380 if (!trans)
381 return "NULL";
382 switch (trans->type) {
383 case TRANS_CC:
384 snprintf(namebuf, sizeof(namebuf), "%s:%s",
385 trans_type_name(trans->type), gsm48_cc_state_name(trans->cc.state));
386 return namebuf;
387
388 default:
389 return trans_type_name(trans->type);
390 }
391}