blob: 1d8fe7720eaa4387df2688ea1af93b3970cd8337 [file] [log] [blame]
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +01001/*
2 * (C) 2017 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <osmocom/core/application.h>
21
22#include <osmocom/bsc/debug.h>
23#include <osmocom/bsc/osmo_bsc.h>
24#include <osmocom/bsc/signal.h>
25#include <osmocom/bsc/bsc_subscriber.h>
26#include <osmocom/bsc/bsc_msc_data.h>
Stefan Sperling714c2f92018-01-11 14:53:18 +010027#include <osmocom/bsc/gsm_data_shared.h>
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +010028#include <osmocom/bsc/common_bsc.h>
29#include <osmocom/bsc/osmo_bsc_rf.h>
30
31struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex)
32{
33 struct msgb *msg = msgb_alloc(size, label);
34 unsigned char *rc;
35 msg->l2h = msg->l3h = msg->head;
36 rc = msgb_put(msg, osmo_hexparse(hex, msg->head, msgb_tailroom(msg)));
37 OSMO_ASSERT(rc == msg->l2h);
38 return msg;
39}
40
41uint16_t gl_expect_lac = 0;
42
43/* override, requires '-Wl,--wrap=bsc_grace_paging_request' */
44int __real_bsc_grace_paging_request(enum signal_rf rf_policy, struct bsc_subscr *subscr, int chan_needed,
Stefan Sperling714c2f92018-01-11 14:53:18 +010045 struct bsc_msc_data *msc, struct gsm_bts *bts);
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +010046int __wrap_bsc_grace_paging_request(enum signal_rf rf_policy, struct bsc_subscr *subscr, int chan_needed,
Stefan Sperling714c2f92018-01-11 14:53:18 +010047 struct bsc_msc_data *msc, struct gsm_bts *bts)
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +010048{
49 if (subscr->lac == GSM_LAC_RESERVED_ALL_BTS)
50 fprintf(stderr, "BSC paging started on entire BSS (%u)\n", subscr->lac);
51 else
52 fprintf(stderr, "BSC paging started with LAC %u\n", subscr->lac);
53 OSMO_ASSERT(gl_expect_lac == subscr->lac);
54 return 0;
55}
56
57struct {
58 const char *msg;
59 uint16_t expect_lac;
60 int expect_rc;
61} cell_identifier_tests[] = {
62 {
63 "001652080859512069000743940904010844601a03050065",
64 /* ^^^^^^ Cell Identifier List: LAC */
65 0x65, 0
66 },
67 {
68 "001452080859512069000743940904010844601a0106",
69 /* ^^ Cell Identifier List: BSS */
70 GSM_LAC_RESERVED_ALL_BTS, 0
71 },
72 {
73 "001952080859512069000743940904010844601a060415f5490065",
74 /* ^^^^^^^^^^^^ Cell Identifier List: LAI */
75 GSM_LAC_RESERVED_ALL_BTS, 0
76 },
Stefan Sperling33e90092018-01-05 17:22:11 +010077 {
78 "001952080859512069000743940904010844601a060400f1100065",
79 /* ^^^^^^^^^^^^ Cell Identifier List: LAI */
80 0x65, 0
81 },
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +010082};
83
84void test_cell_identifier()
85{
86 int i;
87 int rc;
88 struct gsm_network *net;
89 struct bsc_msc_data *msc;
Stefan Sperling714c2f92018-01-11 14:53:18 +010090 struct gsm_bts *bts;
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +010091
Harald Welted9956d92017-12-17 21:48:47 +010092 net = bsc_network_init(NULL, 1, 1);
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +010093 net->bsc_data->rf_ctrl = talloc_zero(NULL, struct osmo_bsc_rf);
94 net->bsc_data->rf_ctrl->policy = S_RF_ON;
95
96 msc = talloc_zero(net, struct bsc_msc_data);
97 msc->network = net;
98
Stefan Sperling714c2f92018-01-11 14:53:18 +010099 bts = gsm_bts_alloc_register(net, GSM_BTS_TYPE_UNKNOWN, 0);
100 if (bts == NULL) {
101 fprintf(stderr, "gsm_bts_alloc_register() returned NULL\n");
102 return;
103 }
104
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +0100105 log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
106
107 for (i = 0; i < ARRAY_SIZE(cell_identifier_tests); i++) {
108 struct msgb *msg;
109 fprintf(stderr, "\n%d:\n", i);
110 msg = msgb_from_hex("test_cell_identifier", 1024, cell_identifier_tests[i].msg);
111
112 gl_expect_lac = cell_identifier_tests[i].expect_lac;
Stefan Sperling714c2f92018-01-11 14:53:18 +0100113 bts->location_area_code = (gl_expect_lac == GSM_LAC_RESERVED_ALL_BTS ? 0 : gl_expect_lac);
Neels Hofmeyr9eb208f2017-11-07 03:38:28 +0100114 rc = bsc_handle_udt(msc, msg, msgb_l2len(msg));
115
116 fprintf(stderr, "bsc_handle_udt() returned %d\n", rc);
117 OSMO_ASSERT(rc == cell_identifier_tests[i].expect_rc);
118
119 msgb_free(msg);
120 }
121}
122
123int main(int argc, char **argv)
124{
125 osmo_init_logging(&log_info);
126 log_set_use_color(osmo_stderr_target, 0);
127 log_set_print_timestamp(osmo_stderr_target, 0);
128 log_set_print_filename(osmo_stderr_target, 0);
129 log_set_print_category(osmo_stderr_target, 1);
130
131 test_cell_identifier();
132
133 return 0;
134}