diff options
Diffstat (limited to 'src/host/virt_phy/src/virt_prim_pm.c')
-rw-r--r-- | src/host/virt_phy/src/virt_prim_pm.c | 93 |
1 files changed, 60 insertions, 33 deletions
diff --git a/src/host/virt_phy/src/virt_prim_pm.c b/src/host/virt_phy/src/virt_prim_pm.c index 312461c4..9afee0c8 100644 --- a/src/host/virt_phy/src/virt_prim_pm.c +++ b/src/host/virt_phy/src/virt_prim_pm.c @@ -1,3 +1,26 @@ + +/* (C) 2010 by Dieter Spaar <spaar@mirider.augusta.de> + * (C) 2010 by Harald Welte <laforge@gnumonks.org> + * (C) 2016 by Sebastian Stumpf <sebastian.stumpf87@googlemail.com> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + #include <stdint.h> #include <stdio.h> #include <string.h> @@ -22,19 +45,26 @@ static struct l1_model_ms *l1_model_ms = NULL; * @param [in] arfcn to change sig str for. * @param [in] sig_lev the measured signal level value. */ -uint16_t prim_pm_set_sig_strength(uint16_t arfcn, int16_t sig_lev) { - if(l1_model_ms->state->pm.timeout_s > 0 || l1_model_ms->state->pm.timeout_us > 0) { - osmo_timer_schedule(&l1_model_ms->state->pm.meas.arfcn_sig_lev_timers[arfcn], l1_model_ms->state->pm.timeout_s, l1_model_ms->state->pm.timeout_us); +uint16_t prim_pm_set_sig_strength(uint16_t arfcn, int16_t sig_lev) +{ + if (l1_model_ms->state->pm.timeout_s > 0 || l1_model_ms->state->pm.timeout_us > 0) { + osmo_timer_schedule(&l1_model_ms->state->pm.meas.arfcn_sig_lev_timers[arfcn], + l1_model_ms->state->pm.timeout_s, + l1_model_ms->state->pm.timeout_us); } - l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn] = sig_lev - l1_model_ms->state->pm.meas.arfcn_sig_lev_red_dbm[arfcn]; - DEBUGP(DL1C, "Power measurement set for arfcn %u. Set signal level to %d (== rxlev: %u).\n", arfcn, l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn], dbm2rxlev(l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn])); + l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn] = + sig_lev - l1_model_ms->state->pm.meas.arfcn_sig_lev_red_dbm[arfcn]; + DEBUGP(DL1C, "Power measurement set for arfcn %u. Set signal level to %d (== rxlev: %u).\n", + arfcn, l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn], + dbm2rxlev(l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn])); return l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn]; } -void prim_pm_timer_cb(void *data) { - // reset the signal level to bad value if no messages have been received from that rfcn for a given time - DEBUGP(DL1C, - "Timeout occurred for arfcn, signal level reset to worst value.\n"); +void prim_pm_timer_cb(void *data) +{ + /* reset the signal level to bad value if no messages have been + * received from that rfcn for a given time */ + DEBUGP(DL1C, "Timeout occurred for arfcn, signal level reset to worst value.\n"); *((int16_t*)data) = MIN_SIG_LEV_DBM; } @@ -45,50 +75,47 @@ void prim_pm_timer_cb(void *data) { * * @param [in] msg the received message. * - * Process power measurement for a given range of arfcns to calculate signal power and connection quality. - * - * Note: This should only be called after a certain time so some messages have already been received. + * Process power measurement for a given range of arfcns to calculate + * signal power and connection quality. * + * Note: This should only be called after a certain time so some + * messages have already been received. */ void l1ctl_rx_pm_req(struct msgb *msg) { - struct l1ctl_hdr *l1h = (struct l1ctl_hdr *)msg->data; - struct l1ctl_pm_req *pm_req = (struct l1ctl_pm_req *)l1h->data; + struct l1ctl_hdr *l1h = (struct l1ctl_hdr *) msg->data; + struct l1ctl_pm_req *pm_req = (struct l1ctl_pm_req *) l1h->data; struct msgb *resp_msg = l1ctl_msgb_alloc(L1CTL_PM_CONF); uint16_t arfcn_next; - // convert to host order + + /* convert to host order */ pm_req->range.band_arfcn_from = ntohs(pm_req->range.band_arfcn_from); pm_req->range.band_arfcn_to = ntohs(pm_req->range.band_arfcn_to); - DEBUGP(DL1C, - "Received from l23 - L1CTL_PM_REQ TYPE=%u, FROM=%d, TO=%d\n", - pm_req->type, pm_req->range.band_arfcn_from, - pm_req->range.band_arfcn_to); + DEBUGP(DL1C, "Received from l23 - L1CTL_PM_REQ TYPE=%u, FROM=%d, TO=%d\n", + pm_req->type, pm_req->range.band_arfcn_from, pm_req->range.band_arfcn_to); for (arfcn_next = pm_req->range.band_arfcn_from; - arfcn_next <= pm_req->range.band_arfcn_to; - ++arfcn_next) { - struct l1ctl_pm_conf *pm_conf = - (struct l1ctl_pm_conf *)msgb_put(resp_msg, - sizeof(*pm_conf)); + arfcn_next <= pm_req->range.band_arfcn_to; ++arfcn_next) { + struct l1ctl_pm_conf *pm_conf = (struct l1ctl_pm_conf *) msgb_put(resp_msg, sizeof(*pm_conf)); pm_conf->band_arfcn = htons(arfcn_next); - // set min and max to the value calculated for that arfcn (IGNORE UPLINKK AND PCS AND OTHER FLAGS) + /* set min and max to the value calculated for that + * arfcn (IGNORE UPLINKK AND PCS AND OTHER FLAGS) */ pm_conf->pm[0] = dbm2rxlev(l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn_next & ARFCN_NO_FLAGS_MASK]); pm_conf->pm[1] = dbm2rxlev(l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[arfcn_next & ARFCN_NO_FLAGS_MASK]); if (arfcn_next == pm_req->range.band_arfcn_to) { struct l1ctl_hdr *resp_l1h = msgb_l1(resp_msg); resp_l1h->flags |= L1CTL_F_DONE; } - // no more space to hold mor pm info in msgb, flush to l23 + /* no more space to hold mor pm info in msgb, flush to l23 */ if (msgb_tailroom(resp_msg) < sizeof(*pm_conf)) { l1ctl_sap_tx_to_l23(resp_msg); resp_msg = l1ctl_msgb_alloc(L1CTL_PM_CONF); } } - // transmit the remaining part of pm response to l23 - if (resp_msg) { + /* transmit the remaining part of pm response to l23 */ + if (resp_msg) l1ctl_sap_tx_to_l23(resp_msg); - } } /** @@ -100,10 +127,10 @@ void prim_pm_init(struct l1_model_ms *model) { int i; l1_model_ms = model; - // init the signal level of all arfcns with the lowest value possible - memset (model->state->pm.meas.arfcn_sig_lev_dbm, MIN_SIG_LEV_DBM, sizeof (int16_t) * 1024); - // init timers - for(i = 0; i < 1024; ++i) { + /* init the signal level of all arfcns with the lowest value possible */ + memset(model->state->pm.meas.arfcn_sig_lev_dbm, MIN_SIG_LEV_DBM, sizeof (int16_t) * 1024); + /* init timers */ + for (i = 0; i < 1024; ++i) { l1_model_ms->state->pm.meas.arfcn_sig_lev_timers[i].cb = prim_pm_timer_cb; l1_model_ms->state->pm.meas.arfcn_sig_lev_timers[i].data = &l1_model_ms->state->pm.meas.arfcn_sig_lev_dbm[i]; } |