Harald Welte | 8c8f791 | 2009-10-26 20:42:55 +0100 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 2 | * 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 Freyther | 680833e | 2010-07-25 18:08:53 +0800 | [diff] [blame] | 5 | * (C) 2008, 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 6 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 11 | * 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 Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 13 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * GNU Affero General Public License for more details. |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 19 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 20 | * 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 Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
Vadim Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 25 | #include <stdint.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 26 | #include <errno.h> |
| 27 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 28 | #include <osmocom/msc/gsm_04_80.h> |
| 29 | #include <osmocom/msc/msc_ifaces.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 30 | |
Vadim Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 31 | #include <osmocom/gsm/protocol/gsm_04_80.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 32 | #include <osmocom/gsm/gsm0480.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 33 | #include <osmocom/core/msgb.h> |
| 34 | #include <osmocom/gsm/tlv.h> |
Holger Hans Peter Freyther | c0714b8 | 2010-09-30 18:48:28 +0800 | [diff] [blame] | 35 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 36 | static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, uint8_t tag) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 37 | { |
Holger Hans Peter Freyther | ac30cc8 | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 38 | uint8_t *data = msgb_push(msgb, 2); |
| 39 | |
| 40 | data[0] = tag; |
Holger Hans Peter Freyther | e6373b7 | 2010-07-27 01:25:59 +0800 | [diff] [blame] | 41 | data[1] = msgb->len - 2; |
Holger Hans Peter Freyther | ac30cc8 | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 42 | return data; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Vadim Yanitskiy | 5df4e4d | 2018-06-12 08:03:53 +0700 | [diff] [blame] | 45 | /*! 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 Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 59 | int msc_send_ussd_reject(struct gsm_subscriber_connection *conn, |
Vadim Yanitskiy | 5df4e4d | 2018-06-12 08:03:53 +0700 | [diff] [blame] | 60 | uint8_t transaction_id, int invoke_id, |
| 61 | uint8_t problem_tag, uint8_t problem_code) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 62 | { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 63 | struct gsm48_hdr *gh; |
Vadim Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 64 | struct msgb *msg; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 65 | |
Vadim Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 66 | msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code); |
| 67 | if (!msg) |
| 68 | return -1; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 69 | |
| 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 Yanitskiy | 5df4e4d | 2018-06-12 08:03:53 +0700 | [diff] [blame] | 75 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 76 | gh->proto_discr |= transaction_id << 4; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 77 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 78 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 79 | return msc_tx_dtap(conn, msg); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 80 | } |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 81 | |
Neels Hofmeyr | 43273c6 | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 82 | int msc_send_ussd_notify(struct gsm_subscriber_connection *conn, int level, const char *text) |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 83 | { |
Neels Hofmeyr | 43273c6 | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 84 | struct msgb *msg = gsm0480_create_ussd_notify(level, text); |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 85 | if (!msg) |
| 86 | return -1; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 87 | return msc_tx_dtap(conn, msg); |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 88 | } |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 89 | |
Neels Hofmeyr | 43273c6 | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 90 | int msc_send_ussd_release_complete(struct gsm_subscriber_connection *conn) |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 91 | { |
Neels Hofmeyr | 43273c6 | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 92 | struct msgb *msg = gsm0480_create_ussd_release_complete(); |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 93 | if (!msg) |
| 94 | return -1; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 95 | return msc_tx_dtap(conn, msg); |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 96 | } |