2014-08-24 08:44:31 +00:00
|
|
|
/* Control Interface for osmo-bts */
|
|
|
|
|
|
|
|
/* (C) 2014 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
*
|
|
|
|
* 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
|
2024-02-17 09:17:14 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2014-08-24 08:44:31 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <osmocom/vty/command.h>
|
|
|
|
#include <osmocom/ctrl/control_if.h>
|
2014-08-24 14:55:30 +00:00
|
|
|
#include <osmocom/ctrl/ports.h>
|
2016-01-17 11:36:22 +00:00
|
|
|
#include <osmo-bts/bts_model.h>
|
2014-08-24 08:44:31 +00:00
|
|
|
#include <osmo-bts/logging.h>
|
|
|
|
#include <osmo-bts/gsm_data.h>
|
2016-01-04 19:29:24 +00:00
|
|
|
#include <osmo-bts/control_if.h>
|
2020-07-03 15:27:01 +00:00
|
|
|
#include <osmo-bts/bts_trx.h>
|
2014-08-24 08:44:31 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-17 17:46:47 +00:00
|
|
|
struct ctrl_handle *bts_controlif_setup(struct gsm_bts *bts, uint16_t port)
|
2014-08-24 08:44:31 +00:00
|
|
|
{
|
|
|
|
struct ctrl_handle *hdl;
|
|
|
|
int rc = 0;
|
|
|
|
|
2022-12-17 17:46:47 +00:00
|
|
|
hdl = ctrl_interface_setup(bts, port, bts_ctrl_node_lookup);
|
2014-08-24 08:44:31 +00:00
|
|
|
if (!hdl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
rc = bts_ctrl_cmds_install(bts);
|
|
|
|
if (rc) {
|
|
|
|
/* FIXME: close control interface */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-09 08:49:09 +00:00
|
|
|
rc = bts_model_ctrl_cmds_install(bts);
|
|
|
|
if (rc) {
|
|
|
|
/* FIXME: cleanup generic control commands */
|
|
|
|
/* FIXME: close control interface */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-08-24 08:44:31 +00:00
|
|
|
return hdl;
|
|
|
|
}
|