aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2021-04-14 23:45:01 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2021-06-01 20:00:51 +0200
commit829c8e505216210502571a79fe371cf49d805d7b (patch)
tree0b9397ddd1e3b5a9ea2e3dfe2d54487a9e1de6b3
parent858a0211a018386a54ea01dc4b34159bd527c8c5 (diff)
Drop duplicated arfcn_range_encode.c available in libosmocore
This code is available in libosmocore since ~3 years ago (fdf8b7b1beeb0cda262c5fb060a933aa7edb5e9a). Let's use it instead of maintaining duplicated code which diverges over time. Depends: osmo-bsc.git Iae058c35506bc25c9f4790889b89ac46aea664b6 (contains cherry-pick of bug fixed in osmo-bsc.git). Change-Id: I53ad3067623077b6a8737c2a0aecc8b46bf71a15
-rw-r--r--include/osmocom/bsc/Makefile.am1
-rw-r--r--include/osmocom/bsc/arfcn_range_encode.h26
-rw-r--r--include/osmocom/bsc/system_information.h4
-rw-r--r--src/osmo-bsc/Makefile.am1
-rw-r--r--src/osmo-bsc/arfcn_range_encode.c340
-rw-r--r--src/osmo-bsc/system_information.c32
-rw-r--r--tests/bsc/Makefile.am1
-rw-r--r--tests/gsm0408/Makefile.am1
-rw-r--r--tests/gsm0408/gsm0408_test.c338
-rw-r--r--tests/gsm0408/gsm0408_test.ok56
-rw-r--r--tests/handover/Makefile.am1
11 files changed, 18 insertions, 783 deletions
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 7ca99fa9a..be27dae30 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -4,7 +4,6 @@ noinst_HEADERS = \
abis_om2000.h \
abis_rsl.h \
acc.h \
- arfcn_range_encode.h \
assignment_fsm.h \
bsc_rll.h \
bsc_subscriber.h \
diff --git a/include/osmocom/bsc/arfcn_range_encode.h b/include/osmocom/bsc/arfcn_range_encode.h
deleted file mode 100644
index 7ec710c33..000000000
--- a/include/osmocom/bsc/arfcn_range_encode.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef ARFCN_RANGE_ENCODE_H
-#define ARFCN_RANGE_ENCODE_H
-
-#include <stdint.h>
-
-enum gsm48_range {
- ARFCN_RANGE_INVALID = -1,
- ARFCN_RANGE_128 = 127,
- ARFCN_RANGE_256 = 255,
- ARFCN_RANGE_512 = 511,
- ARFCN_RANGE_1024 = 1023,
-};
-
-#define RANGE_ENC_MAX_ARFCNS 29
-
-int range_enc_determine_range(const int *arfcns, int size, int *f0_out);
-int range_enc_arfcns(enum gsm48_range rng, const int *arfcns, int sze, int *out, int idx);
-int range_enc_find_index(enum gsm48_range rng, const int *arfcns, int size);
-int range_enc_filter_arfcns(int *arfcns, const int sze, const int f0, int *f0_included);
-
-int range_enc_range128(uint8_t *chan_list, int f0, int *w);
-int range_enc_range256(uint8_t *chan_list, int f0, int *w);
-int range_enc_range512(uint8_t *chan_list, int f0, int *w);
-int range_enc_range1024(uint8_t *chan_list, int f0, int f0_incl, int *w);
-
-#endif
diff --git a/include/osmocom/bsc/system_information.h b/include/osmocom/bsc/system_information.h
index e86a3493c..08d34f8bf 100644
--- a/include/osmocom/bsc/system_information.h
+++ b/include/osmocom/bsc/system_information.h
@@ -3,7 +3,7 @@
#include <osmocom/gsm/sysinfo.h>
-#include <osmocom/bsc/arfcn_range_encode.h>
+#include <osmocom/gsm/gsm48_arfcn_range_encode.h>
struct gsm_bts;
@@ -13,7 +13,7 @@ int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type type);
size_t si2q_earfcn_count(const struct osmo_earfcn_si2q *e);
unsigned range1024_p(unsigned n);
unsigned range512_q(unsigned m);
-int range_encode(enum gsm48_range r, int *arfcns, int arfcns_used, int *w,
+int range_encode(enum osmo_gsm48_range r, int *arfcns, int arfcns_used, int *w,
int f0, uint8_t *chan_list);
uint8_t si2q_num(struct gsm_bts *bts);
int bts_earfcn_add(struct gsm_bts *bts, uint16_t earfcn, uint8_t thresh_hi, uint8_t thresh_lo, uint8_t prio,
diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am
index ca398255f..f91c6bfec 100644
--- a/src/osmo-bsc/Makefile.am
+++ b/src/osmo-bsc/Makefile.am
@@ -33,7 +33,6 @@ osmo_bsc_SOURCES = \
abis_om2000_vty.c \
abis_rsl.c \
acc.c \
- arfcn_range_encode.c \
assignment_fsm.c \
bsc_ctrl_commands.c \
bsc_ctrl_lookup.c \
diff --git a/src/osmo-bsc/arfcn_range_encode.c b/src/osmo-bsc/arfcn_range_encode.c
deleted file mode 100644
index 54d98a967..000000000
--- a/src/osmo-bsc/arfcn_range_encode.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/* gsm 04.08 system information (si) encoding and decoding
- * 3gpp ts 04.08 version 7.21.0 release 1998 / etsi ts 100 940 v7.21.0 */
-
-/*
- * (C) 2012 Holger Hans Peter Freyther
- * (C) 2012 by On-Waves
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <osmocom/bsc/arfcn_range_encode.h>
-#include <osmocom/bsc/debug.h>
-
-#include <osmocom/gsm/protocol/gsm_04_08.h>
-
-#include <osmocom/core/utils.h>
-
-#include <errno.h>
-
-static inline int greatest_power_of_2_lesser_or_equal_to(int index)
-{
- int power_of_2 = 1;
-
- do {
- power_of_2 *= 2;
- } while (power_of_2 <= index);
-
- /* now go back one step */
- return power_of_2 / 2;
-}
-
-static inline int mod(int data, int range)
-{
- int res = data % range;
- while (res < 0)
- res += range;
- return res;
-}
-
-/**
- * Determine at which index to split the ARFCNs to create an
- * equally size partition for the given range. Return -1 if
- * no such partition exists.
- */
-int range_enc_find_index(enum gsm48_range range, const int *freqs, const int size)
-{
- int i, j, n;
-
- const int RANGE_DELTA = (range - 1) / 2;
-
- for (i = 0; i < size; ++i) {
- n = 0;
- for (j = 0; j < size; ++j) {
- if (mod(freqs[j] - freqs[i], range) <= RANGE_DELTA)
- n += 1;
- }
-
- if (n - 1 == (size - 1) / 2)
- return i;
- }
-
- return -1;
-}
-
-/* Worker for range_enc_arfcns(), do not call directly. */
-int _range_enc_arfcns(enum gsm48_range range,
- const int *arfcns, int size, int *out,
- const int index)
-{
- int split_at;
- int i;
-
- /*
- * The below is a GNU extension and we can remove it when
- * we move to a quicksort like in-situ swap with the pivot.
- */
- int arfcns_left[size / 2];
- int arfcns_right[size / 2];
- int l_size;
- int r_size;
- int l_origin;
- int r_origin;
-
- /* Now do the processing */
- split_at = range_enc_find_index(range, arfcns, size);
- if (split_at < 0)
- return -EINVAL;
-
- /* we now know where to split */
- out[index] = 1 + arfcns[split_at];
-
- /* calculate the work that needs to be done for the leafs */
- l_origin = mod(arfcns[split_at] + ((range - 1) / 2) + 1, range);
- r_origin = mod(arfcns[split_at] + 1, range);
- for (i = 0, l_size = 0, r_size = 0; i < size; ++i) {
- if (mod(arfcns[i] - l_origin, range) < range / 2)
- arfcns_left[l_size++] = mod(arfcns[i] - l_origin, range);
- if (mod(arfcns[i] - r_origin, range) < range / 2)
- arfcns_right[r_size++] = mod(arfcns[i] - r_origin, range);
- }
-
- /*
- * Now recurse and we need to make this iterative... but as the
- * tree is balanced the stack will not be too deep.
- */
- if (l_size)
- range_enc_arfcns(range / 2, arfcns_left, l_size,
- out, index + greatest_power_of_2_lesser_or_equal_to(index + 1));
- if (r_size)
- range_enc_arfcns((range - 1) / 2, arfcns_right, r_size,
- out, index + (2 * greatest_power_of_2_lesser_or_equal_to(index + 1)));
- return 0;
-}
-
-/**
- * Range encode the ARFCN list.
- * \param range The range to use.
- * \param arfcns The list of ARFCNs
- * \param size The size of the list of ARFCNs
- * \param out Place to store the W(i) output.
- */
-int range_enc_arfcns(enum gsm48_range range,
- const int *arfcns, int size, int *out,
- const int index)
-{
- if (size <= 0)
- return 0;
-
- if (size == 1) {
- out[index] = 1 + arfcns[0];
- return 0;
- }
-
- return _range_enc_arfcns(range, arfcns, size, out, index);
-}
-
-/*
- * The easiest is to use f0 == arfcns[0]. This means that under certain
- * circumstances we can encode less ARFCNs than possible with an optimal f0.
- *
- * TODO: Solve the optimisation problem and pick f0 so that the max distance
- * is the smallest. Taking into account the modulo operation. I think picking
- * size/2 will be the optimal arfcn.
- */
-/**
- * This implements the range determination as described in GSM 04.08 J4. The
- * result will be a base frequency f0 and the range to use. Note that for range
- * 1024 encoding f0 always refers to ARFCN 0 even if it is not an element of
- * the arfcns list.
- *
- * \param[in] arfcns The input frequencies, they must be sorted, lowest number first
- * \param[in] size The length of the array
- * \param[out] f0 The selected F0 base frequency. It might not be inside the list
- */
-int range_enc_determine_range(const int *arfcns, const int size, int *f0)
-{
- int max = 0;
-
- /* don't dereference arfcns[] array if size is 0 */
- if (size == 0)
- return ARFCN_RANGE_128;
-
- /*
- * Go for the easiest. And pick arfcns[0] == f0.
- */
- max = arfcns[size - 1] - arfcns[0];
- *f0 = arfcns[0];
-
- if (max < 128 && size <= 29)
- return ARFCN_RANGE_128;
- if (max < 256 && size <= 22)
- return ARFCN_RANGE_256;
- if (max < 512 && size <= 18)
- return ARFCN_RANGE_512;
- if (max < 1024 && size <= 17) {
- *f0 = 0;
- return ARFCN_RANGE_1024;
- }
-
- return ARFCN_RANGE_INVALID;
-}
-
-static void write_orig_arfcn(uint8_t *chan_list, int f0)
-{
- chan_list[0] |= (f0 >> 9) & 1;
- chan_list[1] = (f0 >> 1);
- chan_list[2] = (f0 & 1) << 7;
-}
-
-static void write_all_wn(uint8_t *chan_list, int bit_offs,
- int *w, int w_size, int w1_len)
-{
- int octet_offs = 0; /* offset into chan_list */
- int wk_len = w1_len; /* encoding size in bits of w[k] */
- int k; /* 1 based */
- int level = 0; /* tree level, top level = 0 */
- int lvl_left = 1; /* nodes per tree level */
-
- /* W(2^i) to W(2^(i+1)-1) are on w1_len-i bits when present */
-
- for (k = 1; k <= w_size; k++) {
- int wk_left = wk_len;
- DEBUGP(DRR,
- "k=%d, wk_len=%d, offs=%d:%d, level=%d, "
- "lvl_left=%d\n",
- k, wk_len, octet_offs, bit_offs, level, lvl_left);
-
- while (wk_left > 0) {
- int cur_bits = 8 - bit_offs;
- int cur_mask;
- int wk_slice;
-
- if (cur_bits > wk_left)
- cur_bits = wk_left;
-
- cur_mask = ((1 << cur_bits) - 1);
-
- DEBUGP(DRR,
- " wk_left=%d, cur_bits=%d, offs=%d:%d\n",
- wk_left, cur_bits, octet_offs, bit_offs);
-
- /* advance */
- wk_left -= cur_bits;
- bit_offs += cur_bits;
-
- /* right aligned wk data for current out octet */
- wk_slice = (w[k-1] >> wk_left) & cur_mask;
-
- /* cur_bits now contains the number of bits
- * that are to be copied from wk to the chan_list.
- * wk_left is set to the number of bits that must
- * not yet be copied.
- * bit_offs points after the bit area that is going to
- * be overwritten:
- *
- * wk_left
- * |
- * v
- * wk: WWWWWWWWWWW
- * |||||<-- wk_slice, cur_bits=5
- * --WWWWW-
- * ^
- * |
- * bit_offs
- */
-
- DEBUGP(DRR,
- " wk=%02x, slice=%02x/%02x, cl=%02x\n",
- w[k-1], wk_slice, cur_mask, wk_slice << (8 - bit_offs));
-
- chan_list[octet_offs] &= ~(cur_mask << (8 - bit_offs));
- chan_list[octet_offs] |= wk_slice << (8 - bit_offs);
-
- /* adjust output */
- if (bit_offs == 8) {
- bit_offs = 0;
- octet_offs += 1;
- }
- }
-
- /* adjust bit sizes */
- lvl_left -= 1;
- if (!lvl_left) {
- /* completed tree level, advance to next */
- level += 1;
- lvl_left = 1 << level;
- wk_len -= 1;
- }
- }
-}
-
-int range_enc_range128(uint8_t *chan_list, int f0, int *w)
-{
- chan_list[0] = 0x8C;
- write_orig_arfcn(chan_list, f0);
-
- write_all_wn(&chan_list[2], 1, w, 28, 7);
- return 0;
-}
-
-int range_enc_range256(uint8_t *chan_list, int f0, int *w)
-{
- chan_list[0] = 0x8A;
- write_orig_arfcn(chan_list, f0);
-
- write_all_wn(&chan_list[2], 1, w, 21, 8);
- return 0;
-}
-
-int range_enc_range512(uint8_t *chan_list, int f0, int *w)
-{
- chan_list[0] = 0x88;
- write_orig_arfcn(chan_list, f0);
-
- write_all_wn(&chan_list[2], 1, w, 17, 9);
- return 0;
-}
-
-int range_enc_range1024(uint8_t *chan_list, int f0, int f0_included, int *w)
-{
- chan_list[0] = 0x80 | (f0_included << 2);
-
- write_all_wn(&chan_list[0], 6, w, 16, 10);
- return 0;
-}
-
-int range_enc_filter_arfcns(int *arfcns,
- const int size, const int f0, int *f0_included)
-{
- int i, j = 0;
- *f0_included = 0;
-
- for (i = 0; i < size; ++i) {
- /*
- * Appendix J.4 says the following:
- * All frequencies except F(0), minus F(0) + 1.
- * I assume we need to exclude it here.
- */
- if (arfcns[i] == f0) {
- *f0_included = 1;
- continue;
- }
-
- arfcns[j++] = mod(arfcns[i] - (f0 + 1), 1024);
- }
-
- return j;
-}
diff --git a/src/osmo-bsc/system_information.c b/src/osmo-bsc/system_information.c
index eddc650e0..21cbcae8f 100644
--- a/src/osmo-bsc/system_information.c
+++ b/src/osmo-bsc/system_information.c
@@ -33,11 +33,11 @@
#include <osmocom/gsm/gsm48_ie.h>
#include <osmocom/gsm/gsm48_rest_octets.h>
#include <osmocom/gsm/gsm48.h>
+#include <osmocom/gsm/gsm48_arfcn_range_encode.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/abis_rsl.h>
-#include <osmocom/bsc/arfcn_range_encode.h>
#include <osmocom/bsc/gsm_04_08_rr.h>
#include <osmocom/bsc/acc.h>
#include <osmocom/bsc/neighbor_ident.h>
@@ -431,7 +431,7 @@ static inline int enc_freq_lst_var_bitmap(uint8_t *chan_list,
return 0;
}
-int range_encode(enum gsm48_range r, int *arfcns, int arfcns_used, int *w,
+int range_encode(enum osmo_gsm48_range r, int *arfcns, int arfcns_used, int *w,
int f0, uint8_t *chan_list)
{
/*
@@ -440,22 +440,22 @@ int range_encode(enum gsm48_range r, int *arfcns, int arfcns_used, int *w,
*/
int rc, f0_included;
- range_enc_filter_arfcns(arfcns, arfcns_used, f0, &f0_included);
+ osmo_gsm48_range_enc_filter_arfcns(arfcns, arfcns_used, f0, &f0_included);
- rc = range_enc_arfcns(r, arfcns, arfcns_used, w, 0);
+ rc = osmo_gsm48_range_enc_arfcns(r, arfcns, arfcns_used, w, 0);
if (rc < 0)
return rc;
/* Select the range and the amount of bits needed */
switch (r) {
- case ARFCN_RANGE_128:
- return range_enc_range128(chan_list, f0, w);
- case ARFCN_RANGE_256:
- return range_enc_range256(chan_list, f0, w);
- case ARFCN_RANGE_512:
- return range_enc_range512(chan_list, f0, w);
- case ARFCN_RANGE_1024:
- return range_enc_range1024(chan_list, f0, f0_included, w);
+ case OSMO_GSM48_ARFCN_RANGE_128:
+ return osmo_gsm48_range_enc_128(chan_list, f0, w);
+ case OSMO_GSM48_ARFCN_RANGE_256:
+ return osmo_gsm48_range_enc_256(chan_list, f0, w);
+ case OSMO_GSM48_ARFCN_RANGE_512:
+ return osmo_gsm48_range_enc_512(chan_list, f0, w);
+ case OSMO_GSM48_ARFCN_RANGE_1024:
+ return osmo_gsm48_range_enc_1024(chan_list, f0, f0_included, w);
default:
return -ERANGE;
};
@@ -468,8 +468,8 @@ static inline int enc_freq_lst_range(uint8_t *chan_list,
const struct bitvec *bv, const struct gsm_bts *bts,
bool bis, bool ter, bool pgsm)
{
- int arfcns[RANGE_ENC_MAX_ARFCNS];
- int w[RANGE_ENC_MAX_ARFCNS];
+ int arfcns[OSMO_GSM48_RANGE_ENC_MAX_ARFCNS];
+ int w[OSMO_GSM48_RANGE_ENC_MAX_ARFCNS];
int arfcns_used = 0;
int i, range, f0;
@@ -488,8 +488,8 @@ static inline int enc_freq_lst_range(uint8_t *chan_list,
/*
* Check if the given list of ARFCNs can be encoded.
*/
- range = range_enc_determine_range(arfcns, arfcns_used, &f0);
- if (range == ARFCN_RANGE_INVALID)
+ range = osmo_gsm48_range_enc_determine_range(arfcns, arfcns_used, &f0);
+ if (range == OSMO_GSM48_ARFCN_RANGE_INVALID)
return -2;
memset(w, 0, sizeof(w));
diff --git a/tests/bsc/Makefile.am b/tests/bsc/Makefile.am
index 2cc57a448..d08ca1808 100644
--- a/tests/bsc/Makefile.am
+++ b/tests/bsc/Makefile.am
@@ -36,7 +36,6 @@ bsc_test_SOURCES = \
bsc_test_LDADD = \
$(top_builddir)/src/osmo-bsc/abis_nm.o \
$(top_builddir)/src/osmo-bsc/acc.o \
- $(top_builddir)/src/osmo-bsc/arfcn_range_encode.o \
$(top_builddir)/src/osmo-bsc/osmo_bsc_filter.o \
$(top_builddir)/src/osmo-bsc/bsc_subscriber.o \
$(top_builddir)/src/osmo-bsc/bts.o \
diff --git a/tests/gsm0408/Makefile.am b/tests/gsm0408/Makefile.am
index 571e7e67f..271a0fd34 100644
--- a/tests/gsm0408/Makefile.am
+++ b/tests/gsm0408/Makefile.am
@@ -27,7 +27,6 @@ gsm0408_test_LDADD = \
$(top_builddir)/src/osmo-bsc/abis_nm.o \
$(top_builddir)/src/osmo-bsc/acc.o \
$(top_builddir)/src/osmo-bsc/gsm_04_08_rr.o \
- $(top_builddir)/src/osmo-bsc/arfcn_range_encode.o \
$(top_builddir)/src/osmo-bsc/bts.o \
$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts_omlattr.o \
$(top_builddir)/src/osmo-bsc/bts_sm.o \
diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index 7c92c3613..4255ab26e 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -26,7 +26,6 @@
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/debug.h>
-#include <osmocom/bsc/arfcn_range_encode.h>
#include <osmocom/bsc/system_information.h>
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/bts.h>
@@ -274,338 +273,6 @@ static inline void test_si2q_long(struct gsm_network *net)
bts_del(bts);
}
-struct {
- int range;
- int arfcns_num;
- int arfcns[RANGE_ENC_MAX_ARFCNS];
-} arfcn_test_ranges[] = {
- {ARFCN_RANGE_512, 12,
- { 1, 12, 31, 51, 57, 91, 97, 98, 113, 117, 120, 125 }},
- {ARFCN_RANGE_512, 17,
- { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }},
- {ARFCN_RANGE_512, 18,
- { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }},
- {ARFCN_RANGE_512, 18,
- { 1, 17, 31, 45, 58, 79, 81, 97,
- 113, 127, 213, 277, 287, 311, 331, 391,
- 417, 511 }},
- {ARFCN_RANGE_512, 6,
- { 1, 17, 31, 45, 58, 79 }},
- {ARFCN_RANGE_512, 6,
- { 10, 17, 31, 45, 58, 79 }},
- {ARFCN_RANGE_1024, 17,
- { 0, 17, 31, 45, 58, 79, 81, 97,
- 113, 127, 213, 277, 287, 311, 331, 391,
- 1023 }},
- {ARFCN_RANGE_1024, 16,
- { 17, 31, 45, 58, 79, 81, 97, 113,
- 127, 213, 277, 287, 311, 331, 391, 1023 }},
- {-1}
-};
-
-static int test_single_range_encoding(int range, const int *orig_arfcns,
- int arfcns_num, int silent)
-{
- int arfcns[RANGE_ENC_MAX_ARFCNS];
- int w[RANGE_ENC_MAX_ARFCNS];
- int f0_included = 0;
- int rc, f0;
- uint8_t chan_list[16] = {0};
- struct gsm_sysinfo_freq dec_freq[1024] = {{0}};
- int dec_arfcns[RANGE_ENC_MAX_ARFCNS] = {0};
- int dec_arfcns_count = 0;
- int arfcns_used = 0;
- int i;
-
- arfcns_used = arfcns_num;
- memmove(arfcns, orig_arfcns, sizeof(arfcns));
-
- f0 = range == ARFCN_RANGE_1024 ? 0 : arfcns[0];
- /*
- * Manipulate the ARFCN list according to the rules in J4 depending
- * on the selected range.
- */
- arfcns_used = range_enc_filter_arfcns(arfcns, arfcns_used,
- f0, &f0_included);
-
- memset(w, 0, sizeof(w));
- range_enc_arfcns(range, arfcns, arfcns_used, w, 0);
-
- if (!silent)
- fprintf(stderr, "range=%d, arfcns_used=%d, f0=%d, f0_included=%d\n",
- range, arfcns_used, f0, f0_included);
-
- /* Select the range and the amount of bits needed */
- switch (range) {
- case ARFCN_RANGE_128:
- range_enc_range128(chan_list, f0, w);
- break;
- case ARFCN_RANGE_256:
- range_enc_range256(chan_list, f0, w);
- break;
- case ARFCN_RANGE_512:
- range_enc_range512(chan_list, f0, w);
- break;
- case ARFCN_RANGE_1024:
- range_enc_range1024(chan_list, f0, f0_included, w);
- break;
- default:
- return 1;
- };
-
- if (!silent)
- printf("chan_list = %s\n",
- osmo_hexdump(chan_list, sizeof(chan_list)));
-
- rc = gsm48_decode_freq_list(dec_freq, chan_list, sizeof(chan_list),
- 0xfe, 1);
- if (rc != 0) {
- printf("Cannot decode freq list, rc = %d\n", rc);
- return 1;
- }
-
- for (i = 0; i < ARRAY_SIZE(dec_freq); i++) {
- if (dec_freq[i].mask &&
- dec_arfcns_count < ARRAY_SIZE(dec_arfcns))
- dec_arfcns[dec_arfcns_count++] = i;
- }
-
- if (!silent) {
- printf("Decoded freqs %d (expected %d)\n",
- dec_arfcns_count, arfcns_num);
- printf("Decoded: ");
- for (i = 0; i < dec_arfcns_count; i++) {
- printf("%d ", dec_arfcns[i]);
- if (dec_arfcns[i] != orig_arfcns[i])
- printf("(!= %d) ", orig_arfcns[i]);
- }
- printf("\n");
- }
-
- if (dec_arfcns_count != arfcns_num) {
- printf("Wrong number of arfcns\n");
- return 1;
- }
-
- if (memcmp(dec_arfcns, orig_arfcns, sizeof(dec_arfcns)) != 0) {
- printf("Decoding error, got wrong freqs\n");
- fprintf(stderr, " w = ");
- for (i = 0; i < ARRAY_SIZE(w); i++)
- fprintf(stderr, "%d ", w[i]);
- fprintf(stderr, "\n");
- return 1;
- }
-
- return 0;
-}
-
-static void test_random_range_encoding(int range, int max_arfcn_num)
-{
- int arfcns_num = 0;
- int test_idx;
- int rc, max_count;
- int num_tests = 1024;
-
- printf("Random range test: range %d, max num ARFCNs %d\n",
- range, max_arfcn_num);
-
- srandom(1);
-
- for (max_count = 1; max_count < max_arfcn_num; max_count++) {
- for (test_idx = 0; test_idx < num_tests; test_idx++) {
- int count;
- int i;
- int min_freq = 0;
-
- int rnd_arfcns[RANGE_ENC_MAX_ARFCNS] = {0};
- char rnd_arfcns_set[1024] = {0};
-
- if (range < ARFCN_RANGE_1024)
- min_freq = random() % (1023 - range);
-
- for (count = max_count; count; ) {
- int arfcn = min_freq + random() % (range + 1);
- OSMO_ASSERT(arfcn < ARRAY_SIZE(rnd_arfcns_set));
-
- if (!rnd_arfcns_set[arfcn]) {
- rnd_arfcns_set[arfcn] = 1;
- count -= 1;
- }
- }
-
- arfcns_num = 0;
- for (i = 0; i < ARRAY_SIZE(rnd_arfcns_set); i++)
- if (rnd_arfcns_set[i])
- rnd_arfcns[arfcns_num++] = i;
-
- rc = test_single_range_encoding(range, rnd_arfcns,
- arfcns_num, 1);
- if (rc != 0) {
- printf("Failed on test %d, range %d, num ARFCNs %d\n",
- test_idx, range, max_count);
- test_single_range_encoding(range, rnd_arfcns,
- arfcns_num, 0);
- return;
- }
- }
- }
-}
-
-static void test_range_encoding()
-{
- int *arfcns;
- int arfcns_num = 0;
- int test_idx;
- int range;
-
- for (test_idx = 0; arfcn_test_ranges[test_idx].arfcns_num > 0; test_idx++)
- {
- arfcns_num = arfcn_test_ranges[test_idx].arfcns_num;
- arfcns = &arfcn_test_ranges[test_idx].arfcns[0];
- range = arfcn_test_ranges[test_idx].range;
-
- printf("Range test %d: range %d, num ARFCNs %d\n",
- test_idx, range, arfcns_num);
-
- test_single_range_encoding(range, arfcns, arfcns_num, 0);
- }
-
- test_random_range_encoding(ARFCN_RANGE_128, 29);
- test_random_range_encoding(ARFCN_RANGE_256, 22);
- test_random_range_encoding(ARFCN_RANGE_512, 18);
- test_random_range_encoding(ARFCN_RANGE_1024, 16);
-}
-
-static int freqs1[] = {
- 12, 70, 121, 190, 250, 320, 401, 475, 520, 574, 634, 700, 764, 830, 905, 980
-};
-
-static int freqs2[] = {
- 402, 460, 1, 67, 131, 197, 272, 347,
-};
-
-static int freqs3[] = {
- 68, 128, 198, 279, 353, 398, 452,
-
-};
-
-static int w_out[] = {
- 122, 2, 69, 204, 75, 66, 60, 70, 83, 3, 24, 67, 54, 64, 70, 9,
-};
-
-static int range128[] = {
- 1, 1 + 127,
-};
-
-static int range256[] = {
- 1, 1 + 128,
-};
-
-static int range512[] = {
- 1, 1+ 511,
-};
-
-
-static void test_arfcn_filter()
-{
- int arfcns[50], i, res, f0_included;
- for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
- arfcns[i] = (i + 1) * 2;
-
- /* check that the arfcn is taken out. f0_included is only set for Range1024 */
- f0_included = 24;
- res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
- arfcns[0], &f0_included);
- VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
- VERIFY(f0_included, ==, 1);
- for (i = 0; i < res; ++i)
- VERIFY(arfcns[i], ==, ((i+2) * 2) - (2+1));
-
- /* check with range1024, ARFCN 0 is included */
- for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
- arfcns[i] = i * 2;
- res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
- 0, &f0_included);
- VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
- VERIFY(f0_included, ==, 1);
- for (i = 0; i < res; ++i)
- VERIFY(arfcns[i], ==, (i + 1) * 2 - 1);
-
- /* check with range1024, ARFCN 0 not included */
- for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
- arfcns[i] = (i + 1) * 2;
- res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
- 0, &f0_included);
- VERIFY(res, ==, ARRAY_SIZE(arfcns));
- VERIFY(f0_included, ==, 0);
- for (i = 0; i < res; ++i)
- VERIFY(arfcns[i], ==, ((i + 1) * 2) - 1);
-}
-
-static void test_print_encoding()
-{
- int rc;
- int w[17];
- uint8_t chan_list[16];
- memset(chan_list, 0x23, sizeof(chan_list));
-
- for (rc = 0; rc < ARRAY_SIZE(w); ++rc)
- switch (rc % 3) {
- case 0:
- w[rc] = 0xAAAA;
- break;
- case 1:
- w[rc] = 0x5555;
- break;
- case 2:
- w[rc] = 0x9696;
- break;
- }
-
- range_enc_range512(chan_list, (1 << 9) | 0x96, w);
-
- printf("Range512: %s\n", osmo_hexdump(chan_list, ARRAY_SIZE(chan_list)));
-}
-
-static void test_si_range_helpers()
-{
- int ws[(sizeof(freqs1)/sizeof(freqs1[0]))];
- int i, f0 = 0xFFFFFF;
-
- memset(&ws[0], 0x23, sizeof(ws));
-
- i = range_enc_find_index(1023, freqs1, ARRAY_SIZE(freqs1));
- printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs1[i] : -1);
- VERIFY(i, ==, 2);
-
- i = range_enc_find_index(511, freqs2, ARRAY_SIZE(freqs2));
- printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs2[i] : -1);
- VERIFY(i, ==, 2);
-
- i = range_enc_find_index(511, freqs3, ARRAY_SIZE(freqs3));
- printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs3[i] : -1);
- VERIFY(i, ==, 0);
-
- range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0);
-
- for (i = 0; i < sizeof(freqs1)/sizeof(freqs1[0]); ++i) {
- printf("w[%d]=%d\n", i, ws[i]);
- VERIFY(ws[i], ==, w_out[i]);
- }
-
- i = range_enc_determine_range(range128, ARRAY_SIZE(range128), &f0);
- VERIFY(i, ==, ARFCN_RANGE_128);
- VERIFY(f0, ==, 1);
-
- i = range_enc_determine_range(range256, ARRAY_SIZE(range256), &f0);
- VERIFY(i, ==, ARFCN_RANGE_256);
- VERIFY(f0, ==, 1);
-
- i = range_enc_determine_range(range512, ARRAY_SIZE(range512), &f0);
- VERIFY(i, ==, ARFCN_RANGE_512);
- VERIFY(f0, ==, 1);
-}
-
static void test_si_ba_ind(struct gsm_network *net)
{
struct gsm_bts *bts = bts_init(net);
@@ -915,11 +582,6 @@ int main(int argc, char **argv)
}
bsc_gsmnet = net;
- test_si_range_helpers();
- test_arfcn_filter();
- test_print_encoding();
- test_range_encoding();
-
test_si2q_segfault(net);
test_si2q_e(net);
test_si2q_u(net);
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index f1aa46301..b22d0c241 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -1,59 +1,3 @@
-Element is: 2 => freqs[i] = 121
-Element is: 2 => freqs[i] = 1
-Element is: 0 => freqs[i] = 68
-w[0]=122
-w[1]=2
-w[2]=69
-w[3]=204
-w[4]=75
-w[5]=66
-w[6]=60
-w[7]=70
-w[8]=83
-w[9]=3
-w[10]=24
-w[11]=67
-w[12]=54
-w[13]=64
-w[14]=70
-w[15]=9
-Range512: 89 4b 2a 95 65 95 55 2c a9 55 aa 55 6a 95 59 55
-Range test 0: range 511, num ARFCNs 12
-chan_list = 88 00 98 34 85 36 7c 50 22 dc 5e ec 00 00 00 00
-Decoded freqs 12 (expected 12)
-Decoded: 1 12 31 51 57 91 97 98 113 117 120 125
-Range test 1: range 511, num ARFCNs 17
-chan_list = 88 00 82 7f 01 3f 7e 04 0b ff ff fc 10 41 07 e0
-Decoded freqs 17 (expected 17)
-Decoded: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
-Range test 2: range 511, num ARFCNs 18
-chan_list = 88 00 82 7f 01 7f 7e 04 0b ff ff fc 10 41 07 ff
-Decoded freqs 18 (expected 18)
-Decoded: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
-Range test 3: range 511, num ARFCNs 18
-chan_list = 88 00 94 3a 44 32 d7 2a 43 2a 13 94 e5 38 39 f6
-Decoded freqs 18 (expected 18)
-Decoded: 1 17 31 45 58 79 81 97 113 127 213 277 287 311 331 391 417 511
-Range test 4: range 511, num ARFCNs 6
-chan_list = 88 00 8b 3c 88 b9 6b 00 00 00 00 00 00 00 00 00
-Decoded freqs 6 (expected 6)
-Decoded: 1 17 31 45 58 79
-Range test 5: range 511, num ARFCNs 6
-chan_list = 88 05 08 fc 88 b9 6b 00 00 00 00 00 00 00 00 00
-Decoded freqs 6 (expected 6)
-Decoded: 10 17 31 45 58 79
-Range test 6: range 1023, num ARFCNs 17
-chan_list = 84 71 e4 ab b9 58 05 cb 39 17 fd b0 75 62 0f 2f
-Decoded freqs 17 (expected 17)
-Decoded: 0 17 31 45 58 79 81 97 113 127 213 277 287 311 331 391 1023
-Range test 7: range 1023, num ARFCNs 16
-chan_list = 80 71 e4 ab b9 58 05 cb 39 17 fd b0 75 62 0f 2f
-Decoded freqs 16 (expected 16)
-Decoded: 17 31 45 58 79 81 97 113 127 213 277 287 311 331 391 1023
-Random range test: range 127, max num ARFCNs 29
-Random range test: range 255, max num ARFCNs 22
-Random range test: range 511, max num ARFCNs 18
-Random range test: range 1023, max num ARFCNs 16
BTS allocation OK in test_si2q_segfault()
Test SI2quater UARFCN (same scrambling code and diversity):
generating SI2quater for 0 EARFCNs and 1 UARFCNs...
diff --git a/tests/handover/Makefile.am b/tests/handover/Makefile.am
index b3bc21f6b..f0b2e7a29 100644
--- a/tests/handover/Makefile.am
+++ b/tests/handover/Makefile.am
@@ -47,7 +47,6 @@ handover_test_LDADD = \
$(top_builddir)/src/osmo-bsc/abis_om2000_vty.o \
$(top_builddir)/src/osmo-bsc/abis_rsl.o \
$(top_builddir)/src/osmo-bsc/acc.o \
- $(top_builddir)/src/osmo-bsc/arfcn_range_encode.o \
$(top_builddir)/src/osmo-bsc/assignment_fsm.o \
$(top_builddir)/src/osmo-bsc/bsc_ctrl_commands.o \
$(top_builddir)/src/osmo-bsc/bsc_init.o \