Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2009,2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 3 | * (C) 2009,2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | * |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 8 | * 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 Chemeris | 22630e6 | 2020-05-13 00:44:04 +0300 | [diff] [blame] | 24 | #include <string.h> |
| 25 | |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 26 | #include <osmocom/core/byteswap.h> |
Philipp Maier | 2908dbf | 2020-06-05 14:16:11 +0200 | [diff] [blame] | 27 | #include <osmocom/core/endian.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 28 | #include <osmocom/gsm/gsm0808.h> |
Neels Hofmeyr | 5b214e2 | 2020-09-18 18:00:50 +0200 | [diff] [blame] | 29 | #include <osmocom/gsm/gsm0808_lcs.h> |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 30 | #include <osmocom/gsm/gsm0808_utils.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 31 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
| 32 | #include <osmocom/gsm/gsm48.h> |
Neels Hofmeyr | 5b214e2 | 2020-09-18 18:00:50 +0200 | [diff] [blame] | 33 | #include <osmocom/gsm/gad.h> |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 34 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 35 | /*! \addtogroup gsm0808 |
| 36 | * @{ |
Harald Welte | 37b6165 | 2017-10-16 18:46:03 +0200 | [diff] [blame] | 37 | * \file gsm0808.c |
| 38 | * Helper functions regarding the TS 08.08 / 48.008 A interface, primarily |
| 39 | * message generation/encoding. |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 40 | */ |
| 41 | |
Alexander Chemeris | 22630e6 | 2020-05-13 00:44:04 +0300 | [diff] [blame] | 42 | /*! Char buffer to return strings from functions */ |
| 43 | static __thread char str_buff[512]; |
| 44 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 45 | /*! 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 Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 47 | * \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 Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 54 | struct 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 Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 58 | { |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 59 | 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 */ |
| 77 | struct 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 Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 80 | struct msgb* msg; |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 81 | struct { |
| 82 | uint8_t ident; |
| 83 | struct gsm48_loc_area_id lai; |
| 84 | uint16_t ci; |
| 85 | } __attribute__ ((packed)) lai_ci; |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 86 | |
| 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 Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 92 | /* create layer 3 header */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 93 | msgb_v_put(msg, BSS_MAP_MSG_COMPLETE_LAYER_3); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 94 | |
| 95 | /* create the cell header */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 96 | lai_ci.ident = CELL_IDENT_WHOLE_GLOBAL; |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 97 | gsm48_generate_lai2(&lai_ci.lai, &cell->lai); |
| 98 | lai_ci.ci = osmo_htons(cell->cell_identity); |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 99 | msgb_tlv_put(msg, GSM0808_IE_CELL_IDENTIFIER, sizeof(lai_ci), |
| 100 | (uint8_t *) &lai_ci); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 101 | |
| 102 | /* copy the layer3 data */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 103 | msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, |
| 104 | msgb_l3len(msg_l3), msg_l3->l3h); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 105 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 106 | /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */ |
| 107 | if (scl) |
| 108 | gsm0808_enc_speech_codec_list(msg, scl); |
| 109 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 110 | /* push the bssmap header */ |
| 111 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 112 | |
| 113 | return msg; |
| 114 | } |
| 115 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 116 | /*! 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 Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 119 | * \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 Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 125 | struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc, |
| 126 | uint16_t cc, int lac, uint16_t _ci) |
| 127 | { |
Neels Hofmeyr | 4eeb808 | 2018-03-23 01:47:14 +0100 | [diff] [blame] | 128 | 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 Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 141 | /*! Create BSSMAP RESET message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 142 | * \returns callee-allocated msgb with BSSMAP Reset message */ |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 143 | struct msgb *gsm0808_create_reset(void) |
| 144 | { |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 145 | uint8_t cause = GSM0808_CAUSE_EQUIPMENT_FAILURE; |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 146 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 147 | "bssmap: reset"); |
| 148 | if (!msg) |
| 149 | return NULL; |
| 150 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 151 | msgb_v_put(msg, BSS_MAP_MSG_RESET); |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 152 | gsm0808_enc_cause(msg, cause); |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 153 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 154 | |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 155 | return msg; |
| 156 | } |
| 157 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 158 | /*! Create BSSMAP RESET ACK message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 159 | * \returns callee-allocated msgb with BSSMAP Reset ACK message */ |
Harald Welte | a62fe31 | 2013-06-19 15:14:37 +0200 | [diff] [blame] | 160 | struct 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 Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 173 | /*! Create BSSMAP Clear Complete message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 174 | * \returns callee-allocated msgb with BSSMAP Clear Complete message */ |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 175 | struct 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 Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 179 | uint8_t val = BSS_MAP_MSG_CLEAR_COMPLETE; |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 180 | if (!msg) |
| 181 | return NULL; |
| 182 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 183 | msg->l3h = msg->data; |
| 184 | msgb_tlv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 1, &val); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 185 | |
| 186 | return msg; |
| 187 | } |
| 188 | |
Harald Welte | d1365e1 | 2019-02-18 13:44:30 +0100 | [diff] [blame] | 189 | /*! 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 Maier | 1a146c8 | 2018-10-30 09:36:49 +0100 | [diff] [blame] | 193 | * \param[in] cause TS 08.08 cause value |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 194 | * \returns callee-allocated msgb with BSSMAP Clear Command message */ |
Philipp Maier | 1a146c8 | 2018-10-30 09:36:49 +0100 | [diff] [blame] | 195 | struct msgb *gsm0808_create_clear_command(uint8_t cause) |
Holger Hans Peter Freyther | a3f05d8 | 2010-10-27 11:49:24 +0200 | [diff] [blame] | 196 | { |
| 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 Freyther | aeebe39 | 2010-10-27 12:36:05 +0200 | [diff] [blame] | 202 | msg->l3h = msgb_tv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 4); |
| 203 | msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD); |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 204 | gsm0808_enc_cause(msg, cause); |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 205 | |
Holger Hans Peter Freyther | a3f05d8 | 2010-10-27 11:49:24 +0200 | [diff] [blame] | 206 | return msg; |
| 207 | } |
| 208 | |
Philipp Maier | 74c4c4e | 2019-02-04 16:42:28 +0100 | [diff] [blame] | 209 | /*! 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. */ |
| 213 | struct msgb *gsm0808_create_clear_command2(uint8_t cause, bool csfb_ind) |
| 214 | { |
Harald Welte | 10ba47d | 2019-02-18 12:36:54 +0100 | [diff] [blame] | 215 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 216 | "bssmap: clear command"); |
Philipp Maier | 74c4c4e | 2019-02-04 16:42:28 +0100 | [diff] [blame] | 217 | if (!msg) |
| 218 | return NULL; |
| 219 | |
Harald Welte | 10ba47d | 2019-02-18 12:36:54 +0100 | [diff] [blame] | 220 | msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD); |
| 221 | gsm0808_enc_cause(msg, cause); |
| 222 | |
Philipp Maier | 74c4c4e | 2019-02-04 16:42:28 +0100 | [diff] [blame] | 223 | if (csfb_ind) |
| 224 | msgb_v_put(msg, GSM0808_IE_CSFB_INDICATION); |
| 225 | |
Harald Welte | 10ba47d | 2019-02-18 12:36:54 +0100 | [diff] [blame] | 226 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 227 | |
Philipp Maier | 74c4c4e | 2019-02-04 16:42:28 +0100 | [diff] [blame] | 228 | return msg; |
| 229 | } |
| 230 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 231 | /*! Create BSSMAP Cipher Mode Command message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 232 | * \param[in] ei Mandatory Encryption Information |
| 233 | * \param[in] cipher_response_mode optional 1-byte Cipher Response Mode |
| 234 | * \returns callee-allocated msgb with BSSMAP Cipher Mode Command message */ |
Philipp Maier | b478dd3 | 2017-03-29 15:50:05 +0200 | [diff] [blame] | 235 | struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei, |
| 236 | const uint8_t *cipher_response_mode) |
| 237 | { |
| 238 | /* See also: 3GPP TS 48.008 3.2.1.30 CIPHER MODE COMMAND */ |
| 239 | struct msgb *msg; |
| 240 | |
| 241 | /* Mandatory emelent! */ |
| 242 | OSMO_ASSERT(ei); |
| 243 | |
| 244 | msg = |
| 245 | msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 246 | "cipher-mode-command"); |
| 247 | if (!msg) |
| 248 | return NULL; |
| 249 | |
| 250 | /* Message Type 3.2.2.1 */ |
| 251 | msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_CMD); |
| 252 | |
| 253 | /* Encryption Information 3.2.2.10 */ |
| 254 | gsm0808_enc_encrypt_info(msg, ei); |
| 255 | |
| 256 | /* Cipher Response Mode 3.2.2.34 */ |
| 257 | if (cipher_response_mode) |
| 258 | msgb_tv_put(msg, GSM0808_IE_CIPHER_RESPONSE_MODE, |
| 259 | *cipher_response_mode); |
| 260 | |
| 261 | /* pre-pend the header */ |
| 262 | msg->l3h = |
| 263 | msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 264 | |
| 265 | return msg; |
| 266 | } |
| 267 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 268 | /*! Create BSSMAP Cipher Mode Complete message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 269 | * \param[in] layer3 L3 Message to be included |
| 270 | * \param[in] alg_id Chosen Encrpytion Algorithm |
| 271 | * \returns callee-allocated msgb with BSSMAP Cipher Mode Complete message */ |
Holger Hans Peter Freyther | 81716d5 | 2010-04-17 06:16:35 +0200 | [diff] [blame] | 272 | struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id) |
| 273 | { |
| 274 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 275 | "cipher-complete"); |
| 276 | if (!msg) |
| 277 | return NULL; |
| 278 | |
| 279 | /* send response with BSS override for A5/1... cheating */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 280 | msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_COMPLETE); |
Holger Hans Peter Freyther | 81716d5 | 2010-04-17 06:16:35 +0200 | [diff] [blame] | 281 | |
| 282 | /* include layer3 in case we have at least two octets */ |
| 283 | if (layer3 && msgb_l3len(layer3) > 2) { |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 284 | msg->l4h = msgb_tlv_put(msg, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS, |
| 285 | msgb_l3len(layer3), layer3->l3h); |
Holger Hans Peter Freyther | 81716d5 | 2010-04-17 06:16:35 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Vadim Yanitskiy | ecaf5fa | 2020-08-31 19:10:39 +0700 | [diff] [blame] | 288 | /* Optional Chosen Encryption Algorithm IE */ |
| 289 | if (alg_id > 0) |
| 290 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, alg_id); |
Holger Hans Peter Freyther | 81716d5 | 2010-04-17 06:16:35 +0200 | [diff] [blame] | 291 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 292 | /* pre-pend the header */ |
| 293 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 294 | |
Holger Hans Peter Freyther | 81716d5 | 2010-04-17 06:16:35 +0200 | [diff] [blame] | 295 | return msg; |
| 296 | } |
| 297 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 298 | /*! Create BSSMAP Cipher Mode Reject message |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 299 | * \param[in] cause 3GPP TS 08.08 §3.2.2.5 cause value |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 300 | * \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */ |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 301 | struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause) |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 302 | { |
| 303 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 304 | "bssmap: cipher mode reject"); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 305 | if (!msg) |
| 306 | return NULL; |
| 307 | |
Harald Welte | 62e4085 | 2017-12-17 20:50:34 +0100 | [diff] [blame] | 308 | msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT); |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 309 | |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 310 | gsm0808_enc_cause(msg, cause); |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 311 | |
| 312 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 313 | |
| 314 | return msg; |
| 315 | } |
| 316 | |
Max | ed651d2 | 2018-11-07 15:25:05 +0100 | [diff] [blame] | 317 | /*! Create BSSMAP Cipher Mode Reject message |
| 318 | * \param[in] class 3GPP TS 08.08 §3.2.2.5 cause's class |
| 319 | * \param[in] ext 3GPP TS 08.08 §3.2.2.5 cause value (national application extension) |
| 320 | * \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */ |
| 321 | struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext) |
| 322 | { |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 323 | uint16_t cause; |
Max | ed651d2 | 2018-11-07 15:25:05 +0100 | [diff] [blame] | 324 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 325 | "bssmap: cipher mode reject"); |
| 326 | if (!msg) |
| 327 | return NULL; |
| 328 | |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 329 | /* Set cause code class in the upper byte */ |
| 330 | cause = 0x80 | (class << 4); |
| 331 | cause = cause << 8; |
| 332 | |
| 333 | /* Set cause code extension in the lower byte */ |
| 334 | cause |= ext; |
Max | ed651d2 | 2018-11-07 15:25:05 +0100 | [diff] [blame] | 335 | |
| 336 | msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT); |
| 337 | |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 338 | gsm0808_enc_cause(msg, cause); |
Max | ed651d2 | 2018-11-07 15:25:05 +0100 | [diff] [blame] | 339 | |
| 340 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 341 | |
| 342 | return msg; |
| 343 | } |
| 344 | |
Harald Welte | 64e807c | 2018-05-29 21:00:56 +0200 | [diff] [blame] | 345 | /*! Create BSSMAP LCLS CONNECT CONTROL message (TS 48.008 3.2.1.91). |
| 346 | * \param[in] config LCLS Configuration |
| 347 | * \param[in] control LCLS Connection Status Control |
| 348 | * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */ |
Max | 45f89c9 | 2018-12-19 19:35:26 +0100 | [diff] [blame] | 349 | struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config, |
| 350 | enum gsm0808_lcls_control control) |
Harald Welte | 64e807c | 2018-05-29 21:00:56 +0200 | [diff] [blame] | 351 | { |
Max | 45f89c9 | 2018-12-19 19:35:26 +0100 | [diff] [blame] | 352 | struct msgb *msg; |
| 353 | |
| 354 | /* According to NOTE 1 in §3.2.1.91 at least one of the parameters is required */ |
| 355 | if (config == GSM0808_LCLS_CFG_NA && control == GSM0808_LCLS_CSC_NA) |
| 356 | return NULL; |
| 357 | |
| 358 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "bssmap: LCLS CONN CTRL"); |
Harald Welte | 64e807c | 2018-05-29 21:00:56 +0200 | [diff] [blame] | 359 | if (!msg) |
| 360 | return NULL; |
| 361 | |
| 362 | msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL); |
Max | 45f89c9 | 2018-12-19 19:35:26 +0100 | [diff] [blame] | 363 | if (config != GSM0808_LCLS_CFG_NA) |
| 364 | msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, config); |
| 365 | if (control != GSM0808_LCLS_CSC_NA) |
| 366 | msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, control); |
Harald Welte | 64e807c | 2018-05-29 21:00:56 +0200 | [diff] [blame] | 367 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 368 | |
| 369 | return msg; |
| 370 | } |
| 371 | |
| 372 | /*! Create BSSMAP LCLS CONNECT CONTROL ACK message (TS 48.008 3.2.1.92). |
| 373 | * \param[in] status LCLS BSS Status |
| 374 | * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */ |
| 375 | struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status) |
| 376 | { |
| 377 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 378 | "bssmap: LCLS CONN CTRL ACK"); |
| 379 | if (!msg) |
| 380 | return NULL; |
| 381 | |
| 382 | msgb_v_put(msg, BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK); |
| 383 | msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status); |
| 384 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 385 | |
| 386 | return msg; |
| 387 | } |
| 388 | |
| 389 | /*! Create BSSMAP LCLS NOTIFICATION message (TS 48.008 3.2.1.93). |
| 390 | * \param[in] status LCLS BSS Status |
| 391 | * \param[in] break_req Include the LCLS BREAK REQ IE (true) or not (false) |
| 392 | * \returns callee-allocated msgb with BSSMAP LCLS NOTIFICATION */ |
| 393 | struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req) |
| 394 | { |
| 395 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 396 | "bssmap: LCLS NOTIFICATION"); |
| 397 | if (!msg) |
| 398 | return NULL; |
| 399 | |
| 400 | msgb_v_put(msg, BSS_MAP_MSG_LCLS_NOTIFICATION); |
| 401 | msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status); |
| 402 | if (break_req) |
| 403 | msgb_v_put(msg, GSM0808_IE_LCLS_BREAK_REQ); |
| 404 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 405 | |
| 406 | return msg; |
| 407 | } |
| 408 | |
Neels Hofmeyr | 2c79d55 | 2018-09-13 05:36:32 +0200 | [diff] [blame] | 409 | /*! Create BSSMAP Classmark Request message |
| 410 | * \returns callee-allocated msgb with BSSMAP Classmark Request message */ |
| 411 | struct msgb *gsm0808_create_classmark_request() |
| 412 | { |
| 413 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 414 | "classmark-request"); |
| 415 | if (!msg) |
| 416 | return NULL; |
| 417 | |
| 418 | msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_RQST); |
| 419 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 420 | return msg; |
| 421 | } |
Harald Welte | 64e807c | 2018-05-29 21:00:56 +0200 | [diff] [blame] | 422 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 423 | /*! Create BSSMAP Classmark Update message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 424 | * \param[in] cm2 Classmark 2 |
| 425 | * \param[in] cm2_len length (in octets) of \a cm2 |
| 426 | * \param[in] cm3 Classmark 3 |
| 427 | * \param[in] cm3_len length (in octets) of \a cm3 |
| 428 | * \returns callee-allocated msgb with BSSMAP Classmark Update message */ |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 429 | struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len, |
| 430 | const uint8_t *cm3, uint8_t cm3_len) |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 431 | { |
| 432 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 433 | "classmark-update"); |
| 434 | if (!msg) |
| 435 | return NULL; |
| 436 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 437 | msgb_v_put(msg, BSS_MAP_MSG_CLASSMARK_UPDATE); |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 438 | msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T2, cm2_len, cm2); |
| 439 | if (cm3) |
| 440 | msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T3, |
| 441 | cm3_len, cm3); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 442 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 443 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 444 | |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 445 | return msg; |
| 446 | } |
| 447 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 448 | /*! Create BSSMAP SAPI N Reject message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 449 | * \param[in] link_id Link Identifier |
Vadim Yanitskiy | fa6cd88 | 2020-08-26 18:03:59 +0700 | [diff] [blame] | 450 | * \param[in] cause BSSAP Cause value (see 3GPP TS 48.008, section 3.2.2.5) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 451 | * \returns callee-allocated msgb with BSSMAP SAPI N Reject message */ |
Vadim Yanitskiy | fa6cd88 | 2020-08-26 18:03:59 +0700 | [diff] [blame] | 452 | struct msgb *gsm0808_create_sapi_reject_cause(uint8_t link_id, uint16_t cause) |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 453 | { |
| 454 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 455 | "bssmap: sapi 'n' reject"); |
| 456 | if (!msg) |
| 457 | return NULL; |
| 458 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 459 | msgb_v_put(msg, BSS_MAP_MSG_SAPI_N_REJECT); |
Alexander Chemeris | a5b1b86 | 2020-05-12 01:03:08 +0300 | [diff] [blame] | 460 | msgb_tv_put(msg, GSM0808_IE_DLCI, link_id); |
Vadim Yanitskiy | fa6cd88 | 2020-08-26 18:03:59 +0700 | [diff] [blame] | 461 | gsm0808_enc_cause(msg, cause); |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 462 | |
| 463 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 464 | |
| 465 | return msg; |
| 466 | } |
| 467 | |
Vadim Yanitskiy | fa6cd88 | 2020-08-26 18:03:59 +0700 | [diff] [blame] | 468 | /*! Create BSSMAP SAPI N Reject message (with hard-coded cause "BSS not equipped"). |
| 469 | * DEPRECATED: use gsm0808_create_sapi_reject_cause() instead. |
| 470 | * \param[in] link_id Link Identifier |
| 471 | * \param[in] cause BSSAP Cause value (see 3GPP TS 48.008, section 3.2.2.5) |
| 472 | * \returns callee-allocated msgb with BSSMAP SAPI N Reject message */ |
| 473 | struct msgb *gsm0808_create_sapi_reject(uint8_t link_id) |
| 474 | { |
| 475 | return gsm0808_create_sapi_reject_cause(link_id, GSM0808_CAUSE_BSS_NOT_EQUIPPED); |
| 476 | } |
| 477 | |
Max | 5207432 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 478 | /*! Create BSSMAP Assignment Request message, 3GPP TS 48.008 §3.2.1.1. |
| 479 | * This is identical to gsm0808_create_ass(), but adds KC and LCLS IEs. |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 480 | * \param[in] ct Channel Type |
| 481 | * \param[in] cic Circuit Identity Code (Classic A only) |
| 482 | * \param[in] ss Socket Address of MSC-side RTP socket (AoIP only) |
| 483 | * \param[in] scl Speech Codec List (AoIP only) |
Max | 49c0668 | 2018-11-21 22:10:26 +0100 | [diff] [blame] | 484 | * \param[in] ci Call Identifier (Optional), §3.2.2.105 |
Max | 5207432 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 485 | * \param[in] kc Kc128 ciphering key (Optional, A5/4), §3.2.2.109 |
| 486 | * \param[in] lcls Optional LCLS parameters |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 487 | * \returns callee-allocated msgb with BSSMAP Assignment Request message */ |
Max | 5207432 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 488 | struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct, |
| 489 | const uint16_t *cic, |
| 490 | const struct sockaddr_storage *ss, |
| 491 | const struct gsm0808_speech_codec_list *scl, |
| 492 | const uint32_t *ci, |
| 493 | const uint8_t *kc, const struct osmo_lcls *lcls) |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 494 | { |
| 495 | /* See also: 3GPP TS 48.008 3.2.1.1 ASSIGNMENT REQUEST */ |
| 496 | struct msgb *msg; |
| 497 | uint16_t cic_sw; |
| 498 | uint32_t ci_sw; |
| 499 | |
| 500 | /* Mandatory emelent! */ |
| 501 | OSMO_ASSERT(ct); |
| 502 | |
| 503 | msg = |
| 504 | msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 505 | "bssmap: ass req"); |
| 506 | if (!msg) |
| 507 | return NULL; |
| 508 | |
| 509 | /* Message Type 3.2.2.1 */ |
| 510 | msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_RQST); |
| 511 | |
| 512 | /* Channel Type 3.2.2.11 */ |
| 513 | gsm0808_enc_channel_type(msg, ct); |
| 514 | |
| 515 | /* Circuit Identity Code 3.2.2.2 */ |
| 516 | if (cic) { |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 517 | cic_sw = osmo_htons(*cic); |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 518 | msgb_tv_fixed_put(msg, GSM0808_IE_CIRCUIT_IDENTITY_CODE, |
| 519 | sizeof(cic_sw), (uint8_t *) & cic_sw); |
| 520 | } |
| 521 | |
| 522 | /* AoIP: AoIP Transport Layer Address (MGW) 3.2.2.102 */ |
| 523 | if (ss) { |
| 524 | gsm0808_enc_aoip_trasp_addr(msg, ss); |
| 525 | } |
| 526 | |
| 527 | /* AoIP: Codec List (MSC Preferred) 3.2.2.103 */ |
| 528 | if (scl) |
| 529 | gsm0808_enc_speech_codec_list(msg, scl); |
| 530 | |
| 531 | /* AoIP: Call Identifier 3.2.2.105 */ |
| 532 | if (ci) { |
Philipp Maier | 2908dbf | 2020-06-05 14:16:11 +0200 | [diff] [blame] | 533 | /* NOTE: 3GPP TS 48.008, section 3.2.2.105 specifies that |
| 534 | the least significant byte should be transmitted first. |
| 535 | On x86, this would mean that the endieness is already |
| 536 | correct, however a platform independed implementation |
| 537 | is required: */ |
| 538 | #ifndef OSMO_IS_LITTLE_ENDIAN |
| 539 | ci_sw = osmo_swab32(*ci); |
| 540 | #else |
| 541 | ci_sw = *ci; |
| 542 | #endif |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 543 | msgb_tv_fixed_put(msg, GSM0808_IE_CALL_ID, sizeof(ci_sw), |
| 544 | (uint8_t *) & ci_sw); |
| 545 | } |
| 546 | |
Max | 5207432 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 547 | if (kc) |
| 548 | msgb_tv_fixed_put(msg, GSM0808_IE_KC_128, 16, kc); |
| 549 | |
Max | 4702215 | 2018-12-19 18:51:00 +0100 | [diff] [blame] | 550 | if (lcls) |
| 551 | gsm0808_enc_lcls(msg, lcls); |
Max | 5207432 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 552 | |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 553 | /* push the bssmap header */ |
| 554 | msg->l3h = |
| 555 | msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 556 | |
| 557 | return msg; |
| 558 | } |
| 559 | |
Max | 5207432 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 560 | /*! Create BSSMAP Assignment Request message, 3GPP TS 48.008 §3.2.1.1. |
| 561 | * \param[in] ct Channel Type |
| 562 | * \param[in] cic Circuit Identity Code (Classic A only) |
| 563 | * \param[in] ss Socket Address of MSC-side RTP socket (AoIP only) |
| 564 | * \param[in] scl Speech Codec List (AoIP only) |
| 565 | * \param[in] ci Call Identifier (Optional), §3.2.2.105 |
| 566 | * \returns callee-allocated msgb with BSSMAP Assignment Request message */ |
| 567 | struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct, |
| 568 | const uint16_t *cic, |
| 569 | const struct sockaddr_storage *ss, |
| 570 | const struct gsm0808_speech_codec_list *scl, |
| 571 | const uint32_t *ci) |
| 572 | { |
| 573 | return gsm0808_create_ass2(ct, cic, ss, scl, ci, NULL, NULL); |
| 574 | } |
| 575 | |
Max | 414c8f5 | 2019-01-08 14:44:24 +0100 | [diff] [blame] | 576 | /*! Create BSSMAP Assignment Completed message as per 3GPP TS 48.008 §3.2.1.2 |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 577 | * \param[in] rr_cause GSM 04.08 RR Cause value |
| 578 | * \param[in] chosen_channel Chosen Channel |
| 579 | * \param[in] encr_alg_id Encryption Algorithm ID |
| 580 | * \param[in] speech_mode Speech Mode |
| 581 | * \param[in] ss Socket Address of BSS-side RTP socket |
| 582 | * \param[in] sc Speech Codec (current) |
| 583 | * \param[in] scl Speech Codec List (permitted) |
Max | 414c8f5 | 2019-01-08 14:44:24 +0100 | [diff] [blame] | 584 | * \param[in] lcls_bss_status §3.2.2.119 LCLS-BSS-Status, optional |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 585 | * \returns callee-allocated msgb with BSSMAP Assignment Complete message */ |
Max | 414c8f5 | 2019-01-08 14:44:24 +0100 | [diff] [blame] | 586 | struct msgb *gsm0808_create_ass_compl2(uint8_t rr_cause, uint8_t chosen_channel, |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 587 | uint8_t encr_alg_id, uint8_t speech_mode, |
| 588 | const struct sockaddr_storage *ss, |
| 589 | const struct gsm0808_speech_codec *sc, |
Max | 414c8f5 | 2019-01-08 14:44:24 +0100 | [diff] [blame] | 590 | const struct gsm0808_speech_codec_list *scl, |
| 591 | enum gsm0808_lcls_status lcls_bss_status) |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 592 | { |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 593 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 594 | "bssmap: ass compl"); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 595 | if (!msg) |
| 596 | return NULL; |
| 597 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 598 | msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_COMPLETE); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 599 | |
| 600 | /* write 3.2.2.22 */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 601 | msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, rr_cause); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 602 | |
| 603 | /* write cirtcuit identity code 3.2.2.2 */ |
| 604 | /* write cell identifier 3.2.2.17 */ |
| 605 | /* write chosen channel 3.2.2.33 when BTS picked it */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 606 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, chosen_channel); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 607 | |
| 608 | /* write chosen encryption algorithm 3.2.2.44 */ |
Vadim Yanitskiy | ecaf5fa | 2020-08-31 19:10:39 +0700 | [diff] [blame] | 609 | if (encr_alg_id > 0) |
| 610 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, encr_alg_id); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 611 | |
| 612 | /* write circuit pool 3.2.2.45 */ |
| 613 | /* write speech version chosen: 3.2.2.51 when BTS picked it */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 614 | if (speech_mode != 0) |
| 615 | msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, speech_mode); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 616 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 617 | /* AoIP: AoIP Transport Layer Address (BSS) 3.2.2.102 */ |
| 618 | if (ss) |
| 619 | gsm0808_enc_aoip_trasp_addr(msg, ss); |
| 620 | |
| 621 | /* AoIP: Speech Codec (Chosen) 3.2.2.104 */ |
| 622 | if (sc) |
| 623 | gsm0808_enc_speech_codec(msg, sc); |
| 624 | |
| 625 | /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */ |
| 626 | if (scl) |
| 627 | gsm0808_enc_speech_codec_list(msg, scl); |
| 628 | |
Max | 414c8f5 | 2019-01-08 14:44:24 +0100 | [diff] [blame] | 629 | /* FIXME: write LSA identifier 3.2.2.15 - see 3GPP TS 43.073 */ |
| 630 | |
| 631 | /* LCLS-BSS-Status 3.2.2.119 */ |
| 632 | if (lcls_bss_status != GSM0808_LCLS_STS_NA) |
| 633 | msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, lcls_bss_status); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 634 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 635 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 636 | |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 637 | return msg; |
| 638 | } |
| 639 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 640 | /*! Create BSSMAP Assignment Completed message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 641 | * \param[in] rr_cause GSM 04.08 RR Cause value |
| 642 | * \param[in] chosen_channel Chosen Channel |
| 643 | * \param[in] encr_alg_id Encryption Algorithm ID |
| 644 | * \param[in] speech_mode Speech Mode |
Max | 414c8f5 | 2019-01-08 14:44:24 +0100 | [diff] [blame] | 645 | * \param[in] ss Socket Address of BSS-side RTP socket |
| 646 | * \param[in] sc Speech Codec (current) |
| 647 | * \param[in] scl Speech Codec List (permitted) |
| 648 | * \returns callee-allocated msgb with BSSMAP Assignment Complete message */ |
| 649 | struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel, |
| 650 | uint8_t encr_alg_id, uint8_t speech_mode, |
| 651 | const struct sockaddr_storage *ss, |
| 652 | const struct gsm0808_speech_codec *sc, |
| 653 | const struct gsm0808_speech_codec_list *scl) |
| 654 | { |
| 655 | return gsm0808_create_ass_compl2(rr_cause, chosen_channel, encr_alg_id, speech_mode, |
| 656 | ss, sc, scl, GSM0808_LCLS_STS_NA); |
| 657 | } |
| 658 | |
| 659 | /*! Create BSSMAP Assignment Completed message |
| 660 | * \param[in] rr_cause GSM 04.08 RR Cause value |
| 661 | * \param[in] chosen_channel Chosen Channel |
| 662 | * \param[in] encr_alg_id Encryption Algorithm ID |
| 663 | * \param[in] speech_mode Speech Mode |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 664 | * \returns callee-allocated msgb with BSSMAP Assignment Complete message */ |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 665 | struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause, |
| 666 | uint8_t chosen_channel, |
| 667 | uint8_t encr_alg_id, |
| 668 | uint8_t speech_mode) |
| 669 | { |
Max | 414c8f5 | 2019-01-08 14:44:24 +0100 | [diff] [blame] | 670 | return gsm0808_create_ass_compl2(rr_cause, chosen_channel, encr_alg_id, |
| 671 | speech_mode, NULL, NULL, NULL, GSM0808_LCLS_STS_NA); |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 672 | } |
| 673 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 674 | /*! Create BSSMAP Assignment Failure message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 675 | * \param[in] cause BSSMAP Cause value |
| 676 | * \param[in] rr_cause GSM 04.08 RR Cause value |
| 677 | * \param[in] scl Optional Speech Cdec List (AoIP) |
| 678 | * \returns callee-allocated msgb with BSSMAP Assignment Failure message */ |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 679 | struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause, |
| 680 | const struct gsm0808_speech_codec_list |
| 681 | *scl) |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 682 | { |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 683 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 684 | "bssmap: ass fail"); |
| 685 | if (!msg) |
| 686 | return NULL; |
| 687 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 688 | msgb_v_put(msg, BSS_MAP_MSG_ASSIGMENT_FAILURE); |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 689 | gsm0808_enc_cause(msg, cause); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 690 | |
| 691 | /* RR cause 3.2.2.22 */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 692 | if (rr_cause) |
| 693 | msgb_tv_put(msg, GSM0808_IE_RR_CAUSE, *rr_cause); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 694 | |
| 695 | /* Circuit pool 3.22.45 */ |
| 696 | /* Circuit pool list 3.2.2.46 */ |
| 697 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 698 | /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */ |
| 699 | if (scl) |
| 700 | gsm0808_enc_speech_codec_list(msg, scl); |
| 701 | |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 702 | /* update the size */ |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 703 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 704 | |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 705 | return msg; |
| 706 | } |
Holger Hans Peter Freyther | 7daa01c | 2010-04-17 05:14:36 +0200 | [diff] [blame] | 707 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 708 | /*! Create BSSMAP Assignment Failure message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 709 | * \param[in] cause BSSMAP Cause value |
| 710 | * \param[in] rr_cause GSM 04.08 RR Cause value |
| 711 | * \returns callee-allocated msgb with BSSMAP Assignment Failure message */ |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 712 | struct msgb *gsm0808_create_assignment_failure(uint8_t cause, |
| 713 | uint8_t *rr_cause) |
| 714 | { |
| 715 | return gsm0808_create_ass_fail(cause, rr_cause, NULL); |
| 716 | } |
| 717 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 718 | /*! Create BSSMAP Clear Request message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 719 | * \param[in] cause BSSMAP Cause value |
| 720 | * \returns callee-allocated msgb with BSSMAP Clear Request message */ |
Holger Hans Peter Freyther | af270a4 | 2010-11-04 12:42:50 +0100 | [diff] [blame] | 721 | struct msgb *gsm0808_create_clear_rqst(uint8_t cause) |
| 722 | { |
| 723 | struct msgb *msg; |
| 724 | |
| 725 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 726 | "bssmap: clear rqst"); |
| 727 | if (!msg) |
| 728 | return NULL; |
| 729 | |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 730 | msgb_v_put(msg, BSS_MAP_MSG_CLEAR_RQST); |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 731 | gsm0808_enc_cause(msg, cause); |
Harald Welte | 65c2d36 | 2012-01-21 14:26:01 +0100 | [diff] [blame] | 732 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
Holger Hans Peter Freyther | af270a4 | 2010-11-04 12:42:50 +0100 | [diff] [blame] | 733 | |
Holger Hans Peter Freyther | af270a4 | 2010-11-04 12:42:50 +0100 | [diff] [blame] | 734 | return msg; |
| 735 | } |
| 736 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 737 | /*! Create BSSMAP PAGING message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 738 | * \param[in] imsi Mandatory paged IMSI in string representation |
| 739 | * \param[in] tmsi Optional paged TMSI |
Stefan Sperling | 3953f41 | 2018-08-28 15:06:30 +0200 | [diff] [blame] | 740 | * \param[in] cil Mandatory Cell Identity List (where to page) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 741 | * \param[in] chan_needed Channel Type needed |
| 742 | * \returns callee-allocated msgb with BSSMAP PAGING message */ |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 743 | struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi, |
| 744 | const struct gsm0808_cell_id_list2 *cil, |
| 745 | const uint8_t *chan_needed) |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 746 | { |
| 747 | struct msgb *msg; |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 748 | uint8_t mid_buf[GSM48_MI_SIZE + 2]; |
| 749 | int mid_len; |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 750 | uint32_t tmsi_sw; |
| 751 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 752 | /* Mandatory elements! */ |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 753 | OSMO_ASSERT(imsi); |
| 754 | OSMO_ASSERT(cil); |
| 755 | |
| 756 | /* Malformed IMSI */ |
| 757 | OSMO_ASSERT(strlen(imsi) <= GSM48_MI_SIZE); |
| 758 | |
| 759 | msg = |
| 760 | msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "paging"); |
| 761 | if (!msg) |
| 762 | return NULL; |
| 763 | |
| 764 | /* Message Type 3.2.2.1 */ |
| 765 | msgb_v_put(msg, BSS_MAP_MSG_PAGING); |
| 766 | |
Stefan Sperling | 3953f41 | 2018-08-28 15:06:30 +0200 | [diff] [blame] | 767 | /* mandatory IMSI 3.2.2.6 */ |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 768 | mid_len = gsm48_generate_mid_from_imsi(mid_buf, imsi); |
| 769 | msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 770 | |
| 771 | /* TMSI 3.2.2.7 */ |
| 772 | if (tmsi) { |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 773 | tmsi_sw = osmo_htonl(*tmsi); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 774 | msgb_tlv_put(msg, GSM0808_IE_TMSI, sizeof(*tmsi), |
| 775 | (uint8_t *) & tmsi_sw); |
| 776 | } |
| 777 | |
Stefan Sperling | 3953f41 | 2018-08-28 15:06:30 +0200 | [diff] [blame] | 778 | /* mandatory Cell Identifier List 3.2.2.27 */ |
| 779 | gsm0808_enc_cell_id_list2(msg, cil); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 780 | |
| 781 | /* Channel Needed 3.2.2.36 */ |
| 782 | if (chan_needed) { |
| 783 | msgb_tv_put(msg, GSM0808_IE_CHANNEL_NEEDED, |
| 784 | (*chan_needed) & 0x03); |
| 785 | } |
| 786 | |
| 787 | /* pre-pend the header */ |
| 788 | msg->l3h = |
| 789 | msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 790 | |
| 791 | return msg; |
| 792 | } |
| 793 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 794 | /*! DEPRECATED: Use gsm0808_create_paging2 instead. |
| 795 | * Create BSSMAP PAGING message. |
| 796 | * \param[in] imsi Mandatory paged IMSI in string representation |
| 797 | * \param[in] tmsi Optional paged TMSI |
| 798 | * \param[in] cil Cell Identity List (where to page) |
| 799 | * \param[in] chan_needed Channel Type needed |
| 800 | * \returns callee-allocated msgb with BSSMAP PAGING message */ |
| 801 | struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi, |
| 802 | const struct gsm0808_cell_id_list *cil, |
| 803 | const uint8_t *chan_needed) |
| 804 | { |
| 805 | struct gsm0808_cell_id_list2 cil2 = {}; |
| 806 | |
| 807 | /* Mandatory emelents! */ |
| 808 | OSMO_ASSERT(cil); |
| 809 | |
| 810 | if (cil->id_list_len > GSM0808_CELL_ID_LIST2_MAXLEN) |
| 811 | return NULL; |
| 812 | |
| 813 | cil2.id_discr = cil->id_discr; |
| 814 | memcpy(cil2.id_list, cil->id_list_lac, cil->id_list_len * sizeof(cil2.id_list[0].lac)); |
| 815 | cil2.id_list_len = cil->id_list_len; |
| 816 | |
| 817 | return gsm0808_create_paging2(imsi, tmsi, &cil2, chan_needed); |
| 818 | } |
| 819 | |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 820 | static uint8_t put_old_bss_to_new_bss_information(struct msgb *msg, |
| 821 | const struct gsm0808_old_bss_to_new_bss_info *i) |
| 822 | { |
| 823 | uint8_t *old_tail; |
| 824 | uint8_t *tlv_len; |
| 825 | |
| 826 | msgb_put_u8(msg, GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION); |
| 827 | tlv_len = msgb_put(msg, 1); |
| 828 | old_tail = msg->tail; |
| 829 | |
| 830 | if (i->extra_information_present) { |
| 831 | uint8_t val = 0; |
| 832 | if (i->extra_information.prec) |
| 833 | val |= 1 << 0; |
| 834 | if (i->extra_information.lcs) |
| 835 | val |= 1 << 1; |
| 836 | if (i->extra_information.ue_prob) |
| 837 | val |= 1 << 2; |
| 838 | msgb_tlv_put(msg, GSM0808_FE_IE_EXTRA_INFORMATION, 1, &val); |
| 839 | } |
| 840 | |
| 841 | if (i->current_channel_type_2_present) { |
| 842 | uint8_t val[2] = { |
| 843 | i->current_channel_type_2.mode, |
| 844 | i->current_channel_type_2.field, |
| 845 | }; |
| 846 | msgb_tlv_put(msg, GSM0808_FE_IE_CURRENT_CHANNEL_TYPE_2, 2, val); |
| 847 | } |
| 848 | |
| 849 | *tlv_len = (uint8_t) (msg->tail - old_tail); |
| 850 | return *tlv_len + 2; |
| 851 | } |
| 852 | |
| 853 | /*! Create BSSMAP HANDOVER REQUIRED message. |
| 854 | * \param[in] params All information to be encoded. |
Neels Hofmeyr | 302aafc | 2019-04-10 19:23:45 +0200 | [diff] [blame] | 855 | * \returns newly allocated msgb with BSSMAP HANDOVER REQUIRED message. */ |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 856 | struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params) |
| 857 | { |
| 858 | struct msgb *msg; |
| 859 | |
| 860 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUIRED"); |
| 861 | if (!msg) |
| 862 | return NULL; |
| 863 | |
| 864 | /* Message Type, 3.2.2.1 */ |
| 865 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_REQUIRED); |
| 866 | |
| 867 | /* Cause, 3.2.2.5 */ |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 868 | gsm0808_enc_cause(msg, params->cause); |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 869 | |
| 870 | /* Cell Identifier List, 3.2.2.27 */ |
| 871 | gsm0808_enc_cell_id_list2(msg, ¶ms->cil); |
| 872 | |
| 873 | /* Current Channel Type 1, 3.2.2.49 */ |
| 874 | if (params->current_channel_type_1_present) |
| 875 | msgb_tv_fixed_put(msg, GSM0808_IE_CURRENT_CHANNEL_TYPE_1, 1, ¶ms->current_channel_type_1); |
| 876 | |
| 877 | /* Speech Version (Used), 3.2.2.51 */ |
| 878 | if (params->speech_version_used_present) |
Neels Hofmeyr | 302aafc | 2019-04-10 19:23:45 +0200 | [diff] [blame] | 879 | msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_used); |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 880 | |
| 881 | if (params->old_bss_to_new_bss_info_present) |
| 882 | put_old_bss_to_new_bss_information(msg, ¶ms->old_bss_to_new_bss_info); |
| 883 | |
| 884 | /* pre-pend the header */ |
| 885 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 886 | |
| 887 | return msg; |
| 888 | } |
| 889 | |
Neels Hofmeyr | f7e9c51 | 2019-03-06 04:25:38 +0100 | [diff] [blame] | 890 | /*! Create BSSMAP HANDOVER REQUIRED REJECT message. |
| 891 | * \returns newly allocated msgb with BSSMAP HANDOVER REQUIRED REJECT message. */ |
| 892 | struct msgb *gsm0808_create_handover_required_reject(const struct gsm0808_handover_required_reject *params) |
| 893 | { |
| 894 | struct msgb *msg; |
| 895 | |
| 896 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUIRED-REJECT"); |
| 897 | if (!msg) |
| 898 | return NULL; |
| 899 | |
| 900 | /* Message Type, 3.2.2.1 */ |
| 901 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT); |
| 902 | |
| 903 | /* Cause, 3.2.2.5 */ |
| 904 | gsm0808_enc_cause(msg, params->cause); |
| 905 | |
| 906 | /* prepend the header */ |
| 907 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 908 | |
| 909 | return msg; |
| 910 | } |
| 911 | |
| 912 | /*! Create BSSMAP HANDOVER REQUEST message, 3GPP TS 48.008 3.2.1.8. |
| 913 | * Sent from the MSC to the potential new target cell during inter-BSC handover, or to the target MSC during inter-MSC |
| 914 | * handover. |
| 915 | */ |
| 916 | struct msgb *gsm0808_create_handover_request(const struct gsm0808_handover_request *params) |
| 917 | { |
| 918 | struct msgb *msg; |
| 919 | |
| 920 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUEST"); |
| 921 | if (!msg) |
| 922 | return NULL; |
| 923 | |
| 924 | /* Message Type, 3.2.2.1 */ |
| 925 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_RQST); |
| 926 | |
| 927 | /* Channel Type 3.2.2.11 */ |
| 928 | gsm0808_enc_channel_type(msg, ¶ms->channel_type); |
| 929 | |
| 930 | /* Encryption Information 3.2.2.10 */ |
| 931 | gsm0808_enc_encrypt_info(msg, ¶ms->encryption_information); |
| 932 | |
| 933 | /* Classmark Information 1 3.2.2.30 or Classmark Information 2 3.2.2.19 (Classmark 2 wins) */ |
| 934 | if (params->classmark_information.classmark2_len) { |
| 935 | msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T2, |
| 936 | params->classmark_information.classmark2_len, |
| 937 | (const uint8_t*)¶ms->classmark_information.classmark2); |
| 938 | } else if (params->classmark_information.classmark1_set) { |
| 939 | msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1, |
| 940 | sizeof(params->classmark_information.classmark1), |
| 941 | (const uint8_t*)¶ms->classmark_information.classmark1); |
| 942 | } |
| 943 | /* (Classmark 3 possibly follows below) */ |
| 944 | |
| 945 | /* Cell Identifier (Serving) , 3.2.2.17 */ |
| 946 | gsm0808_enc_cell_id(msg, ¶ms->cell_identifier_serving); |
| 947 | |
| 948 | /* Cell Identifier (Target) , 3.2.2.17 */ |
| 949 | gsm0808_enc_cell_id(msg, ¶ms->cell_identifier_target); |
| 950 | |
| 951 | /* Cause, 3.2.2.5 */ |
| 952 | gsm0808_enc_cause(msg, params->cause); |
| 953 | |
| 954 | /* Classmark Information 3 3.2.2.20 */ |
| 955 | if (params->classmark_information.classmark3_len) { |
| 956 | msgb_tlv_put(msg, GSM0808_IE_CLASSMARK_INFORMATION_T3, |
| 957 | params->classmark_information.classmark3_len, |
| 958 | (const uint8_t*)¶ms->classmark_information.classmark3); |
| 959 | } |
| 960 | |
| 961 | /* Current Channel type 1 3.2.2.49 */ |
| 962 | if (params->current_channel_type_1_present) |
| 963 | msgb_tv_fixed_put(msg, GSM0808_IE_CURRENT_CHANNEL_TYPE_1, 1, ¶ms->current_channel_type_1); |
| 964 | |
| 965 | /* Speech Version (Used), 3.2.2.51 */ |
| 966 | if (params->speech_version_used) { |
| 967 | msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_used); |
| 968 | } |
| 969 | |
| 970 | /* Chosen Encryption Algorithm (Serving) 3.2.2.44 */ |
Vadim Yanitskiy | ecaf5fa | 2020-08-31 19:10:39 +0700 | [diff] [blame] | 971 | if (params->chosen_encryption_algorithm_serving > 0) |
Neels Hofmeyr | f7e9c51 | 2019-03-06 04:25:38 +0100 | [diff] [blame] | 972 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encryption_algorithm_serving); |
| 973 | |
| 974 | /* Old BSS to New BSS Information 3.2.2.58 */ |
| 975 | if (params->old_bss_to_new_bss_info_raw && params->old_bss_to_new_bss_info_raw_len) { |
| 976 | msgb_tlv_put(msg, GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION, |
| 977 | params->old_bss_to_new_bss_info_raw_len, |
| 978 | params->old_bss_to_new_bss_info_raw); |
| 979 | } else if (params->old_bss_to_new_bss_info_present) { |
| 980 | put_old_bss_to_new_bss_information(msg, ¶ms->old_bss_to_new_bss_info); |
| 981 | } |
| 982 | |
| 983 | /* IMSI 3.2.2.6 */ |
| 984 | if (params->imsi) { |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 985 | uint8_t mid_buf[GSM48_MI_SIZE + 2]; |
| 986 | int mid_len = gsm48_generate_mid_from_imsi(mid_buf, params->imsi); |
| 987 | msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2); |
Neels Hofmeyr | f7e9c51 | 2019-03-06 04:25:38 +0100 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | if (params->aoip_transport_layer) |
| 991 | gsm0808_enc_aoip_trasp_addr(msg, params->aoip_transport_layer); |
| 992 | |
| 993 | if (params->codec_list_msc_preferred) |
| 994 | gsm0808_enc_speech_codec_list(msg, params->codec_list_msc_preferred); |
| 995 | |
| 996 | if (params->call_id_present) { |
| 997 | uint8_t val[4]; |
| 998 | osmo_store32le(params->call_id, val); |
| 999 | msgb_tv_fixed_put(msg, GSM0808_IE_CALL_ID, 4, val); |
| 1000 | } |
| 1001 | |
| 1002 | if (params->global_call_reference && params->global_call_reference_len) { |
| 1003 | msgb_tlv_put(msg, GSM0808_IE_GLOBAL_CALL_REF, |
| 1004 | params->global_call_reference_len, params->global_call_reference); |
| 1005 | } |
| 1006 | |
| 1007 | /* prepend header with final length */ |
| 1008 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1009 | |
| 1010 | return msg; |
| 1011 | } |
| 1012 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1013 | /*! Create BSSMAP HANDOVER REQUEST ACKNOWLEDGE message, 3GPP TS 48.008 3.2.1.10. |
| 1014 | * Sent from the MT BSC back to the MSC when it has allocated an lchan to handover to. |
| 1015 | * l3_info is the RR Handover Command that the MO BSC sends to the MS to move over. */ |
Neels Hofmeyr | 73b943e | 2019-03-14 04:10:25 +0100 | [diff] [blame] | 1016 | struct msgb *gsm0808_create_handover_request_ack2(const struct gsm0808_handover_request_ack *params) |
Neels Hofmeyr | b662b36 | 2018-04-16 22:31:15 +0200 | [diff] [blame] | 1017 | { |
| 1018 | struct msgb *msg; |
| 1019 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1020 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-REQUEST-ACK"); |
Neels Hofmeyr | b662b36 | 2018-04-16 22:31:15 +0200 | [diff] [blame] | 1021 | if (!msg) |
| 1022 | return NULL; |
| 1023 | |
| 1024 | /* Message Type, 3.2.2.1 */ |
| 1025 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE); |
| 1026 | |
Neels Hofmeyr | 73b943e | 2019-03-14 04:10:25 +0100 | [diff] [blame] | 1027 | /* Layer 3 Information, 3.2.2.24 -- it is actually mandatory, but rather compose a nonstandard message than |
| 1028 | * segfault or return NULL without a log message. */ |
| 1029 | if (params->l3_info && params->l3_info_len) |
| 1030 | msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, params->l3_info_len, params->l3_info); |
Neels Hofmeyr | b662b36 | 2018-04-16 22:31:15 +0200 | [diff] [blame] | 1031 | |
Neels Hofmeyr | 73b943e | 2019-03-14 04:10:25 +0100 | [diff] [blame] | 1032 | if (params->chosen_channel_present) |
| 1033 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, params->chosen_channel); |
Vadim Yanitskiy | ecaf5fa | 2020-08-31 19:10:39 +0700 | [diff] [blame] | 1034 | if (params->chosen_encr_alg > 0) |
Neels Hofmeyr | 73b943e | 2019-03-14 04:10:25 +0100 | [diff] [blame] | 1035 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg); |
| 1036 | |
| 1037 | if (params->chosen_speech_version != 0) |
| 1038 | msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->chosen_speech_version); |
| 1039 | |
| 1040 | if (params->aoip_transport_layer) |
| 1041 | gsm0808_enc_aoip_trasp_addr(msg, params->aoip_transport_layer); |
| 1042 | |
| 1043 | /* AoIP: Speech Codec (Chosen) 3.2.2.104 */ |
| 1044 | if (params->speech_codec_chosen_present) |
| 1045 | gsm0808_enc_speech_codec(msg, ¶ms->speech_codec_chosen); |
Neels Hofmeyr | b662b36 | 2018-04-16 22:31:15 +0200 | [diff] [blame] | 1046 | |
Neels Hofmeyr | 43c266f | 2018-08-28 01:08:38 +0200 | [diff] [blame] | 1047 | /* prepend header with final length */ |
| 1048 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1049 | |
Neels Hofmeyr | b662b36 | 2018-04-16 22:31:15 +0200 | [diff] [blame] | 1050 | return msg; |
| 1051 | } |
| 1052 | |
Neels Hofmeyr | 73b943e | 2019-03-14 04:10:25 +0100 | [diff] [blame] | 1053 | /*! Same as gsm0808_create_handover_request_ack2() but with less parameters. |
| 1054 | * In particular, this lacks the AoIP Transport Layer address. */ |
| 1055 | struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len, |
| 1056 | uint8_t chosen_channel, uint8_t chosen_encr_alg, |
| 1057 | uint8_t chosen_speech_version) |
| 1058 | { |
| 1059 | struct gsm0808_handover_request_ack params = { |
| 1060 | .l3_info = l3_info, |
| 1061 | .l3_info_len = l3_info_len, |
| 1062 | .chosen_channel = chosen_channel, |
| 1063 | .chosen_encr_alg = chosen_encr_alg, |
| 1064 | .chosen_speech_version = chosen_speech_version, |
| 1065 | }; |
| 1066 | |
| 1067 | return gsm0808_create_handover_request_ack2(¶ms); |
| 1068 | } |
| 1069 | |
Neels Hofmeyr | f7e9c51 | 2019-03-06 04:25:38 +0100 | [diff] [blame] | 1070 | /*! Create BSSMAP HANDOVER COMMAND message, 3GPP TS 48.008 3.2.1.11. |
| 1071 | * Sent from the MSC to the old BSS to transmit the RR Handover Command received from the new BSS. */ |
| 1072 | struct msgb *gsm0808_create_handover_command(const struct gsm0808_handover_command *params) |
| 1073 | { |
| 1074 | struct msgb *msg; |
| 1075 | |
| 1076 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-COMMAND"); |
| 1077 | if (!msg) |
| 1078 | return NULL; |
| 1079 | |
| 1080 | /* Message Type, 3.2.2.1 */ |
| 1081 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_CMD); |
| 1082 | |
| 1083 | msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION, params->l3_info_len, params->l3_info); |
| 1084 | |
| 1085 | if (params->cell_identifier.id_discr != CELL_IDENT_NO_CELL) |
| 1086 | gsm0808_enc_cell_id(msg, ¶ms->cell_identifier); |
| 1087 | |
| 1088 | if (params->new_bss_to_old_bss_info_raw |
| 1089 | && params->new_bss_to_old_bss_info_raw_len) |
| 1090 | msgb_tlv_put(msg, GSM0808_IE_NEW_BSS_TO_OLD_BSS_INFO, params->new_bss_to_old_bss_info_raw_len, |
| 1091 | params->new_bss_to_old_bss_info_raw); |
| 1092 | |
| 1093 | /* prepend header with final length */ |
| 1094 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1095 | |
| 1096 | return msg; |
| 1097 | } |
| 1098 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1099 | /*! Create BSSMAP HANDOVER DETECT message, 3GPP TS 48.008 3.2.1.40. |
| 1100 | * Sent from the MT BSC back to the MSC when the MS has sent a handover RACH request and the MT BSC has |
| 1101 | * received the Handover Detect message. */ |
| 1102 | struct msgb *gsm0808_create_handover_detect() |
| 1103 | { |
| 1104 | struct msgb *msg; |
| 1105 | |
| 1106 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-DETECT"); |
| 1107 | if (!msg) |
| 1108 | return NULL; |
| 1109 | |
| 1110 | /* Message Type, 3.2.2.1 */ |
| 1111 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_DETECT); |
| 1112 | |
Neels Hofmeyr | 43c266f | 2018-08-28 01:08:38 +0200 | [diff] [blame] | 1113 | /* prepend header with final length */ |
| 1114 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1115 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1116 | return msg; |
| 1117 | } |
| 1118 | |
Neels Hofmeyr | f7e9c51 | 2019-03-06 04:25:38 +0100 | [diff] [blame] | 1119 | /*! Create BSSMAP HANDOVER SUCCEEDED message, 3GPP TS 48.008 3.2.1.13. |
| 1120 | * Sent from the MSC back to the old BSS to notify that the MS has successfully accessed the new BSS. */ |
| 1121 | struct msgb *gsm0808_create_handover_succeeded() |
| 1122 | { |
| 1123 | struct msgb *msg; |
| 1124 | |
| 1125 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-DETECT"); |
| 1126 | if (!msg) |
| 1127 | return NULL; |
| 1128 | |
| 1129 | /* Message Type, 3.2.2.1 */ |
| 1130 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_SUCCEEDED); |
| 1131 | |
| 1132 | /* prepend header with final length */ |
| 1133 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1134 | |
| 1135 | return msg; |
| 1136 | } |
| 1137 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1138 | /*! Create BSSMAP HANDOVER COMPLETE message, 3GPP TS 48.008 3.2.1.12. |
| 1139 | * Sent from the MT BSC back to the MSC when the MS has fully settled into the new lchan. */ |
| 1140 | struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params) |
| 1141 | { |
| 1142 | struct msgb *msg; |
| 1143 | |
| 1144 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-COMPLETE"); |
| 1145 | if (!msg) |
| 1146 | return NULL; |
| 1147 | |
| 1148 | /* Message Type, 3.2.2.1 */ |
| 1149 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_COMPLETE); |
| 1150 | |
| 1151 | /* RR Cause, 3.2.2.22 */ |
| 1152 | if (params->rr_cause_present) |
| 1153 | msgb_tlv_put(msg, GSM0808_IE_RR_CAUSE, 1, ¶ms->rr_cause); |
| 1154 | |
| 1155 | /* AoIP: Speech Codec (Chosen) 3.2.2.104 */ |
| 1156 | if (params->speech_codec_chosen_present) |
| 1157 | gsm0808_enc_speech_codec(msg, ¶ms->speech_codec_chosen); |
| 1158 | |
| 1159 | /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */ |
| 1160 | if (params->codec_list_bss_supported.len) |
| 1161 | gsm0808_enc_speech_codec_list(msg, ¶ms->codec_list_bss_supported); |
| 1162 | |
| 1163 | /* Chosen Encryption Algorithm 3.2.2.44 */ |
Vadim Yanitskiy | ecaf5fa | 2020-08-31 19:10:39 +0700 | [diff] [blame] | 1164 | if (params->chosen_encr_alg_present && params->chosen_encr_alg > 0) |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1165 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg); |
| 1166 | |
| 1167 | /* LCLS-BSS-Status 3.2.2.119 */ |
| 1168 | if (params->lcls_bss_status_present) |
| 1169 | msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, params->lcls_bss_status); |
| 1170 | |
Neels Hofmeyr | 43c266f | 2018-08-28 01:08:38 +0200 | [diff] [blame] | 1171 | /* prepend header with final length */ |
| 1172 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1173 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1174 | return msg; |
| 1175 | } |
| 1176 | |
| 1177 | /*! Create BSSMAP HANDOVER FAILURE message, 3GPP TS 48.008 3.2.1.16. |
| 1178 | * Sent from the MT BSC back to the MSC when the handover has failed. */ |
| 1179 | struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params) |
| 1180 | { |
| 1181 | struct msgb *msg; |
| 1182 | |
| 1183 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-FAILURE"); |
| 1184 | if (!msg) |
| 1185 | return NULL; |
| 1186 | |
| 1187 | /* Message Type, 3.2.2.1 */ |
| 1188 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_FAILURE); |
| 1189 | |
| 1190 | /* Cause, 3.2.2.5 */ |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 1191 | gsm0808_enc_cause(msg, params->cause); |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1192 | |
| 1193 | /* RR Cause, 3.2.2.22 */ |
| 1194 | if (params->rr_cause_present) |
| 1195 | msgb_tlv_put(msg, GSM0808_IE_RR_CAUSE, 1, ¶ms->rr_cause); |
| 1196 | |
| 1197 | /* AoIP: add Codec List (BSS Supported) 3.2.2.103 */ |
| 1198 | if (params->codec_list_bss_supported.len) |
| 1199 | gsm0808_enc_speech_codec_list(msg, ¶ms->codec_list_bss_supported); |
| 1200 | |
Neels Hofmeyr | 43c266f | 2018-08-28 01:08:38 +0200 | [diff] [blame] | 1201 | /* prepend header with final length */ |
| 1202 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1203 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 1204 | return msg; |
| 1205 | } |
| 1206 | |
Philipp Maier | 225bdf4 | 2018-10-30 14:56:59 +0100 | [diff] [blame] | 1207 | /*! Create BSSMAP HANDOVER PERFORMED message, 3GPP TS 48.008 3.2.1.25. |
| 1208 | * \param[in] params All information to be encoded. |
| 1209 | * \returns callee-allocated msgb with BSSMAP HANDOVER PERFORMED message */ |
| 1210 | struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params) |
| 1211 | { |
| 1212 | struct msgb *msg; |
| 1213 | |
| 1214 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-HANDOVER-PERFORMED"); |
| 1215 | if (!msg) |
| 1216 | return NULL; |
| 1217 | |
| 1218 | /* Message Type, 3.2.2.1 */ |
| 1219 | msgb_v_put(msg, BSS_MAP_MSG_HANDOVER_PERFORMED); |
| 1220 | |
| 1221 | /* Cause, 3.2.2.5 */ |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 1222 | gsm0808_enc_cause(msg, params->cause); |
Philipp Maier | 225bdf4 | 2018-10-30 14:56:59 +0100 | [diff] [blame] | 1223 | |
| 1224 | /* Cell Identifier, 3.2.2.17 */ |
| 1225 | gsm0808_enc_cell_id(msg, ¶ms->cell_id); |
| 1226 | |
| 1227 | /* Chosen Channel 3.2.2.33 */ |
| 1228 | if (params->chosen_channel_present) |
| 1229 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_CHANNEL, params->chosen_channel); |
| 1230 | |
| 1231 | /* Chosen Encryption Algorithm 3.2.2.44 */ |
Vadim Yanitskiy | ecaf5fa | 2020-08-31 19:10:39 +0700 | [diff] [blame] | 1232 | if (params->chosen_encr_alg_present && params->chosen_encr_alg > 0) |
Philipp Maier | 225bdf4 | 2018-10-30 14:56:59 +0100 | [diff] [blame] | 1233 | msgb_tv_put(msg, GSM0808_IE_CHOSEN_ENCR_ALG, params->chosen_encr_alg); |
| 1234 | |
| 1235 | /* Speech Version (chosen) 3.2.2.51 */ |
| 1236 | if (params->speech_version_chosen_present) |
| 1237 | msgb_tv_put(msg, GSM0808_IE_SPEECH_VERSION, params->speech_version_chosen); |
| 1238 | |
| 1239 | /* AoIP: Speech Codec (chosen) 3.2.2.104 */ |
| 1240 | if (params->speech_codec_chosen_present) |
| 1241 | gsm0808_enc_speech_codec(msg, ¶ms->speech_codec_chosen); |
| 1242 | |
| 1243 | /* LCLS-BSS-Status 3.2.2.119 */ |
| 1244 | if (params->lcls_bss_status_present) |
| 1245 | msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, params->lcls_bss_status); |
| 1246 | |
| 1247 | /* prepend header with final length */ |
| 1248 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1249 | |
| 1250 | return msg; |
| 1251 | } |
| 1252 | |
Neels Hofmeyr | 9b35e56 | 2020-06-22 17:59:18 +0200 | [diff] [blame] | 1253 | /*! Create BSSMAP COMMON ID message, 3GPP TS 48.008 3.2.1.68. |
| 1254 | * \param[in] imsi IMSI digits (decimal string). |
| 1255 | * \param[in] selected_plmn_id Selected PLMN ID to encode, or NULL to not encode this IE. |
| 1256 | * \param[in] last_used_eutran_plnm_id Last used E-UTRAN PLMN ID to encode, or NULL to not encode this IE. |
| 1257 | * \returns callee-allocated msgb with BSSMAP COMMON ID message, or NULL if encoding failed. */ |
Harald Welte | 1bd726a | 2020-06-21 22:04:52 +0200 | [diff] [blame] | 1258 | struct msgb *gsm0808_create_common_id(const char *imsi, |
| 1259 | const struct osmo_plmn_id *selected_plmn_id, |
| 1260 | const struct osmo_plmn_id *last_used_eutran_plnm_id) |
| 1261 | { |
| 1262 | struct msgb *msg; |
Harald Welte | 1bd726a | 2020-06-21 22:04:52 +0200 | [diff] [blame] | 1263 | uint8_t *out; |
Neels Hofmeyr | 9b35e56 | 2020-06-22 17:59:18 +0200 | [diff] [blame] | 1264 | struct osmo_mobile_identity mi; |
| 1265 | int rc; |
Harald Welte | 1bd726a | 2020-06-21 22:04:52 +0200 | [diff] [blame] | 1266 | |
| 1267 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "COMMON-ID"); |
| 1268 | if (!msg) |
| 1269 | return NULL; |
| 1270 | |
| 1271 | /* Message Type, 3.2.2.1 */ |
| 1272 | msgb_v_put(msg, BSS_MAP_MSG_COMMON_ID); |
| 1273 | |
| 1274 | /* mandatory IMSI 3.2.2.6 */ |
Neels Hofmeyr | 9b35e56 | 2020-06-22 17:59:18 +0200 | [diff] [blame] | 1275 | mi = (struct osmo_mobile_identity){ .type = GSM_MI_TYPE_IMSI }; |
| 1276 | OSMO_STRLCPY_ARRAY(mi.imsi, imsi); |
| 1277 | out = msgb_tl_put(msg, GSM0808_IE_IMSI); |
| 1278 | rc = osmo_mobile_identity_encode_msgb(msg, &mi, false); |
| 1279 | if (rc < 0) { |
| 1280 | msgb_free(msg); |
| 1281 | return NULL; |
| 1282 | } |
| 1283 | /* write the MI value length */ |
| 1284 | *out = rc; |
Harald Welte | 1bd726a | 2020-06-21 22:04:52 +0200 | [diff] [blame] | 1285 | |
| 1286 | /* not implemented: SNA Access Information */ |
| 1287 | |
| 1288 | /* Selected PLMN ID */ |
| 1289 | if (selected_plmn_id) { |
| 1290 | msgb_v_put(msg, GSM0808_IE_SELECTED_PLMN_ID); |
| 1291 | out = msgb_put(msg, 3); |
| 1292 | osmo_plmn_to_bcd(out, selected_plmn_id); |
| 1293 | } |
| 1294 | |
| 1295 | /* Last used E-UTRAN PLMN ID */ |
| 1296 | if (last_used_eutran_plnm_id) { |
| 1297 | msgb_v_put(msg, GSM0808_IE_LAST_USED_EUTRAN_PLMN_ID); |
| 1298 | out = msgb_put(msg, 3); |
| 1299 | osmo_plmn_to_bcd(out, last_used_eutran_plnm_id); |
| 1300 | } |
| 1301 | |
| 1302 | /* prepend header with final length */ |
| 1303 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1304 | |
| 1305 | return msg; |
| 1306 | } |
| 1307 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1308 | /*! Prepend a DTAP header to given Message Buffer |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1309 | * \param[in] msgb Message Buffer |
| 1310 | * \param[in] link_id Link Identifier */ |
Holger Hans Peter Freyther | 9a3dec0 | 2010-05-16 08:15:40 +0800 | [diff] [blame] | 1311 | void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id) |
| 1312 | { |
| 1313 | uint8_t *hh = msgb_push(msg, 3); |
| 1314 | hh[0] = BSSAP_MSG_DTAP; |
| 1315 | hh[1] = link_id; |
| 1316 | hh[2] = msg->len - 3; |
| 1317 | } |
| 1318 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1319 | /*! Create BSSMAP DTAP message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1320 | * \param[in] msg_l3 Messge Buffer containing Layer3 message |
| 1321 | * \param[in] link_id Link Identifier |
| 1322 | * \returns callee-allocated msgb with BSSMAP DTAP message */ |
Holger Hans Peter Freyther | c25c668 | 2010-11-04 12:26:06 +0100 | [diff] [blame] | 1323 | struct msgb *gsm0808_create_dtap(struct msgb *msg_l3, uint8_t link_id) |
| 1324 | { |
| 1325 | struct dtap_header *header; |
| 1326 | uint8_t *data; |
| 1327 | struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, |
| 1328 | "dtap"); |
| 1329 | if (!msg) |
| 1330 | return NULL; |
| 1331 | |
| 1332 | /* DTAP header */ |
| 1333 | msg->l3h = msgb_put(msg, sizeof(*header)); |
| 1334 | header = (struct dtap_header *) &msg->l3h[0]; |
| 1335 | header->type = BSSAP_MSG_DTAP; |
| 1336 | header->link_id = link_id; |
| 1337 | header->length = msgb_l3len(msg_l3); |
| 1338 | |
| 1339 | /* Payload */ |
| 1340 | data = msgb_put(msg, header->length); |
| 1341 | memcpy(data, msg_l3->l3h, header->length); |
| 1342 | |
| 1343 | return msg; |
| 1344 | } |
| 1345 | |
Neels Hofmeyr | 5b214e2 | 2020-09-18 18:00:50 +0200 | [diff] [blame] | 1346 | struct msgb *gsm0808_create_perform_location_request(const struct gsm0808_perform_location_request *params) |
| 1347 | { |
| 1348 | struct msgb *msg; |
| 1349 | uint8_t *out; |
| 1350 | int rc; |
| 1351 | |
| 1352 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-REQUEST"); |
| 1353 | if (!msg) |
| 1354 | return NULL; |
| 1355 | |
| 1356 | /* Message Type, 3.2.2.1 */ |
| 1357 | msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_RQST); |
| 1358 | |
| 1359 | /* Location Type 3.2.2.63 */ |
| 1360 | osmo_bssmap_le_ie_enc_location_type(msg, ¶ms->location_type); |
| 1361 | |
| 1362 | if (params->imsi.type == GSM_MI_TYPE_IMSI) { |
| 1363 | /* IMSI 3.2.2.6 */ |
| 1364 | out = msgb_tl_put(msg, GSM0808_IE_IMSI); |
| 1365 | rc = osmo_mobile_identity_encode_msgb(msg, ¶ms->imsi, false); |
| 1366 | if (rc < 0) { |
| 1367 | msgb_free(msg); |
| 1368 | return NULL; |
| 1369 | } |
| 1370 | /* write the MI value length */ |
| 1371 | *out = rc; |
| 1372 | } |
| 1373 | |
| 1374 | /* prepend header with final length */ |
| 1375 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1376 | |
| 1377 | return msg; |
| 1378 | } |
| 1379 | |
| 1380 | struct msgb *gsm0808_create_perform_location_response(const struct gsm0808_perform_location_response *params) |
| 1381 | { |
| 1382 | struct msgb *msg; |
| 1383 | |
| 1384 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-RESPONSE"); |
| 1385 | if (!msg) |
| 1386 | return NULL; |
| 1387 | |
| 1388 | /* Message Type, 3.2.2.1 */ |
| 1389 | msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE); |
| 1390 | |
| 1391 | if (params->location_estimate_present) { |
| 1392 | uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LOCATION_ESTIMATE); |
| 1393 | int rc = osmo_gad_raw_write(msg, ¶ms->location_estimate); |
| 1394 | if (rc < 0) { |
| 1395 | msgb_free(msg); |
| 1396 | return NULL; |
| 1397 | } |
| 1398 | *l = rc; |
| 1399 | } |
| 1400 | |
| 1401 | if (params->lcs_cause.present) { |
| 1402 | uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LCS_CAUSE); |
| 1403 | int rc = osmo_lcs_cause_enc(msg, ¶ms->lcs_cause); |
| 1404 | if (rc < 0) { |
| 1405 | msgb_free(msg); |
| 1406 | return NULL; |
| 1407 | } |
| 1408 | *l = rc; |
| 1409 | } |
| 1410 | |
| 1411 | /* prepend header with final length */ |
| 1412 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1413 | |
| 1414 | return msg; |
| 1415 | } |
| 1416 | |
| 1417 | int gsm0808_enc_lcs_cause(struct msgb *msg, const struct lcs_cause_ie *lcs_cause) |
| 1418 | { |
| 1419 | uint8_t *l = msgb_tl_put(msg, GSM0808_IE_LCS_CAUSE); |
| 1420 | int rc = osmo_lcs_cause_enc(msg, lcs_cause); |
| 1421 | if (rc <= 0) |
| 1422 | return rc; |
| 1423 | *l = rc; |
| 1424 | return rc + 2; |
| 1425 | } |
| 1426 | |
| 1427 | struct msgb *gsm0808_create_perform_location_abort(const struct lcs_cause_ie *lcs_cause) |
| 1428 | { |
| 1429 | struct msgb *msg; |
| 1430 | |
| 1431 | msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "BSSMAP-PERFORM-LOCATION-ABORT"); |
| 1432 | if (!msg) |
| 1433 | return NULL; |
| 1434 | |
| 1435 | /* Message Type, 3.2.2.1 */ |
| 1436 | msgb_v_put(msg, BSS_MAP_MSG_PERFORM_LOCATION_ABORT); |
| 1437 | |
| 1438 | gsm0808_enc_lcs_cause(msg, lcs_cause); |
| 1439 | |
| 1440 | /* prepend header with final length */ |
| 1441 | msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); |
| 1442 | |
| 1443 | return msg; |
| 1444 | } |
| 1445 | |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1446 | /* As per 3GPP TS 48.008 version 11.7.0 Release 11 */ |
Holger Hans Peter Freyther | 7daa01c | 2010-04-17 05:14:36 +0200 | [diff] [blame] | 1447 | static const struct tlv_definition bss_att_tlvdef = { |
| 1448 | .def = { |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1449 | [GSM0808_IE_CIRCUIT_IDENTITY_CODE] = { TLV_TYPE_FIXED, 2 }, |
| 1450 | [GSM0808_IE_CONNECTION_RELEASE_RQSTED] = { TLV_TYPE_TV }, |
| 1451 | [GSM0808_IE_RESOURCE_AVAILABLE] = { TLV_TYPE_FIXED, 21 }, |
| 1452 | [GSM0808_IE_CAUSE] = { TLV_TYPE_TLV }, |
Holger Hans Peter Freyther | 7daa01c | 2010-04-17 05:14:36 +0200 | [diff] [blame] | 1453 | [GSM0808_IE_IMSI] = { TLV_TYPE_TLV }, |
| 1454 | [GSM0808_IE_TMSI] = { TLV_TYPE_TLV }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1455 | [GSM0808_IE_NUMBER_OF_MSS] = { TLV_TYPE_TV }, |
Dmitri Soloviev | 2909942 | 2013-07-11 09:25:37 +0200 | [diff] [blame] | 1456 | [GSM0808_IE_LAYER_3_HEADER_INFORMATION] = { TLV_TYPE_TLV }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1457 | [GSM0808_IE_ENCRYPTION_INFORMATION] = { TLV_TYPE_TLV }, |
| 1458 | [GSM0808_IE_CHANNEL_TYPE] = { TLV_TYPE_TLV }, |
| 1459 | [GSM0808_IE_PERIODICITY] = { TLV_TYPE_TV }, |
| 1460 | [GSM0808_IE_EXTENDED_RESOURCE_INDICATOR]= { TLV_TYPE_TV }, |
| 1461 | [GSM0808_IE_TOTAL_RESOURCE_ACCESSIBLE] = { TLV_TYPE_FIXED, 4 }, |
| 1462 | [GSM0808_IE_LSA_IDENTIFIER] = { TLV_TYPE_TLV }, |
| 1463 | [GSM0808_IE_LSA_IDENTIFIER_LIST] = { TLV_TYPE_TLV }, |
Holger Hans Peter Freyther | 715e945 | 2014-08-21 14:17:45 +0200 | [diff] [blame] | 1464 | [GSM0808_IE_LSA_INFORMATION] = { TLV_TYPE_TLV }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1465 | [GSM0808_IE_CELL_IDENTIFIER] = { TLV_TYPE_TLV }, |
| 1466 | [GSM0808_IE_PRIORITY] = { TLV_TYPE_TLV }, |
| 1467 | [GSM0808_IE_CLASSMARK_INFORMATION_T2] = { TLV_TYPE_TLV }, |
| 1468 | [GSM0808_IE_CLASSMARK_INFORMATION_T3] = { TLV_TYPE_TLV }, |
| 1469 | [GSM0808_IE_INTERFERENCE_BAND_TO_USE] = { TLV_TYPE_TV }, |
| 1470 | [GSM0808_IE_RR_CAUSE] = { TLV_TYPE_TV }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1471 | [GSM0808_IE_LAYER_3_INFORMATION] = { TLV_TYPE_TLV }, |
| 1472 | [GSM0808_IE_DLCI] = { TLV_TYPE_TV }, |
| 1473 | [GSM0808_IE_DOWNLINK_DTX_FLAG] = { TLV_TYPE_TV }, |
| 1474 | [GSM0808_IE_CELL_IDENTIFIER_LIST] = { TLV_TYPE_TLV }, |
| 1475 | [GSM0808_IE_CELL_ID_LIST_SEGMENT] = { TLV_TYPE_TLV }, |
| 1476 | [GSM0808_IE_CELL_ID_LIST_SEG_EST_CELLS] = { TLV_TYPE_TLV }, |
| 1477 | [GSM0808_IE_CELL_ID_LIST_SEG_CELLS_TBE] = { TLV_TYPE_TLV }, |
| 1478 | [GSM0808_IE_CELL_ID_LIST_SEG_REL_CELLS] = { TLV_TYPE_TLV }, |
| 1479 | [GSM0808_IE_CELL_ID_LIST_SEG_NE_CELLS] = { TLV_TYPE_TLV }, |
| 1480 | [GSM0808_IE_RESPONSE_RQST] = { TLV_TYPE_T }, |
| 1481 | [GSM0808_IE_RESOURCE_INDICATION_METHOD] = { TLV_TYPE_TV }, |
| 1482 | [GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1] = { TLV_TYPE_TV }, |
| 1483 | [GSM0808_IE_CIRCUIT_IDENTITY_CODE_LIST] = { TLV_TYPE_TLV }, |
| 1484 | [GSM0808_IE_DIAGNOSTIC] = { TLV_TYPE_TLV }, |
| 1485 | [GSM0808_IE_CHOSEN_CHANNEL] = { TLV_TYPE_TV }, |
| 1486 | [GSM0808_IE_CIPHER_RESPONSE_MODE] = { TLV_TYPE_TV }, |
| 1487 | [GSM0808_IE_LAYER_3_MESSAGE_CONTENTS] = { TLV_TYPE_TLV }, |
| 1488 | [GSM0808_IE_CHANNEL_NEEDED] = { TLV_TYPE_TV }, |
| 1489 | [GSM0808_IE_TRACE_TYPE] = { TLV_TYPE_TV }, |
| 1490 | [GSM0808_IE_TRIGGERID] = { TLV_TYPE_TLV }, |
| 1491 | [GSM0808_IE_TRACE_REFERENCE] = { TLV_TYPE_TV }, |
| 1492 | [GSM0808_IE_TRANSACTIONID] = { TLV_TYPE_TLV }, |
| 1493 | [GSM0808_IE_MOBILE_IDENTITY] = { TLV_TYPE_TLV }, |
| 1494 | [GSM0808_IE_OMCID] = { TLV_TYPE_TLV }, |
| 1495 | [GSM0808_IE_FORWARD_INDICATOR] = { TLV_TYPE_TV }, |
Holger Hans Peter Freyther | c2b7f92 | 2010-08-04 18:50:43 +0800 | [diff] [blame] | 1496 | [GSM0808_IE_CHOSEN_ENCR_ALG] = { TLV_TYPE_TV }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1497 | [GSM0808_IE_CIRCUIT_POOL] = { TLV_TYPE_TV }, |
| 1498 | [GSM0808_IE_CIRCUIT_POOL_LIST] = { TLV_TYPE_TLV }, |
| 1499 | [GSM0808_IE_TIME_INDICATION] = { TLV_TYPE_TV }, |
| 1500 | [GSM0808_IE_RESOURCE_SITUATION] = { TLV_TYPE_TLV }, |
| 1501 | [GSM0808_IE_CURRENT_CHANNEL_TYPE_1] = { TLV_TYPE_TV }, |
| 1502 | [GSM0808_IE_QUEUEING_INDICATOR] = { TLV_TYPE_TV }, |
| 1503 | [GSM0808_IE_SPEECH_VERSION] = { TLV_TYPE_TV }, |
| 1504 | [GSM0808_IE_ASSIGNMENT_REQUIREMENT] = { TLV_TYPE_TV }, |
| 1505 | [GSM0808_IE_TALKER_FLAG] = { TLV_TYPE_T }, |
| 1506 | [GSM0808_IE_GROUP_CALL_REFERENCE] = { TLV_TYPE_TLV }, |
| 1507 | [GSM0808_IE_EMLPP_PRIORITY] = { TLV_TYPE_TV }, |
| 1508 | [GSM0808_IE_CONFIG_EVO_INDI] = { TLV_TYPE_TV }, |
| 1509 | [GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION] = { TLV_TYPE_TLV }, |
| 1510 | [GSM0808_IE_LCS_QOS] = { TLV_TYPE_TLV }, |
| 1511 | [GSM0808_IE_LSA_ACCESS_CTRL_SUPPR] = { TLV_TYPE_TV }, |
| 1512 | [GSM0808_IE_LCS_PRIORITY] = { TLV_TYPE_TLV }, |
| 1513 | [GSM0808_IE_LOCATION_TYPE] = { TLV_TYPE_TLV }, |
| 1514 | [GSM0808_IE_LOCATION_ESTIMATE] = { TLV_TYPE_TLV }, |
| 1515 | [GSM0808_IE_POSITIONING_DATA] = { TLV_TYPE_TLV }, |
| 1516 | [GSM0808_IE_LCS_CAUSE] = { TLV_TYPE_TLV }, |
| 1517 | [GSM0808_IE_APDU] = { TLV_TYPE_TLV }, |
| 1518 | [GSM0808_IE_NETWORK_ELEMENT_IDENTITY] = { TLV_TYPE_TLV }, |
| 1519 | [GSM0808_IE_GPS_ASSISTANCE_DATA] = { TLV_TYPE_TLV }, |
| 1520 | [GSM0808_IE_DECIPHERING_KEYS] = { TLV_TYPE_TLV }, |
| 1521 | [GSM0808_IE_RETURN_ERROR_RQST] = { TLV_TYPE_TLV }, |
| 1522 | [GSM0808_IE_RETURN_ERROR_CAUSE] = { TLV_TYPE_TLV }, |
| 1523 | [GSM0808_IE_SEGMENTATION] = { TLV_TYPE_TLV }, |
| 1524 | [GSM0808_IE_SERVICE_HANDOVER] = { TLV_TYPE_TLV }, |
| 1525 | [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_UMTS] = { TLV_TYPE_TLV }, |
| 1526 | [GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_CDMA2000] = { TLV_TYPE_TLV }, |
| 1527 | [GSM0808_IE_GERAN_CLASSMARK] = { TLV_TYPE_TLV }, |
| 1528 | [GSM0808_IE_GERAN_BSC_CONTAINER] = { TLV_TYPE_TLV }, |
| 1529 | [GSM0808_IE_NEW_BSS_TO_OLD_BSS_INFO] = { TLV_TYPE_TLV }, |
| 1530 | [GSM0800_IE_INTER_SYSTEM_INFO] = { TLV_TYPE_TLV }, |
| 1531 | [GSM0808_IE_SNA_ACCESS_INFO] = { TLV_TYPE_TLV }, |
| 1532 | [GSM0808_IE_VSTK_RAND_INFO] = { TLV_TYPE_TLV }, |
| 1533 | [GSM0808_IE_PAGING_INFO] = { TLV_TYPE_TV }, |
| 1534 | [GSM0808_IE_IMEI] = { TLV_TYPE_TLV }, |
| 1535 | [GSM0808_IE_VELOCITY_ESTIMATE] = { TLV_TYPE_TLV }, |
| 1536 | [GSM0808_IE_VGCS_FEATURE_FLAGS] = { TLV_TYPE_TLV }, |
| 1537 | [GSM0808_IE_TALKER_PRIORITY] = { TLV_TYPE_TV }, |
| 1538 | [GSM0808_IE_EMERGENCY_SET_INDICATION] = { TLV_TYPE_T }, |
| 1539 | [GSM0808_IE_TALKER_IDENTITY] = { TLV_TYPE_TLV }, |
| 1540 | [GSM0808_IE_SMS_TO_VGCS] = { TLV_TYPE_TLV }, |
| 1541 | [GSM0808_IE_VGCS_TALKER_MODE] = { TLV_TYPE_TLV }, |
| 1542 | [GSM0808_IE_VGCS_VBS_CELL_STATUS] = { TLV_TYPE_TLV }, |
| 1543 | [GSM0808_IE_GANSS_ASSISTANCE_DATA] = { TLV_TYPE_TLV }, |
| 1544 | [GSM0808_IE_GANSS_POSITIONING_DATA] = { TLV_TYPE_TLV }, |
| 1545 | [GSM0808_IE_GANSS_LOCATION_TYPE] = { TLV_TYPE_TLV }, |
| 1546 | [GSM0808_IE_APP_DATA] = { TLV_TYPE_TLV }, |
| 1547 | [GSM0808_IE_DATA_IDENTITY] = { TLV_TYPE_TLV }, |
| 1548 | [GSM0808_IE_APP_DATA_INFO] = { TLV_TYPE_TLV }, |
| 1549 | [GSM0808_IE_MSISDN] = { TLV_TYPE_TLV }, |
| 1550 | [GSM0808_IE_AOIP_TRASP_ADDR] = { TLV_TYPE_TLV }, |
| 1551 | [GSM0808_IE_SPEECH_CODEC_LIST] = { TLV_TYPE_TLV }, |
| 1552 | [GSM0808_IE_SPEECH_CODEC] = { TLV_TYPE_TLV }, |
| 1553 | [GSM0808_IE_CALL_ID] = { TLV_TYPE_FIXED, 4 }, |
| 1554 | [GSM0808_IE_CALL_ID_LIST] = { TLV_TYPE_TLV }, |
| 1555 | [GSM0808_IE_A_IF_SEL_FOR_RESET] = { TLV_TYPE_TV }, |
| 1556 | [GSM0808_IE_KC_128] = { TLV_TYPE_FIXED, 16 }, |
| 1557 | [GSM0808_IE_CSG_IDENTIFIER] = { TLV_TYPE_TLV }, |
| 1558 | [GSM0808_IE_REDIR_ATTEMPT_FLAG] = { TLV_TYPE_T }, |
| 1559 | [GSM0808_IE_REROUTE_REJ_CAUSE] = { TLV_TYPE_TV }, |
| 1560 | [GSM0808_IE_SEND_SEQ_NUM] = { TLV_TYPE_TV }, |
| 1561 | [GSM0808_IE_REROUTE_COMPL_OUTCOME] = { TLV_TYPE_TV }, |
| 1562 | [GSM0808_IE_GLOBAL_CALL_REF] = { TLV_TYPE_TLV }, |
| 1563 | [GSM0808_IE_LCLS_CONFIG] = { TLV_TYPE_TV }, |
| 1564 | [GSM0808_IE_LCLS_CONN_STATUS_CTRL] = { TLV_TYPE_TV }, |
| 1565 | [GSM0808_IE_LCLS_CORR_NOT_NEEDED] = { TLV_TYPE_TV }, |
| 1566 | [GSM0808_IE_LCLS_BSS_STATUS] = { TLV_TYPE_TV }, |
| 1567 | [GSM0808_IE_LCLS_BREAK_REQ] = { TLV_TYPE_TV }, |
| 1568 | [GSM0808_IE_CSFB_INDICATION] = { TLV_TYPE_T }, |
| 1569 | [GSM0808_IE_CS_TO_PS_SRVCC] = { TLV_TYPE_T }, |
| 1570 | [GSM0808_IE_SRC_ENB_TO_TGT_ENB_TRANSP] = { TLV_TYPE_TLV }, |
| 1571 | [GSM0808_IE_CS_TO_PS_SRVCC_IND] = { TLV_TYPE_T }, |
| 1572 | [GSM0808_IE_CN_TO_MS_TRANSP_INFO] = { TLV_TYPE_TLV }, |
| 1573 | [GSM0808_IE_SELECTED_PLMN_ID] = { TLV_TYPE_FIXED, 3 }, |
| 1574 | [GSM0808_IE_LAST_USED_EUTRAN_PLMN_ID] = { TLV_TYPE_FIXED, 3 }, |
Pau Espin Pedrol | 18506c8 | 2019-04-16 15:47:59 +0200 | [diff] [blame] | 1575 | |
| 1576 | /* Osmocom extensions */ |
| 1577 | [GSM0808_IE_OSMO_OSMUX_SUPPORT] = { TLV_TYPE_T }, |
| 1578 | [GSM0808_IE_OSMO_OSMUX_CID] = { TLV_TYPE_TV }, |
Holger Hans Peter Freyther | 7daa01c | 2010-04-17 05:14:36 +0200 | [diff] [blame] | 1579 | }, |
| 1580 | }; |
| 1581 | |
Harald Welte | f4d45ab | 2011-07-16 12:13:00 +0200 | [diff] [blame] | 1582 | const struct tlv_definition *gsm0808_att_tlvdef(void) |
Holger Hans Peter Freyther | 7daa01c | 2010-04-17 05:14:36 +0200 | [diff] [blame] | 1583 | { |
| 1584 | return &bss_att_tlvdef; |
| 1585 | } |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1586 | |
Pau Espin Pedrol | 392f607 | 2019-11-27 12:07:04 +0100 | [diff] [blame] | 1587 | const struct value_string gsm0406_dlci_sapi_names[] = { |
| 1588 | { DLCI_SAPI_RR_MM_CC, "RR/MM/CC" }, |
| 1589 | { DLCI_SAPI_SMS, "SMS" }, |
| 1590 | { 0, NULL } |
| 1591 | }; |
| 1592 | |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1593 | static const struct value_string gsm0808_msgt_names[] = { |
| 1594 | { BSS_MAP_MSG_ASSIGMENT_RQST, "ASSIGNMENT REQ" }, |
| 1595 | { BSS_MAP_MSG_ASSIGMENT_COMPLETE, "ASSIGNMENT COMPL" }, |
| 1596 | { BSS_MAP_MSG_ASSIGMENT_FAILURE, "ASSIGNMENT FAIL" }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1597 | { BSS_MAP_MSG_CHAN_MOD_RQST, "CHANNEL MODIFY REQUEST" }, |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1598 | |
| 1599 | { BSS_MAP_MSG_HANDOVER_RQST, "HANDOVER REQ" }, |
| 1600 | { BSS_MAP_MSG_HANDOVER_REQUIRED, "HANDOVER REQUIRED" }, |
| 1601 | { BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE,"HANDOVER REQ ACK" }, |
| 1602 | { BSS_MAP_MSG_HANDOVER_CMD, "HANDOVER CMD" }, |
| 1603 | { BSS_MAP_MSG_HANDOVER_COMPLETE, "HANDOVER COMPLETE" }, |
| 1604 | { BSS_MAP_MSG_HANDOVER_SUCCEEDED, "HANDOVER SUCCESS" }, |
| 1605 | { BSS_MAP_MSG_HANDOVER_FAILURE, "HANDOVER FAILURE" }, |
| 1606 | { BSS_MAP_MSG_HANDOVER_PERFORMED, "HANDOVER PERFORMED" }, |
| 1607 | { BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE, "HANDOVER CAND ENQ" }, |
| 1608 | { BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE, "HANDOVER CAND RESP" }, |
| 1609 | { BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT, "HANDOVER REQ REJ" }, |
| 1610 | { BSS_MAP_MSG_HANDOVER_DETECT, "HANDOVER DETECT" }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1611 | { BSS_MAP_MSG_INT_HANDOVER_REQUIRED, "INT HANDOVER REQ" }, |
| 1612 | { BSS_MAP_MSG_INT_HANDOVER_REQUIRED_REJ,"INT HANDOVER REQ REJ" }, |
| 1613 | { BSS_MAP_MSG_INT_HANDOVER_CMD, "INT HANDOVER CMD" }, |
| 1614 | { BSS_MAP_MSG_INT_HANDOVER_ENQUIRY, "INT HANDOVER ENQ" }, |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1615 | |
| 1616 | { BSS_MAP_MSG_CLEAR_CMD, "CLEAR COMMAND" }, |
| 1617 | { BSS_MAP_MSG_CLEAR_COMPLETE, "CLEAR COMPLETE" }, |
| 1618 | { BSS_MAP_MSG_CLEAR_RQST, "CLEAR REQUEST" }, |
| 1619 | { BSS_MAP_MSG_SAPI_N_REJECT, "SAPI N REJECT" }, |
| 1620 | { BSS_MAP_MSG_CONFUSION, "CONFUSION" }, |
| 1621 | |
| 1622 | { BSS_MAP_MSG_SUSPEND, "SUSPEND" }, |
| 1623 | { BSS_MAP_MSG_RESUME, "RESUME" }, |
| 1624 | { BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION, "CONN ORIENT INFO" }, |
| 1625 | { BSS_MAP_MSG_PERFORM_LOCATION_RQST, "PERFORM LOC REQ" }, |
| 1626 | { BSS_MAP_MSG_LSA_INFORMATION, "LSA INFORMATION" }, |
| 1627 | { BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE, "PERFORM LOC RESP" }, |
| 1628 | { BSS_MAP_MSG_PERFORM_LOCATION_ABORT, "PERFORM LOC ABORT" }, |
| 1629 | { BSS_MAP_MSG_COMMON_ID, "COMMON ID" }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1630 | { BSS_MAP_MSG_REROUTE_CMD, "REROUTE COMMAND" }, |
| 1631 | { BSS_MAP_MSG_REROUTE_COMPLETE, "REROUTE COMPLETE" }, |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1632 | |
| 1633 | { BSS_MAP_MSG_RESET, "RESET" }, |
| 1634 | { BSS_MAP_MSG_RESET_ACKNOWLEDGE, "RESET ACK" }, |
| 1635 | { BSS_MAP_MSG_OVERLOAD, "OVERLOAD" }, |
| 1636 | { BSS_MAP_MSG_RESET_CIRCUIT, "RESET CIRCUIT" }, |
| 1637 | { BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE, "RESET CIRCUIT ACK" }, |
| 1638 | { BSS_MAP_MSG_MSC_INVOKE_TRACE, "MSC INVOKE TRACE" }, |
| 1639 | { BSS_MAP_MSG_BSS_INVOKE_TRACE, "BSS INVOKE TRACE" }, |
| 1640 | { BSS_MAP_MSG_CONNECTIONLESS_INFORMATION, "CONNLESS INFO" }, |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1641 | { BSS_MAP_MSG_RESET_IP_RSRC, "RESET IP RESOURCE" }, |
| 1642 | { BSS_MAP_MSG_RESET_IP_RSRC_ACK, "RESET IP RESOURCE ACK" }, |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1643 | |
| 1644 | { BSS_MAP_MSG_BLOCK, "BLOCK" }, |
| 1645 | { BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE, "BLOCK ACK" }, |
| 1646 | { BSS_MAP_MSG_UNBLOCK, "UNBLOCK" }, |
| 1647 | { BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE, "UNBLOCK ACK" }, |
| 1648 | { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK, "CIRC GROUP BLOCK" }, |
| 1649 | { BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE, "CIRC GORUP BLOCK ACK" }, |
| 1650 | { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK, "CIRC GROUP UNBLOCK" }, |
| 1651 | { BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE, "CIRC GROUP UNBLOCK ACK" }, |
| 1652 | { BSS_MAP_MSG_UNEQUIPPED_CIRCUIT, "UNEQUIPPED CIRCUIT" }, |
| 1653 | { BSS_MAP_MSG_CHANGE_CIRCUIT, "CHANGE CIRCUIT" }, |
| 1654 | { BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE, "CHANGE CIRCUIT ACK" }, |
| 1655 | |
| 1656 | { BSS_MAP_MSG_RESOURCE_RQST, "RESOURCE REQ" }, |
| 1657 | { BSS_MAP_MSG_RESOURCE_INDICATION, "RESOURCE IND" }, |
| 1658 | { BSS_MAP_MSG_PAGING, "PAGING" }, |
| 1659 | { BSS_MAP_MSG_CIPHER_MODE_CMD, "CIPHER MODE CMD" }, |
| 1660 | { BSS_MAP_MSG_CLASSMARK_UPDATE, "CLASSMARK UPDATE" }, |
| 1661 | { BSS_MAP_MSG_CIPHER_MODE_COMPLETE, "CIPHER MODE COMPLETE" }, |
| 1662 | { BSS_MAP_MSG_QUEUING_INDICATION, "QUEUING INDICATION" }, |
| 1663 | { BSS_MAP_MSG_COMPLETE_LAYER_3, "COMPLETE LAYER 3" }, |
| 1664 | { BSS_MAP_MSG_CLASSMARK_RQST, "CLASSMARK REQ" }, |
| 1665 | { BSS_MAP_MSG_CIPHER_MODE_REJECT, "CIPHER MODE REJECT" }, |
| 1666 | { BSS_MAP_MSG_LOAD_INDICATION, "LOAD IND" }, |
| 1667 | |
Harald Welte | 92107df | 2014-06-21 23:16:20 +0200 | [diff] [blame] | 1668 | { BSS_MAP_MSG_VGCS_VBS_SETUP, "VGCS/VBS SETUP" }, |
| 1669 | { BSS_MAP_MSG_VGCS_VBS_SETUP_ACK, "VGCS/VBS SETUP ACK" }, |
| 1670 | { BSS_MAP_MSG_VGCS_VBS_SETUP_REFUSE, "VGCS/VBS SETUP REFUSE" }, |
| 1671 | { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RQST, "VGCS/VBS ASSIGN REQ" }, |
| 1672 | { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RESULT, "VGCS/VBS ASSIGN RES" }, |
| 1673 | { BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_FAILURE, "VGCS/VBS ASSIGN FAIL" }, |
| 1674 | { BSS_MAP_MSG_VGCS_VBS_QUEUING_INDICATION, "VGCS/VBS QUEUING IND" }, |
| 1675 | { BSS_MAP_MSG_UPLINK_RQST, "UPLINK REQ" }, |
| 1676 | { BSS_MAP_MSG_UPLINK_RQST_ACKNOWLEDGE, "UPLINK REQ ACK" }, |
| 1677 | { BSS_MAP_MSG_UPLINK_RQST_CONFIRMATION, "UPLINK REQ CONF" }, |
| 1678 | { BSS_MAP_MSG_UPLINK_RELEASE_INDICATION,"UPLINK REL IND" }, |
| 1679 | { BSS_MAP_MSG_UPLINK_REJECT_CMD, "UPLINK REJ CMD" }, |
| 1680 | { BSS_MAP_MSG_UPLINK_RELEASE_CMD, "UPLINK REL CMD" }, |
| 1681 | { BSS_MAP_MSG_UPLINK_SEIZED_CMD, "UPLINK SEIZED CMD" }, |
| 1682 | { BSS_MAP_MSG_VGCS_ADDL_INFO, "VGCS ADDL INFO" }, |
| 1683 | { BSS_MAP_MSG_NOTIFICATION_DATA, "NOTIF DATA" }, |
| 1684 | { BSS_MAP_MSG_UPLINK_APP_DATA, "UPLINK APP DATA" }, |
| 1685 | |
| 1686 | { BSS_MAP_MSG_LCLS_CONNECT_CTRL, "LCLS-CONNECT-CONTROL" }, |
| 1687 | { BSS_MAP_MSG_LCLS_CONNECT_CTRL_ACK, "CLS-CONNECT-CONTROL-ACK" }, |
| 1688 | { BSS_MAP_MSG_LCLS_NOTIFICATION, "LCLS-NOTIFICATION" }, |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1689 | |
| 1690 | { 0, NULL } |
| 1691 | }; |
| 1692 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1693 | /*! Return string name of BSSMAP Message Type */ |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1694 | const char *gsm0808_bssmap_name(uint8_t msg_type) |
| 1695 | { |
| 1696 | return get_value_string(gsm0808_msgt_names, msg_type); |
| 1697 | } |
| 1698 | |
| 1699 | static const struct value_string gsm0808_bssap_names[] = { |
| 1700 | { BSSAP_MSG_BSS_MANAGEMENT, "MANAGEMENT" }, |
| 1701 | { BSSAP_MSG_DTAP, "DTAP" }, |
Neels Hofmeyr | 90fdb08 | 2017-03-01 14:59:44 +0100 | [diff] [blame] | 1702 | { 0, NULL } |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1703 | }; |
| 1704 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1705 | /*! Return string name of BSSAP Message Type */ |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 1706 | const char *gsm0808_bssap_name(uint8_t msg_type) |
| 1707 | { |
| 1708 | return get_value_string(gsm0808_bssap_names, msg_type); |
| 1709 | } |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1710 | |
Neels Hofmeyr | ffad574 | 2018-01-12 05:34:03 +0100 | [diff] [blame] | 1711 | const struct value_string gsm0808_speech_codec_type_names[] = { |
| 1712 | { GSM0808_SCT_FR1, "FR1" }, |
| 1713 | { GSM0808_SCT_FR2, "FR2" }, |
| 1714 | { GSM0808_SCT_FR3, "FR3" }, |
| 1715 | { GSM0808_SCT_FR4, "FR4" }, |
| 1716 | { GSM0808_SCT_FR5, "FR5" }, |
| 1717 | { GSM0808_SCT_HR1, "HR1" }, |
| 1718 | { GSM0808_SCT_HR3, "HR3" }, |
| 1719 | { GSM0808_SCT_HR4, "HR4" }, |
| 1720 | { GSM0808_SCT_HR6, "HR6" }, |
| 1721 | { GSM0808_SCT_CSD, "CSD" }, |
| 1722 | { 0, NULL } |
| 1723 | }; |
| 1724 | |
Philipp Maier | cdd0581 | 2018-07-12 18:21:07 +0200 | [diff] [blame] | 1725 | const struct value_string gsm0808_permitted_speech_names[] = { |
| 1726 | { GSM0808_PERM_FR1, "FR1" }, |
| 1727 | { GSM0808_PERM_FR2, "FR2" }, |
| 1728 | { GSM0808_PERM_FR3, "FR3" }, |
| 1729 | { GSM0808_PERM_FR4, "FR4" }, |
| 1730 | { GSM0808_PERM_FR5, "FR5" }, |
| 1731 | { GSM0808_PERM_HR1, "HR1" }, |
| 1732 | { GSM0808_PERM_HR2, "HR2" }, |
| 1733 | { GSM0808_PERM_HR3, "HR3" }, |
| 1734 | { GSM0808_PERM_HR4, "HR4" }, |
| 1735 | { GSM0808_PERM_HR6, "HR6" }, |
| 1736 | { 0, NULL } |
| 1737 | }; |
| 1738 | |
Pau Espin Pedrol | f2cda62 | 2018-07-06 17:16:41 +0200 | [diff] [blame] | 1739 | const struct value_string gsm0808_chosen_enc_alg_names[] = { |
| 1740 | { GSM0808_ALG_ID_A5_0, "A5/0" }, |
| 1741 | { GSM0808_ALG_ID_A5_1, "A5/1" }, |
| 1742 | { GSM0808_ALG_ID_A5_2, "A5/2" }, |
| 1743 | { GSM0808_ALG_ID_A5_3, "A5/3" }, |
| 1744 | { GSM0808_ALG_ID_A5_4, "A5/4" }, |
| 1745 | { GSM0808_ALG_ID_A5_5, "A5/5" }, |
| 1746 | { GSM0808_ALG_ID_A5_6, "A5/6" }, |
| 1747 | { GSM0808_ALG_ID_A5_7, "A5/7" }, |
| 1748 | { 0, NULL } |
| 1749 | }; |
| 1750 | |
Philipp Maier | dbb7659 | 2018-03-29 12:55:26 +0200 | [diff] [blame] | 1751 | static const struct value_string gsm0808_cause_names[] = { |
| 1752 | { GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, "RADIO INTERFACE MESSAGE FAILURE" }, |
| 1753 | { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, "RADIO INTERFACE FAILURE" }, |
| 1754 | { GSM0808_CAUSE_UPLINK_QUALITY, "UPLINK QUALITY" }, |
| 1755 | { GSM0808_CAUSE_UPLINK_STRENGTH, "UPLINK STRENGTH" }, |
| 1756 | { GSM0808_CAUSE_DOWNLINK_QUALITY, "DOWNLINK QUALITY" }, |
| 1757 | { GSM0808_CAUSE_DOWNLINK_STRENGTH, "DOWNLINK STRENGTH" }, |
| 1758 | { GSM0808_CAUSE_DISTANCE, "DISTANCE" }, |
| 1759 | { GSM0808_CAUSE_O_AND_M_INTERVENTION, "O AND M INTERVENTION" }, |
| 1760 | { GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION, "RESPONSE TO MSC INVOCATION" }, |
| 1761 | { GSM0808_CAUSE_CALL_CONTROL, "CALL CONTROL" }, |
| 1762 | { GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION, "RADIO INTERFACE FAILURE REVERSION" }, |
| 1763 | { GSM0808_CAUSE_HANDOVER_SUCCESSFUL, "HANDOVER SUCCESSFUL" }, |
| 1764 | { GSM0808_CAUSE_BETTER_CELL, "BETTER CELL" }, |
| 1765 | { GSM0808_CAUSE_DIRECTED_RETRY, "DIRECTED RETRY" }, |
| 1766 | { GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL, "JOINED GROUP CALL CHANNEL" }, |
| 1767 | { GSM0808_CAUSE_TRAFFIC, "TRAFFIC" }, |
| 1768 | { GSM0808_CAUSE_REDUCE_LOAD_IN_SERVING_CELL, "REDUCE LOAD IN SERVING CELL" }, |
| 1769 | { GSM0808_CAUSE_TRAFFIC_LOAD_IN_TGT_HIGHER_THAN_IN_SRC_CELL, "TRAFFIC LOAD IN TGT HIGHER THAN IN SRC CELL" }, |
| 1770 | { GSM0808_CAUSE_RELOCATION_TRIGGERED, "RELOCATION TRIGGERED" }, |
Thorsten Alteholz | 0062a5f | 2018-05-15 15:28:55 +0200 | [diff] [blame] | 1771 | { GSM0808_CAUSE_REQUESTED_OPT_NOT_AUTHORISED, "REQUESTED OPT NOT AUTHORISED" }, |
Philipp Maier | dbb7659 | 2018-03-29 12:55:26 +0200 | [diff] [blame] | 1772 | { GSM0808_CAUSE_ALT_CHAN_CONFIG_REQUESTED, "ALT CHAN CONFIG REQUESTED" }, |
| 1773 | { GSM0808_CAUSE_RESP_TO_INT_HO_ENQ_MSG, "RESP TO INT HO ENQ MSG" }, |
| 1774 | { GSM0808_CAUSE_INT_HO_ENQUIRY_REJECT, "INT HO ENQUIRY REJECT" }, |
| 1775 | { GSM0808_CAUSE_REDUNDANCY_LEVEL_NOT_ADEQUATE, "REDUNDANCY LEVEL NOT ADEQUATE" }, |
| 1776 | { GSM0808_CAUSE_EQUIPMENT_FAILURE, "EQUIPMENT FAILURE" }, |
| 1777 | { GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, "NO RADIO RESOURCE AVAILABLE" }, |
| 1778 | { GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE, "RQSTED TERRESTRIAL RESOURCE UNAVAILABLE" }, |
| 1779 | { GSM0808_CAUSE_CCCH_OVERLOAD, "CCCH OVERLOAD" }, |
| 1780 | { GSM0808_CAUSE_PROCESSOR_OVERLOAD, "PROCESSOR OVERLOAD" }, |
| 1781 | { GSM0808_CAUSE_BSS_NOT_EQUIPPED, "BSS NOT EQUIPPED" }, |
| 1782 | { GSM0808_CAUSE_MS_NOT_EQUIPPED, "MS NOT EQUIPPED" }, |
| 1783 | { GSM0808_CAUSE_INVALID_CELL, "INVALID CELL" }, |
| 1784 | { GSM0808_CAUSE_TRAFFIC_LOAD, "TRAFFIC LOAD" }, |
| 1785 | { GSM0808_CAUSE_PREEMPTION, "PREEMPTION" }, |
| 1786 | { GSM0808_CAUSE_DTM_HO_SGSN_FAILURE, "DTM HO SGSN FAILURE" }, |
| 1787 | { GSM0808_CAUSE_DTM_HO_PS_ALLOC_FAILURE, "DTM HO PS ALLOC FAILURE" }, |
| 1788 | { GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE, "RQSTED TRANSCODING RATE ADAPTION UNAVAILABLE" }, |
| 1789 | { GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH, "CIRCUIT POOL MISMATCH" }, |
| 1790 | { GSM0808_CAUSE_SWITCH_CIRCUIT_POOL, "SWITCH CIRCUIT POOL" }, |
| 1791 | { GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE, "RQSTED SPEECH VERSION UNAVAILABLE" }, |
| 1792 | { GSM0808_CAUSE_LSA_NOT_ALLOWED, "LSA NOT ALLOWED" }, |
| 1793 | { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL, "REQ CODEC TYPE OR CONFIG UNAVAIL" }, |
| 1794 | { GSM0808_CAUSE_REQ_A_IF_TYPE_UNAVAIL, "REQ A IF TYPE UNAVAIL" }, |
| 1795 | { GSM0808_CAUSE_INVALID_CSG_CELL, "INVALID CSG CELL" }, |
| 1796 | { GSM0808_CAUSE_REQ_REDUND_LEVEL_NOT_AVAIL, "REQ REDUND LEVEL NOT AVAIL" }, |
| 1797 | { GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED, "CIPHERING ALGORITHM NOT SUPPORTED" }, |
| 1798 | { GSM0808_CAUSE_GERAN_IU_MODE_FAILURE, "GERAN IU MODE FAILURE" }, |
| 1799 | { GSM0808_CAUSE_INC_RELOC_NOT_SUPP_DT_PUESBINE_FEATURE, "INC RELOC NOT SUPP DT PUESBINE FEATURE" }, |
| 1800 | { GSM0808_CAUSE_ACCESS_RESTRICTED_DUE_TO_SHARED_NETWORKS, "ACCESS RESTRICTED DUE TO SHARED NETWORKS" }, |
| 1801 | { GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_NOT_SUPP, "REQ CODEC TYPE OR CONFIG NOT SUPP" }, |
| 1802 | { GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP, "REQ A IF TYPE NOT SUPP" }, |
| 1803 | { GSM0808_CAUSE_REQ_REDUND_LVL_NOT_SUPP, "REQ REDUND LVL NOT SUPP" }, |
| 1804 | { GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED, "TERRESTRIAL CIRCUIT ALREADY ALLOCATED" }, |
| 1805 | { GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS, "INVALID MESSAGE CONTENTS" }, |
| 1806 | { GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING, "INFORMATION ELEMENT OR FIELD MISSING" }, |
| 1807 | { GSM0808_CAUSE_INCORRECT_VALUE, "INCORRECT VALUE" }, |
| 1808 | { GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE, "UNKNOWN MESSAGE TYPE" }, |
| 1809 | { GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT, "UNKNOWN INFORMATION ELEMENT" }, |
| 1810 | { GSM0808_CAUSE_DTM_HO_INVALID_PS_IND, "DTM HO INVALID PS IND" }, |
| 1811 | { GSM0808_CAUSE_CALL_ID_ALREADY_ALLOC, "CALL ID ALREADY ALLOC" }, |
| 1812 | { GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC, "PROTOCOL ERROR BETWEEN BSS AND MSC" }, |
Thorsten Alteholz | 0062a5f | 2018-05-15 15:28:55 +0200 | [diff] [blame] | 1813 | { GSM0808_CAUSE_VGCS_VBS_CALL_NON_EXISTENT, "VGCS VBS CALL NON EXISTENT" }, |
Philipp Maier | dbb7659 | 2018-03-29 12:55:26 +0200 | [diff] [blame] | 1814 | { GSM0808_CAUSE_DTM_HO_TIMER_EXPIRY, "DTM HO TIMER EXPIRY" }, |
| 1815 | { 0, NULL } |
| 1816 | }; |
| 1817 | |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 1818 | static const struct value_string gsm0808_cause_class_names[] = { |
| 1819 | { GSM0808_CAUSE_CLASS_NORM0, "Normal event" }, |
| 1820 | { GSM0808_CAUSE_CLASS_NORM1, "Normal event" }, |
| 1821 | { GSM0808_CAUSE_CLASS_RES_UNAVAIL, "Resource unavailable" }, |
| 1822 | { GSM0808_CAUSE_CLASS_SRV_OPT_NA, "Service or option not available" }, |
| 1823 | { GSM0808_CAUSE_CLASS_SRV_OPT_NIMPL, "Service or option not implemented" }, |
| 1824 | { GSM0808_CAUSE_CLASS_INVAL, "Invalid message" }, |
| 1825 | { GSM0808_CAUSE_CLASS_PERR, "Protocol error" }, |
| 1826 | { GSM0808_CAUSE_CLASS_INTW, "Interworking" }, |
| 1827 | { 0, NULL } |
| 1828 | }; |
| 1829 | |
| 1830 | /*! Return string name of BSSMAP Cause Class name */ |
| 1831 | const char *gsm0808_cause_class_name(enum gsm0808_cause_class class) |
| 1832 | { |
| 1833 | return get_value_string(gsm0808_cause_class_names, class); |
| 1834 | } |
| 1835 | |
Philipp Maier | dbb7659 | 2018-03-29 12:55:26 +0200 | [diff] [blame] | 1836 | /*! Return string name of BSSMAP Cause name */ |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 1837 | const char *gsm0808_cause_name(enum gsm0808_cause cause) |
Philipp Maier | dbb7659 | 2018-03-29 12:55:26 +0200 | [diff] [blame] | 1838 | { |
| 1839 | return get_value_string(gsm0808_cause_names, cause); |
| 1840 | } |
| 1841 | |
Alexander Chemeris | fdfe25b | 2020-05-12 23:21:56 +0300 | [diff] [blame] | 1842 | enum gsm0808_cause gsm0808_get_cause(const struct tlv_parsed *tp) |
| 1843 | { |
| 1844 | const uint8_t *buf = TLVP_VAL_MINLEN(tp, GSM0808_IE_CAUSE, 1); |
| 1845 | |
| 1846 | if (!buf) |
| 1847 | return -EBADMSG; |
| 1848 | |
| 1849 | if (TLVP_LEN(tp, GSM0808_IE_CAUSE) > 1) { |
| 1850 | if (!gsm0808_cause_ext(buf[0])) |
| 1851 | return -EINVAL; |
| 1852 | return buf[1]; |
| 1853 | } |
| 1854 | |
| 1855 | return buf[0]; |
| 1856 | } |
| 1857 | |
Alexander Chemeris | 22630e6 | 2020-05-13 00:44:04 +0300 | [diff] [blame] | 1858 | const char *gsm0808_diagnostics_octet_location_str(uint8_t pointer) |
| 1859 | { |
| 1860 | switch (pointer) { |
| 1861 | case 0: |
| 1862 | return "Error location not determined"; |
| 1863 | case 1: |
| 1864 | return "The first octet of the message received (i.e. the message type) was found erroneous (unknown)"; |
| 1865 | case 0xfd: |
| 1866 | return "The first octet of the BSSAP header (Discrimination) was found erroneous"; |
| 1867 | case 0xfe: |
| 1868 | return "(DTAP only) The DLCI (second) octet of the BSSAP header was found erroneous"; |
| 1869 | case 0xff: |
| 1870 | return "The last octet of the BSSAP header (length indicator) was found erroneous"; |
| 1871 | default: |
| 1872 | snprintf(str_buff, sizeof(str_buff), "The %d octet of the message received was found erroneous", pointer); |
| 1873 | return str_buff; |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | const char *gsm0808_diagnostics_bit_location_str(uint8_t bit_pointer) |
| 1878 | { |
| 1879 | if (bit_pointer == 0) { |
| 1880 | return "No particular part of the octet is indicated"; |
| 1881 | } else if (bit_pointer > 8) { |
| 1882 | return "Reserved value"; |
| 1883 | } |
| 1884 | |
| 1885 | snprintf(str_buff, sizeof(str_buff), |
| 1886 | "An error was provoked by the field whose most significant bit is in bit position %d", |
| 1887 | bit_pointer); |
| 1888 | return str_buff; |
| 1889 | } |
| 1890 | |
Harald Welte | ebd362d | 2018-06-02 14:11:19 +0200 | [diff] [blame] | 1891 | const struct value_string gsm0808_lcls_config_names[] = { |
| 1892 | { GSM0808_LCLS_CFG_BOTH_WAY, "Connect both-way" }, |
| 1893 | { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL, |
| 1894 | "Connect both-way, bi-cast UL to CN" }, |
| 1895 | { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL, |
| 1896 | "Connect both-way, send access DL from CN" }, |
| 1897 | { GSM0808_LCLS_CFG_BOTH_WAY_AND_SEND_DL_BLOCK_LOCAL_DL, |
| 1898 | "Connect both-way, send access DL from CN, block local DL" }, |
| 1899 | { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL, |
| 1900 | "Connect both-way, bi-cast UL to CN, send access DL from CN" }, |
| 1901 | { GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL_SEND_DL_BLOCK_LOCAL_DL, |
| 1902 | "Connect both-way, bi-cast UL to CN, send access DL from CN, block local DL" }, |
Max | 961db7c | 2018-11-08 11:40:23 +0100 | [diff] [blame] | 1903 | { GSM0808_LCLS_CFG_NA, "Not available" }, |
Harald Welte | ebd362d | 2018-06-02 14:11:19 +0200 | [diff] [blame] | 1904 | { 0, NULL } |
| 1905 | }; |
| 1906 | |
| 1907 | const struct value_string gsm0808_lcls_control_names[] = { |
| 1908 | { GSM0808_LCLS_CSC_CONNECT, "Connect" }, |
| 1909 | { GSM0808_LCLS_CSC_DO_NOT_CONNECT, "Do not connect" }, |
| 1910 | { GSM0808_LCLS_CSC_RELEASE_LCLS, "Release LCLS" }, |
| 1911 | { GSM0808_LCLS_CSC_BICAST_UL_AT_HANDOVER, "Bi-cast UL at Handover" }, |
| 1912 | { GSM0808_LCLS_CSC_BICAST_UL_AND_RECV_DL_AT_HANDOVER, "Bi-cast UL and receive DL at Handover" }, |
Max | 961db7c | 2018-11-08 11:40:23 +0100 | [diff] [blame] | 1913 | { GSM0808_LCLS_CSC_NA, "Not available" }, |
Harald Welte | ebd362d | 2018-06-02 14:11:19 +0200 | [diff] [blame] | 1914 | { 0, NULL } |
| 1915 | }; |
| 1916 | |
| 1917 | const struct value_string gsm0808_lcls_status_names[] = { |
| 1918 | { GSM0808_LCLS_STS_NOT_YET_LS, "Call not yet locally switched" }, |
| 1919 | { GSM0808_LCLS_STS_NOT_POSSIBLE_LS, "Call not possible to be locally switched" }, |
| 1920 | { GSM0808_LCLS_STS_NO_LONGER_LS, "Call is no longer locally switched" }, |
| 1921 | { GSM0808_LCLS_STS_REQ_LCLS_NOT_SUPP, "Requested LCLS configuration is not supported" }, |
| 1922 | { GSM0808_LCLS_STS_LOCALLY_SWITCHED, "Call is locally switched with requested LCLS config" }, |
Max | 961db7c | 2018-11-08 11:40:23 +0100 | [diff] [blame] | 1923 | { GSM0808_LCLS_STS_NA, "Not available" }, |
Harald Welte | ebd362d | 2018-06-02 14:11:19 +0200 | [diff] [blame] | 1924 | { 0, NULL } |
| 1925 | }; |
| 1926 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1927 | /*! @} */ |