Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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 |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 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 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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/>. |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
Harald Welte | cd1c428 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 21 | #include <stdlib.h> |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 22 | |
| 23 | #include <assert.h> |
| 24 | |
Holger Hans Peter Freyther | 7b87e44 | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 25 | #include <osmocom/core/application.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 26 | #include <osmocom/core/select.h> |
Holger Hans Peter Freyther | 7b87e44 | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 27 | |
Neels Hofmeyr | b46b0a6 | 2016-05-14 00:57:04 +0200 | [diff] [blame^] | 28 | #include <openbsc/common_bsc.h> |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 29 | #include <openbsc/abis_rsl.h> |
Holger Hans Peter Freyther | 7b87e44 | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 30 | #include <openbsc/debug.h> |
| 31 | #include <openbsc/gsm_subscriber.h> |
| 32 | |
| 33 | static int s_end = 0; |
| 34 | static struct gsm_subscriber_connection s_conn; |
Holger Hans Peter Freyther | 61623df | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 35 | static void *s_data; |
Neels Hofmeyr | 344340b | 2016-03-03 16:12:04 +0100 | [diff] [blame] | 36 | static gsm_cbfn *s_cbfn = NULL; |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 37 | |
| 38 | /* our handler */ |
| 39 | static int subscr_cb(unsigned int hook, unsigned int event, struct msgb *msg, void *data, void *param) |
| 40 | { |
| 41 | assert(hook == 101); |
| 42 | assert(event == 200); |
| 43 | assert(msg == (void*)0x1323L); |
Holger Hans Peter Freyther | 7b87e44 | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 44 | assert(data == &s_conn); |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 45 | assert(param == (void*)0x2342L); |
| 46 | printf("Reached, didn't crash, test passed\n"); |
Holger Hans Peter Freyther | 7b87e44 | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 47 | s_end = true; |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | /* mock object for testing, directly invoke the cb... maybe later through the timer */ |
Holger Hans Peter Freyther | 3673741 | 2014-05-28 16:39:50 +0200 | [diff] [blame] | 52 | int paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscriber, int type, gsm_cbfn *cbfn, void *data) |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 53 | { |
Holger Hans Peter Freyther | 61623df | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 54 | s_data = data; |
| 55 | s_cbfn = cbfn; |
Holger Hans Peter Freyther | 3673741 | 2014-05-28 16:39:50 +0200 | [diff] [blame] | 56 | |
| 57 | /* claim we have patched */ |
| 58 | return 1; |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | |
Neels Hofmeyr | 3ac0a39 | 2016-09-25 15:47:36 +0200 | [diff] [blame] | 62 | void test_request_chan(void) |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 63 | { |
Harald Welte | cd1c428 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 64 | struct gsm_network *network; |
| 65 | struct gsm_bts *bts; |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 66 | |
| 67 | printf("Testing the gsm_subscriber chan logic\n"); |
| 68 | |
| 69 | /* Create a dummy network */ |
Neels Hofmeyr | 5494c27 | 2016-05-14 00:45:26 +0200 | [diff] [blame] | 70 | network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL); |
Harald Welte | cd1c428 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 71 | if (!network) |
| 72 | exit(1); |
Harald Welte | a994fd4 | 2011-06-26 14:55:06 +0200 | [diff] [blame] | 73 | bts = gsm_bts_alloc(network); |
Harald Welte | cd1c428 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 74 | bts->location_area_code = 23; |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 75 | |
| 76 | /* Create a dummy subscriber */ |
| 77 | struct gsm_subscriber *subscr = subscr_alloc(); |
| 78 | subscr->lac = 23; |
Jacob Erlbeck | da8770b | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 79 | subscr->group = network->subscr_group; |
| 80 | |
| 81 | OSMO_ASSERT(subscr->group); |
| 82 | OSMO_ASSERT(subscr->group->net == network); |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 83 | |
| 84 | /* Ask for a channel... */ |
Neels Hofmeyr | 344340b | 2016-03-03 16:12:04 +0100 | [diff] [blame] | 85 | struct subscr_request *sr; |
| 86 | sr = subscr_request_channel(subscr, RSL_CHANNEED_TCH_F, subscr_cb, (void*)0x2342L); |
| 87 | OSMO_ASSERT(sr); |
| 88 | OSMO_ASSERT(s_cbfn); |
Holger Hans Peter Freyther | 61623df | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 89 | s_cbfn(101, 200, (void*)0x1323L, &s_conn, s_data); |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 90 | |
Holger Hans Peter Freyther | 61623df | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 91 | OSMO_ASSERT(s_end); |
Neels Hofmeyr | 3ac0a39 | 2016-09-25 15:47:36 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Neels Hofmeyr | ef245a5 | 2016-09-25 15:58:01 +0200 | [diff] [blame] | 94 | void test_dyn_ts_subslots(void) |
| 95 | { |
| 96 | struct gsm_bts_trx_ts ts; |
| 97 | |
| 98 | printf("Testing subslot numbers for pchan types\n"); |
| 99 | |
| 100 | ts.pchan = GSM_PCHAN_TCH_F; |
| 101 | OSMO_ASSERT(ts_subslots(&ts) == 1); |
| 102 | |
| 103 | ts.pchan = GSM_PCHAN_TCH_H; |
| 104 | OSMO_ASSERT(ts_subslots(&ts) == 2); |
| 105 | |
| 106 | ts.pchan = GSM_PCHAN_PDCH; |
| 107 | OSMO_ASSERT(ts_subslots(&ts) == 0); |
| 108 | |
| 109 | ts.pchan = GSM_PCHAN_TCH_F_PDCH; |
| 110 | ts.flags = 0; /* TCH_F mode */ |
| 111 | OSMO_ASSERT(ts_subslots(&ts) == 1); |
| 112 | ts.flags = TS_F_PDCH_ACTIVE; |
Neels Hofmeyr | bc9efd1 | 2016-09-25 15:33:02 +0200 | [diff] [blame] | 113 | OSMO_ASSERT(ts_subslots(&ts) == 0); |
Neels Hofmeyr | ef245a5 | 2016-09-25 15:58:01 +0200 | [diff] [blame] | 114 | |
| 115 | ts.pchan = GSM_PCHAN_TCH_F_TCH_H_PDCH; |
| 116 | ts.dyn.pchan_is = GSM_PCHAN_TCH_F; |
| 117 | OSMO_ASSERT(ts_subslots(&ts) == 1); |
| 118 | ts.dyn.pchan_is = GSM_PCHAN_TCH_H; |
| 119 | OSMO_ASSERT(ts_subslots(&ts) == 2); |
| 120 | ts.dyn.pchan_is = GSM_PCHAN_PDCH; |
| 121 | OSMO_ASSERT(ts_subslots(&ts) == 0); |
| 122 | } |
| 123 | |
Neels Hofmeyr | 3ac0a39 | 2016-09-25 15:47:36 +0200 | [diff] [blame] | 124 | int main(int argc, char **argv) |
| 125 | { |
| 126 | osmo_init_logging(&log_info); |
| 127 | |
| 128 | test_request_chan(); |
Neels Hofmeyr | ef245a5 | 2016-09-25 15:58:01 +0200 | [diff] [blame] | 129 | test_dyn_ts_subslots(); |
Holger Hans Peter Freyther | 7b87e44 | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 130 | |
| 131 | return EXIT_SUCCESS; |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 134 | void _abis_nm_sendmsg() {} |
Holger Hans Peter Freyther | d035eec | 2009-08-10 06:40:05 +0200 | [diff] [blame] | 135 | void sms_alloc() {} |
Holger Hans Peter Freyther | 7ff8806 | 2013-12-27 20:10:24 +0100 | [diff] [blame] | 136 | void sms_free() {} |
Holger Hans Peter Freyther | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 137 | void gsm_net_update_ctype(struct gsm_network *network) {} |
Holger Hans Peter Freyther | 1860583 | 2010-12-21 13:43:52 +0100 | [diff] [blame] | 138 | void gsm48_secure_channel() {} |
Holger Hans Peter Freyther | a32e9c1 | 2010-12-28 17:47:43 +0100 | [diff] [blame] | 139 | void paging_request_stop() {} |
Holger Hans Peter Freyther | 0fe0c8c | 2010-12-29 11:07:22 +0100 | [diff] [blame] | 140 | void vty_out() {} |
Holger Hans Peter Freyther | c25021f | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 141 | void* connection_for_subscr(void) { abort(); return NULL; } |
Holger Hans Peter Freyther | 1860583 | 2010-12-21 13:43:52 +0100 | [diff] [blame] | 142 | |
Holger Hans Peter Freyther | f8584a1 | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 143 | |
Holger Hans Peter Freyther | 648879c | 2010-01-11 16:42:07 +0100 | [diff] [blame] | 144 | struct tlv_definition nm_att_tlvdef; |
| 145 | |