blob: 201acfc81c1365d50779d8a5b180a01b831e6662 [file] [log] [blame]
Harald Welteb5503132011-05-24 15:01:53 +02001/* 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 Welteb5503132011-05-24 15:01:53 +020026
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 */
36osmo_static_assert(sizeof(struct gsm48_system_information_type_header) == 3, _si_header_size);
37osmo_static_assert(sizeof(struct gsm48_rach_control) == 3, _si_rach_control);
38osmo_static_assert(sizeof(struct gsm48_system_information_type_1) == 22, _si1_size);
39osmo_static_assert(sizeof(struct gsm48_system_information_type_2) == 23, _si2_size);
40osmo_static_assert(sizeof(struct gsm48_system_information_type_3) == 19, _si3_size);
41osmo_static_assert(sizeof(struct gsm48_system_information_type_4) == 13, _si4_size);
42
43/* bs11 forgot the l2 len, 0-6 rest octets */
44osmo_static_assert(sizeof(struct gsm48_system_information_type_5) == 18, _si5_size);
45osmo_static_assert(sizeof(struct gsm48_system_information_type_6) == 11, _si6_size);
46
47osmo_static_assert(sizeof(struct gsm48_system_information_type_13) == 3, _si13_size);
48
49static 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 Welte620f7ab2011-06-25 21:39:18 +020071 [SYSINFO_TYPE_EMO] = RSL_EXT_MEAS_ORDER,
72 [SYSINFO_TYPE_MEAS_INFO]= RSL_MEAS_INFO,
Harald Welteb5503132011-05-24 15:01:53 +020073};
74
Sylvain Munautf2699502011-05-29 15:39:04 +020075static const uint8_t rsl2sitype[256] = {
Harald Welteb5503132011-05-24 15:01:53 +020076 [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 Welte620f7ab2011-06-25 21:39:18 +020097 [RSL_EXT_MEAS_ORDER] = SYSINFO_TYPE_EMO,
98 [RSL_MEAS_INFO] = SYSINFO_TYPE_MEAS_INFO,
Harald Welteb5503132011-05-24 15:01:53 +020099};
100
101const 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 Welte620f7ab2011-06-25 21:39:18 +0200123 { SYSINFO_TYPE_EMO, "EMO" },
124 { SYSINFO_TYPE_MEAS_INFO, "MI" },
Harald Welteb5503132011-05-24 15:01:53 +0200125 { 0, NULL }
126};
127
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200128/*! Add pair of arfcn and measurement bandwith value to earfcn struct
Max03309b52016-03-17 11:51:09 +0100129 * \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 */
Maxea345cd2016-03-17 14:46:19 +0100134int osmo_earfcn_add(struct osmo_earfcn_si2q *e, uint16_t arfcn, uint8_t meas_bw)
Max03309b52016-03-17 11:51:09 +0100135{
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
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200147/*! Return number of bits necessary to represent earfcn struct as
Maxfbb8bfa2016-04-15 16:04:04 +0200148 * 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 */
152size_t osmo_earfcn_bit_size(const struct osmo_earfcn_si2q *e)
153{
Max91dd2192017-05-11 15:38:10 +0200154 return osmo_earfcn_bit_size_ext(e, 0);
155}
156
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200157/*! Return number of bits necessary to represent earfcn struct as
Max91dd2192017-05-11 15:38:10 +0200158 * Repeated E-UTRAN Neighbour Cells IE from 3GPP TS 44.018 Table 10.5.2.33b.1
159 * \param[in,out] e earfcn struct
160 * \param[in] offset into earfcn struct: how many EARFCNs to skip while estimating size
161 * \returns number of bits
162 */
163size_t osmo_earfcn_bit_size_ext(const struct osmo_earfcn_si2q *e, size_t offset)
164{
Maxfbb8bfa2016-04-15 16:04:04 +0200165 /* 1 stop bit + 5 bits for THRESH_E-UTRAN_high */
Max91dd2192017-05-11 15:38:10 +0200166 size_t i, bits = 6, skip = 0;
Maxfbb8bfa2016-04-15 16:04:04 +0200167 for (i = 0; i < e->length; i++) {
168 if (e->arfcn[i] != OSMO_EARFCN_INVALID) {
Max91dd2192017-05-11 15:38:10 +0200169 if (skip < offset)
170 skip++;
171 else {
172 bits += 17;
173 if (OSMO_EARFCN_MEAS_INVALID == e->meas_bw[i])
174 bits++;
175 else
176 bits += 4;
177 }
Maxfbb8bfa2016-04-15 16:04:04 +0200178 }
179 }
180 bits += (e->prio_valid) ? 4 : 1;
181 bits += (e->thresh_lo_valid) ? 6 : 1;
182 bits += (e->qrxlm_valid) ? 6 : 1;
183 return bits;
184}
185
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200186/*! Delete arfcn (and corresponding measurement bandwith) from earfcn
Max03309b52016-03-17 11:51:09 +0100187 * struct
188 * \param[in,out] e earfcn struct
189 * \param[in] arfcn EARFCN value, 16 bits
190 * \returns 0 on success, error otherwise
191 */
Maxea345cd2016-03-17 14:46:19 +0100192int osmo_earfcn_del(struct osmo_earfcn_si2q *e, uint16_t arfcn)
Max03309b52016-03-17 11:51:09 +0100193{
194 size_t i;
195 for (i = 0; i < e->length; i++) {
196 if (arfcn == e->arfcn[i]) {
197 e->arfcn[i] = OSMO_EARFCN_INVALID;
198 e->meas_bw[i] = OSMO_EARFCN_MEAS_INVALID;
199 return 0;
200 }
201 }
202 return -ENOENT;
203}
204
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200205/*! Initialize earfcn struct
Max03309b52016-03-17 11:51:09 +0100206 * \param[in,out] e earfcn struct
207 */
Maxea345cd2016-03-17 14:46:19 +0100208void osmo_earfcn_init(struct osmo_earfcn_si2q *e)
Max03309b52016-03-17 11:51:09 +0100209{
210 size_t i;
211 for (i = 0; i < e->length; i++) {
212 e->arfcn[i] = OSMO_EARFCN_INVALID;
213 e->meas_bw[i] = OSMO_EARFCN_MEAS_INVALID;
214 }
215}
216
Harald Welteb5503132011-05-24 15:01:53 +0200217uint8_t osmo_sitype2rsl(enum osmo_sysinfo_type si_type)
218{
219 return sitype2rsl[si_type];
220}
221
222enum osmo_sysinfo_type osmo_rsl2sitype(uint8_t rsl_si)
223{
224 return rsl2sitype[rsl_si];
225}