diff --git a/include/osmo-bts/control_if.h b/include/osmo-bts/control_if.h new file mode 100644 index 000000000..e50238a47 --- /dev/null +++ b/include/osmo-bts/control_if.h @@ -0,0 +1,3 @@ +#pragma once + +struct ctrl_handle *bts_controlif_setup(struct gsm_bts *bts, uint16_t port); diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 77f73b473..10627e2aa 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -7,4 +7,4 @@ libbts_a_SOURCES = gsm_data_shared.c sysinfo.c logging.c abis.c oml.c bts.c \ rsl.c vty.c paging.c measurement.c amr.c lchan.c \ load_indication.c pcu_sock.c handover.c msg_utils.c \ load_indication.c pcu_sock.c handover.c msg_utils.c \ - tx_power.c + tx_power.c bts_ctrl_commands.c bts_ctrl_lookup.c diff --git a/src/common/bts_ctrl_commands.c b/src/common/bts_ctrl_commands.c new file mode 100644 index 000000000..6d223ff71 --- /dev/null +++ b/src/common/bts_ctrl_commands.c @@ -0,0 +1,78 @@ +/* Control Interface for osmo-bts */ + +/* (C) 2014 by Harald Welte + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include + +#include + +#include +#include +#include + +CTRL_CMD_DEFINE(therm_att, "thermal-attenuation"); +static int get_therm_att(struct ctrl_cmd *cmd, void *data) +{ + struct gsm_bts_trx *trx = cmd->node; + struct trx_power_params *tpp = &trx->power_params; + + cmd->reply = talloc_asprintf(cmd, "%d", tpp->thermal_attenuation_mdB); + + return CTRL_CMD_REPLY; +} + +static int set_therm_att(struct ctrl_cmd *cmd, void *data) +{ + struct gsm_bts_trx *trx = cmd->node; + struct trx_power_params *tpp = &trx->power_params; + int val = atoi(cmd->value); + + printf("set_therm_att(trx=%p, tpp=%p)\n", trx, tpp); + + tpp->thermal_attenuation_mdB = val; + + power_ramp_start(trx, tpp->p_total_cur_mdBm, 0); + + return get_therm_att(cmd, data); +} + +static int verify_therm_att(struct ctrl_cmd *cmd, const char *value, void *data) +{ + int val = atoi(value); + + /* permit between 0 to 40 dB attenuation */ + if (val < 0 || val > to_mdB(40)) + return 1; + + return 0; +} + + +int bts_ctrl_cmds_install(struct gsm_bts *bts) +{ + int rc = 0; + + rc |= ctrl_cmd_install(CTRL_NODE_TRX, &cmd_therm_att); + + return rc; +} diff --git a/src/common/bts_ctrl_lookup.c b/src/common/bts_ctrl_lookup.c new file mode 100644 index 000000000..ec6434e0c --- /dev/null +++ b/src/common/bts_ctrl_lookup.c @@ -0,0 +1,103 @@ +/* Control Interface for osmo-bts */ + +/* (C) 2014 by Harald Welte + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License + * along with this program. If not, see . + * + */ + +#include + +#include +#include +#include +#include + +extern vector ctrl_node_vec; + +/*! \brief control interface lookup function for bsc/bts gsm_data + * \param[in] data Private data passed to controlif_setup() + * \param[in] vline Vector of the line holding the command string + * \param[out] node_type type (CTRL_NODE_) that was determined + * \param[out] node_data private dta of node that was determined + * \param i Current index into vline, up to which it is parsed + */ +static int bts_ctrl_node_lookup(void *data, vector vline, int *node_type, + void **node_data, int *i) +{ + struct gsm_bts *bts = data; + struct gsm_bts_trx *trx = NULL; + struct gsm_bts_trx_ts *ts = NULL; + char *token = vector_slot(vline, *i); + long num; + + /* TODO: We need to make sure that the following chars are digits + * and/or use strtol to check if number conversion was successful + * Right now something like net.bts_stats will not work */ + if (!strcmp(token, "trx")) { + if (*node_type != CTRL_NODE_ROOT || !*node_data) + goto err_missing; + bts = *node_data; + (*i)++; + if (!ctrl_parse_get_num(vline, *i, &num)) + goto err_index; + + trx = gsm_bts_trx_num(bts, num); + if (!trx) + goto err_missing; + *node_data = trx; + *node_type = CTRL_NODE_TRX; + } else if (!strcmp(token, "ts")) { + if (*node_type != CTRL_NODE_TRX || !*node_data) + goto err_missing; + trx = *node_data; + (*i)++; + if (!ctrl_parse_get_num(vline, *i, &num)) + goto err_index; + + if ((num >= 0) && (num < TRX_NR_TS)) + ts = &trx->ts[num]; + if (!ts) + goto err_missing; + *node_data = ts; + *node_type = CTRL_NODE_TS; + } else + return 0; + + return 1; +err_missing: + return -ENODEV; +err_index: + return -ERANGE; +} + +struct ctrl_handle *bts_controlif_setup(struct gsm_bts *bts, uint16_t port) +{ + struct ctrl_handle *hdl; + int rc = 0; + + hdl = ctrl_interface_setup(bts, port, bts_ctrl_node_lookup); + if (!hdl) + return NULL; + + rc = bts_ctrl_cmds_install(bts); + if (rc) { + /* FIXME: close control interface */ + return NULL; + } + + return hdl; +} diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c index d12421df1..8c930965e 100644 --- a/src/osmo-bts-sysmo/main.c +++ b/src/osmo-bts-sysmo/main.c @@ -45,6 +45,7 @@ #include #include #include +#include #define SYSMOBTS_RF_LOCK_PATH "/var/lock/bts_rf_lock" @@ -290,6 +291,8 @@ static int write_pid_file(char *procname) return 0; } +extern int sysmobts_ctrlif_inst_cmds(void); + int main(int argc, char **argv) { struct stat st; @@ -348,6 +351,8 @@ int main(int argc, char **argv) } write_pid_file("osmo-bts"); + bts_controlif_setup(bts, 3333); + rc = telnet_init(tall_bts_ctx, NULL, 4241); if (rc < 0) { fprintf(stderr, "Error initializing telnet\n");