1 /* "Application" code of the layer2/3 stack */
3 /* (C) 2010 by Holger Hans Peter Freyther
4 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <osmocom/osmocom_data.h>
30 #include <osmocom/l1ctl.h>
31 #include <osmocom/l23_app.h>
32 #include <osmocom/gsm48_rr.h>
33 #include <osmocom/sysinfo.h>
34 #include <osmocom/lapdm.h>
35 #include <osmocom/gsmtap_util.h>
36 #include <osmocom/logging.h>
37 #include <osmocom/telnet_interface.h>
39 #include <osmocore/msgb.h>
40 #include <osmocore/talloc.h>
41 #include <osmocore/select.h>
42 #include <osmocore/signal.h>
44 extern struct log_target *stderr_target;
46 static int started = 0;
48 int mncc_recv_dummy(struct osmocom_ms *ms, int msg_type, void *arg);
50 int mobile_work(struct osmocom_ms *ms)
56 w |= gsm48_rsl_dequeue(ms);
57 w |= gsm48_rr_dequeue(ms);
58 w |= gsm48_mmxx_dequeue(ms);
59 w |= gsm48_mmr_dequeue(ms);
60 w |= gsm48_mmevent_dequeue(ms);
61 w |= gsm322_plmn_dequeue(ms);
62 w |= gsm322_cs_dequeue(ms);
63 w |= mncc_dequeue(ms);
70 static int signal_cb(unsigned int subsys, unsigned int signal,
71 void *handler_data, void *signal_data)
73 struct osmocom_ms *ms;
76 if (subsys != SS_L1CTL)
82 printf("L1_RESET, TODO: resend last radio request "
83 "(CCCH / dedicated / power scan)\n");
88 gsm_subscr_testcard(ms, 1, 1, "0000000000");
89 // ms->subscr.plmn_valid = 1;
90 ms->subscr.plmn_mcc = 262;
91 ms->subscr.plmn_mnc = 2;
92 ms->plmn.mode = PLMN_MODE_MANUAL;
93 /* start PLMN + cell selection process */
94 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
97 gsm322_plmn_sendmsg(ms, nmsg);
98 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
101 gsm322_cs_sendmsg(ms, nmsg);
106 int mobile_exit(struct osmocom_ms *ms)
108 struct gsm48_mmlayer *mm = &ms->mmlayer;
110 if (!mm->power_off && started) {
114 nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_IMSI_DETACH);
117 gsm48_mmevent_msg(mm->ms, nmsg);
122 /* in case there is a lockup during exit */
123 signal(SIGINT, SIG_DFL);
124 signal(SIGHUP, SIG_DFL);
125 signal(SIGTERM, SIG_DFL);
126 signal(SIGPIPE, SIG_DFL);
128 unregister_signal_handler(SS_L1CTL, &signal_cb, NULL);
138 int l23_app_init(struct osmocom_ms *ms)
140 log_parse_category_mask(stderr_target, "DCS:DPLMN:DRR:DMM:DCC:DMNCC:DPAG");
144 gsm_support_init(ms);
148 INIT_LLIST_HEAD(&ms->trans_list);
149 ms->cclayer.mncc_recv = mncc_recv_dummy;
151 l23_app_work = mobile_work;
152 register_signal_handler(SS_L1CTL, &signal_cb, NULL);
153 l23_app_exit = mobile_exit;
155 telnet_init(ms, 4242);