blob: b529f4c72b91995194c262dc3cb400de53830d0c [file] [log] [blame]
Harald Welteeac38c32017-05-29 18:02:53 +02001/* 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
27#include "bscconfig.h"
28
29#include <openbsc/debug.h>
30#include <openbsc/gsm_data.h>
31#include <openbsc/gsm_subscriber.h>
32#include <openbsc/gsm_04_08.h>
33#include <openbsc/bsc_api.h>
34#include <openbsc/msc_ifaces.h>
35
36#include <osmocom/gsm/gsm48.h>
37#include <osmocom/gsm/gsm_utils.h>
38#include <osmocom/gsm/protocol/gsm_04_14.h>
39#include <osmocom/gsm/tlv.h>
40#include <osmocom/core/msgb.h>
41#include <osmocom/core/talloc.h>
42#include <osmocom/core/utils.h>
43
44static struct msgb *create_gsm0414_msg(uint8_t msg_type)
45{
46 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.14");
47 struct gsm48_hdr *gh;
48
49 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
50 gh->proto_discr = GSM48_PDISC_TEST;
51 gh->msg_type = msg_type;
52 return msg;
53}
54
55static int gsm0414_conn_sendmsg(struct gsm_subscriber_connection *conn, struct msgb *msg)
56{
57 return msc_tx_dtap(conn, msg);
58}
59
60static int gsm0414_tx_simple(struct gsm_subscriber_connection *conn, uint8_t msg_type)
61{
62 struct msgb *msg = create_gsm0414_msg(msg_type);
63
64 return gsm0414_conn_sendmsg(conn, msg);
65}
66
67
68/* Send a CLOSE_TCH_LOOOP_CMD according to Section 8.1 */
69int gsm0414_tx_close_tch_loop_cmd(struct gsm_subscriber_connection *conn,
70 enum gsm414_tch_loop_mode loop_mode)
71{
72 struct msgb *msg = create_gsm0414_msg(GSM414_MT_CLOSE_TCH_LOOP_CMD);
73 uint8_t subch;
74
75 subch = (loop_mode << 1);
76 msgb_put_u8(msg, subch);
77
78 msg->lchan = conn->lchan;
79 return gsm0414_conn_sendmsg(conn, msg);
80}
81
82/* Send a OPEN_LOOP_CMD according to Section 8.3 */
83int gsm0414_tx_open_loop_cmd(struct gsm_subscriber_connection *conn)
84{
85 return gsm0414_tx_simple(conn, GSM414_MT_OPEN_LOOP_CMD);
86}
87
88/* Send a ACT_EMMI_CMD according to Section 8.8 */
89int gsm0414_tx_act_emmi_cmd(struct gsm_subscriber_connection *conn)
90{
91 return gsm0414_tx_simple(conn, GSM414_MT_ACT_EMMI_CMD);
92}
93
94/* Send a DEACT_EMMI_CMD according to Section 8.10 */
95int gsm0414_tx_deact_emmi_cmd(struct gsm_subscriber_connection *conn)
96{
97 return gsm0414_tx_simple(conn, GSM414_MT_DEACT_EMMI_CMD);
98}
99
100/* Send a TEST_INTERFACE according to Section 8.11 */
101int gsm0414_tx_test_interface(struct gsm_subscriber_connection *conn,
102 uint8_t tested_devs)
103{
104 struct msgb *msg = create_gsm0414_msg(GSM414_MT_TEST_INTERFACE);
105 msgb_put_u8(msg, tested_devs);
106 return gsm0414_conn_sendmsg(conn, msg);
107}
108
109/* Send a RESET_MS_POSITION_STORED according to Section 8.11 */
110int gsm0414_tx_reset_ms_pos_store(struct gsm_subscriber_connection *conn,
111 uint8_t technology)
112{
113 struct msgb *msg = create_gsm0414_msg(GSM414_MT_RESET_MS_POS_STORED);
114 msgb_put_u8(msg, technology);
115 return gsm0414_conn_sendmsg(conn, msg);
116}
117
118
119
120/* Entry point for incoming GSM48_PDISC_TEST received from MS */
121int gsm0414_rcv_test(struct gsm_subscriber_connection *conn,
122 struct msgb *msg)
123{
124 struct gsm48_hdr *gh = msgb_l3(msg);
125
126 if (msgb_l3len(msg) < sizeof(*gh))
127 return -1;
128
129 LOGP(DMM, LOGL_NOTICE, "%s: Received TEST class message '%s'\n", "FIXME",
130 get_value_string(gsm414_msgt_names, gh->msg_type));
131
132 return 0;
133}