Change in osmo-bsc[master]: change bs_power to bs_power_db

laforge gerrit-no-reply at lists.osmocom.org
Sat Jun 5 14:35:17 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/24421 )

Change subject: change bs_power to bs_power_db
......................................................................

change bs_power to bs_power_db

The RSL BS Power IE in measurement reports is encoded as dB / 2.
Instead of using this coding all over the code, converting to dB and
often printing confusing values in logging etc, store as plain dB.

The conversions should be at the points where a "weird" format is
defined: the RSL encoding needs divided-by-two, so apply it there. The
meas_vis is (now unfortunately) defined as div-two, and so on. But
internally we now just store the plain dB value and calculate with it
without duplicating the wire decoding step everywhere.

Rename to bs_power_db to clarify the unit of the stored value.

Change-Id: I229db1d6bcf532af95aff56b2ad18b5ed9d81616
---
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/meas_rep.h
M src/osmo-bsc/abis_rsl.c
M src/osmo-bsc/bsc_vty.c
M src/osmo-bsc/lchan_fsm.c
M src/osmo-bsc/meas_rep.c
M src/utils/meas_db.c
M src/utils/meas_json.c
8 files changed, 21 insertions(+), 18 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  fixeria: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 1540864..2515d7e 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -686,7 +686,7 @@
 	/* The logical channel type */
 	enum gsm_chan_t type;
 	/* Power levels for MS and BTS */
-	uint8_t bs_power;
+	uint8_t bs_power_db;
 	uint8_t ms_power;
 	/* Encryption information */
 	struct gsm_encr encr;
diff --git a/include/osmocom/bsc/meas_rep.h b/include/osmocom/bsc/meas_rep.h
index b0c03f0..54e0519 100644
--- a/include/osmocom/bsc/meas_rep.h
+++ b/include/osmocom/bsc/meas_rep.h
@@ -38,7 +38,7 @@
 	struct gsm_meas_rep_unidir ul;
 	struct gsm_meas_rep_unidir dl;
 
-	uint8_t bs_power;
+	uint8_t bs_power_db;
 	/* according to 3GPP TS 48.058 § MS Timing Offset [-63; 192] */
 	int16_t ms_timing_offset;
 	struct {
diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c
index 00bb5dc..8e64ce5 100644
--- a/src/osmo-bsc/abis_rsl.c
+++ b/src/osmo-bsc/abis_rsl.c
@@ -300,6 +300,7 @@
 	struct abis_rsl_dchan_hdr *dh;
 	struct msgb *msg;
 	uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
+	uint8_t bs_power_enc;
 
 	db = abs(db);
 	if (db > 30)
@@ -307,15 +308,15 @@
 
 	msg = rsl_msgb_alloc();
 
-	lchan->bs_power = db/2;
+	bs_power_enc = db / 2;
 	if (fpc)
-		lchan->bs_power |= 0x10;
+		bs_power_enc |= 0x10;
 
 	dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
 	init_dchan_hdr(dh, RSL_MT_BS_POWER_CONTROL);
 	dh->chan_nr = chan_nr;
 
-	msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
+	msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power_enc);
 
 	/* BS Power Control Parameters (if supported by BTS model) */
 	add_power_control_params(msg, RSL_IE_BS_POWER_PARAM, lchan);
@@ -579,7 +580,7 @@
 	}
 
 	if (bts->bs_power_ctrl.mode != GSM_PWR_CTRL_MODE_NONE)
-		msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
+		msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power_db / 2);
 	if (bts->ms_power_ctrl.mode != GSM_PWR_CTRL_MODE_NONE)
 		msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
 
@@ -1044,7 +1045,7 @@
 		DEBUGPC(DMEAS, "DTXd ");
 
 	print_meas_rep_uni(&mr->ul, "ul");
-	DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power);
+	DEBUGPC(DMEAS, "BS_POWER=%ddB ", mr->bs_power_db);
 
 	if (mr->flags & MEAS_REP_F_MS_TO)
 		DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);
@@ -1099,6 +1100,7 @@
 	uint8_t len;
 	const uint8_t *val;
 	int rc;
+	uint8_t bs_power_enc;
 
 	if (!lchan_may_receive_data(msg->lchan)) {
 		LOG_LCHAN(msg->lchan, LOGL_DEBUG, "MEAS RES for inactive channel\n");
@@ -1132,7 +1134,8 @@
 		mr->ul.sub.rx_qual = val[2] & 0x7;
 	}
 
-	mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
+	bs_power_enc = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
+	mr->bs_power_db = (bs_power_enc & 0x0f) * 2;
 
 	/* Optional Parts */
 	if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET)) {
diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c
index 1db284a..724a3b0 100644
--- a/src/osmo-bsc/bsc_vty.c
+++ b/src/osmo-bsc/bsc_vty.c
@@ -1640,7 +1640,7 @@
 		VTY_NEWLINE);
 	vty_out(vty, "  BS Power: %u dBm, MS Power: %u dBm%s",
 		lchan->ts->trx->nominal_power - lchan->ts->trx->max_power_red
-		- lchan->bs_power*2,
+		- lchan->bs_power_db,
 		ms_pwr_dbm(lchan->ts->trx->bts->band, lchan->ms_power),
 		VTY_NEWLINE);
 	vty_out(vty, "  Channel Mode / Codec: %s%s",
diff --git a/src/osmo-bsc/lchan_fsm.c b/src/osmo-bsc/lchan_fsm.c
index 48cfbdf..17e0c89 100644
--- a/src/osmo-bsc/lchan_fsm.c
+++ b/src/osmo-bsc/lchan_fsm.c
@@ -614,18 +614,18 @@
 	if (old_lchan && old_lchan->ts->trx->bts == bts) {
 		ms_power_dbm = ms_pwr_dbm(bts->band, old_lchan->ms_power);
 		lchan_update_ms_power_ctrl_level(lchan, ms_power_dbm >= 0 ? ms_power_dbm : bts->ms_max_power);
-		lchan->bs_power = old_lchan->bs_power;
+		lchan->bs_power_db = old_lchan->bs_power_db;
 	} else {
 		lchan_update_ms_power_ctrl_level(lchan, bts->ms_max_power);
 		/* Upon last entering the UNUSED state, from lchan_reset():
-		 * - bs_power is still zero, 0dB reduction, output power = Pn.
+		 * - bs_power_db is still zero, 0dB reduction, output power = Pn.
 		 * - TA is still zero, to be determined by RACH. */
 
 		/* Default BS Power reduction value (in 2 dB steps) */
 		if (bts->bs_power_ctrl.mode == GSM_PWR_CTRL_MODE_DYN_BTS)
-			lchan->bs_power = bts->bs_power_ctrl.bs_power_max_db / 2;
+			lchan->bs_power_db = bts->bs_power_ctrl.bs_power_max_db;
 		else
-			lchan->bs_power = bts->bs_power_ctrl.bs_power_val_db / 2;
+			lchan->bs_power_db = bts->bs_power_ctrl.bs_power_val_db;
 	}
 
 	if (gsm48_chan_mode_to_non_vamos(info->ch_mode_rate.chan_mode) == GSM48_CMODE_SPEECH_AMR) {
diff --git a/src/osmo-bsc/meas_rep.c b/src/osmo-bsc/meas_rep.c
index 9b2fca0..32c689d 100644
--- a/src/osmo-bsc/meas_rep.c
+++ b/src/osmo-bsc/meas_rep.c
@@ -32,14 +32,14 @@
 		if (!(rep->flags & MEAS_REP_F_DL_VALID))
 			return -EINVAL;
 		/* Add BS Power value to rxlev: improve the RXLEV value by the amount of power that the BTS is reducing
-		 * transmission. Note that bs_power is coded as dB/2, a positive value indicating the amount of power reduction
+		 * transmission. Note that bs_power is coded as dB, a positive value indicating the amount of power reduction
 		 * on the downlink; rxlev is coded in dB, where a higher number means stronger signal. */
-		return rep->dl.full.rx_lev + (rep->bs_power * 2);
+		return rep->dl.full.rx_lev + rep->bs_power_db;
 	case MEAS_REP_DL_RXLEV_SUB:
 		if (!(rep->flags & MEAS_REP_F_DL_VALID))
 			return -EINVAL;
 		/* Apply BS Power as explained above */
-		return rep->dl.sub.rx_lev + (rep->bs_power * 2);
+		return rep->dl.sub.rx_lev + rep->bs_power_db;
 	case MEAS_REP_DL_RXQUAL_FULL:
 		if (!(rep->flags & MEAS_REP_F_DL_VALID))
 			return -EINVAL;
diff --git a/src/utils/meas_db.c b/src/utils/meas_db.c
index 7233dcd..4fc2916 100644
--- a/src/utils/meas_db.c
+++ b/src/utils/meas_db.c
@@ -111,7 +111,7 @@
 
 
 	SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 5, mr->nr));
-	SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 6, mr->bs_power));
+	SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 6, mr->bs_power_db / 2));
 
 	if (mr->flags & MEAS_REP_F_MS_TO)
 		SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 7, mr->ms_timing_offset));
diff --git a/src/utils/meas_json.c b/src/utils/meas_json.c
index b44a300..82b1e57 100644
--- a/src/utils/meas_json.c
+++ b/src/utils/meas_json.c
@@ -62,7 +62,7 @@
 	printf(", \"UL_MEAS\":{");
 	print_meas_rep_uni_json(&mr->ul);
 	printf("}");
-	printf(", \"BS_POWER\":%d", mr->bs_power);
+	printf(", \"BS_POWER\":%d", mr->bs_power_db / 2);
 	if (mr->flags & MEAS_REP_F_MS_TO)
 		printf(", \"MS_TO\":%d", mr->ms_timing_offset);
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/24421
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I229db1d6bcf532af95aff56b2ad18b5ed9d81616
Gerrit-Change-Number: 24421
Gerrit-PatchSet: 9
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-CC: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210605/b2c36978/attachment.htm>


More information about the gerrit-log mailing list