blob: f28b8414c7d08c39c2de7dd92e2334060688d8fe [file] [log] [blame]
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +01001/* SNMP-like status interface. Look-up of BTS/TRX
2 *
3 * (C) 2010-2011 by Daniel Willmann <daniel@totalueberwachung.de>
4 * (C) 2010-2011 by On-Waves
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
Harald Welteba874b82014-08-20 23:47:15 +020024#include <errno.h>
25
26#include <osmocom/vty/command.h>
27#include <osmocom/ctrl/control_if.h>
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +010028#include <openbsc/debug.h>
Harald Welteba874b82014-08-20 23:47:15 +020029#include <openbsc/gsm_data.h>
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +010030
31extern vector ctrl_node_vec;
32
Harald Weltea67455f2014-08-21 14:24:01 +020033/*! \brief control interface lookup function for bsc/bts gsm_data
34 * \param[in] data Private data passed to controlif_setup()
35 * \param[in] vline Vector of the line holding the command string
36 * \param[out] node_type type (CTRL_NODE_) that was determined
37 * \param[out] node_data private dta of node that was determined
38 * \param i Current index into vline, up to which it is parsed
39 */
Harald Welte02cc2b62014-08-21 15:10:13 +020040static int bsc_ctrl_node_lookup(void *data, vector vline, int *node_type,
41 void **node_data, int *i)
Harald Weltea67455f2014-08-21 14:24:01 +020042{
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +010043 struct gsm_network *net = data;
44 struct gsm_bts *bts = NULL;
45 struct gsm_bts_trx *trx = NULL;
46 struct gsm_bts_trx_ts *ts = NULL;
Harald Weltea67455f2014-08-21 14:24:01 +020047 char *token = vector_slot(vline, *i);
48 long num;
49
50 /* TODO: We need to make sure that the following chars are digits
51 * and/or use strtol to check if number conversion was successful
52 * Right now something like net.bts_stats will not work */
53 if (!strcmp(token, "bts")) {
54 if (!net)
55 goto err_missing;
56 (*i)++;
57 if (!ctrl_parse_get_num(vline, *i, &num))
58 goto err_index;
59
60 bts = gsm_bts_num(net, num);
61 if (!bts)
62 goto err_missing;
63 *node_data = bts;
64 *node_type = CTRL_NODE_BTS;
65 } else if (!strcmp(token, "trx")) {
66 if (!bts)
67 goto err_missing;
68 (*i)++;
69 if (!ctrl_parse_get_num(vline, *i, &num))
70 goto err_index;
71
72 trx = gsm_bts_trx_num(bts, num);
73 if (!trx)
74 goto err_missing;
75 *node_data = trx;
76 *node_type = CTRL_NODE_TRX;
77 } else if (!strcmp(token, "ts")) {
78 if (!trx)
79 goto err_missing;
80 (*i)++;
81 if (!ctrl_parse_get_num(vline, *i, &num))
82 goto err_index;
83
84 if ((num >= 0) && (num < TRX_NR_TS))
85 ts = &trx->ts[num];
86 if (!ts)
87 goto err_missing;
88 *node_data = ts;
89 *node_type = CTRL_NODE_TS;
90 } else
91 return 0;
92
93 return 1;
94err_missing:
95 return -ENODEV;
96err_index:
97 return -ERANGE;
98}
99
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +0100100struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port)
101{
Harald Welte02cc2b62014-08-21 15:10:13 +0200102 return controlif_setup(net, port, bsc_ctrl_node_lookup);
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +0100103}