[layer23] Fix of GPS states
[osmocom-bb.git] / src / host / layer23 / src / mobile / app_mobile.c
index 154768b..6ba4b9e 100644 (file)
@@ -46,10 +46,12 @@ extern struct log_target *stderr_target;
 static const char *config_file = "/etc/osmocom/osmocom.cfg";
 extern void *l23_ctx;
 extern unsigned short vty_port;
+extern int vty_reading;
 
 int mobile_started = 0;
 
 int mncc_recv_mobile(struct osmocom_ms *ms, int msg_type, void *arg);
+int mncc_recv_dummy(struct osmocom_ms *ms, int msg_type, void *arg);
 
 int mobile_work(struct osmocom_ms *ms)
 {
@@ -101,20 +103,17 @@ static int signal_cb(unsigned int subsys, unsigned int signal,
                                                set->test_rplmn_mnc);
                        break;
                default:
-                       /* no SIM */
-                       ;
+                       /* no SIM, trigger PLMN selection process */
+                       nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
+                       if (!nmsg)
+                               return -ENOMEM;
+                       gsm322_plmn_sendmsg(ms, nmsg);
+                       nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
+                       if (!nmsg)
+                               return -ENOMEM;
+                       gsm322_cs_sendmsg(ms, nmsg);
                }
 
-               /* start PLMN + cell selection process */
-               nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
-               if (!nmsg)
-                       return -ENOMEM;
-               gsm322_plmn_sendmsg(ms, nmsg);
-               nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
-               if (!nmsg)
-                       return -ENOMEM;
-               gsm322_cs_sendmsg(ms, nmsg);
-
                mobile_started = 1;
        }
        return 0;
@@ -150,6 +149,7 @@ int mobile_exit(struct osmocom_ms *ms)
        gsm_subscr_exit(ms);
        gsm48_cc_exit(ms);
        gsm_sim_exit(ms);
+       gsm_settings_exit(ms);
 
        printf("Power off!\n");
 
@@ -167,20 +167,21 @@ int l23_app_init(struct osmocom_ms *ms)
        int rc;
        struct telnet_connection dummy_conn;
 
-//     log_parse_category_mask(stderr_target, "DRSL:DLAPDM:DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
+//     log_parse_category_mask(stderr_target, "DL1C:DRSL:DLAPDM:DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
        log_parse_category_mask(stderr_target, "DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
+       log_set_log_level(stderr_target, LOGL_INFO);
 
        srand(time(NULL));
 
+       gps_init();
+       gsm_support_init(ms);
        gsm_sim_init(ms);
        gsm_settings_init(ms);
        gsm48_cc_init(ms);
-       gsm_support_init(ms);
        gsm_subscr_init(ms);
        gsm48_rr_init(ms);
        gsm48_mm_init(ms);
        INIT_LLIST_HEAD(&ms->trans_list);
-       ms->cclayer.mncc_recv = mncc_recv_mobile;
        gsm322_init(ms);
 
        l23_app_work = mobile_work;
@@ -190,6 +191,7 @@ int l23_app_init(struct osmocom_ms *ms)
        vty_init(&vty_info);
        ms_vty_init();
        dummy_conn.priv = NULL;
+       vty_reading = 1;
        rc = vty_read_config_file(config_file, &dummy_conn);
        if (rc < 0) {
                fprintf(stderr, "Failed to parse the config file: '%s'\n",
@@ -198,9 +200,16 @@ int l23_app_init(struct osmocom_ms *ms)
                        "'touch %s'\n", config_file);
                return rc;
        }
+       vty_reading = 0;
        telnet_init(l23_ctx, NULL, vty_port);
        if (rc < 0)
                return rc;
+
+       if (ms->settings.ch_cap == GSM_CAP_SDCCH)
+               ms->cclayer.mncc_recv = mncc_recv_dummy;
+       else
+               ms->cclayer.mncc_recv = mncc_recv_mobile;
+
        printf("VTY available on port %u.\n", vty_port);
 
        gsm_random_imei(&ms->settings);