blob: 158c49038088b718bd74d19bf8c07943724e24f2 [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 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
Alexander Chemeris22630e62020-05-13 00:44:04 +030024#include <string.h>
25
Harald Welte95871da2017-05-15 12:11:36 +020026#include <osmocom/core/byteswap.h>
Philipp Maier2908dbf2020-06-05 14:16:11 +020027#include <osmocom/core/endian.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010028#include <osmocom/gsm/gsm0808.h>
Neels Hofmeyr5b214e22020-09-18 18:00:50 +020029#include <osmocom/gsm/gsm0808_lcs.h>
Philipp Maierfa896ab2017-03-27 16:55:32 +020030#include <osmocom/gsm/gsm0808_utils.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010031#include <osmocom/gsm/protocol/gsm_08_08.h>
32#include <osmocom/gsm/gsm48.h>
Neels Hofmeyr5b214e22020-09-18 18:00:50 +020033#include <osmocom/gsm/gad.h>
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020034
Harald Welte96e2a002017-06-12 21:44:18 +020035/*! \addtogroup gsm0808
36 * @{
Harald Welte37b61652017-10-16 18:46:03 +020037 * \file gsm0808.c
38 * Helper functions regarding the TS 08.08 / 48.008 A interface, primarily
39 * message generation/encoding.
Harald Welte96e2a002017-06-12 21:44:18 +020040 */
41
Alexander Chemeris22630e62020-05-13 00:44:04 +030042/*! Char buffer to return strings from functions */
43static __thread char str_buff[512];
44
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010045/*! Create "Complete L3 Info" for AoIP, legacy implementation.
46 * Instead use gsm0808_create_layer3_aoip2(), which is capable of three-digit MNC with leading zeros.
Harald Welte96e2a002017-06-12 21:44:18 +020047 * \param[in] msg_l3 msgb containing Layer 3 Message
48 * \param[in] nc Mobile Network Code
49 * \param[in] cc Mobile Country Code
50 * \param[in] lac Location Area Code
51 * \param[in] _ci Cell Identity
52 * \param[in] scl Speech Codec List
53 * \returns callee-allocated msgb with Complete L3 Info message */
Philipp Maierfa896ab2017-03-27 16:55:32 +020054struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc,
55 uint16_t cc, int lac, uint16_t _ci,
56 const struct gsm0808_speech_codec_list
57 *scl)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020058{
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010059 struct osmo_cell_global_id cgi = {
60 .lai = {
61 .plmn = {
62 .mcc = cc,
63 .mnc = nc,
64 },
65 .lac = lac,
66 },
67 .cell_identity = _ci,
68 };
69 return gsm0808_create_layer3_2(msg_l3, &cgi, scl);
70}
71
72/*! Create "Complete L3 Info" for AoIP.
73 * \param[in] msg_l3 msgb containing Layer 3 Message -- not modified by this call.
74 * \param[in] cell MCC, MNC, LAC, CI to identify the cell.
75 * \param[in] scl Speech Codec List, optional.
76 * \returns newly allocated msgb with Complete L3 Info message */
77struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell,
78 const struct gsm0808_speech_codec_list *scl)
79{
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020080 struct msgb* msg;
Harald Welte65c2d362012-01-21 14:26:01 +010081 struct {
82 uint8_t ident;
83 struct gsm48_loc_area_id lai;
84 uint16_t ci;
85 } __attribute__ ((packed)) lai_ci;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020086
87 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
88 "bssmap cmpl l3");
89 if (!msg)
90 return NULL;
91
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020092 /* create layer 3 header */
Harald Welte65c2d362012-01-21 14:26:01 +010093 msgb_v_put(msg, BSS_MAP_MSG_COMPLETE_LAYER_3);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020094
95 /* create the cell header */
Harald Welte65c2d362012-01-21 14:26:01 +010096 lai_ci.ident = CELL_IDENT_WHOLE_GLOBAL;
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010097 gsm48_generate_lai2(&lai_ci.lai, &cell->lai);
98 lai_ci.ci = osmo_htons(cell->cell_identity);
Harald Welte65c2d362012-01-21 14:26:01 +010099 msgb_tlv_put(msg, GSM0808_IE_CELL_IDENTIFIER, sizeof(lai_ci),
100 (uint8_t *) &lai_ci);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200101
102 /* copy the layer3 data */
Harald Welte65c2d362012-01-21 14:26:01 +0100103 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION,
104 msgb_l3len(msg_l3), msg_l3->l3h);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200105
Philipp Maierfa896ab2017-03-27 16:55:32 +0200106 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
107 if (scl)
108 gsm0808_enc_speech_codec_list(msg, scl);
109
Harald Welte65c2d362012-01-21 14:26:01 +0100110 /* push the bssmap header */
111 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200112
113 return msg;
114}
115
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100116/*! Create "Complete L3 Info" for A, legacy implementation.
117 * Instead use gsm0808_create_layer3_2() with the scl parameter passed as NULL,
118 * which is capable of three-digit MNC with leading zeros.
Harald Welte96e2a002017-06-12 21:44:18 +0200119 * \param[in] msg_l3 msgb containing Layer 3 Message
120 * \param[in] nc Mobile Network Code
121 * \param[in] cc Mobile Country Code
122 * \param[in] lac Location Area Code
123 * \param[in] _ci Cell Identity
124 * \returns callee-allocated msgb with Complete L3 Info message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200125struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc,
126 uint16_t cc, int lac, uint16_t _ci)
127{
Neels Hofmeyr4eeb8082018-03-23 01:47:14 +0100128 struct osmo_cell_global_id cgi = {
129 .lai = {
130 .plmn = {
131 .mcc = cc,
132 .mnc = nc,
133 },
134 .lac = lac,
135 },
136 .cell_identity = _ci,
137 };
138 return gsm0808_create_layer3_2(msg_l3, &cgi, NULL);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200139}
140
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200141/*! Create BSSMAP RESET message
Harald Welte96e2a002017-06-12 21:44:18 +0200142 * \returns callee-allocated msgb with BSSMAP Reset message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200143struct msgb *gsm0808_create_reset(void)
144{
Harald Welte65c2d362012-01-21 14:26:01 +0100145 uint8_t cause = GSM0808_CAUSE_EQUIPMENT_FAILURE;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200146 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
147 "bssmap: reset");
148 if (!msg)
149 return NULL;
150
Harald Welte65c2d362012-01-21 14:26:01 +0100151 msgb_v_put(msg, BSS_MAP_MSG_RESET);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100152 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100153 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
154
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200155 return msg;
156}
157
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200158/*! Create BSSMAP RESET ACK message
Harald Welte96e2a002017-06-12 21:44:18 +0200159 * \returns callee-allocated msgb with BSSMAP Reset ACK message */
Harald Weltea62fe312013-06-19 15:14:37 +0200160struct msgb *gsm0808_create_reset_ack(void)
161{
162 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
163 "bssmap: reset ack");
164 if (!msg)
165 return NULL;
166
167 msgb_v_put(msg, BSS_MAP_MSG_RESET_ACKNOWLEDGE);
168 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
169
170 return msg;
171}
172
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200173/*! Create BSSMAP Clear Complete message
Harald Welte96e2a002017-06-12 21:44:18 +0200174 * \returns callee-allocated msgb with BSSMAP Clear Complete message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200175struct msgb *gsm0808_create_clear_complete(void)
176{
177 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
178 "bssmap: clear complete");
Harald Welte65c2d362012-01-21 14:26:01 +0100179 uint8_t val = BSS_MAP_MSG_CLEAR_COMPLETE;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200180 if (!msg)
181 return NULL;
182
Harald Welte65c2d362012-01-21 14:26:01 +0100183 msg->l3h = msg->data;
184 msgb_tlv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 1, &val);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200185
186 return msg;
187}
188
Harald Welted1365e12019-02-18 13:44:30 +0100189/*! Create BSSMAP Clear Command message with BSSAP header *before* l3h and BSSMAP in l3h.
190 * This is quite different from most (all?) other gsm0808_create_* which have l3h
191 * point to the BSSAP header. However, we have to keep this for backwards compatibility.
192 * Use gsm0808_create_clear_command2() for a 'modern' implementation.
Philipp Maier1a146c82018-10-30 09:36:49 +0100193 * \param[in] cause TS 08.08 cause value
Harald Welte96e2a002017-06-12 21:44:18 +0200194 * \returns callee-allocated msgb with BSSMAP Clear Command message */
Philipp Maier1a146c82018-10-30 09:36:49 +0100195struct msgb *gsm0808_create_clear_command(uint8_t cause)
Holger Hans Peter Freythera3f05d82010-10-27 11:49:24 +0200196{
197 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
198 "bssmap: clear command");
199 if (!msg)
200 return NULL;
201
Holger Hans Peter Freytheraeebe392010-10-27 12:36:05 +0200202 msg->l3h = msgb_tv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 4);
203 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100204 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100205
Holger Hans Peter Freythera3f05d82010-10-27 11:49:24 +0200206 return msg;
207}
208
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100209/*! Create BSSMAP Clear Command message.
210 * \param[in] cause TS 08.08 cause value.
211 * \param[in] csfb_ind indicate that the call was established in an CSFB context.
212 * \returns callee-allocated msgb with BSSMAP Clear Command message. */
213struct msgb *gsm0808_create_clear_command2(uint8_t cause, bool csfb_ind)
214{
Harald Welte10ba47d2019-02-18 12:36:54 +0100215 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
216 "bssmap: clear command");
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100217 if (!msg)
218 return NULL;
219
Harald Welte10ba47d2019-02-18 12:36:54 +0100220 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD);
221 gsm0808_enc_cause(msg, cause);
222
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100223 if (csfb_ind)
224 msgb_v_put(msg, GSM0808_IE_CSFB_INDICATION);
225
Harald Welte10ba47d2019-02-18 12:36:54 +0100226 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
227
Philipp Maier74c4c4e2019-02-04 16:42:28 +0100228 return msg;
229}
230
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200231/*! Superseded by gsm0808_create_cipher2() to include Kc128.
232 * Create BSSMAP Cipher Mode Command message (without Kc128).
Harald Welte96e2a002017-06-12 21:44:18 +0200233 * \param[in] ei Mandatory Encryption Information
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200234 * \param[in] kc128 optional kc128 key for A5/4
Harald Welte96e2a002017-06-12 21:44:18 +0200235 * \param[in] cipher_response_mode optional 1-byte Cipher Response Mode
236 * \returns callee-allocated msgb with BSSMAP Cipher Mode Command message */
Philipp Maierb478dd32017-03-29 15:50:05 +0200237struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
238 const uint8_t *cipher_response_mode)
239{
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200240 struct gsm0808_cipher_mode_command cmc = {
241 .ei = *ei,
242 .cipher_response_mode_present = (cipher_response_mode != NULL),
243 .cipher_response_mode = (cipher_response_mode ? *cipher_response_mode : 0),
244 };
245 return gsm0808_create_cipher2(&cmc);
246}
247
248/*! Create BSSMAP Cipher Mode Command message.
249 * \param[in] cmc Information to encode.
250 * \returns callee-allocated msgb with BSSMAP Cipher Mode Command message */
251struct msgb *gsm0808_create_cipher2(const struct gsm0808_cipher_mode_command *cmc)
252{
Philipp Maierb478dd32017-03-29 15:50:05 +0200253 /* See also: 3GPP TS 48.008 3.2.1.30 CIPHER MODE COMMAND */
254 struct msgb *msg;
255
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200256 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "cipher-mode-command");
Philipp Maierb478dd32017-03-29 15:50:05 +0200257 if (!msg)
258 return NULL;
259
260 /* Message Type 3.2.2.1 */
261 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_CMD);
262
263 /* Encryption Information 3.2.2.10 */
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200264 gsm0808_enc_encrypt_info(msg, &cmc->ei);
Philipp Maierb478dd32017-03-29 15:50:05 +0200265
266 /* Cipher Response Mode 3.2.2.34 */
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200267 if (cmc->cipher_response_mode_present)
Philipp Maierb478dd32017-03-29 15:50:05 +0200268 msgb_tv_put(msg, GSM0808_IE_CIPHER_RESPONSE_MODE,
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +0200269 cmc->cipher_response_mode);
270
271 /* Kc128 3.2.2.109 */
272 if (cmc->kc128_present)
273 gsm0808_enc_kc128(msg, cmc->kc128);
Philipp Maierb478dd32017-03-29 15:50:05 +0200274
275 /* pre-pend the header */
276 msg->l3h =
277 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
278
279 return msg;
280}
281
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200282/*! Create BSSMAP Cipher Mode Complete message
Harald Welte96e2a002017-06-12 21:44:18 +0200283 * \param[in] layer3 L3 Message to be included
284 * \param[in] alg_id Chosen Encrpytion Algorithm
285 * \returns callee-allocated msgb with BSSMAP Cipher Mode Complete message */
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200286struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id)
287{
288 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
289 "cipher-complete");
290 if (!msg)
291 return NULL;
292
293 /* send response with BSS override for A5/1... cheating */
Harald Welte65c2d362012-01-21 14:26:01 +0100294 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_COMPLETE);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200295
296 /* include layer3 in case we have at least two octets */
297 if (layer3 && msgb_l3len(layer3) > 2) {
Harald Welte65c2d362012-01-21 14:26:01 +0100298 msg->l4h = msgb_tlv_put(msg, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS,
299 msgb_l3len(layer3), layer3->l3h);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200300 }
301
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +0700302 /* Optional Chosen Encryption Algorithm IE */
303 if (alg_id > 0)
304 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, alg_id);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200305
Harald Welte65c2d362012-01-21 14:26:01 +0100306 /* pre-pend the header */
307 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
308
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200309 return msg;
310}
311
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200312/*! Create BSSMAP Cipher Mode Reject message
Maxaa934632018-11-07 13:16:54 +0100313 * \param[in] cause 3GPP TS 08.08 §3.2.2.5 cause value
Harald Welte96e2a002017-06-12 21:44:18 +0200314 * \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */
Maxaa934632018-11-07 13:16:54 +0100315struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200316{
317 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
Maxaa934632018-11-07 13:16:54 +0100318 "bssmap: cipher mode reject");
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200319 if (!msg)
320 return NULL;
321
Harald Welte62e40852017-12-17 20:50:34 +0100322 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT);
Maxaa934632018-11-07 13:16:54 +0100323
Philipp Maier4f4905f2018-11-30 13:36:12 +0100324 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100325
326 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200327
328 return msg;
329}
330
Maxed651d22018-11-07 15:25:05 +0100331/*! Create BSSMAP Cipher Mode Reject message
332 * \param[in] class 3GPP TS 08.08 §3.2.2.5 cause's class
333 * \param[in] ext 3GPP TS 08.08 §3.2.2.5 cause value (national application extension)
334 * \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */
335struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext)
336{
Philipp Maier4f4905f2018-11-30 13:36:12 +0100337 uint16_t cause;
Maxed651d22018-11-07 15:25:05 +0100338 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
339 "bssmap: cipher mode reject");
340 if (!msg)
341 return NULL;
342
Philipp Maier4f4905f2018-11-30 13:36:12 +0100343 /* Set cause code class in the upper byte */
344 cause = 0x80 | (class << 4);
345 cause = cause << 8;
346
347 /* Set cause code extension in the lower byte */
348 cause |= ext;
Maxed651d22018-11-07 15:25:05 +0100349
350 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT);
351
Philipp Maier4f4905f2018-11-30 13:36:12 +0100352 gsm0808_enc_cause(msg, cause);
Maxed651d22018-11-07 15:25:05 +0100353
354 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
355
356 return msg;
357}
358
Harald Welte64e807c2018-05-29 21:00:56 +0200359/*! Create BSSMAP LCLS CONNECT CONTROL message (TS 48.008 3.2.1.91).
360 * \param[in] config LCLS Configuration
361 * \param[in] control LCLS Connection Status Control
362 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
Max45f89c92018-12-19 19:35:26 +0100363struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config,
364 enum gsm0808_lcls_control control)
Harald Welte64e807c2018-05-29 21:00:56 +0200365{
Max45f89c92018-12-19 19:35:26 +0100366 struct msgb *msg;
367
368 /* According to NOTE 1 in §3.2.1.91 at least one of the parameters is required */
369 if (config == GSM0808_LCLS_CFG_NA && control == GSM0808_LCLS_CSC_NA)
370 return NULL;
371
372 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "bssmap: LCLS CONN CTRL");
Harald Welte64e807c2018-05-29 21:00:56 +0200373 if (!msg)
374 return NULL;
375
376 msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL);
Max45f89c92018-12-19 19:35:26 +0100377 if (config != GSM0808_LCLS_CFG_NA)
378 msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, config);
379 if (control != GSM0808_LCLS_CSC_NA)
380 msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, control);
Harald Welte64e807c2018-05-29 21:00:56 +0200381 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
382
383 return msg;
384}
385
386/*! Create BSSMAP LCLS CONNECT CONTROL ACK message (TS 48.008 3.2.1.92).
387 * \param[in] status LCLS BSS Status
388 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
389struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status)
390{
391 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
392 "bssmap: LCLS CONN CTRL ACK");
393 if (!msg)
394 return NULL;
395
396 msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK);
397 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status);
398 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
399
400 return msg;
401}
402
403/*! Create BSSMAP LCLS NOTIFICATION message (TS 48.008 3.2.1.93).
404 * \param[in] status LCLS BSS Status
405 * \param[in] break_req Include the LCLS BREAK REQ IE (true) or not (false)
406 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
407struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req)
408{
409 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
410 "bssmap: LCLS NOTIFICATION");
411 if (!msg)
412 return NULL;
413
414 msgb_v_put(msg, BSS_MAP_MSG_LCLS_NOTIFICATION);
415 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status);
416 if (break_req)
417 msgb_v_put(msg, GSM0808_IE_LCLS_BREAK_REQ);
418 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
419
420 return msg;
421}
422
Neels Hofmeyr2c79d552018-09-13 05:36:32 +0200423/*! Create BSSMAP Classmark Request message
424 * \returns callee-allocated msgb with BSSMAP Classmark Request message */
425struct msgb *gsm0808_create_classmark_request()
426{
427 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
428 "classmark-request");
429 if (!msg)
430 return NULL;
431
432 msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_RQST);
433 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
434 return msg;
435}
Harald Welte64e807c2018-05-29 21:00:56 +0200436
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200437/*! Create BSSMAP Classmark Update message
Harald Welte96e2a002017-06-12 21:44:18 +0200438 * \param[in] cm2 Classmark 2
439 * \param[in] cm2_len length (in octets) of \a cm2
440 * \param[in] cm3 Classmark 3
441 * \param[in] cm3_len length (in octets) of \a cm3
442 * \returns callee-allocated msgb with BSSMAP Classmark Update message */
Harald Welte07b625d2012-01-23 10:02:58 +0100443struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
444 const uint8_t *cm3, uint8_t cm3_len)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200445{
446 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
447 "classmark-update");
448 if (!msg)
449 return NULL;
450
Harald Welte65c2d362012-01-21 14:26:01 +0100451 msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_UPDATE);
Harald Welte07b625d2012-01-23 10:02:58 +0100452 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T2, cm2_len, cm2);
453 if (cm3)
454 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T3,
455 cm3_len, cm3);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200456
Harald Welte65c2d362012-01-21 14:26:01 +0100457 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
458
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200459 return msg;
460}
461
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200462/*! Create BSSMAP SAPI N Reject message
Harald Welte96e2a002017-06-12 21:44:18 +0200463 * \param[in] link_id Link Identifier
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700464 * \param[in] cause BSSAP Cause value (see 3GPP TS 48.008, section 3.2.2.5)
Harald Welte96e2a002017-06-12 21:44:18 +0200465 * \returns callee-allocated msgb with BSSMAP SAPI N Reject message */
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700466struct msgb *gsm0808_create_sapi_reject_cause(uint8_t link_id, uint16_t cause)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200467{
468 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
469 "bssmap: sapi 'n' reject");
470 if (!msg)
471 return NULL;
472
Harald Welte65c2d362012-01-21 14:26:01 +0100473 msgb_v_put(msg, BSS_MAP_MSG_SAPI_N_REJECT);
Alexander Chemerisa5b1b862020-05-12 01:03:08 +0300474 msgb_tv_put(msg, GSM0808_IE_DLCI, link_id);
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700475 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100476
477 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200478
479 return msg;
480}
481
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700482/*! Create BSSMAP SAPI N Reject message (with hard-coded cause "BSS not equipped").
483 * DEPRECATED: use gsm0808_create_sapi_reject_cause() instead.
484 * \param[in] link_id Link Identifier
485 * \param[in] cause BSSAP Cause value (see 3GPP TS 48.008, section 3.2.2.5)
486 * \returns callee-allocated msgb with BSSMAP SAPI N Reject message */
487struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
488{
489 return gsm0808_create_sapi_reject_cause(link_id, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
490}
491
Max52074322018-11-30 10:44:07 +0100492/*! Create BSSMAP Assignment Request message, 3GPP TS 48.008 §3.2.1.1.
493 * This is identical to gsm0808_create_ass(), but adds KC and LCLS IEs.
Harald Welte96e2a002017-06-12 21:44:18 +0200494 * \param[in] ct Channel Type
495 * \param[in] cic Circuit Identity Code (Classic A only)
496 * \param[in] ss Socket Address of MSC-side RTP socket (AoIP only)
497 * \param[in] scl Speech Codec List (AoIP only)
Max49c06682018-11-21 22:10:26 +0100498 * \param[in] ci Call Identifier (Optional), §3.2.2.105
Max52074322018-11-30 10:44:07 +0100499 * \param[in] kc Kc128 ciphering key (Optional, A5/4), §3.2.2.109
500 * \param[in] lcls Optional LCLS parameters
Harald Welte96e2a002017-06-12 21:44:18 +0200501 * \returns callee-allocated msgb with BSSMAP Assignment Request message */
Max52074322018-11-30 10:44:07 +0100502struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
503 const uint16_t *cic,
504 const struct sockaddr_storage *ss,
505 const struct gsm0808_speech_codec_list *scl,
506 const uint32_t *ci,
507 const uint8_t *kc, const struct osmo_lcls *lcls)
Philipp Maierc6144a22017-03-29 17:53:43 +0200508{
509 /* See also: 3GPP TS 48.008 3.2.1.1 ASSIGNMENT REQUEST */
510 struct msgb *msg;
Philipp Maierc6144a22017-03-29 17:53:43 +0200511
512 /* Mandatory emelent! */
513 OSMO_ASSERT(ct);
514
515 msg =
516 msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
517 "bssmap: ass req");
518 if (!msg)
519 return NULL;
520
521 /* Message Type 3.2.2.1 */
522 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_RQST);
523
524 /* Channel Type 3.2.2.11 */
525 gsm0808_enc_channel_type(msg, ct);
526
527 /* Circuit Identity Code 3.2.2.2 */
Vadim Yanitskiy1c4fc222021-02-05 03:58:24 +0100528 if (cic)
529 msgb_tv16_put(msg, GSM0808_IE_CIRCUIT_IDENTITY_CODE, *cic);
Philipp Maierc6144a22017-03-29 17:53:43 +0200530
531 /* AoIP: AoIP Transport Layer Address (MGW) 3.2.2.102 */
532 if (ss) {
533 gsm0808_enc_aoip_trasp_addr(msg, ss);
534 }
535
536 /* AoIP: Codec List (MSC Preferred) 3.2.2.103 */
537 if (scl)
538 gsm0808_enc_speech_codec_list(msg, scl);
539
540 /* AoIP: Call Identifier 3.2.2.105 */
541 if (ci) {
Philipp Maier2908dbf2020-06-05 14:16:11 +0200542 /* NOTE: 3GPP TS 48.008, section 3.2.2.105 specifies that
Vadim Yanitskiy1c4fc222021-02-05 03:58:24 +0100543 * the least significant byte shall be transmitted first. */
544 msgb_v_put(msg, GSM0808_IE_CALL_ID);
545 osmo_store32le(*ci, msgb_put(msg, sizeof(*ci)));
Philipp Maierc6144a22017-03-29 17:53:43 +0200546 }
547
Max52074322018-11-30 10:44:07 +0100548 if (kc)
549 msgb_tv_fixed_put(msg, GSM0808_IE_KC_128, 16, kc);
550
Max47022152018-12-19 18:51:00 +0100551 if (lcls)
552 gsm0808_enc_lcls(msg, lcls);
Max52074322018-11-30 10:44:07 +0100553
Philipp Maierc6144a22017-03-29 17:53:43 +0200554 /* push the bssmap header */
555 msg->l3h =
556 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
557
558 return msg;
559}
560
Max52074322018-11-30 10:44:07 +0100561/*! Create BSSMAP Assignment Request message, 3GPP TS 48.008 §3.2.1.1.
562 * \param[in] ct Channel Type
563 * \param[in] cic Circuit Identity Code (Classic A only)
564 * \param[in] ss Socket Address of MSC-side RTP socket (AoIP only)
565 * \param[in] scl Speech Codec List (AoIP only)
566 * \param[in] ci Call Identifier (Optional), §3.2.2.105
567 * \returns callee-allocated msgb with BSSMAP Assignment Request message */
568struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct,
569 const uint16_t *cic,
570 const struct sockaddr_storage *ss,
571 const struct gsm0808_speech_codec_list *scl,
572 const uint32_t *ci)
573{
574 return gsm0808_create_ass2(ct, cic, ss, scl, ci, NULL, NULL);
575}
576
Max414c8f52019-01-08 14:44:24 +0100577/*! Create BSSMAP Assignment Completed message as per 3GPP TS 48.008 §3.2.1.2
Harald Welte96e2a002017-06-12 21:44:18 +0200578 * \param[in] rr_cause GSM 04.08 RR Cause value
579 * \param[in] chosen_channel Chosen Channel
580 * \param[in] encr_alg_id Encryption Algorithm ID
581 * \param[in] speech_mode Speech Mode
582 * \param[in] ss Socket Address of BSS-side RTP socket
583 * \param[in] sc Speech Codec (current)
584 * \param[in] scl Speech Codec List (permitted)
Max414c8f52019-01-08 14:44:24 +0100585 * \param[in] lcls_bss_status §3.2.2.119 LCLS-BSS-Status, optional
Harald Welte96e2a002017-06-12 21:44:18 +0200586 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
Max414c8f52019-01-08 14:44:24 +0100587struct msgb *gsm0808_create_ass_compl2(uint8_t rr_cause, uint8_t chosen_channel,
Philipp Maierfa896ab2017-03-27 16:55:32 +0200588 uint8_t encr_alg_id, uint8_t speech_mode,
589 const struct sockaddr_storage *ss,
590 const struct gsm0808_speech_codec *sc,
Max414c8f52019-01-08 14:44:24 +0100591 const struct gsm0808_speech_codec_list *scl,
592 enum gsm0808_lcls_status lcls_bss_status)
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200593{
Harald Welte65c2d362012-01-21 14:26:01 +0100594 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
595 "bssmap: ass compl");
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200596 if (!msg)
597 return NULL;
598
Harald Welte65c2d362012-01-21 14:26:01 +0100599 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_COMPLETE);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200600
601 /* write 3.2.2.22 */
Harald Welte65c2d362012-01-21 14:26:01 +0100602 msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, rr_cause);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200603
604 /* write cirtcuit identity code 3.2.2.2 */
605 /* write cell identifier 3.2.2.17 */
606 /* write chosen channel 3.2.2.33 when BTS picked it */
Harald Welte65c2d362012-01-21 14:26:01 +0100607 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, chosen_channel);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200608
609 /* write chosen encryption algorithm 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +0700610 if (encr_alg_id > 0)
611 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, encr_alg_id);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200612
613 /* write circuit pool 3.2.2.45 */
614 /* write speech version chosen: 3.2.2.51 when BTS picked it */
Harald Welte65c2d362012-01-21 14:26:01 +0100615 if (speech_mode != 0)
616 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, speech_mode);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200617
Philipp Maierfa896ab2017-03-27 16:55:32 +0200618 /* AoIP: AoIP Transport Layer Address (BSS) 3.2.2.102 */
619 if (ss)
620 gsm0808_enc_aoip_trasp_addr(msg, ss);
621
622 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
623 if (sc)
624 gsm0808_enc_speech_codec(msg, sc);
625
626 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
627 if (scl)
628 gsm0808_enc_speech_codec_list(msg, scl);
629
Max414c8f52019-01-08 14:44:24 +0100630 /* FIXME: write LSA identifier 3.2.2.15 - see 3GPP TS 43.073 */
631
632 /* LCLS-BSS-Status 3.2.2.119 */
633 if (lcls_bss_status != GSM0808_LCLS_STS_NA)
634 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, lcls_bss_status);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200635
Harald Welte65c2d362012-01-21 14:26:01 +0100636 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200637
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200638 return msg;
639}
640
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200641/*! Create BSSMAP Assignment Completed message
Harald Welte96e2a002017-06-12 21:44:18 +0200642 * \param[in] rr_cause GSM 04.08 RR Cause value
643 * \param[in] chosen_channel Chosen Channel
644 * \param[in] encr_alg_id Encryption Algorithm ID
645 * \param[in] speech_mode Speech Mode
Max414c8f52019-01-08 14:44:24 +0100646 * \param[in] ss Socket Address of BSS-side RTP socket
647 * \param[in] sc Speech Codec (current)
648 * \param[in] scl Speech Codec List (permitted)
649 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
650struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel,
651 uint8_t encr_alg_id, uint8_t speech_mode,
652 const struct sockaddr_storage *ss,
653 const struct gsm0808_speech_codec *sc,
654 const struct gsm0808_speech_codec_list *scl)
655{
656 return gsm0808_create_ass_compl2(rr_cause, chosen_channel, encr_alg_id, speech_mode,
657 ss, sc, scl, GSM0808_LCLS_STS_NA);
658}
659
660/*! Create BSSMAP Assignment Completed message
661 * \param[in] rr_cause GSM 04.08 RR Cause value
662 * \param[in] chosen_channel Chosen Channel
663 * \param[in] encr_alg_id Encryption Algorithm ID
664 * \param[in] speech_mode Speech Mode
Harald Welte96e2a002017-06-12 21:44:18 +0200665 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200666struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
667 uint8_t chosen_channel,
668 uint8_t encr_alg_id,
669 uint8_t speech_mode)
670{
Max414c8f52019-01-08 14:44:24 +0100671 return gsm0808_create_ass_compl2(rr_cause, chosen_channel, encr_alg_id,
672 speech_mode, NULL, NULL, NULL, GSM0808_LCLS_STS_NA);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200673}
674
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200675/*! Create BSSMAP Assignment Failure message
Harald Welte96e2a002017-06-12 21:44:18 +0200676 * \param[in] cause BSSMAP Cause value
677 * \param[in] rr_cause GSM 04.08 RR Cause value
678 * \param[in] scl Optional Speech Cdec List (AoIP)
679 * \returns callee-allocated msgb with BSSMAP Assignment Failure message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200680struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause,
681 const struct gsm0808_speech_codec_list
682 *scl)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200683{
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200684 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
685 "bssmap: ass fail");
686 if (!msg)
687 return NULL;
688
Harald Welte65c2d362012-01-21 14:26:01 +0100689 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_FAILURE);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100690 gsm0808_enc_cause(msg, cause);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200691
692 /* RR cause 3.2.2.22 */
Harald Welte65c2d362012-01-21 14:26:01 +0100693 if (rr_cause)
694 msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, *rr_cause);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200695
696 /* Circuit pool 3.22.45 */
697 /* Circuit pool list 3.2.2.46 */
698
Philipp Maierfa896ab2017-03-27 16:55:32 +0200699 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
700 if (scl)
701 gsm0808_enc_speech_codec_list(msg, scl);
702
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200703 /* update the size */
Harald Welte65c2d362012-01-21 14:26:01 +0100704 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
705
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200706 return msg;
707}
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +0200708
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200709/*! Create BSSMAP Assignment Failure message
Harald Welte96e2a002017-06-12 21:44:18 +0200710 * \param[in] cause BSSMAP Cause value
711 * \param[in] rr_cause GSM 04.08 RR Cause value
712 * \returns callee-allocated msgb with BSSMAP Assignment Failure message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200713struct msgb *gsm0808_create_assignment_failure(uint8_t cause,
714 uint8_t *rr_cause)
715{
716 return gsm0808_create_ass_fail(cause, rr_cause, NULL);
717}
718
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200719/*! Create BSSMAP Clear Request message
Harald Welte96e2a002017-06-12 21:44:18 +0200720 * \param[in] cause BSSMAP Cause value
721 * \returns callee-allocated msgb with BSSMAP Clear Request message */
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100722struct msgb *gsm0808_create_clear_rqst(uint8_t cause)
723{
724 struct msgb *msg;
725
726 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
727 "bssmap: clear rqst");
728 if (!msg)
729 return NULL;
730
Harald Welte65c2d362012-01-21 14:26:01 +0100731 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_RQST);
Philipp Maier4f4905f2018-11-30 13:36:12 +0100732 gsm0808_enc_cause(msg, cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100733 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100734
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100735 return msg;
736}
737
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200738/*! Create BSSMAP PAGING message
Harald Welte96e2a002017-06-12 21:44:18 +0200739 * \param[in] imsi Mandatory paged IMSI in string representation
740 * \param[in] tmsi Optional paged TMSI
Stefan Sperling3953f412018-08-28 15:06:30 +0200741 * \param[in] cil Mandatory Cell Identity List (where to page)
Harald Welte96e2a002017-06-12 21:44:18 +0200742 * \param[in] chan_needed Channel Type needed
743 * \returns callee-allocated msgb with BSSMAP PAGING message */
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100744struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
745 const struct gsm0808_cell_id_list2 *cil,
746 const uint8_t *chan_needed)
Philipp Maier3d48ec02017-03-29 17:37:55 +0200747{
748 struct msgb *msg;
Harald Weltea13fb752020-06-16 08:44:42 +0200749 uint8_t mid_buf[GSM48_MI_SIZE + 2];
750 int mid_len;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200751 uint32_t tmsi_sw;
752
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100753 /* Mandatory elements! */
Philipp Maier3d48ec02017-03-29 17:37:55 +0200754 OSMO_ASSERT(imsi);
755 OSMO_ASSERT(cil);
756
757 /* Malformed IMSI */
758 OSMO_ASSERT(strlen(imsi) <= GSM48_MI_SIZE);
759
760 msg =
761 msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "paging");
762 if (!msg)
763 return NULL;
764
765 /* Message Type 3.2.2.1 */
766 msgb_v_put(msg, BSS_MAP_MSG_PAGING);
767
Stefan Sperling3953f412018-08-28 15:06:30 +0200768 /* mandatory IMSI 3.2.2.6 */
Harald Weltea13fb752020-06-16 08:44:42 +0200769 mid_len = gsm48_generate_mid_from_imsi(mid_buf, imsi);
770 msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200771
772 /* TMSI 3.2.2.7 */
773 if (tmsi) {
Harald Welte95871da2017-05-15 12:11:36 +0200774 tmsi_sw = osmo_htonl(*tmsi);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200775 msgb_tlv_put(msg, GSM0808_IE_TMSI, sizeof(*tmsi),
776 (uint8_t *) & tmsi_sw);
777 }
778
Stefan Sperling3953f412018-08-28 15:06:30 +0200779 /* mandatory Cell Identifier List 3.2.2.27 */
780 gsm0808_enc_cell_id_list2(msg, cil);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200781
782 /* Channel Needed 3.2.2.36 */
783 if (chan_needed) {
784 msgb_tv_put(msg, GSM0808_IE_CHANNEL_NEEDED,
785 (*chan_needed) & 0x03);
786 }
787
788 /* pre-pend the header */
789 msg->l3h =
790 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
791
792 return msg;
793}
794
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100795/*! DEPRECATED: Use gsm0808_create_paging2 instead.
796 * Create BSSMAP PAGING message.
797 * \param[in] imsi Mandatory paged IMSI in string representation
798 * \param[in] tmsi Optional paged TMSI
799 * \param[in] cil Cell Identity List (where to page)
800 * \param[in] chan_needed Channel Type needed
801 * \returns callee-allocated msgb with BSSMAP PAGING message */
802struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
803 const struct gsm0808_cell_id_list *cil,
804 const uint8_t *chan_needed)
805{
806 struct gsm0808_cell_id_list2 cil2 = {};
807
Pau Espin Pedrol49766ab2021-04-19 12:14:36 +0200808 /* Mandatory elements! */
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100809 OSMO_ASSERT(cil);
810
811 if (cil->id_list_len > GSM0808_CELL_ID_LIST2_MAXLEN)
812 return NULL;
813
814 cil2.id_discr = cil->id_discr;
815 memcpy(cil2.id_list, cil->id_list_lac, cil->id_list_len * sizeof(cil2.id_list[0].lac));
816 cil2.id_list_len = cil->id_list_len;
817
818 return gsm0808_create_paging2(imsi, tmsi, &cil2, chan_needed);
819}
820
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100821static uint8_t put_old_bss_to_new_bss_information(struct msgb *msg,
822 const struct gsm0808_old_bss_to_new_bss_info *i)
823{
824 uint8_t *old_tail;
825 uint8_t *tlv_len;
826
827 msgb_put_u8(msg, GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION);
828 tlv_len = msgb_put(msg, 1);
829 old_tail = msg->tail;
830
831 if (i->extra_information_present) {
832 uint8_t val = 0;
833 if (i->extra_information.prec)
834 val |= 1 << 0;
835 if (i->extra_information.lcs)
836 val |= 1 << 1;
837 if (i->extra_information.ue_prob)
838 val |= 1 << 2;
839 msgb_tlv_put(msg, GSM0808_FE_IE_EXTRA_INFORMATION, 1, &val);
840 }
841
842 if (i->current_channel_type_2_present) {
843 uint8_t val[2] = {
844 i->current_channel_type_2.mode,
845 i->current_channel_type_2.field,
846 };
847 msgb_tlv_put(msg, GSM0808_FE_IE_CURRENT_CHANNEL_TYPE_2, 2, val);
848 }
849
Pau Espin Pedrol1b625cb2021-04-14 21:27:31 +0200850 if (i->last_eutran_plmn_id_present) {
851 msgb_put_u8(msg, GSM0808_FE_IE_LAST_USED_EUTRAN_PLMN_ID);
852 osmo_plmn_to_bcd(msgb_put(msg, 3), &i->last_eutran_plmn_id);
853 }
854
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100855 *tlv_len = (uint8_t) (msg->tail - old_tail);
856 return *tlv_len + 2;
857}
858
859/*! Create BSSMAP HANDOVER REQUIRED message.
860 * \param[in] params All information to be encoded.
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200861 * \returns newly allocated msgb with BSSMAP HANDOVER REQUIRED message. */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100862struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params)
863{
864 struct msgb *msg;
865
866 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUIRED");
867 if (!msg)
868 return NULL;
869
870 /* Message Type, 3.2.2.1 */
871 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_REQUIRED);
872
873 /* Cause, 3.2.2.5 */
Philipp Maier4f4905f2018-11-30 13:36:12 +0100874 gsm0808_enc_cause(msg, params->cause);
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100875
876 /* Cell Identifier List, 3.2.2.27 */
877 gsm0808_enc_cell_id_list2(msg, &params->cil);
878
879 /* Current Channel Type 1, 3.2.2.49 */
880 if (params->current_channel_type_1_present)
881 msgb_tv_fixed_put(msg, GSM0808_IE_CURRENT_CHANNEL_TYPE_1, 1, &params->current_channel_type_1);
882
883 /* Speech Version (Used), 3.2.2.51 */
884 if (params->speech_version_used_present)
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200885 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_used);
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100886
887 if (params->old_bss_to_new_bss_info_present)
888 put_old_bss_to_new_bss_information(msg, &params->old_bss_to_new_bss_info);
889
890 /* pre-pend the header */
891 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
892
893 return msg;
894}
895
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100896/*! Create BSSMAP HANDOVER REQUIRED REJECT message.
897 * \returns newly allocated msgb with BSSMAP HANDOVER REQUIRED REJECT message. */
898struct msgb *gsm0808_create_handover_required_reject(const struct gsm0808_handover_required_reject *params)
899{
900 struct msgb *msg;
901
902 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUIRED-REJECT");
903 if (!msg)
904 return NULL;
905
906 /* Message Type, 3.2.2.1 */
907 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT);
908
909 /* Cause, 3.2.2.5 */
910 gsm0808_enc_cause(msg, params->cause);
911
912 /* prepend the header */
913 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
914
915 return msg;
916}
917
918/*! Create BSSMAP HANDOVER REQUEST message, 3GPP TS 48.008 3.2.1.8.
919 * Sent from the MSC to the potential new target cell during inter-BSC handover, or to the target MSC during inter-MSC
920 * handover.
921 */
922struct msgb *gsm0808_create_handover_request(const struct gsm0808_handover_request *params)
923{
924 struct msgb *msg;
925
926 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUEST");
927 if (!msg)
928 return NULL;
929
930 /* Message Type, 3.2.2.1 */
931 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_RQST);
932
933 /* Channel Type 3.2.2.11 */
934 gsm0808_enc_channel_type(msg, &params->channel_type);
935
936 /* Encryption Information 3.2.2.10 */
937 gsm0808_enc_encrypt_info(msg, &params->encryption_information);
938
939 /* Classmark Information 1 3.2.2.30 or Classmark Information 2 3.2.2.19 (Classmark 2 wins) */
940 if (params->classmark_information.classmark2_len) {
941 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T2,
942 params->classmark_information.classmark2_len,
943 (const uint8_t*)&params->classmark_information.classmark2);
944 } else if (params->classmark_information.classmark1_set) {
945 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1,
946 sizeof(params->classmark_information.classmark1),
947 (const uint8_t*)&params->classmark_information.classmark1);
948 }
949 /* (Classmark 3 possibly follows below) */
950
951 /* Cell Identifier (Serving) , 3.2.2.17 */
952 gsm0808_enc_cell_id(msg, &params->cell_identifier_serving);
953
954 /* Cell Identifier (Target) , 3.2.2.17 */
955 gsm0808_enc_cell_id(msg, &params->cell_identifier_target);
956
957 /* Cause, 3.2.2.5 */
958 gsm0808_enc_cause(msg, params->cause);
959
960 /* Classmark Information 3 3.2.2.20 */
961 if (params->classmark_information.classmark3_len) {
962 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T3,
963 params->classmark_information.classmark3_len,
964 (const uint8_t*)&params->classmark_information.classmark3);
965 }
966
967 /* Current Channel type 1 3.2.2.49 */
968 if (params->current_channel_type_1_present)
969 msgb_tv_fixed_put(msg, GSM0808_IE_CURRENT_CHANNEL_TYPE_1, 1, &params->current_channel_type_1);
970
971 /* Speech Version (Used), 3.2.2.51 */
972 if (params->speech_version_used) {
973 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_used);
974 }
975
976 /* Chosen Encryption Algorithm (Serving) 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +0700977 if (params->chosen_encryption_algorithm_serving > 0)
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100978 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encryption_algorithm_serving);
979
980 /* Old BSS to New BSS Information 3.2.2.58 */
981 if (params->old_bss_to_new_bss_info_raw && params->old_bss_to_new_bss_info_raw_len) {
982 msgb_tlv_put(msg, GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION,
983 params->old_bss_to_new_bss_info_raw_len,
984 params->old_bss_to_new_bss_info_raw);
985 } else if (params->old_bss_to_new_bss_info_present) {
986 put_old_bss_to_new_bss_information(msg, &params->old_bss_to_new_bss_info);
987 }
988
989 /* IMSI 3.2.2.6 */
990 if (params->imsi) {
Harald Weltea13fb752020-06-16 08:44:42 +0200991 uint8_t mid_buf[GSM48_MI_SIZE + 2];
992 int mid_len = gsm48_generate_mid_from_imsi(mid_buf, params->imsi);
993 msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2);
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100994 }
995
996 if (params->aoip_transport_layer)
997 gsm0808_enc_aoip_trasp_addr(msg, params->aoip_transport_layer);
998
999 if (params->codec_list_msc_preferred)
1000 gsm0808_enc_speech_codec_list(msg, params->codec_list_msc_preferred);
1001
1002 if (params->call_id_present) {
1003 uint8_t val[4];
1004 osmo_store32le(params->call_id, val);
1005 msgb_tv_fixed_put(msg, GSM0808_IE_CALL_ID, 4, val);
1006 }
1007
Neels Hofmeyre4378b72021-06-10 00:54:35 +02001008 if (params->more_items && params->kc128_present)
1009 gsm0808_enc_kc128(msg, params->kc128);
1010
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001011 if (params->global_call_reference && params->global_call_reference_len) {
1012 msgb_tlv_put(msg, GSM0808_IE_GLOBAL_CALL_REF,
1013 params->global_call_reference_len, params->global_call_reference);
1014 }
1015
1016 /* prepend header with final length */
1017 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1018
1019 return msg;
1020}
1021
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001022/*! Create BSSMAP HANDOVER REQUEST ACKNOWLEDGE message, 3GPP TS 48.008 3.2.1.10.
1023 * Sent from the MT BSC back to the MSC when it has allocated an lchan to handover to.
1024 * 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 +01001025struct msgb *gsm0808_create_handover_request_ack2(const struct gsm0808_handover_request_ack *params)
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001026{
1027 struct msgb *msg;
1028
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001029 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUEST-ACK");
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001030 if (!msg)
1031 return NULL;
1032
1033 /* Message Type, 3.2.2.1 */
1034 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE);
1035
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001036 /* Layer 3 Information, 3.2.2.24 -- it is actually mandatory, but rather compose a nonstandard message than
1037 * segfault or return NULL without a log message. */
1038 if (params->l3_info && params->l3_info_len)
1039 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, params->l3_info_len, params->l3_info);
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001040
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001041 if (params->chosen_channel_present)
1042 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, params->chosen_channel);
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +07001043 if (params->chosen_encr_alg > 0)
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001044 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg);
1045
1046 if (params->chosen_speech_version != 0)
1047 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->chosen_speech_version);
1048
1049 if (params->aoip_transport_layer)
1050 gsm0808_enc_aoip_trasp_addr(msg, params->aoip_transport_layer);
1051
1052 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
1053 if (params->speech_codec_chosen_present)
1054 gsm0808_enc_speech_codec(msg, &params->speech_codec_chosen);
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001055
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001056 /* prepend header with final length */
1057 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1058
Neels Hofmeyrb662b362018-04-16 22:31:15 +02001059 return msg;
1060}
1061
Neels Hofmeyr73b943e2019-03-14 04:10:25 +01001062/*! Same as gsm0808_create_handover_request_ack2() but with less parameters.
1063 * In particular, this lacks the AoIP Transport Layer address. */
1064struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len,
1065 uint8_t chosen_channel, uint8_t chosen_encr_alg,
1066 uint8_t chosen_speech_version)
1067{
1068 struct gsm0808_handover_request_ack params = {
1069 .l3_info = l3_info,
1070 .l3_info_len = l3_info_len,
1071 .chosen_channel = chosen_channel,
1072 .chosen_encr_alg = chosen_encr_alg,
1073 .chosen_speech_version = chosen_speech_version,
1074 };
1075
1076 return gsm0808_create_handover_request_ack2(&params);
1077}
1078
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001079/*! Create BSSMAP HANDOVER COMMAND message, 3GPP TS 48.008 3.2.1.11.
1080 * Sent from the MSC to the old BSS to transmit the RR Handover Command received from the new BSS. */
1081struct msgb *gsm0808_create_handover_command(const struct gsm0808_handover_command *params)
1082{
1083 struct msgb *msg;
1084
1085 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-COMMAND");
1086 if (!msg)
1087 return NULL;
1088
1089 /* Message Type, 3.2.2.1 */
1090 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_CMD);
1091
1092 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, params->l3_info_len, params->l3_info);
1093
1094 if (params->cell_identifier.id_discr != CELL_IDENT_NO_CELL)
1095 gsm0808_enc_cell_id(msg, &params->cell_identifier);
1096
1097 if (params->new_bss_to_old_bss_info_raw
1098 && params->new_bss_to_old_bss_info_raw_len)
1099 msgb_tlv_put(msg, GSM0808_IE_NEW_BSS_TO_OLD_BSS_INFO, params->new_bss_to_old_bss_info_raw_len,
1100 params->new_bss_to_old_bss_info_raw);
1101
1102 /* prepend header with final length */
1103 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1104
1105 return msg;
1106}
1107
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001108/*! Create BSSMAP HANDOVER DETECT message, 3GPP TS 48.008 3.2.1.40.
1109 * Sent from the MT BSC back to the MSC when the MS has sent a handover RACH request and the MT BSC has
1110 * received the Handover Detect message. */
1111struct msgb *gsm0808_create_handover_detect()
1112{
1113 struct msgb *msg;
1114
1115 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-DETECT");
1116 if (!msg)
1117 return NULL;
1118
1119 /* Message Type, 3.2.2.1 */
1120 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_DETECT);
1121
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001122 /* prepend header with final length */
1123 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1124
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001125 return msg;
1126}
1127
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +01001128/*! Create BSSMAP HANDOVER SUCCEEDED message, 3GPP TS 48.008 3.2.1.13.
1129 * Sent from the MSC back to the old BSS to notify that the MS has successfully accessed the new BSS. */
1130struct msgb *gsm0808_create_handover_succeeded()
1131{
1132 struct msgb *msg;
1133
1134 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-DETECT");
1135 if (!msg)
1136 return NULL;
1137
1138 /* Message Type, 3.2.2.1 */
1139 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_SUCCEEDED);
1140
1141 /* prepend header with final length */
1142 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1143
1144 return msg;
1145}
1146
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001147/*! Create BSSMAP HANDOVER COMPLETE message, 3GPP TS 48.008 3.2.1.12.
1148 * Sent from the MT BSC back to the MSC when the MS has fully settled into the new lchan. */
1149struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params)
1150{
1151 struct msgb *msg;
1152
1153 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-COMPLETE");
1154 if (!msg)
1155 return NULL;
1156
1157 /* Message Type, 3.2.2.1 */
1158 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_COMPLETE);
1159
1160 /* RR Cause, 3.2.2.22 */
1161 if (params->rr_cause_present)
1162 msgb_tlv_put(msg, GSM0808_IE_RR_CAUSE, 1, &params->rr_cause);
1163
1164 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
1165 if (params->speech_codec_chosen_present)
1166 gsm0808_enc_speech_codec(msg, &params->speech_codec_chosen);
1167
1168 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
1169 if (params->codec_list_bss_supported.len)
1170 gsm0808_enc_speech_codec_list(msg, &params->codec_list_bss_supported);
1171
1172 /* Chosen Encryption Algorithm 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +07001173 if (params->chosen_encr_alg_present && params->chosen_encr_alg > 0)
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001174 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg);
1175
1176 /* LCLS-BSS-Status 3.2.2.119 */
1177 if (params->lcls_bss_status_present)
1178 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, params->lcls_bss_status);
1179
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001180 /* prepend header with final length */
1181 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1182
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001183 return msg;
1184}
1185
1186/*! Create BSSMAP HANDOVER FAILURE message, 3GPP TS 48.008 3.2.1.16.
1187 * Sent from the MT BSC back to the MSC when the handover has failed. */
1188struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params)
1189{
1190 struct msgb *msg;
1191
1192 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-FAILURE");
1193 if (!msg)
1194 return NULL;
1195
1196 /* Message Type, 3.2.2.1 */
1197 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_FAILURE);
1198
1199 /* Cause, 3.2.2.5 */
Philipp Maier4f4905f2018-11-30 13:36:12 +01001200 gsm0808_enc_cause(msg, params->cause);
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001201
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: add Codec List (BSS Supported) 3.2.2.103 */
1207 if (params->codec_list_bss_supported.len)
1208 gsm0808_enc_speech_codec_list(msg, &params->codec_list_bss_supported);
1209
Neels Hofmeyr43c266f2018-08-28 01:08:38 +02001210 /* prepend header with final length */
1211 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1212
Neels Hofmeyr60f31532018-04-16 22:42:09 +02001213 return msg;
1214}
1215
Philipp Maier225bdf42018-10-30 14:56:59 +01001216/*! Create BSSMAP HANDOVER PERFORMED message, 3GPP TS 48.008 3.2.1.25.
1217 * \param[in] params All information to be encoded.
1218 * \returns callee-allocated msgb with BSSMAP HANDOVER PERFORMED message */
1219struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params)
1220{
1221 struct msgb *msg;
1222
1223 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-PERFORMED");
1224 if (!msg)
1225 return NULL;
1226
1227 /* Message Type, 3.2.2.1 */
1228 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_PERFORMED);
1229
1230 /* Cause, 3.2.2.5 */
Philipp Maier4f4905f2018-11-30 13:36:12 +01001231 gsm0808_enc_cause(msg, params->cause);
Philipp Maier225bdf42018-10-30 14:56:59 +01001232
1233 /* Cell Identifier, 3.2.2.17 */
1234 gsm0808_enc_cell_id(msg, &params->cell_id);
1235
1236 /* Chosen Channel 3.2.2.33 */
1237 if (params->chosen_channel_present)
1238 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, params->chosen_channel);
1239
1240 /* Chosen Encryption Algorithm 3.2.2.44 */
Vadim Yanitskiyecaf5fa2020-08-31 19:10:39 +07001241 if (params->chosen_encr_alg_present && params->chosen_encr_alg > 0)
Philipp Maier225bdf42018-10-30 14:56:59 +01001242 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg);
1243
1244 /* Speech Version (chosen) 3.2.2.51 */
1245 if (params->speech_version_chosen_present)
1246 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_chosen);
1247
1248 /* AoIP: Speech Codec (chosen) 3.2.2.104 */
1249 if (params->speech_codec_chosen_present)
1250 gsm0808_enc_speech_codec(msg, &params->speech_codec_chosen);
1251
1252 /* LCLS-BSS-Status 3.2.2.119 */
1253 if (params->lcls_bss_status_present)
1254 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, params->lcls_bss_status);
1255
1256 /* prepend header with final length */
1257 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1258
1259 return msg;
1260}
1261
Neels Hofmeyr9b35e562020-06-22 17:59:18 +02001262/*! Create BSSMAP COMMON ID message, 3GPP TS 48.008 3.2.1.68.
1263 * \param[in] imsi IMSI digits (decimal string).
1264 * \param[in] selected_plmn_id Selected PLMN ID to encode, or NULL to not encode this IE.
1265 * \param[in] last_used_eutran_plnm_id Last used E-UTRAN PLMN ID to encode, or NULL to not encode this IE.
1266 * \returns callee-allocated msgb with BSSMAP COMMON ID message, or NULL if encoding failed. */
Harald Welte1bd726a2020-06-21 22:04:52 +02001267struct msgb *gsm0808_create_common_id(const char *imsi,
1268 const struct osmo_plmn_id *selected_plmn_id,
1269 const struct osmo_plmn_id *last_used_eutran_plnm_id)
1270{
1271 struct msgb *msg;
Harald Welte1bd726a2020-06-21 22:04:52 +02001272 uint8_t *out;
Neels Hofmeyr9b35e562020-06-22 17:59:18 +02001273 struct osmo_mobile_identity mi;
1274 int rc;
Harald Welte1bd726a2020-06-21 22:04:52 +02001275
1276 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "COMMON-ID");
1277 if (!msg)
1278 return NULL;
1279
1280 /* Message Type, 3.2.2.1 */
1281 msgb_v_put(msg, BSS_MAP_MSG_COMMON_ID);
1282
1283 /* mandatory IMSI 3.2.2.6 */
Neels Hofmeyr9b35e562020-06-22 17:59:18 +02001284 mi = (struct osmo_mobile_identity){ .type = GSM_MI_TYPE_IMSI };
1285 OSMO_STRLCPY_ARRAY(mi.imsi, imsi);
1286 out = msgb_tl_put(msg, GSM0808_IE_IMSI);
1287 rc = osmo_mobile_identity_encode_msgb(msg, &mi, false);
1288 if (rc < 0) {
1289 msgb_free(msg);
1290 return NULL;
1291 }
1292 /* write the MI value length */
1293 *out = rc;
Harald Welte1bd726a2020-06-21 22:04:52 +02001294
1295 /* not implemented: SNA Access Information */
1296
1297 /* Selected PLMN ID */
1298 if (selected_plmn_id) {
1299 msgb_v_put(msg, GSM0808_IE_SELECTED_PLMN_ID);
1300 out = msgb_put(msg, 3);
1301 osmo_plmn_to_bcd(out, selected_plmn_id);
1302 }
1303
1304 /* Last used E-UTRAN PLMN ID */
1305 if (last_used_eutran_plnm_id) {
1306 msgb_v_put(msg, GSM0808_IE_LAST_USED_EUTRAN_PLMN_ID);
1307 out = msgb_put(msg, 3);
1308 osmo_plmn_to_bcd(out, last_used_eutran_plnm_id);
1309 }
1310
1311 /* prepend header with final length */
1312 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1313
1314 return msg;
1315}
1316
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001317/*! Prepend a DTAP header to given Message Buffer
Harald Welte96e2a002017-06-12 21:44:18 +02001318 * \param[in] msgb Message Buffer
1319 * \param[in] link_id Link Identifier */
Holger Hans Peter Freyther9a3dec02010-05-16 08:15:40 +08001320void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id)
1321{
1322 uint8_t *hh = msgb_push(msg, 3);
1323 hh[0] = BSSAP_MSG_DTAP;
1324 hh[1] = link_id;
1325 hh[2] = msg->len - 3;
1326}
1327
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001328/*! Create BSSMAP DTAP message
Harald Welte96e2a002017-06-12 21:44:18 +02001329 * \param[in] msg_l3 Messge Buffer containing Layer3 message
1330 * \param[in] link_id Link Identifier
1331 * \returns callee-allocated msgb with BSSMAP DTAP message */
Holger Hans Peter Freytherc25c6682010-11-04 12:26:06 +01001332struct msgb *gsm0808_create_dtap(struct msgb *msg_l3, uint8_t link_id)
1333{
1334 struct dtap_header *header;
1335 uint8_t *data;
1336 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
1337 "dtap");
1338 if (!msg)
1339 return NULL;
1340
1341 /* DTAP header */
1342 msg->l3h = msgb_put(msg, sizeof(*header));
1343 header = (struct dtap_header *) &msg->l3h[0];
1344 header->type = BSSAP_MSG_DTAP;
1345 header->link_id = link_id;
1346 header->length = msgb_l3len(msg_l3);
1347
1348 /* Payload */
1349 data = msgb_put(msg, header->length);
1350 memcpy(data, msg_l3->l3h, header->length);
1351
1352 return msg;
1353}
1354
Neels Hofmeyr5b214e22020-09-18 18:00:50 +02001355struct msgb *gsm0808_create_perform_location_request(const struct gsm0808_perform_location_request *params)
1356{
1357 struct msgb *msg;
1358 uint8_t *out;
1359 int rc;
1360
1361 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-REQUEST");
1362 if (!msg)
1363 return NULL;
1364
1365 /* Message Type, 3.2.2.1 */
1366 msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_RQST);
1367
1368 /* Location Type 3.2.2.63 */
1369 osmo_bssmap_le_ie_enc_location_type(msg, &params->location_type);
1370
1371 if (params->imsi.type == GSM_MI_TYPE_IMSI) {
1372 /* IMSI 3.2.2.6 */
1373 out = msgb_tl_put(msg, GSM0808_IE_IMSI);
1374 rc = osmo_mobile_identity_encode_msgb(msg, &params->imsi, false);
1375 if (rc < 0) {
1376 msgb_free(msg);
1377 return NULL;
1378 }
1379 /* write the MI value length */
1380 *out = rc;
1381 }
1382
1383 /* prepend header with final length */
1384 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1385
1386 return msg;
1387}
1388
1389struct msgb *gsm0808_create_perform_location_response(const struct gsm0808_perform_location_response *params)
1390{
1391 struct msgb *msg;
1392
1393 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-RESPONSE");
1394 if (!msg)
1395 return NULL;
1396
1397 /* Message Type, 3.2.2.1 */
1398 msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE);
1399
1400 if (params->location_estimate_present) {
1401 uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LOCATION_ESTIMATE);
1402 int rc = osmo_gad_raw_write(msg, &params->location_estimate);
1403 if (rc < 0) {
1404 msgb_free(msg);
1405 return NULL;
1406 }
1407 *l = rc;
1408 }
1409
1410 if (params->lcs_cause.present) {
1411 uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LCS_CAUSE);
1412 int rc = osmo_lcs_cause_enc(msg, &params->lcs_cause);
1413 if (rc < 0) {
1414 msgb_free(msg);
1415 return NULL;
1416 }
1417 *l = rc;
1418 }
1419
1420 /* prepend header with final length */
1421 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1422
1423 return msg;
1424}
1425
1426int gsm0808_enc_lcs_cause(struct msgb *msg, const struct lcs_cause_ie *lcs_cause)
1427{
1428 uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LCS_CAUSE);
1429 int rc = osmo_lcs_cause_enc(msg, lcs_cause);
1430 if (rc <= 0)
1431 return rc;
1432 *l = rc;
1433 return rc + 2;
1434}
1435
1436struct msgb *gsm0808_create_perform_location_abort(const struct lcs_cause_ie *lcs_cause)
1437{
1438 struct msgb *msg;
1439
1440 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-ABORT");
1441 if (!msg)
1442 return NULL;
1443
1444 /* Message Type, 3.2.2.1 */
1445 msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_ABORT);
1446
1447 gsm0808_enc_lcs_cause(msg, lcs_cause);
1448
1449 /* prepend header with final length */
1450 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
1451
1452 return msg;
1453}
1454
Harald Welte92107df2014-06-21 23:16:20 +02001455/* As per 3GPP TS 48.008 version 11.7.0 Release 11 */
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001456static const struct tlv_definition bss_att_tlvdef = {
1457 .def = {
Harald Welte92107df2014-06-21 23:16:20 +02001458 [GSM0808_IE_CIRCUIT_IDENTITY_CODE] = { TLV_TYPE_FIXED, 2 },
1459 [GSM0808_IE_CONNECTION_RELEASE_RQSTED] = { TLV_TYPE_TV },
1460 [GSM0808_IE_RESOURCE_AVAILABLE] = { TLV_TYPE_FIXED, 21 },
1461 [GSM0808_IE_CAUSE] = { TLV_TYPE_TLV },
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001462 [GSM0808_IE_IMSI] = { TLV_TYPE_TLV },
1463 [GSM0808_IE_TMSI] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001464 [GSM0808_IE_NUMBER_OF_MSS] = { TLV_TYPE_TV },
Dmitri Soloviev29099422013-07-11 09:25:37 +02001465 [GSM0808_IE_LAYER_3_HEADER_INFORMATION] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001466 [GSM0808_IE_ENCRYPTION_INFORMATION] = { TLV_TYPE_TLV },
1467 [GSM0808_IE_CHANNEL_TYPE] = { TLV_TYPE_TLV },
1468 [GSM0808_IE_PERIODICITY] = { TLV_TYPE_TV },
1469 [GSM0808_IE_EXTENDED_RESOURCE_INDICATOR]= { TLV_TYPE_TV },
1470 [GSM0808_IE_TOTAL_RESOURCE_ACCESSIBLE] = { TLV_TYPE_FIXED, 4 },
1471 [GSM0808_IE_LSA_IDENTIFIER] = { TLV_TYPE_TLV },
1472 [GSM0808_IE_LSA_IDENTIFIER_LIST] = { TLV_TYPE_TLV },
Holger Hans Peter Freyther715e9452014-08-21 14:17:45 +02001473 [GSM0808_IE_LSA_INFORMATION] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +02001474 [GSM0808_IE_CELL_IDENTIFIER] = { TLV_TYPE_TLV },
1475 [GSM0808_IE_PRIORITY] = { TLV_TYPE_TLV },
1476 [GSM0808_IE_CLASSMARK_INFORMATION_T2] = { TLV_TYPE_TLV },
1477 [GSM0808_IE_CLASSMARK_INFORMATION_T3] = { TLV_TYPE_TLV },
1478 [GSM0808_IE_INTERFERENCE_BAND_TO_USE] = { TLV_TYPE_TV },
1479 [GSM0808_IE_RR_CAUSE] = { TLV_TYPE_TV },
Harald Welte92107df2014-06-21 23:16:20 +02001480 [GSM0808_IE_LAYER_3_INFORMATION] = { TLV_TYPE_TLV },
1481 [GSM0808_IE_DLCI] = { TLV_TYPE_TV },
1482 [GSM0808_IE_DOWNLINK_DTX_FLAG] = { TLV_TYPE_TV },
1483 [GSM0808_IE_CELL_IDENTIFIER_LIST] = { TLV_TYPE_TLV },
1484 [GSM0808_IE_CELL_ID_LIST_SEGMENT] = { TLV_TYPE_TLV },
1485 [GSM0808_IE_CELL_ID_LIST_SEG_EST_CELLS] = { TLV_TYPE_TLV },
1486 [GSM0808_IE_CELL_ID_LIST_SEG_CELLS_TBE] = { TLV_TYPE_TLV },
1487 [GSM0808_IE_CELL_ID_LIST_SEG_REL_CELLS] = { TLV_TYPE_TLV },
1488 [GSM0808_IE_CELL_ID_LIST_SEG_NE_CELLS] = { TLV_TYPE_TLV },
1489 [GSM0808_IE_RESPONSE_RQST] = { TLV_TYPE_T },
1490 [GSM0808_IE_RESOURCE_INDICATION_METHOD] = { TLV_TYPE_TV },
1491 [GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1] = { TLV_TYPE_TV },
1492 [GSM0808_IE_CIRCUIT_IDENTITY_CODE_LIST] = { TLV_TYPE_TLV },
1493 [GSM0808_IE_DIAGNOSTIC] = { TLV_TYPE_TLV },
1494 [GSM0808_IE_CHOSEN_CHANNEL] = { TLV_TYPE_TV },
1495 [GSM0808_IE_CIPHER_RESPONSE_MODE] = { TLV_TYPE_TV },
1496 [GSM0808_IE_LAYER_3_MESSAGE_CONTENTS] = { TLV_TYPE_TLV },
1497 [GSM0808_IE_CHANNEL_NEEDED] = { TLV_TYPE_TV },
1498 [GSM0808_IE_TRACE_TYPE] = { TLV_TYPE_TV },
1499 [GSM0808_IE_TRIGGERID] = { TLV_TYPE_TLV },
1500 [GSM0808_IE_TRACE_REFERENCE] = { TLV_TYPE_TV },
1501 [GSM0808_IE_TRANSACTIONID] = { TLV_TYPE_TLV },
1502 [GSM0808_IE_MOBILE_IDENTITY] = { TLV_TYPE_TLV },
1503 [GSM0808_IE_OMCID] = { TLV_TYPE_TLV },
1504 [GSM0808_IE_FORWARD_INDICATOR] = { TLV_TYPE_TV },
Holger Hans Peter Freytherc2b7f922010-08-04 18:50:43 +08001505 [GSM0808_IE_CHOSEN_ENCR_ALG] = { TLV_TYPE_TV },
Harald Welte92107df2014-06-21 23:16:20 +02001506 [GSM0808_IE_CIRCUIT_POOL] = { TLV_TYPE_TV },
1507 [GSM0808_IE_CIRCUIT_POOL_LIST] = { TLV_TYPE_TLV },
1508 [GSM0808_IE_TIME_INDICATION] = { TLV_TYPE_TV },
1509 [GSM0808_IE_RESOURCE_SITUATION] = { TLV_TYPE_TLV },
1510 [GSM0808_IE_CURRENT_CHANNEL_TYPE_1] = { TLV_TYPE_TV },
1511 [GSM0808_IE_QUEUEING_INDICATOR] = { TLV_TYPE_TV },
1512 [GSM0808_IE_SPEECH_VERSION] = { TLV_TYPE_TV },
1513 [GSM0808_IE_ASSIGNMENT_REQUIREMENT] = { TLV_TYPE_TV },
1514 [GSM0808_IE_TALKER_FLAG] = { TLV_TYPE_T },
1515 [GSM0808_IE_GROUP_CALL_REFERENCE] = { TLV_TYPE_TLV },
1516 [GSM0808_IE_EMLPP_PRIORITY] = { TLV_TYPE_TV },
1517 [GSM0808_IE_CONFIG_EVO_INDI] = { TLV_TYPE_TV },
1518 [GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION] = { TLV_TYPE_TLV },
1519 [GSM0808_IE_LCS_QOS] = { TLV_TYPE_TLV },
1520 [GSM0808_IE_LSA_ACCESS_CTRL_SUPPR] = { TLV_TYPE_TV },
1521 [GSM0808_IE_LCS_PRIORITY] = { TLV_TYPE_TLV },
1522 [GSM0808_IE_LOCATION_TYPE] = { TLV_TYPE_TLV },
1523 [GSM0808_IE_LOCATION_ESTIMATE] = { TLV_TYPE_TLV },
1524 [GSM0808_IE_POSITIONING_DATA] = { TLV_TYPE_TLV },
1525 [GSM0808_IE_LCS_CAUSE] = { TLV_TYPE_TLV },
1526 [GSM0808_IE_APDU] = { TLV_TYPE_TLV },
1527 [GSM0808_IE_NETWORK_ELEMENT_IDENTITY] = { TLV_TYPE_TLV },
1528 [GSM0808_IE_GPS_ASSISTANCE_DATA] = { TLV_TYPE_TLV },
1529 [GSM0808_IE_DECIPHERING_KEYS] = { TLV_TYPE_TLV },
1530 [GSM0808_IE_RETURN_ERROR_RQST] = { TLV_TYPE_TLV },
1531 [GSM0808_IE_RETURN_ERROR_CAUSE] = { TLV_TYPE_TLV },
1532 [GSM0808_IE_SEGMENTATION] = { TLV_TYPE_TLV },
1533 [GSM0808_IE_SERVICE_HANDOVER] = { TLV_TYPE_TLV },
1534 [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_UMTS] = { TLV_TYPE_TLV },
1535 [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_CDMA2000] = { TLV_TYPE_TLV },
1536 [GSM0808_IE_GERAN_CLASSMARK] = { TLV_TYPE_TLV },
1537 [GSM0808_IE_GERAN_BSC_CONTAINER] = { TLV_TYPE_TLV },
1538 [GSM0808_IE_NEW_BSS_TO_OLD_BSS_INFO] = { TLV_TYPE_TLV },
1539 [GSM0800_IE_INTER_SYSTEM_INFO] = { TLV_TYPE_TLV },
1540 [GSM0808_IE_SNA_ACCESS_INFO] = { TLV_TYPE_TLV },
1541 [GSM0808_IE_VSTK_RAND_INFO] = { TLV_TYPE_TLV },
1542 [GSM0808_IE_PAGING_INFO] = { TLV_TYPE_TV },
1543 [GSM0808_IE_IMEI] = { TLV_TYPE_TLV },
1544 [GSM0808_IE_VELOCITY_ESTIMATE] = { TLV_TYPE_TLV },
1545 [GSM0808_IE_VGCS_FEATURE_FLAGS] = { TLV_TYPE_TLV },
1546 [GSM0808_IE_TALKER_PRIORITY] = { TLV_TYPE_TV },
1547 [GSM0808_IE_EMERGENCY_SET_INDICATION] = { TLV_TYPE_T },
1548 [GSM0808_IE_TALKER_IDENTITY] = { TLV_TYPE_TLV },
1549 [GSM0808_IE_SMS_TO_VGCS] = { TLV_TYPE_TLV },
1550 [GSM0808_IE_VGCS_TALKER_MODE] = { TLV_TYPE_TLV },
1551 [GSM0808_IE_VGCS_VBS_CELL_STATUS] = { TLV_TYPE_TLV },
1552 [GSM0808_IE_GANSS_ASSISTANCE_DATA] = { TLV_TYPE_TLV },
1553 [GSM0808_IE_GANSS_POSITIONING_DATA] = { TLV_TYPE_TLV },
1554 [GSM0808_IE_GANSS_LOCATION_TYPE] = { TLV_TYPE_TLV },
1555 [GSM0808_IE_APP_DATA] = { TLV_TYPE_TLV },
1556 [GSM0808_IE_DATA_IDENTITY] = { TLV_TYPE_TLV },
1557 [GSM0808_IE_APP_DATA_INFO] = { TLV_TYPE_TLV },
1558 [GSM0808_IE_MSISDN] = { TLV_TYPE_TLV },
1559 [GSM0808_IE_AOIP_TRASP_ADDR] = { TLV_TYPE_TLV },
1560 [GSM0808_IE_SPEECH_CODEC_LIST] = { TLV_TYPE_TLV },
1561 [GSM0808_IE_SPEECH_CODEC] = { TLV_TYPE_TLV },
1562 [GSM0808_IE_CALL_ID] = { TLV_TYPE_FIXED, 4 },
1563 [GSM0808_IE_CALL_ID_LIST] = { TLV_TYPE_TLV },
1564 [GSM0808_IE_A_IF_SEL_FOR_RESET] = { TLV_TYPE_TV },
1565 [GSM0808_IE_KC_128] = { TLV_TYPE_FIXED, 16 },
1566 [GSM0808_IE_CSG_IDENTIFIER] = { TLV_TYPE_TLV },
1567 [GSM0808_IE_REDIR_ATTEMPT_FLAG] = { TLV_TYPE_T },
1568 [GSM0808_IE_REROUTE_REJ_CAUSE] = { TLV_TYPE_TV },
1569 [GSM0808_IE_SEND_SEQ_NUM] = { TLV_TYPE_TV },
1570 [GSM0808_IE_REROUTE_COMPL_OUTCOME] = { TLV_TYPE_TV },
1571 [GSM0808_IE_GLOBAL_CALL_REF] = { TLV_TYPE_TLV },
1572 [GSM0808_IE_LCLS_CONFIG] = { TLV_TYPE_TV },
1573 [GSM0808_IE_LCLS_CONN_STATUS_CTRL] = { TLV_TYPE_TV },
1574 [GSM0808_IE_LCLS_CORR_NOT_NEEDED] = { TLV_TYPE_TV },
1575 [GSM0808_IE_LCLS_BSS_STATUS] = { TLV_TYPE_TV },
1576 [GSM0808_IE_LCLS_BREAK_REQ] = { TLV_TYPE_TV },
1577 [GSM0808_IE_CSFB_INDICATION] = { TLV_TYPE_T },
1578 [GSM0808_IE_CS_TO_PS_SRVCC] = { TLV_TYPE_T },
1579 [GSM0808_IE_SRC_ENB_TO_TGT_ENB_TRANSP] = { TLV_TYPE_TLV },
1580 [GSM0808_IE_CS_TO_PS_SRVCC_IND] = { TLV_TYPE_T },
1581 [GSM0808_IE_CN_TO_MS_TRANSP_INFO] = { TLV_TYPE_TLV },
1582 [GSM0808_IE_SELECTED_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
1583 [GSM0808_IE_LAST_USED_EUTRAN_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
Pau Espin Pedrol18506c82019-04-16 15:47:59 +02001584
1585 /* Osmocom extensions */
1586 [GSM0808_IE_OSMO_OSMUX_SUPPORT] = { TLV_TYPE_T },
1587 [GSM0808_IE_OSMO_OSMUX_CID] = { TLV_TYPE_TV },
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001588 },
1589};
1590
Harald Weltef4d45ab2011-07-16 12:13:00 +02001591const struct tlv_definition *gsm0808_att_tlvdef(void)
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001592{
1593 return &bss_att_tlvdef;
1594}
Harald Welte9b837e62011-07-11 17:43:19 +02001595
Pau Espin Pedrolcde47792021-04-19 12:24:02 +02001596/* As per 3GPP TS 48.008 version 16.0.0 Release 16 § 3.2.2.58 Old BSS to New BSS Information */
1597const struct tlv_definition gsm0808_old_bss_to_new_bss_info_att_tlvdef = {
1598 .def = {
1599 [GSM0808_FE_IE_EXTRA_INFORMATION] = { TLV_TYPE_TLV },
1600 [GSM0808_FE_IE_CURRENT_CHANNEL_TYPE_2] = { TLV_TYPE_TLV },
1601 [GSM0808_FE_IE_TARGET_CELL_RADIO_INFORMATION] = { TLV_TYPE_TLV },
1602 [GSM0808_FE_IE_GPRS_SUSPEND_INFORMATION] = { TLV_TYPE_TLV },
1603 [GSM0808_FE_IE_MULTIRATE_CONFIGURATION_INFORMATION] = { TLV_TYPE_TLV },
1604 [GSM0808_FE_IE_DUAL_TRANSFER_MODE_INFORMATION] = { TLV_TYPE_TLV },
1605 [GSM0808_FE_IE_INTER_RAT_HANDOVER_INFO] = { TLV_TYPE_TLV },
1606 [GSM0808_FE_IE_CDMA2000_CAPABILITY_INFORMATION] = { TLV_TYPE_TLV },
1607 [GSM0808_FE_IE_DOWNLINK_CELL_LOAD_INFORMATION] = { TLV_TYPE_TLV },
1608 [GSM0808_FE_IE_UPLINK_CELL_LOAD_INFORMATION] = { TLV_TYPE_TLV },
1609 [GSM0808_FE_IE_CELL_LOAD_INFORMATION_GROUP] = { TLV_TYPE_TLV },
1610 [GSM0808_FE_IE_CELL_LOAD_INFORMATION] = { TLV_TYPE_TLV },
1611 [GSM0808_FE_IE_PS_INDICATION] = { TLV_TYPE_TLV },
1612 [GSM0808_FE_IE_DTM_HANDOVER_COMMAND_INDICATION] = { TLV_TYPE_TLV },
1613 [GSM0808_FE_IE_D_RNTI] = { TLV_TYPE_TLV },
1614 [GSM0808_FE_IE_IRAT_MEASUREMENT_CONFIGURATION] = { TLV_TYPE_TLV },
1615 [GSM0808_FE_IE_SOURCE_CELL_ID] = { TLV_TYPE_TLV },
1616 [GSM0808_FE_IE_IRAT_MEASUREMENT_CONFIGURATION_EXTENDED_E_ARFCNS] = { TLV_TYPE_TLV },
1617 [GSM0808_FE_IE_VGCS_TALKER_MODE] = { TLV_TYPE_TLV },
1618 [GSM0808_FE_IE_LAST_USED_EUTRAN_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
1619 },
1620};
1621
Pau Espin Pedrol392f6072019-11-27 12:07:04 +01001622const struct value_string gsm0406_dlci_sapi_names[] = {
1623 { DLCI_SAPI_RR_MM_CC, "RR/MM/CC" },
1624 { DLCI_SAPI_SMS, "SMS" },
1625 { 0, NULL }
1626};
1627
Harald Welte9b837e62011-07-11 17:43:19 +02001628static const struct value_string gsm0808_msgt_names[] = {
1629 { BSS_MAP_MSG_ASSIGMENT_RQST, "ASSIGNMENT REQ" },
1630 { BSS_MAP_MSG_ASSIGMENT_COMPLETE, "ASSIGNMENT COMPL" },
1631 { BSS_MAP_MSG_ASSIGMENT_FAILURE, "ASSIGNMENT FAIL" },
Harald Welte92107df2014-06-21 23:16:20 +02001632 { BSS_MAP_MSG_CHAN_MOD_RQST, "CHANNEL MODIFY REQUEST" },
Harald Welte9b837e62011-07-11 17:43:19 +02001633
1634 { BSS_MAP_MSG_HANDOVER_RQST, "HANDOVER REQ" },
1635 { BSS_MAP_MSG_HANDOVER_REQUIRED, "HANDOVER REQUIRED" },
1636 { BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE,"HANDOVER REQ ACK" },
1637 { BSS_MAP_MSG_HANDOVER_CMD, "HANDOVER CMD" },
1638 { BSS_MAP_MSG_HANDOVER_COMPLETE, "HANDOVER COMPLETE" },
1639 { BSS_MAP_MSG_HANDOVER_SUCCEEDED, "HANDOVER SUCCESS" },
1640 { BSS_MAP_MSG_HANDOVER_FAILURE, "HANDOVER FAILURE" },
1641 { BSS_MAP_MSG_HANDOVER_PERFORMED, "HANDOVER PERFORMED" },
1642 { BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE, "HANDOVER CAND ENQ" },
1643 { BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE, "HANDOVER CAND RESP" },
1644 { BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT, "HANDOVER REQ REJ" },
1645 { BSS_MAP_MSG_HANDOVER_DETECT, "HANDOVER DETECT" },
Harald Welte92107df2014-06-21 23:16:20 +02001646 { BSS_MAP_MSG_INT_HANDOVER_REQUIRED, "INT HANDOVER REQ" },
1647 { BSS_MAP_MSG_INT_HANDOVER_REQUIRED_REJ,"INT HANDOVER REQ REJ" },
1648 { BSS_MAP_MSG_INT_HANDOVER_CMD, "INT HANDOVER CMD" },
1649 { BSS_MAP_MSG_INT_HANDOVER_ENQUIRY, "INT HANDOVER ENQ" },
Harald Welte9b837e62011-07-11 17:43:19 +02001650
1651 { BSS_MAP_MSG_CLEAR_CMD, "CLEAR COMMAND" },
1652 { BSS_MAP_MSG_CLEAR_COMPLETE, "CLEAR COMPLETE" },
1653 { BSS_MAP_MSG_CLEAR_RQST, "CLEAR REQUEST" },
1654 { BSS_MAP_MSG_SAPI_N_REJECT, "SAPI N REJECT" },
1655 { BSS_MAP_MSG_CONFUSION, "CONFUSION" },
1656
1657 { BSS_MAP_MSG_SUSPEND, "SUSPEND" },
1658 { BSS_MAP_MSG_RESUME, "RESUME" },
1659 { BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION, "CONN ORIENT INFO" },
1660 { BSS_MAP_MSG_PERFORM_LOCATION_RQST, "PERFORM LOC REQ" },
1661 { BSS_MAP_MSG_LSA_INFORMATION, "LSA INFORMATION" },
1662 { BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE, "PERFORM LOC RESP" },
1663 { BSS_MAP_MSG_PERFORM_LOCATION_ABORT, "PERFORM LOC ABORT" },
1664 { BSS_MAP_MSG_COMMON_ID, "COMMON ID" },
Harald Welte92107df2014-06-21 23:16:20 +02001665 { BSS_MAP_MSG_REROUTE_CMD, "REROUTE COMMAND" },
1666 { BSS_MAP_MSG_REROUTE_COMPLETE, "REROUTE COMPLETE" },
Harald Welte9b837e62011-07-11 17:43:19 +02001667
1668 { BSS_MAP_MSG_RESET, "RESET" },
1669 { BSS_MAP_MSG_RESET_ACKNOWLEDGE, "RESET ACK" },
1670 { BSS_MAP_MSG_OVERLOAD, "OVERLOAD" },
1671 { BSS_MAP_MSG_RESET_CIRCUIT, "RESET CIRCUIT" },
1672 { BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE, "RESET CIRCUIT ACK" },
1673 { BSS_MAP_MSG_MSC_INVOKE_TRACE, "MSC INVOKE TRACE" },
1674 { BSS_MAP_MSG_BSS_INVOKE_TRACE, "BSS INVOKE TRACE" },
1675 { BSS_MAP_MSG_CONNECTIONLESS_INFORMATION, "CONNLESS INFO" },
Harald Welte92107df2014-06-21 23:16:20 +02001676 { BSS_MAP_MSG_RESET_IP_RSRC, "RESET IP RESOURCE" },
1677 { BSS_MAP_MSG_RESET_IP_RSRC_ACK, "RESET IP RESOURCE ACK" },
Harald Welte9b837e62011-07-11 17:43:19 +02001678
1679 { BSS_MAP_MSG_BLOCK, "BLOCK" },
1680 { BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE, "BLOCK ACK" },
1681 { BSS_MAP_MSG_UNBLOCK, "UNBLOCK" },
1682 { BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE, "UNBLOCK ACK" },
1683 { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK, "CIRC GROUP BLOCK" },
1684 { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE, "CIRC GORUP BLOCK ACK" },
1685 { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK, "CIRC GROUP UNBLOCK" },
1686 { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE, "CIRC GROUP UNBLOCK ACK" },
1687 { BSS_MAP_MSG_UNEQUIPPED_CIRCUIT, "UNEQUIPPED CIRCUIT" },
1688 { BSS_MAP_MSG_CHANGE_CIRCUIT, "CHANGE CIRCUIT" },
1689 { BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE, "CHANGE CIRCUIT ACK" },
1690
1691 { BSS_MAP_MSG_RESOURCE_RQST, "RESOURCE REQ" },
1692 { BSS_MAP_MSG_RESOURCE_INDICATION, "RESOURCE IND" },
1693 { BSS_MAP_MSG_PAGING, "PAGING" },
1694 { BSS_MAP_MSG_CIPHER_MODE_CMD, "CIPHER MODE CMD" },
1695 { BSS_MAP_MSG_CLASSMARK_UPDATE, "CLASSMARK UPDATE" },
1696 { BSS_MAP_MSG_CIPHER_MODE_COMPLETE, "CIPHER MODE COMPLETE" },
1697 { BSS_MAP_MSG_QUEUING_INDICATION, "QUEUING INDICATION" },
1698 { BSS_MAP_MSG_COMPLETE_LAYER_3, "COMPLETE LAYER 3" },
1699 { BSS_MAP_MSG_CLASSMARK_RQST, "CLASSMARK REQ" },
1700 { BSS_MAP_MSG_CIPHER_MODE_REJECT, "CIPHER MODE REJECT" },
1701 { BSS_MAP_MSG_LOAD_INDICATION, "LOAD IND" },
1702
Harald Welte92107df2014-06-21 23:16:20 +02001703 { BSS_MAP_MSG_VGCS_VBS_SETUP, "VGCS/VBS SETUP" },
1704 { BSS_MAP_MSG_VGCS_VBS_SETUP_ACK, "VGCS/VBS SETUP ACK" },
1705 { BSS_MAP_MSG_VGCS_VBS_SETUP_REFUSE, "VGCS/VBS SETUP REFUSE" },
1706 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RQST, "VGCS/VBS ASSIGN REQ" },
1707 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RESULT, "VGCS/VBS ASSIGN RES" },
1708 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_FAILURE, "VGCS/VBS ASSIGN FAIL" },
1709 { BSS_MAP_MSG_VGCS_VBS_QUEUING_INDICATION, "VGCS/VBS QUEUING IND" },
1710 { BSS_MAP_MSG_UPLINK_RQST, "UPLINK REQ" },
1711 { BSS_MAP_MSG_UPLINK_RQST_ACKNOWLEDGE, "UPLINK REQ ACK" },
1712 { BSS_MAP_MSG_UPLINK_RQST_CONFIRMATION, "UPLINK REQ CONF" },
1713 { BSS_MAP_MSG_UPLINK_RELEASE_INDICATION,"UPLINK REL IND" },
1714 { BSS_MAP_MSG_UPLINK_REJECT_CMD, "UPLINK REJ CMD" },
1715 { BSS_MAP_MSG_UPLINK_RELEASE_CMD, "UPLINK REL CMD" },
1716 { BSS_MAP_MSG_UPLINK_SEIZED_CMD, "UPLINK SEIZED CMD" },
1717 { BSS_MAP_MSG_VGCS_ADDL_INFO, "VGCS ADDL INFO" },
1718 { BSS_MAP_MSG_NOTIFICATION_DATA, "NOTIF DATA" },
1719 { BSS_MAP_MSG_UPLINK_APP_DATA, "UPLINK APP DATA" },
1720
1721 { BSS_MAP_MSG_LCLS_CONNECT_CTRL, "LCLS-CONNECT-CONTROL" },
1722 { BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK, "CLS-CONNECT-CONTROL-ACK" },
1723 { BSS_MAP_MSG_LCLS_NOTIFICATION, "LCLS-NOTIFICATION" },
Harald Welte9b837e62011-07-11 17:43:19 +02001724
1725 { 0, NULL }
1726};
1727
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001728/*! Return string name of BSSMAP Message Type */
Harald Welte9b837e62011-07-11 17:43:19 +02001729const char *gsm0808_bssmap_name(uint8_t msg_type)
1730{
1731 return get_value_string(gsm0808_msgt_names, msg_type);
1732}
1733
1734static const struct value_string gsm0808_bssap_names[] = {
1735 { BSSAP_MSG_BSS_MANAGEMENT, "MANAGEMENT" },
1736 { BSSAP_MSG_DTAP, "DTAP" },
Neels Hofmeyr90fdb082017-03-01 14:59:44 +01001737 { 0, NULL }
Harald Welte9b837e62011-07-11 17:43:19 +02001738};
1739
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001740/*! Return string name of BSSAP Message Type */
Harald Welte9b837e62011-07-11 17:43:19 +02001741const char *gsm0808_bssap_name(uint8_t msg_type)
1742{
1743 return get_value_string(gsm0808_bssap_names, msg_type);
1744}
Harald Welte96e2a002017-06-12 21:44:18 +02001745
Neels Hofmeyrffad5742018-01-12 05:34:03 +01001746const struct value_string gsm0808_speech_codec_type_names[] = {
1747 { GSM0808_SCT_FR1, "FR1" },
1748 { GSM0808_SCT_FR2, "FR2" },
1749 { GSM0808_SCT_FR3, "FR3" },
1750 { GSM0808_SCT_FR4, "FR4" },
1751 { GSM0808_SCT_FR5, "FR5" },
1752 { GSM0808_SCT_HR1, "HR1" },
1753 { GSM0808_SCT_HR3, "HR3" },
1754 { GSM0808_SCT_HR4, "HR4" },
1755 { GSM0808_SCT_HR6, "HR6" },
1756 { GSM0808_SCT_CSD, "CSD" },
1757 { 0, NULL }
1758};
1759
Philipp Maiercdd05812018-07-12 18:21:07 +02001760const struct value_string gsm0808_permitted_speech_names[] = {
1761 { GSM0808_PERM_FR1, "FR1" },
1762 { GSM0808_PERM_FR2, "FR2" },
1763 { GSM0808_PERM_FR3, "FR3" },
1764 { GSM0808_PERM_FR4, "FR4" },
1765 { GSM0808_PERM_FR5, "FR5" },
1766 { GSM0808_PERM_HR1, "HR1" },
1767 { GSM0808_PERM_HR2, "HR2" },
1768 { GSM0808_PERM_HR3, "HR3" },
1769 { GSM0808_PERM_HR4, "HR4" },
1770 { GSM0808_PERM_HR6, "HR6" },
1771 { 0, NULL }
1772};
1773
Pau Espin Pedrolf2cda622018-07-06 17:16:41 +02001774const struct value_string gsm0808_chosen_enc_alg_names[] = {
1775 { GSM0808_ALG_ID_A5_0, "A5/0" },
1776 { GSM0808_ALG_ID_A5_1, "A5/1" },
1777 { GSM0808_ALG_ID_A5_2, "A5/2" },
1778 { GSM0808_ALG_ID_A5_3, "A5/3" },
1779 { GSM0808_ALG_ID_A5_4, "A5/4" },
1780 { GSM0808_ALG_ID_A5_5, "A5/5" },
1781 { GSM0808_ALG_ID_A5_6, "A5/6" },
1782 { GSM0808_ALG_ID_A5_7, "A5/7" },
1783 { 0, NULL }
1784};
1785
Philipp Maierdbb76592018-03-29 12:55:26 +02001786static const struct value_string gsm0808_cause_names[] = {
1787 { GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, "RADIO INTERFACE MESSAGE FAILURE" },
1788 { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, "RADIO INTERFACE FAILURE" },
1789 { GSM0808_CAUSE_UPLINK_QUALITY, "UPLINK QUALITY" },
1790 { GSM0808_CAUSE_UPLINK_STRENGTH, "UPLINK STRENGTH" },
1791 { GSM0808_CAUSE_DOWNLINK_QUALITY, "DOWNLINK QUALITY" },
1792 { GSM0808_CAUSE_DOWNLINK_STRENGTH, "DOWNLINK STRENGTH" },
1793 { GSM0808_CAUSE_DISTANCE, "DISTANCE" },
1794 { GSM0808_CAUSE_O_AND_M_INTERVENTION, "O AND M INTERVENTION" },
1795 { GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION, "RESPONSE TO MSC INVOCATION" },
1796 { GSM0808_CAUSE_CALL_CONTROL, "CALL CONTROL" },
1797 { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION, "RADIO INTERFACE FAILURE REVERSION" },
1798 { GSM0808_CAUSE_HANDOVER_SUCCESSFUL, "HANDOVER SUCCESSFUL" },
1799 { GSM0808_CAUSE_BETTER_CELL, "BETTER CELL" },
1800 { GSM0808_CAUSE_DIRECTED_RETRY, "DIRECTED RETRY" },
1801 { GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL, "JOINED GROUP CALL CHANNEL" },
1802 { GSM0808_CAUSE_TRAFFIC, "TRAFFIC" },
1803 { GSM0808_CAUSE_REDUCE_LOAD_IN_SERVING_CELL, "REDUCE LOAD IN SERVING CELL" },
1804 { GSM0808_CAUSE_TRAFFIC_LOAD_IN_TGT_HIGHER_THAN_IN_SRC_CELL, "TRAFFIC LOAD IN TGT HIGHER THAN IN SRC CELL" },
1805 { GSM0808_CAUSE_RELOCATION_TRIGGERED, "RELOCATION TRIGGERED" },
Thorsten Alteholz0062a5f2018-05-15 15:28:55 +02001806 { GSM0808_CAUSE_REQUESTED_OPT_NOT_AUTHORISED, "REQUESTED OPT NOT AUTHORISED" },
Philipp Maierdbb76592018-03-29 12:55:26 +02001807 { GSM0808_CAUSE_ALT_CHAN_CONFIG_REQUESTED, "ALT CHAN CONFIG REQUESTED" },
1808 { GSM0808_CAUSE_RESP_TO_INT_HO_ENQ_MSG, "RESP TO INT HO ENQ MSG" },
1809 { GSM0808_CAUSE_INT_HO_ENQUIRY_REJECT, "INT HO ENQUIRY REJECT" },
1810 { GSM0808_CAUSE_REDUNDANCY_LEVEL_NOT_ADEQUATE, "REDUNDANCY LEVEL NOT ADEQUATE" },
1811 { GSM0808_CAUSE_EQUIPMENT_FAILURE, "EQUIPMENT FAILURE" },
1812 { GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, "NO RADIO RESOURCE AVAILABLE" },
1813 { GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE, "RQSTED TERRESTRIAL RESOURCE UNAVAILABLE" },
1814 { GSM0808_CAUSE_CCCH_OVERLOAD, "CCCH OVERLOAD" },
1815 { GSM0808_CAUSE_PROCESSOR_OVERLOAD, "PROCESSOR OVERLOAD" },
1816 { GSM0808_CAUSE_BSS_NOT_EQUIPPED, "BSS NOT EQUIPPED" },
1817 { GSM0808_CAUSE_MS_NOT_EQUIPPED, "MS NOT EQUIPPED" },
1818 { GSM0808_CAUSE_INVALID_CELL, "INVALID CELL" },
1819 { GSM0808_CAUSE_TRAFFIC_LOAD, "TRAFFIC LOAD" },
1820 { GSM0808_CAUSE_PREEMPTION, "PREEMPTION" },
1821 { GSM0808_CAUSE_DTM_HO_SGSN_FAILURE, "DTM HO SGSN FAILURE" },
1822 { GSM0808_CAUSE_DTM_HO_PS_ALLOC_FAILURE, "DTM HO PS ALLOC FAILURE" },
1823 { GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE, "RQSTED TRANSCODING RATE ADAPTION UNAVAILABLE" },
1824 { GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH, "CIRCUIT POOL MISMATCH" },
1825 { GSM0808_CAUSE_SWITCH_CIRCUIT_POOL, "SWITCH CIRCUIT POOL" },
1826 { GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE, "RQSTED SPEECH VERSION UNAVAILABLE" },
1827 { GSM0808_CAUSE_LSA_NOT_ALLOWED, "LSA NOT ALLOWED" },
1828 { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL, "REQ CODEC TYPE OR CONFIG UNAVAIL" },
1829 { GSM0808_CAUSE_REQ_A_IF_TYPE_UNAVAIL, "REQ A IF TYPE UNAVAIL" },
1830 { GSM0808_CAUSE_INVALID_CSG_CELL, "INVALID CSG CELL" },
1831 { GSM0808_CAUSE_REQ_REDUND_LEVEL_NOT_AVAIL, "REQ REDUND LEVEL NOT AVAIL" },
1832 { GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED, "CIPHERING ALGORITHM NOT SUPPORTED" },
1833 { GSM0808_CAUSE_GERAN_IU_MODE_FAILURE, "GERAN IU MODE FAILURE" },
1834 { GSM0808_CAUSE_INC_RELOC_NOT_SUPP_DT_PUESBINE_FEATURE, "INC RELOC NOT SUPP DT PUESBINE FEATURE" },
1835 { GSM0808_CAUSE_ACCESS_RESTRICTED_DUE_TO_SHARED_NETWORKS, "ACCESS RESTRICTED DUE TO SHARED NETWORKS" },
1836 { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_NOT_SUPP, "REQ CODEC TYPE OR CONFIG NOT SUPP" },
1837 { GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP, "REQ A IF TYPE NOT SUPP" },
1838 { GSM0808_CAUSE_REQ_REDUND_LVL_NOT_SUPP, "REQ REDUND LVL NOT SUPP" },
1839 { GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED, "TERRESTRIAL CIRCUIT ALREADY ALLOCATED" },
1840 { GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS, "INVALID MESSAGE CONTENTS" },
1841 { GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING, "INFORMATION ELEMENT OR FIELD MISSING" },
1842 { GSM0808_CAUSE_INCORRECT_VALUE, "INCORRECT VALUE" },
1843 { GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE, "UNKNOWN MESSAGE TYPE" },
1844 { GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT, "UNKNOWN INFORMATION ELEMENT" },
1845 { GSM0808_CAUSE_DTM_HO_INVALID_PS_IND, "DTM HO INVALID PS IND" },
1846 { GSM0808_CAUSE_CALL_ID_ALREADY_ALLOC, "CALL ID ALREADY ALLOC" },
1847 { GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC, "PROTOCOL ERROR BETWEEN BSS AND MSC" },
Thorsten Alteholz0062a5f2018-05-15 15:28:55 +02001848 { GSM0808_CAUSE_VGCS_VBS_CALL_NON_EXISTENT, "VGCS VBS CALL NON EXISTENT" },
Philipp Maierdbb76592018-03-29 12:55:26 +02001849 { GSM0808_CAUSE_DTM_HO_TIMER_EXPIRY, "DTM HO TIMER EXPIRY" },
1850 { 0, NULL }
1851};
1852
Maxaa934632018-11-07 13:16:54 +01001853static const struct value_string gsm0808_cause_class_names[] = {
1854 { GSM0808_CAUSE_CLASS_NORM0, "Normal event" },
1855 { GSM0808_CAUSE_CLASS_NORM1, "Normal event" },
1856 { GSM0808_CAUSE_CLASS_RES_UNAVAIL, "Resource unavailable" },
1857 { GSM0808_CAUSE_CLASS_SRV_OPT_NA, "Service or option not available" },
1858 { GSM0808_CAUSE_CLASS_SRV_OPT_NIMPL, "Service or option not implemented" },
1859 { GSM0808_CAUSE_CLASS_INVAL, "Invalid message" },
1860 { GSM0808_CAUSE_CLASS_PERR, "Protocol error" },
1861 { GSM0808_CAUSE_CLASS_INTW, "Interworking" },
1862 { 0, NULL }
1863};
1864
1865/*! Return string name of BSSMAP Cause Class name */
1866const char *gsm0808_cause_class_name(enum gsm0808_cause_class class)
1867{
1868 return get_value_string(gsm0808_cause_class_names, class);
1869}
1870
Philipp Maierdbb76592018-03-29 12:55:26 +02001871/*! Return string name of BSSMAP Cause name */
Maxaa934632018-11-07 13:16:54 +01001872const char *gsm0808_cause_name(enum gsm0808_cause cause)
Philipp Maierdbb76592018-03-29 12:55:26 +02001873{
1874 return get_value_string(gsm0808_cause_names, cause);
1875}
1876
Alexander Chemerisfdfe25b2020-05-12 23:21:56 +03001877enum gsm0808_cause gsm0808_get_cause(const struct tlv_parsed *tp)
1878{
1879 const uint8_t *buf = TLVP_VAL_MINLEN(tp, GSM0808_IE_CAUSE, 1);
1880
1881 if (!buf)
1882 return -EBADMSG;
1883
1884 if (TLVP_LEN(tp, GSM0808_IE_CAUSE) > 1) {
1885 if (!gsm0808_cause_ext(buf[0]))
1886 return -EINVAL;
1887 return buf[1];
1888 }
1889
1890 return buf[0];
1891}
1892
Alexander Chemeris22630e62020-05-13 00:44:04 +03001893const char *gsm0808_diagnostics_octet_location_str(uint8_t pointer)
1894{
1895 switch (pointer) {
1896 case 0:
1897 return "Error location not determined";
1898 case 1:
1899 return "The first octet of the message received (i.e. the message type) was found erroneous (unknown)";
1900 case 0xfd:
1901 return "The first octet of the BSSAP header (Discrimination) was found erroneous";
1902 case 0xfe:
1903 return "(DTAP only) The DLCI (second) octet of the BSSAP header was found erroneous";
1904 case 0xff:
1905 return "The last octet of the BSSAP header (length indicator) was found erroneous";
1906 default:
1907 snprintf(str_buff, sizeof(str_buff), "The %d octet of the message received was found erroneous", pointer);
1908 return str_buff;
1909 }
1910}
1911
1912const char *gsm0808_diagnostics_bit_location_str(uint8_t bit_pointer)
1913{
1914 if (bit_pointer == 0) {
1915 return "No particular part of the octet is indicated";
1916 } else if (bit_pointer > 8) {
1917 return "Reserved value";
1918 }
1919
1920 snprintf(str_buff, sizeof(str_buff),
1921 "An error was provoked by the field whose most significant bit is in bit position %d",
1922 bit_pointer);
1923 return str_buff;
1924}
1925
Harald Welteebd362d2018-06-02 14:11:19 +02001926const struct value_string gsm0808_lcls_config_names[] = {
1927 { GSM0808_LCLS_CFG_BOTH_WAY, "Connect both-way" },
1928 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL,
1929 "Connect both-way, bi-cast UL to CN" },
1930 { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL,
1931 "Connect both-way, send access DL from CN" },
1932 { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL_BLOCK_LOCAL_DL,
1933 "Connect both-way, send access DL from CN, block local DL" },
1934 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL,
1935 "Connect both-way, bi-cast UL to CN, send access DL from CN" },
1936 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL_BLOCK_LOCAL_DL,
1937 "Connect both-way, bi-cast UL to CN, send access DL from CN, block local DL" },
Max961db7c2018-11-08 11:40:23 +01001938 { GSM0808_LCLS_CFG_NA, "Not available" },
Harald Welteebd362d2018-06-02 14:11:19 +02001939 { 0, NULL }
1940};
1941
1942const struct value_string gsm0808_lcls_control_names[] = {
1943 { GSM0808_LCLS_CSC_CONNECT, "Connect" },
1944 { GSM0808_LCLS_CSC_DO_NOT_CONNECT, "Do not connect" },
1945 { GSM0808_LCLS_CSC_RELEASE_LCLS, "Release LCLS" },
1946 { GSM0808_LCLS_CSC_BICAST_UL_AT_HANDOVER, "Bi-cast UL at Handover" },
1947 { GSM0808_LCLS_CSC_BICAST_UL_AND_RECV_DL_AT_HANDOVER, "Bi-cast UL and receive DL at Handover" },
Max961db7c2018-11-08 11:40:23 +01001948 { GSM0808_LCLS_CSC_NA, "Not available" },
Harald Welteebd362d2018-06-02 14:11:19 +02001949 { 0, NULL }
1950};
1951
1952const struct value_string gsm0808_lcls_status_names[] = {
1953 { GSM0808_LCLS_STS_NOT_YET_LS, "Call not yet locally switched" },
1954 { GSM0808_LCLS_STS_NOT_POSSIBLE_LS, "Call not possible to be locally switched" },
1955 { GSM0808_LCLS_STS_NO_LONGER_LS, "Call is no longer locally switched" },
1956 { GSM0808_LCLS_STS_REQ_LCLS_NOT_SUPP, "Requested LCLS configuration is not supported" },
1957 { GSM0808_LCLS_STS_LOCALLY_SWITCHED, "Call is locally switched with requested LCLS config" },
Max961db7c2018-11-08 11:40:23 +01001958 { GSM0808_LCLS_STS_NA, "Not available" },
Harald Welteebd362d2018-06-02 14:11:19 +02001959 { 0, NULL }
1960};
1961
Harald Welte96e2a002017-06-12 21:44:18 +02001962/*! @} */