Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gsm48_ie.c |
| 2 | * GSM Mobile Radio Interface Layer 3 messages. |
| 3 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0. */ |
| 4 | /* |
| 5 | * (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | b1ac2b9 | 2010-04-09 07:50:18 +0200 | [diff] [blame] | 6 | * (C) 2009-2010 by Andreas Eversberg |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 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 | 1e90866 | 2010-03-07 23:39:54 +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 | |
| 29 | #include <stdint.h> |
| 30 | #include <string.h> |
| 31 | #include <errno.h> |
| 32 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 33 | #include <osmocom/core/utils.h> |
| 34 | #include <osmocom/core/msgb.h> |
| 35 | #include <osmocom/gsm/tlv.h> |
| 36 | #include <osmocom/gsm/mncc.h> |
| 37 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 38 | #include <osmocom/gsm/gsm48_ie.h> |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 39 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 40 | /*! \addtogroup gsm0408 |
| 41 | * @{ |
| 42 | */ |
| 43 | |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 44 | static const char bcd_num_digits[] = { |
| 45 | '0', '1', '2', '3', '4', '5', '6', '7', |
| 46 | '8', '9', '*', '#', 'a', 'b', 'c', '\0' |
| 47 | }; |
| 48 | |
Neels Hofmeyr | 8212fc6 | 2019-04-01 14:34:37 +0200 | [diff] [blame] | 49 | /*! Like gsm48_decode_bcd_number2() but with less airtight bounds checking. |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 50 | * \param[out] Caller-provided output buffer |
| 51 | * \param[in] bcd_lv Length-Value portion of to-be-decoded IE |
| 52 | * \param[in] h_len Length of an optional heder between L and V portion |
| 53 | * \returns - in case of success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 54 | int gsm48_decode_bcd_number(char *output, int output_len, |
| 55 | const uint8_t *bcd_lv, int h_len) |
| 56 | { |
| 57 | uint8_t in_len = bcd_lv[0]; |
Neels Hofmeyr | 83d4531 | 2019-04-29 19:15:11 +0200 | [diff] [blame] | 58 | /* Just assume the input buffer is big enough for the length byte and the following data, so pass in_len + 1 for |
| 59 | * the input buffer size. */ |
| 60 | return gsm48_decode_bcd_number2(output, output_len, bcd_lv, in_len + 1, h_len); |
| 61 | } |
| 62 | |
| 63 | /*! Decode a 'called/calling/connect party BCD number' as in 10.5.4.7. |
| 64 | * \param[out] output Caller-provided output buffer. |
| 65 | * \param[in] output_len sizeof(output). |
| 66 | * \param[in] bcd_lv Length-Value part of to-be-decoded IE. |
| 67 | * \param[in] input_len Size of the bcd_lv buffer for bounds checking. |
| 68 | * \param[in] h_len Length of an optional header between L and V parts. |
Vadim Yanitskiy | 7194087 | 2019-05-26 00:49:57 +0700 | [diff] [blame] | 69 | * \return 0 in case of success, negative on error. |
| 70 | * |
| 71 | * Errors checked: |
| 72 | * - no or too little input data (-EIO), |
Vadim Yanitskiy | e4799f5 | 2019-05-26 00:55:20 +0700 | [diff] [blame] | 73 | * - IE length exceeds input data size (-EINVAL), |
Vadim Yanitskiy | 7194087 | 2019-05-26 00:49:57 +0700 | [diff] [blame] | 74 | * - no or too little output buffer size (-ENOSPC), |
| 75 | * - decoded number exceeds size of the output buffer (-ENOSPC). |
| 76 | * |
| 77 | * The output is guaranteed to be nul terminated iff output_len > 0. |
Neels Hofmeyr | 83d4531 | 2019-04-29 19:15:11 +0200 | [diff] [blame] | 78 | */ |
| 79 | int gsm48_decode_bcd_number2(char *output, size_t output_len, |
| 80 | const uint8_t *bcd_lv, size_t input_len, |
| 81 | size_t h_len) |
| 82 | { |
| 83 | uint8_t in_len; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 84 | int i; |
Oliver Smith | 186f878 | 2019-06-06 16:11:32 +0200 | [diff] [blame] | 85 | bool truncated = false; |
Neels Hofmeyr | 83d4531 | 2019-04-29 19:15:11 +0200 | [diff] [blame] | 86 | if (output_len < 1) |
| 87 | return -ENOSPC; |
| 88 | *output = '\0'; |
| 89 | if (input_len < 1) |
| 90 | return -EIO; |
| 91 | in_len = bcd_lv[0]; |
| 92 | /* len + 1: the BCD length plus the length byte itself must fit in the input buffer. */ |
| 93 | if (input_len < in_len + 1) |
Vadim Yanitskiy | e4799f5 | 2019-05-26 00:55:20 +0700 | [diff] [blame] | 94 | return -EINVAL; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 95 | |
| 96 | for (i = 1 + h_len; i <= in_len; i++) { |
| 97 | /* lower nibble */ |
Oliver Smith | 186f878 | 2019-06-06 16:11:32 +0200 | [diff] [blame] | 98 | if (output_len <= 1) { |
| 99 | truncated = true; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 100 | break; |
Oliver Smith | 186f878 | 2019-06-06 16:11:32 +0200 | [diff] [blame] | 101 | } |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 102 | *output++ = bcd_num_digits[bcd_lv[i] & 0xf]; |
Vadim Yanitskiy | 2cd1dda | 2019-05-26 00:14:16 +0700 | [diff] [blame] | 103 | output_len--; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 104 | |
| 105 | /* higher nibble */ |
Oliver Smith | 186f878 | 2019-06-06 16:11:32 +0200 | [diff] [blame] | 106 | if (output_len <= 1) { |
| 107 | /* not truncated if there is exactly one 0xf ('\0') higher nibble remaining */ |
| 108 | if (i == in_len && (bcd_lv[i] & 0xf0) == 0xf0) { |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | truncated = true; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 113 | break; |
Oliver Smith | 186f878 | 2019-06-06 16:11:32 +0200 | [diff] [blame] | 114 | } |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 115 | *output++ = bcd_num_digits[bcd_lv[i] >> 4]; |
Vadim Yanitskiy | 2cd1dda | 2019-05-26 00:14:16 +0700 | [diff] [blame] | 116 | output_len--; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 117 | } |
| 118 | if (output_len >= 1) |
| 119 | *output++ = '\0'; |
| 120 | |
Vadim Yanitskiy | 7194087 | 2019-05-26 00:49:57 +0700 | [diff] [blame] | 121 | /* Indicate whether the output was truncated */ |
Oliver Smith | 186f878 | 2019-06-06 16:11:32 +0200 | [diff] [blame] | 122 | if (truncated) |
Vadim Yanitskiy | 7194087 | 2019-05-26 00:49:57 +0700 | [diff] [blame] | 123 | return -ENOSPC; |
| 124 | |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 128 | /*! convert a single ASCII character to call-control BCD */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 129 | static int asc_to_bcd(const char asc) |
| 130 | { |
| 131 | int i; |
| 132 | |
| 133 | for (i = 0; i < ARRAY_SIZE(bcd_num_digits); i++) { |
| 134 | if (bcd_num_digits[i] == asc) |
| 135 | return i; |
| 136 | } |
| 137 | return -EINVAL; |
| 138 | } |
| 139 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 140 | /*! convert a ASCII phone number to 'called/calling/connect party BCD number' |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 141 | * \param[out] bcd_lv Caller-provided output buffer |
| 142 | * \param[in] max_len Maximum Length of \a bcd_lv |
| 143 | * \param[in] h_len Length of an optional heder between L and V portion |
| 144 | * \param[in] input phone number as 0-terminated ASCII |
Vadim Yanitskiy | 1dc8264 | 2019-05-27 00:53:54 +0700 | [diff] [blame] | 145 | * \returns number of bytes used in \a bcd_lv |
| 146 | * |
| 147 | * Depending on a context (e.g. called or calling party BCD number), the |
| 148 | * optional header between L and V parts can contain TON (Type Of Number), |
| 149 | * NPI (Numbering Plan Indication), presentation or screening indicator. |
| 150 | * NOTE: it is up to the caller to initialize this header! |
| 151 | */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 152 | int gsm48_encode_bcd_number(uint8_t *bcd_lv, uint8_t max_len, |
| 153 | int h_len, const char *input) |
| 154 | { |
| 155 | int in_len = strlen(input); |
| 156 | int i; |
| 157 | uint8_t *bcd_cur = bcd_lv + 1 + h_len; |
| 158 | |
| 159 | /* two digits per byte, plus type byte */ |
| 160 | bcd_lv[0] = in_len/2 + h_len; |
| 161 | if (in_len % 2) |
| 162 | bcd_lv[0]++; |
| 163 | |
| 164 | if (bcd_lv[0] > max_len) |
| 165 | return -EIO; |
| 166 | |
| 167 | for (i = 0; i < in_len; i++) { |
| 168 | int rc = asc_to_bcd(input[i]); |
| 169 | if (rc < 0) |
| 170 | return rc; |
| 171 | if (i % 2 == 0) |
| 172 | *bcd_cur = rc; |
| 173 | else |
| 174 | *bcd_cur++ |= (rc << 4); |
| 175 | } |
| 176 | /* append padding nibble in case of odd length */ |
| 177 | if (i % 2) |
| 178 | *bcd_cur++ |= 0xf0; |
| 179 | |
| 180 | /* return how many bytes we used */ |
| 181 | return (bcd_cur - bcd_lv); |
| 182 | } |
| 183 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 184 | /*! Decode TS 04.08 Bearer Capability IE (10.5.4.5) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 185 | * \param[out] Caller-provided memory for decoded output |
| 186 | * \[aram[in] LV portion of TS 04.08 Bearer Capability |
| 187 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 188 | int gsm48_decode_bearer_cap(struct gsm_mncc_bearer_cap *bcap, |
| 189 | const uint8_t *lv) |
| 190 | { |
| 191 | uint8_t in_len = lv[0]; |
| 192 | int i, s; |
| 193 | |
| 194 | if (in_len < 1) |
| 195 | return -EINVAL; |
| 196 | |
| 197 | bcap->speech_ver[0] = -1; /* end of list, of maximum 7 values */ |
| 198 | |
| 199 | /* octet 3 */ |
| 200 | bcap->transfer = lv[1] & 0x07; |
| 201 | bcap->mode = (lv[1] & 0x08) >> 3; |
| 202 | bcap->coding = (lv[1] & 0x10) >> 4; |
| 203 | bcap->radio = (lv[1] & 0x60) >> 5; |
| 204 | |
Harald Welte | c8a0b93 | 2012-08-24 21:27:26 +0200 | [diff] [blame] | 205 | switch (bcap->transfer) { |
| 206 | case GSM_MNCC_BCAP_SPEECH: |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 207 | i = 1; |
| 208 | s = 0; |
| 209 | while(!(lv[i] & 0x80)) { |
| 210 | i++; /* octet 3a etc */ |
| 211 | if (in_len < i) |
| 212 | return 0; |
| 213 | bcap->speech_ver[s++] = lv[i] & 0x0f; |
| 214 | bcap->speech_ver[s] = -1; /* end of list */ |
| 215 | if (i == 2) /* octet 3a */ |
| 216 | bcap->speech_ctm = (lv[i] & 0x20) >> 5; |
| 217 | if (s == 7) /* maximum speech versions + end of list */ |
| 218 | return 0; |
| 219 | } |
Harald Welte | c8a0b93 | 2012-08-24 21:27:26 +0200 | [diff] [blame] | 220 | break; |
| 221 | case GSM_MNCC_BCAP_UNR_DIG: |
| 222 | case GSM_MNCC_BCAP_FAX_G3: |
| 223 | i = 1; |
| 224 | while(!(lv[i] & 0x80)) { |
| 225 | i++; /* octet 3a etc */ |
| 226 | if (in_len < i) |
| 227 | return 0; |
| 228 | /* ignore them */ |
| 229 | } |
| 230 | /* octet 4: skip */ |
| 231 | i++; |
| 232 | /* octet 5 */ |
| 233 | i++; |
| 234 | if (in_len < i) |
| 235 | return 0; |
| 236 | bcap->data.rate_adaption = (lv[i] >> 3) & 3; |
| 237 | bcap->data.sig_access = lv[i] & 7; |
| 238 | while(!(lv[i] & 0x80)) { |
| 239 | i++; /* octet 5a etc */ |
| 240 | if (in_len < i) |
| 241 | return 0; |
| 242 | /* ignore them */ |
| 243 | } |
| 244 | /* octet 6 */ |
| 245 | i++; |
| 246 | if (in_len < i) |
| 247 | return 0; |
| 248 | bcap->data.async = lv[i] & 1; |
| 249 | if (!(lv[i] & 0x80)) { |
| 250 | i++; |
| 251 | if (in_len < i) |
| 252 | return 0; |
| 253 | /* octet 6a */ |
| 254 | bcap->data.nr_stop_bits = ((lv[i] >> 7) & 1) + 1; |
| 255 | if (lv[i] & 0x10) |
| 256 | bcap->data.nr_data_bits = 8; |
| 257 | else |
| 258 | bcap->data.nr_data_bits = 7; |
| 259 | bcap->data.user_rate = lv[i] & 0xf; |
| 260 | |
| 261 | if (!(lv[i] & 0x80)) { |
| 262 | i++; |
| 263 | if (in_len < i) |
| 264 | return 0; |
| 265 | /* octet 6b */ |
| 266 | bcap->data.parity = lv[i] & 7; |
| 267 | bcap->data.interm_rate = (lv[i] >> 5) & 3; |
| 268 | |
| 269 | /* octet 6c */ |
| 270 | if (!(lv[i] & 0x80)) { |
| 271 | i++; |
| 272 | if (in_len < i) |
| 273 | return 0; |
| 274 | bcap->data.transp = (lv[i] >> 5) & 3; |
| 275 | bcap->data.modem_type = lv[i] & 0x1F; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | } |
| 280 | break; |
| 281 | default: |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 282 | i = 1; |
| 283 | while (!(lv[i] & 0x80)) { |
| 284 | i++; /* octet 3a etc */ |
| 285 | if (in_len < i) |
| 286 | return 0; |
| 287 | /* ignore them */ |
| 288 | } |
| 289 | /* FIXME: implement OCTET 4+ parsing */ |
Harald Welte | c8a0b93 | 2012-08-24 21:27:26 +0200 | [diff] [blame] | 290 | break; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 296 | /*! Encode TS 04.08 Bearer Capability IE (10.5.4.5) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 297 | * \param[out] msg Message Buffer to which IE is to be appended |
| 298 | * \param[in] lv_only Write only LV portion (1) or TLV (0) |
| 299 | * \param[in] bcap Decoded Bearer Capability to be encoded |
| 300 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 301 | int gsm48_encode_bearer_cap(struct msgb *msg, int lv_only, |
| 302 | const struct gsm_mncc_bearer_cap *bcap) |
| 303 | { |
| 304 | uint8_t lv[32 + 1]; |
| 305 | int i = 1, s; |
| 306 | |
| 307 | lv[1] = bcap->transfer; |
| 308 | lv[1] |= bcap->mode << 3; |
| 309 | lv[1] |= bcap->coding << 4; |
| 310 | lv[1] |= bcap->radio << 5; |
| 311 | |
Harald Welte | c8a0b93 | 2012-08-24 21:27:26 +0200 | [diff] [blame] | 312 | switch (bcap->transfer) { |
| 313 | case GSM_MNCC_BCAP_SPEECH: |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 314 | for (s = 0; bcap->speech_ver[s] >= 0; s++) { |
| 315 | i++; /* octet 3a etc */ |
| 316 | lv[i] = bcap->speech_ver[s]; |
| 317 | if (i == 2) /* octet 3a */ |
| 318 | lv[i] |= bcap->speech_ctm << 5; |
| 319 | } |
| 320 | lv[i] |= 0x80; /* last IE of octet 3 etc */ |
Harald Welte | c8a0b93 | 2012-08-24 21:27:26 +0200 | [diff] [blame] | 321 | break; |
| 322 | case GSM48_BCAP_ITCAP_UNR_DIG_INF: |
| 323 | case GSM48_BCAP_ITCAP_FAX_G3: |
| 324 | lv[i++] |= 0x80; /* last IE of octet 3 etc */ |
| 325 | /* octet 4 */ |
| 326 | lv[i++] = 0xb8; |
| 327 | /* octet 5 */ |
| 328 | lv[i++] = 0x80 | ((bcap->data.rate_adaption & 3) << 3) |
| 329 | | (bcap->data.sig_access & 7); |
| 330 | /* octet 6 */ |
| 331 | lv[i++] = 0x20 | (bcap->data.async & 1); |
| 332 | /* octet 6a */ |
| 333 | lv[i++] = (bcap->data.user_rate & 0xf) | |
| 334 | (bcap->data.nr_data_bits == 8 ? 0x10 : 0x00) | |
| 335 | (bcap->data.nr_stop_bits == 2 ? 0x40 : 0x00); |
| 336 | /* octet 6b */ |
| 337 | lv[i++] = (bcap->data.parity & 7) | |
| 338 | ((bcap->data.interm_rate & 3) << 5); |
| 339 | /* octet 6c */ |
| 340 | lv[i] = 0x80 | (bcap->data.modem_type & 0x1f); |
| 341 | break; |
| 342 | default: |
| 343 | return -EINVAL; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | lv[0] = i; |
| 347 | if (lv_only) |
| 348 | msgb_lv_put(msg, lv[0], lv+1); |
| 349 | else |
| 350 | msgb_tlv_put(msg, GSM48_IE_BEARER_CAP, lv[0], lv+1); |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 355 | /*! Decode TS 04.08 Call Control Capabilities IE (10.5.4.5a) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 356 | * \param[out] Caller-provided memory for decoded CC capabilities |
| 357 | * \param[in] lv Length-Value of IE |
| 358 | * \retursns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 359 | int gsm48_decode_cccap(struct gsm_mncc_cccap *ccap, const uint8_t *lv) |
| 360 | { |
| 361 | uint8_t in_len = lv[0]; |
| 362 | |
| 363 | if (in_len < 1) |
| 364 | return -EINVAL; |
| 365 | |
| 366 | /* octet 3 */ |
| 367 | ccap->dtmf = lv[1] & 0x01; |
| 368 | ccap->pcp = (lv[1] & 0x02) >> 1; |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 373 | /*! Encodoe TS 04.08 Call Control Capabilities (10.5.4.5a) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 374 | * \param[out] msg Message Buffer to which to append IE (as TLV) |
| 375 | * \param[in] ccap Decoded CC Capabilities to be encoded |
| 376 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 377 | int gsm48_encode_cccap(struct msgb *msg, |
| 378 | const struct gsm_mncc_cccap *ccap) |
| 379 | { |
| 380 | uint8_t lv[2]; |
| 381 | |
| 382 | lv[0] = 1; |
| 383 | lv[1] = 0; |
| 384 | if (ccap->dtmf) |
| 385 | lv [1] |= 0x01; |
| 386 | if (ccap->pcp) |
| 387 | lv [1] |= 0x02; |
| 388 | |
| 389 | msgb_tlv_put(msg, GSM48_IE_CC_CAP, lv[0], lv+1); |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 394 | /*! Decode TS 04.08 Called Party BCD Number IE (10.5.4.7) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 395 | * \param[out] called Caller-provided memory for decoded number |
| 396 | * \param[in] lv Length-Value portion of IE |
| 397 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 398 | int gsm48_decode_called(struct gsm_mncc_number *called, |
| 399 | const uint8_t *lv) |
| 400 | { |
| 401 | uint8_t in_len = lv[0]; |
| 402 | |
| 403 | if (in_len < 1) |
| 404 | return -EINVAL; |
| 405 | |
| 406 | /* octet 3 */ |
| 407 | called->plan = lv[1] & 0x0f; |
| 408 | called->type = (lv[1] & 0x70) >> 4; |
| 409 | |
| 410 | /* octet 4..N */ |
| 411 | gsm48_decode_bcd_number(called->number, sizeof(called->number), lv, 1); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 416 | /*! Encode TS 04.08 Called Party IE (10.5.4.7) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 417 | * \param[out] msg Mesage Buffer to which to append IE (as TLV) |
| 418 | * \param[in] called MNCC Number to encode/append |
| 419 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 420 | int gsm48_encode_called(struct msgb *msg, |
| 421 | const struct gsm_mncc_number *called) |
| 422 | { |
| 423 | uint8_t lv[18]; |
| 424 | int ret; |
| 425 | |
| 426 | /* octet 3 */ |
Sylvain Munaut | 47ee693 | 2010-09-20 20:59:23 +0200 | [diff] [blame] | 427 | lv[1] = 0x80; /* no extension */ |
| 428 | lv[1] |= called->plan; |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 429 | lv[1] |= called->type << 4; |
| 430 | |
| 431 | /* octet 4..N, octet 2 */ |
| 432 | ret = gsm48_encode_bcd_number(lv, sizeof(lv), 1, called->number); |
| 433 | if (ret < 0) |
| 434 | return ret; |
| 435 | |
| 436 | msgb_tlv_put(msg, GSM48_IE_CALLED_BCD, lv[0], lv+1); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 441 | /*! Decode TS 04.08 Caller ID |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 442 | * \param[out] called Caller-provided memory for decoded number |
| 443 | * \param[in] lv Length-Value portion of IE |
| 444 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 445 | int gsm48_decode_callerid(struct gsm_mncc_number *callerid, |
| 446 | const uint8_t *lv) |
| 447 | { |
| 448 | uint8_t in_len = lv[0]; |
| 449 | int i = 1; |
| 450 | |
| 451 | if (in_len < 1) |
| 452 | return -EINVAL; |
| 453 | |
| 454 | /* octet 3 */ |
| 455 | callerid->plan = lv[1] & 0x0f; |
| 456 | callerid->type = (lv[1] & 0x70) >> 4; |
| 457 | |
| 458 | /* octet 3a */ |
| 459 | if (!(lv[1] & 0x80)) { |
| 460 | callerid->screen = lv[2] & 0x03; |
| 461 | callerid->present = (lv[2] & 0x60) >> 5; |
| 462 | i = 2; |
| 463 | } |
| 464 | |
| 465 | /* octet 4..N */ |
| 466 | gsm48_decode_bcd_number(callerid->number, sizeof(callerid->number), lv, i); |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 471 | /*! Encode TS 04.08 Caller ID IE |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 472 | * \param[out] msg Mesage Buffer to which to append IE (as TLV) |
| 473 | * \param[in] ie IE Identifier (tag) |
| 474 | * \param[in] max_len maximum generated output in bytes |
| 475 | * \param[in] callerid MNCC Number to encode/append |
| 476 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 477 | int gsm48_encode_callerid(struct msgb *msg, int ie, int max_len, |
| 478 | const struct gsm_mncc_number *callerid) |
| 479 | { |
| 480 | uint8_t lv[max_len - 1]; |
| 481 | int h_len = 1; |
| 482 | int ret; |
| 483 | |
| 484 | /* octet 3 */ |
| 485 | lv[1] = callerid->plan; |
| 486 | lv[1] |= callerid->type << 4; |
| 487 | |
| 488 | if (callerid->present || callerid->screen) { |
| 489 | /* octet 3a */ |
| 490 | lv[2] = callerid->screen; |
| 491 | lv[2] |= callerid->present << 5; |
| 492 | lv[2] |= 0x80; |
| 493 | h_len++; |
| 494 | } else |
| 495 | lv[1] |= 0x80; |
| 496 | |
| 497 | /* octet 4..N, octet 2 */ |
| 498 | ret = gsm48_encode_bcd_number(lv, sizeof(lv), h_len, callerid->number); |
| 499 | if (ret < 0) |
| 500 | return ret; |
| 501 | |
| 502 | msgb_tlv_put(msg, ie, lv[0], lv+1); |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 507 | /*! Decode TS 04.08 Cause IE (10.5.4.11) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 508 | * \param[out] cause Caller-provided memory for output |
| 509 | * \param[in] lv LV portion of Cause IE |
| 510 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 511 | int gsm48_decode_cause(struct gsm_mncc_cause *cause, |
| 512 | const uint8_t *lv) |
| 513 | { |
| 514 | uint8_t in_len = lv[0]; |
| 515 | int i; |
| 516 | |
| 517 | if (in_len < 2) |
| 518 | return -EINVAL; |
| 519 | |
| 520 | cause->diag_len = 0; |
| 521 | |
| 522 | /* octet 3 */ |
| 523 | cause->location = lv[1] & 0x0f; |
| 524 | cause->coding = (lv[1] & 0x60) >> 5; |
| 525 | |
| 526 | i = 1; |
| 527 | if (!(lv[i] & 0x80)) { |
| 528 | i++; /* octet 3a */ |
| 529 | if (in_len < i+1) |
| 530 | return 0; |
| 531 | cause->rec = 1; |
| 532 | cause->rec_val = lv[i] & 0x7f; |
| 533 | } |
| 534 | i++; |
| 535 | |
| 536 | /* octet 4 */ |
| 537 | cause->value = lv[i] & 0x7f; |
| 538 | i++; |
| 539 | |
| 540 | if (in_len < i) /* no diag */ |
| 541 | return 0; |
| 542 | |
| 543 | if (in_len - (i-1) > 32) /* maximum 32 octets */ |
| 544 | return 0; |
| 545 | |
| 546 | /* octet 5-N */ |
| 547 | memcpy(cause->diag, lv + i, in_len - (i-1)); |
| 548 | cause->diag_len = in_len - (i-1); |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 553 | /*! Encode TS 04.08 Cause IE (10.5.4.11) |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 554 | * \param[out] msg Message Buffer to which to append IE |
| 555 | * \param[in] lv_only Encode as LV (1) or TLV (0) |
| 556 | * \param[in] cause Cause value to be encoded |
| 557 | * \returns 0 on success; negative on error */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 558 | int gsm48_encode_cause(struct msgb *msg, int lv_only, |
| 559 | const struct gsm_mncc_cause *cause) |
| 560 | { |
| 561 | uint8_t lv[32+4]; |
| 562 | int i; |
| 563 | |
| 564 | if (cause->diag_len > 32) |
| 565 | return -EINVAL; |
| 566 | |
| 567 | /* octet 3 */ |
| 568 | lv[1] = cause->location; |
| 569 | lv[1] |= cause->coding << 5; |
| 570 | |
| 571 | i = 1; |
| 572 | if (cause->rec) { |
| 573 | i++; /* octet 3a */ |
| 574 | lv[i] = cause->rec_val; |
| 575 | } |
| 576 | lv[i] |= 0x80; /* end of octet 3 */ |
| 577 | |
| 578 | /* octet 4 */ |
| 579 | i++; |
| 580 | lv[i] = 0x80 | cause->value; |
| 581 | |
| 582 | /* octet 5-N */ |
| 583 | if (cause->diag_len) { |
| 584 | memcpy(lv + i, cause->diag, cause->diag_len); |
| 585 | i += cause->diag_len; |
| 586 | } |
| 587 | |
| 588 | lv[0] = i; |
| 589 | if (lv_only) |
| 590 | msgb_lv_put(msg, lv[0], lv+1); |
| 591 | else |
| 592 | msgb_tlv_put(msg, GSM48_IE_CAUSE, lv[0], lv+1); |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 597 | /*! Decode TS 04.08 Calling Number IE (10.5.4.9) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 598 | int gsm48_decode_calling(struct gsm_mncc_number *calling, |
| 599 | const uint8_t *lv) |
| 600 | { |
| 601 | return gsm48_decode_callerid(calling, lv); |
| 602 | } |
| 603 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 604 | /*! Encode TS 04.08 Calling Number IE (10.5.4.9) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 605 | int gsm48_encode_calling(struct msgb *msg, |
| 606 | const struct gsm_mncc_number *calling) |
| 607 | { |
| 608 | return gsm48_encode_callerid(msg, GSM48_IE_CALLING_BCD, 14, calling); |
| 609 | } |
| 610 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 611 | /*! Decode TS 04.08 Connected Number IE (10.5.4.13) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 612 | int gsm48_decode_connected(struct gsm_mncc_number *connected, |
| 613 | const uint8_t *lv) |
| 614 | { |
| 615 | return gsm48_decode_callerid(connected, lv); |
| 616 | } |
| 617 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 618 | /*! Encode TS 04.08 Connected Number IE (10.5.4.13) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 619 | int gsm48_encode_connected(struct msgb *msg, |
| 620 | const struct gsm_mncc_number *connected) |
| 621 | { |
| 622 | return gsm48_encode_callerid(msg, GSM48_IE_CONN_BCD, 14, connected); |
| 623 | } |
| 624 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 625 | /*! Decode TS 04.08 Redirecting Number IE (10.5.4.21b) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 626 | int gsm48_decode_redirecting(struct gsm_mncc_number *redirecting, |
| 627 | const uint8_t *lv) |
| 628 | { |
| 629 | return gsm48_decode_callerid(redirecting, lv); |
| 630 | } |
| 631 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 632 | /*! Encode TS 04.08 Redirecting Number IE (10.5.4.21b) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 633 | int gsm48_encode_redirecting(struct msgb *msg, |
| 634 | const struct gsm_mncc_number *redirecting) |
| 635 | { |
| 636 | return gsm48_encode_callerid(msg, GSM48_IE_REDIR_BCD, 19, redirecting); |
| 637 | } |
| 638 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 639 | /*! Decode TS 04.08 Facility IE (10.5.4.15) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 640 | int gsm48_decode_facility(struct gsm_mncc_facility *facility, |
| 641 | const uint8_t *lv) |
| 642 | { |
| 643 | uint8_t in_len = lv[0]; |
| 644 | |
| 645 | if (in_len < 1) |
| 646 | return -EINVAL; |
| 647 | |
| 648 | if (in_len > sizeof(facility->info)) |
| 649 | return -EINVAL; |
| 650 | |
| 651 | memcpy(facility->info, lv+1, in_len); |
| 652 | facility->len = in_len; |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 657 | /*! Encode TS 04.08 Facility IE (10.5.4.15) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 658 | int gsm48_encode_facility(struct msgb *msg, int lv_only, |
| 659 | const struct gsm_mncc_facility *facility) |
| 660 | { |
| 661 | uint8_t lv[GSM_MAX_FACILITY + 1]; |
| 662 | |
| 663 | if (facility->len < 1 || facility->len > GSM_MAX_FACILITY) |
| 664 | return -EINVAL; |
| 665 | |
| 666 | memcpy(lv+1, facility->info, facility->len); |
| 667 | lv[0] = facility->len; |
| 668 | if (lv_only) |
| 669 | msgb_lv_put(msg, lv[0], lv+1); |
| 670 | else |
| 671 | msgb_tlv_put(msg, GSM48_IE_FACILITY, lv[0], lv+1); |
| 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 676 | /*! Decode TS 04.08 Notify IE (10.5.4.20) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 677 | int gsm48_decode_notify(int *notify, const uint8_t *v) |
| 678 | { |
| 679 | *notify = v[0] & 0x7f; |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 684 | /*! Encode TS 04.08 Notify IE (10.5.4.20) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 685 | int gsm48_encode_notify(struct msgb *msg, int notify) |
| 686 | { |
| 687 | msgb_v_put(msg, notify | 0x80); |
| 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 692 | /*! Decode TS 04.08 Signal IE (10.5.4.23) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 693 | int gsm48_decode_signal(int *signal, const uint8_t *v) |
| 694 | { |
| 695 | *signal = v[0]; |
| 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 700 | /*! Encode TS 04.08 Signal IE (10.5.4.23) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 701 | int gsm48_encode_signal(struct msgb *msg, int signal) |
| 702 | { |
| 703 | msgb_tv_put(msg, GSM48_IE_SIGNAL, signal); |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 708 | /*! Decode TS 04.08 Keypad IE (10.5.4.17) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 709 | int gsm48_decode_keypad(int *keypad, const uint8_t *lv) |
| 710 | { |
| 711 | uint8_t in_len = lv[0]; |
| 712 | |
| 713 | if (in_len < 1) |
| 714 | return -EINVAL; |
| 715 | |
| 716 | *keypad = lv[1] & 0x7f; |
| 717 | |
| 718 | return 0; |
| 719 | } |
| 720 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 721 | /*! Encode TS 04.08 Keypad IE (10.5.4.17) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 722 | int gsm48_encode_keypad(struct msgb *msg, int keypad) |
| 723 | { |
| 724 | msgb_tv_put(msg, GSM48_IE_KPD_FACILITY, keypad); |
| 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 729 | /*! Decode TS 04.08 Progress IE (10.5.4.21) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 730 | int gsm48_decode_progress(struct gsm_mncc_progress *progress, |
| 731 | const uint8_t *lv) |
| 732 | { |
| 733 | uint8_t in_len = lv[0]; |
| 734 | |
| 735 | if (in_len < 2) |
| 736 | return -EINVAL; |
| 737 | |
| 738 | progress->coding = (lv[1] & 0x60) >> 5; |
| 739 | progress->location = lv[1] & 0x0f; |
| 740 | progress->descr = lv[2] & 0x7f; |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 745 | /*! Encode TS 04.08 Progress IE (10.5.4.21) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 746 | int gsm48_encode_progress(struct msgb *msg, int lv_only, |
| 747 | const struct gsm_mncc_progress *p) |
| 748 | { |
| 749 | uint8_t lv[3]; |
| 750 | |
| 751 | lv[0] = 2; |
| 752 | lv[1] = 0x80 | ((p->coding & 0x3) << 5) | (p->location & 0xf); |
| 753 | lv[2] = 0x80 | (p->descr & 0x7f); |
| 754 | if (lv_only) |
| 755 | msgb_lv_put(msg, lv[0], lv+1); |
| 756 | else |
| 757 | msgb_tlv_put(msg, GSM48_IE_PROGR_IND, lv[0], lv+1); |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 762 | /*! Decode TS 04.08 User-User IE (10.5.4.25) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 763 | int gsm48_decode_useruser(struct gsm_mncc_useruser *uu, |
| 764 | const uint8_t *lv) |
| 765 | { |
| 766 | uint8_t in_len = lv[0]; |
| 767 | char *info = uu->info; |
| 768 | int info_len = sizeof(uu->info); |
| 769 | int i; |
| 770 | |
| 771 | if (in_len < 1) |
| 772 | return -EINVAL; |
| 773 | |
| 774 | uu->proto = lv[1]; |
| 775 | |
| 776 | for (i = 2; i <= in_len; i++) { |
| 777 | info_len--; |
| 778 | if (info_len <= 1) |
| 779 | break; |
| 780 | *info++ = lv[i]; |
| 781 | } |
| 782 | if (info_len >= 1) |
| 783 | *info++ = '\0'; |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 788 | /*! Encode TS 04.08 User-User IE (10.5.4.25) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 789 | int gsm48_encode_useruser(struct msgb *msg, int lv_only, |
| 790 | const struct gsm_mncc_useruser *uu) |
| 791 | { |
| 792 | uint8_t lv[GSM_MAX_USERUSER + 2]; |
| 793 | |
| 794 | if (strlen(uu->info) > GSM_MAX_USERUSER) |
| 795 | return -EINVAL; |
| 796 | |
| 797 | lv[0] = 1 + strlen(uu->info); |
| 798 | lv[1] = uu->proto; |
| 799 | memcpy(lv + 2, uu->info, strlen(uu->info)); |
| 800 | if (lv_only) |
| 801 | msgb_lv_put(msg, lv[0], lv+1); |
| 802 | else |
| 803 | msgb_tlv_put(msg, GSM48_IE_USER_USER, lv[0], lv+1); |
| 804 | |
| 805 | return 0; |
| 806 | } |
| 807 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 808 | /*! Decode TS 04.08 SS Version IE (10.5.4.24) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 809 | int gsm48_decode_ssversion(struct gsm_mncc_ssversion *ssv, |
| 810 | const uint8_t *lv) |
| 811 | { |
| 812 | uint8_t in_len = lv[0]; |
| 813 | |
| 814 | if (in_len < 1 || in_len < sizeof(ssv->info)) |
| 815 | return -EINVAL; |
| 816 | |
| 817 | memcpy(ssv->info, lv + 1, in_len); |
| 818 | ssv->len = in_len; |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 823 | /*! Encode TS 04.08 SS Version IE (10.5.4.24) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 824 | int gsm48_encode_ssversion(struct msgb *msg, |
| 825 | const struct gsm_mncc_ssversion *ssv) |
| 826 | { |
| 827 | uint8_t lv[GSM_MAX_SSVERSION + 1]; |
| 828 | |
| 829 | if (ssv->len > GSM_MAX_SSVERSION) |
| 830 | return -EINVAL; |
| 831 | |
| 832 | lv[0] = ssv->len; |
| 833 | memcpy(lv + 1, ssv->info, ssv->len); |
| 834 | msgb_tlv_put(msg, GSM48_IE_SS_VERS, lv[0], lv+1); |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | /* decode 'more data' does not require a function, because it has no value */ |
| 840 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 841 | /*! Encode TS 04.08 More Data IE (10.5.4.19) */ |
Harald Welte | 1e90866 | 2010-03-07 23:39:54 +0100 | [diff] [blame] | 842 | int gsm48_encode_more(struct msgb *msg) |
| 843 | { |
| 844 | uint8_t *ie; |
| 845 | |
| 846 | ie = msgb_put(msg, 1); |
| 847 | ie[0] = GSM48_IE_MORE_DATA; |
| 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 852 | static int32_t smod(int32_t n, int32_t m) |
| 853 | { |
| 854 | int32_t res; |
| 855 | |
| 856 | res = n % m; |
| 857 | |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 858 | if (res <= 0) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 859 | res += m; |
| 860 | |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 861 | return res; |
| 862 | } |
| 863 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 864 | /*! Decode TS 04.08 Cell Channel Description IE (10.5.2.1b) and other frequency lists |
Pau Espin Pedrol | d8d0c3e | 2018-11-15 18:26:01 +0100 | [diff] [blame] | 865 | * \param[out] f Caller-provided output memory, an array of 1024 elements |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 866 | * \param[in] cd Cell Channel Description IE |
| 867 | * \param[in] len Length of \a cd in bytes |
| 868 | * \returns 0 on success; negative on error */ |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 869 | int gsm48_decode_freq_list(struct gsm_sysinfo_freq *f, uint8_t *cd, |
| 870 | uint8_t len, uint8_t mask, uint8_t frqt) |
| 871 | { |
| 872 | int i; |
| 873 | |
| 874 | /* NOTES: |
| 875 | * |
| 876 | * The Range format uses "SMOD" computation. |
| 877 | * e.g. "n SMOD m" equals "((n - 1) % m) + 1" |
| 878 | * A cascade of multiple SMOD computations is simpified: |
| 879 | * "(n SMOD m) SMOD o" equals "(((n - 1) % m) % o) + 1" |
| 880 | * |
| 881 | * The Range format uses 16 octets of data in SYSTEM INFORMATION. |
| 882 | * When used in dedicated messages, the length can be less. |
| 883 | * In this case the ranges are decoded for all frequencies that |
| 884 | * fit in the block of given length. |
| 885 | */ |
| 886 | |
| 887 | /* tabula rasa */ |
| 888 | for (i = 0; i < 1024; i++) |
| 889 | f[i].mask &= ~frqt; |
| 890 | |
| 891 | /* 00..XXX. */ |
| 892 | if ((cd[0] & 0xc0 & mask) == 0x00) { |
| 893 | /* Bit map 0 format */ |
| 894 | if (len < 16) |
| 895 | return -EINVAL; |
| 896 | for (i = 1; i <= 124; i++) |
| 897 | if ((cd[15 - ((i-1) >> 3)] & (1 << ((i-1) & 7)))) |
| 898 | f[i].mask |= frqt; |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | /* 10..0XX. */ |
| 904 | if ((cd[0] & 0xc8 & mask) == 0x80) { |
| 905 | /* Range 1024 format */ |
| 906 | uint16_t w[17]; /* 1..16 */ |
| 907 | struct gsm48_range_1024 *r = (struct gsm48_range_1024 *)cd; |
| 908 | |
| 909 | if (len < 2) |
| 910 | return -EINVAL; |
| 911 | memset(w, 0, sizeof(w)); |
| 912 | if (r->f0) |
| 913 | f[0].mask |= frqt; |
| 914 | w[1] = (r->w1_hi << 8) | r->w1_lo; |
| 915 | if (len >= 4) |
| 916 | w[2] = (r->w2_hi << 1) | r->w2_lo; |
| 917 | if (len >= 5) |
| 918 | w[3] = (r->w3_hi << 2) | r->w3_lo; |
| 919 | if (len >= 6) |
| 920 | w[4] = (r->w4_hi << 2) | r->w4_lo; |
| 921 | if (len >= 7) |
| 922 | w[5] = (r->w5_hi << 2) | r->w5_lo; |
| 923 | if (len >= 8) |
| 924 | w[6] = (r->w6_hi << 2) | r->w6_lo; |
| 925 | if (len >= 9) |
| 926 | w[7] = (r->w7_hi << 2) | r->w7_lo; |
| 927 | if (len >= 10) |
| 928 | w[8] = (r->w8_hi << 1) | r->w8_lo; |
| 929 | if (len >= 10) |
| 930 | w[9] = r->w9; |
| 931 | if (len >= 11) |
| 932 | w[10] = r->w10; |
| 933 | if (len >= 12) |
| 934 | w[11] = (r->w11_hi << 6) | r->w11_lo; |
| 935 | if (len >= 13) |
| 936 | w[12] = (r->w12_hi << 5) | r->w12_lo; |
| 937 | if (len >= 14) |
| 938 | w[13] = (r->w13_hi << 4) | r->w13_lo; |
| 939 | if (len >= 15) |
| 940 | w[14] = (r->w14_hi << 3) | r->w14_lo; |
| 941 | if (len >= 16) |
| 942 | w[15] = (r->w15_hi << 2) | r->w15_lo; |
| 943 | if (len >= 16) |
| 944 | w[16] = r->w16; |
| 945 | if (w[1]) |
| 946 | f[w[1]].mask |= frqt; |
| 947 | if (w[2]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 948 | f[smod(w[1] - 512 + w[2], 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 949 | if (w[3]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 950 | f[smod(w[1] + w[3], 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 951 | if (w[4]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 952 | f[smod(w[1] - 512 + smod(w[2] - 256 + w[4], 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 953 | if (w[5]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 954 | f[smod(w[1] + smod(w[3] - 256 + w[5], 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 955 | if (w[6]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 956 | f[smod(w[1] - 512 + smod(w[2] + w[6], 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 957 | if (w[7]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 958 | f[smod(w[1] + smod(w[3] + w[7], 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 959 | if (w[8]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 960 | f[smod(w[1] - 512 + smod(w[2] - 256 + smod(w[4] - 128 + w[8] , 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 961 | if (w[9]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 962 | f[smod(w[1] + smod(w[3] - 256 + smod(w[5] - 128 + w[9] , 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 963 | if (w[10]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 964 | f[smod(w[1] - 512 + smod(w[2] + smod(w[6] - 128 + w[10], 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 965 | if (w[11]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 966 | f[smod(w[1] + smod(w[3] + smod(w[7] - 128 + w[11], 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 967 | if (w[12]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 968 | f[smod(w[1] - 512 + smod(w[2] - 256 + smod(w[4] + w[12], 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 969 | if (w[13]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 970 | f[smod(w[1] + smod(w[3] - 256 + smod(w[5] + w[13], 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 971 | if (w[14]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 972 | f[smod(w[1] - 512 + smod(w[2] + smod(w[6] + w[14], 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 973 | if (w[15]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 974 | f[smod(w[1] + smod(w[3] + smod(w[7] + w[15], 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 975 | if (w[16]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 976 | f[smod(w[1] - 512 + smod(w[2] - 256 + smod(w[4] - 128 + smod(w[8] - 64 + w[16], 127), 255), 511), 1023)].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 977 | |
| 978 | return 0; |
| 979 | } |
| 980 | /* 10..100. */ |
| 981 | if ((cd[0] & 0xce & mask) == 0x88) { |
| 982 | /* Range 512 format */ |
| 983 | uint16_t w[18]; /* 1..17 */ |
| 984 | struct gsm48_range_512 *r = (struct gsm48_range_512 *)cd; |
| 985 | |
| 986 | if (len < 4) |
| 987 | return -EINVAL; |
| 988 | memset(w, 0, sizeof(w)); |
| 989 | w[0] = (r->orig_arfcn_hi << 9) | (r->orig_arfcn_mid << 1) | r->orig_arfcn_lo; |
| 990 | w[1] = (r->w1_hi << 2) | r->w1_lo; |
| 991 | if (len >= 5) |
| 992 | w[2] = (r->w2_hi << 2) | r->w2_lo; |
| 993 | if (len >= 6) |
| 994 | w[3] = (r->w3_hi << 2) | r->w3_lo; |
| 995 | if (len >= 7) |
| 996 | w[4] = (r->w4_hi << 1) | r->w4_lo; |
| 997 | if (len >= 7) |
| 998 | w[5] = r->w5; |
| 999 | if (len >= 8) |
| 1000 | w[6] = r->w6; |
| 1001 | if (len >= 9) |
| 1002 | w[7] = (r->w7_hi << 6) | r->w7_lo; |
| 1003 | if (len >= 10) |
| 1004 | w[8] = (r->w8_hi << 4) | r->w8_lo; |
| 1005 | if (len >= 11) |
| 1006 | w[9] = (r->w9_hi << 2) | r->w9_lo; |
| 1007 | if (len >= 11) |
| 1008 | w[10] = r->w10; |
| 1009 | if (len >= 12) |
| 1010 | w[11] = r->w11; |
| 1011 | if (len >= 13) |
| 1012 | w[12] = (r->w12_hi << 4) | r->w12_lo; |
| 1013 | if (len >= 14) |
| 1014 | w[13] = (r->w13_hi << 2) | r->w13_lo; |
| 1015 | if (len >= 14) |
| 1016 | w[14] = r->w14; |
| 1017 | if (len >= 15) |
| 1018 | w[15] = r->w15; |
| 1019 | if (len >= 16) |
| 1020 | w[16] = (r->w16_hi << 3) | r->w16_lo; |
| 1021 | if (len >= 16) |
| 1022 | w[17] = r->w17; |
| 1023 | f[w[0]].mask |= frqt; |
| 1024 | if (w[1]) |
| 1025 | f[(w[0] + w[1]) % 1024].mask |= frqt; |
| 1026 | if (w[2]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1027 | f[(w[0] + smod(w[1] - 256 + w[2], 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1028 | if (w[3]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1029 | f[(w[0] + smod(w[1] + w[3], 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1030 | if (w[4]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1031 | f[(w[0] + smod(w[1] - 256 + smod(w[2] - 128 + w[4], 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1032 | if (w[5]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1033 | f[(w[0] + smod(w[1] + smod(w[3] - 128 + w[5], 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1034 | if (w[6]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1035 | f[(w[0] + smod(w[1] - 256 + smod(w[2] + w[6], 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1036 | if (w[7]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1037 | f[(w[0] + smod(w[1] + smod(w[3] + w[7], 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1038 | if (w[8]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1039 | f[(w[0] + smod(w[1] - 256 + smod(w[2] - 128 + smod(w[4] - 64 + w[8] , 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1040 | if (w[9]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1041 | f[(w[0] + smod(w[1] + smod(w[3] - 128 + smod(w[5] - 64 + w[9] , 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1042 | if (w[10]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1043 | f[(w[0] + smod(w[1] - 256 + smod(w[2] + smod(w[6] - 64 + w[10], 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1044 | if (w[11]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1045 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] - 64 + w[11], 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1046 | if (w[12]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1047 | f[(w[0] + smod(w[1] - 256 + smod(w[2] - 128 + smod(w[4] + w[12], 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1048 | if (w[13]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1049 | f[(w[0] + smod(w[1] + smod(w[3] - 128 + smod(w[5] + w[13], 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1050 | if (w[14]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1051 | f[(w[0] + smod(w[1] - 256 + smod(w[2] + smod(w[6] + w[14], 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1052 | if (w[15]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1053 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] + w[15], 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1054 | if (w[16]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1055 | f[(w[0] + smod(w[1] - 256 + smod(w[2] - 128 + smod(w[4] - 64 + smod(w[8] - 32 + w[16], 63), 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1056 | if (w[17]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1057 | f[(w[0] + smod(w[1] + smod(w[3] - 128 + smod(w[5] - 64 + smod(w[9] - 32 + w[17], 63), 127), 255), 511)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1058 | |
| 1059 | return 0; |
| 1060 | } |
| 1061 | /* 10..101. */ |
| 1062 | if ((cd[0] & 0xce & mask) == 0x8a) { |
| 1063 | /* Range 256 format */ |
| 1064 | uint16_t w[22]; /* 1..21 */ |
| 1065 | struct gsm48_range_256 *r = (struct gsm48_range_256 *)cd; |
| 1066 | |
| 1067 | if (len < 4) |
| 1068 | return -EINVAL; |
| 1069 | memset(w, 0, sizeof(w)); |
| 1070 | w[0] = (r->orig_arfcn_hi << 9) | (r->orig_arfcn_mid << 1) | r->orig_arfcn_lo; |
| 1071 | w[1] = (r->w1_hi << 1) | r->w1_lo; |
| 1072 | if (len >= 4) |
| 1073 | w[2] = r->w2; |
| 1074 | if (len >= 5) |
| 1075 | w[3] = r->w3; |
| 1076 | if (len >= 6) |
| 1077 | w[4] = (r->w4_hi << 5) | r->w4_lo; |
| 1078 | if (len >= 7) |
| 1079 | w[5] = (r->w5_hi << 3) | r->w5_lo; |
| 1080 | if (len >= 8) |
| 1081 | w[6] = (r->w6_hi << 1) | r->w6_lo; |
| 1082 | if (len >= 8) |
| 1083 | w[7] = r->w7; |
| 1084 | if (len >= 9) |
| 1085 | w[8] = (r->w8_hi << 4) | r->w8_lo; |
| 1086 | if (len >= 10) |
| 1087 | w[9] = (r->w9_hi << 1) | r->w9_lo; |
| 1088 | if (len >= 10) |
| 1089 | w[10] = r->w10; |
| 1090 | if (len >= 11) |
| 1091 | w[11] = (r->w11_hi << 3) | r->w11_lo; |
| 1092 | if (len >= 11) |
| 1093 | w[12] = r->w12; |
| 1094 | if (len >= 12) |
| 1095 | w[13] = r->w13; |
| 1096 | if (len >= 13) |
Jacob Erlbeck | 85bc549 | 2014-01-13 14:21:23 +0100 | [diff] [blame] | 1097 | w[14] = (r->w14_hi << 2) | r->w14_lo; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1098 | if (len >= 13) |
Jacob Erlbeck | 85bc549 | 2014-01-13 14:21:23 +0100 | [diff] [blame] | 1099 | w[15] = r->w15; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1100 | if (len >= 14) |
| 1101 | w[16] = (r->w16_hi << 3) | r->w16_lo; |
| 1102 | if (len >= 14) |
| 1103 | w[17] = r->w17; |
| 1104 | if (len >= 15) |
Jacob Erlbeck | 85bc549 | 2014-01-13 14:21:23 +0100 | [diff] [blame] | 1105 | w[18] = (r->w18_hi << 3) | r->w18_lo; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1106 | if (len >= 15) |
Jacob Erlbeck | 85bc549 | 2014-01-13 14:21:23 +0100 | [diff] [blame] | 1107 | w[19] = r->w19; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1108 | if (len >= 16) |
| 1109 | w[20] = (r->w20_hi << 3) | r->w20_lo; |
| 1110 | if (len >= 16) |
| 1111 | w[21] = r->w21; |
| 1112 | f[w[0]].mask |= frqt; |
| 1113 | if (w[1]) |
| 1114 | f[(w[0] + w[1]) % 1024].mask |= frqt; |
| 1115 | if (w[2]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1116 | f[(w[0] + smod(w[1] - 128 + w[2], 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1117 | if (w[3]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1118 | f[(w[0] + smod(w[1] + w[3], 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1119 | if (w[4]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1120 | f[(w[0] + smod(w[1] - 128 + smod(w[2] - 64 + w[4], 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1121 | if (w[5]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1122 | f[(w[0] + smod(w[1] + smod(w[3] - 64 + w[5], 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1123 | if (w[6]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1124 | f[(w[0] + smod(w[1] - 128 + smod(w[2] + w[6], 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1125 | if (w[7]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1126 | f[(w[0] + smod(w[1] + smod(w[3] + w[7], 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1127 | if (w[8]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1128 | f[(w[0] + smod(w[1] - 128 + smod(w[2] - 64 + smod(w[4] - 32 + w[8] , 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1129 | if (w[9]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1130 | f[(w[0] + smod(w[1] + smod(w[3] - 64 + smod(w[5] - 32 + w[9] , 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1131 | if (w[10]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1132 | f[(w[0] + smod(w[1] - 128 + smod(w[2] + smod(w[6] - 32 + w[10], 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1133 | if (w[11]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1134 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] - 32 + w[11], 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1135 | if (w[12]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1136 | f[(w[0] + smod(w[1] - 128 + smod(w[2] - 64 + smod(w[4] + w[12], 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1137 | if (w[13]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1138 | f[(w[0] + smod(w[1] + smod(w[3] - 64 + smod(w[5] + w[13], 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1139 | if (w[14]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1140 | f[(w[0] + smod(w[1] - 128 + smod(w[2] + smod(w[6] + w[14], 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1141 | if (w[15]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1142 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] + w[15], 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1143 | if (w[16]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1144 | f[(w[0] + smod(w[1] - 128 + smod(w[2] - 64 + smod(w[4] - 32 + smod(w[8] - 16 + w[16], 31), 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1145 | if (w[17]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1146 | f[(w[0] + smod(w[1] + smod(w[3] - 64 + smod(w[5] - 32 + smod(w[9] - 16 + w[17], 31), 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1147 | if (w[18]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1148 | f[(w[0] + smod(w[1] - 128 + smod(w[2] + smod(w[6] - 32 + smod(w[10] - 16 + w[18], 31), 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1149 | if (w[19]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1150 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] - 32 + smod(w[11] - 16 + w[19], 31), 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1151 | if (w[20]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1152 | f[(w[0] + smod(w[1] - 128 + smod(w[2] - 64 + smod(w[4] + smod(w[12] - 16 + w[20], 31), 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1153 | if (w[21]) |
Sylvain Munaut | 71fd42f | 2011-09-01 22:05:29 +0200 | [diff] [blame] | 1154 | f[(w[0] + smod(w[1] + smod(w[3] - 64 + smod(w[5] + smod(w[13] - 16 + w[21], 31), 63), 127), 255)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | /* 10..110. */ |
| 1159 | if ((cd[0] & 0xce & mask) == 0x8c) { |
| 1160 | /* Range 128 format */ |
| 1161 | uint16_t w[29]; /* 1..28 */ |
| 1162 | struct gsm48_range_128 *r = (struct gsm48_range_128 *)cd; |
| 1163 | |
| 1164 | if (len < 3) |
| 1165 | return -EINVAL; |
| 1166 | memset(w, 0, sizeof(w)); |
| 1167 | w[0] = (r->orig_arfcn_hi << 9) | (r->orig_arfcn_mid << 1) | r->orig_arfcn_lo; |
| 1168 | w[1] = r->w1; |
| 1169 | if (len >= 4) |
| 1170 | w[2] = r->w2; |
| 1171 | if (len >= 5) |
| 1172 | w[3] = (r->w3_hi << 4) | r->w3_lo; |
| 1173 | if (len >= 6) |
| 1174 | w[4] = (r->w4_hi << 1) | r->w4_lo; |
| 1175 | if (len >= 6) |
| 1176 | w[5] = r->w5; |
| 1177 | if (len >= 7) |
| 1178 | w[6] = (r->w6_hi << 3) | r->w6_lo; |
| 1179 | if (len >= 7) |
| 1180 | w[7] = r->w7; |
| 1181 | if (len >= 8) |
| 1182 | w[8] = r->w8; |
| 1183 | if (len >= 8) |
| 1184 | w[9] = r->w9; |
| 1185 | if (len >= 9) |
| 1186 | w[10] = r->w10; |
| 1187 | if (len >= 9) |
| 1188 | w[11] = r->w11; |
| 1189 | if (len >= 10) |
| 1190 | w[12] = r->w12; |
| 1191 | if (len >= 10) |
| 1192 | w[13] = r->w13; |
| 1193 | if (len >= 11) |
| 1194 | w[14] = r->w14; |
| 1195 | if (len >= 11) |
| 1196 | w[15] = r->w15; |
| 1197 | if (len >= 12) |
| 1198 | w[16] = r->w16; |
| 1199 | if (len >= 12) |
| 1200 | w[17] = r->w17; |
| 1201 | if (len >= 13) |
| 1202 | w[18] = (r->w18_hi << 1) | r->w18_lo; |
| 1203 | if (len >= 13) |
| 1204 | w[19] = r->w19; |
| 1205 | if (len >= 13) |
| 1206 | w[20] = r->w20; |
| 1207 | if (len >= 14) |
| 1208 | w[21] = (r->w21_hi << 2) | r->w21_lo; |
| 1209 | if (len >= 14) |
| 1210 | w[22] = r->w22; |
| 1211 | if (len >= 14) |
| 1212 | w[23] = r->w23; |
| 1213 | if (len >= 15) |
| 1214 | w[24] = r->w24; |
| 1215 | if (len >= 15) |
| 1216 | w[25] = r->w25; |
| 1217 | if (len >= 16) |
| 1218 | w[26] = (r->w26_hi << 1) | r->w26_lo; |
| 1219 | if (len >= 16) |
| 1220 | w[27] = r->w27; |
| 1221 | if (len >= 16) |
| 1222 | w[28] = r->w28; |
| 1223 | f[w[0]].mask |= frqt; |
| 1224 | if (w[1]) |
| 1225 | f[(w[0] + w[1]) % 1024].mask |= frqt; |
| 1226 | if (w[2]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1227 | f[(w[0] + smod(w[1] - 64 + w[2], 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1228 | if (w[3]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1229 | f[(w[0] + smod(w[1] + w[3], 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1230 | if (w[4]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1231 | f[(w[0] + smod(w[1] - 64 + smod(w[2] - 32 + w[4], 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1232 | if (w[5]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1233 | f[(w[0] + smod(w[1] + smod(w[3] - 32 + w[5], 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1234 | if (w[6]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1235 | f[(w[0] + smod(w[1] - 64 + smod(w[2] + w[6], 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1236 | if (w[7]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1237 | f[(w[0] + smod(w[1] + smod(w[3] + w[7], 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1238 | if (w[8]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1239 | f[(w[0] + smod(w[1] - 64 + smod(w[2] - 32 + smod(w[4] - 16 + w[8] , 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1240 | if (w[9]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1241 | f[(w[0] + smod(w[1] + smod(w[3] - 32 + smod(w[5] - 16 + w[9] , 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1242 | if (w[10]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1243 | f[(w[0] + smod(w[1] - 64 + smod(w[2] + smod(w[6] - 16 + w[10], 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1244 | if (w[11]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1245 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] - 16 + w[11], 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1246 | if (w[12]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1247 | f[(w[0] + smod(w[1] - 64 + smod(w[2] - 32 + smod(w[4] + w[12], 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1248 | if (w[13]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1249 | f[(w[0] + smod(w[1] + smod(w[3] - 32 + smod(w[5] + w[13], 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1250 | if (w[14]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1251 | f[(w[0] + smod(w[1] - 64 + smod(w[2] + smod(w[6] + w[14], 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1252 | if (w[15]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1253 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] + w[15], 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1254 | if (w[16]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1255 | f[(w[0] + smod(w[1] - 64 + smod(w[2] - 32 + smod(w[4] - 16 + smod(w[8] - 8 + w[16], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1256 | if (w[17]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1257 | f[(w[0] + smod(w[1] + smod(w[3] - 32 + smod(w[5] - 16 + smod(w[9] - 8 + w[17], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1258 | if (w[18]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1259 | f[(w[0] + smod(w[1] - 64 + smod(w[2] + smod(w[6] - 16 + smod(w[10] - 8 + w[18], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1260 | if (w[19]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1261 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] - 16 + smod(w[11] - 8 + w[19], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1262 | if (w[20]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1263 | f[(w[0] + smod(w[1] - 64 + smod(w[2] - 32 + smod(w[4] + smod(w[12] - 8 + w[20], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1264 | if (w[21]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1265 | f[(w[0] + smod(w[1] + smod(w[3] - 32 + smod(w[5] + smod(w[13] - 8 + w[21], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1266 | if (w[22]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1267 | f[(w[0] + smod(w[1] - 64 + smod(w[2] + smod(w[6] + smod(w[14] - 8 + w[22], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1268 | if (w[23]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1269 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] + smod(w[15] - 8 + w[23], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1270 | if (w[24]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1271 | f[(w[0] + smod(w[1] - 64 + smod(w[2] - 32 + smod(w[4] - 16 + smod(w[8] + w[24], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1272 | if (w[25]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1273 | f[(w[0] + smod(w[1] + smod(w[3] - 32 + smod(w[5] - 16 + smod(w[9] + w[25], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1274 | if (w[26]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1275 | f[(w[0] + smod(w[1] - 64 + smod(w[2] + smod(w[6] - 16 + smod(w[10] + w[26], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1276 | if (w[27]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1277 | f[(w[0] + smod(w[1] + smod(w[3] + smod(w[7] - 16 + smod(w[11] + w[27], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1278 | if (w[28]) |
Andreas.Eversberg | eaac0cf | 2011-09-02 20:12:19 +0200 | [diff] [blame] | 1279 | f[(w[0] + smod(w[1] - 64 + smod(w[2] - 32 + smod(w[4] + smod(w[12] + w[28], 15), 31), 63), 127)) % 1024].mask |= frqt; |
Harald Welte | 1523d70 | 2010-08-04 11:46:44 +0200 | [diff] [blame] | 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | /* 10..111. */ |
| 1284 | if ((cd[0] & 0xce & mask) == 0x8e) { |
| 1285 | /* Variable bitmap format (can be any length >= 3) */ |
| 1286 | uint16_t orig = 0; |
| 1287 | struct gsm48_var_bit *r = (struct gsm48_var_bit *)cd; |
| 1288 | |
| 1289 | if (len < 3) |
| 1290 | return -EINVAL; |
| 1291 | orig = (r->orig_arfcn_hi << 9) | (r->orig_arfcn_mid << 1) | r->orig_arfcn_lo; |
| 1292 | f[orig].mask |= frqt; |
| 1293 | for (i = 1; 2 + (i >> 3) < len; i++) |
| 1294 | if ((cd[2 + (i >> 3)] & (0x80 >> (i & 7)))) |
| 1295 | f[(orig + i) % 1024].mask |= frqt; |
| 1296 | |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | return 0; |
| 1301 | } |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 1302 | /*! @} */ |