blob: 77d84b32c6ebe1b4f73f1ed97ffa6b12c64a33a8 [file] [log] [blame]
Philipp Maierfbf66102017-04-09 12:32:51 +02001/* (C) 2017 by Sysmocom s.f.m.c. GmbH
Harald Weltec9e78592018-02-09 01:42:50 +01002 * (C) 2018 by Harald Welte <laforge@gnumonks.org>
Philipp Maierfbf66102017-04-09 12:32:51 +02003 * All Rights Reserved
4 *
5 * Author: Philipp Maier
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <osmocom/core/utils.h>
23#include <osmocom/core/msgb.h>
24#include <osmocom/core/logging.h>
25#include <osmocom/sigtran/sccp_helpers.h>
26#include <osmocom/sccp/sccp_types.h>
27#include <osmocom/gsm/gsm0808.h>
Max43b01b02017-09-15 11:22:30 +020028#include <osmocom/gsm/gsm48.h>
Philipp Maierfbf66102017-04-09 12:32:51 +020029#include <osmocom/gsm/gsm0808_utils.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020030#include <osmocom/msc/debug.h>
31#include <osmocom/msc/gsm_data.h>
32#include <osmocom/msc/a_iface_bssap.h>
33#include <osmocom/msc/a_iface.h>
34#include <osmocom/msc/osmo_msc.h>
Philipp Maierfbf66102017-04-09 12:32:51 +020035#include <osmocom/core/byteswap.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020036#include <osmocom/msc/a_reset.h>
Max43b01b02017-09-15 11:22:30 +020037#include <osmocom/msc/transaction.h>
Philipp Maier621ba032017-11-07 17:19:25 +010038#include <osmocom/msc/msc_mgcp.h>
Max43b01b02017-09-15 11:22:30 +020039
40#include <errno.h>
Philipp Maierfbf66102017-04-09 12:32:51 +020041
42#define IP_V4_ADDR_LEN 4
43
44/*
45 * Helper functions to lookup and allocate subscribers
46 */
47
48/* Allocate a new subscriber connection */
49static struct gsm_subscriber_connection *subscr_conn_allocate_a(const struct a_conn_info *a_conn_info,
50 struct gsm_network *network,
51 uint16_t lac, struct osmo_sccp_user *scu, int conn_id)
52{
53 struct gsm_subscriber_connection *conn;
54
Harald Weltef0dc1be2018-02-09 00:37:56 +010055 LOGP(DMSC, LOGL_DEBUG, "Allocating A-Interface subscriber conn: lac %i, conn_id %i\n", lac, conn_id);
Philipp Maierfbf66102017-04-09 12:32:51 +020056
Neels Hofmeyr93c74632018-04-02 23:10:28 +020057 conn = msc_subscr_conn_alloc(network, RAN_GERAN_A, lac);
Philipp Maierfbf66102017-04-09 12:32:51 +020058 if (!conn)
59 return NULL;
60
Philipp Maierfbf66102017-04-09 12:32:51 +020061 conn->a.conn_id = conn_id;
62 conn->a.scu = scu;
63
64 /* Also backup the calling address of the BSC, this allows us to
65 * identify later which BSC is responsible for this subscriber connection */
Harald Welte54a10ef2018-02-09 00:09:16 +010066 memcpy(&conn->a.bsc_addr, &a_conn_info->bsc->bsc_addr, sizeof(conn->a.bsc_addr));
Philipp Maierfbf66102017-04-09 12:32:51 +020067
Harald Welte6de46592018-02-09 00:53:17 +010068 LOGPCONN(conn, LOGL_DEBUG, "A-Interface subscriber connection successfully allocated!\n");
Philipp Maierfbf66102017-04-09 12:32:51 +020069 return conn;
70}
71
72/* Return an existing A subscriber connection record for the given
73 * connection IDs, or return NULL if not found. */
74static struct gsm_subscriber_connection *subscr_conn_lookup_a(const struct gsm_network *network, int conn_id)
75{
76 struct gsm_subscriber_connection *conn;
77
78 OSMO_ASSERT(network);
79
80 DEBUGP(DMSC, "Looking for A subscriber: conn_id %i\n", conn_id);
81
82 /* FIXME: log_subscribers() is defined in iucs.c as static inline, if
83 * maybe this function should be public to reach it from here? */
84 /* log_subscribers(network); */
85
86 llist_for_each_entry(conn, &network->subscr_conns, entry) {
87 if (conn->via_ran == RAN_GERAN_A && conn->a.conn_id == conn_id) {
Harald Welte6de46592018-02-09 00:53:17 +010088 LOGPCONN(conn, LOGL_DEBUG, "Found A subscriber for conn_id %i\n", conn_id);
Philipp Maierfbf66102017-04-09 12:32:51 +020089 return conn;
90 }
91 }
92 DEBUGP(DMSC, "No A subscriber found for conn_id %i\n", conn_id);
93 return NULL;
94}
95
96/*
97 * BSSMAP handling for UNITDATA
98 */
99
100/* Endpoint to handle BSSMAP reset */
101static void bssmap_rx_reset(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg)
102{
103 struct gsm_network *network = a_conn_info->network;
104 struct osmo_ss7_instance *ss7;
105
106 ss7 = osmo_ss7_instance_find(network->a.cs7_instance);
107 OSMO_ASSERT(ss7);
108
Harald Welte1f477442018-02-09 01:49:01 +0100109 LOGP(DBSSAP, LOGL_NOTICE, "Rx BSSMAP RESET from BSC %s, sending RESET ACK\n",
Harald Welte54a10ef2018-02-09 00:09:16 +0100110 osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr));
111 osmo_sccp_tx_unitdata_msg(scu, &a_conn_info->bsc->msc_addr, &a_conn_info->bsc->bsc_addr,
112 gsm0808_create_reset_ack());
Philipp Maierfbf66102017-04-09 12:32:51 +0200113
114 /* Make sure all orphand subscriber connections will be cleard */
Harald Welte54a10ef2018-02-09 00:09:16 +0100115 a_clear_all(scu, &a_conn_info->bsc->bsc_addr);
116
Philipp Maierf913e5f2018-05-07 10:15:49 +0200117 if (!a_conn_info->bsc->reset_fsm)
Harald Welte54a10ef2018-02-09 00:09:16 +0100118 a_start_reset(a_conn_info->bsc, true);
Harald Welte4de01152018-03-18 22:20:34 +0100119
120 /* Treat an incoming RESET like an ACK to any RESET request we may have just sent.
121 * After all, what we wanted is the A interface to be reset, which we now know has happened. */
Philipp Maierf913e5f2018-05-07 10:15:49 +0200122 a_reset_ack_confirm(a_conn_info->bsc->reset_fsm);
Philipp Maierfbf66102017-04-09 12:32:51 +0200123}
124
125/* Endpoint to handle BSSMAP reset acknowlegement */
126static void bssmap_rx_reset_ack(const struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info,
127 struct msgb *msg)
128{
129
130 struct gsm_network *network = a_conn_info->network;
131 struct osmo_ss7_instance *ss7;
132
133 ss7 = osmo_ss7_instance_find(network->a.cs7_instance);
134 OSMO_ASSERT(ss7);
135
Philipp Maierf913e5f2018-05-07 10:15:49 +0200136 if (a_conn_info->bsc->reset_fsm == NULL) {
Harald Welte1f477442018-02-09 01:49:01 +0100137 LOGP(DBSSAP, LOGL_ERROR, "Received RESET ACK from an unknown BSC %s, ignoring...\n",
Harald Welte54a10ef2018-02-09 00:09:16 +0100138 osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr));
Harald Weltea172e9e2018-02-09 21:33:24 +0100139 return;
Philipp Maierfbf66102017-04-09 12:32:51 +0200140 }
141
Harald Welte1f477442018-02-09 01:49:01 +0100142 LOGP(DBSSAP, LOGL_NOTICE, "Received RESET ACK from BSC %s\n",
Harald Welte54a10ef2018-02-09 00:09:16 +0100143 osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr));
Philipp Maierfbf66102017-04-09 12:32:51 +0200144
145 /* Confirm that we managed to get the reset ack message
146 * towards the connection reset logic */
Philipp Maierf913e5f2018-05-07 10:15:49 +0200147 a_reset_ack_confirm(a_conn_info->bsc->reset_fsm);
Philipp Maierfbf66102017-04-09 12:32:51 +0200148}
149
150/* Handle UNITDATA BSSMAP messages */
151static void bssmap_rcvmsg_udt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg)
152{
153 /* Note: When in the MSC role, RESET ACK is the only valid message that
154 * can be received via UNITDATA */
155
156 if (msgb_l3len(msg) < 1) {
Harald Welte1f477442018-02-09 01:49:01 +0100157 LOGP(DBSSAP, LOGL_NOTICE, "Error: No data received -- discarding message!\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200158 return;
159 }
160
Harald Welte1f477442018-02-09 01:49:01 +0100161 LOGP(DBSSAP, LOGL_DEBUG, "Rx BSSMAP UDT %s\n", gsm0808_bssmap_name(msg->l3h[0]));
Philipp Maierfbf66102017-04-09 12:32:51 +0200162
163 switch (msg->l3h[0]) {
164 case BSS_MAP_MSG_RESET:
165 bssmap_rx_reset(scu, a_conn_info, msg);
166 break;
167 case BSS_MAP_MSG_RESET_ACKNOWLEDGE:
168 bssmap_rx_reset_ack(scu, a_conn_info, msg);
169 break;
170 default:
Harald Welte1f477442018-02-09 01:49:01 +0100171 LOGP(DBSSAP, LOGL_NOTICE, "Unimplemented message format: %s -- message discarded!\n",
Philipp Maierfbf66102017-04-09 12:32:51 +0200172 gsm0808_bssmap_name(msg->l3h[0]));
Philipp Maierfbf66102017-04-09 12:32:51 +0200173 }
174}
175
176/* Receive incoming connection less data messages via sccp */
Neels Hofmeyrc1d69252017-12-18 04:06:04 +0100177void a_sccp_rx_udt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg)
Philipp Maierfbf66102017-04-09 12:32:51 +0200178{
179 /* Note: The only valid message type that can be received
180 * via UNITDATA are BSS Management messages */
181 struct bssmap_header *bs;
182
183 OSMO_ASSERT(scu);
184 OSMO_ASSERT(a_conn_info);
185 OSMO_ASSERT(msg);
186
Harald Welte1f477442018-02-09 01:49:01 +0100187 LOGP(DBSSAP, LOGL_DEBUG, "Rx BSSMAP UDT: %s\n", msgb_hexdump_l2(msg));
Philipp Maierfbf66102017-04-09 12:32:51 +0200188
189 if (msgb_l2len(msg) < sizeof(*bs)) {
Harald Welte1f477442018-02-09 01:49:01 +0100190 LOGP(DBSSAP, LOGL_ERROR, "Error: Header is too short -- discarding message!\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200191 return;
192 }
193
194 bs = (struct bssmap_header *)msgb_l2(msg);
195 if (bs->length < msgb_l2len(msg) - sizeof(*bs)) {
Harald Welte1f477442018-02-09 01:49:01 +0100196 LOGP(DBSSAP, LOGL_ERROR, "Error: Message is too short -- discarding message!\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200197 return;
198 }
199
200 switch (bs->type) {
201 case BSSAP_MSG_BSS_MANAGEMENT:
202 msg->l3h = &msg->l2h[sizeof(struct bssmap_header)];
203 bssmap_rcvmsg_udt(scu, a_conn_info, msg);
204 break;
205 default:
Harald Welte1f477442018-02-09 01:49:01 +0100206 LOGP(DBSSAP, LOGL_ERROR,
Philipp Maierfbf66102017-04-09 12:32:51 +0200207 "Error: Unimplemented message type: %s -- message discarded!\n", gsm0808_bssmap_name(bs->type));
Philipp Maierfbf66102017-04-09 12:32:51 +0200208 }
209}
210
211/*
212 * BSSMAP handling for connection oriented data
213 */
214
215/* Endpoint to handle BSSMAP clear request */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100216static int bssmap_rx_clear_rqst(struct gsm_subscriber_connection *conn,
217 struct msgb *msg, struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200218{
Philipp Maierfbf66102017-04-09 12:32:51 +0200219 uint8_t cause;
Philipp Maierfbf66102017-04-09 12:32:51 +0200220
Harald Welte35284462018-02-09 01:31:29 +0100221 LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP CLEAR REQUEST\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200222
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100223 if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) {
Harald Welte1f477442018-02-09 01:49:01 +0100224 LOGP(DBSSAP, LOGL_ERROR, "Cause code is missing -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100225 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200226 }
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100227 cause = TLVP_VAL(tp, GSM0808_IE_CAUSE)[0];
Philipp Maierfbf66102017-04-09 12:32:51 +0200228
Neels Hofmeyr2a5cd932018-04-06 01:07:42 +0200229 msc_subscr_conn_mo_close(conn, cause);
Philipp Maierfbf66102017-04-09 12:32:51 +0200230
Neels Hofmeyr2a5cd932018-04-06 01:07:42 +0200231 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200232}
233
234/* Endpoint to handle BSSMAP clear complete */
Harald Weltec27ef652018-02-09 01:23:25 +0100235static int bssmap_rx_clear_complete(struct osmo_sccp_user *scu,
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200236 const struct a_conn_info *a_conn_info,
237 struct gsm_subscriber_connection *conn)
Philipp Maierfbf66102017-04-09 12:32:51 +0200238{
239 int rc;
240
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200241 LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP CLEAR COMPLETE, releasing SCCP connection\n");
242
243 if (conn)
244 msc_subscr_conn_rx_bssmap_clear_complete(conn);
245
Philipp Maierfbf66102017-04-09 12:32:51 +0200246 rc = osmo_sccp_tx_disconn(scu, a_conn_info->conn_id,
Harald Welte54a10ef2018-02-09 00:09:16 +0100247 NULL, SCCP_RELEASE_CAUSE_END_USER_ORIGINATED);
Philipp Maierfbf66102017-04-09 12:32:51 +0200248
249 /* Remove the record from the list with active connections. */
250 a_delete_bsc_con(a_conn_info->conn_id);
251
Philipp Maierfbf66102017-04-09 12:32:51 +0200252 return rc;
253}
254
255/* Endpoint to handle layer 3 complete messages */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100256static int bssmap_rx_l3_compl(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info,
257 struct msgb *msg, struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200258{
Stefan Sperlingbe7e0692018-03-14 14:00:00 +0100259 struct gsm0808_cell_id_list2 cil;
260 uint16_t lac = 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200261 uint8_t data_length;
262 const uint8_t *data;
Philipp Maierfbf66102017-04-09 12:32:51 +0200263 struct gsm_network *network = a_conn_info->network;
264 struct gsm_subscriber_connection *conn;
265
Harald Welte1f477442018-02-09 01:49:01 +0100266 LOGP(DBSSAP, LOGL_INFO, "Rx BSSMAP COMPLETE L3 INFO (conn_id=%i)\n", a_conn_info->conn_id);
Philipp Maierfbf66102017-04-09 12:32:51 +0200267
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100268 if (!TLVP_PRESENT(tp, GSM0808_IE_CELL_IDENTIFIER)) {
Harald Welte1f477442018-02-09 01:49:01 +0100269 LOGP(DBSSAP, LOGL_ERROR, "Mandatory CELL IDENTIFIER not present -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100270 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200271 }
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100272 if (!TLVP_PRESENT(tp, GSM0808_IE_LAYER_3_INFORMATION)) {
Harald Welte1f477442018-02-09 01:49:01 +0100273 LOGP(DBSSAP, LOGL_ERROR, "Mandatory LAYER 3 INFORMATION not present -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100274 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200275 }
276
Stefan Sperlingbe7e0692018-03-14 14:00:00 +0100277 /* Parse Cell ID element -- this should yield a cell identifier "list" with 1 element. */
278
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100279 data_length = TLVP_LEN(tp, GSM0808_IE_CELL_IDENTIFIER);
280 data = TLVP_VAL(tp, GSM0808_IE_CELL_IDENTIFIER);
Stefan Sperlingbe7e0692018-03-14 14:00:00 +0100281 if (gsm0808_dec_cell_id_list2(&cil, data, data_length) < 0 || cil.id_list_len != 1) {
Harald Welte1f477442018-02-09 01:49:01 +0100282 LOGP(DBSSAP, LOGL_ERROR,
Stefan Sperlingbe7e0692018-03-14 14:00:00 +0100283 "Unable to parse element CELL IDENTIFIER -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100284 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200285 }
Stefan Sperlingbe7e0692018-03-14 14:00:00 +0100286
287 /* Determine the LAC which we will use for this subscriber. */
288 switch (cil.id_discr) {
289 case CELL_IDENT_WHOLE_GLOBAL: {
290 const struct osmo_cell_global_id *id = &cil.id_list[0].global;
291 if (osmo_plmn_cmp(&id->lai.plmn, &network->plmn) != 0) {
292 LOGP(DBSSAP, LOGL_ERROR,
293 "WHOLE GLOBAL CELL IDENTIFIER does not match network MCC/MNC -- discarding message!\n");
294 return -EINVAL;
295 }
296 lac = id->lai.lac;
297 break;
298 }
299 case CELL_IDENT_LAC_AND_CI: {
300 const struct osmo_lac_and_ci_id *id = &cil.id_list[0].lac_and_ci;
301 lac = id->lac;
302 break;
303 }
304 case CELL_IDENT_LAI_AND_LAC: {
305 const struct osmo_location_area_id *id = &cil.id_list[0].lai_and_lac;
306 if (osmo_plmn_cmp(&id->plmn, &network->plmn) != 0) {
307 LOGP(DBSSAP, LOGL_ERROR,
308 "LAI AND LAC CELL IDENTIFIER does not match network MCC/MNC -- discarding message!\n");
309 return -EINVAL;
310 }
311 lac = id->lac;
312 break;
313 }
314 case CELL_IDENT_LAC:
315 lac = cil.id_list[0].lac;
316 break;
317
318 case CELL_IDENT_CI:
319 case CELL_IDENT_NO_CELL:
320 case CELL_IDENT_BSS:
Harald Welte1f477442018-02-09 01:49:01 +0100321 LOGP(DBSSAP, LOGL_ERROR,
Stefan Sperlingbe7e0692018-03-14 14:00:00 +0100322 "CELL IDENTIFIER does not specify a LAC -- discarding message!\n");
323 return -EINVAL;
324
325 default:
326 LOGP(DBSSAP, LOGL_ERROR,
327 "Unable to parse element CELL IDENTIFIER (unknown cell identification discriminator 0x%x) "
328 "-- discarding message!\n", cil.id_discr);
Harald Weltea172e9e2018-02-09 21:33:24 +0100329 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200330 }
Philipp Maierfbf66102017-04-09 12:32:51 +0200331
332 /* Parse Layer 3 Information element */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100333 msg->l3h = (uint8_t*)TLVP_VAL(tp, GSM0808_IE_LAYER_3_INFORMATION);
Pau Espin Pedrol02a79d82017-12-15 18:55:43 +0100334 msgb_l3trim(msg, TLVP_LEN(tp, GSM0808_IE_LAYER_3_INFORMATION));
Philipp Maierfbf66102017-04-09 12:32:51 +0200335
Harald Welte5060f562018-03-18 21:55:37 +0100336 if (msgb_l3len(msg) < sizeof(struct gsm48_hdr)) {
337 LOGP(DBSSAP, LOGL_ERROR, "COMPL_L3 with too short L3 (%d) -- discarding\n",
338 msgb_l3len(msg));
339 return -ENODATA;
340 }
341
Philipp Maierfbf66102017-04-09 12:32:51 +0200342 /* Create new subscriber context */
Stefan Sperlingbe7e0692018-03-14 14:00:00 +0100343 conn = subscr_conn_allocate_a(a_conn_info, network, lac, scu, a_conn_info->conn_id);
Philipp Maierfbf66102017-04-09 12:32:51 +0200344
345 /* Handover location update to the MSC code */
Neels Hofmeyrd03e7282018-11-30 01:20:32 +0100346 msc_compl_l3(conn, msg, 0);
347 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200348}
349
350/* Endpoint to handle BSSMAP classmark update */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100351static int bssmap_rx_classmark_upd(struct gsm_subscriber_connection *conn, struct msgb *msg,
352 struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200353{
Philipp Maierfbf66102017-04-09 12:32:51 +0200354 const uint8_t *cm2 = NULL;
355 const uint8_t *cm3 = NULL;
356 uint8_t cm2_len = 0;
357 uint8_t cm3_len = 0;
358
Harald Weltefb7ba912018-02-09 01:05:27 +0100359 LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP CLASSMARK UPDATE\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200360
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100361 if (!TLVP_PRESENT(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2)) {
Harald Welte6de46592018-02-09 00:53:17 +0100362 LOGPCONN(conn, LOGL_ERROR, "Mandatory Classmark Information Type 2 not present -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100363 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200364 }
365
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100366 cm2 = TLVP_VAL(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2);
367 cm2_len = TLVP_LEN(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2);
Philipp Maierfbf66102017-04-09 12:32:51 +0200368
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100369 if (TLVP_PRESENT(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3)) {
370 cm3 = TLVP_VAL(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3);
371 cm3_len = TLVP_LEN(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3);
Philipp Maierfbf66102017-04-09 12:32:51 +0200372 }
373
374 /* Inform MSC about the classmark change */
375 msc_classmark_chg(conn, cm2, cm2_len, cm3, cm3_len);
376
Philipp Maierfbf66102017-04-09 12:32:51 +0200377 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200378}
379
380/* Endpoint to handle BSSMAP cipher mode complete */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100381static int bssmap_rx_ciph_compl(struct gsm_subscriber_connection *conn, struct msgb *msg,
382 struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200383{
384 /* FIXME: The field GSM0808_IE_LAYER_3_MESSAGE_CONTENTS is optional by
385 * means of the specification. So there can be messages without L3 info.
386 * In this case, the code will crash becrause msc_cipher_mode_compl()
387 * is not able to deal with msg = NULL and apperently
388 * msc_cipher_mode_compl() was never meant to be used without L3 data.
389 * This needs to be discussed further! */
390
Philipp Maierfbf66102017-04-09 12:32:51 +0200391 uint8_t alg_id = 1;
Max366390d2018-11-02 16:01:03 +0100392 struct rate_ctr_group *msc = conn->network->msc_ctrs;
Philipp Maierfbf66102017-04-09 12:32:51 +0200393
Harald Weltefb7ba912018-02-09 01:05:27 +0100394 LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP CIPHER MODE COMPLETE\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200395
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100396 if (TLVP_PRESENT(tp, GSM0808_IE_CHOSEN_ENCR_ALG)) {
397 alg_id = TLVP_VAL(tp, GSM0808_IE_CHOSEN_ENCR_ALG)[0] - 1;
Philipp Maierfbf66102017-04-09 12:32:51 +0200398 }
399
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100400 if (TLVP_PRESENT(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS)) {
401 msg->l3h = (uint8_t*)TLVP_VAL(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS);
Pau Espin Pedrol02a79d82017-12-15 18:55:43 +0100402 msgb_l3trim(msg, TLVP_LEN(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS));
Philipp Maierfbf66102017-04-09 12:32:51 +0200403 } else {
Philipp Maierfbf66102017-04-09 12:32:51 +0200404 msg = NULL;
405 }
406
Max366390d2018-11-02 16:01:03 +0100407 rate_ctr_inc(&msc->ctr[MSC_CTR_BSSMAP_CIPHER_MODE_COMPLETE]);
408
Philipp Maier4502f5f2017-09-07 11:39:58 +0200409 /* Hand over cipher mode complete message to the MSC */
Philipp Maierfbf66102017-04-09 12:32:51 +0200410 msc_cipher_mode_compl(conn, msg, alg_id);
411
412 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200413}
414
Max662e2ba2018-11-01 17:34:12 +0100415/* Endpoint to handle BSSMAP cipher mode reject, 3GPP TS 08.08 §3.2.1.48 */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100416static int bssmap_rx_ciph_rej(struct gsm_subscriber_connection *conn,
417 struct msgb *msg, struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200418{
Max58099f62018-11-19 15:04:55 +0100419 int rc;
Max662e2ba2018-11-01 17:34:12 +0100420 enum gsm0808_cause cause;
Max366390d2018-11-02 16:01:03 +0100421 struct rate_ctr_group *msc = conn->network->msc_ctrs;
Philipp Maierfbf66102017-04-09 12:32:51 +0200422
Harald Weltefb7ba912018-02-09 01:05:27 +0100423 LOGPCONN(conn, LOGL_NOTICE, "RX BSSMAP CIPHER MODE REJECT\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200424
Max58099f62018-11-19 15:04:55 +0100425 rc = gsm0808_get_cipher_reject_cause(tp);
426 if (rc < 0) {
427 LOGPCONN(conn, LOGL_ERROR, "failed (%s) to extract Cause from Cipher mode reject: %s\n",
428 strerror(-rc), msgb_hexdump(msg));
429 return rc;
Philipp Maierfbf66102017-04-09 12:32:51 +0200430 }
431
Max366390d2018-11-02 16:01:03 +0100432 rate_ctr_inc(&msc->ctr[MSC_CTR_BSSMAP_CIPHER_MODE_REJECT]);
Max58099f62018-11-19 15:04:55 +0100433 cause = (enum gsm0808_cause)rc;
Max662e2ba2018-11-01 17:34:12 +0100434 LOGPCONN(conn, LOGL_NOTICE, "Cipher mode rejection cause: %s\n", gsm0808_cause_name(cause));
Philipp Maierfbf66102017-04-09 12:32:51 +0200435
436 /* FIXME: Can we do something meaningful here? e.g. report to the
437 * msc code somehow that the cipher mode command has failed. */
438
Philipp Maierfbf66102017-04-09 12:32:51 +0200439 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200440}
441
442/* Endpoint to handle BSSMAP assignment failure */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100443static int bssmap_rx_ass_fail(struct gsm_subscriber_connection *conn, struct msgb *msg,
444 struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200445{
Philipp Maierfbf66102017-04-09 12:32:51 +0200446 uint8_t cause;
447 uint8_t *rr_cause_ptr = NULL;
448 uint8_t rr_cause;
449
Harald Weltefb7ba912018-02-09 01:05:27 +0100450 LOGPCONN(conn, LOGL_NOTICE, "Rx BSSMAP ASSIGNMENT FAILURE message\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200451
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100452 if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) {
Harald Welte6de46592018-02-09 00:53:17 +0100453 LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100454 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200455 }
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100456 cause = TLVP_VAL(tp, GSM0808_IE_CAUSE)[0];
Philipp Maierfbf66102017-04-09 12:32:51 +0200457
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100458 if (TLVP_PRESENT(tp, GSM0808_IE_RR_CAUSE)) {
459 rr_cause = TLVP_VAL(tp, GSM0808_IE_RR_CAUSE)[0];
Philipp Maierfbf66102017-04-09 12:32:51 +0200460 rr_cause_ptr = &rr_cause;
461 }
462
463 /* FIXME: In AoIP, the Assignment failure will carry also an optional
464 * Codec List (BSS Supported) element. It has to be discussed if we
465 * can ignore this element. If not, The msc_assign_fail() function
466 * call has to change. However msc_assign_fail() does nothing in the
467 * end. So probably we can just leave it as it is. Even for AoIP */
468
469 /* Inform the MSC about the assignment failure event */
470 msc_assign_fail(conn, cause, rr_cause_ptr);
471
Philipp Maierfbf66102017-04-09 12:32:51 +0200472 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200473}
474
475/* Endpoint to handle sapi "n" reject */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100476static int bssmap_rx_sapi_n_rej(struct gsm_subscriber_connection *conn, struct msgb *msg,
477 struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200478{
Philipp Maierfbf66102017-04-09 12:32:51 +0200479 uint8_t dlci;
480
Harald Welte35284462018-02-09 01:31:29 +0100481 LOGPCONN(conn, LOGL_NOTICE, "Rx BSSMAP SAPI-N-REJECT message\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200482
483 /* Note: The MSC code seems not to care about the cause code, but by
484 * the specification it is mandatory, so we check its presence. See
485 * also 3GPP TS 48.008 3.2.1.34 SAPI "n" REJECT */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100486 if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) {
Harald Welte6de46592018-02-09 00:53:17 +0100487 LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100488 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200489 }
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100490 if (!TLVP_PRESENT(tp, GSM0808_IE_DLCI)) {
Harald Welte6de46592018-02-09 00:53:17 +0100491 LOGPCONN(conn, LOGL_ERROR, "DLCI is missing -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100492 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200493 }
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100494 dlci = TLVP_VAL(tp, GSM0808_IE_DLCI)[0];
Philipp Maierfbf66102017-04-09 12:32:51 +0200495
496 /* Inform the MSC about the sapi "n" reject event */
497 msc_sapi_n_reject(conn, dlci);
498
Philipp Maierfbf66102017-04-09 12:32:51 +0200499 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200500}
501
Philipp Maier8ad3dac2018-08-07 13:00:14 +0200502/* Use the speech codec info we go with the assignment complete to dtermine
503 * which codec we will signal to the MGW */
504static enum mgcp_codecs mgcp_codec_from_sc(struct gsm0808_speech_codec *sc)
505{
506 switch (sc->type) {
507 case GSM0808_SCT_FR1:
508 return CODEC_GSM_8000_1;
509 break;
510 case GSM0808_SCT_FR2:
511 return CODEC_GSMEFR_8000_1;
512 break;
513 case GSM0808_SCT_FR3:
514 return CODEC_AMR_8000_1;
515 break;
516 case GSM0808_SCT_FR4:
517 return CODEC_AMRWB_16000_1;
518 break;
519 case GSM0808_SCT_FR5:
520 return CODEC_AMRWB_16000_1;
521 break;
522 case GSM0808_SCT_HR1:
523 return CODEC_GSMHR_8000_1;
524 break;
525 case GSM0808_SCT_HR3:
526 return CODEC_AMR_8000_1;
527 break;
528 case GSM0808_SCT_HR4:
529 return CODEC_AMRWB_16000_1;
530 break;
531 case GSM0808_SCT_HR6:
532 return CODEC_AMRWB_16000_1;
533 break;
534 default:
535 return CODEC_PCMU_8000_1;
536 break;
537 }
538}
539
Philipp Maierfbf66102017-04-09 12:32:51 +0200540/* Endpoint to handle assignment complete */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100541static int bssmap_rx_ass_compl(struct gsm_subscriber_connection *conn, struct msgb *msg,
542 struct tlv_parsed *tp)
Philipp Maierfbf66102017-04-09 12:32:51 +0200543{
Philipp Maierfbf66102017-04-09 12:32:51 +0200544 struct sockaddr_storage rtp_addr;
Philipp Maier8ad3dac2018-08-07 13:00:14 +0200545 struct gsm0808_speech_codec sc;
Philipp Maierfbf66102017-04-09 12:32:51 +0200546 struct sockaddr_in *rtp_addr_in;
547 int rc;
548
Harald Welte35284462018-02-09 01:31:29 +0100549 LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP ASSIGNMENT COMPLETE message\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200550
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100551 if (!TLVP_PRESENT(tp, GSM0808_IE_AOIP_TRASP_ADDR)) {
Harald Welte6de46592018-02-09 00:53:17 +0100552 LOGPCONN(conn, LOGL_ERROR, "AoIP transport identifier missing -- discarding message!\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100553 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200554 }
555
556 /* Decode AoIP transport address element */
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100557 rc = gsm0808_dec_aoip_trasp_addr(&rtp_addr, TLVP_VAL(tp, GSM0808_IE_AOIP_TRASP_ADDR),
558 TLVP_LEN(tp, GSM0808_IE_AOIP_TRASP_ADDR));
Philipp Maierfbf66102017-04-09 12:32:51 +0200559 if (rc < 0) {
Harald Welte6de46592018-02-09 00:53:17 +0100560 LOGPCONN(conn, LOGL_ERROR, "Unable to decode aoip transport address.\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100561 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200562 }
563
Philipp Maier8ad3dac2018-08-07 13:00:14 +0200564 /* Decode speech codec (choosen) element */
565 rc = gsm0808_dec_speech_codec(&sc, TLVP_VAL(tp, GSM0808_IE_SPEECH_CODEC),
566 TLVP_LEN(tp, GSM0808_IE_SPEECH_CODEC));
567 if (rc < 0) {
568 LOGPCONN(conn, LOGL_ERROR, "Unable to decode speech codec (choosen).\n");
569 return -EINVAL;
570 }
571 conn->rtp.codec_ran = mgcp_codec_from_sc(&sc);
572
Philipp Maierfbf66102017-04-09 12:32:51 +0200573 /* use address / port supplied with the AoIP
574 * transport address element */
575 if (rtp_addr.ss_family == AF_INET) {
576 rtp_addr_in = (struct sockaddr_in *)&rtp_addr;
Philipp Maier621ba032017-11-07 17:19:25 +0100577 msc_mgcp_ass_complete(conn, osmo_ntohs(rtp_addr_in->sin_port), inet_ntoa(rtp_addr_in->sin_addr));
Philipp Maierfbf66102017-04-09 12:32:51 +0200578 } else {
Harald Welte6de46592018-02-09 00:53:17 +0100579 LOGPCONN(conn, LOGL_ERROR, "Unsopported addressing scheme. (supports only IPV4)\n");
Harald Weltea172e9e2018-02-09 21:33:24 +0100580 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200581 }
582
583 /* FIXME: Seems to be related to authentication or,
584 encryption. Is this really in the right place? */
585 msc_rx_sec_mode_compl(conn);
586
Philipp Maierfbf66102017-04-09 12:32:51 +0200587 return 0;
Philipp Maierfbf66102017-04-09 12:32:51 +0200588}
589
590/* Handle incoming connection oriented BSSMAP messages */
591static int rx_bssmap(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg)
592{
Harald Weltec27ef652018-02-09 01:23:25 +0100593 struct gsm_subscriber_connection *conn;
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100594 struct tlv_parsed tp;
Pau Espin Pedrol75559282018-02-14 14:12:24 +0100595 int rc;
Neels Hofmeyrae73d2b2018-04-01 20:58:08 +0200596 uint8_t msg_type;
Harald Weltec27ef652018-02-09 01:23:25 +0100597
Philipp Maierfbf66102017-04-09 12:32:51 +0200598 if (msgb_l3len(msg) < 1) {
Harald Welte1f477442018-02-09 01:49:01 +0100599 LOGP(DBSSAP, LOGL_NOTICE, "Error: No data received -- discarding message!\n");
Philipp Maierfbf66102017-04-09 12:32:51 +0200600 return -1;
601 }
Neels Hofmeyrae73d2b2018-04-01 20:58:08 +0200602 msg_type = msg->l3h[0];
Philipp Maierfbf66102017-04-09 12:32:51 +0200603
Maxf1329c52018-11-19 14:55:56 +0100604 rc = osmo_bssap_tlv_parse(&tp, msg->l3h + 1, msgb_l3len(msg) - 1);
Pau Espin Pedrol75559282018-02-14 14:12:24 +0100605 if (rc < 0) {
606 LOGP(DBSSAP, LOGL_ERROR, "Failed parsing TLV -- discarding message! %s\n",
607 osmo_hexdump(msg->l3h, msgb_l3len(msg)));
608 return -EINVAL;
609 }
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100610
Harald Weltec27ef652018-02-09 01:23:25 +0100611 /* Only message types allowed without a 'conn' */
Neels Hofmeyrae73d2b2018-04-01 20:58:08 +0200612 switch (msg_type) {
Harald Weltec27ef652018-02-09 01:23:25 +0100613 case BSS_MAP_MSG_COMPLETE_LAYER_3:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100614 return bssmap_rx_l3_compl(scu, a_conn_info, msg, &tp);
Harald Weltec27ef652018-02-09 01:23:25 +0100615 default:
616 break;
617 }
618
619 conn = subscr_conn_lookup_a(a_conn_info->network, a_conn_info->conn_id);
620 if (!conn) {
Harald Welte1f477442018-02-09 01:49:01 +0100621 LOGP(DBSSAP, LOGL_ERROR, "Couldn't find subscr_conn for conn_id=%d\n", a_conn_info->conn_id);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200622 /* We expect a Clear Complete to come in on a valid conn. But if for some reason we still
623 * have the SCCP connection while the subscriber connection data is already gone, at
624 * least close the SCCP conn. */
625
626 if (msg_type == BSS_MAP_MSG_CLEAR_COMPLETE)
627 return bssmap_rx_clear_complete(scu, a_conn_info, NULL);
628
Harald Weltec27ef652018-02-09 01:23:25 +0100629 return -EINVAL;
630 }
631
Neels Hofmeyrae73d2b2018-04-01 20:58:08 +0200632 LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP DT1 %s\n", gsm0808_bssmap_name(msg_type));
Philipp Maierfbf66102017-04-09 12:32:51 +0200633
Neels Hofmeyrae73d2b2018-04-01 20:58:08 +0200634 switch (msg_type) {
Philipp Maierfbf66102017-04-09 12:32:51 +0200635 case BSS_MAP_MSG_CLEAR_RQST:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100636 return bssmap_rx_clear_rqst(conn, msg, &tp);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200637 case BSS_MAP_MSG_CLEAR_COMPLETE:
638 return bssmap_rx_clear_complete(scu, a_conn_info, conn);
Philipp Maierfbf66102017-04-09 12:32:51 +0200639 case BSS_MAP_MSG_CLASSMARK_UPDATE:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100640 return bssmap_rx_classmark_upd(conn, msg, &tp);
Philipp Maierfbf66102017-04-09 12:32:51 +0200641 case BSS_MAP_MSG_CIPHER_MODE_COMPLETE:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100642 return bssmap_rx_ciph_compl(conn, msg, &tp);
Philipp Maierfbf66102017-04-09 12:32:51 +0200643 case BSS_MAP_MSG_CIPHER_MODE_REJECT:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100644 return bssmap_rx_ciph_rej(conn, msg, &tp);
Philipp Maierfbf66102017-04-09 12:32:51 +0200645 case BSS_MAP_MSG_ASSIGMENT_FAILURE:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100646 return bssmap_rx_ass_fail(conn, msg, &tp);
Philipp Maierfbf66102017-04-09 12:32:51 +0200647 case BSS_MAP_MSG_SAPI_N_REJECT:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100648 return bssmap_rx_sapi_n_rej(conn, msg, &tp);
Philipp Maierfbf66102017-04-09 12:32:51 +0200649 case BSS_MAP_MSG_ASSIGMENT_COMPLETE:
Pau Espin Pedrol31776ff2018-02-14 12:13:35 +0100650 return bssmap_rx_ass_compl(conn, msg, &tp);
Philipp Maierfbf66102017-04-09 12:32:51 +0200651 default:
Neels Hofmeyrae73d2b2018-04-01 20:58:08 +0200652 LOGPCONN(conn, LOGL_ERROR, "Unimplemented msg type: %s\n", gsm0808_bssmap_name(msg_type));
Philipp Maierfbf66102017-04-09 12:32:51 +0200653 return -EINVAL;
654 }
655
656 return -EINVAL;
657}
658
Harald Weltea172e9e2018-02-09 21:33:24 +0100659/* Endpoint to handle regular BSSAP DTAP messages. No ownership of 'msg' is passed on! */
Philipp Maierfbf66102017-04-09 12:32:51 +0200660static int rx_dtap(const struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg)
661{
662 struct gsm_network *network = a_conn_info->network;
663 struct gsm_subscriber_connection *conn;
Harald Welte0e2fa5d2018-04-09 16:35:01 +0200664 struct dtap_header *dtap = (struct dtap_header *) msg->l2h;
Philipp Maierfbf66102017-04-09 12:32:51 +0200665
666 conn = subscr_conn_lookup_a(network, a_conn_info->conn_id);
667 if (!conn) {
Philipp Maierfbf66102017-04-09 12:32:51 +0200668 return -EINVAL;
669 }
670
Harald Weltefb7ba912018-02-09 01:05:27 +0100671 LOGPCONN(conn, LOGL_DEBUG, "Rx DTAP %s\n", msgb_hexdump_l2(msg));
Philipp Maierfbf66102017-04-09 12:32:51 +0200672
673 /* msc_dtap expects the dtap payload in l3h */
674 msg->l3h = msg->l2h + 3;
Harald Welte0e2fa5d2018-04-09 16:35:01 +0200675 OMSC_LINKID_CB(msg) = dtap->link_id;
Philipp Maierfbf66102017-04-09 12:32:51 +0200676
Philipp Maier4502f5f2017-09-07 11:39:58 +0200677 /* Forward dtap payload into the msc */
Philipp Maier54729d62018-11-19 18:31:16 +0100678 msc_dtap(conn, msg);
Philipp Maierfbf66102017-04-09 12:32:51 +0200679
680 return 0;
681}
682
Harald Weltea172e9e2018-02-09 21:33:24 +0100683/* Handle incoming connection oriented messages. No ownership of 'msg' is passed on! */
Neels Hofmeyrc1d69252017-12-18 04:06:04 +0100684int a_sccp_rx_dt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg)
Philipp Maierfbf66102017-04-09 12:32:51 +0200685{
686 OSMO_ASSERT(scu);
687 OSMO_ASSERT(a_conn_info);
688 OSMO_ASSERT(msg);
689
Philipp Maierfbf66102017-04-09 12:32:51 +0200690 if (msgb_l2len(msg) < sizeof(struct bssmap_header)) {
Harald Welte1f477442018-02-09 01:49:01 +0100691 LOGP(DBSSAP, LOGL_NOTICE, "The header is too short -- discarding message!\n");
Philipp Maier4502f5f2017-09-07 11:39:58 +0200692 return -EINVAL;
Philipp Maierfbf66102017-04-09 12:32:51 +0200693 }
694
695 switch (msg->l2h[0]) {
696 case BSSAP_MSG_BSS_MANAGEMENT:
697 msg->l3h = &msg->l2h[sizeof(struct bssmap_header)];
698 return rx_bssmap(scu, a_conn_info, msg);
Philipp Maierfbf66102017-04-09 12:32:51 +0200699 case BSSAP_MSG_DTAP:
700 return rx_dtap(scu, a_conn_info, msg);
Philipp Maierfbf66102017-04-09 12:32:51 +0200701 default:
Harald Welte1f477442018-02-09 01:49:01 +0100702 LOGP(DBSSAP, LOGL_ERROR, "Unimplemented BSSAP msg type: %s\n", gsm0808_bssap_name(msg->l2h[0]));
Philipp Maierfbf66102017-04-09 12:32:51 +0200703 return -EINVAL;
704 }
705
706 return -EINVAL;
707}