Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 1 | /* GSM MS Testing Layer 3 messages |
| 2 | * 3GPP TS 44.014 / GSM TS 04.14 */ |
| 3 | |
| 4 | /* (C) 2017 by Harald Welte <laforge@gnumonks.org> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 27 | #include <osmocom/msc/debug.h> |
| 28 | #include <osmocom/msc/gsm_data.h> |
| 29 | #include <osmocom/msc/gsm_subscriber.h> |
| 30 | #include <osmocom/msc/gsm_04_08.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 31 | #include <osmocom/msc/msc_a.h> |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 32 | |
| 33 | #include <osmocom/gsm/gsm48.h> |
| 34 | #include <osmocom/gsm/gsm_utils.h> |
| 35 | #include <osmocom/gsm/protocol/gsm_04_14.h> |
| 36 | #include <osmocom/gsm/tlv.h> |
| 37 | #include <osmocom/core/msgb.h> |
| 38 | #include <osmocom/core/talloc.h> |
| 39 | #include <osmocom/core/utils.h> |
| 40 | |
| 41 | static struct msgb *create_gsm0414_msg(uint8_t msg_type) |
| 42 | { |
| 43 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.14"); |
| 44 | struct gsm48_hdr *gh; |
| 45 | |
Vadim Yanitskiy | 72e0f09 | 2020-07-29 05:28:42 +0700 | [diff] [blame] | 46 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 47 | gh->proto_discr = GSM48_PDISC_TEST; |
| 48 | gh->msg_type = msg_type; |
| 49 | return msg; |
| 50 | } |
| 51 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 52 | static int gsm0414_conn_sendmsg(struct msc_a *msc_a, struct msgb *msg) |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 53 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 54 | return msc_a_tx_dtap_to_i(msc_a, msg); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 57 | static int gsm0414_tx_simple(struct msc_a *msc_a, uint8_t msg_type) |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 58 | { |
| 59 | struct msgb *msg = create_gsm0414_msg(msg_type); |
| 60 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 61 | return gsm0414_conn_sendmsg(msc_a, msg); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | |
| 65 | /* Send a CLOSE_TCH_LOOOP_CMD according to Section 8.1 */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 66 | int gsm0414_tx_close_tch_loop_cmd(struct msc_a *msc_a, |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 67 | enum gsm414_tch_loop_mode loop_mode) |
| 68 | { |
| 69 | struct msgb *msg = create_gsm0414_msg(GSM414_MT_CLOSE_TCH_LOOP_CMD); |
| 70 | uint8_t subch; |
| 71 | |
| 72 | subch = (loop_mode << 1); |
| 73 | msgb_put_u8(msg, subch); |
| 74 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 75 | return gsm0414_conn_sendmsg(msc_a, msg); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* Send a OPEN_LOOP_CMD according to Section 8.3 */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 79 | int gsm0414_tx_open_loop_cmd(struct msc_a *msc_a) |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 80 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 81 | return gsm0414_tx_simple(msc_a, GSM414_MT_OPEN_LOOP_CMD); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* Send a ACT_EMMI_CMD according to Section 8.8 */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 85 | int gsm0414_tx_act_emmi_cmd(struct msc_a *msc_a) |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 86 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 87 | return gsm0414_tx_simple(msc_a, GSM414_MT_ACT_EMMI_CMD); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* Send a DEACT_EMMI_CMD according to Section 8.10 */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 91 | int gsm0414_tx_deact_emmi_cmd(struct msc_a *msc_a) |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 92 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 93 | return gsm0414_tx_simple(msc_a, GSM414_MT_DEACT_EMMI_CMD); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* Send a TEST_INTERFACE according to Section 8.11 */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 97 | int gsm0414_tx_test_interface(struct msc_a *msc_a, |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 98 | uint8_t tested_devs) |
| 99 | { |
| 100 | struct msgb *msg = create_gsm0414_msg(GSM414_MT_TEST_INTERFACE); |
| 101 | msgb_put_u8(msg, tested_devs); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 102 | return gsm0414_conn_sendmsg(msc_a, msg); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* Send a RESET_MS_POSITION_STORED according to Section 8.11 */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 106 | int gsm0414_tx_reset_ms_pos_store(struct msc_a *msc_a, |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 107 | uint8_t technology) |
| 108 | { |
| 109 | struct msgb *msg = create_gsm0414_msg(GSM414_MT_RESET_MS_POS_STORED); |
| 110 | msgb_put_u8(msg, technology); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 111 | return gsm0414_conn_sendmsg(msc_a, msg); |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
| 115 | |
| 116 | /* Entry point for incoming GSM48_PDISC_TEST received from MS */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 117 | int gsm0414_rcv_test(struct msc_a *msc_a, |
Harald Welte | eac38c3 | 2017-05-29 18:02:53 +0200 | [diff] [blame] | 118 | struct msgb *msg) |
| 119 | { |
| 120 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 121 | |
| 122 | if (msgb_l3len(msg) < sizeof(*gh)) |
| 123 | return -1; |
| 124 | |
| 125 | LOGP(DMM, LOGL_NOTICE, "%s: Received TEST class message '%s'\n", "FIXME", |
| 126 | get_value_string(gsm414_msgt_names, gh->msg_type)); |
| 127 | |
| 128 | return 0; |
| 129 | } |