Harald Welte | 37b6165 | 2017-10-16 18:46:03 +0200 | [diff] [blame] | 1 | /*! \addtogroup gsm0808 |
| 2 | * @{ |
| 3 | * \file gsm0808_utils.h */ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 4 | /* |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 5 | * (C) 2016 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 18 | * GNU General Public License for more details. |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 19 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 20 | * You should have received a copy of the GNU General Public License |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | */ |
| 24 | #pragma once |
| 25 | |
Harald Welte | 20725b9 | 2017-05-15 12:50:04 +0200 | [diff] [blame] | 26 | struct sockaddr_storage; |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 27 | |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 28 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 29 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Max | 969fb2e | 2018-12-10 11:01:10 +0100 | [diff] [blame] | 30 | #include <osmocom/gsm/gsm29205.h> |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 31 | #include <osmocom/gsm/gsm23003.h> |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 32 | #include <osmocom/gsm/gsm_utils.h> |
Max | adc4172 | 2018-11-19 10:44:55 +0100 | [diff] [blame] | 33 | #include <osmocom/gsm/tlv.h> |
Andreas Eversberg | 5c7336c | 2023-04-20 11:04:14 +0200 | [diff] [blame] | 34 | #include <osmocom/gsm/gsm48.h> |
| 35 | #include <osmocom/core/endian.h> |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 36 | |
| 37 | /*! (225-1)/2 is the maximum number of elements in a cell identifier list. */ |
| 38 | #define GSM0808_CELL_ID_LIST2_MAXLEN 127 |
| 39 | |
Neels Hofmeyr | 250e7f7 | 2018-04-13 03:30:14 +0200 | [diff] [blame] | 40 | /*! Instead of this, use either struct gsm0808_cell_id or gsm0808_cell_id_list2. |
| 41 | * All elements contain parsed representations of the data in the corresponding IE, in host-byte order. |
| 42 | */ |
| 43 | union gsm0808_cell_id_u { |
| 44 | struct osmo_cell_global_id global; |
| 45 | struct osmo_lac_and_ci_id lac_and_ci; |
| 46 | uint16_t ci; |
| 47 | struct osmo_location_area_id lai_and_lac; |
| 48 | uint16_t lac; |
Pau Espin Pedrol | b5551ee | 2022-02-16 13:09:32 +0100 | [diff] [blame] | 49 | struct osmo_service_area_id sai; |
| 50 | /* osmocom specific: */ |
Pau Espin Pedrol | ca33a71 | 2021-01-05 19:36:48 +0100 | [diff] [blame] | 51 | struct osmo_cell_global_id_ps global_ps; |
Neels Hofmeyr | 250e7f7 | 2018-04-13 03:30:14 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | /*! Parsed representation of Cell Identifier IE (3GPP TS 48.008 3.2.2.17) */ |
| 55 | struct gsm0808_cell_id { |
| 56 | enum CELL_IDENT id_discr; |
| 57 | union gsm0808_cell_id_u id; |
| 58 | }; |
| 59 | |
| 60 | /*! Parsed representation of a Cell Identifier List IE (3GPP TS 48.008 3.2.2.27). */ |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 61 | struct gsm0808_cell_id_list2 { |
| 62 | enum CELL_IDENT id_discr; |
Neels Hofmeyr | 250e7f7 | 2018-04-13 03:30:14 +0200 | [diff] [blame] | 63 | union gsm0808_cell_id_u id_list[GSM0808_CELL_ID_LIST2_MAXLEN]; |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 64 | unsigned int id_list_len; |
| 65 | }; |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 66 | |
Andreas Eversberg | 5c7336c | 2023-04-20 11:04:14 +0200 | [diff] [blame] | 67 | /*! Packed representation of a Priority IE (GGPP TS 48.008 3.2.2.18) */ |
| 68 | struct gsm0808_priority { |
| 69 | #if OSMO_IS_LITTLE_ENDIAN |
| 70 | uint8_t pvi:1, /* Preemption Vulnerability indicator */ |
| 71 | qa:1, /* Queuing allowed indicator */ |
| 72 | priority_level:4, /* Priority level: 1 == hightest, 14 == lowest */ |
| 73 | pci:1, /* Preemption Capability indicator */ |
| 74 | spare:1; |
| 75 | #elif OSMO_IS_BIG_ENDIAN |
| 76 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 77 | uint8_t spare:1, pci:1, priority_level:4, qa:1, pvi:1; |
| 78 | #endif |
| 79 | } __attribute__ ((packed)); |
| 80 | |
| 81 | /*! Packed representation of a VGCS Feature Flags IE (3GPP TS 48.008 3.2.2.88) */ |
| 82 | struct gsm0808_vgcs_feature_flags { |
| 83 | #if OSMO_IS_LITTLE_ENDIAN |
| 84 | uint8_t tp_ind:1, /* Talker priority supported */ |
| 85 | as_ind_circuit:1, /* A-interface circuit sharing supported */ |
| 86 | as_ind_link:1, /* A-interface link sharing supported */ |
| 87 | bss_res:1, /* BSS supports re-establishment */ |
| 88 | tcp:1, /* Talker channel parameter supported */ |
| 89 | spare:3; |
| 90 | #elif OSMO_IS_BIG_ENDIAN |
| 91 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 92 | uint8_t spare:3, tcp:1, bss_res:1, as_ind_link:1, as_ind_circuit:1, tp_ind:1; |
| 93 | #endif |
| 94 | } __attribute__ ((packed)); |
| 95 | |
| 96 | /* TS 48.008 3.2.2.52 */ |
| 97 | enum gsm0808_assignment_requirement { |
| 98 | GSM0808_ASRQ_DELAY_ALLOWED = 0x00, |
| 99 | GSM0808_ASRQ_IMMEDIATE = 0x01, |
| 100 | GSM0808_ASRQ_IMMEDIATE_ON_DEMAND = 0x02, |
| 101 | }; |
| 102 | |
| 103 | /* TS 48.008 Table 10.5.8 */ |
| 104 | enum gsm0808_service_flag { |
| 105 | GSM0808_SF_VBS = 0, |
| 106 | GSM0808_SF_VGCS = 1, |
| 107 | }; |
| 108 | |
| 109 | enum gsm0808_call_priority { |
| 110 | GSM0808_CALL_PRIORITY_NONE = 0x00, |
| 111 | GSM0808_CALL_PRIORITY_LEVEL_4 = 0x01, |
| 112 | GSM0808_CALL_PRIORITY_LEVEL_3 = 0x02, |
| 113 | GSM0808_CALL_PRIORITY_LEVEL_2 = 0x03, |
| 114 | GSM0808_CALL_PRIORITY_LEVEL_1 = 0x04, |
| 115 | GSM0808_CALL_PRIORITY_LEVEL_0 = 0x05, |
| 116 | GSM0808_CALL_PRIORITY_LEVEL_B = 0x06, |
| 117 | GSM0808_CALL_PRIORITY_LEVEL_A = 0x07, |
| 118 | }; |
| 119 | |
| 120 | /*! Packed representation of a Group Call Reference IE (3GPP TS 48.008 3.2.2.55) */ |
| 121 | struct gsm0808_group_callref { |
| 122 | #if OSMO_IS_LITTLE_ENDIAN |
| 123 | uint8_t call_ref_hi[3]; |
| 124 | uint8_t call_priority:3, |
| 125 | af:1, /* Acknowledgement flag */ |
| 126 | sf:1, /* Service flag */ |
| 127 | call_ref_lo:3; |
| 128 | uint8_t spare:4, |
| 129 | ciphering_info:4; |
| 130 | #elif OSMO_IS_BIG_ENDIAN |
| 131 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 132 | uint8_t call_ref_hi[3]; |
| 133 | uint8_t call_ref_lo:3, sf:1, af:1, call_priority:3; |
| 134 | uint8_t ciphering_info:4, spare:4; |
| 135 | #endif |
| 136 | } __attribute__ ((packed)); |
| 137 | |
| 138 | /* TS 48.008 3.2.2.26 */ |
| 139 | enum gsm0808_downlink_dtx_flag { |
| 140 | GSM0808_DTX_FLAG_ALLOW = 0, |
| 141 | GSM0808_DTX_FLAG_FORBID = 1, |
| 142 | }; |
| 143 | |
| 144 | /*! Parsed representation of a Cell Identifier List Segment IE (3GPP TS 48.008 3.2.2.27a) */ |
| 145 | struct gsm0808_cell_id_list_segment { |
| 146 | uint8_t seq_last; |
| 147 | uint8_t seq_number; |
| 148 | struct gsm0808_cell_id_list2 cil; |
| 149 | }; |
| 150 | |
| 151 | /*! Parsed representation of a Circuit Pool List IE (3GPP TS 48.008 3.2.2.26) */ |
| 152 | #define CIRCUIT_POOL_LIST_MAXLEN 252 |
| 153 | struct gsm0808_circuit_pool_list { |
| 154 | uint8_t pool[CIRCUIT_POOL_LIST_MAXLEN]; |
| 155 | unsigned int list_len; |
| 156 | }; |
| 157 | |
| 158 | /* 3GPP TS 48.008 Table 3.2.2.90.1 Talker Priority */ |
| 159 | enum gsm0808_talker_priority { |
| 160 | GSM0808_TALKER_PRIORITY_NORMAL = 0x00, |
| 161 | GSM0808_TALKER_PRIORITY_PRIVILEGED = 0x01, |
| 162 | GSM0808_TALKER_PRIORITY_EMERGENCY = 0x02, |
| 163 | }; |
| 164 | |
| 165 | /*! Parsed representation of a Layer 3 Information IE (3GPP TS 48.008 3.2.2.24) */ |
| 166 | #define LAYER_3_INFORMATION_MAXLEN 252 |
| 167 | struct gsm0808_layer_3_information { |
| 168 | uint8_t l3[LAYER_3_INFORMATION_MAXLEN]; |
| 169 | unsigned int l3_len; |
| 170 | }; |
| 171 | |
| 172 | /*! Parsed representation of a Talker Identity IE (3GPP TS 48.008 3.2.2.91) */ |
| 173 | #define TALKER_IDENTITY_MAXLEN 17 |
| 174 | struct gsm0808_talker_identity { |
| 175 | uint8_t talker_id[TALKER_IDENTITY_MAXLEN]; |
| 176 | unsigned int id_bits; |
| 177 | }; |
| 178 | |
| 179 | /* 3GPP TS 48.008 3.2.2.94 VGCS/VBS Cell Status */ |
| 180 | enum gsm0808_vgcs_vbs_cell_status { |
| 181 | GSM0808_CSTAT_ESTABLISHED = 0x00, |
| 182 | GSM0808_CSTAT_NOT_ESTABLISHED1 = 0x01, |
| 183 | GSM0808_CSTAT_RELEASED_NO_USER = 0x02, |
| 184 | GSM0808_CSTAT_NOT_ESTABLISHED2 = 0x03, |
| 185 | }; |
| 186 | |
| 187 | /*! Parsed representation of a SMS to VGCS IE (3GPP TS 48.008 3.2.2.92) */ |
| 188 | #define SMS_TO_VGCS_MAXLEN 252 |
| 189 | struct gsm0808_sms_to_vgcs { |
| 190 | uint8_t sms[SMS_TO_VGCS_MAXLEN]; |
| 191 | unsigned int sms_len; |
| 192 | }; |
| 193 | |
| 194 | /*! Parsed representation of a Application Data IE (3GPP TS 48.008 3.2.2.98) */ |
| 195 | #define APP_DATA_MAXLEN 9 |
| 196 | struct gsm0808_application_data { |
| 197 | uint8_t data[APP_DATA_MAXLEN]; |
| 198 | unsigned int data_len; |
| 199 | }; |
| 200 | |
| 201 | /*! Packed representation of a Data Identity IE (GGPP TS 48.008 3.2.2.99) */ |
| 202 | enum gsm0808_application_idndicator { |
| 203 | GSM0808_AI_APP_DATA = 0x00, |
| 204 | GSM0808_AI_CONFIRM_APP_DATA = 0x01, |
| 205 | }; |
| 206 | |
| 207 | #define GSM0808_DP_MASK_TALKERS_LISTENERS 0x04 |
| 208 | #define GSM0808_DP_MASK_DISPATCHERS 0x02 |
| 209 | #define GSM0808_DP_MASK_NETWORK_APP 0x01 |
| 210 | |
| 211 | struct gsm0808_data_identity { |
| 212 | #if OSMO_IS_LITTLE_ENDIAN |
| 213 | uint8_t ai:1, /* Application Indicator */ |
| 214 | di:4, /* Data identifier */ |
| 215 | dp:3; /* Distribution parameter (bit mask) */ |
| 216 | #elif OSMO_IS_BIG_ENDIAN |
| 217 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 218 | uint8_t dp:3, di:4, ai:1; |
| 219 | #endif |
| 220 | } __attribute__ ((packed)); |
| 221 | |
| 222 | /*! Parsed representation of a MSISDN IE (3GPP TS 48.008 3.2.2.101) */ |
| 223 | #define MSISDN_MAXLEN 20 |
| 224 | |
Max | 7387824 | 2018-11-09 12:35:03 +0100 | [diff] [blame] | 225 | /*! LCLS-related parameters from 3GPP TS 48.008 */ |
| 226 | struct osmo_lcls { |
Max | 14f24c6 | 2018-11-29 19:30:07 +0100 | [diff] [blame] | 227 | enum gsm0808_lcls_config config; /**< §3.2.2.116 Configuration */ |
| 228 | enum gsm0808_lcls_control control; /**< §3.2.2.117 Connection Status Control */ |
Max | 3b90125 | 2019-01-15 14:15:11 +0100 | [diff] [blame] | 229 | struct osmo_gcr_parsed gcr; /**< §3.2.2.115 Global Call Reference */ |
| 230 | bool gcr_available; |
Max | 14f24c6 | 2018-11-29 19:30:07 +0100 | [diff] [blame] | 231 | bool corr_needed; /**< §3.2.2.118 Correlation-Not-Needed */ |
Max | 7387824 | 2018-11-09 12:35:03 +0100 | [diff] [blame] | 232 | }; |
| 233 | |
Max | 5ec0cf5 | 2019-01-15 16:37:09 +0100 | [diff] [blame] | 234 | char *osmo_lcls_dump(const struct osmo_lcls *lcls); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 235 | char *osmo_lcls_dump_buf(char *buf, size_t buf_len, const struct osmo_lcls *lcls); |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 236 | char *osmo_lcls_dump_c(void *ctx, const struct osmo_lcls *lcls); |
Max | 5ec0cf5 | 2019-01-15 16:37:09 +0100 | [diff] [blame] | 237 | char *osmo_gcr_dump(const struct osmo_lcls *lcls); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 238 | char *osmo_gcr_dump_buf(char *buf, size_t buf_len, const struct osmo_lcls *lcls); |
Max | 5ec0cf5 | 2019-01-15 16:37:09 +0100 | [diff] [blame] | 239 | |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 240 | extern const struct value_string gsm0808_cell_id_discr_names[]; |
| 241 | static inline const char *gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr) |
| 242 | { return get_value_string(gsm0808_cell_id_discr_names, id_discr); } |
| 243 | |
| 244 | const char *gsm0808_cell_id_name(const struct gsm0808_cell_id *cid); |
| 245 | const char *gsm0808_cell_id_name2(const struct gsm0808_cell_id *cid); |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 246 | char *gsm0808_cell_id_name_buf(char *buf, size_t buflen, const struct gsm0808_cell_id *cid); |
| 247 | char *gsm0808_cell_id_name_c(const void *ctx, const struct gsm0808_cell_id *cid); |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 248 | const char *gsm0808_cell_id_list_name(const struct gsm0808_cell_id_list2 *cil); |
| 249 | int gsm0808_cell_id_list_name_buf(char *buf, size_t buflen, const struct gsm0808_cell_id_list2 *cil); |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 250 | char *gsm0808_cell_id_list_name_c(const void *ctx, const struct gsm0808_cell_id_list2 *cil); |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 251 | int gsm0808_cell_id_u_name(char *buf, size_t buflen, |
| 252 | enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u); |
Neels Hofmeyr | d01ef75 | 2018-09-21 15:57:26 +0200 | [diff] [blame] | 253 | bool gsm0808_cell_ids_match(const struct gsm0808_cell_id *id1, const struct gsm0808_cell_id *id2, bool exact_match); |
| 254 | int gsm0808_cell_id_matches_list(const struct gsm0808_cell_id *id, const struct gsm0808_cell_id_list2 *list, |
| 255 | unsigned int match_nr, bool exact_match); |
Neels Hofmeyr | 3a50453 | 2019-02-10 22:28:27 +0100 | [diff] [blame] | 256 | void gsm0808_cell_id_from_cgi(struct gsm0808_cell_id *cid, enum CELL_IDENT id_discr, |
| 257 | const struct osmo_cell_global_id *cgi); |
| 258 | int gsm0808_cell_id_to_cgi(struct osmo_cell_global_id *cgi, const struct gsm0808_cell_id *cid); |
Harald Welte | e87693c | 2019-05-03 20:06:50 +0200 | [diff] [blame] | 259 | void gsm0808_msgb_put_cell_id_u(struct msgb *msg, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u); |
Harald Welte | ef7be49 | 2019-05-03 21:01:13 +0200 | [diff] [blame] | 260 | int gsm0808_decode_cell_id_u(union gsm0808_cell_id_u *out, enum CELL_IDENT discr, const uint8_t *buf, unsigned int len); |
Harald Welte | f221003 | 2019-08-31 21:25:05 +0200 | [diff] [blame] | 261 | int gsm0808_cell_id_size(enum CELL_IDENT discr); |
Neels Hofmeyr | a4399c8 | 2018-04-17 02:26:10 +0200 | [diff] [blame] | 262 | |
Philipp Maier | 4f4905f | 2018-11-30 13:36:12 +0100 | [diff] [blame] | 263 | uint8_t gsm0808_enc_cause(struct msgb *msg, uint16_t cause); |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 264 | uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg, |
| 265 | const struct sockaddr_storage *ss); |
Philipp Maier | 2240143 | 2017-03-24 17:59:26 +0100 | [diff] [blame] | 266 | int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss, |
| 267 | const uint8_t *elem, uint8_t len); |
Pau Espin Pedrol | 18506c8 | 2019-04-16 15:47:59 +0200 | [diff] [blame] | 268 | int gsm0808_dec_osmux_cid(uint8_t *cid, const uint8_t *elem, uint8_t len); |
Max | 969fb2e | 2018-12-10 11:01:10 +0100 | [diff] [blame] | 269 | |
Max | 4702215 | 2018-12-19 18:51:00 +0100 | [diff] [blame] | 270 | uint8_t gsm0808_enc_lcls(struct msgb *msg, const struct osmo_lcls *lcls); |
| 271 | int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp); |
Max | 969fb2e | 2018-12-10 11:01:10 +0100 | [diff] [blame] | 272 | |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 273 | uint8_t gsm0808_enc_speech_codec(struct msgb *msg, |
Vadim Yanitskiy | 5a51331 | 2022-12-14 00:23:59 +0700 | [diff] [blame] | 274 | const struct gsm0808_speech_codec *sc) |
| 275 | OSMO_DEPRECATED("use gsm0808_enc_speech_codec2() instead"); |
| 276 | int gsm0808_enc_speech_codec2(struct msgb *msg, |
| 277 | const struct gsm0808_speech_codec *sc); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 278 | int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc, |
| 279 | const uint8_t *elem, uint8_t len); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 280 | uint8_t gsm0808_enc_speech_codec_list(struct msgb *msg, |
Vadim Yanitskiy | 5a51331 | 2022-12-14 00:23:59 +0700 | [diff] [blame] | 281 | const struct gsm0808_speech_codec_list *scl) |
| 282 | OSMO_DEPRECATED("use gsm0808_enc_speech_codec_list2() instead"); |
| 283 | int gsm0808_enc_speech_codec_list2(struct msgb *msg, |
| 284 | const struct gsm0808_speech_codec_list *scl); |
Philipp Maier | 6f725d6 | 2017-03-24 18:03:17 +0100 | [diff] [blame] | 285 | int gsm0808_dec_speech_codec_list(struct gsm0808_speech_codec_list *scl, |
| 286 | const uint8_t *elem, uint8_t len); |
Philipp Maier | e0c6530 | 2017-03-28 17:05:40 +0200 | [diff] [blame] | 287 | uint8_t gsm0808_enc_channel_type(struct msgb *msg, |
| 288 | const struct gsm0808_channel_type *ct); |
Philipp Maier | e0c6530 | 2017-03-28 17:05:40 +0200 | [diff] [blame] | 289 | int gsm0808_dec_channel_type(struct gsm0808_channel_type *ct, |
| 290 | const uint8_t *elem, uint8_t len); |
Philipp Maier | 14e76b9 | 2017-03-28 18:36:52 +0200 | [diff] [blame] | 291 | uint8_t gsm0808_enc_encrypt_info(struct msgb *msg, |
| 292 | const struct gsm0808_encrypt_info *ei); |
Philipp Maier | 14e76b9 | 2017-03-28 18:36:52 +0200 | [diff] [blame] | 293 | int gsm0808_dec_encrypt_info(struct gsm0808_encrypt_info *ei, |
| 294 | const uint8_t *elem, uint8_t len); |
Neels Hofmeyr | 4a9756c | 2021-06-10 00:48:15 +0200 | [diff] [blame] | 295 | int gsm0808_enc_kc128(struct msgb *msg, const uint8_t *kc128); |
| 296 | int gsm0808_dec_kc128(uint8_t *kc128, const uint8_t *elem, uint8_t len); |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 297 | uint8_t gsm0808_enc_cell_id_list2(struct msgb *msg, const struct gsm0808_cell_id_list2 *cil); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 298 | uint8_t gsm0808_enc_cell_id_list(struct msgb *msg, |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 299 | const struct gsm0808_cell_id_list *cil) |
| 300 | OSMO_DEPRECATED("use gsm0808_enc_cell_id_list2 instead"); |
| 301 | int gsm0808_dec_cell_id_list2(struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len); |
Philipp Maier | 783047e | 2017-03-29 11:35:50 +0200 | [diff] [blame] | 302 | int gsm0808_dec_cell_id_list(struct gsm0808_cell_id_list *cil, |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 303 | const uint8_t *elem, uint8_t len) |
| 304 | OSMO_DEPRECATED("use gsm0808_dec_cell_id_list2 instead"); |
Neels Hofmeyr | 74663d9 | 2018-03-23 01:46:42 +0100 | [diff] [blame] | 305 | int gsm0808_cell_id_list_add(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id_list2 *src); |
Neels Hofmeyr | 38e5841 | 2018-05-25 16:56:35 +0200 | [diff] [blame] | 306 | void gsm0808_cell_id_to_list(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id *src); |
Neels Hofmeyr | 250e7f7 | 2018-04-13 03:30:14 +0200 | [diff] [blame] | 307 | uint8_t gsm0808_enc_cell_id(struct msgb *msg, const struct gsm0808_cell_id *ci); |
| 308 | int gsm0808_dec_cell_id(struct gsm0808_cell_id *ci, const uint8_t *elem, uint8_t len); |
Neels Hofmeyr | 9a391e2 | 2017-06-23 02:34:08 +0200 | [diff] [blame] | 309 | int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch); |
Philipp Maier | 884ba0f | 2017-06-02 13:49:16 +0200 | [diff] [blame] | 310 | int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc, |
| 311 | uint8_t perm_spch); |
Philipp Maier | 369015c | 2018-09-21 09:07:20 +0200 | [diff] [blame] | 312 | uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cfg, bool fr); |
Philipp Maier | 3713af8 | 2019-02-27 16:48:25 +0100 | [diff] [blame] | 313 | int gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg, uint16_t s15_s0); |
Harald Welte | 37b6165 | 2017-10-16 18:46:03 +0200 | [diff] [blame] | 314 | |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 315 | /*! \returns 3GPP TS 08.08 §3.2.2.5 Class of a given Cause */ |
| 316 | static inline enum gsm0808_cause_class gsm0808_cause_class(enum gsm0808_cause cause) |
| 317 | { |
Alexander Chemeris | ecfb0d6 | 2020-05-13 00:39:15 +0300 | [diff] [blame] | 318 | return (cause >> 4) & 0x7; |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /*! \returns true if 3GPP TS 08.08 §3.2.2.5 Class has extended bit set */ |
| 322 | static inline bool gsm0808_cause_ext(enum gsm0808_cause cause) |
| 323 | { |
| 324 | /* check that cause looks like 1XXX0000 where XXX represent class */ |
| 325 | return (cause & 0x80) && !(cause & 0x0F); |
| 326 | } |
| 327 | |
Alexander Chemeris | 2ac8f91 | 2020-05-13 22:38:08 +0300 | [diff] [blame] | 328 | int gsm0808_get_cipher_reject_cause(const struct tlv_parsed *tp) |
| 329 | OSMO_DEPRECATED("Use gsm0808_get_cause() instead"); |
| 330 | |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 331 | /*! \returns 3GPP TS 48.008 3.2.2.49 Current Channel Type 1 from enum gsm_chan_t. */ |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 332 | static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type) |
| 333 | { |
| 334 | switch (type) { |
| 335 | default: |
| 336 | return 0; |
| 337 | case GSM_LCHAN_SDCCH: |
| 338 | return 0x01; |
| 339 | case GSM_LCHAN_TCH_F: |
| 340 | return 0x18; |
| 341 | case GSM_LCHAN_TCH_H: |
| 342 | return 0x19; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | /*! Return 3GPP TS 48.008 3.2.2.51 Speech Version aka permitted speech version indication in 3.2.2.11 |
| 347 | * Channel Type. */ |
| 348 | static inline enum gsm0808_permitted_speech gsm0808_permitted_speech(enum gsm_chan_t type, |
| 349 | enum gsm48_chan_mode mode) |
| 350 | { |
Vadim Yanitskiy | c57cc4b | 2023-03-23 16:43:16 +0700 | [diff] [blame] | 351 | #define MODE_TYPE(mode, type) ((mode << 16) | type) |
| 352 | |
| 353 | switch (MODE_TYPE(mode, type)) { |
| 354 | case MODE_TYPE(GSM48_CMODE_SPEECH_V1, GSM_LCHAN_TCH_F): |
| 355 | return GSM0808_PERM_FR1; |
| 356 | case MODE_TYPE(GSM48_CMODE_SPEECH_V1, GSM_LCHAN_TCH_H): |
| 357 | return GSM0808_PERM_HR1; |
| 358 | case MODE_TYPE(GSM48_CMODE_SPEECH_EFR, GSM_LCHAN_TCH_F): |
| 359 | return GSM0808_PERM_FR2; |
| 360 | case MODE_TYPE(GSM48_CMODE_SPEECH_EFR, GSM_LCHAN_TCH_H): |
| 361 | return GSM0808_PERM_HR2; /* (deprecated) */ |
| 362 | case MODE_TYPE(GSM48_CMODE_SPEECH_AMR, GSM_LCHAN_TCH_F): |
| 363 | return GSM0808_PERM_FR3; |
| 364 | case MODE_TYPE(GSM48_CMODE_SPEECH_AMR, GSM_LCHAN_TCH_H): |
| 365 | return GSM0808_PERM_HR3; |
| 366 | case MODE_TYPE(GSM48_CMODE_SPEECH_V4, GSM_LCHAN_TCH_F): |
| 367 | return GSM0808_PERM_FR4; |
| 368 | case MODE_TYPE(GSM48_CMODE_SPEECH_V4, GSM_LCHAN_TCH_H): |
| 369 | return GSM0808_PERM_HR4; |
| 370 | case MODE_TYPE(GSM48_CMODE_SPEECH_V5, GSM_LCHAN_TCH_F): |
| 371 | return GSM0808_PERM_FR5; /* FR only */ |
| 372 | case MODE_TYPE(GSM48_CMODE_SPEECH_V6, GSM_LCHAN_TCH_H): |
| 373 | return GSM0808_PERM_HR6; /* HR only */ |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 374 | default: |
| 375 | return 0; |
| 376 | } |
Vadim Yanitskiy | c57cc4b | 2023-03-23 16:43:16 +0700 | [diff] [blame] | 377 | |
| 378 | #undef MODE_TYPE |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /*! Return 3GPP TS 48.008 3.2.2.33 Chosen Channel. */ |
| 382 | static inline uint8_t gsm0808_chosen_channel(enum gsm_chan_t type, enum gsm48_chan_mode mode) |
| 383 | { |
| 384 | uint8_t channel_mode = 0, channel = 0; |
| 385 | |
| 386 | switch (mode) { |
| 387 | case GSM48_CMODE_SPEECH_V1: |
| 388 | case GSM48_CMODE_SPEECH_EFR: |
| 389 | case GSM48_CMODE_SPEECH_AMR: |
Vadim Yanitskiy | c57cc4b | 2023-03-23 16:43:16 +0700 | [diff] [blame] | 390 | case GSM48_CMODE_SPEECH_V4: |
| 391 | case GSM48_CMODE_SPEECH_V5: |
| 392 | case GSM48_CMODE_SPEECH_V6: |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 393 | channel_mode = 0x9; |
| 394 | break; |
| 395 | case GSM48_CMODE_SIGN: |
| 396 | channel_mode = 0x8; |
| 397 | break; |
| 398 | case GSM48_CMODE_DATA_14k5: |
| 399 | channel_mode = 0xe; |
| 400 | break; |
| 401 | case GSM48_CMODE_DATA_12k0: |
| 402 | channel_mode = 0xb; |
| 403 | break; |
| 404 | case GSM48_CMODE_DATA_6k0: |
| 405 | channel_mode = 0xc; |
| 406 | break; |
| 407 | case GSM48_CMODE_DATA_3k6: |
| 408 | channel_mode = 0xd; |
| 409 | break; |
Vadim Yanitskiy | c57cc4b | 2023-03-23 16:43:16 +0700 | [diff] [blame] | 410 | case GSM48_CMODE_DATA_29k0: |
| 411 | channel_mode = 0x1; |
| 412 | break; |
| 413 | case GSM48_CMODE_DATA_32k0: |
| 414 | channel_mode = 0x2; |
| 415 | break; |
| 416 | case GSM48_CMODE_DATA_43k5: |
| 417 | channel_mode = 0x3; |
| 418 | break; |
| 419 | case GSM48_CMODE_DATA_43k5_14k5: |
| 420 | channel_mode = 0x4; |
| 421 | break; |
| 422 | case GSM48_CMODE_DATA_29k0_14k5: |
| 423 | channel_mode = 0x5; |
| 424 | break; |
| 425 | case GSM48_CMODE_DATA_43k5_29k0: |
| 426 | channel_mode = 0x6; |
| 427 | break; |
| 428 | case GSM48_CMODE_DATA_14k5_43k5: |
| 429 | channel_mode = 0x7; |
| 430 | break; |
| 431 | case GSM48_CMODE_DATA_14k5_29k0: |
| 432 | channel_mode = 0xa; |
| 433 | break; |
| 434 | case GSM48_CMODE_DATA_29k0_43k5: |
| 435 | channel_mode = 0xf; |
| 436 | break; |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 437 | default: |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | switch (type) { |
| 442 | case GSM_LCHAN_NONE: |
| 443 | channel = 0x0; |
| 444 | break; |
| 445 | case GSM_LCHAN_SDCCH: |
| 446 | channel = 0x1; |
| 447 | break; |
| 448 | case GSM_LCHAN_TCH_F: |
| 449 | channel = 0x8; |
| 450 | break; |
| 451 | case GSM_LCHAN_TCH_H: |
| 452 | channel = 0x9; |
| 453 | break; |
Vadim Yanitskiy | c57cc4b | 2023-03-23 16:43:16 +0700 | [diff] [blame] | 454 | /* TODO: more than 1 TCHs? */ |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 455 | default: |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | return channel_mode << 4 | channel; |
| 460 | } |
| 461 | |
| 462 | const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 463 | char *gsm0808_channel_type_name_buf(char *buf, size_t buf_len, const struct gsm0808_channel_type *ct); |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 464 | char *gsm0808_channel_type_name_c(const void *ctx, const struct gsm0808_channel_type *ct); |
Neels Hofmeyr | afacc2b | 2018-04-16 22:41:51 +0200 | [diff] [blame] | 465 | |
Andreas Eversberg | 5c7336c | 2023-04-20 11:04:14 +0200 | [diff] [blame] | 466 | uint8_t gsm0808_enc_group_callref(struct msgb *msg, const struct gsm0808_group_callref *gc); |
| 467 | int gsm0808_dec_group_callref(struct gsm0808_group_callref *gc, const uint8_t *elem, uint8_t len); |
| 468 | uint8_t gsm0808_enc_priority(struct msgb *msg, const struct gsm0808_priority *pri); |
| 469 | int gsm0808_dec_priority(struct gsm0808_priority *pri, const uint8_t *elem, uint8_t len); |
| 470 | uint8_t gsm0808_enc_vgcs_feature_flags(struct msgb *msg, const struct gsm0808_vgcs_feature_flags *ff); |
| 471 | int gsm0808_dec_vgcs_feature_flags(struct gsm0808_vgcs_feature_flags *ff, const uint8_t *elem, uint8_t len); |
| 472 | uint8_t gsm0808_enc_talker_identity(struct msgb *msg, const struct gsm0808_talker_identity *ti); |
| 473 | int gsm0808_dec_talker_identity(struct gsm0808_talker_identity *ti, const uint8_t *elem, uint8_t len); |
| 474 | uint8_t gsm0808_enc_data_identity(struct msgb *msg, const struct gsm0808_data_identity *ai); |
| 475 | int gsm0808_dec_data_identity(struct gsm0808_data_identity *ai, const uint8_t *elem, uint8_t len); |
| 476 | uint8_t gsm0808_enc_msisdn(struct msgb *msg, const char *msisdn); |
| 477 | int gsm0808_dec_msisdn(char *msisdn, const char *elem, uint8_t len); |
| 478 | uint8_t gsm0808_enc_assign_req(struct msgb *msg, const enum gsm0808_assignment_requirement ar); |
| 479 | int gsm0808_dec_assign_req(enum gsm0808_assignment_requirement *ar, const uint8_t *elem, uint8_t len); |
| 480 | uint8_t gsm0808_enc_cell_id_list_segment(struct msgb *msg, uint8_t ie_type, |
| 481 | const struct gsm0808_cell_id_list_segment *ci); |
| 482 | int gsm0808_dec_cell_id_list_segment(struct gsm0808_cell_id_list_segment *ci, const uint8_t *elem, uint8_t len); |
| 483 | int gsm0808_dec_call_id(uint32_t *ci, const uint8_t *elem, uint8_t len); |
| 484 | |
Harald Welte | 37b6165 | 2017-10-16 18:46:03 +0200 | [diff] [blame] | 485 | /*! @} */ |