blob: 6a79b5bb62583fcd54e131a1245fa82de2524d68 [file] [log] [blame]
Harald Welte8c8f7912009-10-26 20:42:55 +01001/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
Harald Welte6eafe912009-10-16 08:32:58 +02002 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
4/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther680833e2010-07-25 18:08:53 +08005 * (C) 2008, 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte6eafe912009-10-16 08:32:58 +02006 * (C) 2009 by Mike Haben <michael.haben@btinternet.com>
7 *
8 * All Rights Reserved
9 *
10 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010011 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
Harald Welte6eafe912009-10-16 08:32:58 +020013 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * GNU Affero General Public License for more details.
Harald Welte6eafe912009-10-16 08:32:58 +020019 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010020 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte6eafe912009-10-16 08:32:58 +020022 *
23 */
24
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070025#include <stdint.h>
Harald Welte6eafe912009-10-16 08:32:58 +020026#include <errno.h>
27
Neels Hofmeyr90843962017-09-04 15:04:35 +020028#include <osmocom/msc/gsm_04_80.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010029#include <osmocom/msc/msc_a.h>
Harald Welte6eafe912009-10-16 08:32:58 +020030
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070031#include <osmocom/gsm/protocol/gsm_04_80.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010032#include <osmocom/gsm/gsm0480.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010033#include <osmocom/core/msgb.h>
34#include <osmocom/gsm/tlv.h>
Holger Hans Peter Freytherc0714b82010-09-30 18:48:28 +080035
Vadim Yanitskiy5df4e4d2018-06-12 08:03:53 +070036/*! Send a MT RELEASE COMPLETE message with Reject component
37 * (see section 3.6.1) and given error code (see section 3.6.7).
38 *
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010039 * \param[in] msc_a Active subscriber
Vadim Yanitskiy5df4e4d2018-06-12 08:03:53 +070040 * \param[in] transaction_id Transaction ID with TI flag set
41 * \param[in] invoke_id InvokeID of the request
42 * \param[in] problem_tag Problem code tag (table 3.13)
43 * \param[in] problem_code Problem code (tables 3.14-17)
44 * \return result of \ref msc_tx_dtap
45 *
46 * Note: if InvokeID is not available, e.g. when message parsing
47 * failed, any incorrect value can be passed (0x00 > x > 0xff), so
48 * the universal NULL-tag (see table 3.6) will be used instead.
49 */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010050int msc_send_ussd_reject(struct msc_a *msc_a, uint8_t transaction_id, int invoke_id,
51 uint8_t problem_tag, uint8_t problem_code)
Harald Welte6eafe912009-10-16 08:32:58 +020052{
Harald Welte6eafe912009-10-16 08:32:58 +020053 struct gsm48_hdr *gh;
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070054 struct msgb *msg;
Harald Welte6eafe912009-10-16 08:32:58 +020055
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070056 msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code);
57 if (!msg)
58 return -1;
Harald Welte6eafe912009-10-16 08:32:58 +020059
60 /* Wrap the component in a Facility message */
Neels Hofmeyra92025e2019-01-22 01:51:21 +010061 msgb_push_tl(msg, GSM0480_IE_FACILITY);
Harald Welte6eafe912009-10-16 08:32:58 +020062
63 /* And finally pre-pend the L3 header */
64 gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
Vadim Yanitskiy5df4e4d2018-06-12 08:03:53 +070065 gh->proto_discr = GSM48_PDISC_NC_SS;
66 gh->proto_discr |= transaction_id << 4;
Harald Welte6eafe912009-10-16 08:32:58 +020067 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
68
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010069 return msc_a_tx_dtap_to_i(msc_a, msg);
Harald Welte6eafe912009-10-16 08:32:58 +020070}
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080071
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010072int msc_send_ussd_notify(struct msc_a *msc_a, int level, const char *text)
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080073{
Neels Hofmeyr43273c62016-05-10 12:50:31 +020074 struct msgb *msg = gsm0480_create_ussd_notify(level, text);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080075 if (!msg)
76 return -1;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010077 return msc_a_tx_dtap_to_i(msc_a, msg);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080078}
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080079
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010080int msc_send_ussd_release_complete(struct msc_a *msc_a, uint8_t transaction_id)
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080081{
Vadim Yanitskiyf20c6b72018-11-29 01:20:58 +070082 struct msgb *msg = gsm0480_create_release_complete(transaction_id);
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080083 if (!msg)
84 return -1;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010085 return msc_a_tx_dtap_to_i(msc_a, msg);
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080086}
Vadim Yanitskiy3acfe682019-02-06 17:54:21 +070087
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010088int msc_send_ussd_release_complete_cause(struct msc_a *msc_a,
Vadim Yanitskiy3acfe682019-02-06 17:54:21 +070089 uint8_t transaction_id,
90 uint8_t cause_loc, uint8_t cause_val)
91{
92 struct msgb *msg;
93 uint8_t *cause_ie;
94
95 msg = gsm0480_create_release_complete(transaction_id);
96 if (!msg)
97 return -1;
98
99 /* Encode cause IE (see GSM 04.08, section 10.5.4.11)
100 * with fixed length (2 bytes of TL, 2 bytes of payload).
101 * NOTE: we don't use gsm48_encode_cause() API because
102 * it wants gsm_mncc_cause struct from us. */
103 cause_ie = msgb_put(msg, 2 + 2);
104 cause_ie[0] = GSM48_IE_CAUSE;
105 cause_ie[1] = 2;
106
107 /* Coding standard defined for the GSM PLMNs,
108 * location and cause: as given by caller,
109 * no extension, no diagnostics. */
110 cause_ie[2] = (1 << 7) | (0x03 << 5) | (cause_loc & 0x0f);
111 cause_ie[3] = (1 << 7) | cause_val;
112
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100113 return msc_a_tx_dtap_to_i(msc_a, msg);
Vadim Yanitskiy3acfe682019-02-06 17:54:21 +0700114}