2014-03-23 15:25:16 +00:00
|
|
|
/* SNMP-like status interface. Look-up of BTS/TRX
|
|
|
|
*
|
|
|
|
* (C) 2010-2011 by Daniel Willmann <daniel@totalueberwachung.de>
|
|
|
|
* (C) 2010-2011 by On-Waves
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-08-20 21:47:15 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <osmocom/vty/command.h>
|
|
|
|
#include <osmocom/ctrl/control_if.h>
|
2014-03-23 15:25:16 +00:00
|
|
|
#include <openbsc/debug.h>
|
2014-08-20 21:47:15 +00:00
|
|
|
#include <openbsc/gsm_data.h>
|
2014-03-23 15:25:16 +00:00
|
|
|
|
|
|
|
extern vector ctrl_node_vec;
|
|
|
|
|
2014-08-21 12:24:01 +00:00
|
|
|
/*! \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
|
|
|
|
*/
|
2014-08-21 13:10:13 +00:00
|
|
|
static int bsc_ctrl_node_lookup(void *data, vector vline, int *node_type,
|
|
|
|
void **node_data, int *i)
|
2014-08-21 12:24:01 +00:00
|
|
|
{
|
2014-03-23 15:25:16 +00:00
|
|
|
struct gsm_network *net = data;
|
|
|
|
struct gsm_bts *bts = NULL;
|
|
|
|
struct gsm_bts_trx *trx = NULL;
|
|
|
|
struct gsm_bts_trx_ts *ts = NULL;
|
2014-08-21 12:24:01 +00:00
|
|
|
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, "bts")) {
|
|
|
|
if (!net)
|
|
|
|
goto err_missing;
|
|
|
|
(*i)++;
|
|
|
|
if (!ctrl_parse_get_num(vline, *i, &num))
|
|
|
|
goto err_index;
|
|
|
|
|
|
|
|
bts = gsm_bts_num(net, num);
|
|
|
|
if (!bts)
|
|
|
|
goto err_missing;
|
|
|
|
*node_data = bts;
|
|
|
|
*node_type = CTRL_NODE_BTS;
|
|
|
|
} else if (!strcmp(token, "trx")) {
|
|
|
|
if (!bts)
|
|
|
|
goto err_missing;
|
|
|
|
(*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 (!trx)
|
|
|
|
goto err_missing;
|
|
|
|
(*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;
|
|
|
|
}
|
|
|
|
|
2014-03-23 15:25:16 +00:00
|
|
|
struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port)
|
|
|
|
{
|
2014-08-21 13:25:25 +00:00
|
|
|
return ctrl_interface_setup(net, port, bsc_ctrl_node_lookup);
|
2014-03-23 15:25:16 +00:00
|
|
|
}
|