Harald Welte | b550313 | 2011-05-24 15:01:53 +0200 | [diff] [blame] | 1 | /* GSM 04.08 System Information (SI) encoding and decoding |
| 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
| 4 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <errno.h> |
| 24 | #include <string.h> |
| 25 | #include <stdio.h> |
Harald Welte | b550313 | 2011-05-24 15:01:53 +0200 | [diff] [blame] | 26 | |
| 27 | #include <osmocom/core/bitvec.h> |
| 28 | #include <osmocom/core/utils.h> |
| 29 | #include <osmocom/gsm/sysinfo.h> |
| 30 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 31 | #include <osmocom/gsm/protocol/gsm_08_58.h> |
| 32 | |
| 33 | /* verify the sizes of the system information type structs */ |
| 34 | |
| 35 | /* rest octets are not part of the struct */ |
| 36 | osmo_static_assert(sizeof(struct gsm48_system_information_type_header) == 3, _si_header_size); |
| 37 | osmo_static_assert(sizeof(struct gsm48_rach_control) == 3, _si_rach_control); |
| 38 | osmo_static_assert(sizeof(struct gsm48_system_information_type_1) == 22, _si1_size); |
| 39 | osmo_static_assert(sizeof(struct gsm48_system_information_type_2) == 23, _si2_size); |
| 40 | osmo_static_assert(sizeof(struct gsm48_system_information_type_3) == 19, _si3_size); |
| 41 | osmo_static_assert(sizeof(struct gsm48_system_information_type_4) == 13, _si4_size); |
| 42 | |
| 43 | /* bs11 forgot the l2 len, 0-6 rest octets */ |
| 44 | osmo_static_assert(sizeof(struct gsm48_system_information_type_5) == 18, _si5_size); |
| 45 | osmo_static_assert(sizeof(struct gsm48_system_information_type_6) == 11, _si6_size); |
| 46 | |
| 47 | osmo_static_assert(sizeof(struct gsm48_system_information_type_13) == 3, _si13_size); |
| 48 | |
| 49 | static const uint8_t sitype2rsl[_MAX_SYSINFO_TYPE] = { |
| 50 | [SYSINFO_TYPE_1] = RSL_SYSTEM_INFO_1, |
| 51 | [SYSINFO_TYPE_2] = RSL_SYSTEM_INFO_2, |
| 52 | [SYSINFO_TYPE_3] = RSL_SYSTEM_INFO_3, |
| 53 | [SYSINFO_TYPE_4] = RSL_SYSTEM_INFO_4, |
| 54 | [SYSINFO_TYPE_5] = RSL_SYSTEM_INFO_5, |
| 55 | [SYSINFO_TYPE_6] = RSL_SYSTEM_INFO_6, |
| 56 | [SYSINFO_TYPE_7] = RSL_SYSTEM_INFO_7, |
| 57 | [SYSINFO_TYPE_8] = RSL_SYSTEM_INFO_8, |
| 58 | [SYSINFO_TYPE_9] = RSL_SYSTEM_INFO_9, |
| 59 | [SYSINFO_TYPE_10] = RSL_SYSTEM_INFO_10, |
| 60 | [SYSINFO_TYPE_13] = RSL_SYSTEM_INFO_13, |
| 61 | [SYSINFO_TYPE_16] = RSL_SYSTEM_INFO_16, |
| 62 | [SYSINFO_TYPE_17] = RSL_SYSTEM_INFO_17, |
| 63 | [SYSINFO_TYPE_18] = RSL_SYSTEM_INFO_18, |
| 64 | [SYSINFO_TYPE_19] = RSL_SYSTEM_INFO_19, |
| 65 | [SYSINFO_TYPE_20] = RSL_SYSTEM_INFO_20, |
| 66 | [SYSINFO_TYPE_2bis] = RSL_SYSTEM_INFO_2bis, |
| 67 | [SYSINFO_TYPE_2ter] = RSL_SYSTEM_INFO_2ter, |
| 68 | [SYSINFO_TYPE_2quater] = RSL_SYSTEM_INFO_2quater, |
| 69 | [SYSINFO_TYPE_5bis] = RSL_SYSTEM_INFO_5bis, |
| 70 | [SYSINFO_TYPE_5ter] = RSL_SYSTEM_INFO_5ter, |
Harald Welte | 620f7ab | 2011-06-25 21:39:18 +0200 | [diff] [blame] | 71 | [SYSINFO_TYPE_EMO] = RSL_EXT_MEAS_ORDER, |
| 72 | [SYSINFO_TYPE_MEAS_INFO]= RSL_MEAS_INFO, |
Harald Welte | b550313 | 2011-05-24 15:01:53 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Sylvain Munaut | f269950 | 2011-05-29 15:39:04 +0200 | [diff] [blame] | 75 | static const uint8_t rsl2sitype[256] = { |
Harald Welte | b550313 | 2011-05-24 15:01:53 +0200 | [diff] [blame] | 76 | [RSL_SYSTEM_INFO_1] = SYSINFO_TYPE_1, |
| 77 | [RSL_SYSTEM_INFO_2] = SYSINFO_TYPE_2, |
| 78 | [RSL_SYSTEM_INFO_3] = SYSINFO_TYPE_3, |
| 79 | [RSL_SYSTEM_INFO_4] = SYSINFO_TYPE_4, |
| 80 | [RSL_SYSTEM_INFO_5] = SYSINFO_TYPE_5, |
| 81 | [RSL_SYSTEM_INFO_6] = SYSINFO_TYPE_6, |
| 82 | [RSL_SYSTEM_INFO_7] = SYSINFO_TYPE_7, |
| 83 | [RSL_SYSTEM_INFO_8] = SYSINFO_TYPE_8, |
| 84 | [RSL_SYSTEM_INFO_9] = SYSINFO_TYPE_9, |
| 85 | [RSL_SYSTEM_INFO_10] = SYSINFO_TYPE_10, |
| 86 | [RSL_SYSTEM_INFO_13] = SYSINFO_TYPE_13, |
| 87 | [RSL_SYSTEM_INFO_16] = SYSINFO_TYPE_16, |
| 88 | [RSL_SYSTEM_INFO_17] = SYSINFO_TYPE_17, |
| 89 | [RSL_SYSTEM_INFO_18] = SYSINFO_TYPE_18, |
| 90 | [RSL_SYSTEM_INFO_19] = SYSINFO_TYPE_19, |
| 91 | [RSL_SYSTEM_INFO_20] = SYSINFO_TYPE_20, |
| 92 | [RSL_SYSTEM_INFO_2bis] = SYSINFO_TYPE_2bis, |
| 93 | [RSL_SYSTEM_INFO_2ter] = SYSINFO_TYPE_2ter, |
| 94 | [RSL_SYSTEM_INFO_2quater] = SYSINFO_TYPE_2quater, |
| 95 | [RSL_SYSTEM_INFO_5bis] = SYSINFO_TYPE_5bis, |
| 96 | [RSL_SYSTEM_INFO_5ter] = SYSINFO_TYPE_5ter, |
Harald Welte | 620f7ab | 2011-06-25 21:39:18 +0200 | [diff] [blame] | 97 | [RSL_EXT_MEAS_ORDER] = SYSINFO_TYPE_EMO, |
| 98 | [RSL_MEAS_INFO] = SYSINFO_TYPE_MEAS_INFO, |
Harald Welte | b550313 | 2011-05-24 15:01:53 +0200 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | const struct value_string osmo_sitype_strs[_MAX_SYSINFO_TYPE] = { |
| 102 | { SYSINFO_TYPE_1, "1" }, |
| 103 | { SYSINFO_TYPE_2, "2" }, |
| 104 | { SYSINFO_TYPE_3, "3" }, |
| 105 | { SYSINFO_TYPE_4, "4" }, |
| 106 | { SYSINFO_TYPE_5, "5" }, |
| 107 | { SYSINFO_TYPE_6, "6" }, |
| 108 | { SYSINFO_TYPE_7, "7" }, |
| 109 | { SYSINFO_TYPE_8, "8" }, |
| 110 | { SYSINFO_TYPE_9, "9" }, |
| 111 | { SYSINFO_TYPE_10, "10" }, |
| 112 | { SYSINFO_TYPE_13, "13" }, |
| 113 | { SYSINFO_TYPE_16, "16" }, |
| 114 | { SYSINFO_TYPE_17, "17" }, |
| 115 | { SYSINFO_TYPE_18, "18" }, |
| 116 | { SYSINFO_TYPE_19, "19" }, |
| 117 | { SYSINFO_TYPE_20, "20" }, |
| 118 | { SYSINFO_TYPE_2bis, "2bis" }, |
| 119 | { SYSINFO_TYPE_2ter, "2ter" }, |
| 120 | { SYSINFO_TYPE_2quater, "2quater" }, |
| 121 | { SYSINFO_TYPE_5bis, "5bis" }, |
| 122 | { SYSINFO_TYPE_5ter, "5ter" }, |
Harald Welte | 620f7ab | 2011-06-25 21:39:18 +0200 | [diff] [blame] | 123 | { SYSINFO_TYPE_EMO, "EMO" }, |
| 124 | { SYSINFO_TYPE_MEAS_INFO, "MI" }, |
Harald Welte | b550313 | 2011-05-24 15:01:53 +0200 | [diff] [blame] | 125 | { 0, NULL } |
| 126 | }; |
| 127 | |
Max | 03309b5 | 2016-03-17 11:51:09 +0100 | [diff] [blame] | 128 | /*! \brief Add pair of arfcn and measurement bandwith value to earfcn struct |
| 129 | * \param[in,out] e earfcn struct |
| 130 | * \param[in] arfcn EARFCN value, 16 bits |
| 131 | * \param[in] meas_bw measurement bandwith value |
| 132 | * \returns 0 on success, error otherwise |
| 133 | */ |
Max | ea345cd | 2016-03-17 14:46:19 +0100 | [diff] [blame] | 134 | int osmo_earfcn_add(struct osmo_earfcn_si2q *e, uint16_t arfcn, uint8_t meas_bw) |
Max | 03309b5 | 2016-03-17 11:51:09 +0100 | [diff] [blame] | 135 | { |
| 136 | size_t i; |
| 137 | for (i = 0; i < e->length; i++) { |
| 138 | if (OSMO_EARFCN_INVALID == e->arfcn[i]) { |
| 139 | e->arfcn[i] = arfcn; |
| 140 | e->meas_bw[i] = meas_bw; |
| 141 | return 0; |
| 142 | } |
| 143 | } |
| 144 | return -ENOMEM; |
| 145 | } |
| 146 | |
Max | fbb8bfa | 2016-04-15 16:04:04 +0200 | [diff] [blame] | 147 | /*! \brief Return number of bits necessary to represent earfcn struct as |
| 148 | * Repeated E-UTRAN Neighbour Cells IE from 3GPP TS 44.018 Table 10.5.2.33b.1 |
| 149 | * \param[in,out] e earfcn struct |
| 150 | * \returns number of bits |
| 151 | */ |
| 152 | size_t osmo_earfcn_bit_size(const struct osmo_earfcn_si2q *e) |
| 153 | { |
| 154 | /* 1 stop bit + 5 bits for THRESH_E-UTRAN_high */ |
| 155 | size_t i, bits = 6; |
| 156 | for (i = 0; i < e->length; i++) { |
| 157 | if (e->arfcn[i] != OSMO_EARFCN_INVALID) { |
| 158 | bits += 17; |
| 159 | if (OSMO_EARFCN_MEAS_INVALID == e->meas_bw[i]) |
| 160 | bits++; |
| 161 | else |
| 162 | bits += 4; |
| 163 | } |
| 164 | } |
| 165 | bits += (e->prio_valid) ? 4 : 1; |
| 166 | bits += (e->thresh_lo_valid) ? 6 : 1; |
| 167 | bits += (e->qrxlm_valid) ? 6 : 1; |
| 168 | return bits; |
| 169 | } |
| 170 | |
Max | 03309b5 | 2016-03-17 11:51:09 +0100 | [diff] [blame] | 171 | /*! \brief Delete arfcn (and corresponding measurement bandwith) from earfcn |
| 172 | * struct |
| 173 | * \param[in,out] e earfcn struct |
| 174 | * \param[in] arfcn EARFCN value, 16 bits |
| 175 | * \returns 0 on success, error otherwise |
| 176 | */ |
Max | ea345cd | 2016-03-17 14:46:19 +0100 | [diff] [blame] | 177 | int osmo_earfcn_del(struct osmo_earfcn_si2q *e, uint16_t arfcn) |
Max | 03309b5 | 2016-03-17 11:51:09 +0100 | [diff] [blame] | 178 | { |
| 179 | size_t i; |
| 180 | for (i = 0; i < e->length; i++) { |
| 181 | if (arfcn == e->arfcn[i]) { |
| 182 | e->arfcn[i] = OSMO_EARFCN_INVALID; |
| 183 | e->meas_bw[i] = OSMO_EARFCN_MEAS_INVALID; |
| 184 | return 0; |
| 185 | } |
| 186 | } |
| 187 | return -ENOENT; |
| 188 | } |
| 189 | |
| 190 | /*! \brief Initialize earfcn struct |
| 191 | * \param[in,out] e earfcn struct |
| 192 | */ |
Max | ea345cd | 2016-03-17 14:46:19 +0100 | [diff] [blame] | 193 | void osmo_earfcn_init(struct osmo_earfcn_si2q *e) |
Max | 03309b5 | 2016-03-17 11:51:09 +0100 | [diff] [blame] | 194 | { |
| 195 | size_t i; |
| 196 | for (i = 0; i < e->length; i++) { |
| 197 | e->arfcn[i] = OSMO_EARFCN_INVALID; |
| 198 | e->meas_bw[i] = OSMO_EARFCN_MEAS_INVALID; |
| 199 | } |
| 200 | } |
| 201 | |
Harald Welte | b550313 | 2011-05-24 15:01:53 +0200 | [diff] [blame] | 202 | uint8_t osmo_sitype2rsl(enum osmo_sysinfo_type si_type) |
| 203 | { |
| 204 | return sitype2rsl[si_type]; |
| 205 | } |
| 206 | |
| 207 | enum osmo_sysinfo_type osmo_rsl2sitype(uint8_t rsl_si) |
| 208 | { |
| 209 | return rsl2sitype[rsl_si]; |
| 210 | } |