Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 1 | /* |
| 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> |
| 27 | #include <osmocom/bsc/common_bsc.h> |
| 28 | #include <osmocom/bsc/osmo_bsc_rf.h> |
| 29 | |
| 30 | struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex) |
| 31 | { |
| 32 | struct msgb *msg = msgb_alloc(size, label); |
| 33 | unsigned char *rc; |
| 34 | msg->l2h = msg->l3h = msg->head; |
| 35 | rc = msgb_put(msg, osmo_hexparse(hex, msg->head, msgb_tailroom(msg))); |
| 36 | OSMO_ASSERT(rc == msg->l2h); |
| 37 | return msg; |
| 38 | } |
| 39 | |
| 40 | uint16_t gl_expect_lac = 0; |
| 41 | |
| 42 | /* override, requires '-Wl,--wrap=bsc_grace_paging_request' */ |
| 43 | int __real_bsc_grace_paging_request(enum signal_rf rf_policy, struct bsc_subscr *subscr, int chan_needed, |
Stefan Sperling | 714c2f9 | 2018-01-11 14:53:18 +0100 | [diff] [blame] | 44 | struct bsc_msc_data *msc, struct gsm_bts *bts); |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 45 | int __wrap_bsc_grace_paging_request(enum signal_rf rf_policy, struct bsc_subscr *subscr, int chan_needed, |
Stefan Sperling | 714c2f9 | 2018-01-11 14:53:18 +0100 | [diff] [blame] | 46 | struct bsc_msc_data *msc, struct gsm_bts *bts) |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 47 | { |
| 48 | if (subscr->lac == GSM_LAC_RESERVED_ALL_BTS) |
| 49 | fprintf(stderr, "BSC paging started on entire BSS (%u)\n", subscr->lac); |
| 50 | else |
| 51 | fprintf(stderr, "BSC paging started with LAC %u\n", subscr->lac); |
| 52 | OSMO_ASSERT(gl_expect_lac == subscr->lac); |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | struct { |
| 57 | const char *msg; |
| 58 | uint16_t expect_lac; |
| 59 | int expect_rc; |
| 60 | } cell_identifier_tests[] = { |
| 61 | { |
| 62 | "001652080859512069000743940904010844601a03050065", |
| 63 | /* ^^^^^^ Cell Identifier List: LAC */ |
| 64 | 0x65, 0 |
| 65 | }, |
| 66 | { |
| 67 | "001452080859512069000743940904010844601a0106", |
| 68 | /* ^^ Cell Identifier List: BSS */ |
| 69 | GSM_LAC_RESERVED_ALL_BTS, 0 |
| 70 | }, |
| 71 | { |
| 72 | "001952080859512069000743940904010844601a060415f5490065", |
| 73 | /* ^^^^^^^^^^^^ Cell Identifier List: LAI */ |
| 74 | GSM_LAC_RESERVED_ALL_BTS, 0 |
| 75 | }, |
Stefan Sperling | 33e9009 | 2018-01-05 17:22:11 +0100 | [diff] [blame] | 76 | { |
| 77 | "001952080859512069000743940904010844601a060400f1100065", |
| 78 | /* ^^^^^^^^^^^^ Cell Identifier List: LAI */ |
| 79 | 0x65, 0 |
| 80 | }, |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
Harald Welte | 519c7e1 | 2018-01-28 02:45:46 +0100 | [diff] [blame] | 83 | struct gsm_network *bsc_gsmnet; |
| 84 | |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 85 | void test_cell_identifier() |
| 86 | { |
| 87 | int i; |
| 88 | int rc; |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 89 | struct bsc_msc_data *msc; |
Stefan Sperling | 714c2f9 | 2018-01-11 14:53:18 +0100 | [diff] [blame] | 90 | struct gsm_bts *bts; |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 91 | |
Neels Hofmeyr | f7a6329 | 2018-02-27 12:37:26 +0100 | [diff] [blame] | 92 | bsc_gsmnet = bsc_network_init(NULL); |
Harald Welte | 519c7e1 | 2018-01-28 02:45:46 +0100 | [diff] [blame] | 93 | bsc_gsmnet->bsc_data->rf_ctrl = talloc_zero(NULL, struct osmo_bsc_rf); |
| 94 | bsc_gsmnet->bsc_data->rf_ctrl->policy = S_RF_ON; |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 95 | |
Harald Welte | 519c7e1 | 2018-01-28 02:45:46 +0100 | [diff] [blame] | 96 | msc = talloc_zero(bsc_gsmnet, struct bsc_msc_data); |
| 97 | msc->network = bsc_gsmnet; |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 98 | |
Harald Welte | 519c7e1 | 2018-01-28 02:45:46 +0100 | [diff] [blame] | 99 | bts = gsm_bts_alloc_register(bsc_gsmnet, GSM_BTS_TYPE_UNKNOWN, 0); |
Stefan Sperling | 714c2f9 | 2018-01-11 14:53:18 +0100 | [diff] [blame] | 100 | if (bts == NULL) { |
| 101 | fprintf(stderr, "gsm_bts_alloc_register() returned NULL\n"); |
| 102 | return; |
| 103 | } |
| 104 | |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 105 | 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 Sperling | 714c2f9 | 2018-01-11 14:53:18 +0100 | [diff] [blame] | 113 | bts->location_area_code = (gl_expect_lac == GSM_LAC_RESERVED_ALL_BTS ? 0 : gl_expect_lac); |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 114 | 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 | |
Neels Hofmeyr | 7997bf4 | 2018-02-13 17:16:44 +0100 | [diff] [blame] | 123 | static const struct log_info_cat log_categories[] = { |
| 124 | [DMSC] = { |
| 125 | .name = "DMSC", |
| 126 | .description = "Mobile Switching Center", |
| 127 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 128 | }, |
| 129 | [DREF] = { |
| 130 | .name = "DREF", |
| 131 | .description = "Reference Counting", |
| 132 | .enabled = 0, .loglevel = LOGL_DEBUG, |
| 133 | }, |
| 134 | }; |
| 135 | |
| 136 | static const struct log_info log_info = { |
| 137 | .cat = log_categories, |
| 138 | .num_cat = ARRAY_SIZE(log_categories), |
| 139 | }; |
| 140 | |
Neels Hofmeyr | 9eb208f | 2017-11-07 03:38:28 +0100 | [diff] [blame] | 141 | int main(int argc, char **argv) |
| 142 | { |
| 143 | osmo_init_logging(&log_info); |
| 144 | log_set_use_color(osmo_stderr_target, 0); |
| 145 | log_set_print_timestamp(osmo_stderr_target, 0); |
| 146 | log_set_print_filename(osmo_stderr_target, 0); |
| 147 | log_set_print_category(osmo_stderr_target, 1); |
| 148 | |
| 149 | test_cell_identifier(); |
| 150 | |
| 151 | return 0; |
| 152 | } |