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/bb/common/osmocom_data.h>
30 #include <osmocom/bb/common/l1ctl.h>
31 #include <osmocom/bb/common/l23_app.h>
32 #include <osmocom/bb/common/lapdm.h>
33 #include <osmocom/bb/common/logging.h>
34 #include <osmocom/bb/mobile/gsm48_rr.h>
35 #include <osmocom/bb/mobile/sysinfo.h>
36 #include <osmocom/bb/mobile/vty.h>
37 #include <osmocom/bb/mobile/gps.h>
38 #include <osmocom/vty/telnet_interface.h>
40 #include <osmocore/msgb.h>
41 #include <osmocore/talloc.h>
42 #include <osmocore/select.h>
43 #include <osmocore/signal.h>
45 extern struct log_target *stderr_target;
46 static const char *config_file = "/etc/osmocom/osmocom.cfg";
48 extern unsigned short vty_port;
49 extern int vty_reading;
51 int mobile_started = 0;
53 int mncc_recv_mobile(struct osmocom_ms *ms, int msg_type, void *arg);
54 int mncc_recv_dummy(struct osmocom_ms *ms, int msg_type, void *arg);
56 int mobile_work(struct osmocom_ms *ms)
62 w |= gsm48_rsl_dequeue(ms);
63 w |= gsm48_rr_dequeue(ms);
64 w |= gsm48_mmxx_dequeue(ms);
65 w |= gsm48_mmr_dequeue(ms);
66 w |= gsm48_mmevent_dequeue(ms);
67 w |= gsm322_plmn_dequeue(ms);
68 w |= gsm322_cs_dequeue(ms);
69 w |= gsm_sim_job_dequeue(ms);
70 w |= mncc_dequeue(ms);
77 static int signal_cb(unsigned int subsys, unsigned int signal,
78 void *handler_data, void *signal_data)
80 struct osmocom_ms *ms;
81 struct gsm_settings *set;
84 if (subsys != SS_L1CTL)
95 /* insert test card, if enabled */
96 switch (set->sim_type) {
97 case GSM_SIM_TYPE_READER:
98 /* trigger sim card reader process */
99 gsm_subscr_simcard(ms);
101 case GSM_SIM_TYPE_TEST:
102 gsm_subscr_testcard(ms, set->test_rplmn_mcc,
103 set->test_rplmn_mnc);
106 /* no SIM, trigger PLMN selection process */
107 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
110 gsm322_plmn_sendmsg(ms, nmsg);
111 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
114 gsm322_cs_sendmsg(ms, nmsg);
122 int mobile_exit(struct osmocom_ms *ms)
124 struct gsm48_mmlayer *mm = &ms->mmlayer;
126 if (!mm->power_off && mobile_started) {
130 nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_IMSI_DETACH);
133 gsm48_mmevent_msg(mm->ms, nmsg);
138 /* in case there is a lockup during exit */
139 signal(SIGINT, SIG_DFL);
140 signal(SIGHUP, SIG_DFL);
141 signal(SIGTERM, SIG_DFL);
142 signal(SIGPIPE, SIG_DFL);
144 unregister_signal_handler(SS_L1CTL, &signal_cb, NULL);
152 gsm_settings_exit(ms);
154 printf("Power off!\n");
159 static struct vty_app_info vty_info = {
161 .version = PACKAGE_VERSION,
162 .go_parent_cb = ms_vty_go_parent,
165 int l23_app_init(struct osmocom_ms *ms)
168 struct telnet_connection dummy_conn;
170 // log_parse_category_mask(stderr_target, "DL1C:DRSL:DLAPDM:DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
171 log_parse_category_mask(stderr_target, "DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
172 log_set_log_level(stderr_target, LOGL_INFO);
177 gsm_support_init(ms);
179 gsm_settings_init(ms);
184 INIT_LLIST_HEAD(&ms->trans_list);
187 l23_app_work = mobile_work;
188 register_signal_handler(SS_L1CTL, &signal_cb, NULL);
189 l23_app_exit = mobile_exit;
193 dummy_conn.priv = NULL;
195 rc = vty_read_config_file(config_file, &dummy_conn);
197 fprintf(stderr, "Failed to parse the config file: '%s'\n",
199 fprintf(stderr, "Please check or create config file using: "
200 "'touch %s'\n", config_file);
204 telnet_init(l23_ctx, NULL, vty_port);
208 if (ms->settings.ch_cap == GSM_CAP_SDCCH)
209 ms->cclayer.mncc_recv = mncc_recv_dummy;
211 ms->cclayer.mncc_recv = mncc_recv_mobile;
213 printf("VTY available on port %u.\n", vty_port);
215 gsm_random_imei(&ms->settings);
217 l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL);
218 printf("Mobile initialized, please start phone now!\n");