blob: 495a313252bf60696411c36dc22c9d32817825cc [file] [log] [blame]
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +01001/* GSM 08.08 BSSMAP handling */
2/* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * (C) 2009-2010 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +01009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +010015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +010018 *
19 */
20
21#include <openbsc/osmo_bsc.h>
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +010022#include <openbsc/osmo_bsc_grace.h>
Holger Hans Peter Freyther50c579b2010-11-10 10:07:30 +010023#include <openbsc/osmo_msc_data.h>
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +010024#include <openbsc/debug.h>
Holger Hans Peter Freyther9c838ae2010-11-15 09:16:09 +010025#include <openbsc/gsm_subscriber.h>
Holger Hans Peter Freyther50c579b2010-11-10 10:07:30 +010026#include <openbsc/mgcp.h>
Holger Hans Peter Freyther9c838ae2010-11-15 09:16:09 +010027#include <openbsc/paging.h>
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +010028
Harald Welted36ff762011-03-23 18:26:56 +010029#include <osmocom/gsm/protocol/gsm_08_08.h>
30#include <osmocom/gsm/gsm0808.h>
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +010031
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +010032#include <arpa/inet.h>
33
34static uint16_t read_data16(const uint8_t *data)
35{
36 uint16_t res;
37
38 memcpy(&res, data, sizeof(res));
39 return res;
40}
41
Holger Hans Peter Freyther50c579b2010-11-10 10:07:30 +010042/*
43 * helpers for the assignment command
44 */
45enum gsm0808_permitted_speech audio_support_to_gsm88(struct gsm_audio_support *audio)
46{
47 if (audio->hr) {
48 switch (audio->ver) {
49 case 1:
50 return GSM0808_PERM_HR1;
51 break;
52 case 2:
53 return GSM0808_PERM_HR2;
54 break;
55 case 3:
56 return GSM0808_PERM_HR3;
57 break;
58 default:
59 LOGP(DMSC, LOGL_ERROR, "Wrong speech mode: %d\n", audio->ver);
60 return GSM0808_PERM_FR1;
61 }
62 } else {
63 switch (audio->ver) {
64 case 1:
65 return GSM0808_PERM_FR1;
66 break;
67 case 2:
68 return GSM0808_PERM_FR2;
69 break;
70 case 3:
71 return GSM0808_PERM_FR3;
72 break;
73 default:
74 LOGP(DMSC, LOGL_ERROR, "Wrong speech mode: %d\n", audio->ver);
75 return GSM0808_PERM_HR1;
76 }
77 }
78}
79
80enum gsm48_chan_mode gsm88_to_chan_mode(enum gsm0808_permitted_speech speech)
81{
82 switch (speech) {
83 case GSM0808_PERM_HR1:
84 case GSM0808_PERM_FR1:
85 return GSM48_CMODE_SPEECH_V1;
86 break;
87 case GSM0808_PERM_HR2:
88 case GSM0808_PERM_FR2:
89 return GSM48_CMODE_SPEECH_EFR;
90 break;
91 case GSM0808_PERM_HR3:
92 case GSM0808_PERM_FR3:
93 return GSM48_CMODE_SPEECH_AMR;
94 break;
95 }
96
97 LOGP(DMSC, LOGL_FATAL, "Should not be reached.\n");
98 return GSM48_CMODE_SPEECH_AMR;
99}
100
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100101static int bssmap_handle_reset_ack(struct gsm_network *net,
102 struct msgb *msg, unsigned int length)
103{
104 LOGP(DMSC, LOGL_NOTICE, "Reset ACK from MSC\n");
105 return 0;
106}
107
108/* GSM 08.08 ยง 3.2.1.19 */
109static int bssmap_handle_paging(struct gsm_network *net,
110 struct msgb *msg, unsigned int payload_length)
111{
Holger Hans Peter Freyther9c838ae2010-11-15 09:16:09 +0100112 struct gsm_subscriber *subscr;
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100113 struct tlv_parsed tp;
114 char mi_string[GSM48_MI_SIZE];
115 uint32_t tmsi = GSM_RESERVED_TMSI;
116 unsigned int lac = GSM_LAC_RESERVED_ALL_BTS;
117 uint8_t data_length;
118 const uint8_t *data;
119 uint8_t chan_needed = RSL_CHANNEED_ANY;
120
121 tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l4h + 1, payload_length - 1, 0, 0);
122
123 if (!TLVP_PRESENT(&tp, GSM0808_IE_IMSI)) {
124 LOGP(DMSC, LOGL_ERROR, "Mandantory IMSI not present.\n");
125 return -1;
126 } else if ((TLVP_VAL(&tp, GSM0808_IE_IMSI)[0] & GSM_MI_TYPE_MASK) != GSM_MI_TYPE_IMSI) {
127 LOGP(DMSC, LOGL_ERROR, "Wrong content in the IMSI\n");
128 return -1;
129 }
130
131 if (!TLVP_PRESENT(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST)) {
132 LOGP(DMSC, LOGL_ERROR, "Mandantory CELL IDENTIFIER LIST not present.\n");
133 return -1;
134 }
135
136 if (TLVP_PRESENT(&tp, GSM0808_IE_TMSI)) {
137 gsm48_mi_to_string(mi_string, sizeof(mi_string),
138 TLVP_VAL(&tp, GSM0808_IE_TMSI), TLVP_LEN(&tp, GSM0808_IE_TMSI));
139 tmsi = strtoul(mi_string, NULL, 10);
140 }
141
142
143 /*
144 * parse the IMSI
145 */
146 gsm48_mi_to_string(mi_string, sizeof(mi_string),
147 TLVP_VAL(&tp, GSM0808_IE_IMSI), TLVP_LEN(&tp, GSM0808_IE_IMSI));
148
149 /*
150 * parse the cell identifier list
151 */
152 data_length = TLVP_LEN(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
153 data = TLVP_VAL(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
154
155 /*
156 * Support paging to all network or one BTS at one LAC
157 */
158 if (data_length == 3 && data[0] == CELL_IDENT_LAC) {
159 lac = ntohs(read_data16(&data[1]));
160 } else if (data_length > 1 || (data[0] & 0x0f) != CELL_IDENT_BSS) {
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200161 LOGP(DMSC, LOGL_ERROR, "Unsupported Cell Identifier List: %s\n", osmo_hexdump(data, data_length));
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100162 return -1;
163 }
164
165 if (TLVP_PRESENT(&tp, GSM0808_IE_CHANNEL_NEEDED) && TLVP_LEN(&tp, GSM0808_IE_CHANNEL_NEEDED) == 1)
166 chan_needed = TLVP_VAL(&tp, GSM0808_IE_CHANNEL_NEEDED)[0] & 0x03;
167
168 if (TLVP_PRESENT(&tp, GSM0808_IE_EMLPP_PRIORITY)) {
169 LOGP(DMSC, LOGL_ERROR, "eMLPP is not handled\n");
170 }
171
Holger Hans Peter Freyther9c838ae2010-11-15 09:16:09 +0100172 subscr = subscr_get_or_create(net, mi_string);
173 if (!subscr) {
174 LOGP(DMSC, LOGL_ERROR, "Failed to allocate a subscriber for %s\n", mi_string);
175 return -1;
176 }
177
178 subscr->lac = lac;
179 subscr->tmsi = tmsi;
180
Harald Weltecccd3012011-07-11 18:18:35 +0200181 LOGP(DMSC, LOGL_INFO, "Paging request from MSC IMSI: '%s' TMSI: '0x%x/%u' LAC: 0x%x\n", mi_string, tmsi, tmsi, lac);
Holger Hans Peter Freyther9c838ae2010-11-15 09:16:09 +0100182 paging_request(net, subscr, chan_needed, NULL, NULL);
183 return 0;
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100184}
185
Holger Hans Peter Freytherf1f57a82010-11-10 09:34:47 +0100186/*
187 * GSM 08.08 ยง 3.1.9.1 and 3.2.1.21...
188 * release our gsm_subscriber_connection and send message
189 */
190static int bssmap_handle_clear_command(struct osmo_bsc_sccp_con *conn,
191 struct msgb *msg, unsigned int payload_length)
192{
193 struct msgb *resp;
194
195 /* TODO: handle the cause of this package */
196
197 if (conn->conn) {
Harald Weltecccd3012011-07-11 18:18:35 +0200198 LOGP(DMSC, LOGL_INFO, "Releasing all transactions on %p\n", conn);
Holger Hans Peter Freytherf1f57a82010-11-10 09:34:47 +0100199 gsm0808_clear(conn->conn);
200 subscr_con_free(conn->conn);
201 conn->conn = NULL;
202 }
203
204 /* send the clear complete message */
205 resp = gsm0808_create_clear_complete();
206 if (!resp) {
207 LOGP(DMSC, LOGL_ERROR, "Sending clear complete failed.\n");
208 return -1;
209 }
210
211 bsc_queue_for_msc(conn, resp);
212 return 0;
213}
214
Holger Hans Peter Freytherfae3c652010-11-10 09:44:34 +0100215/*
216 * GSM 08.08 ยง 3.4.7 cipher mode handling. We will have to pick
217 * the cipher to be used for this. In case we are already using
218 * a cipher we will have to send cipher mode reject to the MSC,
219 * otherwise we will have to pick something that we and the MS
220 * is supporting. Currently we are doing it in a rather static
221 * way by picking one ecnryption or no encrytpion.
222 */
223static int bssmap_handle_cipher_mode(struct osmo_bsc_sccp_con *conn,
224 struct msgb *msg, unsigned int payload_length)
225{
226 uint16_t len;
227 struct gsm_network *network = NULL;
228 const uint8_t *data;
229 struct tlv_parsed tp;
230 struct msgb *resp;
231 int reject_cause = -1;
232 int include_imeisv = 1;
233
234 if (!conn->conn) {
235 LOGP(DMSC, LOGL_ERROR, "No lchan/msc_data in cipher mode command.\n");
236 goto reject;
237 }
238
239 if (conn->ciphering_handled) {
240 LOGP(DMSC, LOGL_ERROR, "Already seen ciphering command. Protocol Error.\n");
241 goto reject;
242 }
243
244 conn->ciphering_handled = 1;
245
246 tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l4h + 1, payload_length - 1, 0, 0);
247 if (!TLVP_PRESENT(&tp, GSM0808_IE_ENCRYPTION_INFORMATION)) {
248 LOGP(DMSC, LOGL_ERROR, "IE Encryption Information missing.\n");
249 goto reject;
250 }
251
252 /*
253 * check if our global setting is allowed
254 * - Currently we check for A5/0 and A5/1
255 * - Copy the key if that is necessary
256 * - Otherwise reject
257 */
258 len = TLVP_LEN(&tp, GSM0808_IE_ENCRYPTION_INFORMATION);
259 if (len < 1) {
260 LOGP(DMSC, LOGL_ERROR, "IE Encryption Information is too short.\n");
261 goto reject;
262 }
263
264 network = conn->conn->bts->network;
265 data = TLVP_VAL(&tp, GSM0808_IE_ENCRYPTION_INFORMATION);
266
267 if (TLVP_PRESENT(&tp, GSM0808_IE_CIPHER_RESPONSE_MODE))
268 include_imeisv = TLVP_VAL(&tp, GSM0808_IE_CIPHER_RESPONSE_MODE)[0] & 0x1;
269
270 if (network->a5_encryption == 0 && (data[0] & 0x1) == 0x1) {
271 gsm0808_cipher_mode(conn->conn, 0, NULL, 0, include_imeisv);
272 } else if (network->a5_encryption != 0 && (data[0] & 0x2) == 0x2) {
273 gsm0808_cipher_mode(conn->conn, 1, &data[1], len - 1, include_imeisv);
274 } else {
275 LOGP(DMSC, LOGL_ERROR, "Can not select encryption...\n");
276 goto reject;
277 }
278
Harald Welte75413c42011-07-12 00:03:43 +0200279 return 0;
280
Holger Hans Peter Freytherfae3c652010-11-10 09:44:34 +0100281reject:
282 resp = gsm0808_create_cipher_reject(reject_cause);
283 if (!resp) {
284 LOGP(DMSC, LOGL_ERROR, "Sending the cipher reject failed.\n");
285 return -1;
286 }
287
288 bsc_queue_for_msc(conn, resp);
289 return -1;
290}
291
Holger Hans Peter Freyther50c579b2010-11-10 10:07:30 +0100292/*
293 * Handle the assignment request message.
294 *
295 * See ยง3.2.1.1 for the message type
296 */
297static int bssmap_handle_assignm_req(struct osmo_bsc_sccp_con *conn,
298 struct msgb *msg, unsigned int length)
299{
300 struct msgb *resp;
301 struct gsm_network *network;
302 struct tlv_parsed tp;
303 uint8_t *data;
304 uint16_t cic;
305 uint8_t timeslot;
306 uint8_t multiplex;
307 enum gsm48_chan_mode chan_mode = GSM48_CMODE_SIGN;
308 int i, supported, port, full_rate = -1;
309
310 if (!conn->conn) {
311 LOGP(DMSC, LOGL_ERROR, "No lchan/msc_data in cipher mode command.\n");
312 return -1;
313 }
314
315 network = conn->conn->bts->network;
316 tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l4h + 1, length - 1, 0, 0);
317
318 if (!TLVP_PRESENT(&tp, GSM0808_IE_CHANNEL_TYPE)) {
319 LOGP(DMSC, LOGL_ERROR, "Mandantory channel type not present.\n");
320 goto reject;
321 }
322
323 if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) {
324 LOGP(DMSC, LOGL_ERROR, "Identity code missing. Audio routing will not work.\n");
325 goto reject;
326 }
327
328 cic = ntohs(read_data16(TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)));
329 timeslot = cic & 0x1f;
330 multiplex = (cic & ~0x1f) >> 5;
331
332 /*
333 * Currently we only support a limited subset of all
334 * possible channel types. The limitation ends by not using
335 * multi-slot, limiting the channel coding, speech...
336 */
337 if (TLVP_LEN(&tp, GSM0808_IE_CHANNEL_TYPE) < 3) {
338 LOGP(DMSC, LOGL_ERROR, "ChannelType len !=3 not supported: %d\n",
339 TLVP_LEN(&tp, GSM0808_IE_CHANNEL_TYPE));
340 goto reject;
341 }
342
343 /*
344 * Try to figure out if we support the proposed speech codecs. For
345 * now we will always pick the full rate codecs.
346 */
347
348 data = (uint8_t *) TLVP_VAL(&tp, GSM0808_IE_CHANNEL_TYPE);
349 if ((data[0] & 0xf) != 0x1) {
350 LOGP(DMSC, LOGL_ERROR, "ChannelType != speech: %d\n", data[0]);
351 goto reject;
352 }
353
354 if (data[1] != GSM0808_SPEECH_FULL_PREF && data[1] != GSM0808_SPEECH_HALF_PREF) {
355 LOGP(DMSC, LOGL_ERROR, "ChannelType full not allowed: %d\n", data[1]);
356 goto reject;
357 }
358
359 /*
360 * go through the list of preferred codecs of our gsm network
361 * and try to find it among the permitted codecs. If we found
362 * it we will send chan_mode to the right mode and break the
363 * inner loop. The outer loop will exit due chan_mode having
364 * the correct value.
365 */
366 full_rate = 0;
367 for (supported = 0;
368 chan_mode == GSM48_CMODE_SIGN && supported < network->msc_data->audio_length;
369 ++supported) {
370
371 int perm_val = audio_support_to_gsm88(network->msc_data->audio_support[supported]);
372 for (i = 2; i < TLVP_LEN(&tp, GSM0808_IE_CHANNEL_TYPE); ++i) {
373 if ((data[i] & 0x7f) == perm_val) {
374 chan_mode = gsm88_to_chan_mode(perm_val);
375 full_rate = (data[i] & 0x4) == 0;
376 break;
377 } else if ((data[i] & 0x80) == 0x00) {
378 break;
379 }
380 }
381 }
382
383 if (chan_mode == GSM48_CMODE_SIGN) {
384 LOGP(DMSC, LOGL_ERROR, "No supported audio type found.\n");
385 goto reject;
386 }
387
388 /* map it to a MGCP Endpoint and a RTP port */
389 port = mgcp_timeslot_to_endpoint(multiplex, timeslot);
390 conn->rtp_port = rtp_calculate_port(port,
391 network->msc_data->rtp_base);
392
393 return gsm0808_assign_req(conn->conn, chan_mode, full_rate);
394
395reject:
396 resp = gsm0808_create_assignment_failure(GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, NULL);
397 if (!resp) {
398 LOGP(DMSC, LOGL_ERROR, "Channel allocation failure.\n");
399 return -1;
400 }
401
402 bsc_queue_for_msc(conn, resp);
403 return -1;
404}
405
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100406static int bssmap_rcvmsg_udt(struct gsm_network *net,
407 struct msgb *msg, unsigned int length)
408{
409 int ret = 0;
410
411 if (length < 1) {
412 LOGP(DMSC, LOGL_ERROR, "Not enough room: %d\n", length);
413 return -1;
414 }
415
Harald Weltecccd3012011-07-11 18:18:35 +0200416 LOGP(DMSC, LOGL_INFO, "Rx MSC UDT BSSMAP %s\n",
417 gsm0808_bssmap_name(msg->l4h[0]));
418
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100419 switch (msg->l4h[0]) {
420 case BSS_MAP_MSG_RESET_ACKNOWLEDGE:
421 ret = bssmap_handle_reset_ack(net, msg, length);
422 break;
423 case BSS_MAP_MSG_PAGING:
424 if (bsc_grace_allow_new_connection(net))
425 ret = bssmap_handle_paging(net, msg, length);
426 break;
427 }
428
429 return ret;
430}
431
432static int bssmap_rcvmsg_dt1(struct osmo_bsc_sccp_con *conn,
433 struct msgb *msg, unsigned int length)
434{
Holger Hans Peter Freytherf1f57a82010-11-10 09:34:47 +0100435 int ret = 0;
436
437 if (length < 1) {
438 LOGP(DMSC, LOGL_ERROR, "Not enough room: %d\n", length);
439 return -1;
440 }
441
Harald Weltecccd3012011-07-11 18:18:35 +0200442 LOGP(DMSC, LOGL_INFO, "Rx MSC DT1 BSSMAP %s\n",
443 gsm0808_bssmap_name(msg->l4h[0]));
444
Holger Hans Peter Freytherf1f57a82010-11-10 09:34:47 +0100445 switch (msg->l4h[0]) {
446 case BSS_MAP_MSG_CLEAR_CMD:
447 ret = bssmap_handle_clear_command(conn, msg, length);
448 break;
Holger Hans Peter Freytherfae3c652010-11-10 09:44:34 +0100449 case BSS_MAP_MSG_CIPHER_MODE_CMD:
450 ret = bssmap_handle_cipher_mode(conn, msg, length);
451 break;
Holger Hans Peter Freyther50c579b2010-11-10 10:07:30 +0100452 case BSS_MAP_MSG_ASSIGMENT_RQST:
453 ret = bssmap_handle_assignm_req(conn, msg, length);
454 break;
Holger Hans Peter Freytherf1f57a82010-11-10 09:34:47 +0100455 default:
Harald Welte9f32a8a2011-07-11 17:56:34 +0200456 LOGP(DMSC, LOGL_NOTICE, "Unimplemented msg type: %s\n",
457 gsm0808_bssmap_name(msg->l4h[0]));
Holger Hans Peter Freytherf1f57a82010-11-10 09:34:47 +0100458 break;
459 }
460
461 return ret;
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100462}
463
464static int dtap_rcvmsg(struct osmo_bsc_sccp_con *conn,
465 struct msgb *msg, unsigned int length)
466{
Holger Hans Peter Freytherdbc698a2010-11-10 10:17:05 +0100467 struct dtap_header *header;
468 struct msgb *gsm48;
469 uint8_t *data;
470
Harald Weltecccd3012011-07-11 18:18:35 +0200471 LOGP(DMSC, LOGL_DEBUG, "Rx MSC DTAP: %s\n",
472 osmo_hexdump(msg->l3h, length));
473
Holger Hans Peter Freytherdbc698a2010-11-10 10:17:05 +0100474 if (!conn->conn) {
475 LOGP(DMSC, LOGL_ERROR, "No subscriber connection available\n");
476 return -1;
477 }
478
479 header = (struct dtap_header *) msg->l3h;
480 if (sizeof(*header) >= length) {
Harald Weltecccd3012011-07-11 18:18:35 +0200481 LOGP(DMSC, LOGL_ERROR, "The DTAP header does not fit. Wanted: %lu got: %u\n", sizeof(*header), length);
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200482 LOGP(DMSC, LOGL_ERROR, "hex: %s\n", osmo_hexdump(msg->l3h, length));
Holger Hans Peter Freytherdbc698a2010-11-10 10:17:05 +0100483 return -1;
484 }
485
486 if (header->length > length - sizeof(*header)) {
487 LOGP(DMSC, LOGL_ERROR, "The DTAP l4 information does not fit: header: %u length: %u\n", header->length, length);
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200488 LOGP(DMSC, LOGL_ERROR, "hex: %s\n", osmo_hexdump(msg->l3h, length));
Holger Hans Peter Freytherdbc698a2010-11-10 10:17:05 +0100489 return -1;
490 }
491
Harald Weltecccd3012011-07-11 18:18:35 +0200492 LOGP(DMSC, LOGL_INFO, "Rx MSC DTAP, SAPI: %u CHAN: %u\n", header->link_id & 0x07, header->link_id & 0xC0);
Holger Hans Peter Freytherdbc698a2010-11-10 10:17:05 +0100493
494 /* forward the data */
495 gsm48 = gsm48_msgb_alloc();
496 if (!gsm48) {
497 LOGP(DMSC, LOGL_ERROR, "Allocation of the message failed.\n");
498 return -1;
499 }
500
501 gsm48->l3h = gsm48->data;
502 data = msgb_put(gsm48, length - sizeof(*header));
503 memcpy(data, msg->l3h + sizeof(*header), length - sizeof(*header));
504
505 /* pass it to the filter for extra actions */
506 bsc_scan_msc_msg(conn->conn, gsm48);
507 return gsm0808_submit_dtap(conn->conn, gsm48, header->link_id, 1);
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100508}
509
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +0100510int bsc_handle_udt(struct gsm_network *network,
511 struct bsc_msc_connection *conn,
512 struct msgb *msgb, unsigned int length)
513{
514 struct bssmap_header *bs;
515
Harald Weltecccd3012011-07-11 18:18:35 +0200516 LOGP(DMSC, LOGL_DEBUG, "Rx MSC UDT: %s\n",
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200517 osmo_hexdump(msgb->l3h, length));
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +0100518
519 if (length < sizeof(*bs)) {
520 LOGP(DMSC, LOGL_ERROR, "The header is too short.\n");
521 return -1;
522 }
523
524 bs = (struct bssmap_header *) msgb->l3h;
525 if (bs->length < length - sizeof(*bs))
526 return -1;
527
528 switch (bs->type) {
529 case BSSAP_MSG_BSS_MANAGEMENT:
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100530 msgb->l4h = &msgb->l3h[sizeof(*bs)];
531 bssmap_rcvmsg_udt(network, msgb, length - sizeof(*bs));
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +0100532 break;
533 default:
Harald Welte9f32a8a2011-07-11 17:56:34 +0200534 LOGP(DMSC, LOGL_NOTICE, "Unimplemented msg type: %s\n",
535 gsm0808_bssmap_name(bs->type));
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +0100536 }
537
538 return 0;
539}
540
541int bsc_handle_dt1(struct osmo_bsc_sccp_con *conn,
542 struct msgb *msg, unsigned int len)
543{
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100544 if (len < sizeof(struct bssmap_header)) {
545 LOGP(DMSC, LOGL_ERROR, "The header is too short.\n");
546 }
547
548 switch (msg->l3h[0]) {
549 case BSSAP_MSG_BSS_MANAGEMENT:
550 msg->l4h = &msg->l3h[sizeof(struct bssmap_header)];
551 bssmap_rcvmsg_dt1(conn, msg, len - sizeof(struct bssmap_header));
552 break;
553 case BSSAP_MSG_DTAP:
554 dtap_rcvmsg(conn, msg, len);
555 break;
556 default:
Harald Weltecccd3012011-07-11 18:18:35 +0200557 LOGP(DMSC, LOGL_NOTICE, "Unimplemented BSSAP msg type: %s\n",
558 gsm0808_bssap_name(msg->l3h[0]));
Holger Hans Peter Freyther890dfc52010-11-10 09:24:37 +0100559 }
560
Holger Hans Peter Freyther3485feb2010-11-09 23:28:33 +0100561 return -1;
562}