Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gsm48.c |
| 2 | * GSM Mobile Radio Interface Layer 3 messages |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 3 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 4 | /* |
| 5 | * (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 6 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 7 | * |
| 8 | * All Rights Reserved |
| 9 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | * |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | #include <stdio.h> |
| 30 | #include <string.h> |
Max | fe65fa7 | 2016-05-10 17:17:05 +0200 | [diff] [blame] | 31 | #include <stdbool.h> |
Pau Espin Pedrol | 4573502 | 2017-06-18 14:05:24 +0200 | [diff] [blame] | 32 | #include <inttypes.h> |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 33 | #include <ctype.h> |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 34 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 35 | #include <osmocom/core/utils.h> |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 36 | #include <osmocom/core/byteswap.h> |
| 37 | #include <osmocom/core/bit16gen.h> |
| 38 | #include <osmocom/core/bit32gen.h> |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 39 | #include <osmocom/core/talloc.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 40 | #include <osmocom/gsm/tlv.h> |
| 41 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | 94df39e | 2011-06-26 14:33:57 +0200 | [diff] [blame] | 42 | #include <osmocom/gsm/gsm0502.h> |
Max | fb348ee | 2016-03-30 21:14:53 +0200 | [diff] [blame] | 43 | #include <osmocom/gsm/gsm_utils.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 44 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Vadim Yanitskiy | 8d41d72 | 2018-04-17 11:17:28 +0700 | [diff] [blame] | 45 | #include <osmocom/gsm/protocol/gsm_04_80.h> |
Harald Welte | 2aee7b1 | 2011-06-26 14:20:04 +0200 | [diff] [blame] | 46 | #include <osmocom/gsm/protocol/gsm_08_58.h> |
Max | fdca25d | 2016-07-05 16:06:28 +0200 | [diff] [blame] | 47 | #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 48 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 49 | /*! \addtogroup gsm0408 |
| 50 | * @{ |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 51 | * GSM Mobile Radion Interface L3 messages / TS 04.08 |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 52 | */ |
| 53 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 54 | /*! TLV parser definitions for TS 04.08 CC */ |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 55 | const struct tlv_definition gsm48_att_tlvdef = { |
| 56 | .def = { |
| 57 | [GSM48_IE_MOBILE_ID] = { TLV_TYPE_TLV }, |
| 58 | [GSM48_IE_NAME_LONG] = { TLV_TYPE_TLV }, |
| 59 | [GSM48_IE_NAME_SHORT] = { TLV_TYPE_TLV }, |
| 60 | [GSM48_IE_UTC] = { TLV_TYPE_TV }, |
| 61 | [GSM48_IE_NET_TIME_TZ] = { TLV_TYPE_FIXED, 7 }, |
| 62 | [GSM48_IE_LSA_IDENT] = { TLV_TYPE_TLV }, |
| 63 | |
| 64 | [GSM48_IE_BEARER_CAP] = { TLV_TYPE_TLV }, |
| 65 | [GSM48_IE_CAUSE] = { TLV_TYPE_TLV }, |
| 66 | [GSM48_IE_CC_CAP] = { TLV_TYPE_TLV }, |
| 67 | [GSM48_IE_ALERT] = { TLV_TYPE_TLV }, |
| 68 | [GSM48_IE_FACILITY] = { TLV_TYPE_TLV }, |
| 69 | [GSM48_IE_PROGR_IND] = { TLV_TYPE_TLV }, |
| 70 | [GSM48_IE_AUX_STATUS] = { TLV_TYPE_TLV }, |
| 71 | [GSM48_IE_NOTIFY] = { TLV_TYPE_TV }, |
| 72 | [GSM48_IE_KPD_FACILITY] = { TLV_TYPE_TV }, |
| 73 | [GSM48_IE_SIGNAL] = { TLV_TYPE_TV }, |
| 74 | [GSM48_IE_CONN_BCD] = { TLV_TYPE_TLV }, |
| 75 | [GSM48_IE_CONN_SUB] = { TLV_TYPE_TLV }, |
| 76 | [GSM48_IE_CALLING_BCD] = { TLV_TYPE_TLV }, |
| 77 | [GSM48_IE_CALLING_SUB] = { TLV_TYPE_TLV }, |
| 78 | [GSM48_IE_CALLED_BCD] = { TLV_TYPE_TLV }, |
| 79 | [GSM48_IE_CALLED_SUB] = { TLV_TYPE_TLV }, |
| 80 | [GSM48_IE_REDIR_BCD] = { TLV_TYPE_TLV }, |
| 81 | [GSM48_IE_REDIR_SUB] = { TLV_TYPE_TLV }, |
| 82 | [GSM48_IE_LOWL_COMPAT] = { TLV_TYPE_TLV }, |
| 83 | [GSM48_IE_HIGHL_COMPAT] = { TLV_TYPE_TLV }, |
| 84 | [GSM48_IE_USER_USER] = { TLV_TYPE_TLV }, |
| 85 | [GSM48_IE_SS_VERS] = { TLV_TYPE_TLV }, |
| 86 | [GSM48_IE_MORE_DATA] = { TLV_TYPE_T }, |
| 87 | [GSM48_IE_CLIR_SUPP] = { TLV_TYPE_T }, |
| 88 | [GSM48_IE_CLIR_INVOC] = { TLV_TYPE_T }, |
| 89 | [GSM48_IE_REV_C_SETUP] = { TLV_TYPE_T }, |
| 90 | [GSM48_IE_REPEAT_CIR] = { TLV_TYPE_T }, |
| 91 | [GSM48_IE_REPEAT_SEQ] = { TLV_TYPE_T }, |
| 92 | /* FIXME: more elements */ |
| 93 | }, |
| 94 | }; |
| 95 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 96 | /*! TLV parser definitions for TS 04.08 RR */ |
Andreas Eversberg | 014cb87 | 2010-07-12 09:11:00 +0200 | [diff] [blame] | 97 | const struct tlv_definition gsm48_rr_att_tlvdef = { |
| 98 | .def = { |
| 99 | /* NOTE: Don't add IE 17 = MOBILE_ID here, it already used. */ |
| 100 | [GSM48_IE_VGCS_TARGET] = { TLV_TYPE_TLV }, |
| 101 | [GSM48_IE_FRQSHORT_AFTER] = { TLV_TYPE_FIXED, 9 }, |
| 102 | [GSM48_IE_MUL_RATE_CFG] = { TLV_TYPE_TLV }, |
| 103 | [GSM48_IE_FREQ_L_AFTER] = { TLV_TYPE_TLV }, |
| 104 | [GSM48_IE_MSLOT_DESC] = { TLV_TYPE_TLV }, |
| 105 | [GSM48_IE_CHANMODE_2] = { TLV_TYPE_TV }, |
| 106 | [GSM48_IE_FRQSHORT_BEFORE] = { TLV_TYPE_FIXED, 9 }, |
| 107 | [GSM48_IE_CHANMODE_3] = { TLV_TYPE_TV }, |
| 108 | [GSM48_IE_CHANMODE_4] = { TLV_TYPE_TV }, |
| 109 | [GSM48_IE_CHANMODE_5] = { TLV_TYPE_TV }, |
| 110 | [GSM48_IE_CHANMODE_6] = { TLV_TYPE_TV }, |
| 111 | [GSM48_IE_CHANMODE_7] = { TLV_TYPE_TV }, |
| 112 | [GSM48_IE_CHANMODE_8] = { TLV_TYPE_TV }, |
| 113 | [GSM48_IE_FREQ_L_BEFORE] = { TLV_TYPE_TLV }, |
| 114 | [GSM48_IE_CH_DESC_1_BEFORE] = { TLV_TYPE_FIXED, 3 }, |
| 115 | [GSM48_IE_CH_DESC_2_BEFORE] = { TLV_TYPE_FIXED, 3 }, |
| 116 | [GSM48_IE_F_CH_SEQ_BEFORE] = { TLV_TYPE_FIXED, 9 }, |
| 117 | [GSM48_IE_CLASSMARK3] = { TLV_TYPE_TLV }, |
| 118 | [GSM48_IE_MA_BEFORE] = { TLV_TYPE_TLV }, |
| 119 | [GSM48_IE_RR_PACKET_UL] = { TLV_TYPE_TLV }, |
| 120 | [GSM48_IE_RR_PACKET_DL] = { TLV_TYPE_TLV }, |
| 121 | [GSM48_IE_CELL_CH_DESC] = { TLV_TYPE_FIXED, 16 }, |
| 122 | [GSM48_IE_CHANMODE_1] = { TLV_TYPE_TV }, |
| 123 | [GSM48_IE_CHDES_2_AFTER] = { TLV_TYPE_FIXED, 3 }, |
| 124 | [GSM48_IE_MODE_SEC_CH] = { TLV_TYPE_TV }, |
| 125 | [GSM48_IE_F_CH_SEQ_AFTER] = { TLV_TYPE_FIXED, 9 }, |
| 126 | [GSM48_IE_MA_AFTER] = { TLV_TYPE_TLV }, |
| 127 | [GSM48_IE_BA_RANGE] = { TLV_TYPE_TLV }, |
| 128 | [GSM48_IE_GROUP_CHDES] = { TLV_TYPE_TLV }, |
| 129 | [GSM48_IE_BA_LIST_PREF] = { TLV_TYPE_TLV }, |
| 130 | [GSM48_IE_MOB_OVSERV_DIF] = { TLV_TYPE_TLV }, |
| 131 | [GSM48_IE_REALTIME_DIFF] = { TLV_TYPE_TLV }, |
| 132 | [GSM48_IE_START_TIME] = { TLV_TYPE_FIXED, 2 }, |
| 133 | [GSM48_IE_TIMING_ADVANCE] = { TLV_TYPE_TV }, |
| 134 | [GSM48_IE_GROUP_CIP_SEQ] = { TLV_TYPE_SINGLE_TV }, |
| 135 | [GSM48_IE_CIP_MODE_SET] = { TLV_TYPE_SINGLE_TV }, |
| 136 | [GSM48_IE_GPRS_RESUMPT] = { TLV_TYPE_SINGLE_TV }, |
| 137 | [GSM48_IE_SYNC_IND] = { TLV_TYPE_SINGLE_TV }, |
| 138 | }, |
| 139 | }; |
| 140 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 141 | /*! TLV parser definitions for TS 04.08 MM */ |
Andreas Eversberg | 014cb87 | 2010-07-12 09:11:00 +0200 | [diff] [blame] | 142 | const struct tlv_definition gsm48_mm_att_tlvdef = { |
| 143 | .def = { |
| 144 | [GSM48_IE_MOBILE_ID] = { TLV_TYPE_TLV }, |
| 145 | [GSM48_IE_NAME_LONG] = { TLV_TYPE_TLV }, |
| 146 | [GSM48_IE_NAME_SHORT] = { TLV_TYPE_TLV }, |
| 147 | [GSM48_IE_UTC] = { TLV_TYPE_TV }, |
| 148 | [GSM48_IE_NET_TIME_TZ] = { TLV_TYPE_FIXED, 7 }, |
| 149 | [GSM48_IE_LSA_IDENT] = { TLV_TYPE_TLV }, |
Jacob Erlbeck | 1c3f088 | 2013-09-16 10:29:57 +0200 | [diff] [blame] | 150 | [GSM48_IE_NET_DST] = { TLV_TYPE_TLV }, |
Andreas Eversberg | 014cb87 | 2010-07-12 09:11:00 +0200 | [diff] [blame] | 151 | |
| 152 | [GSM48_IE_LOCATION_AREA] = { TLV_TYPE_FIXED, 5 }, |
| 153 | [GSM48_IE_PRIORITY_LEV] = { TLV_TYPE_SINGLE_TV }, |
| 154 | [GSM48_IE_FOLLOW_ON_PROC] = { TLV_TYPE_T }, |
| 155 | [GSM48_IE_CTS_PERMISSION] = { TLV_TYPE_T }, |
| 156 | }, |
| 157 | }; |
| 158 | |
Harald Welte | e9e190a | 2010-03-25 11:44:57 +0800 | [diff] [blame] | 159 | static const struct value_string rr_cause_names[] = { |
| 160 | { GSM48_RR_CAUSE_NORMAL, "Normal event" }, |
| 161 | { GSM48_RR_CAUSE_ABNORMAL_UNSPEC, "Abnormal release, unspecified" }, |
| 162 | { GSM48_RR_CAUSE_ABNORMAL_UNACCT, "Abnormal release, channel unacceptable" }, |
| 163 | { GSM48_RR_CAUSE_ABNORMAL_TIMER, "Abnormal release, timer expired" }, |
| 164 | { GSM48_RR_CAUSE_ABNORMAL_NOACT, "Abnormal release, no activity on radio path" }, |
| 165 | { GSM48_RR_CAUSE_PREMPTIVE_REL, "Preemptive release" }, |
| 166 | { GSM48_RR_CAUSE_HNDOVER_IMP, "Handover impossible, timing advance out of range" }, |
| 167 | { GSM48_RR_CAUSE_CHAN_MODE_UNACCT, "Channel mode unacceptable" }, |
| 168 | { GSM48_RR_CAUSE_FREQ_NOT_IMPL, "Frequency not implemented" }, |
| 169 | { GSM48_RR_CAUSE_CALL_CLEARED, "Call already cleared" }, |
| 170 | { GSM48_RR_CAUSE_SEMANT_INCORR, "Semantically incorrect message" }, |
| 171 | { GSM48_RR_CAUSE_INVALID_MAND_INF, "Invalid mandatory information" }, |
| 172 | { GSM48_RR_CAUSE_MSG_TYPE_N, "Message type non-existant or not implemented" }, |
| 173 | { GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT, "Message type not compatible with protocol state" }, |
| 174 | { GSM48_RR_CAUSE_COND_IE_ERROR, "Conditional IE error" }, |
| 175 | { GSM48_RR_CAUSE_NO_CELL_ALLOC_A, "No cell allocation available" }, |
| 176 | { GSM48_RR_CAUSE_PROT_ERROR_UNSPC, "Protocol error unspecified" }, |
| 177 | { 0, NULL }, |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 180 | /*! return string representation of RR Cause value */ |
Philipp | ada0042 | 2016-10-27 13:30:16 +0200 | [diff] [blame] | 181 | const char *rr_cause_name(uint8_t cause) |
| 182 | { |
| 183 | return get_value_string(rr_cause_names, cause); |
| 184 | } |
| 185 | |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 186 | /*! Return MCC-MNC-LAC-RAC as string, in a caller-provided output buffer. |
| 187 | * \param[out] buf caller-provided output buffer |
| 188 | * \param[in] buf_len size of buf in bytes |
| 189 | * \param[in] rai RAI to encode. |
| 190 | * \returns buf |
| 191 | */ |
| 192 | char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai) |
| 193 | { |
| 194 | snprintf(buf, buf_len, "%s-%s-%u-%u", |
| 195 | osmo_mcc_name(rai->mcc), osmo_mnc_name(rai->mnc, rai->mnc_3_digits), rai->lac, |
| 196 | rai->rac); |
| 197 | return buf; |
| 198 | } |
| 199 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 200 | /*! Return MCC-MNC-LAC-RAC as string, in a static buffer. |
| 201 | * \param[in] rai RAI to encode. |
| 202 | * \returns Static string buffer. |
| 203 | */ |
| 204 | const char *osmo_rai_name(const struct gprs_ra_id *rai) |
| 205 | { |
Harald Welte | 171ef82 | 2019-03-28 10:49:05 +0100 | [diff] [blame] | 206 | static __thread char buf[32]; |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 207 | return osmo_rai_name_buf(buf, sizeof(buf), rai); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 208 | } |
| 209 | |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 210 | /*! Return MCC-MNC-LAC-RAC as string, in dynamically-allocated output buffer. |
| 211 | * \param[in] ctx talloc context from which to allocate output buffer |
| 212 | * \param[in] rai RAI to encode. |
| 213 | * \returns string representation in dynamically-allocated output buffer. |
| 214 | */ |
| 215 | char *osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai) |
| 216 | { |
| 217 | char *buf = talloc_size(ctx, 32); |
| 218 | if (!buf) |
| 219 | return NULL; |
| 220 | return osmo_rai_name_buf(buf, 32, rai); |
| 221 | } |
| 222 | |
Harald Welte | 9eb6d88 | 2010-03-25 12:00:54 +0800 | [diff] [blame] | 223 | /* FIXME: convert to value_string */ |
Andreas Eversberg | 014cb87 | 2010-07-12 09:11:00 +0200 | [diff] [blame] | 224 | static const char *cc_state_names[32] = { |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 225 | "NULL", |
| 226 | "INITIATED", |
Andreas Eversberg | 1ef041f | 2010-04-09 07:52:12 +0200 | [diff] [blame] | 227 | "MM_CONNECTION_PEND", |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 228 | "MO_CALL_PROC", |
| 229 | "CALL_DELIVERED", |
| 230 | "illegal state 5", |
| 231 | "CALL_PRESENT", |
| 232 | "CALL_RECEIVED", |
| 233 | "CONNECT_REQUEST", |
| 234 | "MO_TERM_CALL_CONF", |
| 235 | "ACTIVE", |
| 236 | "DISCONNECT_REQ", |
| 237 | "DISCONNECT_IND", |
| 238 | "illegal state 13", |
| 239 | "illegal state 14", |
| 240 | "illegal state 15", |
| 241 | "illegal state 16", |
| 242 | "illegal state 17", |
| 243 | "illegal state 18", |
| 244 | "RELEASE_REQ", |
| 245 | "illegal state 20", |
| 246 | "illegal state 21", |
| 247 | "illegal state 22", |
| 248 | "illegal state 23", |
| 249 | "illegal state 24", |
| 250 | "illegal state 25", |
| 251 | "MO_ORIG_MODIFY", |
| 252 | "MO_TERM_MODIFY", |
| 253 | "CONNECT_IND", |
| 254 | "illegal state 29", |
| 255 | "illegal state 30", |
| 256 | "illegal state 31", |
| 257 | }; |
| 258 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 259 | /*! return string representation of CC State */ |
Harald Welte | 9eb6d88 | 2010-03-25 12:00:54 +0800 | [diff] [blame] | 260 | const char *gsm48_cc_state_name(uint8_t state) |
| 261 | { |
| 262 | if (state < ARRAY_SIZE(cc_state_names)) |
| 263 | return cc_state_names[state]; |
| 264 | |
| 265 | return "invalid"; |
| 266 | } |
| 267 | |
| 268 | static const struct value_string cc_msg_names[] = { |
| 269 | { GSM48_MT_CC_ALERTING, "ALERTING" }, |
| 270 | { GSM48_MT_CC_CALL_PROC, "CALL_PROC" }, |
| 271 | { GSM48_MT_CC_PROGRESS, "PROGRESS" }, |
| 272 | { GSM48_MT_CC_ESTAB, "ESTAB" }, |
| 273 | { GSM48_MT_CC_SETUP, "SETUP" }, |
| 274 | { GSM48_MT_CC_ESTAB_CONF, "ESTAB_CONF" }, |
| 275 | { GSM48_MT_CC_CONNECT, "CONNECT" }, |
| 276 | { GSM48_MT_CC_CALL_CONF, "CALL_CONF" }, |
| 277 | { GSM48_MT_CC_START_CC, "START_CC" }, |
| 278 | { GSM48_MT_CC_RECALL, "RECALL" }, |
| 279 | { GSM48_MT_CC_EMERG_SETUP, "EMERG_SETUP" }, |
| 280 | { GSM48_MT_CC_CONNECT_ACK, "CONNECT_ACK" }, |
| 281 | { GSM48_MT_CC_USER_INFO, "USER_INFO" }, |
| 282 | { GSM48_MT_CC_MODIFY_REJECT, "MODIFY_REJECT" }, |
| 283 | { GSM48_MT_CC_MODIFY, "MODIFY" }, |
| 284 | { GSM48_MT_CC_HOLD, "HOLD" }, |
| 285 | { GSM48_MT_CC_HOLD_ACK, "HOLD_ACK" }, |
| 286 | { GSM48_MT_CC_HOLD_REJ, "HOLD_REJ" }, |
| 287 | { GSM48_MT_CC_RETR, "RETR" }, |
| 288 | { GSM48_MT_CC_RETR_ACK, "RETR_ACK" }, |
| 289 | { GSM48_MT_CC_RETR_REJ, "RETR_REJ" }, |
| 290 | { GSM48_MT_CC_MODIFY_COMPL, "MODIFY_COMPL" }, |
| 291 | { GSM48_MT_CC_DISCONNECT, "DISCONNECT" }, |
| 292 | { GSM48_MT_CC_RELEASE_COMPL, "RELEASE_COMPL" }, |
| 293 | { GSM48_MT_CC_RELEASE, "RELEASE" }, |
| 294 | { GSM48_MT_CC_STOP_DTMF, "STOP_DTMF" }, |
| 295 | { GSM48_MT_CC_STOP_DTMF_ACK, "STOP_DTMF_ACK" }, |
| 296 | { GSM48_MT_CC_STATUS_ENQ, "STATUS_ENQ" }, |
| 297 | { GSM48_MT_CC_START_DTMF, "START_DTMF" }, |
| 298 | { GSM48_MT_CC_START_DTMF_ACK, "START_DTMF_ACK" }, |
| 299 | { GSM48_MT_CC_START_DTMF_REJ, "START_DTMF_REJ" }, |
| 300 | { GSM48_MT_CC_CONG_CTRL, "CONG_CTRL" }, |
| 301 | { GSM48_MT_CC_FACILITY, "FACILITY" }, |
| 302 | { GSM48_MT_CC_STATUS, "STATUS" }, |
| 303 | { GSM48_MT_CC_NOTIFY, "NOTFIY" }, |
| 304 | { 0, NULL } |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 305 | }; |
| 306 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 307 | /*! return string representation of CC Message Type */ |
Harald Welte | 9eb6d88 | 2010-03-25 12:00:54 +0800 | [diff] [blame] | 308 | const char *gsm48_cc_msg_name(uint8_t msgtype) |
| 309 | { |
| 310 | return get_value_string(cc_msg_names, msgtype); |
| 311 | } |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 312 | |
Philipp | 72e43f0 | 2016-10-27 13:35:20 +0200 | [diff] [blame] | 313 | |
| 314 | static const struct value_string rr_msg_names[] = { |
| 315 | /* Channel establishment messages */ |
| 316 | { GSM48_MT_RR_INIT_REQ, "RR INITIALISATION REQUEST" }, |
| 317 | { GSM48_MT_RR_ADD_ASS, "ADDITIONAL ASSIGNMENT" }, |
| 318 | { GSM48_MT_RR_IMM_ASS, "IMMEDIATE ASSIGNMENT" }, |
| 319 | { GSM48_MT_RR_IMM_ASS_EXT, "MMEDIATE ASSIGNMENT EXTENDED" }, |
| 320 | { GSM48_MT_RR_IMM_ASS_REJ, "IMMEDIATE ASSIGNMENT REJECT" }, |
| 321 | { GSM48_MT_RR_DTM_ASS_FAIL, "DTM ASSIGNMENT FAILURE" }, |
| 322 | { GSM48_MT_RR_DTM_REJECT, "DTM REJECT" }, |
| 323 | { GSM48_MT_RR_DTM_REQUEST, "DTM REQUEST" }, |
| 324 | { GSM48_MT_RR_PACKET_ASS, "PACKET ASSIGNMENT" }, |
| 325 | |
| 326 | /* Ciphering messages */ |
| 327 | { GSM48_MT_RR_CIPH_M_CMD, "CIPHERING MODE COMMAND" }, |
| 328 | { GSM48_MT_RR_CIPH_M_COMPL, "CIPHERING MODE COMPLETE" }, |
| 329 | |
| 330 | /* Configuration change messages */ |
| 331 | { GSM48_MT_RR_CFG_CHG_CMD, "CONFIGURATION CHANGE COMMAND" }, |
| 332 | { GSM48_MT_RR_CFG_CHG_ACK, "CONFIGURATION CHANGE ACK" }, |
| 333 | { GSM48_MT_RR_CFG_CHG_REJ, "CONFIGURATION CHANGE REJECT" }, |
| 334 | |
| 335 | /* Handover messages */ |
| 336 | { GSM48_MT_RR_ASS_CMD, "ASSIGNMENT COMMAND" }, |
| 337 | { GSM48_MT_RR_ASS_COMPL, "ASSIGNMENT COMPLETE" }, |
| 338 | { GSM48_MT_RR_ASS_FAIL, "ASSIGNMENT FAILURE" }, |
| 339 | { GSM48_MT_RR_HANDO_CMD, "HANDOVER COMMAND" }, |
| 340 | { GSM48_MT_RR_HANDO_COMPL, "HANDOVER COMPLETE" }, |
| 341 | { GSM48_MT_RR_HANDO_FAIL, "HANDOVER FAILURE" }, |
| 342 | { GSM48_MT_RR_HANDO_INFO, "PHYSICAL INFORMATION" }, |
| 343 | { GSM48_MT_RR_DTM_ASS_CMD, "DTM ASSIGNMENT COMMAND" }, |
| 344 | |
| 345 | { GSM48_MT_RR_CELL_CHG_ORDER, "RR-CELL CHANGE ORDER" }, |
| 346 | { GSM48_MT_RR_PDCH_ASS_CMD, "PDCH ASSIGNMENT COMMAND" }, |
| 347 | |
| 348 | /* Channel release messages */ |
| 349 | { GSM48_MT_RR_CHAN_REL, "CHANNEL RELEASE" }, |
| 350 | { GSM48_MT_RR_PART_REL, "PARTIAL RELEASE" }, |
| 351 | { GSM48_MT_RR_PART_REL_COMP, "PARTIAL RELEASE COMPLETE" }, |
| 352 | |
| 353 | /* Paging and Notification messages */ |
| 354 | { GSM48_MT_RR_PAG_REQ_1, "PAGING REQUEST TYPE 1" }, |
| 355 | { GSM48_MT_RR_PAG_REQ_2, "PAGING REQUEST TYPE 2" }, |
| 356 | { GSM48_MT_RR_PAG_REQ_3, "PAGING REQUEST TYPE 3" }, |
| 357 | { GSM48_MT_RR_PAG_RESP, "PAGING RESPONSE" }, |
| 358 | { GSM48_MT_RR_NOTIF_NCH, "NOTIFICATION/NCH" }, |
| 359 | { GSM48_MT_RR_NOTIF_FACCH, "(Reserved)" }, |
| 360 | { GSM48_MT_RR_NOTIF_RESP, "NOTIFICATION/RESPONSE" }, |
| 361 | { GSM48_MT_RR_PACKET_NOTIF, "PACKET NOTIFICATION" }, |
| 362 | /* 3G Specific messages */ |
| 363 | { GSM48_MT_RR_UTRAN_CLSM_CHG, "UTRAN Classmark Change" }, |
| 364 | { GSM48_MT_RR_CDMA2K_CLSM_CHG, "cdma 2000 Classmark Change" }, |
| 365 | { GSM48_MT_RR_IS_TO_UTRAN_HANDO, "Inter System to UTRAN Handover Command" }, |
| 366 | { GSM48_MT_RR_IS_TO_CDMA2K_HANDO, "Inter System to cdma2000 Handover Command" }, |
| 367 | |
| 368 | /* System information messages */ |
| 369 | { GSM48_MT_RR_SYSINFO_8, "SYSTEM INFORMATION TYPE 8" }, |
| 370 | { GSM48_MT_RR_SYSINFO_1, "SYSTEM INFORMATION TYPE 1" }, |
| 371 | { GSM48_MT_RR_SYSINFO_2, "SYSTEM INFORMATION TYPE 2" }, |
| 372 | { GSM48_MT_RR_SYSINFO_3, "SYSTEM INFORMATION TYPE 3" }, |
| 373 | { GSM48_MT_RR_SYSINFO_4, "SYSTEM INFORMATION TYPE 4" }, |
| 374 | { GSM48_MT_RR_SYSINFO_5, "SYSTEM INFORMATION TYPE 5" }, |
| 375 | { GSM48_MT_RR_SYSINFO_6, "SYSTEM INFORMATION TYPE 6" }, |
| 376 | { GSM48_MT_RR_SYSINFO_7, "SYSTEM INFORMATION TYPE 7" }, |
| 377 | { GSM48_MT_RR_SYSINFO_2bis, "SYSTEM INFORMATION TYPE 2bis" }, |
| 378 | { GSM48_MT_RR_SYSINFO_2ter, "SYSTEM INFORMATION TYPE 2ter" }, |
| 379 | { GSM48_MT_RR_SYSINFO_2quater, "SYSTEM INFORMATION TYPE 2quater" }, |
| 380 | { GSM48_MT_RR_SYSINFO_5bis, "SYSTEM INFORMATION TYPE 5bis" }, |
| 381 | { GSM48_MT_RR_SYSINFO_5ter, "SYSTEM INFORMATION TYPE 5ter" }, |
| 382 | { GSM48_MT_RR_SYSINFO_9, "SYSTEM INFORMATION TYPE 9" }, |
| 383 | { GSM48_MT_RR_SYSINFO_13, "SYSTEM INFORMATION TYPE 13" }, |
| 384 | { GSM48_MT_RR_SYSINFO_16, "SYSTEM INFORMATION TYPE 16" }, |
| 385 | { GSM48_MT_RR_SYSINFO_17, "SYSTEM INFORMATION TYPE 17" }, |
| 386 | { GSM48_MT_RR_SYSINFO_18, "SYSTEM INFORMATION TYPE 18" }, |
| 387 | { GSM48_MT_RR_SYSINFO_19, "SYSTEM INFORMATION TYPE 19" }, |
| 388 | { GSM48_MT_RR_SYSINFO_20, "SYSTEM INFORMATION TYPE 20" }, |
| 389 | |
| 390 | /* Miscellaneous messages */ |
| 391 | { GSM48_MT_RR_CHAN_MODE_MODIF, "CHANNEL MODE MODIFY" }, |
| 392 | { GSM48_MT_RR_STATUS, "RR STATUS" }, |
| 393 | { GSM48_MT_RR_CHAN_MODE_MODIF_ACK, "CHANNEL MODE MODIFY ACKNOWLEDGE" }, |
| 394 | { GSM48_MT_RR_FREQ_REDEF, "FREQUENCY REDEFINITION" }, |
| 395 | { GSM48_MT_RR_MEAS_REP, "MEASUREMENT REPORT" }, |
| 396 | { GSM48_MT_RR_CLSM_CHG, "CLASSMARK CHANGE" }, |
| 397 | { GSM48_MT_RR_CLSM_ENQ, "CLASSMARK ENQUIRY" }, |
| 398 | { GSM48_MT_RR_EXT_MEAS_REP, "EXTENDED MEASUREMENT REPORT" }, |
| 399 | { GSM48_MT_RR_EXT_MEAS_REP_ORD, "EXTENDED MEASUREMENT ORDER" }, |
| 400 | { GSM48_MT_RR_GPRS_SUSP_REQ, "GPRS SUSPENSION REQUEST" }, |
| 401 | { GSM48_MT_RR_DTM_INFO, "DTM INFORMATION" }, |
| 402 | |
| 403 | /* VGCS uplink control messages */ |
| 404 | { GSM48_MT_RR_VGCS_UPL_GRANT, "VGCS UPLINK GRANT" }, |
| 405 | { GSM48_MT_RR_UPLINK_RELEASE, "UPLINK RELEASE" }, |
| 406 | { GSM48_MT_RR_UPLINK_FREE, "0c" }, |
| 407 | { GSM48_MT_RR_UPLINK_BUSY, "UPLINK BUSY" }, |
| 408 | { GSM48_MT_RR_TALKER_IND, "TALKER INDICATION" }, |
| 409 | |
| 410 | /* Application messages */ |
| 411 | { GSM48_MT_RR_APP_INFO, "Application Information" }, |
| 412 | { 0, NULL } |
| 413 | }; |
| 414 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 415 | /*! return string representation of RR Message Type */ |
Philipp | 72e43f0 | 2016-10-27 13:35:20 +0200 | [diff] [blame] | 416 | const char *gsm48_rr_msg_name(uint8_t msgtype) |
| 417 | { |
| 418 | return get_value_string(rr_msg_names, msgtype); |
| 419 | } |
| 420 | |
| 421 | |
Max | fb348ee | 2016-03-30 21:14:53 +0200 | [diff] [blame] | 422 | const struct value_string gsm48_chan_mode_names[] = { |
| 423 | { GSM48_CMODE_SIGN, "SIGNALLING" }, |
| 424 | { GSM48_CMODE_SPEECH_V1, "SPEECH_V1" }, |
| 425 | { GSM48_CMODE_SPEECH_EFR, "SPEECH_EFR" }, |
| 426 | { GSM48_CMODE_SPEECH_AMR, "SPEECH_AMR" }, |
| 427 | { GSM48_CMODE_DATA_14k5, "DATA_14k5" }, |
| 428 | { GSM48_CMODE_DATA_12k0, "DATA_12k0" }, |
| 429 | { GSM48_CMODE_DATA_6k0, "DATA_6k0" }, |
| 430 | { GSM48_CMODE_DATA_3k6, "DATA_3k6" }, |
| 431 | { 0, NULL }, |
| 432 | }; |
| 433 | |
| 434 | const struct value_string gsm_chan_t_names[] = { |
| 435 | { GSM_LCHAN_NONE, "NONE" }, |
| 436 | { GSM_LCHAN_SDCCH, "SDCCH" }, |
| 437 | { GSM_LCHAN_TCH_F, "TCH_F" }, |
| 438 | { GSM_LCHAN_TCH_H, "TCH_H" }, |
| 439 | { GSM_LCHAN_UNKNOWN, "UNKNOWN" }, |
| 440 | { GSM_LCHAN_CCCH, "CCCH" }, |
| 441 | { GSM_LCHAN_PDTCH, "PDTCH" }, |
| 442 | { GSM_LCHAN_CBCH, "CBCH" }, |
| 443 | { 0, NULL }, |
| 444 | }; |
| 445 | |
Harald Welte | 1a8c4e0 | 2015-08-16 17:56:25 +0200 | [diff] [blame] | 446 | static const struct value_string mi_type_names[] = { |
| 447 | { GSM_MI_TYPE_NONE, "NONE" }, |
| 448 | { GSM_MI_TYPE_IMSI, "IMSI" }, |
| 449 | { GSM_MI_TYPE_IMEI, "IMEI" }, |
| 450 | { GSM_MI_TYPE_IMEISV, "IMEI-SV" }, |
| 451 | { GSM_MI_TYPE_TMSI, "TMSI" }, |
| 452 | { 0, NULL } |
| 453 | }; |
| 454 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 455 | /*! return string representation of Mobile Identity Type */ |
Harald Welte | 1a8c4e0 | 2015-08-16 17:56:25 +0200 | [diff] [blame] | 456 | const char *gsm48_mi_type_name(uint8_t mi) |
| 457 | { |
| 458 | return get_value_string(mi_type_names, mi); |
| 459 | } |
| 460 | |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 461 | /*! Return a human readable representation of a Mobile Identity in caller-provided buffer. |
| 462 | * \param[out] buf caller-provided output buffer |
| 463 | * \param[in] buf_len size of buf in bytes |
Neels Hofmeyr | 02fd83d | 2019-01-05 00:38:54 +0100 | [diff] [blame] | 464 | * \param[in] mi Mobile Identity buffer containing 3GPP TS 04.08 style MI type and data. |
| 465 | * \param[in] mi_len Length of mi. |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 466 | * \return buf |
Neels Hofmeyr | 02fd83d | 2019-01-05 00:38:54 +0100 | [diff] [blame] | 467 | */ |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 468 | char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len) |
Neels Hofmeyr | 02fd83d | 2019-01-05 00:38:54 +0100 | [diff] [blame] | 469 | { |
Neels Hofmeyr | 02fd83d | 2019-01-05 00:38:54 +0100 | [diff] [blame] | 470 | uint8_t mi_type; |
| 471 | uint32_t tmsi; |
| 472 | char mi_string[GSM48_MI_SIZE]; |
| 473 | |
| 474 | mi_type = (mi && mi_len) ? (mi[0] & GSM_MI_TYPE_MASK) : GSM_MI_TYPE_NONE; |
| 475 | |
| 476 | switch (mi_type) { |
| 477 | case GSM_MI_TYPE_TMSI: |
| 478 | /* Table 10.5.4.3, reverse generate_mid_from_tmsi */ |
| 479 | if (mi_len == GSM48_TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) { |
| 480 | tmsi = osmo_load32be(&mi[1]); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 481 | snprintf(buf, buf_len, "TMSI-0x%08" PRIX32, tmsi); |
| 482 | return buf; |
Neels Hofmeyr | 02fd83d | 2019-01-05 00:38:54 +0100 | [diff] [blame] | 483 | } |
| 484 | return "TMSI-invalid"; |
| 485 | |
| 486 | case GSM_MI_TYPE_IMSI: |
| 487 | case GSM_MI_TYPE_IMEI: |
| 488 | case GSM_MI_TYPE_IMEISV: |
| 489 | osmo_bcd2str(mi_string, sizeof(mi_string), mi, 1, (mi_len * 2) - (mi[0] & GSM_MI_ODD ? 0 : 1), true); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 490 | snprintf(buf, buf_len, "%s-%s", gsm48_mi_type_name(mi_type), mi_string); |
| 491 | return buf; |
Neels Hofmeyr | 02fd83d | 2019-01-05 00:38:54 +0100 | [diff] [blame] | 492 | |
| 493 | default: |
| 494 | return "unknown"; |
| 495 | } |
| 496 | } |
| 497 | |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 498 | /*! Return a human readable representation of a Mobile Identity in static buffer. |
| 499 | * \param[in] mi Mobile Identity buffer containing 3GPP TS 04.08 style MI type and data. |
| 500 | * \param[in] mi_len Length of mi. |
| 501 | * \return A string like "IMSI-1234567", "TMSI-0x1234ABCD" or "unknown", "TMSI-invalid"... |
| 502 | */ |
| 503 | const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len) |
| 504 | { |
Harald Welte | 171ef82 | 2019-03-28 10:49:05 +0100 | [diff] [blame] | 505 | static __thread char mi_name[10 + GSM48_MI_SIZE + 1]; |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 506 | return osmo_mi_name_buf(mi_name, sizeof(mi_name), mi, mi_len); |
| 507 | } |
| 508 | |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 509 | /*! Return a human readable representation of a Mobile Identity in dynamically-allocated buffer. |
| 510 | * \param[in] ctx talloc context from which to allocate output buffer |
| 511 | * \param[in] mi Mobile Identity buffer containing 3GPP TS 04.08 style MI type and data. |
| 512 | * \param[in] mi_len Length of mi. |
| 513 | * \return A string like "IMSI-1234567", "TMSI-0x1234ABCD" or "unknown", "TMSI-invalid" in a |
| 514 | * dynamically-allocated output buffer. |
| 515 | */ |
| 516 | char *osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len) |
| 517 | { |
| 518 | size_t buf_len = 10 + GSM48_MI_SIZE + 1; |
| 519 | char *mi_name = talloc_size(ctx, buf_len); |
| 520 | if (!mi_name) |
| 521 | return NULL; |
| 522 | return osmo_mi_name_buf(mi_name, buf_len, mi, mi_len); |
| 523 | } |
| 524 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 525 | /*! Checks is particular message is cipherable in A/Gb mode according to |
Max | fdca25d | 2016-07-05 16:06:28 +0200 | [diff] [blame] | 526 | * 3GPP TS 24.008 § 4.7.1.2 |
| 527 | * \param[in] hdr Message header |
| 528 | * \return true if message can be encrypted, false otherwise |
| 529 | */ |
| 530 | bool gsm48_hdr_gmm_cipherable(const struct gsm48_hdr *hdr) |
| 531 | { |
| 532 | switch(hdr->msg_type) { |
| 533 | case GSM48_MT_GMM_ATTACH_REQ: |
| 534 | case GSM48_MT_GMM_ATTACH_REJ: |
| 535 | case GSM48_MT_GMM_AUTH_CIPH_REQ: |
| 536 | case GSM48_MT_GMM_AUTH_CIPH_RESP: |
| 537 | case GSM48_MT_GMM_AUTH_CIPH_REJ: |
| 538 | case GSM48_MT_GMM_AUTH_CIPH_FAIL: |
| 539 | case GSM48_MT_GMM_ID_REQ: |
| 540 | case GSM48_MT_GMM_ID_RESP: |
| 541 | case GSM48_MT_GMM_RA_UPD_REQ: |
| 542 | case GSM48_MT_GMM_RA_UPD_REJ: |
| 543 | return false; |
| 544 | default: |
| 545 | return true; |
| 546 | } |
| 547 | } |
| 548 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 549 | /* Convert MCC + MNC to BCD representation, legacy implementation. |
| 550 | * Instead use osmo_plmn_to_bcd(), which is also capable of converting |
| 551 | * 3-digit MNC that have leading zeros. For parameters, also see there. */ |
Neels Hofmeyr | bdccc1b | 2016-03-15 13:28:10 +0100 | [diff] [blame] | 552 | void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc) |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 553 | { |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 554 | const struct osmo_plmn_id plmn = { |
| 555 | .mcc = mcc, |
| 556 | .mnc = mnc, |
| 557 | .mnc_3_digits = false, |
| 558 | }; |
| 559 | osmo_plmn_to_bcd(bcd_dst, &plmn); |
Neels Hofmeyr | bdccc1b | 2016-03-15 13:28:10 +0100 | [diff] [blame] | 560 | } |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 561 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 562 | /* Convert given 3-byte BCD buffer to integers, legacy implementation. |
| 563 | * Instead use osmo_plmn_from_bcd(), which is also capable of converting |
| 564 | * 3-digit MNC that have leading zeros. For parameters, also see there. */ |
Neels Hofmeyr | bdccc1b | 2016-03-15 13:28:10 +0100 | [diff] [blame] | 565 | void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc) |
| 566 | { |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 567 | struct osmo_plmn_id plmn; |
| 568 | osmo_plmn_from_bcd(bcd_src, &plmn); |
| 569 | *mcc = plmn.mcc; |
| 570 | *mnc = plmn.mnc; |
Neels Hofmeyr | bdccc1b | 2016-03-15 13:28:10 +0100 | [diff] [blame] | 571 | } |
| 572 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 573 | /*! Encode TS 04.08 Location Area Identifier, legacy implementation. |
| 574 | * Instead use gsm48_generate_lai2(), which is capable of three-digit MNC with leading zeros. |
| 575 | * \param[out] lai48 caller-provided memory for output |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 576 | * \param[in] mcc Mobile Country Code |
| 577 | * \param[in] mnc Mobile Network Code |
| 578 | * \param[in] lac Location Area Code */ |
Neels Hofmeyr | bdccc1b | 2016-03-15 13:28:10 +0100 | [diff] [blame] | 579 | void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc, |
| 580 | uint16_t mnc, uint16_t lac) |
| 581 | { |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 582 | const struct osmo_location_area_id lai = { |
| 583 | .plmn = { |
| 584 | .mcc = mcc, |
| 585 | .mnc = mnc, |
| 586 | .mnc_3_digits = false, |
| 587 | }, |
| 588 | .lac = lac, |
| 589 | }; |
| 590 | gsm48_generate_lai2(lai48, &lai); |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 593 | /*! Encode TS 04.08 Location Area Identifier. |
| 594 | * \param[out] lai48 caller-provided memory for output. |
| 595 | * \param[in] lai input of MCC-MNC-LAC. */ |
| 596 | void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai) |
| 597 | { |
| 598 | osmo_plmn_to_bcd(&lai48->digits[0], &lai->plmn); |
| 599 | lai48->lac = osmo_htons(lai->lac); |
| 600 | } |
| 601 | |
| 602 | /*! Decode TS 04.08 Location Area Identifier, legacy implementation. |
| 603 | * Instead use gsm48_decode_lai2(), which is capable of three-digit MNC with leading zeros. |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 604 | * \param[in] Location Area Identifier (encoded) |
| 605 | * \param[out] mcc Mobile Country Code |
| 606 | * \param[out] mnc Mobile Network Code |
| 607 | * \param[out] lac Location Area Code |
| 608 | * \returns 0 |
| 609 | * |
| 610 | * Attention: this function returns true integers, not hex! */ |
Harald Welte | 774a9de | 2012-07-13 21:35:13 +0200 | [diff] [blame] | 611 | int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc, |
| 612 | uint16_t *mnc, uint16_t *lac) |
| 613 | { |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 614 | struct osmo_location_area_id decoded; |
| 615 | gsm48_decode_lai2(lai, &decoded); |
| 616 | *mcc = decoded.plmn.mcc; |
| 617 | *mnc = decoded.plmn.mnc; |
| 618 | *lac = decoded.lac; |
Harald Welte | 774a9de | 2012-07-13 21:35:13 +0200 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 622 | /*! Decode TS 04.08 Location Area Identifier. |
| 623 | * \param[in] Location Area Identifier (encoded). |
| 624 | * \param[out] decoded Target buffer to write decoded values of MCC-MNC-LAC. |
| 625 | * |
| 626 | * Attention: this function returns true integers, not hex! */ |
| 627 | void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded) |
| 628 | { |
| 629 | osmo_plmn_from_bcd(&lai->digits[0], &decoded->plmn); |
| 630 | decoded->lac = osmo_ntohs(lai->lac); |
| 631 | } |
| 632 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 633 | /*! Set DTX mode in Cell Options IE (3GPP TS 44.018) |
Max | fe65fa7 | 2016-05-10 17:17:05 +0200 | [diff] [blame] | 634 | * \param[in] op Cell Options structure in which DTX parameters will be set |
| 635 | * \param[in] full Mode for full-rate channels |
| 636 | * \param[in] half Mode for half-rate channels |
| 637 | * \param[in] is_bcch Indicates if we should use 10.5.2.3.1 instead of |
| 638 | * 10.5.2.3a.2 |
| 639 | * |
| 640 | * There is no space for separate DTX settings for Full and Half rate channels |
| 641 | * in BCCH - in this case full setting is used for both and half parameter is |
| 642 | * ignored. |
| 643 | */ |
| 644 | void gsm48_set_dtx(struct gsm48_cell_options *op, enum gsm48_dtx_mode full, |
| 645 | enum gsm48_dtx_mode half, bool is_bcch) |
| 646 | { |
| 647 | if (is_bcch) { |
| 648 | switch (full) { |
| 649 | case GSM48_DTX_MAY_BE_USED: |
| 650 | op->dtx = 0; |
| 651 | return; |
| 652 | case GSM48_DTX_SHALL_BE_USED: |
| 653 | op->dtx = 1; |
| 654 | return; |
| 655 | case GSM48_DTX_SHALL_NOT_BE_USED: |
| 656 | op->dtx = 2; |
| 657 | return; |
| 658 | } |
| 659 | } else { |
| 660 | switch (full) { |
| 661 | case GSM48_DTX_MAY_BE_USED: |
| 662 | op->dtx = (half == GSM48_DTX_SHALL_BE_USED) ? 3 : 0; |
| 663 | op->d = (half == GSM48_DTX_SHALL_NOT_BE_USED) ? 0 : 1; |
| 664 | return; |
| 665 | case GSM48_DTX_SHALL_BE_USED: |
| 666 | op->dtx = (half == GSM48_DTX_MAY_BE_USED) ? 3 : 1; |
| 667 | op->d = (half == GSM48_DTX_SHALL_BE_USED) ? 1 : 0; |
| 668 | return; |
| 669 | case GSM48_DTX_SHALL_NOT_BE_USED: |
| 670 | op->dtx = 2; |
| 671 | op->d = (half == GSM48_DTX_SHALL_BE_USED) ? 1 : 0; |
| 672 | return; |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 677 | /*! Generate TS 04.08 Mobile ID from TMSI |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 678 | * \param[out] buf Caller-provided output buffer (7 bytes) |
| 679 | * \param[in] tmsi TMSI to be encoded |
| 680 | * \returns number of byes encoded (always 7) */ |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 681 | int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi) |
| 682 | { |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 683 | uint32_t tmsi_be = osmo_htonl(tmsi); |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 684 | |
| 685 | buf[0] = GSM48_IE_MOBILE_ID; |
| 686 | buf[1] = GSM48_TMSI_LEN; |
| 687 | buf[2] = 0xf0 | GSM_MI_TYPE_TMSI; |
Holger Hans Peter Freyther | cd252e3 | 2013-07-03 09:56:53 +0200 | [diff] [blame] | 688 | memcpy(&buf[3], &tmsi_be, sizeof(tmsi_be)); |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 689 | |
| 690 | return 7; |
| 691 | } |
| 692 | |
Harald Welte | 1c3bae1 | 2019-01-20 10:37:49 +0100 | [diff] [blame] | 693 | /*! Generate TS 24.008 §10.5.1.4 Mobile ID of BCD type from ASCII string |
| 694 | * \param[out] buf Caller-provided output buffer of at least GSM48_MID_MAX_SIZE bytes |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 695 | * \param[in] id Identity to be encoded |
Harald Welte | 1c3bae1 | 2019-01-20 10:37:49 +0100 | [diff] [blame] | 696 | * \param[in] mi_type Type of identity (e.g. GSM_MI_TYPE_IMSI, IMEI, IMEISV) |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 697 | * \returns number of bytes used in \a buf */ |
| 698 | uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type) |
| 699 | { |
Harald Welte | 1c3bae1 | 2019-01-20 10:37:49 +0100 | [diff] [blame] | 700 | uint8_t length = strnlen(id, 16), i, off = 0, odd = (length & 1) == 1; |
| 701 | /* maximum length == 16 (IMEISV) */ |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 702 | |
| 703 | buf[0] = GSM48_IE_MOBILE_ID; |
Neels Hofmeyr | 23187fa | 2018-12-05 23:24:50 +0100 | [diff] [blame] | 704 | buf[2] = osmo_char2bcd(id[0]) << 4 | (mi_type & GSM_MI_TYPE_MASK) | (odd << 3); |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 705 | |
| 706 | /* if the length is even we will fill half of the last octet */ |
| 707 | buf[1] = (length + (odd ? 1 : 2)) >> 1; |
Harald Welte | 1c3bae1 | 2019-01-20 10:37:49 +0100 | [diff] [blame] | 708 | /* buf[1] maximum = 18/2 = 9 */ |
| 709 | OSMO_ASSERT(buf[1] <= 9); |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 710 | |
| 711 | for (i = 1; i < buf[1]; ++i) { |
| 712 | uint8_t upper, lower = osmo_char2bcd(id[++off]); |
| 713 | if (!odd && off + 1 == length) |
| 714 | upper = 0x0f; |
| 715 | else |
| 716 | upper = osmo_char2bcd(id[++off]) & 0x0f; |
| 717 | |
| 718 | buf[2 + i] = (upper << 4) | lower; |
| 719 | } |
| 720 | |
Harald Welte | 1c3bae1 | 2019-01-20 10:37:49 +0100 | [diff] [blame] | 721 | /* maximum return value: 2 + 9 = 11 */ |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 722 | return 2 + buf[1]; |
| 723 | } |
| 724 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 725 | /*! Generate TS 04.08 Mobile ID from IMSI |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 726 | * \param[out] buf Caller-provided output buffer |
| 727 | * \param[in] imsi IMSI to be encoded |
| 728 | * \returns number of bytes used in \a buf */ |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 729 | int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi) |
| 730 | { |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 731 | return gsm48_generate_mid(buf, imsi, GSM_MI_TYPE_IMSI); |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 732 | } |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 733 | |
Neels Hofmeyr | 627e011 | 2018-12-05 21:32:40 +0100 | [diff] [blame] | 734 | /*! Convert TS 04.08 Mobile Identity (10.5.1.4) to string. |
| 735 | * This function does not validate the Mobile Identity digits, i.e. digits > 9 are returned as 'A'-'F'. |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 736 | * \param[out] string Caller-provided buffer for output |
| 737 | * \param[in] str_len Length of \a string in bytes |
| 738 | * \param[in] mi Mobile Identity to be stringified |
| 739 | * \param[in] mi_len Length of \a mi in bytes |
Neels Hofmeyr | 6aa20ee | 2018-12-06 00:40:37 +0100 | [diff] [blame] | 740 | * \returns WARNING: the return value of this function is not well implemented. |
| 741 | * Depending on the MI type and amount of output buffer, this may return |
| 742 | * the nr of written bytes, or the written strlen(), or the snprintf() |
| 743 | * style strlen()-if-the-buffer-were-large-enough. */ |
Vadim Yanitskiy | 0d8da79 | 2019-07-25 19:12:23 +0700 | [diff] [blame] | 744 | int gsm48_mi_to_string(char *string, int str_len, const uint8_t *mi, int mi_len) |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 745 | { |
Neels Hofmeyr | 627e011 | 2018-12-05 21:32:40 +0100 | [diff] [blame] | 746 | int rc; |
Harald Welte | 163d0ea | 2010-04-09 07:57:40 +0200 | [diff] [blame] | 747 | uint8_t mi_type; |
Harald Welte | 163d0ea | 2010-04-09 07:57:40 +0200 | [diff] [blame] | 748 | uint32_t tmsi; |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 749 | |
Neels Hofmeyr | 6adffb9 | 2018-12-05 23:30:31 +0100 | [diff] [blame] | 750 | mi_type = (mi && mi_len) ? (mi[0] & GSM_MI_TYPE_MASK) : GSM_MI_TYPE_NONE; |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 751 | |
| 752 | switch (mi_type) { |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 753 | case GSM_MI_TYPE_TMSI: |
Holger Freyther | 45abec2 | 2016-05-20 19:21:27 +0000 | [diff] [blame] | 754 | /* Table 10.5.4.3, reverse generate_mid_from_tmsi */ |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 755 | if (mi_len == GSM48_TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) { |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 756 | tmsi = osmo_load32be(&mi[1]); |
Pau Espin Pedrol | 4573502 | 2017-06-18 14:05:24 +0200 | [diff] [blame] | 757 | return snprintf(string, str_len, "%"PRIu32, tmsi); |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 758 | } |
| 759 | break; |
| 760 | case GSM_MI_TYPE_IMSI: |
| 761 | case GSM_MI_TYPE_IMEI: |
| 762 | case GSM_MI_TYPE_IMEISV: |
Neels Hofmeyr | 627e011 | 2018-12-05 21:32:40 +0100 | [diff] [blame] | 763 | rc = osmo_bcd2str(string, str_len, mi, |
| 764 | 1, mi_len * 2 - ((mi[0] & GSM_MI_ODD) ? 0 : 1), true); |
| 765 | /* osmo_bcd2str() returns snprintf style strlen(), this returns bytes written. */ |
| 766 | if (rc < 0) |
| 767 | return 0; |
| 768 | else if (rc < str_len) |
| 769 | return rc + 1; |
| 770 | else |
| 771 | return strlen(string) + 1; |
Neels Hofmeyr | ea2a0ab | 2018-12-05 23:30:08 +0100 | [diff] [blame] | 772 | |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 773 | default: |
| 774 | break; |
| 775 | } |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 776 | |
Neels Hofmeyr | ea2a0ab | 2018-12-05 23:30:08 +0100 | [diff] [blame] | 777 | if (str_len < 1) |
| 778 | return 0; |
| 779 | *string = '\0'; |
| 780 | return 1; |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 781 | } |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 782 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 783 | /*! Parse TS 04.08 Routing Area Identifier |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 784 | * \param[out] Caller-provided memory for decoded RA ID |
| 785 | * \param[in] buf Input buffer pointing to RAI IE value */ |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 786 | void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf) |
| 787 | { |
| 788 | raid->mcc = (buf[0] & 0xf) * 100; |
| 789 | raid->mcc += (buf[0] >> 4) * 10; |
| 790 | raid->mcc += (buf[1] & 0xf) * 1; |
| 791 | |
| 792 | /* I wonder who came up with the stupidity of encoding the MNC |
| 793 | * differently depending on how many digits its decimal number has! */ |
| 794 | if ((buf[1] >> 4) == 0xf) { |
| 795 | raid->mnc = (buf[2] & 0xf) * 10; |
| 796 | raid->mnc += (buf[2] >> 4) * 1; |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 797 | raid->mnc_3_digits = false; |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 798 | } else { |
| 799 | raid->mnc = (buf[2] & 0xf) * 100; |
| 800 | raid->mnc += (buf[2] >> 4) * 10; |
| 801 | raid->mnc += (buf[1] >> 4) * 1; |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 802 | raid->mnc_3_digits = true; |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 803 | } |
| 804 | |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 805 | raid->lac = osmo_load16be(buf + 3); |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 806 | raid->rac = buf[5]; |
| 807 | } |
Harald Welte | 35a9394 | 2010-05-01 14:25:22 +0200 | [diff] [blame] | 808 | |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 809 | /*! Encode a 3GPP TS 24.008 § 10.5.5.15 Routing area identification |
| 810 | * \param[out] out Caller-provided packed struct |
| 811 | * \param[in] raid Routing Area ID to be encoded |
| 812 | */ |
| 813 | void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid) |
| 814 | { |
| 815 | out->lac = osmo_htons(raid->lac); |
| 816 | out->rac = raid->rac; |
| 817 | |
| 818 | out->digits[0] = ((raid->mcc / 100) % 10) | (((raid->mcc / 10) % 10) << 4); |
| 819 | out->digits[1] = raid->mcc % 10; |
| 820 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 821 | if (raid->mnc < 100 && !raid->mnc_3_digits) { |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 822 | out->digits[1] |= 0xf0; |
| 823 | out->digits[2] = ((raid->mnc / 10) % 10) | ((raid->mnc % 10) << 4); |
| 824 | } else { |
| 825 | out->digits[1] |= (raid->mnc % 10) << 4; |
| 826 | out->digits[2] = ((raid->mnc / 100) % 10) | (((raid->mnc / 10) % 10) << 4); |
| 827 | } |
| 828 | } |
| 829 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 830 | /*! Encode a TS 04.08 Routing Area Identifier |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 831 | * \param[out] buf Caller-provided output buffer of 6 bytes |
| 832 | * \param[in] raid Routing Area ID to be encoded |
| 833 | * \returns number of bytes used in \a buf */ |
Harald Welte | 35a9394 | 2010-05-01 14:25:22 +0200 | [diff] [blame] | 834 | int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) |
| 835 | { |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 836 | gsm48_encode_ra((struct gsm48_ra_id *)buf, raid); |
Harald Welte | 35a9394 | 2010-05-01 14:25:22 +0200 | [diff] [blame] | 837 | |
| 838 | return 6; |
| 839 | } |
Harald Welte | 2aee7b1 | 2011-06-26 14:20:04 +0200 | [diff] [blame] | 840 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 841 | /*! Determine number of paging sub-channels |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 842 | * \param[in] chan_desc Control Channel Description |
| 843 | * \returns number of paging sub-channels |
| 844 | * |
| 845 | * Uses From Table 10.5.33 of GSM 04.08 to determine the number of |
| 846 | * paging sub-channels in the given control channel configuration |
| 847 | */ |
Harald Welte | 2aee7b1 | 2011-06-26 14:20:04 +0200 | [diff] [blame] | 848 | int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc) |
| 849 | { |
Harald Welte | 94df39e | 2011-06-26 14:33:57 +0200 | [diff] [blame] | 850 | unsigned int n_pag_blocks = gsm0502_get_n_pag_blocks(chan_desc); |
| 851 | |
| 852 | if (chan_desc->ccch_conf == RSL_BCCH_CCCH_CONF_1_C) |
| 853 | return OSMO_MAX(1, n_pag_blocks) * (chan_desc->bs_pa_mfrms + 2); |
| 854 | else |
| 855 | return n_pag_blocks * (chan_desc->bs_pa_mfrms + 2); |
Harald Welte | 2aee7b1 | 2011-06-26 14:20:04 +0200 | [diff] [blame] | 856 | } |
Neels Hofmeyr | dbd994c | 2017-03-09 23:07:02 +0100 | [diff] [blame] | 857 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 858 | /*! TS 04.08 Protocol Descriptor names */ |
Neels Hofmeyr | dbd994c | 2017-03-09 23:07:02 +0100 | [diff] [blame] | 859 | const struct value_string gsm48_pdisc_names[] = { |
Harald Welte | ea0bc96 | 2018-01-24 16:17:45 +0100 | [diff] [blame] | 860 | { GSM48_PDISC_GROUP_CC, "VGCC" }, |
| 861 | { GSM48_PDISC_BCAST_CC, "VBCC" }, |
| 862 | { GSM48_PDISC_PDSS1, "PDSS1" }, |
| 863 | { GSM48_PDISC_CC, "CC" }, |
| 864 | { GSM48_PDISC_PDSS2, "PDSS2" }, |
| 865 | { GSM48_PDISC_MM, "MM" }, |
| 866 | { GSM48_PDISC_RR, "RR" }, |
| 867 | { GSM48_PDISC_MM_GPRS, "GMM" }, |
| 868 | { GSM48_PDISC_SMS, "SMS" }, |
| 869 | { GSM48_PDISC_SM_GPRS, "SM" }, |
| 870 | { GSM48_PDISC_NC_SS, "NCSS" }, |
| 871 | { GSM48_PDISC_LOC, "LCS" }, |
| 872 | { GSM48_PDISC_EXTEND, "EXTD" }, |
| 873 | { GSM48_PDISC_MASK, "MASK" }, |
Neels Hofmeyr | dbd994c | 2017-03-09 23:07:02 +0100 | [diff] [blame] | 874 | { 0, NULL } |
| 875 | }; |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 876 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 877 | /*! TS 04.08 RR Message Type names */ |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 878 | const struct value_string gsm48_rr_msgtype_names[] = { |
| 879 | OSMO_VALUE_STRING(GSM48_MT_RR_INIT_REQ), |
| 880 | OSMO_VALUE_STRING(GSM48_MT_RR_ADD_ASS), |
| 881 | OSMO_VALUE_STRING(GSM48_MT_RR_IMM_ASS), |
| 882 | OSMO_VALUE_STRING(GSM48_MT_RR_IMM_ASS_EXT), |
| 883 | OSMO_VALUE_STRING(GSM48_MT_RR_IMM_ASS_REJ), |
| 884 | OSMO_VALUE_STRING(GSM48_MT_RR_DTM_ASS_FAIL), |
| 885 | OSMO_VALUE_STRING(GSM48_MT_RR_DTM_REJECT), |
| 886 | OSMO_VALUE_STRING(GSM48_MT_RR_DTM_REQUEST), |
| 887 | OSMO_VALUE_STRING(GSM48_MT_RR_PACKET_ASS), |
| 888 | |
| 889 | OSMO_VALUE_STRING(GSM48_MT_RR_CIPH_M_CMD), |
| 890 | OSMO_VALUE_STRING(GSM48_MT_RR_CIPH_M_COMPL), |
| 891 | |
| 892 | OSMO_VALUE_STRING(GSM48_MT_RR_CFG_CHG_CMD), |
| 893 | OSMO_VALUE_STRING(GSM48_MT_RR_CFG_CHG_ACK), |
| 894 | OSMO_VALUE_STRING(GSM48_MT_RR_CFG_CHG_REJ), |
| 895 | |
| 896 | OSMO_VALUE_STRING(GSM48_MT_RR_ASS_CMD), |
| 897 | OSMO_VALUE_STRING(GSM48_MT_RR_ASS_COMPL), |
| 898 | OSMO_VALUE_STRING(GSM48_MT_RR_ASS_FAIL), |
| 899 | OSMO_VALUE_STRING(GSM48_MT_RR_HANDO_CMD), |
| 900 | OSMO_VALUE_STRING(GSM48_MT_RR_HANDO_COMPL), |
| 901 | OSMO_VALUE_STRING(GSM48_MT_RR_HANDO_FAIL), |
| 902 | OSMO_VALUE_STRING(GSM48_MT_RR_HANDO_INFO), |
| 903 | OSMO_VALUE_STRING(GSM48_MT_RR_HANDO_INFO), |
| 904 | OSMO_VALUE_STRING(GSM48_MT_RR_DTM_ASS_CMD), |
| 905 | |
| 906 | OSMO_VALUE_STRING(GSM48_MT_RR_CELL_CHG_ORDER), |
| 907 | OSMO_VALUE_STRING(GSM48_MT_RR_PDCH_ASS_CMD), |
| 908 | |
| 909 | OSMO_VALUE_STRING(GSM48_MT_RR_CHAN_REL), |
| 910 | OSMO_VALUE_STRING(GSM48_MT_RR_PART_REL), |
| 911 | OSMO_VALUE_STRING(GSM48_MT_RR_PART_REL_COMP), |
| 912 | |
| 913 | OSMO_VALUE_STRING(GSM48_MT_RR_PAG_REQ_1), |
| 914 | OSMO_VALUE_STRING(GSM48_MT_RR_PAG_REQ_2), |
| 915 | OSMO_VALUE_STRING(GSM48_MT_RR_PAG_REQ_3), |
| 916 | OSMO_VALUE_STRING(GSM48_MT_RR_PAG_RESP), |
| 917 | OSMO_VALUE_STRING(GSM48_MT_RR_NOTIF_NCH), |
| 918 | OSMO_VALUE_STRING(GSM48_MT_RR_NOTIF_FACCH), |
| 919 | OSMO_VALUE_STRING(GSM48_MT_RR_NOTIF_RESP), |
| 920 | OSMO_VALUE_STRING(GSM48_MT_RR_PACKET_NOTIF), |
| 921 | OSMO_VALUE_STRING(GSM48_MT_RR_UTRAN_CLSM_CHG), |
| 922 | OSMO_VALUE_STRING(GSM48_MT_RR_CDMA2K_CLSM_CHG), |
| 923 | OSMO_VALUE_STRING(GSM48_MT_RR_IS_TO_UTRAN_HANDO), |
| 924 | OSMO_VALUE_STRING(GSM48_MT_RR_IS_TO_CDMA2K_HANDO), |
| 925 | |
| 926 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_8), |
| 927 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_1), |
| 928 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_2), |
| 929 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_3), |
| 930 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_4), |
| 931 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_5), |
| 932 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_6), |
| 933 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_7), |
| 934 | |
| 935 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_2bis), |
| 936 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_2ter), |
| 937 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_2quater), |
| 938 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_5bis), |
| 939 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_5ter), |
| 940 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_9), |
| 941 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_13), |
| 942 | |
| 943 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_16), |
| 944 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_17), |
| 945 | |
| 946 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_18), |
| 947 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_19), |
| 948 | OSMO_VALUE_STRING(GSM48_MT_RR_SYSINFO_20), |
| 949 | |
| 950 | OSMO_VALUE_STRING(GSM48_MT_RR_CHAN_MODE_MODIF), |
| 951 | OSMO_VALUE_STRING(GSM48_MT_RR_STATUS), |
| 952 | OSMO_VALUE_STRING(GSM48_MT_RR_CHAN_MODE_MODIF_ACK), |
| 953 | OSMO_VALUE_STRING(GSM48_MT_RR_FREQ_REDEF), |
| 954 | OSMO_VALUE_STRING(GSM48_MT_RR_MEAS_REP), |
| 955 | OSMO_VALUE_STRING(GSM48_MT_RR_CLSM_CHG), |
| 956 | OSMO_VALUE_STRING(GSM48_MT_RR_CLSM_ENQ), |
| 957 | OSMO_VALUE_STRING(GSM48_MT_RR_EXT_MEAS_REP), |
| 958 | OSMO_VALUE_STRING(GSM48_MT_RR_EXT_MEAS_REP_ORD), |
| 959 | OSMO_VALUE_STRING(GSM48_MT_RR_GPRS_SUSP_REQ), |
| 960 | OSMO_VALUE_STRING(GSM48_MT_RR_DTM_INFO), |
| 961 | |
| 962 | OSMO_VALUE_STRING(GSM48_MT_RR_VGCS_UPL_GRANT), |
| 963 | OSMO_VALUE_STRING(GSM48_MT_RR_UPLINK_RELEASE), |
| 964 | OSMO_VALUE_STRING(GSM48_MT_RR_UPLINK_FREE), |
| 965 | OSMO_VALUE_STRING(GSM48_MT_RR_UPLINK_BUSY), |
| 966 | OSMO_VALUE_STRING(GSM48_MT_RR_TALKER_IND), |
| 967 | { 0, NULL } |
| 968 | }; |
| 969 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 970 | /*! TS 04.08 MM Message Type names */ |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 971 | const struct value_string gsm48_mm_msgtype_names[] = { |
| 972 | OSMO_VALUE_STRING(GSM48_MT_MM_IMSI_DETACH_IND), |
| 973 | OSMO_VALUE_STRING(GSM48_MT_MM_LOC_UPD_ACCEPT), |
| 974 | OSMO_VALUE_STRING(GSM48_MT_MM_LOC_UPD_REJECT), |
| 975 | OSMO_VALUE_STRING(GSM48_MT_MM_LOC_UPD_REQUEST), |
| 976 | |
| 977 | OSMO_VALUE_STRING(GSM48_MT_MM_AUTH_REJ), |
| 978 | OSMO_VALUE_STRING(GSM48_MT_MM_AUTH_REQ), |
| 979 | OSMO_VALUE_STRING(GSM48_MT_MM_AUTH_RESP), |
| 980 | OSMO_VALUE_STRING(GSM48_MT_MM_AUTH_FAIL), |
| 981 | OSMO_VALUE_STRING(GSM48_MT_MM_ID_REQ), |
| 982 | OSMO_VALUE_STRING(GSM48_MT_MM_ID_RESP), |
| 983 | OSMO_VALUE_STRING(GSM48_MT_MM_TMSI_REALL_CMD), |
| 984 | OSMO_VALUE_STRING(GSM48_MT_MM_TMSI_REALL_COMPL), |
| 985 | |
| 986 | OSMO_VALUE_STRING(GSM48_MT_MM_CM_SERV_ACC), |
| 987 | OSMO_VALUE_STRING(GSM48_MT_MM_CM_SERV_REJ), |
| 988 | OSMO_VALUE_STRING(GSM48_MT_MM_CM_SERV_ABORT), |
| 989 | OSMO_VALUE_STRING(GSM48_MT_MM_CM_SERV_REQ), |
| 990 | OSMO_VALUE_STRING(GSM48_MT_MM_CM_SERV_PROMPT), |
| 991 | OSMO_VALUE_STRING(GSM48_MT_MM_CM_REEST_REQ), |
| 992 | OSMO_VALUE_STRING(GSM48_MT_MM_ABORT), |
| 993 | |
| 994 | OSMO_VALUE_STRING(GSM48_MT_MM_NULL), |
| 995 | OSMO_VALUE_STRING(GSM48_MT_MM_STATUS), |
| 996 | OSMO_VALUE_STRING(GSM48_MT_MM_INFO), |
| 997 | { 0, NULL } |
| 998 | }; |
| 999 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1000 | /*! TS 04.08 CC Message Type names */ |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1001 | const struct value_string gsm48_cc_msgtype_names[] = { |
| 1002 | OSMO_VALUE_STRING(GSM48_MT_CC_ALERTING), |
| 1003 | OSMO_VALUE_STRING(GSM48_MT_CC_CALL_CONF), |
| 1004 | OSMO_VALUE_STRING(GSM48_MT_CC_CALL_PROC), |
| 1005 | OSMO_VALUE_STRING(GSM48_MT_CC_CONNECT), |
| 1006 | OSMO_VALUE_STRING(GSM48_MT_CC_CONNECT_ACK), |
| 1007 | OSMO_VALUE_STRING(GSM48_MT_CC_EMERG_SETUP), |
| 1008 | OSMO_VALUE_STRING(GSM48_MT_CC_PROGRESS), |
| 1009 | OSMO_VALUE_STRING(GSM48_MT_CC_ESTAB), |
| 1010 | OSMO_VALUE_STRING(GSM48_MT_CC_ESTAB_CONF), |
| 1011 | OSMO_VALUE_STRING(GSM48_MT_CC_RECALL), |
| 1012 | OSMO_VALUE_STRING(GSM48_MT_CC_START_CC), |
| 1013 | OSMO_VALUE_STRING(GSM48_MT_CC_SETUP), |
| 1014 | |
| 1015 | OSMO_VALUE_STRING(GSM48_MT_CC_MODIFY), |
| 1016 | OSMO_VALUE_STRING(GSM48_MT_CC_MODIFY_COMPL), |
| 1017 | OSMO_VALUE_STRING(GSM48_MT_CC_MODIFY_REJECT), |
| 1018 | OSMO_VALUE_STRING(GSM48_MT_CC_USER_INFO), |
| 1019 | OSMO_VALUE_STRING(GSM48_MT_CC_HOLD), |
| 1020 | OSMO_VALUE_STRING(GSM48_MT_CC_HOLD_ACK), |
| 1021 | OSMO_VALUE_STRING(GSM48_MT_CC_HOLD_REJ), |
| 1022 | OSMO_VALUE_STRING(GSM48_MT_CC_RETR), |
| 1023 | OSMO_VALUE_STRING(GSM48_MT_CC_RETR_ACK), |
| 1024 | OSMO_VALUE_STRING(GSM48_MT_CC_RETR_REJ), |
| 1025 | |
| 1026 | OSMO_VALUE_STRING(GSM48_MT_CC_DISCONNECT), |
| 1027 | OSMO_VALUE_STRING(GSM48_MT_CC_RELEASE), |
| 1028 | OSMO_VALUE_STRING(GSM48_MT_CC_RELEASE_COMPL), |
| 1029 | |
| 1030 | OSMO_VALUE_STRING(GSM48_MT_CC_CONG_CTRL), |
| 1031 | OSMO_VALUE_STRING(GSM48_MT_CC_NOTIFY), |
| 1032 | OSMO_VALUE_STRING(GSM48_MT_CC_STATUS), |
| 1033 | OSMO_VALUE_STRING(GSM48_MT_CC_STATUS_ENQ), |
| 1034 | OSMO_VALUE_STRING(GSM48_MT_CC_START_DTMF), |
| 1035 | OSMO_VALUE_STRING(GSM48_MT_CC_STOP_DTMF), |
| 1036 | OSMO_VALUE_STRING(GSM48_MT_CC_STOP_DTMF_ACK), |
| 1037 | OSMO_VALUE_STRING(GSM48_MT_CC_START_DTMF_ACK), |
| 1038 | OSMO_VALUE_STRING(GSM48_MT_CC_START_DTMF_REJ), |
| 1039 | OSMO_VALUE_STRING(GSM48_MT_CC_FACILITY), |
| 1040 | { 0, NULL } |
| 1041 | }; |
| 1042 | |
Keith | 3cdaa8d | 2018-08-31 20:09:18 +0200 | [diff] [blame] | 1043 | /*! TS 04.08 10.5..4.11 Call Control Cause Values */ |
| 1044 | const struct value_string gsm48_cc_cause_names[] = { |
| 1045 | { GSM48_CC_CAUSE_UNASSIGNED_NR, "UNASSIGNED_NR" }, |
| 1046 | { GSM48_CC_CAUSE_NO_ROUTE, "NO_ROUTE" }, |
| 1047 | { GSM48_CC_CAUSE_CHAN_UNACCEPT, "CHAN_UNACCEPT" }, |
| 1048 | { GSM48_CC_CAUSE_OP_DET_BARRING, "OP_DET_BARRING" }, |
| 1049 | { GSM48_CC_CAUSE_NORM_CALL_CLEAR, "NORM_CALL_CLEAR" }, |
| 1050 | { GSM48_CC_CAUSE_USER_BUSY, "USER_BUSY" }, |
| 1051 | { GSM48_CC_CAUSE_USER_NOTRESPOND, "USER_NOTRESPOND" }, |
| 1052 | { GSM48_CC_CAUSE_USER_ALERTING_NA, "USER_ALERTING_NA" }, |
| 1053 | { GSM48_CC_CAUSE_CALL_REJECTED, "CALL_REJECTED" }, |
| 1054 | { GSM48_CC_CAUSE_NUMBER_CHANGED, "NUMBER_CHANGED" }, |
| 1055 | { GSM48_CC_CAUSE_PRE_EMPTION, "PRE_EMPTION" }, |
| 1056 | { GSM48_CC_CAUSE_NONSE_USER_CLR, "NONSE_USER_CLR" }, |
| 1057 | { GSM48_CC_CAUSE_DEST_OOO, "DEST_OOO" }, |
| 1058 | { GSM48_CC_CAUSE_INV_NR_FORMAT, "INV_NR_FORMAT" }, |
| 1059 | { GSM48_CC_CAUSE_FACILITY_REJ, "FACILITY_REJ" }, |
| 1060 | { GSM48_CC_CAUSE_RESP_STATUS_INQ, "RESP_STATUS_INQ" }, |
| 1061 | { GSM48_CC_CAUSE_NORMAL_UNSPEC, "NORMAL_UNSPEC" }, |
| 1062 | { GSM48_CC_CAUSE_NO_CIRCUIT_CHAN, "NO_CIRCUIT_CHAN" }, |
| 1063 | { GSM48_CC_CAUSE_NETWORK_OOO, "NETWORK_OOO" }, |
| 1064 | { GSM48_CC_CAUSE_TEMP_FAILURE, "TEMP_FAILURE" }, |
| 1065 | { GSM48_CC_CAUSE_SWITCH_CONG, "SWITCH_CONG" }, |
| 1066 | { GSM48_CC_CAUSE_ACC_INF_DISCARD, "ACC_INF_DISCARD" }, |
| 1067 | { GSM48_CC_CAUSE_REQ_CHAN_UNAVAIL, "REQ_CHAN_UNAVAIL" }, |
| 1068 | { GSM48_CC_CAUSE_RESOURCE_UNAVAIL, "RESOURCE_UNAVAIL" }, |
| 1069 | { GSM48_CC_CAUSE_QOS_UNAVAIL, "QOS_UNAVAIL" }, |
| 1070 | { GSM48_CC_CAUSE_REQ_FAC_NOT_SUBSC, "REQ_FAC_NOT_SUBSC" }, |
| 1071 | { GSM48_CC_CAUSE_INC_BARRED_CUG, "INC_BARRED_CUG" }, |
| 1072 | { GSM48_CC_CAUSE_BEARER_CAP_UNAUTH, "BEARER_CAP_UNAUTH" }, |
| 1073 | { GSM48_CC_CAUSE_BEARER_CA_UNAVAIL, "BEARER_CA_UNAVAIL" }, |
| 1074 | { GSM48_CC_CAUSE_SERV_OPT_UNAVAIL, "SERV_OPT_UNAVAIL" }, |
| 1075 | { GSM48_CC_CAUSE_BEARERSERV_UNIMPL, "BEARERSERV_UNIMPL" }, |
| 1076 | { GSM48_CC_CAUSE_ACM_GE_ACM_MAX, "ACM_GE_ACM_MAX" }, |
| 1077 | { GSM48_CC_CAUSE_REQ_FAC_NOTIMPL, "REQ_FAC_NOTIMPL" }, |
| 1078 | { GSM48_CC_CAUSE_RESTR_BCAP_AVAIL, "RESTR_BCAP_AVAIL" }, |
| 1079 | { GSM48_CC_CAUSE_SERV_OPT_UNIMPL, "SERV_OPT_UNIMPL" }, |
| 1080 | { GSM48_CC_CAUSE_INVAL_TRANS_ID, "INVAL_TRANS_ID" }, |
| 1081 | { GSM48_CC_CAUSE_USER_NOT_IN_CUG, "USER_NOT_IN_CUG" }, |
| 1082 | { GSM48_CC_CAUSE_INCOMPAT_DEST, "INCOMPAT_DEST" }, |
| 1083 | { GSM48_CC_CAUSE_INVAL_TRANS_NET, "INVAL_TRANS_NET" }, |
| 1084 | { GSM48_CC_CAUSE_SEMANTIC_INCORR, "SEMANTIC_INCORR" }, |
| 1085 | { GSM48_CC_CAUSE_INVAL_MAND_INF, "INVAL_MAND_INF" }, |
| 1086 | { GSM48_CC_CAUSE_MSGTYPE_NOTEXIST, "MSGTYPE_NOTEXIST" }, |
| 1087 | { GSM48_CC_CAUSE_MSGTYPE_INCOMPAT, "MSGTYPE_INCOMPAT" }, |
| 1088 | { GSM48_CC_CAUSE_IE_NOTEXIST, "IE_NOTEXIST" }, |
| 1089 | { GSM48_CC_CAUSE_COND_IE_ERR, "COND_IE_ERR" }, |
| 1090 | { GSM48_CC_CAUSE_MSG_INCOMP_STATE, "MSG_INCOMP_STATE" }, |
| 1091 | { GSM48_CC_CAUSE_RECOVERY_TIMER, "RECOVERY_TIMER" }, |
| 1092 | { GSM48_CC_CAUSE_PROTO_ERR, "PROTO_ERR" }, |
| 1093 | { GSM48_CC_CAUSE_INTERWORKING, "INTERWORKING" }, |
| 1094 | { 0 , NULL } |
| 1095 | }; |
| 1096 | |
Vadim Yanitskiy | 8d41d72 | 2018-04-17 11:17:28 +0700 | [diff] [blame] | 1097 | /*! TS 04.80, section 3.4 Messages for supplementary services control */ |
| 1098 | const struct value_string gsm48_nc_ss_msgtype_names[] = { |
| 1099 | OSMO_VALUE_STRING(GSM0480_MTYPE_RELEASE_COMPLETE), |
| 1100 | OSMO_VALUE_STRING(GSM0480_MTYPE_FACILITY), |
| 1101 | OSMO_VALUE_STRING(GSM0480_MTYPE_REGISTER), |
| 1102 | { 0, NULL } |
| 1103 | }; |
| 1104 | |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1105 | /*! Compose a string naming the message type for given protocol, in a caller-provided buffer. |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1106 | * If the message type string is known, return the message type name, otherwise |
| 1107 | * return "<protocol discriminator name>:<message type in hex>". |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1108 | * \param[out] buf caller-allcated output string buffer |
| 1109 | * \param[in] buf_len size of buf in bytes |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1110 | * \param[in] pdisc protocol discriminator like GSM48_PDISC_MM |
| 1111 | * \param[in] msg_type message type like GSM48_MT_MM_LOC_UPD_REQUEST |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1112 | * \returns buf |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1113 | */ |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1114 | char *gsm48_pdisc_msgtype_name_buf(char *buf, size_t buf_len, uint8_t pdisc, uint8_t msg_type) |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1115 | { |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1116 | const struct value_string *msgt_names; |
| 1117 | |
| 1118 | switch (pdisc) { |
| 1119 | case GSM48_PDISC_RR: |
| 1120 | msgt_names = gsm48_rr_msgtype_names; |
| 1121 | break; |
| 1122 | case GSM48_PDISC_MM: |
| 1123 | msgt_names = gsm48_mm_msgtype_names; |
| 1124 | break; |
| 1125 | case GSM48_PDISC_CC: |
| 1126 | msgt_names = gsm48_cc_msgtype_names; |
| 1127 | break; |
Vadim Yanitskiy | 8d41d72 | 2018-04-17 11:17:28 +0700 | [diff] [blame] | 1128 | case GSM48_PDISC_NC_SS: |
| 1129 | msgt_names = gsm48_nc_ss_msgtype_names; |
| 1130 | break; |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1131 | default: |
| 1132 | msgt_names = NULL; |
| 1133 | break; |
| 1134 | } |
| 1135 | |
| 1136 | if (msgt_names) |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1137 | snprintf(buf, buf_len, "%s", get_value_string(msgt_names, msg_type)); |
| 1138 | else |
| 1139 | snprintf(buf, buf_len, "%s:0x%02x", gsm48_pdisc_name(pdisc), msg_type); |
| 1140 | return buf; |
| 1141 | } |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1142 | |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1143 | /*! Compose a string naming the message type for given protocol, in a static buffer. |
| 1144 | * If the message type string is known, return the message type name, otherwise |
| 1145 | * return "<protocol discriminator name>:<message type in hex>". |
| 1146 | * \param[in] pdisc protocol discriminator like GSM48_PDISC_MM |
| 1147 | * \param[in] msg_type message type like GSM48_MT_MM_LOC_UPD_REQUEST |
| 1148 | * \returns statically allocated string or string constant. |
| 1149 | */ |
| 1150 | const char *gsm48_pdisc_msgtype_name(uint8_t pdisc, uint8_t msg_type) |
| 1151 | { |
Harald Welte | 171ef82 | 2019-03-28 10:49:05 +0100 | [diff] [blame] | 1152 | static __thread char namebuf[64]; |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1153 | return gsm48_pdisc_msgtype_name_buf(namebuf, sizeof(namebuf), pdisc, msg_type); |
Neels Hofmeyr | 00ab9ed | 2017-03-09 23:27:56 +0100 | [diff] [blame] | 1154 | } |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1155 | |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 1156 | /*! Compose a string naming the message type for given protocol, in a dynamically-allocated buffer. |
| 1157 | * If the message type string is known, return the message type name, otherwise |
| 1158 | * return "<protocol discriminator name>:<message type in hex>". |
| 1159 | * \param[in] ctx talloc context from which to allocate output buffer |
| 1160 | * \param[in] pdisc protocol discriminator like GSM48_PDISC_MM |
| 1161 | * \param[in] msg_type message type like GSM48_MT_MM_LOC_UPD_REQUEST |
| 1162 | * \returns string representation in dynamically allocated output buffer. |
| 1163 | */ |
| 1164 | char *gsm48_pdisc_msgtype_name_c(const void *ctx, uint8_t pdisc, uint8_t msg_type) |
| 1165 | { |
| 1166 | char *namebuf = talloc_size(ctx, 64); |
| 1167 | if (!namebuf) |
| 1168 | return NULL; |
| 1169 | return gsm48_pdisc_msgtype_name_buf(namebuf, 64, pdisc, msg_type); |
| 1170 | } |
| 1171 | |
Neels Hofmeyr | aead241 | 2018-04-06 04:31:00 +0200 | [diff] [blame] | 1172 | const struct value_string gsm48_reject_value_names[] = { |
| 1173 | { GSM48_REJECT_IMSI_UNKNOWN_IN_HLR, "IMSI_UNKNOWN_IN_HLR" }, |
| 1174 | { GSM48_REJECT_ILLEGAL_MS, "ILLEGAL_MS" }, |
| 1175 | { GSM48_REJECT_IMSI_UNKNOWN_IN_VLR, "IMSI_UNKNOWN_IN_VLR" }, |
| 1176 | { GSM48_REJECT_IMEI_NOT_ACCEPTED, "IMEI_NOT_ACCEPTED" }, |
| 1177 | { GSM48_REJECT_ILLEGAL_ME, "ILLEGAL_ME" }, |
| 1178 | { GSM48_REJECT_PLMN_NOT_ALLOWED, "PLMN_NOT_ALLOWED" }, |
| 1179 | { GSM48_REJECT_LOC_NOT_ALLOWED, "LOC_NOT_ALLOWED" }, |
| 1180 | { GSM48_REJECT_ROAMING_NOT_ALLOWED, "ROAMING_NOT_ALLOWED" }, |
| 1181 | { GSM48_REJECT_NETWORK_FAILURE, "NETWORK_FAILURE" }, |
| 1182 | { GSM48_REJECT_SYNCH_FAILURE, "SYNCH_FAILURE" }, |
| 1183 | { GSM48_REJECT_CONGESTION, "CONGESTION" }, |
| 1184 | { GSM48_REJECT_SRV_OPT_NOT_SUPPORTED, "SRV_OPT_NOT_SUPPORTED" }, |
| 1185 | { GSM48_REJECT_RQD_SRV_OPT_NOT_SUPPORTED, "RQD_SRV_OPT_NOT_SUPPORTED" }, |
| 1186 | { GSM48_REJECT_SRV_OPT_TMP_OUT_OF_ORDER, "SRV_OPT_TMP_OUT_OF_ORDER" }, |
| 1187 | { GSM48_REJECT_CALL_CAN_NOT_BE_IDENTIFIED, "CALL_CAN_NOT_BE_IDENTIFIED" }, |
| 1188 | { GSM48_REJECT_INCORRECT_MESSAGE, "INCORRECT_MESSAGE" }, |
| 1189 | { GSM48_REJECT_INVALID_MANDANTORY_INF, "INVALID_MANDANTORY_INF" }, |
| 1190 | { GSM48_REJECT_MSG_TYPE_NOT_IMPLEMENTED, "MSG_TYPE_NOT_IMPLEMENTED" }, |
| 1191 | { GSM48_REJECT_MSG_TYPE_NOT_COMPATIBLE, "MSG_TYPE_NOT_COMPATIBLE" }, |
| 1192 | { GSM48_REJECT_INF_ELEME_NOT_IMPLEMENTED, "INF_ELEME_NOT_IMPLEMENTED" }, |
| 1193 | { GSM48_REJECT_CONDTIONAL_IE_ERROR, "CONDTIONAL_IE_ERROR" }, |
| 1194 | { GSM48_REJECT_MSG_NOT_COMPATIBLE, "MSG_NOT_COMPATIBLE" }, |
| 1195 | { GSM48_REJECT_PROTOCOL_ERROR, "PROTOCOL_ERROR" }, |
| 1196 | { GSM48_REJECT_GPRS_NOT_ALLOWED, "GPRS_NOT_ALLOWED" }, |
| 1197 | { GSM48_REJECT_SERVICES_NOT_ALLOWED, "SERVICES_NOT_ALLOWED" }, |
| 1198 | { GSM48_REJECT_MS_IDENTITY_NOT_DERVIVABLE, "MS_IDENTITY_NOT_DERVIVABLE" }, |
| 1199 | { GSM48_REJECT_IMPLICITLY_DETACHED, "IMPLICITLY_DETACHED" }, |
| 1200 | { GSM48_REJECT_GPRS_NOT_ALLOWED_IN_PLMN, "GPRS_NOT_ALLOWED_IN_PLMN" }, |
| 1201 | { GSM48_REJECT_MSC_TMP_NOT_REACHABLE, "MSC_TMP_NOT_REACHABLE" }, |
| 1202 | { 0, NULL } |
| 1203 | }; |
| 1204 | |
Vadim Yanitskiy | 30cfeeb | 2018-08-03 05:44:00 +0700 | [diff] [blame] | 1205 | /*! Wrap a given \ref msg with \ref gsm48_hdr structure |
| 1206 | * \param[out] msg A message to be wrapped |
| 1207 | * \param[in] pdisc GSM TS 04.07 protocol discriminator 1/2, |
| 1208 | * sub-pdisc, trans_id or skip_ind 1/2, |
| 1209 | * see section 11.2.3.1 for details |
| 1210 | * \param[in] msg_type GSM TS 04.08 message type |
| 1211 | * @return pointer to pushed header within \ref msg |
| 1212 | */ |
| 1213 | struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg, |
| 1214 | uint8_t pdisc, uint8_t msg_type) |
| 1215 | { |
| 1216 | struct gsm48_hdr *gh; |
| 1217 | |
| 1218 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
| 1219 | gh->proto_discr = pdisc; |
| 1220 | gh->msg_type = msg_type; |
| 1221 | |
| 1222 | return gh; |
| 1223 | } |
| 1224 | |
Neels Hofmeyr | 92f3f5e | 2019-01-05 00:39:13 +0100 | [diff] [blame] | 1225 | const struct value_string osmo_lu_type_names[] = { |
| 1226 | { GSM48_LUPD_NORMAL, "NORMAL" }, |
| 1227 | { GSM48_LUPD_PERIODIC, "PERIODIC" }, |
| 1228 | { GSM48_LUPD_IMSI_ATT, "IMSI-ATTACH" }, |
| 1229 | { GSM48_LUPD_RESERVED, "RESERVED" }, |
| 1230 | {} |
| 1231 | }; |
| 1232 | |
Neels Hofmeyr | f8963f9 | 2019-01-10 23:33:32 +0100 | [diff] [blame] | 1233 | const struct value_string osmo_cm_service_type_names[] = { |
| 1234 | { GSM48_CMSERV_MO_CALL_PACKET, "MO-Call" }, |
| 1235 | { GSM48_CMSERV_EMERGENCY, "Emergency-Call" }, |
| 1236 | { GSM48_CMSERV_SMS, "Short-Messaging-Service" }, |
| 1237 | { GSM48_CMSERV_SUP_SERV, "Supplementary-Service" }, |
| 1238 | { GSM48_CMSERV_VGCS, "Voice-Group-Call" }, |
| 1239 | { GSM48_CMSERV_VBS, "Voice-Broadcast-Call" }, |
| 1240 | { GSM48_CMSERV_LOC_SERV, "Location-Service" }, |
| 1241 | {} |
| 1242 | }; |
| 1243 | |
Neels Hofmeyr | 7740d26 | 2019-01-16 16:53:26 +0100 | [diff] [blame] | 1244 | bool osmo_gsm48_classmark1_is_r99(const struct gsm48_classmark1 *cm1) |
| 1245 | { |
| 1246 | return cm1->rev_lev >= 2; |
| 1247 | } |
| 1248 | |
| 1249 | bool osmo_gsm48_classmark2_is_r99(const struct gsm48_classmark2 *cm2, uint8_t cm2_len) |
| 1250 | { |
| 1251 | if (!cm2_len) |
| 1252 | return false; |
| 1253 | return cm2->rev_lev >= 2; |
| 1254 | } |
| 1255 | |
| 1256 | /*! Return true if any of Classmark 1 or Classmark 2 are present and indicate R99 capability. |
| 1257 | * \param[in] cm Classmarks. |
| 1258 | * \returns True if R99 or later, false if pre-R99 or no Classmarks are present. |
| 1259 | */ |
| 1260 | bool osmo_gsm48_classmark_is_r99(const struct osmo_gsm48_classmark *cm) |
| 1261 | { |
| 1262 | if (cm->classmark1_set) |
| 1263 | return osmo_gsm48_classmark1_is_r99(&cm->classmark1); |
| 1264 | return osmo_gsm48_classmark2_is_r99(&cm->classmark2, cm->classmark2_len); |
| 1265 | } |
| 1266 | |
| 1267 | /*! Return a string representation of A5 cipher algorithms indicated by Classmark 1, 2 and 3. |
| 1268 | * \param[in] cm Classmarks. |
| 1269 | * \returns A statically allocated string like "cm1{a5/1=supported} cm2{0x23= A5/2 A5/3} no-cm3" |
| 1270 | */ |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1271 | char *osmo_gsm48_classmark_a5_name_buf(char *buf, size_t buf_len, const struct osmo_gsm48_classmark *cm) |
Neels Hofmeyr | 7740d26 | 2019-01-16 16:53:26 +0100 | [diff] [blame] | 1272 | { |
Neels Hofmeyr | 7740d26 | 2019-01-16 16:53:26 +0100 | [diff] [blame] | 1273 | char cm1[42] = "no-cm1"; |
| 1274 | char cm2[42] = " no-cm2"; |
Neels Hofmeyr | 9e6f5f1 | 2019-03-11 05:07:56 +0100 | [diff] [blame] | 1275 | char cm3[42] = " no-cm3"; |
Neels Hofmeyr | 7740d26 | 2019-01-16 16:53:26 +0100 | [diff] [blame] | 1276 | |
| 1277 | if (cm->classmark1_set) |
| 1278 | snprintf(cm1, sizeof(cm1), "cm1{a5/1=%s}", |
| 1279 | cm->classmark1.a5_1 ? "not-supported":"supported" /* inverted logic */); |
| 1280 | |
| 1281 | if (cm->classmark2_len >= 3) |
| 1282 | snprintf(cm2, sizeof(cm2), " cm2{0x%x=%s%s}", |
| 1283 | cm->classmark2.a5_2 + (cm->classmark2.a5_3 << 1), |
| 1284 | cm->classmark2.a5_2 ? " A5/2" : "", |
| 1285 | cm->classmark2.a5_3 ? " A5/3" : ""); |
| 1286 | |
| 1287 | if (cm->classmark3_len >= 1) |
| 1288 | snprintf(cm3, sizeof(cm3), " cm3{0x%x=%s%s%s%s}", |
| 1289 | cm->classmark3[0], |
| 1290 | cm->classmark3[0] & (1 << 0) ? " A5/4" : "", |
| 1291 | cm->classmark3[0] & (1 << 1) ? " A5/5" : "", |
| 1292 | cm->classmark3[0] & (1 << 2) ? " A5/6" : "", |
| 1293 | cm->classmark3[0] & (1 << 3) ? " A5/7" : ""); |
| 1294 | |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1295 | snprintf(buf, buf_len, "%s%s%s", cm1, cm2, cm3); |
Neels Hofmeyr | 7740d26 | 2019-01-16 16:53:26 +0100 | [diff] [blame] | 1296 | return buf; |
| 1297 | } |
| 1298 | |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1299 | /*! Return a string representation of A5 cipher algorithms indicated by Classmark 1, 2 and 3. |
| 1300 | * \param[in] cm Classmarks. |
| 1301 | * \returns A statically allocated string like "cm1{a5/1=supported} cm2{0x23= A5/2 A5/3} no-cm3" |
| 1302 | */ |
| 1303 | const char *osmo_gsm48_classmark_a5_name(const struct osmo_gsm48_classmark *cm) |
| 1304 | { |
Harald Welte | 171ef82 | 2019-03-28 10:49:05 +0100 | [diff] [blame] | 1305 | static __thread char buf[128]; |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1306 | return osmo_gsm48_classmark_a5_name_buf(buf, sizeof(buf), cm); |
| 1307 | } |
| 1308 | |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 1309 | /*! Return a string representation of A5 cipher algorithms indicated by Classmark 1, 2 and 3. |
| 1310 | * \param[in] ctx talloc context from which to allocate output buffer |
| 1311 | * \param[in] cm Classmarks. |
| 1312 | * \returns string like "cm1{a5/1=supported} cm2{0x23= A5/2 A5/3} no-cm3" in dynamically-allocated |
| 1313 | * output buffer. |
| 1314 | */ |
| 1315 | char *osmo_gsm48_classmark_a5_name_c(const void *ctx, const struct osmo_gsm48_classmark *cm) |
| 1316 | { |
| 1317 | char *buf = talloc_size(ctx, 128); |
| 1318 | if (!buf) |
| 1319 | return NULL; |
| 1320 | return osmo_gsm48_classmark_a5_name_buf(buf, 128, cm); |
| 1321 | } |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 1322 | |
Neels Hofmeyr | 7740d26 | 2019-01-16 16:53:26 +0100 | [diff] [blame] | 1323 | /*! Overwrite dst with the Classmark information present in src. |
| 1324 | * Add an new Classmark and overwrite in dst what src has to offer, but where src has no Classmark information, leave |
| 1325 | * dst unchanged. (For Classmark 2 and 3, dst will exactly match any non-zero Classmark length from src, hence may end |
| 1326 | * up with a shorter Classmark after this call.) |
| 1327 | * \param[out] dst The target Classmark storage to be updated. |
| 1328 | * \param[in] src The new Classmark information to read from. |
| 1329 | */ |
| 1330 | void osmo_gsm48_classmark_update(struct osmo_gsm48_classmark *dst, const struct osmo_gsm48_classmark *src) |
| 1331 | { |
| 1332 | if (src->classmark1_set) { |
| 1333 | dst->classmark1 = src->classmark1; |
| 1334 | dst->classmark1_set = true; |
| 1335 | } |
| 1336 | if (src->classmark2_len) { |
| 1337 | dst->classmark2_len = src->classmark2_len; |
| 1338 | dst->classmark2 = src->classmark2; |
| 1339 | } |
| 1340 | if (src->classmark3_len) { |
| 1341 | dst->classmark3_len = src->classmark3_len; |
| 1342 | memcpy(dst->classmark3, src->classmark3, OSMO_MIN(sizeof(dst->classmark3), src->classmark3_len)); |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | |
| 1347 | /*! Determine if the given Classmark (1/2/3) value permits a given A5/n cipher. |
| 1348 | * \param[in] cm Classmarks. |
| 1349 | * \param[in] a5 The N in A5/N for which to query whether support is indicated. |
| 1350 | * \return 1 when the given A5/n is permitted, 0 when not (or a5 > 7), and negative if the respective MS Classmark is |
| 1351 | * not known, where the negative number indicates the classmark type: -2 means Classmark 2 is not available. The |
| 1352 | * idea is that when e.g. A5/3 is requested and the corresponding Classmark 3 is not available, that the caller |
| 1353 | * can react by obtaining Classmark 3 and calling again once it is available. |
| 1354 | */ |
| 1355 | int osmo_gsm48_classmark_supports_a5(const struct osmo_gsm48_classmark *cm, uint8_t a5) |
| 1356 | { |
| 1357 | switch (a5) { |
| 1358 | case 0: |
| 1359 | /* all phones must implement A5/0, see 3GPP TS 43.020 4.9 */ |
| 1360 | return 1; |
| 1361 | case 1: |
| 1362 | /* 3GPP TS 43.020 4.9 requires A5/1 to be suppored by all phones and actually states: |
| 1363 | * "The network shall not provide service to an MS which indicates that it does not |
| 1364 | * support the ciphering algorithm A5/1.". However, let's be more tolerant based |
| 1365 | * on policy here */ |
| 1366 | /* See 3GPP TS 24.008 10.5.1.7 */ |
| 1367 | if (!cm->classmark1_set) |
| 1368 | return -1; |
| 1369 | /* Inverted logic for this bit! */ |
| 1370 | return cm->classmark1.a5_1 ? 0 : 1; |
| 1371 | case 2: |
| 1372 | /* See 3GPP TS 24.008 10.5.1.6 */ |
| 1373 | if (cm->classmark2_len < 3) |
| 1374 | return -2; |
| 1375 | return cm->classmark2.a5_2 ? 1 : 0; |
| 1376 | case 3: |
| 1377 | if (cm->classmark2_len < 3) |
| 1378 | return -2; |
| 1379 | return cm->classmark2.a5_3 ? 1 : 0; |
| 1380 | case 4: |
| 1381 | case 5: |
| 1382 | case 6: |
| 1383 | case 7: |
| 1384 | /* See 3GPP TS 24.008 10.5.1.7 */ |
| 1385 | if (!cm->classmark3_len) |
| 1386 | return -3; |
| 1387 | return (cm->classmark3[0] & (1 << (a5-4))) ? 1 : 0; |
| 1388 | default: |
| 1389 | return 0; |
| 1390 | } |
| 1391 | } |
| 1392 | |
Pau Espin Pedrol | b99f4ca | 2019-10-31 13:35:22 +0100 | [diff] [blame] | 1393 | /*! Decode power class from Classmark1/2 RF power capability field. |
| 1394 | * \param[in] rf_power_cap The RF power capability field (3 bits). |
| 1395 | * \param[in] band the band of the arfcn from where the classmark was received |
| 1396 | * \return the MS power class on success, negative on error. |
| 1397 | */ |
| 1398 | int8_t osmo_gsm48_rfpowercap2powerclass(enum gsm_band band, uint8_t rf_power_cap) |
| 1399 | { |
| 1400 | switch (band) { |
| 1401 | case GSM_BAND_1800: |
| 1402 | case GSM_BAND_1900: |
| 1403 | if (rf_power_cap > 2) |
| 1404 | return -1; |
| 1405 | return rf_power_cap + 1; |
| 1406 | default: |
| 1407 | if (rf_power_cap > 4) |
| 1408 | return -1; |
| 1409 | return rf_power_cap + 1; |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1414 | /*! @} */ |