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> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 29 | #include <osmocom/msc/msc_a.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 | |
Vadim Yanitskiy | 5df4e4d | 2018-06-12 08:03:53 +0700 | [diff] [blame] | 36 | /*! 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 Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 39 | * \param[in] msc_a Active subscriber |
Vadim Yanitskiy | 5df4e4d | 2018-06-12 08:03:53 +0700 | [diff] [blame] | 40 | * \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 Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 50 | int 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 Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 52 | { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 53 | struct gsm48_hdr *gh; |
Vadim Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 54 | struct msgb *msg; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 55 | |
Vadim Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 56 | msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code); |
| 57 | if (!msg) |
| 58 | return -1; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 59 | |
| 60 | /* Wrap the component in a Facility message */ |
Neels Hofmeyr | a92025e | 2019-01-22 01:51:21 +0100 | [diff] [blame] | 61 | msgb_push_tl(msg, GSM0480_IE_FACILITY); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 62 | |
| 63 | /* And finally pre-pend the L3 header */ |
| 64 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
Vadim Yanitskiy | 5df4e4d | 2018-06-12 08:03:53 +0700 | [diff] [blame] | 65 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 66 | gh->proto_discr |= transaction_id << 4; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 67 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 68 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 69 | return msc_a_tx_dtap_to_i(msc_a, msg); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 70 | } |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 71 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 72 | int msc_send_ussd_notify(struct msc_a *msc_a, int level, const char *text) |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 73 | { |
Neels Hofmeyr | 43273c6 | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 74 | struct msgb *msg = gsm0480_create_ussd_notify(level, text); |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 75 | if (!msg) |
| 76 | return -1; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 77 | return msc_a_tx_dtap_to_i(msc_a, msg); |
Holger Hans Peter Freyther | daf7534 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 78 | } |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 79 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 80 | int msc_send_ussd_release_complete(struct msc_a *msc_a, uint8_t transaction_id) |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 81 | { |
Vadim Yanitskiy | f20c6b7 | 2018-11-29 01:20:58 +0700 | [diff] [blame] | 82 | struct msgb *msg = gsm0480_create_release_complete(transaction_id); |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 83 | if (!msg) |
| 84 | return -1; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 85 | return msc_a_tx_dtap_to_i(msc_a, msg); |
Holger Hans Peter Freyther | 68d2679 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 86 | } |
Vadim Yanitskiy | 3acfe68 | 2019-02-06 17:54:21 +0700 | [diff] [blame] | 87 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 88 | int msc_send_ussd_release_complete_cause(struct msc_a *msc_a, |
Vadim Yanitskiy | 3acfe68 | 2019-02-06 17:54:21 +0700 | [diff] [blame] | 89 | 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 Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 113 | return msc_a_tx_dtap_to_i(msc_a, msg); |
Vadim Yanitskiy | 3acfe68 | 2019-02-06 17:54:21 +0700 | [diff] [blame] | 114 | } |