[layer23] Implementation of signal loss criteria as defined in TS 05.08
[osmocom-bb.git] / src / host / layer23 / src / mobile / gsm322.c
index 6addff6..807c662 100644 (file)
@@ -236,6 +236,7 @@ static int gsm322_sync_to_cell(struct gsm322_cellsel *cs)
 {
        struct osmocom_ms *ms = cs->ms;
        struct gsm48_sysinfo *s = cs->si;
+       struct rx_meas_stat *meas = &ms->meas;
 
        cs->ccch_state = GSM322_CCCH_ST_INIT;
        if (s && s->si3) {
@@ -257,6 +258,8 @@ static int gsm322_sync_to_cell(struct gsm322_cellsel *cs)
                cs->ccch_mode = CCCH_MODE_NONE;
        }
 
+       meas->frames = meas->snr = meas->berr = meas->rxlev = 0;
+
        l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL);
        return l1ctl_tx_fbsb_req(ms, cs->arfcn,
                                 L1CTL_FBSB_F_FB01SB, 100, 0,
@@ -443,30 +446,6 @@ void start_cs_timer(struct gsm322_cellsel *cs, int sec, int micro)
        bsc_schedule_timer(&cs->timer, sec, micro);
 }
 
-/* start loss timer */
-void start_loss_timer(struct gsm322_cellsel *cs, int sec, int micro)
-{
-       /* update timer */
-       cs->timer.cb = gsm322_cs_loss;
-       cs->timer.data = cs;
-       if (bsc_timer_pending(&cs->timer)) {
-               struct timeval current_time;
-               unsigned long long currentTime;
-
-               gettimeofday(&current_time, NULL);
-               currentTime = current_time.tv_sec * 1000000LL
-                               + current_time.tv_usec;
-               currentTime += sec * 1000000LL + micro;
-               cs->timer.timeout.tv_sec = currentTime / 1000000LL;
-               cs->timer.timeout.tv_usec = currentTime % 1000000LL;
-
-               return;
-       }
-
-       LOGP(DCS, LOGL_DEBUG, "Starting loss CS timer with %d seconds.\n", sec);
-       bsc_schedule_timer(&cs->timer, sec, micro);
-}
-
 /* stop cell selection timer */
 static void stop_cs_timer(struct gsm322_cellsel *cs)
 {
@@ -2418,7 +2397,7 @@ static int gsm322_l1_signal(unsigned int subsys, unsigned int signal,
                cs->list[i].flags |= GSM322_CS_FLAG_POWER;
                cs->list[i].flags &= ~GSM322_CS_FLAG_SIGNAL;
                /* if minimum level is reached or if we stick to a cell */
-               if (rxlev2dbm(rxlev) >= ms->support.min_rxlev_db
+               if (rxlev2dbm(rxlev) >= ms->settings.min_rxlev_db
                 || ms->settings.stick) {
                        cs->list[i].flags |= GSM322_CS_FLAG_SIGNAL;
                        LOGP(DCS, LOGL_INFO, "Found signal (frequency %d "
@@ -2465,6 +2444,10 @@ static int gsm322_l1_signal(unsigned int subsys, unsigned int signal,
                         || cs->state == GSM322_HPLMN_SEARCH)
                                start_cs_timer(cs, ms->support.scan_to, 0);
                                        // TODO: timer depends on BCCH config
+
+                       /* set downlink signalling failure criterion */
+                       ms->meas.ds_fail = ms->meas.dsc = ms->settings.dsc_max;
+                       LOGP(DRR, LOGL_INFO, "using DSC of %d\n", ms->meas.dsc);
                }
                break;
        case S_L1CTL_FBSB_ERR:
@@ -2488,6 +2471,11 @@ static int gsm322_l1_signal(unsigned int subsys, unsigned int signal,
                else
                        gsm322_cs_timeout(cs);
                break;
+       case S_L1CTL_LOSS_IND:
+               ms = signal_data;
+               cs = &ms->cellsel;
+               gsm322_cs_loss(cs);
+               break;
        case S_L1CTL_RESET:
                ms = signal_data;
                if (ms->mmlayer.power_off_idle) {