blob: 924d763ff81a97b4ee025f19f394c729d5772612 [file] [log] [blame]
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +02001/*
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 Welte9af6ddf2011-01-01 15:25:50 +01006 * 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 Freyther800d29d2009-06-10 12:36:38 +02008 * (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 Welte9af6ddf2011-01-01 15:25:50 +010015 * 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 Freyther800d29d2009-06-10 12:36:38 +020017 *
18 */
19
20#include <stdio.h>
Harald Welte6bfda782009-06-26 20:30:46 +020021#include <stdlib.h>
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020022
23#include <assert.h>
24
Holger Hans Peter Freyther08e324f2012-01-06 14:06:56 +010025#include <osmocom/core/application.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010026#include <osmocom/core/select.h>
Holger Hans Peter Freyther08e324f2012-01-06 14:06:56 +010027
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020028#include <openbsc/abis_rsl.h>
Holger Hans Peter Freyther08e324f2012-01-06 14:06:56 +010029#include <openbsc/debug.h>
30#include <openbsc/gsm_subscriber.h>
31
32static int s_end = 0;
33static struct gsm_subscriber_connection s_conn;
Holger Hans Peter Freytherd6d7aff2015-04-06 12:03:45 +020034static void *s_data;
Neels Hofmeyr51273152016-03-03 16:12:04 +010035static gsm_cbfn *s_cbfn = NULL;
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020036
37/* our handler */
38static int subscr_cb(unsigned int hook, unsigned int event, struct msgb *msg, void *data, void *param)
39{
40 assert(hook == 101);
41 assert(event == 200);
42 assert(msg == (void*)0x1323L);
Holger Hans Peter Freyther08e324f2012-01-06 14:06:56 +010043 assert(data == &s_conn);
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020044 assert(param == (void*)0x2342L);
45 printf("Reached, didn't crash, test passed\n");
Holger Hans Peter Freyther08e324f2012-01-06 14:06:56 +010046 s_end = true;
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020047 return 0;
48}
49
50/* mock object for testing, directly invoke the cb... maybe later through the timer */
Holger Hans Peter Freytherb691bf12014-05-28 16:39:50 +020051int paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscriber, int type, gsm_cbfn *cbfn, void *data)
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020052{
Holger Hans Peter Freytherd6d7aff2015-04-06 12:03:45 +020053 s_data = data;
54 s_cbfn = cbfn;
Holger Hans Peter Freytherb691bf12014-05-28 16:39:50 +020055
56 /* claim we have patched */
57 return 1;
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020058}
59
60
Holger Hans Peter Freytheradb6e1c2010-09-18 06:44:24 +080061int main(int argc, char **argv)
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020062{
Harald Welte6bfda782009-06-26 20:30:46 +020063 struct gsm_network *network;
64 struct gsm_bts *bts;
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020065
Holger Hans Peter Freyther08e324f2012-01-06 14:06:56 +010066 osmo_init_logging(&log_info);
67
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020068 printf("Testing the gsm_subscriber chan logic\n");
69
70 /* Create a dummy network */
Neels Hofmeyr77c8d5f2016-05-09 19:12:44 +020071 network = gsm_network_init(tall_bsc_ctx, 1, 1, NULL);
Harald Welte6bfda782009-06-26 20:30:46 +020072 if (!network)
73 exit(1);
Harald Weltee31816c2011-06-26 14:55:06 +020074 bts = gsm_bts_alloc(network);
Harald Welte6bfda782009-06-26 20:30:46 +020075 bts->location_area_code = 23;
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020076
77 /* Create a dummy subscriber */
78 struct gsm_subscriber *subscr = subscr_alloc();
79 subscr->lac = 23;
Jacob Erlbeck1e30a282014-12-03 09:28:24 +010080 subscr->group = network->subscr_group;
81
82 OSMO_ASSERT(subscr->group);
83 OSMO_ASSERT(subscr->group->net == network);
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020084
85 /* Ask for a channel... */
Neels Hofmeyr51273152016-03-03 16:12:04 +010086 struct subscr_request *sr;
87 sr = subscr_request_channel(subscr, RSL_CHANNEED_TCH_F, subscr_cb, (void*)0x2342L);
88 OSMO_ASSERT(sr);
89 OSMO_ASSERT(s_cbfn);
Holger Hans Peter Freytherd6d7aff2015-04-06 12:03:45 +020090 s_cbfn(101, 200, (void*)0x1323L, &s_conn, s_data);
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020091
Holger Hans Peter Freytherd6d7aff2015-04-06 12:03:45 +020092 OSMO_ASSERT(s_end);
Holger Hans Peter Freyther08e324f2012-01-06 14:06:56 +010093
94 return EXIT_SUCCESS;
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +020095}
96
Harald Weltef338a032011-01-14 15:55:42 +010097void _abis_nm_sendmsg() {}
Holger Hans Peter Freyther7673ce42009-08-10 06:40:05 +020098void sms_alloc() {}
Holger Hans Peter Freyther900394a2013-12-27 20:10:24 +010099void sms_free() {}
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800100void gsm_net_update_ctype(struct gsm_network *network) {}
Holger Hans Peter Freytherd9cdd052010-12-21 13:43:52 +0100101void gsm48_secure_channel() {}
Holger Hans Peter Freytherffccb772010-12-28 17:47:43 +0100102void paging_request_stop() {}
Holger Hans Peter Freyther763b42a2010-12-29 11:07:22 +0100103void vty_out() {}
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200104void* connection_for_subscr(void) { abort(); return NULL; }
Holger Hans Peter Freytherd9cdd052010-12-21 13:43:52 +0100105
Holger Hans Peter Freyther800d29d2009-06-10 12:36:38 +0200106
Holger Hans Peter Freyther98657d52010-01-11 16:42:07 +0100107struct tlv_definition nm_att_tlvdef;
108