[layer23] Cleanup of various 'printf' debugging
[osmocom-bb.git] / src / host / layer23 / src / mobile / gsm322.c
index 9098f24..cdb8d1a 100644 (file)
@@ -249,7 +249,6 @@ static int gsm322_sync_to_cell(struct gsm322_cellsel *cs)
                LOGP(DCS, LOGL_INFO, "No sysinfo, ccch mode NONE\n");
                cs->ccch_mode = CCCH_MODE_NONE;
        }
-//     printf("s->ccch_conf %d\n", cs->si->ccch_conf);
 
        l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL);
        return l1ctl_tx_fbsb_req(ms, cs->arfcn,
@@ -260,6 +259,8 @@ static int gsm322_sync_to_cell(struct gsm322_cellsel *cs)
 static void gsm322_unselect_cell(struct gsm322_cellsel *cs)
 {
        cs->selected = 0;
+       if (cs->si)
+               cs->si->si5 = 0; /* unset SI5* */
        cs->si = NULL;
        memset(&cs->sel_si, 0, sizeof(cs->sel_si));
        cs->sel_mcc = cs->sel_mnc = cs->sel_lac = cs->sel_id = 0;
@@ -748,12 +749,10 @@ static int gsm322_a_go_on_plmn(struct osmocom_ms *ms, struct msgb *msg)
        /* start timer, if on VPLMN of home country OR special case */
        if (!gsm_match_mnc(plmn->mcc, plmn->mnc, subscr->imsi)
         && (subscr->always_search_hplmn
-         || gsm_match_mcc(plmn->mcc, subscr->imsi))) {
-               if (subscr->sim_valid && subscr->t6m_hplmn)
-                       start_plmn_timer(plmn, subscr->t6m_hplmn * 360);
-               else
-                       start_plmn_timer(plmn, 30 * 360);
-       } else
+         || gsm_match_mcc(plmn->mcc, subscr->imsi))
+        && subscr->sim_valid && subscr->t6m_hplmn)
+               start_plmn_timer(plmn, subscr->t6m_hplmn * 360);
+       else
                stop_plmn_timer(plmn);
 
        return 0;
@@ -1998,9 +1997,10 @@ struct gsm322_ba_list *gsm322_cs_sysinfo_sacch(struct osmocom_ms *ms)
                        llist_add_tail(&ba->entry, &cs->ba_list);
                }
                /* update (add) ba list */
-               memcpy(freq, ba->freq, sizeof(freq));
+               memset(freq, 0, sizeof(freq));
                for (i = 0; i <= 1023; i++) {
-                       if ((s->freq[i].mask & FREQ_TYPE_REP))
+                       if ((s->freq[i].mask & (FREQ_TYPE_SERV
+                               | FREQ_TYPE_NCELL | FREQ_TYPE_REP)))
                                freq[i >> 3] |= (1 << (i & 7));
                }
                if (!!memcmp(freq, ba->freq, sizeof(freq))) {
@@ -2038,7 +2038,7 @@ static int gsm322_store_ba_list(struct gsm322_cellsel *cs,
        freq[cs->arfcn >> 3] |= (1 << (cs->arfcn & 7));
        for (i = 0; i <= 1023; i++) {
                if ((s->freq[i].mask &
-                       (FREQ_TYPE_SERV | FREQ_TYPE_NCELL)))
+                   (FREQ_TYPE_SERV | FREQ_TYPE_NCELL | FREQ_TYPE_REP)))
                        freq[i >> 3] |= (1 << (i & 7));
        }
        if (!!memcmp(freq, ba->freq, sizeof(freq))) {
@@ -2387,6 +2387,7 @@ static int gsm322_l1_signal(unsigned int subsys, unsigned int signal,
        struct osmocom_ms *ms;
        struct gsm322_cellsel *cs;
        struct osmobb_meas_res *mr;
+       struct osmobb_fbsb_res *fr;
        int i;
        int8_t rxlev;
 
@@ -2422,12 +2423,16 @@ static int gsm322_l1_signal(unsigned int subsys, unsigned int signal,
                gsm322_cs_powerscan(ms);
                break;
        case S_L1CTL_FBSB_RESP:
-               ms = signal_data;
+               fr = signal_data;
+               ms = fr->ms;
                cs = &ms->cellsel;
                if (cs->ccch_state == GSM322_CCCH_ST_INIT) {
-                       LOGP(DCS, LOGL_INFO, "Channel synched. (ARFCN=%d)\n",
-                               cs->arfcn);
+                       LOGP(DCS, LOGL_INFO, "Channel synched. (ARFCN=%d, "
+                               "snr=%u, BSIC=%u)\n", cs->arfcn, fr->snr,
+                               fr->bsic);
                        cs->ccch_state = GSM322_CCCH_ST_SYNC;
+                       if (cs->si)
+                               cs->si->bsic = fr->bsic;
 #if 0
                        stop_cs_timer(cs);
 
@@ -2964,8 +2969,8 @@ static int gsm322_c_switch_on(struct osmocom_ms *ms, struct msgb *msg)
        if (!subscr->sim_valid) {
                LOGP(DCS, LOGL_INFO, "Switch on without SIM.\n");
                return gsm322_c_any_cell_sel(ms, msg);
-       LOGP(DCS, LOGL_INFO, "Switch on with SIM inserted.\n");
        }
+       LOGP(DCS, LOGL_INFO, "Switch on with SIM inserted.\n");
 
        /* stay in NULL state until PLMN is selected */
 
@@ -2992,7 +2997,7 @@ static struct plmnastatelist {
        {ALL_STATES,
         GSM322_EVENT_SWITCH_OFF, gsm322_a_switch_off},
 
-       {SBIT(GSM322_A6_NO_SIM),
+       {SBIT(GSM322_A0_NULL) | SBIT(GSM322_A6_NO_SIM),
         GSM322_EVENT_SIM_INSERT, gsm322_a_switch_on},
 
        {ALL_STATES,
@@ -3101,7 +3106,7 @@ static struct plmnmstatelist {
        {ALL_STATES,
         GSM322_EVENT_SWITCH_OFF, gsm322_m_switch_off},
 
-       {SBIT(GSM322_M5_NO_SIM),
+       {SBIT(GSM322_M0_NULL) | SBIT(GSM322_M5_NO_SIM),
         GSM322_EVENT_SIM_INSERT, gsm322_m_switch_on},
 
        {ALL_STATES,