blob: ec4c39b7d4e86507fbc5437f911631f50505a0ec [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*
2 * (C) 2009,2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +02003 * (C) 2009,2010 by On-Waves
4 * All Rights Reserved
5 *
Harald Weltee08da972017-11-13 01:00:26 +09006 * SPDX-License-Identifier: GPL-2.0+
7 *
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +02008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 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 General Public License for more details.
17 *
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020018 */
19
Alexander Chemeris22630e62020-05-13 00:44:04 +030020#include <string.h>
21
Harald Welte95871da2017-05-15 12:11:36 +020022#include <osmocom/core/byteswap.h>
Philipp Maier2908dbf2020-06-05 14:16:11 +020023#include <osmocom/core/endian.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010024#include <osmocom/gsm/gsm0808.h>
Neels Hofmeyr5b214e22020-09-18 18:00:50 +020025#include <osmocom/gsm/gsm0808_lcs.h>
Philipp Maierfa896ab2017-03-27 16:55:32 +020026#include <osmocom/gsm/gsm0808_utils.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010027#include <osmocom/gsm/protocol/gsm_08_08.h>
28#include <osmocom/gsm/gsm48.h>
Neels Hofmeyr5b214e22020-09-18 18:00:50 +020029#include <osmocom/gsm/gad.h>
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020030
Harald Welte96e2a002017-06-12 21:44:18 +020031/*! \addtogroup gsm0808
32 * @{
Harald Welte37b61652017-10-16 18:46:03 +020033 * \file gsm0808.c
34 * Helper functions regarding the TS 08.08 / 48.008 A interface, primarily
35 * message generation/encoding.
Harald Welte96e2a002017-06-12 21:44:18 +020036 */
37
Alexander Chemeris22630e62020-05-13 00:44:04 +030038/*! Char buffer to return strings from functions */
39static __thread char str_buff[512];
40
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010041/*! Create "Complete L3 Info" for AoIP, legacy implementation.
42 * Instead use gsm0808_create_layer3_aoip2(), which is capable of three-digit MNC with leading zeros.
Harald Welte96e2a002017-06-12 21:44:18 +020043 * \param[in] msg_l3 msgb containing Layer 3 Message
44 * \param[in] nc Mobile Network Code
45 * \param[in] cc Mobile Country Code
46 * \param[in] lac Location Area Code
47 * \param[in] _ci Cell Identity
48 * \param[in] scl Speech Codec List
49 * \returns callee-allocated msgb with Complete L3 Info message */
Philipp Maierfa896ab2017-03-27 16:55:32 +020050struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc,
51 uint16_t cc, int lac, uint16_t _ci,
52 const struct gsm0808_speech_codec_list
53 *scl)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020054{
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010055 struct osmo_cell_global_id cgi = {
56 .lai = {
57 .plmn = {
58 .mcc = cc,
59 .mnc = nc,
60 },
61 .lac = lac,
62 },
63 .cell_identity = _ci,
64 };
65 return gsm0808_create_layer3_2(msg_l3, &cgi, scl);
66}
67
68/*! Create "Complete L3 Info" for AoIP.
69 * \param[in] msg_l3 msgb containing Layer 3 Message -- not modified by this call.
70 * \param[in] cell MCC, MNC, LAC, CI to identify the cell.
71 * \param[in] scl Speech Codec List, optional.
72 * \returns newly allocated msgb with Complete L3 Info message */
73struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell,
74 const struct gsm0808_speech_codec_list *scl)
75{
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020076 struct msgb* msg;
Harald Welte65c2d362012-01-21 14:26:01 +010077 struct {
78 uint8_t ident;
79 struct gsm48_loc_area_id lai;
80 uint16_t ci;
81 } __attribute__ ((packed)) lai_ci;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020082
83 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
84 "bssmap cmpl l3");
85 if (!msg)
86 return NULL;
87
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020088 /* create layer 3 header */
Harald Welte65c2d362012-01-21 14:26:01 +010089 msgb_v_put(msg, BSS_MAP_MSG_COMPLETE_LAYER_3);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020090
91 /* create the cell header */
Harald Welte65c2d362012-01-21 14:26:01 +010092 lai_ci.ident = CELL_IDENT_WHOLE_GLOBAL;
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010093 gsm48_generate_lai2(&lai_ci.lai, &cell->lai);
94 lai_ci.ci = osmo_htons(cell->cell_identity);
Harald Welte65c2d362012-01-21 14:26:01 +010095 msgb_tlv_put(msg, GSM0808_IE_CELL_IDENTIFIER, sizeof(lai_ci),
96 (uint8_t *) &lai_ci);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020097
98 /* copy the layer3 data */
Harald Welte65c2d362012-01-21 14:26:01 +010099 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION,
100 msgb_l3len(msg_l3), msg_l3->l3h);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200101
Philipp Maierfa896ab2017-03-27 16:55:32 +0200102 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700103 if (scl) {
104 if (gsm0808_enc_speech_codec_list2(msg, scl) < 0)
105 goto exit_free;
106 }
Philipp Maierfa896ab2017-03-27 16:55:32 +0200107
Harald Welte65c2d362012-01-21 14:26:01 +0100108 /* push the bssmap header */
109 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200110
111 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700112
113exit_free:
114 msgb_free(msg);
115 return NULL;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200116}
117
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100118/*! Create "Complete L3 Info" for A, legacy implementation.
119 * Instead use gsm0808_create_layer3_2() with the scl parameter passed as NULL,
120 * which is capable of three-digit MNC with leading zeros.
Harald Welte96e2a002017-06-12 21:44:18 +0200121 * \param[in] msg_l3 msgb containing Layer 3 Message
122 * \param[in] nc Mobile Network Code
123 * \param[in] cc Mobile Country Code
124 * \param[in] lac Location Area Code
125 * \param[in] _ci Cell Identity
126 * \returns callee-allocated msgb with Complete L3 Info message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200127struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc,
128 uint16_t cc, int lac, uint16_t _ci)
129{
Neels Hofmeyr4eeb8082018-03-23 01:47:14 +0100130 struct osmo_cell_global_id cgi = {
131 .lai = {
132 .plmn = {
133 .mcc = cc,
134 .mnc = nc,
135 },
136 .lac = lac,
137 },
138 .cell_identity = _ci,
139 };
140 return gsm0808_create_layer3_2(msg_l3, &cgi, NULL);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200141}
142
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200143/*! Create BSSMAP RESET message
Harald Welte96e2a002017-06-12 21:44:18 +0200144 * \returns callee-allocated msgb with BSSMAP Reset message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200145struct msgb *gsm0808_create_reset(void)
146{
Harald Welte65c2d362012-01-21 14:26:01 +0100147 uint8_t cause = GSM0808_CAUSE_EQUIPMENT_FAILURE;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200148 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
149 "bssmap: reset");
150 if (!msg)
151 return NULL;
152
Harald Welte65c2d362012-01-21 14:26:01 +0100153 msgb_v_put(msg, BSS_MAP_MSG_RESET);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100154 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100155 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
156
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200157 return msg;
158}
159
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200160/*! Create BSSMAP RESET ACK message
Harald Welte96e2a002017-06-12 21:44:18 +0200161 * \returns callee-allocated msgb with BSSMAP Reset ACK message */
Harald Weltea62fe312013-06-19 15:14:37 +0200162struct msgb *gsm0808_create_reset_ack(void)
163{
164 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
165 "bssmap: reset ack");
166 if (!msg)
167 return NULL;
168
169 msgb_v_put(msg, BSS_MAP_MSG_RESET_ACKNOWLEDGE);
170 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
171
172 return msg;
173}
174
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200175/*! Create BSSMAP Clear Complete message
Harald Welte96e2a002017-06-12 21:44:18 +0200176 * \returns callee-allocated msgb with BSSMAP Clear Complete message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200177struct msgb *gsm0808_create_clear_complete(void)
178{
179 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
180 "bssmap: clear complete");
Harald Welte65c2d362012-01-21 14:26:01 +0100181 uint8_t val = BSS_MAP_MSG_CLEAR_COMPLETE;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200182 if (!msg)
183 return NULL;
184
Harald Welte65c2d362012-01-21 14:26:01 +0100185 msg->l3h = msg->data;
186 msgb_tlv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 1, &val);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200187
188 return msg;
189}
190
Harald Welted1365e12019-02-18 13:44:30 +0100191/*! Create BSSMAP Clear Command message with BSSAP header *before* l3h and BSSMAP in l3h.
192 * This is quite different from most (all?) other gsm0808_create_* which have l3h
193 * point to the BSSAP header. However, we have to keep this for backwards compatibility.
194 * Use gsm0808_create_clear_command2() for a 'modern' implementation.
Philipp Maier1a146c82018-10-30 09:36:49 +0100195 * \param[in] cause TS 08.08 cause value
Harald Welte96e2a002017-06-12 21:44:18 +0200196 * \returns callee-allocated msgb with BSSMAP Clear Command message */
Philipp Maier1a146c82018-10-30 09:36:49 +0100197struct msgb *gsm0808_create_clear_command(uint8_t cause)
Holger Hans Peter Freythera3f05d82010-10-27 11:49:24 +0200198{
199 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
200 "bssmap: clear command");
201 if (!msg)
202 return NULL;
203
Holger Hans Peter Freytheraeebe392010-10-27 12:36:05 +0200204 msg->l3h = msgb_tv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 4);
205 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100206 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100207
Holger Hans Peter Freythera3f05d82010-10-27 11:49:24 +0200208 return msg;
209}
210
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100211/*! Create BSSMAP Clear Command message.
212 * \param[in] cause TS 08.08 cause value.
213 * \param[in] csfb_ind indicate that the call was established in an CSFB context.
214 * \returns callee-allocated msgb with BSSMAP Clear Command message. */
215struct msgb *gsm0808_create_clear_command2(uint8_t cause, bool csfb_ind)
216{
Harald Welte10ba47d2019-02-18 12:36:54 +0100217 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
218 "bssmap: clear command");
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100219 if (!msg)
220 return NULL;
221
Harald Welte10ba47d2019-02-18 12:36:54 +0100222 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD);
223 gsm0808_enc_cause(msg, cause);
224
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100225 if (csfb_ind)
226 msgb_v_put(msg, GSM0808_IE_CSFB_INDICATION);
227
Harald Welte10ba47d2019-02-18 12:36:54 +0100228 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
229
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100230 return msg;
231}
232
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200233/*! Superseded by gsm0808_create_cipher2() to include Kc128.
234 * Create BSSMAP Cipher Mode Command message (without Kc128).
Harald Welte96e2a002017-06-12 21:44:18 +0200235 * \param[in] ei Mandatory Encryption Information
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200236 * \param[in] kc128 optional kc128 key for A5/4
Harald Welte96e2a002017-06-12 21:44:18 +0200237 * \param[in] cipher_response_mode optional 1-byte Cipher Response Mode
238 * \returns callee-allocated msgb with BSSMAP Cipher Mode Command message */
Philipp Maierb478dd32017-03-29 15:50:05 +0200239struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
240 const uint8_t *cipher_response_mode)
241{
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200242 struct gsm0808_cipher_mode_command cmc = {
243 .ei = *ei,
244 .cipher_response_mode_present = (cipher_response_mode != NULL),
245 .cipher_response_mode = (cipher_response_mode ? *cipher_response_mode : 0),
246 };
247 return gsm0808_create_cipher2(&cmc);
248}
249
250/*! Create BSSMAP Cipher Mode Command message.
251 * \param[in] cmc Information to encode.
252 * \returns callee-allocated msgb with BSSMAP Cipher Mode Command message */
253struct msgb *gsm0808_create_cipher2(const struct gsm0808_cipher_mode_command *cmc)
254{
Philipp Maierb478dd32017-03-29 15:50:05 +0200255 /* See also: 3GPP TS 48.008 3.2.1.30 CIPHER MODE COMMAND */
256 struct msgb *msg;
257
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200258 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "cipher-mode-command");
Philipp Maierb478dd32017-03-29 15:50:05 +0200259 if (!msg)
260 return NULL;
261
262 /* Message Type 3.2.2.1 */
263 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_CMD);
264
265 /* Encryption Information 3.2.2.10 */
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200266 gsm0808_enc_encrypt_info(msg, &cmc->ei);
Philipp Maierb478dd32017-03-29 15:50:05 +0200267
268 /* Cipher Response Mode 3.2.2.34 */
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200269 if (cmc->cipher_response_mode_present)
Philipp Maierb478dd32017-03-29 15:50:05 +0200270 msgb_tv_put(msg, GSM0808_IE_CIPHER_RESPONSE_MODE,
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200271 cmc->cipher_response_mode);
272
273 /* Kc128 3.2.2.109 */
274 if (cmc->kc128_present)
275 gsm0808_enc_kc128(msg, cmc->kc128);
Philipp Maierb478dd32017-03-29 15:50:05 +0200276
277 /* pre-pend the header */
278 msg->l3h =
279 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
280
281 return msg;
282}
283
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200284/*! Create BSSMAP Cipher Mode Complete message
Harald Welte96e2a002017-06-12 21:44:18 +0200285 * \param[in] layer3 L3 Message to be included
286 * \param[in] alg_id Chosen Encrpytion Algorithm
287 * \returns callee-allocated msgb with BSSMAP Cipher Mode Complete message */
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200288struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id)
289{
290 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
291 "cipher-complete");
292 if (!msg)
293 return NULL;
294
295 /* send response with BSS override for A5/1... cheating */
Harald Welte65c2d362012-01-21 14:26:01 +0100296 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_COMPLETE);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200297
298 /* include layer3 in case we have at least two octets */
299 if (layer3 && msgb_l3len(layer3) > 2) {
Harald Welte65c2d362012-01-21 14:26:01 +0100300 msg->l4h = msgb_tlv_put(msg, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS,
301 msgb_l3len(layer3), layer3->l3h);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200302 }
303
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +0700304 /* Optional Chosen Encryption Algorithm IE */
305 if (alg_id > 0)
306 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, alg_id);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200307
Harald Welte65c2d362012-01-21 14:26:01 +0100308 /* pre-pend the header */
309 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
310
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200311 return msg;
312}
313
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200314/*! Create BSSMAP Cipher Mode Reject message
Maxaa934632018-11-07 13:16:54 +0100315 * \param[in] cause 3GPP TS 08.08 §3.2.2.5 cause value
Harald Welte96e2a002017-06-12 21:44:18 +0200316 * \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */
Maxaa934632018-11-07 13:16:54 +0100317struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200318{
319 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
Maxaa934632018-11-07 13:16:54 +0100320 "bssmap: cipher mode reject");
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200321 if (!msg)
322 return NULL;
323
Harald Welte62e40852017-12-17 20:50:34 +0100324 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT);
Maxaa934632018-11-07 13:16:54 +0100325
Philipp Maier4f4905f2018-11-30 13:36:12 +0100326 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100327
328 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200329
330 return msg;
331}
332
Maxed651d22018-11-07 15:25:05 +0100333/*! Create BSSMAP Cipher Mode Reject message
334 * \param[in] class 3GPP TS 08.08 §3.2.2.5 cause's class
335 * \param[in] ext 3GPP TS 08.08 §3.2.2.5 cause value (national application extension)
336 * \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */
337struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext)
338{
Philipp Maier4f4905f2018-11-30 13:36:12 +0100339 uint16_t cause;
Maxed651d22018-11-07 15:25:05 +0100340 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
341 "bssmap: cipher mode reject");
342 if (!msg)
343 return NULL;
344
Philipp Maier4f4905f2018-11-30 13:36:12 +0100345 /* Set cause code class in the upper byte */
346 cause = 0x80 | (class << 4);
347 cause = cause << 8;
348
349 /* Set cause code extension in the lower byte */
350 cause |= ext;
Maxed651d22018-11-07 15:25:05 +0100351
352 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT);
353
Philipp Maier4f4905f2018-11-30 13:36:12 +0100354 gsm0808_enc_cause(msg, cause);
Maxed651d22018-11-07 15:25:05 +0100355
356 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
357
358 return msg;
359}
360
Harald Welte64e807c2018-05-29 21:00:56 +0200361/*! Create BSSMAP LCLS CONNECT CONTROL message (TS 48.008 3.2.1.91).
362 * \param[in] config LCLS Configuration
363 * \param[in] control LCLS Connection Status Control
364 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
Max45f89c92018-12-19 19:35:26 +0100365struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config,
366 enum gsm0808_lcls_control control)
Harald Welte64e807c2018-05-29 21:00:56 +0200367{
Max45f89c92018-12-19 19:35:26 +0100368 struct msgb *msg;
369
370 /* According to NOTE 1 in §3.2.1.91 at least one of the parameters is required */
371 if (config == GSM0808_LCLS_CFG_NA && control == GSM0808_LCLS_CSC_NA)
372 return NULL;
373
374 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "bssmap: LCLS CONN CTRL");
Harald Welte64e807c2018-05-29 21:00:56 +0200375 if (!msg)
376 return NULL;
377
378 msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL);
Max45f89c92018-12-19 19:35:26 +0100379 if (config != GSM0808_LCLS_CFG_NA)
380 msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, config);
381 if (control != GSM0808_LCLS_CSC_NA)
Keith Whytee8525442022-10-06 01:01:47 +0100382 msgb_tv_put(msg, GSM0808_IE_LCLS_CONN_STATUS_CTRL, control);
Harald Welte64e807c2018-05-29 21:00:56 +0200383 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
384
385 return msg;
386}
387
388/*! Create BSSMAP LCLS CONNECT CONTROL ACK message (TS 48.008 3.2.1.92).
389 * \param[in] status LCLS BSS Status
390 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
391struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status)
392{
393 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
394 "bssmap: LCLS CONN CTRL ACK");
395 if (!msg)
396 return NULL;
397
398 msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK);
399 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status);
400 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
401
402 return msg;
403}
404
405/*! Create BSSMAP LCLS NOTIFICATION message (TS 48.008 3.2.1.93).
406 * \param[in] status LCLS BSS Status
407 * \param[in] break_req Include the LCLS BREAK REQ IE (true) or not (false)
408 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
409struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req)
410{
411 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
412 "bssmap: LCLS NOTIFICATION");
413 if (!msg)
414 return NULL;
415
416 msgb_v_put(msg, BSS_MAP_MSG_LCLS_NOTIFICATION);
417 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status);
418 if (break_req)
419 msgb_v_put(msg, GSM0808_IE_LCLS_BREAK_REQ);
420 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
421
422 return msg;
423}
424
Neels Hofmeyr2c79d552018-09-13 05:36:32 +0200425/*! Create BSSMAP Classmark Request message
426 * \returns callee-allocated msgb with BSSMAP Classmark Request message */
Harald Weltee61d4592022-11-03 11:05:58 +0100427struct msgb *gsm0808_create_classmark_request(void)
Neels Hofmeyr2c79d552018-09-13 05:36:32 +0200428{
429 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
430 "classmark-request");
431 if (!msg)
432 return NULL;
433
434 msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_RQST);
435 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
436 return msg;
437}
Harald Welte64e807c2018-05-29 21:00:56 +0200438
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200439/*! Create BSSMAP Classmark Update message
Harald Welte96e2a002017-06-12 21:44:18 +0200440 * \param[in] cm2 Classmark 2
441 * \param[in] cm2_len length (in octets) of \a cm2
442 * \param[in] cm3 Classmark 3
443 * \param[in] cm3_len length (in octets) of \a cm3
444 * \returns callee-allocated msgb with BSSMAP Classmark Update message */
Harald Welte07b625d2012-01-23 10:02:58 +0100445struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
446 const uint8_t *cm3, uint8_t cm3_len)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200447{
448 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
449 "classmark-update");
450 if (!msg)
451 return NULL;
452
Harald Welte65c2d362012-01-21 14:26:01 +0100453 msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_UPDATE);
Harald Welte07b625d2012-01-23 10:02:58 +0100454 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T2, cm2_len, cm2);
455 if (cm3)
456 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T3,
457 cm3_len, cm3);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200458
Harald Welte65c2d362012-01-21 14:26:01 +0100459 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
460
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200461 return msg;
462}
463
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200464/*! Create BSSMAP SAPI N Reject message
Harald Welte96e2a002017-06-12 21:44:18 +0200465 * \param[in] link_id Link Identifier
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700466 * \param[in] cause BSSAP Cause value (see 3GPP TS 48.008, section 3.2.2.5)
Harald Welte96e2a002017-06-12 21:44:18 +0200467 * \returns callee-allocated msgb with BSSMAP SAPI N Reject message */
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700468struct msgb *gsm0808_create_sapi_reject_cause(uint8_t link_id, uint16_t cause)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200469{
470 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
471 "bssmap: sapi 'n' reject");
472 if (!msg)
473 return NULL;
474
Harald Welte65c2d362012-01-21 14:26:01 +0100475 msgb_v_put(msg, BSS_MAP_MSG_SAPI_N_REJECT);
Alexander Chemerisa5b1b862020-05-12 01:03:08 +0300476 msgb_tv_put(msg, GSM0808_IE_DLCI, link_id);
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700477 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100478
479 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200480
481 return msg;
482}
483
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700484/*! Create BSSMAP SAPI N Reject message (with hard-coded cause "BSS not equipped").
485 * DEPRECATED: use gsm0808_create_sapi_reject_cause() instead.
486 * \param[in] link_id Link Identifier
487 * \param[in] cause BSSAP Cause value (see 3GPP TS 48.008, section 3.2.2.5)
488 * \returns callee-allocated msgb with BSSMAP SAPI N Reject message */
489struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
490{
491 return gsm0808_create_sapi_reject_cause(link_id, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
492}
493
Max52074322018-11-30 10:44:07 +0100494/*! Create BSSMAP Assignment Request message, 3GPP TS 48.008 §3.2.1.1.
495 * This is identical to gsm0808_create_ass(), but adds KC and LCLS IEs.
Harald Welte96e2a002017-06-12 21:44:18 +0200496 * \param[in] ct Channel Type
497 * \param[in] cic Circuit Identity Code (Classic A only)
498 * \param[in] ss Socket Address of MSC-side RTP socket (AoIP only)
499 * \param[in] scl Speech Codec List (AoIP only)
Max49c06682018-11-21 22:10:26 +0100500 * \param[in] ci Call Identifier (Optional), §3.2.2.105
Max52074322018-11-30 10:44:07 +0100501 * \param[in] kc Kc128 ciphering key (Optional, A5/4), §3.2.2.109
502 * \param[in] lcls Optional LCLS parameters
Harald Welte96e2a002017-06-12 21:44:18 +0200503 * \returns callee-allocated msgb with BSSMAP Assignment Request message */
Max52074322018-11-30 10:44:07 +0100504struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
505 const uint16_t *cic,
506 const struct sockaddr_storage *ss,
507 const struct gsm0808_speech_codec_list *scl,
508 const uint32_t *ci,
509 const uint8_t *kc, const struct osmo_lcls *lcls)
Philipp Maierc6144a22017-03-29 17:53:43 +0200510{
511 /* See also: 3GPP TS 48.008 3.2.1.1 ASSIGNMENT REQUEST */
512 struct msgb *msg;
Philipp Maierc6144a22017-03-29 17:53:43 +0200513
514 /* Mandatory emelent! */
515 OSMO_ASSERT(ct);
516
517 msg =
518 msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
519 "bssmap: ass req");
520 if (!msg)
521 return NULL;
522
523 /* Message Type 3.2.2.1 */
524 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_RQST);
525
526 /* Channel Type 3.2.2.11 */
527 gsm0808_enc_channel_type(msg, ct);
528
529 /* Circuit Identity Code 3.2.2.2 */
Vadim Yanitskiy1c4fc222021-02-05 03:58:24 +0100530 if (cic)
531 msgb_tv16_put(msg, GSM0808_IE_CIRCUIT_IDENTITY_CODE, *cic);
Philipp Maierc6144a22017-03-29 17:53:43 +0200532
533 /* AoIP: AoIP Transport Layer Address (MGW) 3.2.2.102 */
534 if (ss) {
535 gsm0808_enc_aoip_trasp_addr(msg, ss);
536 }
537
538 /* AoIP: Codec List (MSC Preferred) 3.2.2.103 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700539 if (scl) {
540 if (gsm0808_enc_speech_codec_list2(msg, scl) < 0)
541 goto exit_free;
542 }
Philipp Maierc6144a22017-03-29 17:53:43 +0200543
544 /* AoIP: Call Identifier 3.2.2.105 */
545 if (ci) {
Philipp Maier2908dbf2020-06-05 14:16:11 +0200546 /* NOTE: 3GPP TS 48.008, section 3.2.2.105 specifies that
Vadim Yanitskiy1c4fc222021-02-05 03:58:24 +0100547 * the least significant byte shall be transmitted first. */
548 msgb_v_put(msg, GSM0808_IE_CALL_ID);
549 osmo_store32le(*ci, msgb_put(msg, sizeof(*ci)));
Philipp Maierc6144a22017-03-29 17:53:43 +0200550 }
551
Max52074322018-11-30 10:44:07 +0100552 if (kc)
553 msgb_tv_fixed_put(msg, GSM0808_IE_KC_128, 16, kc);
554
Max47022152018-12-19 18:51:00 +0100555 if (lcls)
556 gsm0808_enc_lcls(msg, lcls);
Max52074322018-11-30 10:44:07 +0100557
Philipp Maierc6144a22017-03-29 17:53:43 +0200558 /* push the bssmap header */
559 msg->l3h =
560 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
561
562 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700563
564exit_free:
565 msgb_free(msg);
566 return NULL;
Philipp Maierc6144a22017-03-29 17:53:43 +0200567}
568
Max52074322018-11-30 10:44:07 +0100569/*! Create BSSMAP Assignment Request message, 3GPP TS 48.008 §3.2.1.1.
570 * \param[in] ct Channel Type
571 * \param[in] cic Circuit Identity Code (Classic A only)
572 * \param[in] ss Socket Address of MSC-side RTP socket (AoIP only)
573 * \param[in] scl Speech Codec List (AoIP only)
574 * \param[in] ci Call Identifier (Optional), §3.2.2.105
575 * \returns callee-allocated msgb with BSSMAP Assignment Request message */
576struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct,
577 const uint16_t *cic,
578 const struct sockaddr_storage *ss,
579 const struct gsm0808_speech_codec_list *scl,
580 const uint32_t *ci)
581{
582 return gsm0808_create_ass2(ct, cic, ss, scl, ci, NULL, NULL);
583}
584
Max414c8f52019-01-08 14:44:24 +0100585/*! Create BSSMAP Assignment Completed message as per 3GPP TS 48.008 §3.2.1.2
Harald Welte96e2a002017-06-12 21:44:18 +0200586 * \param[in] rr_cause GSM 04.08 RR Cause value
587 * \param[in] chosen_channel Chosen Channel
588 * \param[in] encr_alg_id Encryption Algorithm ID
589 * \param[in] speech_mode Speech Mode
590 * \param[in] ss Socket Address of BSS-side RTP socket
591 * \param[in] sc Speech Codec (current)
592 * \param[in] scl Speech Codec List (permitted)
Max414c8f52019-01-08 14:44:24 +0100593 * \param[in] lcls_bss_status §3.2.2.119 LCLS-BSS-Status, optional
Harald Welte96e2a002017-06-12 21:44:18 +0200594 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
Max414c8f52019-01-08 14:44:24 +0100595struct msgb *gsm0808_create_ass_compl2(uint8_t rr_cause, uint8_t chosen_channel,
Philipp Maierfa896ab2017-03-27 16:55:32 +0200596 uint8_t encr_alg_id, uint8_t speech_mode,
597 const struct sockaddr_storage *ss,
598 const struct gsm0808_speech_codec *sc,
Max414c8f52019-01-08 14:44:24 +0100599 const struct gsm0808_speech_codec_list *scl,
600 enum gsm0808_lcls_status lcls_bss_status)
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200601{
Harald Welte65c2d362012-01-21 14:26:01 +0100602 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
603 "bssmap: ass compl");
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200604 if (!msg)
605 return NULL;
606
Harald Welte65c2d362012-01-21 14:26:01 +0100607 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_COMPLETE);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200608
609 /* write 3.2.2.22 */
Harald Welte65c2d362012-01-21 14:26:01 +0100610 msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, rr_cause);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200611
612 /* write cirtcuit identity code 3.2.2.2 */
613 /* write cell identifier 3.2.2.17 */
614 /* write chosen channel 3.2.2.33 when BTS picked it */
Harald Welte65c2d362012-01-21 14:26:01 +0100615 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, chosen_channel);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200616
617 /* write chosen encryption algorithm 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +0700618 if (encr_alg_id > 0)
619 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, encr_alg_id);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200620
621 /* write circuit pool 3.2.2.45 */
622 /* write speech version chosen: 3.2.2.51 when BTS picked it */
Harald Welte65c2d362012-01-21 14:26:01 +0100623 if (speech_mode != 0)
624 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, speech_mode);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200625
Philipp Maierfa896ab2017-03-27 16:55:32 +0200626 /* AoIP: AoIP Transport Layer Address (BSS) 3.2.2.102 */
627 if (ss)
628 gsm0808_enc_aoip_trasp_addr(msg, ss);
629
630 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700631 if (sc) {
632 if (gsm0808_enc_speech_codec2(msg, sc) < 0)
633 goto exit_free;
634 }
Philipp Maierfa896ab2017-03-27 16:55:32 +0200635
636 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700637 if (scl) {
638 if (gsm0808_enc_speech_codec_list2(msg, scl) < 0)
639 goto exit_free;
640 }
Philipp Maierfa896ab2017-03-27 16:55:32 +0200641
Max414c8f52019-01-08 14:44:24 +0100642 /* FIXME: write LSA identifier 3.2.2.15 - see 3GPP TS 43.073 */
643
644 /* LCLS-BSS-Status 3.2.2.119 */
645 if (lcls_bss_status != GSM0808_LCLS_STS_NA)
646 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, lcls_bss_status);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200647
Harald Welte65c2d362012-01-21 14:26:01 +0100648 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200649
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200650 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700651
652exit_free:
653 msgb_free(msg);
654 return NULL;
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200655}
656
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200657/*! Create BSSMAP Assignment Completed message
Harald Welte96e2a002017-06-12 21:44:18 +0200658 * \param[in] rr_cause GSM 04.08 RR Cause value
659 * \param[in] chosen_channel Chosen Channel
660 * \param[in] encr_alg_id Encryption Algorithm ID
661 * \param[in] speech_mode Speech Mode
Max414c8f52019-01-08 14:44:24 +0100662 * \param[in] ss Socket Address of BSS-side RTP socket
663 * \param[in] sc Speech Codec (current)
664 * \param[in] scl Speech Codec List (permitted)
665 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
666struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel,
667 uint8_t encr_alg_id, uint8_t speech_mode,
668 const struct sockaddr_storage *ss,
669 const struct gsm0808_speech_codec *sc,
670 const struct gsm0808_speech_codec_list *scl)
671{
672 return gsm0808_create_ass_compl2(rr_cause, chosen_channel, encr_alg_id, speech_mode,
673 ss, sc, scl, GSM0808_LCLS_STS_NA);
674}
675
676/*! Create BSSMAP Assignment Completed message
677 * \param[in] rr_cause GSM 04.08 RR Cause value
678 * \param[in] chosen_channel Chosen Channel
679 * \param[in] encr_alg_id Encryption Algorithm ID
680 * \param[in] speech_mode Speech Mode
Harald Welte96e2a002017-06-12 21:44:18 +0200681 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200682struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
683 uint8_t chosen_channel,
684 uint8_t encr_alg_id,
685 uint8_t speech_mode)
686{
Max414c8f52019-01-08 14:44:24 +0100687 return gsm0808_create_ass_compl2(rr_cause, chosen_channel, encr_alg_id,
688 speech_mode, NULL, NULL, NULL, GSM0808_LCLS_STS_NA);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200689}
690
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200691/*! Create BSSMAP Assignment Failure message
Harald Welte96e2a002017-06-12 21:44:18 +0200692 * \param[in] cause BSSMAP Cause value
693 * \param[in] rr_cause GSM 04.08 RR Cause value
694 * \param[in] scl Optional Speech Cdec List (AoIP)
695 * \returns callee-allocated msgb with BSSMAP Assignment Failure message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200696struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause,
697 const struct gsm0808_speech_codec_list
698 *scl)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200699{
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200700 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
701 "bssmap: ass fail");
702 if (!msg)
703 return NULL;
704
Harald Welte65c2d362012-01-21 14:26:01 +0100705 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_FAILURE);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100706 gsm0808_enc_cause(msg, cause);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200707
708 /* RR cause 3.2.2.22 */
Harald Welte65c2d362012-01-21 14:26:01 +0100709 if (rr_cause)
710 msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, *rr_cause);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200711
712 /* Circuit pool 3.22.45 */
713 /* Circuit pool list 3.2.2.46 */
714
Philipp Maierfa896ab2017-03-27 16:55:32 +0200715 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700716 if (scl) {
717 if (gsm0808_enc_speech_codec_list2(msg, scl) < 0)
718 goto exit_free;
719 }
Philipp Maierfa896ab2017-03-27 16:55:32 +0200720
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200721 /* update the size */
Harald Welte65c2d362012-01-21 14:26:01 +0100722 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
723
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200724 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700725
726exit_free:
727 msgb_free(msg);
728 return NULL;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200729}
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +0200730
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200731/*! Create BSSMAP Assignment Failure message
Harald Welte96e2a002017-06-12 21:44:18 +0200732 * \param[in] cause BSSMAP Cause value
733 * \param[in] rr_cause GSM 04.08 RR Cause value
734 * \returns callee-allocated msgb with BSSMAP Assignment Failure message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200735struct msgb *gsm0808_create_assignment_failure(uint8_t cause,
736 uint8_t *rr_cause)
737{
738 return gsm0808_create_ass_fail(cause, rr_cause, NULL);
739}
740
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200741/*! Create BSSMAP Clear Request message
Harald Welte96e2a002017-06-12 21:44:18 +0200742 * \param[in] cause BSSMAP Cause value
743 * \returns callee-allocated msgb with BSSMAP Clear Request message */
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100744struct msgb *gsm0808_create_clear_rqst(uint8_t cause)
745{
746 struct msgb *msg;
747
748 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
749 "bssmap: clear rqst");
750 if (!msg)
751 return NULL;
752
Harald Welte65c2d362012-01-21 14:26:01 +0100753 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_RQST);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100754 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100755 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100756
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100757 return msg;
758}
759
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200760/*! Create BSSMAP PAGING message
Harald Welte96e2a002017-06-12 21:44:18 +0200761 * \param[in] imsi Mandatory paged IMSI in string representation
762 * \param[in] tmsi Optional paged TMSI
Stefan Sperling3953f412018-08-28 15:06:30 +0200763 * \param[in] cil Mandatory Cell Identity List (where to page)
Harald Welte96e2a002017-06-12 21:44:18 +0200764 * \param[in] chan_needed Channel Type needed
765 * \returns callee-allocated msgb with BSSMAP PAGING message */
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100766struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
767 const struct gsm0808_cell_id_list2 *cil,
768 const uint8_t *chan_needed)
Philipp Maier3d48ec02017-03-29 17:37:55 +0200769{
770 struct msgb *msg;
Harald Weltea13fb752020-06-16 08:44:42 +0200771 uint8_t mid_buf[GSM48_MI_SIZE + 2];
772 int mid_len;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200773 uint32_t tmsi_sw;
774
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100775 /* Mandatory elements! */
Philipp Maier3d48ec02017-03-29 17:37:55 +0200776 OSMO_ASSERT(imsi);
777 OSMO_ASSERT(cil);
778
779 /* Malformed IMSI */
780 OSMO_ASSERT(strlen(imsi) <= GSM48_MI_SIZE);
781
782 msg =
783 msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "paging");
784 if (!msg)
785 return NULL;
786
787 /* Message Type 3.2.2.1 */
788 msgb_v_put(msg, BSS_MAP_MSG_PAGING);
789
Stefan Sperling3953f412018-08-28 15:06:30 +0200790 /* mandatory IMSI 3.2.2.6 */
Harald Weltea13fb752020-06-16 08:44:42 +0200791 mid_len = gsm48_generate_mid_from_imsi(mid_buf, imsi);
792 msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200793
794 /* TMSI 3.2.2.7 */
795 if (tmsi) {
Harald Welte95871da2017-05-15 12:11:36 +0200796 tmsi_sw = osmo_htonl(*tmsi);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200797 msgb_tlv_put(msg, GSM0808_IE_TMSI, sizeof(*tmsi),
798 (uint8_t *) & tmsi_sw);
799 }
800
Stefan Sperling3953f412018-08-28 15:06:30 +0200801 /* mandatory Cell Identifier List 3.2.2.27 */
802 gsm0808_enc_cell_id_list2(msg, cil);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200803
804 /* Channel Needed 3.2.2.36 */
805 if (chan_needed) {
806 msgb_tv_put(msg, GSM0808_IE_CHANNEL_NEEDED,
807 (*chan_needed) & 0x03);
808 }
809
810 /* pre-pend the header */
811 msg->l3h =
812 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
813
814 return msg;
815}
816
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100817/*! DEPRECATED: Use gsm0808_create_paging2 instead.
818 * Create BSSMAP PAGING message.
819 * \param[in] imsi Mandatory paged IMSI in string representation
820 * \param[in] tmsi Optional paged TMSI
821 * \param[in] cil Cell Identity List (where to page)
822 * \param[in] chan_needed Channel Type needed
823 * \returns callee-allocated msgb with BSSMAP PAGING message */
824struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
825 const struct gsm0808_cell_id_list *cil,
826 const uint8_t *chan_needed)
827{
828 struct gsm0808_cell_id_list2 cil2 = {};
829
Pau Espin Pedrol49766ab2021-04-19 12:14:36 +0200830 /* Mandatory elements! */
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100831 OSMO_ASSERT(cil);
832
833 if (cil->id_list_len > GSM0808_CELL_ID_LIST2_MAXLEN)
834 return NULL;
835
836 cil2.id_discr = cil->id_discr;
837 memcpy(cil2.id_list, cil->id_list_lac, cil->id_list_len * sizeof(cil2.id_list[0].lac));
838 cil2.id_list_len = cil->id_list_len;
839
840 return gsm0808_create_paging2(imsi, tmsi, &cil2, chan_needed);
841}
842
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100843static uint8_t put_old_bss_to_new_bss_information(struct msgb *msg,
844 const struct gsm0808_old_bss_to_new_bss_info *i)
845{
846 uint8_t *old_tail;
847 uint8_t *tlv_len;
848
849 msgb_put_u8(msg, GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION);
850 tlv_len = msgb_put(msg, 1);
851 old_tail = msg->tail;
852
853 if (i->extra_information_present) {
854 uint8_t val = 0;
855 if (i->extra_information.prec)
856 val |= 1 << 0;
857 if (i->extra_information.lcs)
858 val |= 1 << 1;
859 if (i->extra_information.ue_prob)
860 val |= 1 << 2;
861 msgb_tlv_put(msg, GSM0808_FE_IE_EXTRA_INFORMATION, 1, &val);
862 }
863
864 if (i->current_channel_type_2_present) {
865 uint8_t val[2] = {
866 i->current_channel_type_2.mode,
867 i->current_channel_type_2.field,
868 };
869 msgb_tlv_put(msg, GSM0808_FE_IE_CURRENT_CHANNEL_TYPE_2, 2, val);
870 }
871
Pau Espin Pedrol1b625cb2021-04-14 21:27:31 +0200872 if (i->last_eutran_plmn_id_present) {
873 msgb_put_u8(msg, GSM0808_FE_IE_LAST_USED_EUTRAN_PLMN_ID);
874 osmo_plmn_to_bcd(msgb_put(msg, 3), &i->last_eutran_plmn_id);
875 }
876
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100877 *tlv_len = (uint8_t) (msg->tail - old_tail);
878 return *tlv_len + 2;
879}
880
881/*! Create BSSMAP HANDOVER REQUIRED message.
882 * \param[in] params All information to be encoded.
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200883 * \returns newly allocated msgb with BSSMAP HANDOVER REQUIRED message. */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100884struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params)
885{
886 struct msgb *msg;
887
888 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUIRED");
889 if (!msg)
890 return NULL;
891
892 /* Message Type, 3.2.2.1 */
893 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_REQUIRED);
894
895 /* Cause, 3.2.2.5 */
Philipp Maier4f4905f2018-11-30 13:36:12 +0100896 gsm0808_enc_cause(msg, params->cause);
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100897
898 /* Cell Identifier List, 3.2.2.27 */
899 gsm0808_enc_cell_id_list2(msg, &params->cil);
900
901 /* Current Channel Type 1, 3.2.2.49 */
902 if (params->current_channel_type_1_present)
903 msgb_tv_fixed_put(msg, GSM0808_IE_CURRENT_CHANNEL_TYPE_1, 1, &params->current_channel_type_1);
904
905 /* Speech Version (Used), 3.2.2.51 */
906 if (params->speech_version_used_present)
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200907 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_used);
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100908
909 if (params->old_bss_to_new_bss_info_present)
910 put_old_bss_to_new_bss_information(msg, &params->old_bss_to_new_bss_info);
911
912 /* pre-pend the header */
913 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
914
915 return msg;
916}
917
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100918/*! Create BSSMAP HANDOVER REQUIRED REJECT message.
919 * \returns newly allocated msgb with BSSMAP HANDOVER REQUIRED REJECT message. */
920struct msgb *gsm0808_create_handover_required_reject(const struct gsm0808_handover_required_reject *params)
921{
922 struct msgb *msg;
923
924 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUIRED-REJECT");
925 if (!msg)
926 return NULL;
927
928 /* Message Type, 3.2.2.1 */
929 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT);
930
931 /* Cause, 3.2.2.5 */
932 gsm0808_enc_cause(msg, params->cause);
933
934 /* prepend the header */
935 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
936
937 return msg;
938}
939
940/*! Create BSSMAP HANDOVER REQUEST message, 3GPP TS 48.008 3.2.1.8.
941 * Sent from the MSC to the potential new target cell during inter-BSC handover, or to the target MSC during inter-MSC
942 * handover.
943 */
944struct msgb *gsm0808_create_handover_request(const struct gsm0808_handover_request *params)
945{
946 struct msgb *msg;
947
948 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUEST");
949 if (!msg)
950 return NULL;
951
952 /* Message Type, 3.2.2.1 */
953 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_RQST);
954
955 /* Channel Type 3.2.2.11 */
956 gsm0808_enc_channel_type(msg, &params->channel_type);
957
958 /* Encryption Information 3.2.2.10 */
959 gsm0808_enc_encrypt_info(msg, &params->encryption_information);
960
961 /* Classmark Information 1 3.2.2.30 or Classmark Information 2 3.2.2.19 (Classmark 2 wins) */
962 if (params->classmark_information.classmark2_len) {
963 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T2,
964 params->classmark_information.classmark2_len,
965 (const uint8_t*)&params->classmark_information.classmark2);
966 } else if (params->classmark_information.classmark1_set) {
967 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1,
968 sizeof(params->classmark_information.classmark1),
969 (const uint8_t*)&params->classmark_information.classmark1);
970 }
971 /* (Classmark 3 possibly follows below) */
972
973 /* Cell Identifier (Serving) , 3.2.2.17 */
974 gsm0808_enc_cell_id(msg, &params->cell_identifier_serving);
975
976 /* Cell Identifier (Target) , 3.2.2.17 */
977 gsm0808_enc_cell_id(msg, &params->cell_identifier_target);
978
979 /* Cause, 3.2.2.5 */
980 gsm0808_enc_cause(msg, params->cause);
981
982 /* Classmark Information 3 3.2.2.20 */
983 if (params->classmark_information.classmark3_len) {
984 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T3,
985 params->classmark_information.classmark3_len,
986 (const uint8_t*)&params->classmark_information.classmark3);
987 }
988
989 /* Current Channel type 1 3.2.2.49 */
990 if (params->current_channel_type_1_present)
991 msgb_tv_fixed_put(msg, GSM0808_IE_CURRENT_CHANNEL_TYPE_1, 1, &params->current_channel_type_1);
992
993 /* Speech Version (Used), 3.2.2.51 */
994 if (params->speech_version_used) {
995 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_used);
996 }
997
998 /* Chosen Encryption Algorithm (Serving) 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +0700999 if (params->chosen_encryption_algorithm_serving > 0)
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001000 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encryption_algorithm_serving);
1001
1002 /* Old BSS to New BSS Information 3.2.2.58 */
1003 if (params->old_bss_to_new_bss_info_raw && params->old_bss_to_new_bss_info_raw_len) {
1004 msgb_tlv_put(msg, GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION,
1005 params->old_bss_to_new_bss_info_raw_len,
1006 params->old_bss_to_new_bss_info_raw);
1007 } else if (params->old_bss_to_new_bss_info_present) {
1008 put_old_bss_to_new_bss_information(msg, &params->old_bss_to_new_bss_info);
1009 }
1010
1011 /* IMSI 3.2.2.6 */
1012 if (params->imsi) {
Harald Weltea13fb752020-06-16 08:44:42 +02001013 uint8_t mid_buf[GSM48_MI_SIZE + 2];
1014 int mid_len = gsm48_generate_mid_from_imsi(mid_buf, params->imsi);
1015 msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2);
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001016 }
1017
1018 if (params->aoip_transport_layer)
1019 gsm0808_enc_aoip_trasp_addr(msg, params->aoip_transport_layer);
1020
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001021 if (params->codec_list_msc_preferred) {
1022 if (gsm0808_enc_speech_codec_list2(msg, params->codec_list_msc_preferred) < 0)
1023 goto exit_free;
1024 }
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001025
1026 if (params->call_id_present) {
1027 uint8_t val[4];
1028 osmo_store32le(params->call_id, val);
1029 msgb_tv_fixed_put(msg, GSM0808_IE_CALL_ID, 4, val);
1030 }
1031
Neels Hofmeyre4378b72021-06-10 00:54:35 +02001032 if (params->more_items && params->kc128_present)
1033 gsm0808_enc_kc128(msg, params->kc128);
1034
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001035 if (params->global_call_reference && params->global_call_reference_len) {
1036 msgb_tlv_put(msg, GSM0808_IE_GLOBAL_CALL_REF,
1037 params->global_call_reference_len, params->global_call_reference);
1038 }
1039
1040 /* prepend header with final length */
1041 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1042
1043 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001044
1045exit_free:
1046 msgb_free(msg);
1047 return NULL;
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001048}
1049
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001050/*! Create BSSMAP HANDOVER REQUEST ACKNOWLEDGE message, 3GPP TS 48.008 3.2.1.10.
1051 * Sent from the MT BSC back to the MSC when it has allocated an lchan to handover to.
1052 * l3_info is the RR Handover Command that the MO BSC sends to the MS to move over. */
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001053struct msgb *gsm0808_create_handover_request_ack2(const struct gsm0808_handover_request_ack *params)
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001054{
1055 struct msgb *msg;
1056
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001057 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUEST-ACK");
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001058 if (!msg)
1059 return NULL;
1060
1061 /* Message Type, 3.2.2.1 */
1062 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE);
1063
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001064 /* Layer 3 Information, 3.2.2.24 -- it is actually mandatory, but rather compose a nonstandard message than
1065 * segfault or return NULL without a log message. */
1066 if (params->l3_info && params->l3_info_len)
1067 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, params->l3_info_len, params->l3_info);
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001068
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001069 if (params->chosen_channel_present)
1070 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, params->chosen_channel);
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +07001071 if (params->chosen_encr_alg > 0)
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001072 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg);
1073
1074 if (params->chosen_speech_version != 0)
1075 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->chosen_speech_version);
1076
1077 if (params->aoip_transport_layer)
1078 gsm0808_enc_aoip_trasp_addr(msg, params->aoip_transport_layer);
1079
Neels Hofmeyra25a6dc2022-02-23 14:25:22 +01001080 /* AoIP: add Codec List (BSS Supported) 3.2.2.103.
1081 * (codec_list_bss_supported was added to struct gsm0808_handover_request_ack later than speech_codec_chosen
1082 * below, but it needs to come before it in the message coding). */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001083 if (params->more_items && params->codec_list_bss_supported.len) {
1084 if (gsm0808_enc_speech_codec_list2(msg, &params->codec_list_bss_supported) < 0)
1085 goto exit_free;
1086 }
Neels Hofmeyra25a6dc2022-02-23 14:25:22 +01001087
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001088 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001089 if (params->speech_codec_chosen_present) {
1090 if (gsm0808_enc_speech_codec2(msg, &params->speech_codec_chosen) < 0)
1091 goto exit_free;
1092 }
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001093
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001094 /* prepend header with final length */
1095 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1096
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001097 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001098
1099exit_free:
1100 msgb_free(msg);
1101 return NULL;
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001102}
1103
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001104/*! Same as gsm0808_create_handover_request_ack2() but with less parameters.
1105 * In particular, this lacks the AoIP Transport Layer address. */
1106struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len,
1107 uint8_t chosen_channel, uint8_t chosen_encr_alg,
1108 uint8_t chosen_speech_version)
1109{
1110 struct gsm0808_handover_request_ack params = {
1111 .l3_info = l3_info,
1112 .l3_info_len = l3_info_len,
1113 .chosen_channel = chosen_channel,
1114 .chosen_encr_alg = chosen_encr_alg,
1115 .chosen_speech_version = chosen_speech_version,
1116 };
1117
1118 return gsm0808_create_handover_request_ack2(&params);
1119}
1120
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001121/*! Create BSSMAP HANDOVER COMMAND message, 3GPP TS 48.008 3.2.1.11.
1122 * Sent from the MSC to the old BSS to transmit the RR Handover Command received from the new BSS. */
1123struct msgb *gsm0808_create_handover_command(const struct gsm0808_handover_command *params)
1124{
1125 struct msgb *msg;
1126
1127 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-COMMAND");
1128 if (!msg)
1129 return NULL;
1130
1131 /* Message Type, 3.2.2.1 */
1132 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_CMD);
1133
1134 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, params->l3_info_len, params->l3_info);
1135
1136 if (params->cell_identifier.id_discr != CELL_IDENT_NO_CELL)
1137 gsm0808_enc_cell_id(msg, &params->cell_identifier);
1138
1139 if (params->new_bss_to_old_bss_info_raw
1140 && params->new_bss_to_old_bss_info_raw_len)
1141 msgb_tlv_put(msg, GSM0808_IE_NEW_BSS_TO_OLD_BSS_INFO, params->new_bss_to_old_bss_info_raw_len,
1142 params->new_bss_to_old_bss_info_raw);
1143
1144 /* prepend header with final length */
1145 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1146
1147 return msg;
1148}
1149
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001150/*! Create BSSMAP HANDOVER DETECT message, 3GPP TS 48.008 3.2.1.40.
1151 * Sent from the MT BSC back to the MSC when the MS has sent a handover RACH request and the MT BSC has
1152 * received the Handover Detect message. */
Harald Weltee61d4592022-11-03 11:05:58 +01001153struct msgb *gsm0808_create_handover_detect(void)
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001154{
1155 struct msgb *msg;
1156
1157 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-DETECT");
1158 if (!msg)
1159 return NULL;
1160
1161 /* Message Type, 3.2.2.1 */
1162 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_DETECT);
1163
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001164 /* prepend header with final length */
1165 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1166
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001167 return msg;
1168}
1169
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001170/*! Create BSSMAP HANDOVER SUCCEEDED message, 3GPP TS 48.008 3.2.1.13.
1171 * Sent from the MSC back to the old BSS to notify that the MS has successfully accessed the new BSS. */
Harald Weltee61d4592022-11-03 11:05:58 +01001172struct msgb *gsm0808_create_handover_succeeded(void)
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001173{
1174 struct msgb *msg;
1175
1176 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-DETECT");
1177 if (!msg)
1178 return NULL;
1179
1180 /* Message Type, 3.2.2.1 */
1181 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_SUCCEEDED);
1182
1183 /* prepend header with final length */
1184 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1185
1186 return msg;
1187}
1188
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001189/*! Create BSSMAP HANDOVER COMPLETE message, 3GPP TS 48.008 3.2.1.12.
1190 * Sent from the MT BSC back to the MSC when the MS has fully settled into the new lchan. */
1191struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params)
1192{
1193 struct msgb *msg;
1194
1195 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-COMPLETE");
1196 if (!msg)
1197 return NULL;
1198
1199 /* Message Type, 3.2.2.1 */
1200 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_COMPLETE);
1201
1202 /* RR Cause, 3.2.2.22 */
1203 if (params->rr_cause_present)
1204 msgb_tlv_put(msg, GSM0808_IE_RR_CAUSE, 1, &params->rr_cause);
1205
1206 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001207 if (params->speech_codec_chosen_present) {
1208 if (gsm0808_enc_speech_codec2(msg, &params->speech_codec_chosen) < 0)
1209 goto exit_free;
1210 }
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001211
1212 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001213 if (params->codec_list_bss_supported.len) {
1214 if (gsm0808_enc_speech_codec_list2(msg, &params->codec_list_bss_supported) < 0)
1215 goto exit_free;
1216 }
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001217
1218 /* Chosen Encryption Algorithm 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +07001219 if (params->chosen_encr_alg_present && params->chosen_encr_alg > 0)
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001220 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg);
1221
1222 /* LCLS-BSS-Status 3.2.2.119 */
1223 if (params->lcls_bss_status_present)
1224 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, params->lcls_bss_status);
1225
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001226 /* prepend header with final length */
1227 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1228
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001229 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001230
1231exit_free:
1232 msgb_free(msg);
1233 return NULL;
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001234}
1235
1236/*! Create BSSMAP HANDOVER FAILURE message, 3GPP TS 48.008 3.2.1.16.
1237 * Sent from the MT BSC back to the MSC when the handover has failed. */
1238struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params)
1239{
1240 struct msgb *msg;
1241
1242 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-FAILURE");
1243 if (!msg)
1244 return NULL;
1245
1246 /* Message Type, 3.2.2.1 */
1247 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_FAILURE);
1248
1249 /* Cause, 3.2.2.5 */
Philipp Maier4f4905f2018-11-30 13:36:12 +01001250 gsm0808_enc_cause(msg, params->cause);
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001251
1252 /* RR Cause, 3.2.2.22 */
1253 if (params->rr_cause_present)
1254 msgb_tlv_put(msg, GSM0808_IE_RR_CAUSE, 1, &params->rr_cause);
1255
1256 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001257 if (params->codec_list_bss_supported.len) {
1258 if (gsm0808_enc_speech_codec_list2(msg, &params->codec_list_bss_supported) < 0)
1259 goto exit_free;
1260 }
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001261
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001262 /* prepend header with final length */
1263 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1264
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001265 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001266
1267exit_free:
1268 msgb_free(msg);
1269 return NULL;
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001270}
1271
Philipp Maier225bdf42018-10-30 14:56:59 +01001272/*! Create BSSMAP HANDOVER PERFORMED message, 3GPP TS 48.008 3.2.1.25.
1273 * \param[in] params All information to be encoded.
1274 * \returns callee-allocated msgb with BSSMAP HANDOVER PERFORMED message */
1275struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params)
1276{
1277 struct msgb *msg;
1278
1279 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-PERFORMED");
1280 if (!msg)
1281 return NULL;
1282
1283 /* Message Type, 3.2.2.1 */
1284 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_PERFORMED);
1285
1286 /* Cause, 3.2.2.5 */
Philipp Maier4f4905f2018-11-30 13:36:12 +01001287 gsm0808_enc_cause(msg, params->cause);
Philipp Maier225bdf42018-10-30 14:56:59 +01001288
1289 /* Cell Identifier, 3.2.2.17 */
1290 gsm0808_enc_cell_id(msg, &params->cell_id);
1291
1292 /* Chosen Channel 3.2.2.33 */
1293 if (params->chosen_channel_present)
1294 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, params->chosen_channel);
1295
1296 /* Chosen Encryption Algorithm 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +07001297 if (params->chosen_encr_alg_present && params->chosen_encr_alg > 0)
Philipp Maier225bdf42018-10-30 14:56:59 +01001298 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg);
1299
1300 /* Speech Version (chosen) 3.2.2.51 */
1301 if (params->speech_version_chosen_present)
1302 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_chosen);
1303
1304 /* AoIP: Speech Codec (chosen) 3.2.2.104 */
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001305 if (params->speech_codec_chosen_present) {
1306 if (gsm0808_enc_speech_codec2(msg, &params->speech_codec_chosen) < 0)
1307 goto exit_free;
1308 }
Philipp Maier225bdf42018-10-30 14:56:59 +01001309
1310 /* LCLS-BSS-Status 3.2.2.119 */
1311 if (params->lcls_bss_status_present)
1312 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, params->lcls_bss_status);
1313
1314 /* prepend header with final length */
1315 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1316
1317 return msg;
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001318
1319exit_free:
1320 msgb_free(msg);
1321 return NULL;
Philipp Maier225bdf42018-10-30 14:56:59 +01001322}
1323
Neels Hofmeyr9b35e562020-06-22 17:59:18 +02001324/*! Create BSSMAP COMMON ID message, 3GPP TS 48.008 3.2.1.68.
1325 * \param[in] imsi IMSI digits (decimal string).
1326 * \param[in] selected_plmn_id Selected PLMN ID to encode, or NULL to not encode this IE.
1327 * \param[in] last_used_eutran_plnm_id Last used E-UTRAN PLMN ID to encode, or NULL to not encode this IE.
1328 * \returns callee-allocated msgb with BSSMAP COMMON ID message, or NULL if encoding failed. */
Harald Welte1bd726a2020-06-21 22:04:52 +02001329struct msgb *gsm0808_create_common_id(const char *imsi,
1330 const struct osmo_plmn_id *selected_plmn_id,
1331 const struct osmo_plmn_id *last_used_eutran_plnm_id)
1332{
1333 struct msgb *msg;
Harald Welte1bd726a2020-06-21 22:04:52 +02001334 uint8_t *out;
Neels Hofmeyr9b35e562020-06-22 17:59:18 +02001335 struct osmo_mobile_identity mi;
1336 int rc;
Harald Welte1bd726a2020-06-21 22:04:52 +02001337
1338 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "COMMON-ID");
1339 if (!msg)
1340 return NULL;
1341
1342 /* Message Type, 3.2.2.1 */
1343 msgb_v_put(msg, BSS_MAP_MSG_COMMON_ID);
1344
1345 /* mandatory IMSI 3.2.2.6 */
Neels Hofmeyr9b35e562020-06-22 17:59:18 +02001346 mi = (struct osmo_mobile_identity){ .type = GSM_MI_TYPE_IMSI };
1347 OSMO_STRLCPY_ARRAY(mi.imsi, imsi);
1348 out = msgb_tl_put(msg, GSM0808_IE_IMSI);
1349 rc = osmo_mobile_identity_encode_msgb(msg, &mi, false);
1350 if (rc < 0) {
1351 msgb_free(msg);
1352 return NULL;
1353 }
1354 /* write the MI value length */
1355 *out = rc;
Harald Welte1bd726a2020-06-21 22:04:52 +02001356
1357 /* not implemented: SNA Access Information */
1358
1359 /* Selected PLMN ID */
1360 if (selected_plmn_id) {
1361 msgb_v_put(msg, GSM0808_IE_SELECTED_PLMN_ID);
1362 out = msgb_put(msg, 3);
1363 osmo_plmn_to_bcd(out, selected_plmn_id);
1364 }
1365
1366 /* Last used E-UTRAN PLMN ID */
1367 if (last_used_eutran_plnm_id) {
1368 msgb_v_put(msg, GSM0808_IE_LAST_USED_EUTRAN_PLMN_ID);
1369 out = msgb_put(msg, 3);
1370 osmo_plmn_to_bcd(out, last_used_eutran_plnm_id);
1371 }
1372
1373 /* prepend header with final length */
1374 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1375
1376 return msg;
1377}
1378
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001379/*! Prepend a DTAP header to given Message Buffer
Harald Welte96e2a002017-06-12 21:44:18 +02001380 * \param[in] msgb Message Buffer
1381 * \param[in] link_id Link Identifier */
Holger Hans Peter Freyther9a3dec02010-05-16 08:15:40 +08001382void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id)
1383{
1384 uint8_t *hh = msgb_push(msg, 3);
1385 hh[0] = BSSAP_MSG_DTAP;
1386 hh[1] = link_id;
1387 hh[2] = msg->len - 3;
1388}
1389
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001390/*! Create BSSMAP DTAP message
Harald Welte96e2a002017-06-12 21:44:18 +02001391 * \param[in] msg_l3 Messge Buffer containing Layer3 message
1392 * \param[in] link_id Link Identifier
1393 * \returns callee-allocated msgb with BSSMAP DTAP message */
Holger Hans Peter Freytherc25c6682010-11-04 12:26:06 +01001394struct msgb *gsm0808_create_dtap(struct msgb *msg_l3, uint8_t link_id)
1395{
1396 struct dtap_header *header;
1397 uint8_t *data;
1398 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
1399 "dtap");
1400 if (!msg)
1401 return NULL;
1402
1403 /* DTAP header */
1404 msg->l3h = msgb_put(msg, sizeof(*header));
1405 header = (struct dtap_header *) &msg->l3h[0];
1406 header->type = BSSAP_MSG_DTAP;
1407 header->link_id = link_id;
1408 header->length = msgb_l3len(msg_l3);
1409
1410 /* Payload */
1411 data = msgb_put(msg, header->length);
1412 memcpy(data, msg_l3->l3h, header->length);
1413
1414 return msg;
1415}
1416
Neels Hofmeyr5b214e22020-09-18 18:00:50 +02001417struct msgb *gsm0808_create_perform_location_request(const struct gsm0808_perform_location_request *params)
1418{
1419 struct msgb *msg;
1420 uint8_t *out;
1421 int rc;
1422
1423 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-REQUEST");
1424 if (!msg)
1425 return NULL;
1426
1427 /* Message Type, 3.2.2.1 */
1428 msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_RQST);
1429
1430 /* Location Type 3.2.2.63 */
1431 osmo_bssmap_le_ie_enc_location_type(msg, &params->location_type);
1432
1433 if (params->imsi.type == GSM_MI_TYPE_IMSI) {
1434 /* IMSI 3.2.2.6 */
1435 out = msgb_tl_put(msg, GSM0808_IE_IMSI);
1436 rc = osmo_mobile_identity_encode_msgb(msg, &params->imsi, false);
1437 if (rc < 0) {
1438 msgb_free(msg);
1439 return NULL;
1440 }
1441 /* write the MI value length */
1442 *out = rc;
1443 }
1444
1445 /* prepend header with final length */
1446 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1447
1448 return msg;
1449}
1450
1451struct msgb *gsm0808_create_perform_location_response(const struct gsm0808_perform_location_response *params)
1452{
1453 struct msgb *msg;
1454
1455 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-RESPONSE");
1456 if (!msg)
1457 return NULL;
1458
1459 /* Message Type, 3.2.2.1 */
1460 msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE);
1461
1462 if (params->location_estimate_present) {
1463 uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LOCATION_ESTIMATE);
1464 int rc = osmo_gad_raw_write(msg, &params->location_estimate);
1465 if (rc < 0) {
1466 msgb_free(msg);
1467 return NULL;
1468 }
1469 *l = rc;
1470 }
1471
1472 if (params->lcs_cause.present) {
1473 uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LCS_CAUSE);
1474 int rc = osmo_lcs_cause_enc(msg, &params->lcs_cause);
1475 if (rc < 0) {
1476 msgb_free(msg);
1477 return NULL;
1478 }
1479 *l = rc;
1480 }
1481
1482 /* prepend header with final length */
1483 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1484
1485 return msg;
1486}
1487
1488int gsm0808_enc_lcs_cause(struct msgb *msg, const struct lcs_cause_ie *lcs_cause)
1489{
1490 uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LCS_CAUSE);
1491 int rc = osmo_lcs_cause_enc(msg, lcs_cause);
1492 if (rc <= 0)
1493 return rc;
1494 *l = rc;
1495 return rc + 2;
1496}
1497
1498struct msgb *gsm0808_create_perform_location_abort(const struct lcs_cause_ie *lcs_cause)
1499{
1500 struct msgb *msg;
1501
1502 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-ABORT");
1503 if (!msg)
1504 return NULL;
1505
1506 /* Message Type, 3.2.2.1 */
1507 msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_ABORT);
1508
1509 gsm0808_enc_lcs_cause(msg, lcs_cause);
1510
1511 /* prepend header with final length */
1512 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1513
1514 return msg;
1515}
1516
Harald Welte92107df2014-06-21 23:16:20 +02001517/* As per 3GPP TS 48.008 version 11.7.0 Release 11 */
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001518static const struct tlv_definition bss_att_tlvdef = {
1519 .def = {
Harald Welte92107df2014-06-21 23:16:20 +02001520 [GSM0808_IE_CIRCUIT_IDENTITY_CODE] = { TLV_TYPE_FIXED, 2 },
1521 [GSM0808_IE_CONNECTION_RELEASE_RQSTED] = { TLV_TYPE_TV },
1522 [GSM0808_IE_RESOURCE_AVAILABLE] = { TLV_TYPE_FIXED, 21 },
1523 [GSM0808_IE_CAUSE] = { TLV_TYPE_TLV },
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001524 [GSM0808_IE_IMSI] = { TLV_TYPE_TLV },
1525 [GSM0808_IE_TMSI] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001526 [GSM0808_IE_NUMBER_OF_MSS] = { TLV_TYPE_TV },
Dmitri Soloviev29099422013-07-11 09:25:37 +02001527 [GSM0808_IE_LAYER_3_HEADER_INFORMATION] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001528 [GSM0808_IE_ENCRYPTION_INFORMATION] = { TLV_TYPE_TLV },
1529 [GSM0808_IE_CHANNEL_TYPE] = { TLV_TYPE_TLV },
1530 [GSM0808_IE_PERIODICITY] = { TLV_TYPE_TV },
1531 [GSM0808_IE_EXTENDED_RESOURCE_INDICATOR]= { TLV_TYPE_TV },
1532 [GSM0808_IE_TOTAL_RESOURCE_ACCESSIBLE] = { TLV_TYPE_FIXED, 4 },
1533 [GSM0808_IE_LSA_IDENTIFIER] = { TLV_TYPE_TLV },
1534 [GSM0808_IE_LSA_IDENTIFIER_LIST] = { TLV_TYPE_TLV },
Holger Hans Peter Freyther715e9452014-08-21 14:17:45 +02001535 [GSM0808_IE_LSA_INFORMATION] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001536 [GSM0808_IE_CELL_IDENTIFIER] = { TLV_TYPE_TLV },
1537 [GSM0808_IE_PRIORITY] = { TLV_TYPE_TLV },
1538 [GSM0808_IE_CLASSMARK_INFORMATION_T2] = { TLV_TYPE_TLV },
1539 [GSM0808_IE_CLASSMARK_INFORMATION_T3] = { TLV_TYPE_TLV },
1540 [GSM0808_IE_INTERFERENCE_BAND_TO_USE] = { TLV_TYPE_TV },
1541 [GSM0808_IE_RR_CAUSE] = { TLV_TYPE_TV },
Harald Welte92107df2014-06-21 23:16:20 +02001542 [GSM0808_IE_LAYER_3_INFORMATION] = { TLV_TYPE_TLV },
1543 [GSM0808_IE_DLCI] = { TLV_TYPE_TV },
1544 [GSM0808_IE_DOWNLINK_DTX_FLAG] = { TLV_TYPE_TV },
1545 [GSM0808_IE_CELL_IDENTIFIER_LIST] = { TLV_TYPE_TLV },
1546 [GSM0808_IE_CELL_ID_LIST_SEGMENT] = { TLV_TYPE_TLV },
1547 [GSM0808_IE_CELL_ID_LIST_SEG_EST_CELLS] = { TLV_TYPE_TLV },
1548 [GSM0808_IE_CELL_ID_LIST_SEG_CELLS_TBE] = { TLV_TYPE_TLV },
1549 [GSM0808_IE_CELL_ID_LIST_SEG_REL_CELLS] = { TLV_TYPE_TLV },
1550 [GSM0808_IE_CELL_ID_LIST_SEG_NE_CELLS] = { TLV_TYPE_TLV },
1551 [GSM0808_IE_RESPONSE_RQST] = { TLV_TYPE_T },
1552 [GSM0808_IE_RESOURCE_INDICATION_METHOD] = { TLV_TYPE_TV },
1553 [GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1] = { TLV_TYPE_TV },
1554 [GSM0808_IE_CIRCUIT_IDENTITY_CODE_LIST] = { TLV_TYPE_TLV },
1555 [GSM0808_IE_DIAGNOSTIC] = { TLV_TYPE_TLV },
1556 [GSM0808_IE_CHOSEN_CHANNEL] = { TLV_TYPE_TV },
1557 [GSM0808_IE_CIPHER_RESPONSE_MODE] = { TLV_TYPE_TV },
1558 [GSM0808_IE_LAYER_3_MESSAGE_CONTENTS] = { TLV_TYPE_TLV },
1559 [GSM0808_IE_CHANNEL_NEEDED] = { TLV_TYPE_TV },
1560 [GSM0808_IE_TRACE_TYPE] = { TLV_TYPE_TV },
1561 [GSM0808_IE_TRIGGERID] = { TLV_TYPE_TLV },
1562 [GSM0808_IE_TRACE_REFERENCE] = { TLV_TYPE_TV },
1563 [GSM0808_IE_TRANSACTIONID] = { TLV_TYPE_TLV },
1564 [GSM0808_IE_MOBILE_IDENTITY] = { TLV_TYPE_TLV },
1565 [GSM0808_IE_OMCID] = { TLV_TYPE_TLV },
1566 [GSM0808_IE_FORWARD_INDICATOR] = { TLV_TYPE_TV },
Holger Hans Peter Freytherc2b7f922010-08-04 18:50:43 +08001567 [GSM0808_IE_CHOSEN_ENCR_ALG] = { TLV_TYPE_TV },
Harald Welte92107df2014-06-21 23:16:20 +02001568 [GSM0808_IE_CIRCUIT_POOL] = { TLV_TYPE_TV },
1569 [GSM0808_IE_CIRCUIT_POOL_LIST] = { TLV_TYPE_TLV },
1570 [GSM0808_IE_TIME_INDICATION] = { TLV_TYPE_TV },
1571 [GSM0808_IE_RESOURCE_SITUATION] = { TLV_TYPE_TLV },
1572 [GSM0808_IE_CURRENT_CHANNEL_TYPE_1] = { TLV_TYPE_TV },
1573 [GSM0808_IE_QUEUEING_INDICATOR] = { TLV_TYPE_TV },
1574 [GSM0808_IE_SPEECH_VERSION] = { TLV_TYPE_TV },
1575 [GSM0808_IE_ASSIGNMENT_REQUIREMENT] = { TLV_TYPE_TV },
1576 [GSM0808_IE_TALKER_FLAG] = { TLV_TYPE_T },
1577 [GSM0808_IE_GROUP_CALL_REFERENCE] = { TLV_TYPE_TLV },
1578 [GSM0808_IE_EMLPP_PRIORITY] = { TLV_TYPE_TV },
1579 [GSM0808_IE_CONFIG_EVO_INDI] = { TLV_TYPE_TV },
1580 [GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION] = { TLV_TYPE_TLV },
1581 [GSM0808_IE_LCS_QOS] = { TLV_TYPE_TLV },
1582 [GSM0808_IE_LSA_ACCESS_CTRL_SUPPR] = { TLV_TYPE_TV },
1583 [GSM0808_IE_LCS_PRIORITY] = { TLV_TYPE_TLV },
1584 [GSM0808_IE_LOCATION_TYPE] = { TLV_TYPE_TLV },
1585 [GSM0808_IE_LOCATION_ESTIMATE] = { TLV_TYPE_TLV },
1586 [GSM0808_IE_POSITIONING_DATA] = { TLV_TYPE_TLV },
1587 [GSM0808_IE_LCS_CAUSE] = { TLV_TYPE_TLV },
Pau Espin Pedrolfffd7c32022-03-18 13:45:42 +01001588 [GSM0808_IE_LCS_CLIENT_TYPE] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001589 [GSM0808_IE_APDU] = { TLV_TYPE_TLV },
1590 [GSM0808_IE_NETWORK_ELEMENT_IDENTITY] = { TLV_TYPE_TLV },
1591 [GSM0808_IE_GPS_ASSISTANCE_DATA] = { TLV_TYPE_TLV },
1592 [GSM0808_IE_DECIPHERING_KEYS] = { TLV_TYPE_TLV },
1593 [GSM0808_IE_RETURN_ERROR_RQST] = { TLV_TYPE_TLV },
1594 [GSM0808_IE_RETURN_ERROR_CAUSE] = { TLV_TYPE_TLV },
1595 [GSM0808_IE_SEGMENTATION] = { TLV_TYPE_TLV },
1596 [GSM0808_IE_SERVICE_HANDOVER] = { TLV_TYPE_TLV },
1597 [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_UMTS] = { TLV_TYPE_TLV },
1598 [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_CDMA2000] = { TLV_TYPE_TLV },
1599 [GSM0808_IE_GERAN_CLASSMARK] = { TLV_TYPE_TLV },
1600 [GSM0808_IE_GERAN_BSC_CONTAINER] = { TLV_TYPE_TLV },
1601 [GSM0808_IE_NEW_BSS_TO_OLD_BSS_INFO] = { TLV_TYPE_TLV },
1602 [GSM0800_IE_INTER_SYSTEM_INFO] = { TLV_TYPE_TLV },
1603 [GSM0808_IE_SNA_ACCESS_INFO] = { TLV_TYPE_TLV },
1604 [GSM0808_IE_VSTK_RAND_INFO] = { TLV_TYPE_TLV },
Pau Espin Pedrol3cf47592022-03-18 14:13:01 +01001605 [GSM0808_IE_VSTK_INFO] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001606 [GSM0808_IE_PAGING_INFO] = { TLV_TYPE_TV },
1607 [GSM0808_IE_IMEI] = { TLV_TYPE_TLV },
1608 [GSM0808_IE_VELOCITY_ESTIMATE] = { TLV_TYPE_TLV },
1609 [GSM0808_IE_VGCS_FEATURE_FLAGS] = { TLV_TYPE_TLV },
1610 [GSM0808_IE_TALKER_PRIORITY] = { TLV_TYPE_TV },
1611 [GSM0808_IE_EMERGENCY_SET_INDICATION] = { TLV_TYPE_T },
1612 [GSM0808_IE_TALKER_IDENTITY] = { TLV_TYPE_TLV },
1613 [GSM0808_IE_SMS_TO_VGCS] = { TLV_TYPE_TLV },
1614 [GSM0808_IE_VGCS_TALKER_MODE] = { TLV_TYPE_TLV },
1615 [GSM0808_IE_VGCS_VBS_CELL_STATUS] = { TLV_TYPE_TLV },
1616 [GSM0808_IE_GANSS_ASSISTANCE_DATA] = { TLV_TYPE_TLV },
1617 [GSM0808_IE_GANSS_POSITIONING_DATA] = { TLV_TYPE_TLV },
1618 [GSM0808_IE_GANSS_LOCATION_TYPE] = { TLV_TYPE_TLV },
1619 [GSM0808_IE_APP_DATA] = { TLV_TYPE_TLV },
1620 [GSM0808_IE_DATA_IDENTITY] = { TLV_TYPE_TLV },
1621 [GSM0808_IE_APP_DATA_INFO] = { TLV_TYPE_TLV },
1622 [GSM0808_IE_MSISDN] = { TLV_TYPE_TLV },
1623 [GSM0808_IE_AOIP_TRASP_ADDR] = { TLV_TYPE_TLV },
1624 [GSM0808_IE_SPEECH_CODEC_LIST] = { TLV_TYPE_TLV },
1625 [GSM0808_IE_SPEECH_CODEC] = { TLV_TYPE_TLV },
1626 [GSM0808_IE_CALL_ID] = { TLV_TYPE_FIXED, 4 },
1627 [GSM0808_IE_CALL_ID_LIST] = { TLV_TYPE_TLV },
1628 [GSM0808_IE_A_IF_SEL_FOR_RESET] = { TLV_TYPE_TV },
1629 [GSM0808_IE_KC_128] = { TLV_TYPE_FIXED, 16 },
1630 [GSM0808_IE_CSG_IDENTIFIER] = { TLV_TYPE_TLV },
1631 [GSM0808_IE_REDIR_ATTEMPT_FLAG] = { TLV_TYPE_T },
1632 [GSM0808_IE_REROUTE_REJ_CAUSE] = { TLV_TYPE_TV },
1633 [GSM0808_IE_SEND_SEQ_NUM] = { TLV_TYPE_TV },
1634 [GSM0808_IE_REROUTE_COMPL_OUTCOME] = { TLV_TYPE_TV },
1635 [GSM0808_IE_GLOBAL_CALL_REF] = { TLV_TYPE_TLV },
1636 [GSM0808_IE_LCLS_CONFIG] = { TLV_TYPE_TV },
1637 [GSM0808_IE_LCLS_CONN_STATUS_CTRL] = { TLV_TYPE_TV },
1638 [GSM0808_IE_LCLS_CORR_NOT_NEEDED] = { TLV_TYPE_TV },
1639 [GSM0808_IE_LCLS_BSS_STATUS] = { TLV_TYPE_TV },
1640 [GSM0808_IE_LCLS_BREAK_REQ] = { TLV_TYPE_TV },
1641 [GSM0808_IE_CSFB_INDICATION] = { TLV_TYPE_T },
1642 [GSM0808_IE_CS_TO_PS_SRVCC] = { TLV_TYPE_T },
1643 [GSM0808_IE_SRC_ENB_TO_TGT_ENB_TRANSP] = { TLV_TYPE_TLV },
1644 [GSM0808_IE_CS_TO_PS_SRVCC_IND] = { TLV_TYPE_T },
1645 [GSM0808_IE_CN_TO_MS_TRANSP_INFO] = { TLV_TYPE_TLV },
1646 [GSM0808_IE_SELECTED_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
1647 [GSM0808_IE_LAST_USED_EUTRAN_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
Pau Espin Pedrol3cf47592022-03-18 14:13:01 +01001648 [GSM0808_IE_OLD_LAI] = { TLV_TYPE_FIXED, 5 },
1649 [GSM0808_IE_ATTACH_INDICATOR] = { TLV_TYPE_T },
1650 [GSM0808_IE_SELECTED_OPERATOR] = { TLV_TYPE_FIXED, 3 },
1651 [GSM0808_IE_PS_REGISTERED_OPERATOR] = { TLV_TYPE_FIXED, 3 },
1652 [GSM0808_IE_CS_REGISTERED_OPERATOR] = { TLV_TYPE_FIXED, 3 },
Pau Espin Pedrol18506c82019-04-16 15:47:59 +02001653
1654 /* Osmocom extensions */
1655 [GSM0808_IE_OSMO_OSMUX_SUPPORT] = { TLV_TYPE_T },
1656 [GSM0808_IE_OSMO_OSMUX_CID] = { TLV_TYPE_TV },
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001657 },
1658};
1659
Harald Weltef4d45ab2011-07-16 12:13:00 +02001660const struct tlv_definition *gsm0808_att_tlvdef(void)
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001661{
1662 return &bss_att_tlvdef;
1663}
Harald Welte9b837e62011-07-11 17:43:19 +02001664
Pau Espin Pedrolcde47792021-04-19 12:24:02 +02001665/* As per 3GPP TS 48.008 version 16.0.0 Release 16 § 3.2.2.58 Old BSS to New BSS Information */
1666const struct tlv_definition gsm0808_old_bss_to_new_bss_info_att_tlvdef = {
1667 .def = {
1668 [GSM0808_FE_IE_EXTRA_INFORMATION] = { TLV_TYPE_TLV },
1669 [GSM0808_FE_IE_CURRENT_CHANNEL_TYPE_2] = { TLV_TYPE_TLV },
1670 [GSM0808_FE_IE_TARGET_CELL_RADIO_INFORMATION] = { TLV_TYPE_TLV },
1671 [GSM0808_FE_IE_GPRS_SUSPEND_INFORMATION] = { TLV_TYPE_TLV },
1672 [GSM0808_FE_IE_MULTIRATE_CONFIGURATION_INFORMATION] = { TLV_TYPE_TLV },
1673 [GSM0808_FE_IE_DUAL_TRANSFER_MODE_INFORMATION] = { TLV_TYPE_TLV },
1674 [GSM0808_FE_IE_INTER_RAT_HANDOVER_INFO] = { TLV_TYPE_TLV },
1675 [GSM0808_FE_IE_CDMA2000_CAPABILITY_INFORMATION] = { TLV_TYPE_TLV },
1676 [GSM0808_FE_IE_DOWNLINK_CELL_LOAD_INFORMATION] = { TLV_TYPE_TLV },
1677 [GSM0808_FE_IE_UPLINK_CELL_LOAD_INFORMATION] = { TLV_TYPE_TLV },
1678 [GSM0808_FE_IE_CELL_LOAD_INFORMATION_GROUP] = { TLV_TYPE_TLV },
1679 [GSM0808_FE_IE_CELL_LOAD_INFORMATION] = { TLV_TYPE_TLV },
1680 [GSM0808_FE_IE_PS_INDICATION] = { TLV_TYPE_TLV },
1681 [GSM0808_FE_IE_DTM_HANDOVER_COMMAND_INDICATION] = { TLV_TYPE_TLV },
1682 [GSM0808_FE_IE_D_RNTI] = { TLV_TYPE_TLV },
1683 [GSM0808_FE_IE_IRAT_MEASUREMENT_CONFIGURATION] = { TLV_TYPE_TLV },
1684 [GSM0808_FE_IE_SOURCE_CELL_ID] = { TLV_TYPE_TLV },
1685 [GSM0808_FE_IE_IRAT_MEASUREMENT_CONFIGURATION_EXTENDED_E_ARFCNS] = { TLV_TYPE_TLV },
1686 [GSM0808_FE_IE_VGCS_TALKER_MODE] = { TLV_TYPE_TLV },
1687 [GSM0808_FE_IE_LAST_USED_EUTRAN_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
1688 },
1689};
1690
Pau Espin Pedrol392f6072019-11-27 12:07:04 +01001691const struct value_string gsm0406_dlci_sapi_names[] = {
1692 { DLCI_SAPI_RR_MM_CC, "RR/MM/CC" },
1693 { DLCI_SAPI_SMS, "SMS" },
1694 { 0, NULL }
1695};
1696
Harald Welte9b837e62011-07-11 17:43:19 +02001697static const struct value_string gsm0808_msgt_names[] = {
1698 { BSS_MAP_MSG_ASSIGMENT_RQST, "ASSIGNMENT REQ" },
1699 { BSS_MAP_MSG_ASSIGMENT_COMPLETE, "ASSIGNMENT COMPL" },
1700 { BSS_MAP_MSG_ASSIGMENT_FAILURE, "ASSIGNMENT FAIL" },
Harald Welte92107df2014-06-21 23:16:20 +02001701 { BSS_MAP_MSG_CHAN_MOD_RQST, "CHANNEL MODIFY REQUEST" },
Harald Welte9b837e62011-07-11 17:43:19 +02001702
1703 { BSS_MAP_MSG_HANDOVER_RQST, "HANDOVER REQ" },
1704 { BSS_MAP_MSG_HANDOVER_REQUIRED, "HANDOVER REQUIRED" },
1705 { BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE,"HANDOVER REQ ACK" },
1706 { BSS_MAP_MSG_HANDOVER_CMD, "HANDOVER CMD" },
1707 { BSS_MAP_MSG_HANDOVER_COMPLETE, "HANDOVER COMPLETE" },
1708 { BSS_MAP_MSG_HANDOVER_SUCCEEDED, "HANDOVER SUCCESS" },
1709 { BSS_MAP_MSG_HANDOVER_FAILURE, "HANDOVER FAILURE" },
1710 { BSS_MAP_MSG_HANDOVER_PERFORMED, "HANDOVER PERFORMED" },
1711 { BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE, "HANDOVER CAND ENQ" },
1712 { BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE, "HANDOVER CAND RESP" },
1713 { BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT, "HANDOVER REQ REJ" },
1714 { BSS_MAP_MSG_HANDOVER_DETECT, "HANDOVER DETECT" },
Harald Welte92107df2014-06-21 23:16:20 +02001715 { BSS_MAP_MSG_INT_HANDOVER_REQUIRED, "INT HANDOVER REQ" },
1716 { BSS_MAP_MSG_INT_HANDOVER_REQUIRED_REJ,"INT HANDOVER REQ REJ" },
1717 { BSS_MAP_MSG_INT_HANDOVER_CMD, "INT HANDOVER CMD" },
1718 { BSS_MAP_MSG_INT_HANDOVER_ENQUIRY, "INT HANDOVER ENQ" },
Harald Welte9b837e62011-07-11 17:43:19 +02001719
1720 { BSS_MAP_MSG_CLEAR_CMD, "CLEAR COMMAND" },
1721 { BSS_MAP_MSG_CLEAR_COMPLETE, "CLEAR COMPLETE" },
1722 { BSS_MAP_MSG_CLEAR_RQST, "CLEAR REQUEST" },
1723 { BSS_MAP_MSG_SAPI_N_REJECT, "SAPI N REJECT" },
1724 { BSS_MAP_MSG_CONFUSION, "CONFUSION" },
1725
1726 { BSS_MAP_MSG_SUSPEND, "SUSPEND" },
1727 { BSS_MAP_MSG_RESUME, "RESUME" },
1728 { BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION, "CONN ORIENT INFO" },
1729 { BSS_MAP_MSG_PERFORM_LOCATION_RQST, "PERFORM LOC REQ" },
1730 { BSS_MAP_MSG_LSA_INFORMATION, "LSA INFORMATION" },
1731 { BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE, "PERFORM LOC RESP" },
1732 { BSS_MAP_MSG_PERFORM_LOCATION_ABORT, "PERFORM LOC ABORT" },
1733 { BSS_MAP_MSG_COMMON_ID, "COMMON ID" },
Harald Welte92107df2014-06-21 23:16:20 +02001734 { BSS_MAP_MSG_REROUTE_CMD, "REROUTE COMMAND" },
1735 { BSS_MAP_MSG_REROUTE_COMPLETE, "REROUTE COMPLETE" },
Harald Welte9b837e62011-07-11 17:43:19 +02001736
1737 { BSS_MAP_MSG_RESET, "RESET" },
1738 { BSS_MAP_MSG_RESET_ACKNOWLEDGE, "RESET ACK" },
1739 { BSS_MAP_MSG_OVERLOAD, "OVERLOAD" },
1740 { BSS_MAP_MSG_RESET_CIRCUIT, "RESET CIRCUIT" },
1741 { BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE, "RESET CIRCUIT ACK" },
1742 { BSS_MAP_MSG_MSC_INVOKE_TRACE, "MSC INVOKE TRACE" },
1743 { BSS_MAP_MSG_BSS_INVOKE_TRACE, "BSS INVOKE TRACE" },
1744 { BSS_MAP_MSG_CONNECTIONLESS_INFORMATION, "CONNLESS INFO" },
Harald Welte92107df2014-06-21 23:16:20 +02001745 { BSS_MAP_MSG_RESET_IP_RSRC, "RESET IP RESOURCE" },
1746 { BSS_MAP_MSG_RESET_IP_RSRC_ACK, "RESET IP RESOURCE ACK" },
Harald Welte9b837e62011-07-11 17:43:19 +02001747
1748 { BSS_MAP_MSG_BLOCK, "BLOCK" },
1749 { BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE, "BLOCK ACK" },
1750 { BSS_MAP_MSG_UNBLOCK, "UNBLOCK" },
1751 { BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE, "UNBLOCK ACK" },
1752 { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK, "CIRC GROUP BLOCK" },
1753 { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE, "CIRC GORUP BLOCK ACK" },
1754 { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK, "CIRC GROUP UNBLOCK" },
1755 { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE, "CIRC GROUP UNBLOCK ACK" },
1756 { BSS_MAP_MSG_UNEQUIPPED_CIRCUIT, "UNEQUIPPED CIRCUIT" },
1757 { BSS_MAP_MSG_CHANGE_CIRCUIT, "CHANGE CIRCUIT" },
1758 { BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE, "CHANGE CIRCUIT ACK" },
1759
1760 { BSS_MAP_MSG_RESOURCE_RQST, "RESOURCE REQ" },
1761 { BSS_MAP_MSG_RESOURCE_INDICATION, "RESOURCE IND" },
1762 { BSS_MAP_MSG_PAGING, "PAGING" },
1763 { BSS_MAP_MSG_CIPHER_MODE_CMD, "CIPHER MODE CMD" },
1764 { BSS_MAP_MSG_CLASSMARK_UPDATE, "CLASSMARK UPDATE" },
1765 { BSS_MAP_MSG_CIPHER_MODE_COMPLETE, "CIPHER MODE COMPLETE" },
1766 { BSS_MAP_MSG_QUEUING_INDICATION, "QUEUING INDICATION" },
1767 { BSS_MAP_MSG_COMPLETE_LAYER_3, "COMPLETE LAYER 3" },
1768 { BSS_MAP_MSG_CLASSMARK_RQST, "CLASSMARK REQ" },
1769 { BSS_MAP_MSG_CIPHER_MODE_REJECT, "CIPHER MODE REJECT" },
1770 { BSS_MAP_MSG_LOAD_INDICATION, "LOAD IND" },
1771
Harald Welte92107df2014-06-21 23:16:20 +02001772 { BSS_MAP_MSG_VGCS_VBS_SETUP, "VGCS/VBS SETUP" },
1773 { BSS_MAP_MSG_VGCS_VBS_SETUP_ACK, "VGCS/VBS SETUP ACK" },
1774 { BSS_MAP_MSG_VGCS_VBS_SETUP_REFUSE, "VGCS/VBS SETUP REFUSE" },
1775 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RQST, "VGCS/VBS ASSIGN REQ" },
1776 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RESULT, "VGCS/VBS ASSIGN RES" },
1777 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_FAILURE, "VGCS/VBS ASSIGN FAIL" },
1778 { BSS_MAP_MSG_VGCS_VBS_QUEUING_INDICATION, "VGCS/VBS QUEUING IND" },
1779 { BSS_MAP_MSG_UPLINK_RQST, "UPLINK REQ" },
1780 { BSS_MAP_MSG_UPLINK_RQST_ACKNOWLEDGE, "UPLINK REQ ACK" },
1781 { BSS_MAP_MSG_UPLINK_RQST_CONFIRMATION, "UPLINK REQ CONF" },
1782 { BSS_MAP_MSG_UPLINK_RELEASE_INDICATION,"UPLINK REL IND" },
1783 { BSS_MAP_MSG_UPLINK_REJECT_CMD, "UPLINK REJ CMD" },
1784 { BSS_MAP_MSG_UPLINK_RELEASE_CMD, "UPLINK REL CMD" },
1785 { BSS_MAP_MSG_UPLINK_SEIZED_CMD, "UPLINK SEIZED CMD" },
1786 { BSS_MAP_MSG_VGCS_ADDL_INFO, "VGCS ADDL INFO" },
1787 { BSS_MAP_MSG_NOTIFICATION_DATA, "NOTIF DATA" },
1788 { BSS_MAP_MSG_UPLINK_APP_DATA, "UPLINK APP DATA" },
1789
1790 { BSS_MAP_MSG_LCLS_CONNECT_CTRL, "LCLS-CONNECT-CONTROL" },
Keith Whyte486d9842022-10-06 03:16:15 +01001791 { BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK, "LCLS-CONNECT-CONTROL-ACK" },
Harald Welte92107df2014-06-21 23:16:20 +02001792 { BSS_MAP_MSG_LCLS_NOTIFICATION, "LCLS-NOTIFICATION" },
Harald Welte9b837e62011-07-11 17:43:19 +02001793
1794 { 0, NULL }
1795};
1796
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001797/*! Return string name of BSSMAP Message Type */
Harald Welte9b837e62011-07-11 17:43:19 +02001798const char *gsm0808_bssmap_name(uint8_t msg_type)
1799{
1800 return get_value_string(gsm0808_msgt_names, msg_type);
1801}
1802
1803static const struct value_string gsm0808_bssap_names[] = {
1804 { BSSAP_MSG_BSS_MANAGEMENT, "MANAGEMENT" },
1805 { BSSAP_MSG_DTAP, "DTAP" },
Neels Hofmeyr90fdb082017-03-01 14:59:44 +01001806 { 0, NULL }
Harald Welte9b837e62011-07-11 17:43:19 +02001807};
1808
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001809/*! Return string name of BSSAP Message Type */
Harald Welte9b837e62011-07-11 17:43:19 +02001810const char *gsm0808_bssap_name(uint8_t msg_type)
1811{
1812 return get_value_string(gsm0808_bssap_names, msg_type);
1813}
Harald Welte96e2a002017-06-12 21:44:18 +02001814
Neels Hofmeyrffad5742018-01-12 05:34:03 +01001815const struct value_string gsm0808_speech_codec_type_names[] = {
1816 { GSM0808_SCT_FR1, "FR1" },
1817 { GSM0808_SCT_FR2, "FR2" },
1818 { GSM0808_SCT_FR3, "FR3" },
1819 { GSM0808_SCT_FR4, "FR4" },
1820 { GSM0808_SCT_FR5, "FR5" },
1821 { GSM0808_SCT_HR1, "HR1" },
1822 { GSM0808_SCT_HR3, "HR3" },
1823 { GSM0808_SCT_HR4, "HR4" },
1824 { GSM0808_SCT_HR6, "HR6" },
1825 { GSM0808_SCT_CSD, "CSD" },
1826 { 0, NULL }
1827};
1828
Philipp Maiercdd05812018-07-12 18:21:07 +02001829const struct value_string gsm0808_permitted_speech_names[] = {
1830 { GSM0808_PERM_FR1, "FR1" },
1831 { GSM0808_PERM_FR2, "FR2" },
1832 { GSM0808_PERM_FR3, "FR3" },
1833 { GSM0808_PERM_FR4, "FR4" },
1834 { GSM0808_PERM_FR5, "FR5" },
1835 { GSM0808_PERM_HR1, "HR1" },
1836 { GSM0808_PERM_HR2, "HR2" },
1837 { GSM0808_PERM_HR3, "HR3" },
1838 { GSM0808_PERM_HR4, "HR4" },
1839 { GSM0808_PERM_HR6, "HR6" },
1840 { 0, NULL }
1841};
1842
Pau Espin Pedrolf2cda622018-07-06 17:16:41 +02001843const struct value_string gsm0808_chosen_enc_alg_names[] = {
1844 { GSM0808_ALG_ID_A5_0, "A5/0" },
1845 { GSM0808_ALG_ID_A5_1, "A5/1" },
1846 { GSM0808_ALG_ID_A5_2, "A5/2" },
1847 { GSM0808_ALG_ID_A5_3, "A5/3" },
1848 { GSM0808_ALG_ID_A5_4, "A5/4" },
1849 { GSM0808_ALG_ID_A5_5, "A5/5" },
1850 { GSM0808_ALG_ID_A5_6, "A5/6" },
1851 { GSM0808_ALG_ID_A5_7, "A5/7" },
1852 { 0, NULL }
1853};
1854
Philipp Maierdbb76592018-03-29 12:55:26 +02001855static const struct value_string gsm0808_cause_names[] = {
1856 { GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, "RADIO INTERFACE MESSAGE FAILURE" },
1857 { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, "RADIO INTERFACE FAILURE" },
1858 { GSM0808_CAUSE_UPLINK_QUALITY, "UPLINK QUALITY" },
1859 { GSM0808_CAUSE_UPLINK_STRENGTH, "UPLINK STRENGTH" },
1860 { GSM0808_CAUSE_DOWNLINK_QUALITY, "DOWNLINK QUALITY" },
1861 { GSM0808_CAUSE_DOWNLINK_STRENGTH, "DOWNLINK STRENGTH" },
1862 { GSM0808_CAUSE_DISTANCE, "DISTANCE" },
1863 { GSM0808_CAUSE_O_AND_M_INTERVENTION, "O AND M INTERVENTION" },
1864 { GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION, "RESPONSE TO MSC INVOCATION" },
1865 { GSM0808_CAUSE_CALL_CONTROL, "CALL CONTROL" },
1866 { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION, "RADIO INTERFACE FAILURE REVERSION" },
1867 { GSM0808_CAUSE_HANDOVER_SUCCESSFUL, "HANDOVER SUCCESSFUL" },
1868 { GSM0808_CAUSE_BETTER_CELL, "BETTER CELL" },
1869 { GSM0808_CAUSE_DIRECTED_RETRY, "DIRECTED RETRY" },
1870 { GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL, "JOINED GROUP CALL CHANNEL" },
1871 { GSM0808_CAUSE_TRAFFIC, "TRAFFIC" },
1872 { GSM0808_CAUSE_REDUCE_LOAD_IN_SERVING_CELL, "REDUCE LOAD IN SERVING CELL" },
1873 { GSM0808_CAUSE_TRAFFIC_LOAD_IN_TGT_HIGHER_THAN_IN_SRC_CELL, "TRAFFIC LOAD IN TGT HIGHER THAN IN SRC CELL" },
1874 { GSM0808_CAUSE_RELOCATION_TRIGGERED, "RELOCATION TRIGGERED" },
Thorsten Alteholz0062a5f2018-05-15 15:28:55 +02001875 { GSM0808_CAUSE_REQUESTED_OPT_NOT_AUTHORISED, "REQUESTED OPT NOT AUTHORISED" },
Philipp Maierdbb76592018-03-29 12:55:26 +02001876 { GSM0808_CAUSE_ALT_CHAN_CONFIG_REQUESTED, "ALT CHAN CONFIG REQUESTED" },
1877 { GSM0808_CAUSE_RESP_TO_INT_HO_ENQ_MSG, "RESP TO INT HO ENQ MSG" },
1878 { GSM0808_CAUSE_INT_HO_ENQUIRY_REJECT, "INT HO ENQUIRY REJECT" },
1879 { GSM0808_CAUSE_REDUNDANCY_LEVEL_NOT_ADEQUATE, "REDUNDANCY LEVEL NOT ADEQUATE" },
1880 { GSM0808_CAUSE_EQUIPMENT_FAILURE, "EQUIPMENT FAILURE" },
1881 { GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, "NO RADIO RESOURCE AVAILABLE" },
1882 { GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE, "RQSTED TERRESTRIAL RESOURCE UNAVAILABLE" },
1883 { GSM0808_CAUSE_CCCH_OVERLOAD, "CCCH OVERLOAD" },
1884 { GSM0808_CAUSE_PROCESSOR_OVERLOAD, "PROCESSOR OVERLOAD" },
1885 { GSM0808_CAUSE_BSS_NOT_EQUIPPED, "BSS NOT EQUIPPED" },
1886 { GSM0808_CAUSE_MS_NOT_EQUIPPED, "MS NOT EQUIPPED" },
1887 { GSM0808_CAUSE_INVALID_CELL, "INVALID CELL" },
1888 { GSM0808_CAUSE_TRAFFIC_LOAD, "TRAFFIC LOAD" },
1889 { GSM0808_CAUSE_PREEMPTION, "PREEMPTION" },
1890 { GSM0808_CAUSE_DTM_HO_SGSN_FAILURE, "DTM HO SGSN FAILURE" },
1891 { GSM0808_CAUSE_DTM_HO_PS_ALLOC_FAILURE, "DTM HO PS ALLOC FAILURE" },
1892 { GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE, "RQSTED TRANSCODING RATE ADAPTION UNAVAILABLE" },
1893 { GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH, "CIRCUIT POOL MISMATCH" },
1894 { GSM0808_CAUSE_SWITCH_CIRCUIT_POOL, "SWITCH CIRCUIT POOL" },
1895 { GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE, "RQSTED SPEECH VERSION UNAVAILABLE" },
1896 { GSM0808_CAUSE_LSA_NOT_ALLOWED, "LSA NOT ALLOWED" },
1897 { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL, "REQ CODEC TYPE OR CONFIG UNAVAIL" },
1898 { GSM0808_CAUSE_REQ_A_IF_TYPE_UNAVAIL, "REQ A IF TYPE UNAVAIL" },
1899 { GSM0808_CAUSE_INVALID_CSG_CELL, "INVALID CSG CELL" },
1900 { GSM0808_CAUSE_REQ_REDUND_LEVEL_NOT_AVAIL, "REQ REDUND LEVEL NOT AVAIL" },
1901 { GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED, "CIPHERING ALGORITHM NOT SUPPORTED" },
1902 { GSM0808_CAUSE_GERAN_IU_MODE_FAILURE, "GERAN IU MODE FAILURE" },
1903 { GSM0808_CAUSE_INC_RELOC_NOT_SUPP_DT_PUESBINE_FEATURE, "INC RELOC NOT SUPP DT PUESBINE FEATURE" },
1904 { GSM0808_CAUSE_ACCESS_RESTRICTED_DUE_TO_SHARED_NETWORKS, "ACCESS RESTRICTED DUE TO SHARED NETWORKS" },
1905 { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_NOT_SUPP, "REQ CODEC TYPE OR CONFIG NOT SUPP" },
1906 { GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP, "REQ A IF TYPE NOT SUPP" },
1907 { GSM0808_CAUSE_REQ_REDUND_LVL_NOT_SUPP, "REQ REDUND LVL NOT SUPP" },
1908 { GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED, "TERRESTRIAL CIRCUIT ALREADY ALLOCATED" },
1909 { GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS, "INVALID MESSAGE CONTENTS" },
1910 { GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING, "INFORMATION ELEMENT OR FIELD MISSING" },
1911 { GSM0808_CAUSE_INCORRECT_VALUE, "INCORRECT VALUE" },
1912 { GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE, "UNKNOWN MESSAGE TYPE" },
1913 { GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT, "UNKNOWN INFORMATION ELEMENT" },
1914 { GSM0808_CAUSE_DTM_HO_INVALID_PS_IND, "DTM HO INVALID PS IND" },
1915 { GSM0808_CAUSE_CALL_ID_ALREADY_ALLOC, "CALL ID ALREADY ALLOC" },
1916 { GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC, "PROTOCOL ERROR BETWEEN BSS AND MSC" },
Thorsten Alteholz0062a5f2018-05-15 15:28:55 +02001917 { GSM0808_CAUSE_VGCS_VBS_CALL_NON_EXISTENT, "VGCS VBS CALL NON EXISTENT" },
Philipp Maierdbb76592018-03-29 12:55:26 +02001918 { GSM0808_CAUSE_DTM_HO_TIMER_EXPIRY, "DTM HO TIMER EXPIRY" },
1919 { 0, NULL }
1920};
1921
Maxaa934632018-11-07 13:16:54 +01001922static const struct value_string gsm0808_cause_class_names[] = {
1923 { GSM0808_CAUSE_CLASS_NORM0, "Normal event" },
1924 { GSM0808_CAUSE_CLASS_NORM1, "Normal event" },
1925 { GSM0808_CAUSE_CLASS_RES_UNAVAIL, "Resource unavailable" },
1926 { GSM0808_CAUSE_CLASS_SRV_OPT_NA, "Service or option not available" },
1927 { GSM0808_CAUSE_CLASS_SRV_OPT_NIMPL, "Service or option not implemented" },
1928 { GSM0808_CAUSE_CLASS_INVAL, "Invalid message" },
1929 { GSM0808_CAUSE_CLASS_PERR, "Protocol error" },
1930 { GSM0808_CAUSE_CLASS_INTW, "Interworking" },
1931 { 0, NULL }
1932};
1933
1934/*! Return string name of BSSMAP Cause Class name */
1935const char *gsm0808_cause_class_name(enum gsm0808_cause_class class)
1936{
1937 return get_value_string(gsm0808_cause_class_names, class);
1938}
1939
Philipp Maierdbb76592018-03-29 12:55:26 +02001940/*! Return string name of BSSMAP Cause name */
Maxaa934632018-11-07 13:16:54 +01001941const char *gsm0808_cause_name(enum gsm0808_cause cause)
Philipp Maierdbb76592018-03-29 12:55:26 +02001942{
1943 return get_value_string(gsm0808_cause_names, cause);
1944}
1945
Alexander Chemerisfdfe25b2020-05-12 23:21:56 +03001946enum gsm0808_cause gsm0808_get_cause(const struct tlv_parsed *tp)
1947{
1948 const uint8_t *buf = TLVP_VAL_MINLEN(tp, GSM0808_IE_CAUSE, 1);
1949
1950 if (!buf)
1951 return -EBADMSG;
1952
1953 if (TLVP_LEN(tp, GSM0808_IE_CAUSE) > 1) {
1954 if (!gsm0808_cause_ext(buf[0]))
1955 return -EINVAL;
1956 return buf[1];
1957 }
1958
1959 return buf[0];
1960}
1961
Alexander Chemeris22630e62020-05-13 00:44:04 +03001962const char *gsm0808_diagnostics_octet_location_str(uint8_t pointer)
1963{
1964 switch (pointer) {
1965 case 0:
1966 return "Error location not determined";
1967 case 1:
1968 return "The first octet of the message received (i.e. the message type) was found erroneous (unknown)";
1969 case 0xfd:
1970 return "The first octet of the BSSAP header (Discrimination) was found erroneous";
1971 case 0xfe:
1972 return "(DTAP only) The DLCI (second) octet of the BSSAP header was found erroneous";
1973 case 0xff:
1974 return "The last octet of the BSSAP header (length indicator) was found erroneous";
1975 default:
1976 snprintf(str_buff, sizeof(str_buff), "The %d octet of the message received was found erroneous", pointer);
1977 return str_buff;
1978 }
1979}
1980
1981const char *gsm0808_diagnostics_bit_location_str(uint8_t bit_pointer)
1982{
1983 if (bit_pointer == 0) {
1984 return "No particular part of the octet is indicated";
1985 } else if (bit_pointer > 8) {
1986 return "Reserved value";
1987 }
1988
1989 snprintf(str_buff, sizeof(str_buff),
1990 "An error was provoked by the field whose most significant bit is in bit position %d",
1991 bit_pointer);
1992 return str_buff;
1993}
1994
Harald Welteebd362d2018-06-02 14:11:19 +02001995const struct value_string gsm0808_lcls_config_names[] = {
1996 { GSM0808_LCLS_CFG_BOTH_WAY, "Connect both-way" },
1997 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL,
1998 "Connect both-way, bi-cast UL to CN" },
1999 { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL,
2000 "Connect both-way, send access DL from CN" },
2001 { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL_BLOCK_LOCAL_DL,
2002 "Connect both-way, send access DL from CN, block local DL" },
2003 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL,
2004 "Connect both-way, bi-cast UL to CN, send access DL from CN" },
2005 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL_BLOCK_LOCAL_DL,
2006 "Connect both-way, bi-cast UL to CN, send access DL from CN, block local DL" },
Max961db7c2018-11-08 11:40:23 +01002007 { GSM0808_LCLS_CFG_NA, "Not available" },
Harald Welteebd362d2018-06-02 14:11:19 +02002008 { 0, NULL }
2009};
2010
2011const struct value_string gsm0808_lcls_control_names[] = {
2012 { GSM0808_LCLS_CSC_CONNECT, "Connect" },
2013 { GSM0808_LCLS_CSC_DO_NOT_CONNECT, "Do not connect" },
2014 { GSM0808_LCLS_CSC_RELEASE_LCLS, "Release LCLS" },
2015 { GSM0808_LCLS_CSC_BICAST_UL_AT_HANDOVER, "Bi-cast UL at Handover" },
2016 { GSM0808_LCLS_CSC_BICAST_UL_AND_RECV_DL_AT_HANDOVER, "Bi-cast UL and receive DL at Handover" },
Max961db7c2018-11-08 11:40:23 +01002017 { GSM0808_LCLS_CSC_NA, "Not available" },
Harald Welteebd362d2018-06-02 14:11:19 +02002018 { 0, NULL }
2019};
2020
2021const struct value_string gsm0808_lcls_status_names[] = {
2022 { GSM0808_LCLS_STS_NOT_YET_LS, "Call not yet locally switched" },
2023 { GSM0808_LCLS_STS_NOT_POSSIBLE_LS, "Call not possible to be locally switched" },
2024 { GSM0808_LCLS_STS_NO_LONGER_LS, "Call is no longer locally switched" },
2025 { GSM0808_LCLS_STS_REQ_LCLS_NOT_SUPP, "Requested LCLS configuration is not supported" },
2026 { GSM0808_LCLS_STS_LOCALLY_SWITCHED, "Call is locally switched with requested LCLS config" },
Max961db7c2018-11-08 11:40:23 +01002027 { GSM0808_LCLS_STS_NA, "Not available" },
Harald Welteebd362d2018-06-02 14:11:19 +02002028 { 0, NULL }
2029};
2030
Harald Welte96e2a002017-06-12 21:44:18 +02002031/*! @} */