blob: 9a9f70ee6d16f30478f34986998d12eb40d1f651 [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
Harald Welte95871da2017-05-15 12:11:36 +020024#include <osmocom/core/byteswap.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010025#include <osmocom/gsm/gsm0808.h>
Philipp Maierfa896ab2017-03-27 16:55:32 +020026#include <osmocom/gsm/gsm0808_utils.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010027#include <osmocom/gsm/protocol/gsm_08_08.h>
28#include <osmocom/gsm/gsm48.h>
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020029
Harald Welte96e2a002017-06-12 21:44:18 +020030/*! \addtogroup gsm0808
31 * @{
Harald Welte37b61652017-10-16 18:46:03 +020032 * \file gsm0808.c
33 * Helper functions regarding the TS 08.08 / 48.008 A interface, primarily
34 * message generation/encoding.
Harald Welte96e2a002017-06-12 21:44:18 +020035 */
36
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020037#define BSSMAP_MSG_SIZE 512
38#define BSSMAP_MSG_HEADROOM 128
39
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010040/*! Create "Complete L3 Info" for AoIP, legacy implementation.
41 * Instead use gsm0808_create_layer3_aoip2(), which is capable of three-digit MNC with leading zeros.
Harald Welte96e2a002017-06-12 21:44:18 +020042 * \param[in] msg_l3 msgb containing Layer 3 Message
43 * \param[in] nc Mobile Network Code
44 * \param[in] cc Mobile Country Code
45 * \param[in] lac Location Area Code
46 * \param[in] _ci Cell Identity
47 * \param[in] scl Speech Codec List
48 * \returns callee-allocated msgb with Complete L3 Info message */
Philipp Maierfa896ab2017-03-27 16:55:32 +020049struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc,
50 uint16_t cc, int lac, uint16_t _ci,
51 const struct gsm0808_speech_codec_list
52 *scl)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020053{
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010054 struct osmo_cell_global_id cgi = {
55 .lai = {
56 .plmn = {
57 .mcc = cc,
58 .mnc = nc,
59 },
60 .lac = lac,
61 },
62 .cell_identity = _ci,
63 };
64 return gsm0808_create_layer3_2(msg_l3, &cgi, scl);
65}
66
67/*! Create "Complete L3 Info" for AoIP.
68 * \param[in] msg_l3 msgb containing Layer 3 Message -- not modified by this call.
69 * \param[in] cell MCC, MNC, LAC, CI to identify the cell.
70 * \param[in] scl Speech Codec List, optional.
71 * \returns newly allocated msgb with Complete L3 Info message */
72struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell,
73 const struct gsm0808_speech_codec_list *scl)
74{
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020075 struct msgb* msg;
Harald Welte65c2d362012-01-21 14:26:01 +010076 struct {
77 uint8_t ident;
78 struct gsm48_loc_area_id lai;
79 uint16_t ci;
80 } __attribute__ ((packed)) lai_ci;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020081
82 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
83 "bssmap cmpl l3");
84 if (!msg)
85 return NULL;
86
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020087 /* create layer 3 header */
Harald Welte65c2d362012-01-21 14:26:01 +010088 msgb_v_put(msg, BSS_MAP_MSG_COMPLETE_LAYER_3);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020089
90 /* create the cell header */
Harald Welte65c2d362012-01-21 14:26:01 +010091 lai_ci.ident = CELL_IDENT_WHOLE_GLOBAL;
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010092 gsm48_generate_lai2(&lai_ci.lai, &cell->lai);
93 lai_ci.ci = osmo_htons(cell->cell_identity);
Harald Welte65c2d362012-01-21 14:26:01 +010094 msgb_tlv_put(msg, GSM0808_IE_CELL_IDENTIFIER, sizeof(lai_ci),
95 (uint8_t *) &lai_ci);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020096
97 /* copy the layer3 data */
Harald Welte65c2d362012-01-21 14:26:01 +010098 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION,
99 msgb_l3len(msg_l3), msg_l3->l3h);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200100
Philipp Maierfa896ab2017-03-27 16:55:32 +0200101 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
102 if (scl)
103 gsm0808_enc_speech_codec_list(msg, scl);
104
Harald Welte65c2d362012-01-21 14:26:01 +0100105 /* push the bssmap header */
106 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200107
108 return msg;
109}
110
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100111/*! Create "Complete L3 Info" for A, legacy implementation.
112 * Instead use gsm0808_create_layer3_2() with the scl parameter passed as NULL,
113 * which is capable of three-digit MNC with leading zeros.
Harald Welte96e2a002017-06-12 21:44:18 +0200114 * \param[in] msg_l3 msgb containing Layer 3 Message
115 * \param[in] nc Mobile Network Code
116 * \param[in] cc Mobile Country Code
117 * \param[in] lac Location Area Code
118 * \param[in] _ci Cell Identity
119 * \returns callee-allocated msgb with Complete L3 Info message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200120struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc,
121 uint16_t cc, int lac, uint16_t _ci)
122{
Neels Hofmeyr4eeb8082018-03-23 01:47:14 +0100123 struct osmo_cell_global_id cgi = {
124 .lai = {
125 .plmn = {
126 .mcc = cc,
127 .mnc = nc,
128 },
129 .lac = lac,
130 },
131 .cell_identity = _ci,
132 };
133 return gsm0808_create_layer3_2(msg_l3, &cgi, NULL);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200134}
135
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200136/*! Create BSSMAP RESET message
Harald Welte96e2a002017-06-12 21:44:18 +0200137 * \returns callee-allocated msgb with BSSMAP Reset message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200138struct msgb *gsm0808_create_reset(void)
139{
Harald Welte65c2d362012-01-21 14:26:01 +0100140 uint8_t cause = GSM0808_CAUSE_EQUIPMENT_FAILURE;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200141 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
142 "bssmap: reset");
143 if (!msg)
144 return NULL;
145
Harald Welte65c2d362012-01-21 14:26:01 +0100146 msgb_v_put(msg, BSS_MAP_MSG_RESET);
147 msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &cause);
148 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
149
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200150 return msg;
151}
152
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200153/*! Create BSSMAP RESET ACK message
Harald Welte96e2a002017-06-12 21:44:18 +0200154 * \returns callee-allocated msgb with BSSMAP Reset ACK message */
Harald Weltea62fe312013-06-19 15:14:37 +0200155struct msgb *gsm0808_create_reset_ack(void)
156{
157 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
158 "bssmap: reset ack");
159 if (!msg)
160 return NULL;
161
162 msgb_v_put(msg, BSS_MAP_MSG_RESET_ACKNOWLEDGE);
163 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
164
165 return msg;
166}
167
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200168/*! Create BSSMAP Clear Complete message
Harald Welte96e2a002017-06-12 21:44:18 +0200169 * \returns callee-allocated msgb with BSSMAP Clear Complete message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200170struct msgb *gsm0808_create_clear_complete(void)
171{
172 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
173 "bssmap: clear complete");
Harald Welte65c2d362012-01-21 14:26:01 +0100174 uint8_t val = BSS_MAP_MSG_CLEAR_COMPLETE;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200175 if (!msg)
176 return NULL;
177
Harald Welte65c2d362012-01-21 14:26:01 +0100178 msg->l3h = msg->data;
179 msgb_tlv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 1, &val);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200180
181 return msg;
182}
183
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200184/*! Create BSSMAP Clear Command message
Harald Welte96e2a002017-06-12 21:44:18 +0200185 * \param[in] reason TS 08.08 cause value
186 * \returns callee-allocated msgb with BSSMAP Clear Command message */
Holger Hans Peter Freythera3f05d82010-10-27 11:49:24 +0200187struct msgb *gsm0808_create_clear_command(uint8_t reason)
188{
189 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
190 "bssmap: clear command");
191 if (!msg)
192 return NULL;
193
Holger Hans Peter Freytheraeebe392010-10-27 12:36:05 +0200194 msg->l3h = msgb_tv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 4);
195 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD);
196 msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &reason);
Harald Welte65c2d362012-01-21 14:26:01 +0100197
Holger Hans Peter Freythera3f05d82010-10-27 11:49:24 +0200198 return msg;
199}
200
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200201/*! Create BSSMAP Cipher Mode Command message
Harald Welte96e2a002017-06-12 21:44:18 +0200202 * \param[in] ei Mandatory Encryption Information
203 * \param[in] cipher_response_mode optional 1-byte Cipher Response Mode
204 * \returns callee-allocated msgb with BSSMAP Cipher Mode Command message */
Philipp Maierb478dd32017-03-29 15:50:05 +0200205struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
206 const uint8_t *cipher_response_mode)
207{
208 /* See also: 3GPP TS 48.008 3.2.1.30 CIPHER MODE COMMAND */
209 struct msgb *msg;
210
211 /* Mandatory emelent! */
212 OSMO_ASSERT(ei);
213
214 msg =
215 msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
216 "cipher-mode-command");
217 if (!msg)
218 return NULL;
219
220 /* Message Type 3.2.2.1 */
221 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_CMD);
222
223 /* Encryption Information 3.2.2.10 */
224 gsm0808_enc_encrypt_info(msg, ei);
225
226 /* Cipher Response Mode 3.2.2.34 */
227 if (cipher_response_mode)
228 msgb_tv_put(msg, GSM0808_IE_CIPHER_RESPONSE_MODE,
229 *cipher_response_mode);
230
231 /* pre-pend the header */
232 msg->l3h =
233 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
234
235 return msg;
236}
237
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200238/*! Create BSSMAP Cipher Mode Complete message
Harald Welte96e2a002017-06-12 21:44:18 +0200239 * \param[in] layer3 L3 Message to be included
240 * \param[in] alg_id Chosen Encrpytion Algorithm
241 * \returns callee-allocated msgb with BSSMAP Cipher Mode Complete message */
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200242struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id)
243{
244 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
245 "cipher-complete");
246 if (!msg)
247 return NULL;
248
249 /* send response with BSS override for A5/1... cheating */
Harald Welte65c2d362012-01-21 14:26:01 +0100250 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_COMPLETE);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200251
252 /* include layer3 in case we have at least two octets */
253 if (layer3 && msgb_l3len(layer3) > 2) {
Harald Welte65c2d362012-01-21 14:26:01 +0100254 msg->l4h = msgb_tlv_put(msg, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS,
255 msgb_l3len(layer3), layer3->l3h);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200256 }
257
258 /* and the optional BSS message */
Harald Welte65c2d362012-01-21 14:26:01 +0100259 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, alg_id);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200260
Harald Welte65c2d362012-01-21 14:26:01 +0100261 /* pre-pend the header */
262 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
263
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200264 return msg;
265}
266
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200267/*! Create BSSMAP Cipher Mode Reject message
Harald Welte96e2a002017-06-12 21:44:18 +0200268 * \param[in] reason TS 08.08 cause value
269 * \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200270struct msgb *gsm0808_create_cipher_reject(uint8_t cause)
271{
272 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
273 "bssmap: clear complete");
274 if (!msg)
275 return NULL;
276
Harald Welte62e40852017-12-17 20:50:34 +0100277 msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT);
278 msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &cause);
Harald Welte65c2d362012-01-21 14:26:01 +0100279
280 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200281
282 return msg;
283}
284
Harald Welte64e807c2018-05-29 21:00:56 +0200285/*! Create BSSMAP LCLS CONNECT CONTROL message (TS 48.008 3.2.1.91).
286 * \param[in] config LCLS Configuration
287 * \param[in] control LCLS Connection Status Control
288 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
289struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config *config,
290 enum gsm0808_lcls_control *control)
291{
292 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
293 "bssmap: LCLS CONN CTRL");
294 if (!msg)
295 return NULL;
296
297 msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL);
298 if (config)
299 msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, *config);
300 if (control)
301 msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, *control);
302 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
303
304 return msg;
305}
306
307/*! Create BSSMAP LCLS CONNECT CONTROL ACK message (TS 48.008 3.2.1.92).
308 * \param[in] status LCLS BSS Status
309 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
310struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status)
311{
312 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
313 "bssmap: LCLS CONN CTRL ACK");
314 if (!msg)
315 return NULL;
316
317 msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK);
318 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status);
319 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
320
321 return msg;
322}
323
324/*! Create BSSMAP LCLS NOTIFICATION message (TS 48.008 3.2.1.93).
325 * \param[in] status LCLS BSS Status
326 * \param[in] break_req Include the LCLS BREAK REQ IE (true) or not (false)
327 * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */
328struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req)
329{
330 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
331 "bssmap: LCLS NOTIFICATION");
332 if (!msg)
333 return NULL;
334
335 msgb_v_put(msg, BSS_MAP_MSG_LCLS_NOTIFICATION);
336 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status);
337 if (break_req)
338 msgb_v_put(msg, GSM0808_IE_LCLS_BREAK_REQ);
339 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
340
341 return msg;
342}
343
Neels Hofmeyr2c79d552018-09-13 05:36:32 +0200344/*! Create BSSMAP Classmark Request message
345 * \returns callee-allocated msgb with BSSMAP Classmark Request message */
346struct msgb *gsm0808_create_classmark_request()
347{
348 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
349 "classmark-request");
350 if (!msg)
351 return NULL;
352
353 msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_RQST);
354 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
355 return msg;
356}
Harald Welte64e807c2018-05-29 21:00:56 +0200357
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200358/*! Create BSSMAP Classmark Update message
Harald Welte96e2a002017-06-12 21:44:18 +0200359 * \param[in] cm2 Classmark 2
360 * \param[in] cm2_len length (in octets) of \a cm2
361 * \param[in] cm3 Classmark 3
362 * \param[in] cm3_len length (in octets) of \a cm3
363 * \returns callee-allocated msgb with BSSMAP Classmark Update message */
Harald Welte07b625d2012-01-23 10:02:58 +0100364struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
365 const uint8_t *cm3, uint8_t cm3_len)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200366{
367 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
368 "classmark-update");
369 if (!msg)
370 return NULL;
371
Harald Welte65c2d362012-01-21 14:26:01 +0100372 msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_UPDATE);
Harald Welte07b625d2012-01-23 10:02:58 +0100373 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T2, cm2_len, cm2);
374 if (cm3)
375 msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T3,
376 cm3_len, cm3);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200377
Harald Welte65c2d362012-01-21 14:26:01 +0100378 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
379
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200380 return msg;
381}
382
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200383/*! Create BSSMAP SAPI N Reject message
Harald Welte96e2a002017-06-12 21:44:18 +0200384 * \param[in] link_id Link Identifier
385 * \returns callee-allocated msgb with BSSMAP SAPI N Reject message */
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200386struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
387{
388 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
389 "bssmap: sapi 'n' reject");
390 if (!msg)
391 return NULL;
392
Harald Welte65c2d362012-01-21 14:26:01 +0100393 msgb_v_put(msg, BSS_MAP_MSG_SAPI_N_REJECT);
394 msgb_v_put(msg, link_id);
395 msgb_v_put(msg, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
396
397 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200398
399 return msg;
400}
401
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200402/*! Create BSSMAP Assignment Request message
Harald Welte96e2a002017-06-12 21:44:18 +0200403 * \param[in] ct Channel Type
404 * \param[in] cic Circuit Identity Code (Classic A only)
405 * \param[in] ss Socket Address of MSC-side RTP socket (AoIP only)
406 * \param[in] scl Speech Codec List (AoIP only)
407 * \param[in] ci Call Identifier (Optional, LCLS)
408 * \returns callee-allocated msgb with BSSMAP Assignment Request message */
Philipp Maierc6144a22017-03-29 17:53:43 +0200409struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct,
410 const uint16_t *cic,
411 const struct sockaddr_storage *ss,
412 const struct gsm0808_speech_codec_list *scl,
413 const uint32_t *ci)
414{
415 /* See also: 3GPP TS 48.008 3.2.1.1 ASSIGNMENT REQUEST */
416 struct msgb *msg;
417 uint16_t cic_sw;
418 uint32_t ci_sw;
419
420 /* Mandatory emelent! */
421 OSMO_ASSERT(ct);
422
423 msg =
424 msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
425 "bssmap: ass req");
426 if (!msg)
427 return NULL;
428
429 /* Message Type 3.2.2.1 */
430 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_RQST);
431
432 /* Channel Type 3.2.2.11 */
433 gsm0808_enc_channel_type(msg, ct);
434
435 /* Circuit Identity Code 3.2.2.2 */
436 if (cic) {
Harald Welte95871da2017-05-15 12:11:36 +0200437 cic_sw = osmo_htons(*cic);
Philipp Maierc6144a22017-03-29 17:53:43 +0200438 msgb_tv_fixed_put(msg, GSM0808_IE_CIRCUIT_IDENTITY_CODE,
439 sizeof(cic_sw), (uint8_t *) & cic_sw);
440 }
441
442 /* AoIP: AoIP Transport Layer Address (MGW) 3.2.2.102 */
443 if (ss) {
444 gsm0808_enc_aoip_trasp_addr(msg, ss);
445 }
446
447 /* AoIP: Codec List (MSC Preferred) 3.2.2.103 */
448 if (scl)
449 gsm0808_enc_speech_codec_list(msg, scl);
450
451 /* AoIP: Call Identifier 3.2.2.105 */
452 if (ci) {
Harald Welte95871da2017-05-15 12:11:36 +0200453 ci_sw = osmo_htonl(*ci);
Philipp Maierc6144a22017-03-29 17:53:43 +0200454 msgb_tv_fixed_put(msg, GSM0808_IE_CALL_ID, sizeof(ci_sw),
455 (uint8_t *) & ci_sw);
456 }
457
458 /* push the bssmap header */
459 msg->l3h =
460 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
461
462 return msg;
463}
464
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200465/*! Create BSSMAP Assignment Completed message
Harald Welte96e2a002017-06-12 21:44:18 +0200466 * \param[in] rr_cause GSM 04.08 RR Cause value
467 * \param[in] chosen_channel Chosen Channel
468 * \param[in] encr_alg_id Encryption Algorithm ID
469 * \param[in] speech_mode Speech Mode
470 * \param[in] ss Socket Address of BSS-side RTP socket
471 * \param[in] sc Speech Codec (current)
472 * \param[in] scl Speech Codec List (permitted)
473 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200474struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel,
475 uint8_t encr_alg_id, uint8_t speech_mode,
476 const struct sockaddr_storage *ss,
477 const struct gsm0808_speech_codec *sc,
478 const struct gsm0808_speech_codec_list
479 *scl)
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200480{
Harald Welte65c2d362012-01-21 14:26:01 +0100481 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
482 "bssmap: ass compl");
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200483 if (!msg)
484 return NULL;
485
Harald Welte65c2d362012-01-21 14:26:01 +0100486 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_COMPLETE);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200487
488 /* write 3.2.2.22 */
Harald Welte65c2d362012-01-21 14:26:01 +0100489 msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, rr_cause);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200490
491 /* write cirtcuit identity code 3.2.2.2 */
492 /* write cell identifier 3.2.2.17 */
493 /* write chosen channel 3.2.2.33 when BTS picked it */
Harald Welte65c2d362012-01-21 14:26:01 +0100494 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, chosen_channel);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200495
496 /* write chosen encryption algorithm 3.2.2.44 */
Harald Welte65c2d362012-01-21 14:26:01 +0100497 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, encr_alg_id);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200498
499 /* write circuit pool 3.2.2.45 */
500 /* write speech version chosen: 3.2.2.51 when BTS picked it */
Harald Welte65c2d362012-01-21 14:26:01 +0100501 if (speech_mode != 0)
502 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, speech_mode);
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200503
Philipp Maierfa896ab2017-03-27 16:55:32 +0200504 /* AoIP: AoIP Transport Layer Address (BSS) 3.2.2.102 */
505 if (ss)
506 gsm0808_enc_aoip_trasp_addr(msg, ss);
507
508 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
509 if (sc)
510 gsm0808_enc_speech_codec(msg, sc);
511
512 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
513 if (scl)
514 gsm0808_enc_speech_codec_list(msg, scl);
515
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200516 /* write LSA identifier 3.2.2.15 */
517
Harald Welte65c2d362012-01-21 14:26:01 +0100518 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200519
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200520 return msg;
521}
522
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200523/*! Create BSSMAP Assignment Completed message
Harald Welte96e2a002017-06-12 21:44:18 +0200524 * \param[in] rr_cause GSM 04.08 RR Cause value
525 * \param[in] chosen_channel Chosen Channel
526 * \param[in] encr_alg_id Encryption Algorithm ID
527 * \param[in] speech_mode Speech Mode
528 * \returns callee-allocated msgb with BSSMAP Assignment Complete message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200529struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
530 uint8_t chosen_channel,
531 uint8_t encr_alg_id,
532 uint8_t speech_mode)
533{
534 return gsm0808_create_ass_compl(rr_cause, chosen_channel, encr_alg_id,
535 speech_mode, NULL, NULL, NULL);
536}
537
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200538/*! Create BSSMAP Assignment Failure message
Harald Welte96e2a002017-06-12 21:44:18 +0200539 * \param[in] cause BSSMAP Cause value
540 * \param[in] rr_cause GSM 04.08 RR Cause value
541 * \param[in] scl Optional Speech Cdec List (AoIP)
542 * \returns callee-allocated msgb with BSSMAP Assignment Failure message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200543struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause,
544 const struct gsm0808_speech_codec_list
545 *scl)
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200546{
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200547 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
548 "bssmap: ass fail");
549 if (!msg)
550 return NULL;
551
Harald Welte65c2d362012-01-21 14:26:01 +0100552 msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_FAILURE);
553 msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &cause);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200554
555 /* RR cause 3.2.2.22 */
Harald Welte65c2d362012-01-21 14:26:01 +0100556 if (rr_cause)
557 msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, *rr_cause);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200558
559 /* Circuit pool 3.22.45 */
560 /* Circuit pool list 3.2.2.46 */
561
Philipp Maierfa896ab2017-03-27 16:55:32 +0200562 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
563 if (scl)
564 gsm0808_enc_speech_codec_list(msg, scl);
565
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200566 /* update the size */
Harald Welte65c2d362012-01-21 14:26:01 +0100567 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
568
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200569 return msg;
570}
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +0200571
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200572/*! Create BSSMAP Assignment Failure message
Harald Welte96e2a002017-06-12 21:44:18 +0200573 * \param[in] cause BSSMAP Cause value
574 * \param[in] rr_cause GSM 04.08 RR Cause value
575 * \returns callee-allocated msgb with BSSMAP Assignment Failure message */
Philipp Maierfa896ab2017-03-27 16:55:32 +0200576struct msgb *gsm0808_create_assignment_failure(uint8_t cause,
577 uint8_t *rr_cause)
578{
579 return gsm0808_create_ass_fail(cause, rr_cause, NULL);
580}
581
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200582/*! Create BSSMAP Clear Request message
Harald Welte96e2a002017-06-12 21:44:18 +0200583 * \param[in] cause BSSMAP Cause value
584 * \returns callee-allocated msgb with BSSMAP Clear Request message */
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100585struct msgb *gsm0808_create_clear_rqst(uint8_t cause)
586{
587 struct msgb *msg;
588
589 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
590 "bssmap: clear rqst");
591 if (!msg)
592 return NULL;
593
Harald Welte65c2d362012-01-21 14:26:01 +0100594 msgb_v_put(msg, BSS_MAP_MSG_CLEAR_RQST);
595 msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &cause);
596 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100597
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100598 return msg;
599}
600
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200601/*! Create BSSMAP PAGING message
Harald Welte96e2a002017-06-12 21:44:18 +0200602 * \param[in] imsi Mandatory paged IMSI in string representation
603 * \param[in] tmsi Optional paged TMSI
Stefan Sperling3953f412018-08-28 15:06:30 +0200604 * \param[in] cil Mandatory Cell Identity List (where to page)
Harald Welte96e2a002017-06-12 21:44:18 +0200605 * \param[in] chan_needed Channel Type needed
606 * \returns callee-allocated msgb with BSSMAP PAGING message */
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100607struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
608 const struct gsm0808_cell_id_list2 *cil,
609 const uint8_t *chan_needed)
Philipp Maier3d48ec02017-03-29 17:37:55 +0200610{
611 struct msgb *msg;
612 uint8_t mid_buf[GSM48_MI_SIZE + 2];
613 int mid_len;
614 uint32_t tmsi_sw;
615
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100616 /* Mandatory elements! */
Philipp Maier3d48ec02017-03-29 17:37:55 +0200617 OSMO_ASSERT(imsi);
618 OSMO_ASSERT(cil);
619
620 /* Malformed IMSI */
621 OSMO_ASSERT(strlen(imsi) <= GSM48_MI_SIZE);
622
623 msg =
624 msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "paging");
625 if (!msg)
626 return NULL;
627
628 /* Message Type 3.2.2.1 */
629 msgb_v_put(msg, BSS_MAP_MSG_PAGING);
630
Stefan Sperling3953f412018-08-28 15:06:30 +0200631 /* mandatory IMSI 3.2.2.6 */
Philipp Maier3d48ec02017-03-29 17:37:55 +0200632 mid_len = gsm48_generate_mid_from_imsi(mid_buf, imsi);
633 msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2);
634
635 /* TMSI 3.2.2.7 */
636 if (tmsi) {
Harald Welte95871da2017-05-15 12:11:36 +0200637 tmsi_sw = osmo_htonl(*tmsi);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200638 msgb_tlv_put(msg, GSM0808_IE_TMSI, sizeof(*tmsi),
639 (uint8_t *) & tmsi_sw);
640 }
641
Stefan Sperling3953f412018-08-28 15:06:30 +0200642 /* mandatory Cell Identifier List 3.2.2.27 */
643 gsm0808_enc_cell_id_list2(msg, cil);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200644
645 /* Channel Needed 3.2.2.36 */
646 if (chan_needed) {
647 msgb_tv_put(msg, GSM0808_IE_CHANNEL_NEEDED,
648 (*chan_needed) & 0x03);
649 }
650
651 /* pre-pend the header */
652 msg->l3h =
653 msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
654
655 return msg;
656}
657
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100658/*! DEPRECATED: Use gsm0808_create_paging2 instead.
659 * Create BSSMAP PAGING message.
660 * \param[in] imsi Mandatory paged IMSI in string representation
661 * \param[in] tmsi Optional paged TMSI
662 * \param[in] cil Cell Identity List (where to page)
663 * \param[in] chan_needed Channel Type needed
664 * \returns callee-allocated msgb with BSSMAP PAGING message */
665struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
666 const struct gsm0808_cell_id_list *cil,
667 const uint8_t *chan_needed)
668{
669 struct gsm0808_cell_id_list2 cil2 = {};
670
671 /* Mandatory emelents! */
672 OSMO_ASSERT(cil);
673
674 if (cil->id_list_len > GSM0808_CELL_ID_LIST2_MAXLEN)
675 return NULL;
676
677 cil2.id_discr = cil->id_discr;
678 memcpy(cil2.id_list, cil->id_list_lac, cil->id_list_len * sizeof(cil2.id_list[0].lac));
679 cil2.id_list_len = cil->id_list_len;
680
681 return gsm0808_create_paging2(imsi, tmsi, &cil2, chan_needed);
682}
683
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100684static uint8_t put_old_bss_to_new_bss_information(struct msgb *msg,
685 const struct gsm0808_old_bss_to_new_bss_info *i)
686{
687 uint8_t *old_tail;
688 uint8_t *tlv_len;
689
690 msgb_put_u8(msg, GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION);
691 tlv_len = msgb_put(msg, 1);
692 old_tail = msg->tail;
693
694 if (i->extra_information_present) {
695 uint8_t val = 0;
696 if (i->extra_information.prec)
697 val |= 1 << 0;
698 if (i->extra_information.lcs)
699 val |= 1 << 1;
700 if (i->extra_information.ue_prob)
701 val |= 1 << 2;
702 msgb_tlv_put(msg, GSM0808_FE_IE_EXTRA_INFORMATION, 1, &val);
703 }
704
705 if (i->current_channel_type_2_present) {
706 uint8_t val[2] = {
707 i->current_channel_type_2.mode,
708 i->current_channel_type_2.field,
709 };
710 msgb_tlv_put(msg, GSM0808_FE_IE_CURRENT_CHANNEL_TYPE_2, 2, val);
711 }
712
713 *tlv_len = (uint8_t) (msg->tail - old_tail);
714 return *tlv_len + 2;
715}
716
717/*! Create BSSMAP HANDOVER REQUIRED message.
718 * \param[in] params All information to be encoded.
719 * \returns newly allocated msgb with BSSMAP REQUIRED message. */
720struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params)
721{
722 struct msgb *msg;
723
724 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUIRED");
725 if (!msg)
726 return NULL;
727
728 /* Message Type, 3.2.2.1 */
729 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_REQUIRED);
730
731 /* Cause, 3.2.2.5 */
732 msgb_tlv_put(msg, GSM0808_IE_CAUSE, params->cause & 0x80? 2 : 1, (const uint8_t*)&params->cause);
733
734 /* Cell Identifier List, 3.2.2.27 */
735 gsm0808_enc_cell_id_list2(msg, &params->cil);
736
737 /* Current Channel Type 1, 3.2.2.49 */
738 if (params->current_channel_type_1_present)
739 msgb_tv_fixed_put(msg, GSM0808_IE_CURRENT_CHANNEL_TYPE_1, 1, &params->current_channel_type_1);
740
741 /* Speech Version (Used), 3.2.2.51 */
742 if (params->speech_version_used_present)
743 msgb_tv_fixed_put(msg, GSM0808_IE_SPEECH_VERSION, 1, &params->speech_version_used);
744
745 if (params->old_bss_to_new_bss_info_present)
746 put_old_bss_to_new_bss_information(msg, &params->old_bss_to_new_bss_info);
747
748 /* pre-pend the header */
749 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
750
751 return msg;
752}
753
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200754/*! Create BSSMAP HANDOVER REQUEST ACKNOWLEDGE message, 3GPP TS 48.008 3.2.1.10.
755 * Sent from the MT BSC back to the MSC when it has allocated an lchan to handover to.
756 * l3_info is the RR Handover Command that the MO BSC sends to the MS to move over. */
Neels Hofmeyrb662b362018-04-16 22:31:15 +0200757struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len,
758 uint8_t chosen_channel, uint8_t chosen_encr_alg,
759 uint8_t chosen_speech_version)
760{
761 struct msgb *msg;
762
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200763 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUEST-ACK");
Neels Hofmeyrb662b362018-04-16 22:31:15 +0200764 if (!msg)
765 return NULL;
766
767 /* Message Type, 3.2.2.1 */
768 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE);
769
770 /* Layer 3 Information, 3.2.2.24 */
771 msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, l3_info_len, l3_info);
772
773 msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, chosen_channel);
774 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, chosen_encr_alg);
775 if (chosen_speech_version != 0)
776 msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, chosen_speech_version);
777
Neels Hofmeyr43c266f2018-08-28 01:08:38 +0200778 /* prepend header with final length */
779 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
780
Neels Hofmeyrb662b362018-04-16 22:31:15 +0200781 return msg;
782}
783
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200784/*! Create BSSMAP HANDOVER DETECT message, 3GPP TS 48.008 3.2.1.40.
785 * Sent from the MT BSC back to the MSC when the MS has sent a handover RACH request and the MT BSC has
786 * received the Handover Detect message. */
787struct msgb *gsm0808_create_handover_detect()
788{
789 struct msgb *msg;
790
791 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-DETECT");
792 if (!msg)
793 return NULL;
794
795 /* Message Type, 3.2.2.1 */
796 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_DETECT);
797
Neels Hofmeyr43c266f2018-08-28 01:08:38 +0200798 /* prepend header with final length */
799 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
800
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200801 return msg;
802}
803
804/*! Create BSSMAP HANDOVER COMPLETE message, 3GPP TS 48.008 3.2.1.12.
805 * Sent from the MT BSC back to the MSC when the MS has fully settled into the new lchan. */
806struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params)
807{
808 struct msgb *msg;
809
810 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-COMPLETE");
811 if (!msg)
812 return NULL;
813
814 /* Message Type, 3.2.2.1 */
815 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_COMPLETE);
816
817 /* RR Cause, 3.2.2.22 */
818 if (params->rr_cause_present)
819 msgb_tlv_put(msg, GSM0808_IE_RR_CAUSE, 1, &params->rr_cause);
820
821 /* AoIP: Speech Codec (Chosen) 3.2.2.104 */
822 if (params->speech_codec_chosen_present)
823 gsm0808_enc_speech_codec(msg, &params->speech_codec_chosen);
824
825 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
826 if (params->codec_list_bss_supported.len)
827 gsm0808_enc_speech_codec_list(msg, &params->codec_list_bss_supported);
828
829 /* Chosen Encryption Algorithm 3.2.2.44 */
830 if (params->chosen_encr_alg_present)
831 msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg);
832
833 /* LCLS-BSS-Status 3.2.2.119 */
834 if (params->lcls_bss_status_present)
835 msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, params->lcls_bss_status);
836
Neels Hofmeyr43c266f2018-08-28 01:08:38 +0200837 /* prepend header with final length */
838 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
839
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200840 return msg;
841}
842
843/*! Create BSSMAP HANDOVER FAILURE message, 3GPP TS 48.008 3.2.1.16.
844 * Sent from the MT BSC back to the MSC when the handover has failed. */
845struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params)
846{
847 struct msgb *msg;
848
849 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-FAILURE");
850 if (!msg)
851 return NULL;
852
853 /* Message Type, 3.2.2.1 */
854 msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_FAILURE);
855
856 /* Cause, 3.2.2.5 */
857 msgb_tlv_put(msg, GSM0808_IE_CAUSE, params->cause & 0x80? 2 : 1, (const uint8_t*)&params->cause);
858
859 /* RR Cause, 3.2.2.22 */
860 if (params->rr_cause_present)
861 msgb_tlv_put(msg, GSM0808_IE_RR_CAUSE, 1, &params->rr_cause);
862
863 /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */
864 if (params->codec_list_bss_supported.len)
865 gsm0808_enc_speech_codec_list(msg, &params->codec_list_bss_supported);
866
Neels Hofmeyr43c266f2018-08-28 01:08:38 +0200867 /* prepend header with final length */
868 msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
869
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200870 return msg;
871}
872
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200873/*! Prepend a DTAP header to given Message Buffer
Harald Welte96e2a002017-06-12 21:44:18 +0200874 * \param[in] msgb Message Buffer
875 * \param[in] link_id Link Identifier */
Holger Hans Peter Freyther9a3dec02010-05-16 08:15:40 +0800876void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id)
877{
878 uint8_t *hh = msgb_push(msg, 3);
879 hh[0] = BSSAP_MSG_DTAP;
880 hh[1] = link_id;
881 hh[2] = msg->len - 3;
882}
883
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200884/*! Create BSSMAP DTAP message
Harald Welte96e2a002017-06-12 21:44:18 +0200885 * \param[in] msg_l3 Messge Buffer containing Layer3 message
886 * \param[in] link_id Link Identifier
887 * \returns callee-allocated msgb with BSSMAP DTAP message */
Holger Hans Peter Freytherc25c6682010-11-04 12:26:06 +0100888struct msgb *gsm0808_create_dtap(struct msgb *msg_l3, uint8_t link_id)
889{
890 struct dtap_header *header;
891 uint8_t *data;
892 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
893 "dtap");
894 if (!msg)
895 return NULL;
896
897 /* DTAP header */
898 msg->l3h = msgb_put(msg, sizeof(*header));
899 header = (struct dtap_header *) &msg->l3h[0];
900 header->type = BSSAP_MSG_DTAP;
901 header->link_id = link_id;
902 header->length = msgb_l3len(msg_l3);
903
904 /* Payload */
905 data = msgb_put(msg, header->length);
906 memcpy(data, msg_l3->l3h, header->length);
907
908 return msg;
909}
910
Harald Welte92107df2014-06-21 23:16:20 +0200911/* As per 3GPP TS 48.008 version 11.7.0 Release 11 */
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +0200912static const struct tlv_definition bss_att_tlvdef = {
913 .def = {
Harald Welte92107df2014-06-21 23:16:20 +0200914 [GSM0808_IE_CIRCUIT_IDENTITY_CODE] = { TLV_TYPE_FIXED, 2 },
915 [GSM0808_IE_CONNECTION_RELEASE_RQSTED] = { TLV_TYPE_TV },
916 [GSM0808_IE_RESOURCE_AVAILABLE] = { TLV_TYPE_FIXED, 21 },
917 [GSM0808_IE_CAUSE] = { TLV_TYPE_TLV },
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +0200918 [GSM0808_IE_IMSI] = { TLV_TYPE_TLV },
919 [GSM0808_IE_TMSI] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +0200920 [GSM0808_IE_NUMBER_OF_MSS] = { TLV_TYPE_TV },
Dmitri Soloviev29099422013-07-11 09:25:37 +0200921 [GSM0808_IE_LAYER_3_HEADER_INFORMATION] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +0200922 [GSM0808_IE_ENCRYPTION_INFORMATION] = { TLV_TYPE_TLV },
923 [GSM0808_IE_CHANNEL_TYPE] = { TLV_TYPE_TLV },
924 [GSM0808_IE_PERIODICITY] = { TLV_TYPE_TV },
925 [GSM0808_IE_EXTENDED_RESOURCE_INDICATOR]= { TLV_TYPE_TV },
926 [GSM0808_IE_TOTAL_RESOURCE_ACCESSIBLE] = { TLV_TYPE_FIXED, 4 },
927 [GSM0808_IE_LSA_IDENTIFIER] = { TLV_TYPE_TLV },
928 [GSM0808_IE_LSA_IDENTIFIER_LIST] = { TLV_TYPE_TLV },
Holger Hans Peter Freyther715e9452014-08-21 14:17:45 +0200929 [GSM0808_IE_LSA_INFORMATION] = { TLV_TYPE_TLV },
Harald Welte92107df2014-06-21 23:16:20 +0200930 [GSM0808_IE_CELL_IDENTIFIER] = { TLV_TYPE_TLV },
931 [GSM0808_IE_PRIORITY] = { TLV_TYPE_TLV },
932 [GSM0808_IE_CLASSMARK_INFORMATION_T2] = { TLV_TYPE_TLV },
933 [GSM0808_IE_CLASSMARK_INFORMATION_T3] = { TLV_TYPE_TLV },
934 [GSM0808_IE_INTERFERENCE_BAND_TO_USE] = { TLV_TYPE_TV },
935 [GSM0808_IE_RR_CAUSE] = { TLV_TYPE_TV },
Harald Welte92107df2014-06-21 23:16:20 +0200936 [GSM0808_IE_LAYER_3_INFORMATION] = { TLV_TYPE_TLV },
937 [GSM0808_IE_DLCI] = { TLV_TYPE_TV },
938 [GSM0808_IE_DOWNLINK_DTX_FLAG] = { TLV_TYPE_TV },
939 [GSM0808_IE_CELL_IDENTIFIER_LIST] = { TLV_TYPE_TLV },
940 [GSM0808_IE_CELL_ID_LIST_SEGMENT] = { TLV_TYPE_TLV },
941 [GSM0808_IE_CELL_ID_LIST_SEG_EST_CELLS] = { TLV_TYPE_TLV },
942 [GSM0808_IE_CELL_ID_LIST_SEG_CELLS_TBE] = { TLV_TYPE_TLV },
943 [GSM0808_IE_CELL_ID_LIST_SEG_REL_CELLS] = { TLV_TYPE_TLV },
944 [GSM0808_IE_CELL_ID_LIST_SEG_NE_CELLS] = { TLV_TYPE_TLV },
945 [GSM0808_IE_RESPONSE_RQST] = { TLV_TYPE_T },
946 [GSM0808_IE_RESOURCE_INDICATION_METHOD] = { TLV_TYPE_TV },
947 [GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1] = { TLV_TYPE_TV },
948 [GSM0808_IE_CIRCUIT_IDENTITY_CODE_LIST] = { TLV_TYPE_TLV },
949 [GSM0808_IE_DIAGNOSTIC] = { TLV_TYPE_TLV },
950 [GSM0808_IE_CHOSEN_CHANNEL] = { TLV_TYPE_TV },
951 [GSM0808_IE_CIPHER_RESPONSE_MODE] = { TLV_TYPE_TV },
952 [GSM0808_IE_LAYER_3_MESSAGE_CONTENTS] = { TLV_TYPE_TLV },
953 [GSM0808_IE_CHANNEL_NEEDED] = { TLV_TYPE_TV },
954 [GSM0808_IE_TRACE_TYPE] = { TLV_TYPE_TV },
955 [GSM0808_IE_TRIGGERID] = { TLV_TYPE_TLV },
956 [GSM0808_IE_TRACE_REFERENCE] = { TLV_TYPE_TV },
957 [GSM0808_IE_TRANSACTIONID] = { TLV_TYPE_TLV },
958 [GSM0808_IE_MOBILE_IDENTITY] = { TLV_TYPE_TLV },
959 [GSM0808_IE_OMCID] = { TLV_TYPE_TLV },
960 [GSM0808_IE_FORWARD_INDICATOR] = { TLV_TYPE_TV },
Holger Hans Peter Freytherc2b7f922010-08-04 18:50:43 +0800961 [GSM0808_IE_CHOSEN_ENCR_ALG] = { TLV_TYPE_TV },
Harald Welte92107df2014-06-21 23:16:20 +0200962 [GSM0808_IE_CIRCUIT_POOL] = { TLV_TYPE_TV },
963 [GSM0808_IE_CIRCUIT_POOL_LIST] = { TLV_TYPE_TLV },
964 [GSM0808_IE_TIME_INDICATION] = { TLV_TYPE_TV },
965 [GSM0808_IE_RESOURCE_SITUATION] = { TLV_TYPE_TLV },
966 [GSM0808_IE_CURRENT_CHANNEL_TYPE_1] = { TLV_TYPE_TV },
967 [GSM0808_IE_QUEUEING_INDICATOR] = { TLV_TYPE_TV },
968 [GSM0808_IE_SPEECH_VERSION] = { TLV_TYPE_TV },
969 [GSM0808_IE_ASSIGNMENT_REQUIREMENT] = { TLV_TYPE_TV },
970 [GSM0808_IE_TALKER_FLAG] = { TLV_TYPE_T },
971 [GSM0808_IE_GROUP_CALL_REFERENCE] = { TLV_TYPE_TLV },
972 [GSM0808_IE_EMLPP_PRIORITY] = { TLV_TYPE_TV },
973 [GSM0808_IE_CONFIG_EVO_INDI] = { TLV_TYPE_TV },
974 [GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION] = { TLV_TYPE_TLV },
975 [GSM0808_IE_LCS_QOS] = { TLV_TYPE_TLV },
976 [GSM0808_IE_LSA_ACCESS_CTRL_SUPPR] = { TLV_TYPE_TV },
977 [GSM0808_IE_LCS_PRIORITY] = { TLV_TYPE_TLV },
978 [GSM0808_IE_LOCATION_TYPE] = { TLV_TYPE_TLV },
979 [GSM0808_IE_LOCATION_ESTIMATE] = { TLV_TYPE_TLV },
980 [GSM0808_IE_POSITIONING_DATA] = { TLV_TYPE_TLV },
981 [GSM0808_IE_LCS_CAUSE] = { TLV_TYPE_TLV },
982 [GSM0808_IE_APDU] = { TLV_TYPE_TLV },
983 [GSM0808_IE_NETWORK_ELEMENT_IDENTITY] = { TLV_TYPE_TLV },
984 [GSM0808_IE_GPS_ASSISTANCE_DATA] = { TLV_TYPE_TLV },
985 [GSM0808_IE_DECIPHERING_KEYS] = { TLV_TYPE_TLV },
986 [GSM0808_IE_RETURN_ERROR_RQST] = { TLV_TYPE_TLV },
987 [GSM0808_IE_RETURN_ERROR_CAUSE] = { TLV_TYPE_TLV },
988 [GSM0808_IE_SEGMENTATION] = { TLV_TYPE_TLV },
989 [GSM0808_IE_SERVICE_HANDOVER] = { TLV_TYPE_TLV },
990 [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_UMTS] = { TLV_TYPE_TLV },
991 [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_CDMA2000] = { TLV_TYPE_TLV },
992 [GSM0808_IE_GERAN_CLASSMARK] = { TLV_TYPE_TLV },
993 [GSM0808_IE_GERAN_BSC_CONTAINER] = { TLV_TYPE_TLV },
994 [GSM0808_IE_NEW_BSS_TO_OLD_BSS_INFO] = { TLV_TYPE_TLV },
995 [GSM0800_IE_INTER_SYSTEM_INFO] = { TLV_TYPE_TLV },
996 [GSM0808_IE_SNA_ACCESS_INFO] = { TLV_TYPE_TLV },
997 [GSM0808_IE_VSTK_RAND_INFO] = { TLV_TYPE_TLV },
998 [GSM0808_IE_PAGING_INFO] = { TLV_TYPE_TV },
999 [GSM0808_IE_IMEI] = { TLV_TYPE_TLV },
1000 [GSM0808_IE_VELOCITY_ESTIMATE] = { TLV_TYPE_TLV },
1001 [GSM0808_IE_VGCS_FEATURE_FLAGS] = { TLV_TYPE_TLV },
1002 [GSM0808_IE_TALKER_PRIORITY] = { TLV_TYPE_TV },
1003 [GSM0808_IE_EMERGENCY_SET_INDICATION] = { TLV_TYPE_T },
1004 [GSM0808_IE_TALKER_IDENTITY] = { TLV_TYPE_TLV },
1005 [GSM0808_IE_SMS_TO_VGCS] = { TLV_TYPE_TLV },
1006 [GSM0808_IE_VGCS_TALKER_MODE] = { TLV_TYPE_TLV },
1007 [GSM0808_IE_VGCS_VBS_CELL_STATUS] = { TLV_TYPE_TLV },
1008 [GSM0808_IE_GANSS_ASSISTANCE_DATA] = { TLV_TYPE_TLV },
1009 [GSM0808_IE_GANSS_POSITIONING_DATA] = { TLV_TYPE_TLV },
1010 [GSM0808_IE_GANSS_LOCATION_TYPE] = { TLV_TYPE_TLV },
1011 [GSM0808_IE_APP_DATA] = { TLV_TYPE_TLV },
1012 [GSM0808_IE_DATA_IDENTITY] = { TLV_TYPE_TLV },
1013 [GSM0808_IE_APP_DATA_INFO] = { TLV_TYPE_TLV },
1014 [GSM0808_IE_MSISDN] = { TLV_TYPE_TLV },
1015 [GSM0808_IE_AOIP_TRASP_ADDR] = { TLV_TYPE_TLV },
1016 [GSM0808_IE_SPEECH_CODEC_LIST] = { TLV_TYPE_TLV },
1017 [GSM0808_IE_SPEECH_CODEC] = { TLV_TYPE_TLV },
1018 [GSM0808_IE_CALL_ID] = { TLV_TYPE_FIXED, 4 },
1019 [GSM0808_IE_CALL_ID_LIST] = { TLV_TYPE_TLV },
1020 [GSM0808_IE_A_IF_SEL_FOR_RESET] = { TLV_TYPE_TV },
1021 [GSM0808_IE_KC_128] = { TLV_TYPE_FIXED, 16 },
1022 [GSM0808_IE_CSG_IDENTIFIER] = { TLV_TYPE_TLV },
1023 [GSM0808_IE_REDIR_ATTEMPT_FLAG] = { TLV_TYPE_T },
1024 [GSM0808_IE_REROUTE_REJ_CAUSE] = { TLV_TYPE_TV },
1025 [GSM0808_IE_SEND_SEQ_NUM] = { TLV_TYPE_TV },
1026 [GSM0808_IE_REROUTE_COMPL_OUTCOME] = { TLV_TYPE_TV },
1027 [GSM0808_IE_GLOBAL_CALL_REF] = { TLV_TYPE_TLV },
1028 [GSM0808_IE_LCLS_CONFIG] = { TLV_TYPE_TV },
1029 [GSM0808_IE_LCLS_CONN_STATUS_CTRL] = { TLV_TYPE_TV },
1030 [GSM0808_IE_LCLS_CORR_NOT_NEEDED] = { TLV_TYPE_TV },
1031 [GSM0808_IE_LCLS_BSS_STATUS] = { TLV_TYPE_TV },
1032 [GSM0808_IE_LCLS_BREAK_REQ] = { TLV_TYPE_TV },
1033 [GSM0808_IE_CSFB_INDICATION] = { TLV_TYPE_T },
1034 [GSM0808_IE_CS_TO_PS_SRVCC] = { TLV_TYPE_T },
1035 [GSM0808_IE_SRC_ENB_TO_TGT_ENB_TRANSP] = { TLV_TYPE_TLV },
1036 [GSM0808_IE_CS_TO_PS_SRVCC_IND] = { TLV_TYPE_T },
1037 [GSM0808_IE_CN_TO_MS_TRANSP_INFO] = { TLV_TYPE_TLV },
1038 [GSM0808_IE_SELECTED_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
1039 [GSM0808_IE_LAST_USED_EUTRAN_PLMN_ID] = { TLV_TYPE_FIXED, 3 },
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001040 },
1041};
1042
Harald Weltef4d45ab2011-07-16 12:13:00 +02001043const struct tlv_definition *gsm0808_att_tlvdef(void)
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +02001044{
1045 return &bss_att_tlvdef;
1046}
Harald Welte9b837e62011-07-11 17:43:19 +02001047
1048static const struct value_string gsm0808_msgt_names[] = {
1049 { BSS_MAP_MSG_ASSIGMENT_RQST, "ASSIGNMENT REQ" },
1050 { BSS_MAP_MSG_ASSIGMENT_COMPLETE, "ASSIGNMENT COMPL" },
1051 { BSS_MAP_MSG_ASSIGMENT_FAILURE, "ASSIGNMENT FAIL" },
Harald Welte92107df2014-06-21 23:16:20 +02001052 { BSS_MAP_MSG_CHAN_MOD_RQST, "CHANNEL MODIFY REQUEST" },
Harald Welte9b837e62011-07-11 17:43:19 +02001053
1054 { BSS_MAP_MSG_HANDOVER_RQST, "HANDOVER REQ" },
1055 { BSS_MAP_MSG_HANDOVER_REQUIRED, "HANDOVER REQUIRED" },
1056 { BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE,"HANDOVER REQ ACK" },
1057 { BSS_MAP_MSG_HANDOVER_CMD, "HANDOVER CMD" },
1058 { BSS_MAP_MSG_HANDOVER_COMPLETE, "HANDOVER COMPLETE" },
1059 { BSS_MAP_MSG_HANDOVER_SUCCEEDED, "HANDOVER SUCCESS" },
1060 { BSS_MAP_MSG_HANDOVER_FAILURE, "HANDOVER FAILURE" },
1061 { BSS_MAP_MSG_HANDOVER_PERFORMED, "HANDOVER PERFORMED" },
1062 { BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE, "HANDOVER CAND ENQ" },
1063 { BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE, "HANDOVER CAND RESP" },
1064 { BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT, "HANDOVER REQ REJ" },
1065 { BSS_MAP_MSG_HANDOVER_DETECT, "HANDOVER DETECT" },
Harald Welte92107df2014-06-21 23:16:20 +02001066 { BSS_MAP_MSG_INT_HANDOVER_REQUIRED, "INT HANDOVER REQ" },
1067 { BSS_MAP_MSG_INT_HANDOVER_REQUIRED_REJ,"INT HANDOVER REQ REJ" },
1068 { BSS_MAP_MSG_INT_HANDOVER_CMD, "INT HANDOVER CMD" },
1069 { BSS_MAP_MSG_INT_HANDOVER_ENQUIRY, "INT HANDOVER ENQ" },
Harald Welte9b837e62011-07-11 17:43:19 +02001070
1071 { BSS_MAP_MSG_CLEAR_CMD, "CLEAR COMMAND" },
1072 { BSS_MAP_MSG_CLEAR_COMPLETE, "CLEAR COMPLETE" },
1073 { BSS_MAP_MSG_CLEAR_RQST, "CLEAR REQUEST" },
1074 { BSS_MAP_MSG_SAPI_N_REJECT, "SAPI N REJECT" },
1075 { BSS_MAP_MSG_CONFUSION, "CONFUSION" },
1076
1077 { BSS_MAP_MSG_SUSPEND, "SUSPEND" },
1078 { BSS_MAP_MSG_RESUME, "RESUME" },
1079 { BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION, "CONN ORIENT INFO" },
1080 { BSS_MAP_MSG_PERFORM_LOCATION_RQST, "PERFORM LOC REQ" },
1081 { BSS_MAP_MSG_LSA_INFORMATION, "LSA INFORMATION" },
1082 { BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE, "PERFORM LOC RESP" },
1083 { BSS_MAP_MSG_PERFORM_LOCATION_ABORT, "PERFORM LOC ABORT" },
1084 { BSS_MAP_MSG_COMMON_ID, "COMMON ID" },
Harald Welte92107df2014-06-21 23:16:20 +02001085 { BSS_MAP_MSG_REROUTE_CMD, "REROUTE COMMAND" },
1086 { BSS_MAP_MSG_REROUTE_COMPLETE, "REROUTE COMPLETE" },
Harald Welte9b837e62011-07-11 17:43:19 +02001087
1088 { BSS_MAP_MSG_RESET, "RESET" },
1089 { BSS_MAP_MSG_RESET_ACKNOWLEDGE, "RESET ACK" },
1090 { BSS_MAP_MSG_OVERLOAD, "OVERLOAD" },
1091 { BSS_MAP_MSG_RESET_CIRCUIT, "RESET CIRCUIT" },
1092 { BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE, "RESET CIRCUIT ACK" },
1093 { BSS_MAP_MSG_MSC_INVOKE_TRACE, "MSC INVOKE TRACE" },
1094 { BSS_MAP_MSG_BSS_INVOKE_TRACE, "BSS INVOKE TRACE" },
1095 { BSS_MAP_MSG_CONNECTIONLESS_INFORMATION, "CONNLESS INFO" },
Harald Welte92107df2014-06-21 23:16:20 +02001096 { BSS_MAP_MSG_RESET_IP_RSRC, "RESET IP RESOURCE" },
1097 { BSS_MAP_MSG_RESET_IP_RSRC_ACK, "RESET IP RESOURCE ACK" },
Harald Welte9b837e62011-07-11 17:43:19 +02001098
1099 { BSS_MAP_MSG_BLOCK, "BLOCK" },
1100 { BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE, "BLOCK ACK" },
1101 { BSS_MAP_MSG_UNBLOCK, "UNBLOCK" },
1102 { BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE, "UNBLOCK ACK" },
1103 { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK, "CIRC GROUP BLOCK" },
1104 { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE, "CIRC GORUP BLOCK ACK" },
1105 { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK, "CIRC GROUP UNBLOCK" },
1106 { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE, "CIRC GROUP UNBLOCK ACK" },
1107 { BSS_MAP_MSG_UNEQUIPPED_CIRCUIT, "UNEQUIPPED CIRCUIT" },
1108 { BSS_MAP_MSG_CHANGE_CIRCUIT, "CHANGE CIRCUIT" },
1109 { BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE, "CHANGE CIRCUIT ACK" },
1110
1111 { BSS_MAP_MSG_RESOURCE_RQST, "RESOURCE REQ" },
1112 { BSS_MAP_MSG_RESOURCE_INDICATION, "RESOURCE IND" },
1113 { BSS_MAP_MSG_PAGING, "PAGING" },
1114 { BSS_MAP_MSG_CIPHER_MODE_CMD, "CIPHER MODE CMD" },
1115 { BSS_MAP_MSG_CLASSMARK_UPDATE, "CLASSMARK UPDATE" },
1116 { BSS_MAP_MSG_CIPHER_MODE_COMPLETE, "CIPHER MODE COMPLETE" },
1117 { BSS_MAP_MSG_QUEUING_INDICATION, "QUEUING INDICATION" },
1118 { BSS_MAP_MSG_COMPLETE_LAYER_3, "COMPLETE LAYER 3" },
1119 { BSS_MAP_MSG_CLASSMARK_RQST, "CLASSMARK REQ" },
1120 { BSS_MAP_MSG_CIPHER_MODE_REJECT, "CIPHER MODE REJECT" },
1121 { BSS_MAP_MSG_LOAD_INDICATION, "LOAD IND" },
1122
Harald Welte92107df2014-06-21 23:16:20 +02001123 { BSS_MAP_MSG_VGCS_VBS_SETUP, "VGCS/VBS SETUP" },
1124 { BSS_MAP_MSG_VGCS_VBS_SETUP_ACK, "VGCS/VBS SETUP ACK" },
1125 { BSS_MAP_MSG_VGCS_VBS_SETUP_REFUSE, "VGCS/VBS SETUP REFUSE" },
1126 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RQST, "VGCS/VBS ASSIGN REQ" },
1127 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RESULT, "VGCS/VBS ASSIGN RES" },
1128 { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_FAILURE, "VGCS/VBS ASSIGN FAIL" },
1129 { BSS_MAP_MSG_VGCS_VBS_QUEUING_INDICATION, "VGCS/VBS QUEUING IND" },
1130 { BSS_MAP_MSG_UPLINK_RQST, "UPLINK REQ" },
1131 { BSS_MAP_MSG_UPLINK_RQST_ACKNOWLEDGE, "UPLINK REQ ACK" },
1132 { BSS_MAP_MSG_UPLINK_RQST_CONFIRMATION, "UPLINK REQ CONF" },
1133 { BSS_MAP_MSG_UPLINK_RELEASE_INDICATION,"UPLINK REL IND" },
1134 { BSS_MAP_MSG_UPLINK_REJECT_CMD, "UPLINK REJ CMD" },
1135 { BSS_MAP_MSG_UPLINK_RELEASE_CMD, "UPLINK REL CMD" },
1136 { BSS_MAP_MSG_UPLINK_SEIZED_CMD, "UPLINK SEIZED CMD" },
1137 { BSS_MAP_MSG_VGCS_ADDL_INFO, "VGCS ADDL INFO" },
1138 { BSS_MAP_MSG_NOTIFICATION_DATA, "NOTIF DATA" },
1139 { BSS_MAP_MSG_UPLINK_APP_DATA, "UPLINK APP DATA" },
1140
1141 { BSS_MAP_MSG_LCLS_CONNECT_CTRL, "LCLS-CONNECT-CONTROL" },
1142 { BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK, "CLS-CONNECT-CONTROL-ACK" },
1143 { BSS_MAP_MSG_LCLS_NOTIFICATION, "LCLS-NOTIFICATION" },
Harald Welte9b837e62011-07-11 17:43:19 +02001144
1145 { 0, NULL }
1146};
1147
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001148/*! Return string name of BSSMAP Message Type */
Harald Welte9b837e62011-07-11 17:43:19 +02001149const char *gsm0808_bssmap_name(uint8_t msg_type)
1150{
1151 return get_value_string(gsm0808_msgt_names, msg_type);
1152}
1153
1154static const struct value_string gsm0808_bssap_names[] = {
1155 { BSSAP_MSG_BSS_MANAGEMENT, "MANAGEMENT" },
1156 { BSSAP_MSG_DTAP, "DTAP" },
Neels Hofmeyr90fdb082017-03-01 14:59:44 +01001157 { 0, NULL }
Harald Welte9b837e62011-07-11 17:43:19 +02001158};
1159
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001160/*! Return string name of BSSAP Message Type */
Harald Welte9b837e62011-07-11 17:43:19 +02001161const char *gsm0808_bssap_name(uint8_t msg_type)
1162{
1163 return get_value_string(gsm0808_bssap_names, msg_type);
1164}
Harald Welte96e2a002017-06-12 21:44:18 +02001165
Neels Hofmeyrffad5742018-01-12 05:34:03 +01001166const struct value_string gsm0808_speech_codec_type_names[] = {
1167 { GSM0808_SCT_FR1, "FR1" },
1168 { GSM0808_SCT_FR2, "FR2" },
1169 { GSM0808_SCT_FR3, "FR3" },
1170 { GSM0808_SCT_FR4, "FR4" },
1171 { GSM0808_SCT_FR5, "FR5" },
1172 { GSM0808_SCT_HR1, "HR1" },
1173 { GSM0808_SCT_HR3, "HR3" },
1174 { GSM0808_SCT_HR4, "HR4" },
1175 { GSM0808_SCT_HR6, "HR6" },
1176 { GSM0808_SCT_CSD, "CSD" },
1177 { 0, NULL }
1178};
1179
Philipp Maiercdd05812018-07-12 18:21:07 +02001180const struct value_string gsm0808_permitted_speech_names[] = {
1181 { GSM0808_PERM_FR1, "FR1" },
1182 { GSM0808_PERM_FR2, "FR2" },
1183 { GSM0808_PERM_FR3, "FR3" },
1184 { GSM0808_PERM_FR4, "FR4" },
1185 { GSM0808_PERM_FR5, "FR5" },
1186 { GSM0808_PERM_HR1, "HR1" },
1187 { GSM0808_PERM_HR2, "HR2" },
1188 { GSM0808_PERM_HR3, "HR3" },
1189 { GSM0808_PERM_HR4, "HR4" },
1190 { GSM0808_PERM_HR6, "HR6" },
1191 { 0, NULL }
1192};
1193
Pau Espin Pedrolf2cda622018-07-06 17:16:41 +02001194const struct value_string gsm0808_chosen_enc_alg_names[] = {
1195 { GSM0808_ALG_ID_A5_0, "A5/0" },
1196 { GSM0808_ALG_ID_A5_1, "A5/1" },
1197 { GSM0808_ALG_ID_A5_2, "A5/2" },
1198 { GSM0808_ALG_ID_A5_3, "A5/3" },
1199 { GSM0808_ALG_ID_A5_4, "A5/4" },
1200 { GSM0808_ALG_ID_A5_5, "A5/5" },
1201 { GSM0808_ALG_ID_A5_6, "A5/6" },
1202 { GSM0808_ALG_ID_A5_7, "A5/7" },
1203 { 0, NULL }
1204};
1205
Philipp Maierdbb76592018-03-29 12:55:26 +02001206static const struct value_string gsm0808_cause_names[] = {
1207 { GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, "RADIO INTERFACE MESSAGE FAILURE" },
1208 { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, "RADIO INTERFACE FAILURE" },
1209 { GSM0808_CAUSE_UPLINK_QUALITY, "UPLINK QUALITY" },
1210 { GSM0808_CAUSE_UPLINK_STRENGTH, "UPLINK STRENGTH" },
1211 { GSM0808_CAUSE_DOWNLINK_QUALITY, "DOWNLINK QUALITY" },
1212 { GSM0808_CAUSE_DOWNLINK_STRENGTH, "DOWNLINK STRENGTH" },
1213 { GSM0808_CAUSE_DISTANCE, "DISTANCE" },
1214 { GSM0808_CAUSE_O_AND_M_INTERVENTION, "O AND M INTERVENTION" },
1215 { GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION, "RESPONSE TO MSC INVOCATION" },
1216 { GSM0808_CAUSE_CALL_CONTROL, "CALL CONTROL" },
1217 { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION, "RADIO INTERFACE FAILURE REVERSION" },
1218 { GSM0808_CAUSE_HANDOVER_SUCCESSFUL, "HANDOVER SUCCESSFUL" },
1219 { GSM0808_CAUSE_BETTER_CELL, "BETTER CELL" },
1220 { GSM0808_CAUSE_DIRECTED_RETRY, "DIRECTED RETRY" },
1221 { GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL, "JOINED GROUP CALL CHANNEL" },
1222 { GSM0808_CAUSE_TRAFFIC, "TRAFFIC" },
1223 { GSM0808_CAUSE_REDUCE_LOAD_IN_SERVING_CELL, "REDUCE LOAD IN SERVING CELL" },
1224 { GSM0808_CAUSE_TRAFFIC_LOAD_IN_TGT_HIGHER_THAN_IN_SRC_CELL, "TRAFFIC LOAD IN TGT HIGHER THAN IN SRC CELL" },
1225 { GSM0808_CAUSE_RELOCATION_TRIGGERED, "RELOCATION TRIGGERED" },
Thorsten Alteholz0062a5f2018-05-15 15:28:55 +02001226 { GSM0808_CAUSE_REQUESTED_OPT_NOT_AUTHORISED, "REQUESTED OPT NOT AUTHORISED" },
Philipp Maierdbb76592018-03-29 12:55:26 +02001227 { GSM0808_CAUSE_ALT_CHAN_CONFIG_REQUESTED, "ALT CHAN CONFIG REQUESTED" },
1228 { GSM0808_CAUSE_RESP_TO_INT_HO_ENQ_MSG, "RESP TO INT HO ENQ MSG" },
1229 { GSM0808_CAUSE_INT_HO_ENQUIRY_REJECT, "INT HO ENQUIRY REJECT" },
1230 { GSM0808_CAUSE_REDUNDANCY_LEVEL_NOT_ADEQUATE, "REDUNDANCY LEVEL NOT ADEQUATE" },
1231 { GSM0808_CAUSE_EQUIPMENT_FAILURE, "EQUIPMENT FAILURE" },
1232 { GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, "NO RADIO RESOURCE AVAILABLE" },
1233 { GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE, "RQSTED TERRESTRIAL RESOURCE UNAVAILABLE" },
1234 { GSM0808_CAUSE_CCCH_OVERLOAD, "CCCH OVERLOAD" },
1235 { GSM0808_CAUSE_PROCESSOR_OVERLOAD, "PROCESSOR OVERLOAD" },
1236 { GSM0808_CAUSE_BSS_NOT_EQUIPPED, "BSS NOT EQUIPPED" },
1237 { GSM0808_CAUSE_MS_NOT_EQUIPPED, "MS NOT EQUIPPED" },
1238 { GSM0808_CAUSE_INVALID_CELL, "INVALID CELL" },
1239 { GSM0808_CAUSE_TRAFFIC_LOAD, "TRAFFIC LOAD" },
1240 { GSM0808_CAUSE_PREEMPTION, "PREEMPTION" },
1241 { GSM0808_CAUSE_DTM_HO_SGSN_FAILURE, "DTM HO SGSN FAILURE" },
1242 { GSM0808_CAUSE_DTM_HO_PS_ALLOC_FAILURE, "DTM HO PS ALLOC FAILURE" },
1243 { GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE, "RQSTED TRANSCODING RATE ADAPTION UNAVAILABLE" },
1244 { GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH, "CIRCUIT POOL MISMATCH" },
1245 { GSM0808_CAUSE_SWITCH_CIRCUIT_POOL, "SWITCH CIRCUIT POOL" },
1246 { GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE, "RQSTED SPEECH VERSION UNAVAILABLE" },
1247 { GSM0808_CAUSE_LSA_NOT_ALLOWED, "LSA NOT ALLOWED" },
1248 { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL, "REQ CODEC TYPE OR CONFIG UNAVAIL" },
1249 { GSM0808_CAUSE_REQ_A_IF_TYPE_UNAVAIL, "REQ A IF TYPE UNAVAIL" },
1250 { GSM0808_CAUSE_INVALID_CSG_CELL, "INVALID CSG CELL" },
1251 { GSM0808_CAUSE_REQ_REDUND_LEVEL_NOT_AVAIL, "REQ REDUND LEVEL NOT AVAIL" },
1252 { GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED, "CIPHERING ALGORITHM NOT SUPPORTED" },
1253 { GSM0808_CAUSE_GERAN_IU_MODE_FAILURE, "GERAN IU MODE FAILURE" },
1254 { GSM0808_CAUSE_INC_RELOC_NOT_SUPP_DT_PUESBINE_FEATURE, "INC RELOC NOT SUPP DT PUESBINE FEATURE" },
1255 { GSM0808_CAUSE_ACCESS_RESTRICTED_DUE_TO_SHARED_NETWORKS, "ACCESS RESTRICTED DUE TO SHARED NETWORKS" },
1256 { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_NOT_SUPP, "REQ CODEC TYPE OR CONFIG NOT SUPP" },
1257 { GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP, "REQ A IF TYPE NOT SUPP" },
1258 { GSM0808_CAUSE_REQ_REDUND_LVL_NOT_SUPP, "REQ REDUND LVL NOT SUPP" },
1259 { GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED, "TERRESTRIAL CIRCUIT ALREADY ALLOCATED" },
1260 { GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS, "INVALID MESSAGE CONTENTS" },
1261 { GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING, "INFORMATION ELEMENT OR FIELD MISSING" },
1262 { GSM0808_CAUSE_INCORRECT_VALUE, "INCORRECT VALUE" },
1263 { GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE, "UNKNOWN MESSAGE TYPE" },
1264 { GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT, "UNKNOWN INFORMATION ELEMENT" },
1265 { GSM0808_CAUSE_DTM_HO_INVALID_PS_IND, "DTM HO INVALID PS IND" },
1266 { GSM0808_CAUSE_CALL_ID_ALREADY_ALLOC, "CALL ID ALREADY ALLOC" },
1267 { GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC, "PROTOCOL ERROR BETWEEN BSS AND MSC" },
Thorsten Alteholz0062a5f2018-05-15 15:28:55 +02001268 { GSM0808_CAUSE_VGCS_VBS_CALL_NON_EXISTENT, "VGCS VBS CALL NON EXISTENT" },
Philipp Maierdbb76592018-03-29 12:55:26 +02001269 { GSM0808_CAUSE_DTM_HO_TIMER_EXPIRY, "DTM HO TIMER EXPIRY" },
1270 { 0, NULL }
1271};
1272
1273/*! Return string name of BSSMAP Cause name */
1274const char *gsm0808_cause_name(uint8_t cause)
1275{
1276 return get_value_string(gsm0808_cause_names, cause);
1277}
1278
Harald Welteebd362d2018-06-02 14:11:19 +02001279const struct value_string gsm0808_lcls_config_names[] = {
1280 { GSM0808_LCLS_CFG_BOTH_WAY, "Connect both-way" },
1281 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL,
1282 "Connect both-way, bi-cast UL to CN" },
1283 { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL,
1284 "Connect both-way, send access DL from CN" },
1285 { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL_BLOCK_LOCAL_DL,
1286 "Connect both-way, send access DL from CN, block local DL" },
1287 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL,
1288 "Connect both-way, bi-cast UL to CN, send access DL from CN" },
1289 { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL_BLOCK_LOCAL_DL,
1290 "Connect both-way, bi-cast UL to CN, send access DL from CN, block local DL" },
1291 { 0, NULL }
1292};
1293
1294const struct value_string gsm0808_lcls_control_names[] = {
1295 { GSM0808_LCLS_CSC_CONNECT, "Connect" },
1296 { GSM0808_LCLS_CSC_DO_NOT_CONNECT, "Do not connect" },
1297 { GSM0808_LCLS_CSC_RELEASE_LCLS, "Release LCLS" },
1298 { GSM0808_LCLS_CSC_BICAST_UL_AT_HANDOVER, "Bi-cast UL at Handover" },
1299 { GSM0808_LCLS_CSC_BICAST_UL_AND_RECV_DL_AT_HANDOVER, "Bi-cast UL and receive DL at Handover" },
1300 { 0, NULL }
1301};
1302
1303const struct value_string gsm0808_lcls_status_names[] = {
1304 { GSM0808_LCLS_STS_NOT_YET_LS, "Call not yet locally switched" },
1305 { GSM0808_LCLS_STS_NOT_POSSIBLE_LS, "Call not possible to be locally switched" },
1306 { GSM0808_LCLS_STS_NO_LONGER_LS, "Call is no longer locally switched" },
1307 { GSM0808_LCLS_STS_REQ_LCLS_NOT_SUPP, "Requested LCLS configuration is not supported" },
1308 { GSM0808_LCLS_STS_LOCALLY_SWITCHED, "Call is locally switched with requested LCLS config" },
1309 { 0, NULL }
1310};
1311
Harald Welte96e2a002017-06-12 21:44:18 +02001312/*! @} */