From 9bd9ba476c7280b97d9dad5b247f126e7c4b343b Mon Sep 17 00:00:00 2001 From: Matan Perelman Date: Tue, 30 Jan 2024 17:06:37 +0200 Subject: [PATCH] ctrl: Add ms power This new command allows to control MS power level for a specific logical channel using net.btsN.trxM.tsI.lchanL.ms-power This patch also adds a lchan node to the ctrl interface. Depends: libosmocore.git Ibf2786f668ee7e4f5b6a9ef43f2141cd2d79b4e2 Change-Id: I6f556b66011be6126d6bac31a14101ba37f81cc4 --- include/osmocom/bsc/ctrl.h | 1 + src/osmo-bsc/Makefile.am | 1 + src/osmo-bsc/bsc_ctrl_lookup.c | 15 ++++++ src/osmo-bsc/bts_trx_ts_ctrl.c | 2 + src/osmo-bsc/bts_trx_ts_lchan_ctrl.c | 74 ++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 src/osmo-bsc/bts_trx_ts_lchan_ctrl.c diff --git a/include/osmocom/bsc/ctrl.h b/include/osmocom/bsc/ctrl.h index 0d6c8a0e8..86eb3b114 100644 --- a/include/osmocom/bsc/ctrl.h +++ b/include/osmocom/bsc/ctrl.h @@ -12,6 +12,7 @@ struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port); int bsc_bts_ctrl_cmds_install(void); int bsc_bts_trx_ctrl_cmds_install(void); int bsc_bts_trx_ts_ctrl_cmds_install(void); +int bsc_bts_trx_ts_lchan_ctrl_cmds_install(void); void ctrl_generate_bts_location_state_trap(struct gsm_bts *bts, struct bsc_msc_data *msc); void osmo_bsc_send_trap(struct ctrl_cmd *cmd, struct bsc_msc_data *msc_data); diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am index e577c95dd..10265235e 100644 --- a/src/osmo-bsc/Makefile.am +++ b/src/osmo-bsc/Makefile.am @@ -47,6 +47,7 @@ libbsc_la_SOURCES = \ bts_trx.c \ bts_trx_ctrl.c \ bts_trx_ts_ctrl.c \ + bts_trx_ts_lchan_ctrl.c \ bts_ericsson_rbs2000.c \ bts_init.c \ bts_ipaccess_nanobts.c \ diff --git a/src/osmo-bsc/bsc_ctrl_lookup.c b/src/osmo-bsc/bsc_ctrl_lookup.c index 145cda320..effad4fcd 100644 --- a/src/osmo-bsc/bsc_ctrl_lookup.c +++ b/src/osmo-bsc/bsc_ctrl_lookup.c @@ -43,6 +43,7 @@ static int bsc_ctrl_node_lookup(void *data, vector vline, int *node_type, struct gsm_bts *bts = NULL; struct gsm_bts_trx *trx = NULL; struct gsm_bts_trx_ts *ts = NULL; + struct gsm_lchan *lchan = NULL; struct bsc_msc_data *msc = NULL; char *token = vector_slot(vline, *i); long num; @@ -89,6 +90,20 @@ static int bsc_ctrl_node_lookup(void *data, vector vline, int *node_type, goto err_missing; *node_data = ts; *node_type = CTRL_NODE_TS; + } else if (!strcmp(token, "lchan")) { + if (*node_type != CTRL_NODE_TS || !*node_data) + goto err_missing; + ts = *node_data; + (*i)++; + if (!ctrl_parse_get_num(vline, *i, &num)) + goto err_index; + + if ((num >= 0) && (num < TS_MAX_LCHAN)) + lchan = &ts->lchan[num]; + if (!lchan) + goto err_missing; + *node_data = lchan; + *node_type = CTRL_NODE_LCHAN; } else if (!strcmp(token, "msc")) { if (*node_type != CTRL_NODE_ROOT || !net) goto err_missing; diff --git a/src/osmo-bsc/bts_trx_ts_ctrl.c b/src/osmo-bsc/bts_trx_ts_ctrl.c index dc8aaf42e..f0a592d44 100644 --- a/src/osmo-bsc/bts_trx_ts_ctrl.c +++ b/src/osmo-bsc/bts_trx_ts_ctrl.c @@ -102,5 +102,7 @@ int bsc_bts_trx_ts_ctrl_cmds_install(void) rc |= ctrl_cmd_install(CTRL_NODE_TS, &cmd_ts_hopping_arfcn_add); rc |= ctrl_cmd_install(CTRL_NODE_TS, &cmd_ts_hopping_arfcn_del); + rc |= bsc_bts_trx_ts_lchan_ctrl_cmds_install(); + return rc; } diff --git a/src/osmo-bsc/bts_trx_ts_lchan_ctrl.c b/src/osmo-bsc/bts_trx_ts_lchan_ctrl.c new file mode 100644 index 000000000..a17855626 --- /dev/null +++ b/src/osmo-bsc/bts_trx_ts_lchan_ctrl.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2019-2024 by sysmocom s.f.m.c. GmbH + * + * 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. + * + */ + +#include + +#include +#include +#include +#include + +static int verify_lchan_ms_power(struct ctrl_cmd *cmd, const char *value, void *_data) +{ + int ms_power = atoi(cmd->value); + + if (ms_power < 0 || ms_power > 40) { + cmd->reply = "Value is out of range"; + return 1; + } + + return 0; +} + +/* power control management: Get lchan's ms power in dBm + * format: bts.<0-255>.trx.<0-255>.ts.<0-8>.lchan.<0-8>.ms-power */ +static int get_lchan_ms_power(struct ctrl_cmd *cmd, void *data) +{ + struct gsm_lchan *lchan = cmd->node; + + cmd->reply = talloc_asprintf(cmd, "%u", ms_pwr_dbm(lchan->ts->trx->bts->band, lchan->ms_power)); + if (!cmd->reply) { + cmd->reply = "OOM"; + return CTRL_CMD_ERROR; + } + + return CTRL_CMD_REPLY; +} + +/* power control management: Set lchan's ms power in dBm. + * For static ms power control it will change the ms tx power. + * For dynamic ms power control it will limit the maximum power level. + * format: bts.<0-255>.trx.<0-255>.ts.<0-8>.lchan.<0-8>.ms-power + * ms power is in range 0..40 */ +static int set_lchan_ms_power(struct ctrl_cmd *cmd, void *data) +{ + struct gsm_lchan *lchan = cmd->node; + + lchan->ms_power = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, atoi(cmd->value)); + rsl_chan_ms_power_ctrl(lchan); + cmd->reply = "OK"; + return CTRL_CMD_REPLY; +} + +CTRL_CMD_DEFINE(lchan_ms_power, "ms-power"); + +int bsc_bts_trx_ts_lchan_ctrl_cmds_install(void) +{ + int rc = 0; + + rc |= ctrl_cmd_install(CTRL_NODE_LCHAN, &cmd_lchan_ms_power); + + return rc; +}