blob: 0adf0596e3518815a1ff8a1f84b68bffe6a7adc9 [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>
29#include <osmocom/msc/msc_ifaces.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
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020036static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, uint8_t tag)
Harald Welte6eafe912009-10-16 08:32:58 +020037{
Holger Hans Peter Freytherac30cc82010-07-26 19:08:59 +080038 uint8_t *data = msgb_push(msgb, 2);
39
40 data[0] = tag;
Holger Hans Peter Freythere6373b72010-07-27 01:25:59 +080041 data[1] = msgb->len - 2;
Holger Hans Peter Freytherac30cc82010-07-26 19:08:59 +080042 return data;
Harald Welte6eafe912009-10-16 08:32:58 +020043}
44
Vadim Yanitskiy5df4e4d2018-06-12 08:03:53 +070045/*! Send a MT RELEASE COMPLETE message with Reject component
46 * (see section 3.6.1) and given error code (see section 3.6.7).
47 *
48 * \param[in] conn Active subscriber connection
49 * \param[in] transaction_id Transaction ID with TI flag set
50 * \param[in] invoke_id InvokeID of the request
51 * \param[in] problem_tag Problem code tag (table 3.13)
52 * \param[in] problem_code Problem code (tables 3.14-17)
53 * \return result of \ref msc_tx_dtap
54 *
55 * Note: if InvokeID is not available, e.g. when message parsing
56 * failed, any incorrect value can be passed (0x00 > x > 0xff), so
57 * the universal NULL-tag (see table 3.6) will be used instead.
58 */
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070059int msc_send_ussd_reject(struct gsm_subscriber_connection *conn,
Vadim Yanitskiy5df4e4d2018-06-12 08:03:53 +070060 uint8_t transaction_id, int invoke_id,
61 uint8_t problem_tag, uint8_t problem_code)
Harald Welte6eafe912009-10-16 08:32:58 +020062{
Harald Welte6eafe912009-10-16 08:32:58 +020063 struct gsm48_hdr *gh;
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070064 struct msgb *msg;
Harald Welte6eafe912009-10-16 08:32:58 +020065
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070066 msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code);
67 if (!msg)
68 return -1;
Harald Welte6eafe912009-10-16 08:32:58 +020069
70 /* Wrap the component in a Facility message */
71 msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY);
72
73 /* And finally pre-pend the L3 header */
74 gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
Vadim Yanitskiy5df4e4d2018-06-12 08:03:53 +070075 gh->proto_discr = GSM48_PDISC_NC_SS;
76 gh->proto_discr |= transaction_id << 4;
Harald Welte6eafe912009-10-16 08:32:58 +020077 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
78
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020079 return msc_tx_dtap(conn, msg);
Harald Welte6eafe912009-10-16 08:32:58 +020080}
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080081
Neels Hofmeyr43273c62016-05-10 12:50:31 +020082int msc_send_ussd_notify(struct gsm_subscriber_connection *conn, int level, const char *text)
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080083{
Neels Hofmeyr43273c62016-05-10 12:50:31 +020084 struct msgb *msg = gsm0480_create_ussd_notify(level, text);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080085 if (!msg)
86 return -1;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020087 return msc_tx_dtap(conn, msg);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080088}
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080089
Neels Hofmeyr43273c62016-05-10 12:50:31 +020090int msc_send_ussd_release_complete(struct gsm_subscriber_connection *conn)
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080091{
Neels Hofmeyr43273c62016-05-10 12:50:31 +020092 struct msgb *msg = gsm0480_create_ussd_release_complete();
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080093 if (!msg)
94 return -1;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020095 return msc_tx_dtap(conn, msg);
Holger Hans Peter Freyther68d26792010-07-27 03:31:50 +080096}