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, |
| 44 | struct bsc_msc_data *msc); |
| 45 | int __wrap_bsc_grace_paging_request(enum signal_rf rf_policy, struct bsc_subscr *subscr, int chan_needed, |
| 46 | struct bsc_msc_data *msc) |
| 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 | }, |
| 76 | }; |
| 77 | |
| 78 | void test_cell_identifier() |
| 79 | { |
| 80 | int i; |
| 81 | int rc; |
| 82 | struct gsm_network *net; |
| 83 | struct bsc_msc_data *msc; |
| 84 | |
| 85 | net = bsc_network_init(NULL, 1, 1, NULL); |
| 86 | net->bsc_data->rf_ctrl = talloc_zero(NULL, struct osmo_bsc_rf); |
| 87 | net->bsc_data->rf_ctrl->policy = S_RF_ON; |
| 88 | |
| 89 | msc = talloc_zero(net, struct bsc_msc_data); |
| 90 | msc->network = net; |
| 91 | |
| 92 | log_set_log_level(osmo_stderr_target, LOGL_DEBUG); |
| 93 | |
| 94 | for (i = 0; i < ARRAY_SIZE(cell_identifier_tests); i++) { |
| 95 | struct msgb *msg; |
| 96 | fprintf(stderr, "\n%d:\n", i); |
| 97 | msg = msgb_from_hex("test_cell_identifier", 1024, cell_identifier_tests[i].msg); |
| 98 | |
| 99 | gl_expect_lac = cell_identifier_tests[i].expect_lac; |
| 100 | rc = bsc_handle_udt(msc, msg, msgb_l2len(msg)); |
| 101 | |
| 102 | fprintf(stderr, "bsc_handle_udt() returned %d\n", rc); |
| 103 | OSMO_ASSERT(rc == cell_identifier_tests[i].expect_rc); |
| 104 | |
| 105 | msgb_free(msg); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | int main(int argc, char **argv) |
| 110 | { |
| 111 | osmo_init_logging(&log_info); |
| 112 | log_set_use_color(osmo_stderr_target, 0); |
| 113 | log_set_print_timestamp(osmo_stderr_target, 0); |
| 114 | log_set_print_filename(osmo_stderr_target, 0); |
| 115 | log_set_print_category(osmo_stderr_target, 1); |
| 116 | |
| 117 | test_cell_identifier(); |
| 118 | |
| 119 | return 0; |
| 120 | } |