Holger Hans Peter Freyther | 800d29d | 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 | 9af6ddf | 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 | 800d29d | 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 | 9af6ddf | 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 | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
Harald Welte | 6bfda78 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 21 | #include <stdlib.h> |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 22 | |
| 23 | #include <assert.h> |
| 24 | |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 25 | #include <osmocom/core/application.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 26 | #include <osmocom/core/select.h> |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 27 | |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 28 | #include <openbsc/abis_rsl.h> |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 29 | #include <openbsc/debug.h> |
| 30 | #include <openbsc/gsm_subscriber.h> |
| 31 | |
| 32 | static int s_end = 0; |
| 33 | static struct gsm_subscriber_connection s_conn; |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 34 | |
| 35 | /* our handler */ |
| 36 | static int subscr_cb(unsigned int hook, unsigned int event, struct msgb *msg, void *data, void *param) |
| 37 | { |
| 38 | assert(hook == 101); |
| 39 | assert(event == 200); |
| 40 | assert(msg == (void*)0x1323L); |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 41 | assert(data == &s_conn); |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 42 | assert(param == (void*)0x2342L); |
| 43 | printf("Reached, didn't crash, test passed\n"); |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 44 | s_end = true; |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | /* mock object for testing, directly invoke the cb... maybe later through the timer */ |
Holger Hans Peter Freyther | b691bf1 | 2014-05-28 16:39:50 +0200 | [diff] [blame] | 49 | int paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscriber, int type, gsm_cbfn *cbfn, void *data) |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 50 | { |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 51 | cbfn(101, 200, (void*)0x1323L, &s_conn, data); |
Holger Hans Peter Freyther | b691bf1 | 2014-05-28 16:39:50 +0200 | [diff] [blame] | 52 | |
| 53 | /* claim we have patched */ |
| 54 | return 1; |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
Holger Hans Peter Freyther | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 58 | int main(int argc, char **argv) |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 59 | { |
Harald Welte | 6bfda78 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 60 | struct gsm_network *network; |
| 61 | struct gsm_bts *bts; |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 62 | |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 63 | osmo_init_logging(&log_info); |
| 64 | |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 65 | printf("Testing the gsm_subscriber chan logic\n"); |
| 66 | |
| 67 | /* Create a dummy network */ |
Harald Welte | 6bfda78 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 68 | network = gsm_network_init(1, 1, NULL); |
| 69 | if (!network) |
| 70 | exit(1); |
Harald Welte | e31816c | 2011-06-26 14:55:06 +0200 | [diff] [blame] | 71 | bts = gsm_bts_alloc(network); |
Harald Welte | 6bfda78 | 2009-06-26 20:30:46 +0200 | [diff] [blame] | 72 | bts->location_area_code = 23; |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 73 | |
| 74 | /* Create a dummy subscriber */ |
| 75 | struct gsm_subscriber *subscr = subscr_alloc(); |
| 76 | subscr->lac = 23; |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 77 | subscr->group = network->subscr_group; |
| 78 | |
| 79 | OSMO_ASSERT(subscr->group); |
| 80 | OSMO_ASSERT(subscr->group->net == network); |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 81 | |
| 82 | /* Ask for a channel... */ |
Holger Hans Peter Freyther | e4e8bf4 | 2009-08-20 13:33:51 +0200 | [diff] [blame] | 83 | subscr_get_channel(subscr, RSL_CHANNEED_TCH_F, subscr_cb, (void*)0x2342L); |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 84 | |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 85 | while (!s_end) { |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 86 | osmo_select_main(0); |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 87 | } |
Holger Hans Peter Freyther | 08e324f | 2012-01-06 14:06:56 +0100 | [diff] [blame] | 88 | |
| 89 | return EXIT_SUCCESS; |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 92 | void _abis_nm_sendmsg() {} |
Holger Hans Peter Freyther | 7673ce4 | 2009-08-10 06:40:05 +0200 | [diff] [blame] | 93 | void sms_alloc() {} |
Holger Hans Peter Freyther | 900394a | 2013-12-27 20:10:24 +0100 | [diff] [blame] | 94 | void sms_free() {} |
Holger Hans Peter Freyther | 7889107 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 95 | void gsm_net_update_ctype(struct gsm_network *network) {} |
Holger Hans Peter Freyther | d9cdd05 | 2010-12-21 13:43:52 +0100 | [diff] [blame] | 96 | void gsm48_secure_channel() {} |
Holger Hans Peter Freyther | ffccb77 | 2010-12-28 17:47:43 +0100 | [diff] [blame] | 97 | void paging_request_stop() {} |
Holger Hans Peter Freyther | 763b42a | 2010-12-29 11:07:22 +0100 | [diff] [blame] | 98 | void vty_out() {} |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 99 | void* connection_for_subscr(void) { abort(); return NULL; } |
Holger Hans Peter Freyther | d9cdd05 | 2010-12-21 13:43:52 +0100 | [diff] [blame] | 100 | |
Holger Hans Peter Freyther | 800d29d | 2009-06-10 12:36:38 +0200 | [diff] [blame] | 101 | |
Holger Hans Peter Freyther | 98657d5 | 2010-01-11 16:42:07 +0100 | [diff] [blame] | 102 | struct tlv_definition nm_att_tlvdef; |
| 103 | |