blob: a8a8cf526ec035cdc7daf1982ea9e7ee5d8cd59a [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")) {
Harald Weltee2631872014-08-21 18:25:11 +020054 if (*node_type != CTRL_NODE_ROOT || !net)
Harald Weltea67455f2014-08-21 14:24:01 +020055 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")) {
Harald Weltee2631872014-08-21 18:25:11 +020066 if (*node_type != CTRL_NODE_BTS || !*node_data)
Harald Weltea67455f2014-08-21 14:24:01 +020067 goto err_missing;
Harald Weltee2631872014-08-21 18:25:11 +020068 bts = *node_data;
Harald Weltea67455f2014-08-21 14:24:01 +020069 (*i)++;
70 if (!ctrl_parse_get_num(vline, *i, &num))
71 goto err_index;
72
73 trx = gsm_bts_trx_num(bts, num);
74 if (!trx)
75 goto err_missing;
76 *node_data = trx;
77 *node_type = CTRL_NODE_TRX;
78 } else if (!strcmp(token, "ts")) {
Harald Weltee2631872014-08-21 18:25:11 +020079 if (*node_type != CTRL_NODE_TRX || !*node_data)
Harald Weltea67455f2014-08-21 14:24:01 +020080 goto err_missing;
Harald Weltee2631872014-08-21 18:25:11 +020081 trx = *node_data;
Harald Weltea67455f2014-08-21 14:24:01 +020082 (*i)++;
83 if (!ctrl_parse_get_num(vline, *i, &num))
84 goto err_index;
85
86 if ((num >= 0) && (num < TRX_NR_TS))
87 ts = &trx->ts[num];
88 if (!ts)
89 goto err_missing;
90 *node_data = ts;
91 *node_type = CTRL_NODE_TS;
92 } else
93 return 0;
94
95 return 1;
96err_missing:
97 return -ENODEV;
98err_index:
99 return -ERANGE;
100}
101
Neels Hofmeyr73828152016-02-23 15:10:33 +0100102struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net,
103 const char *bind_addr, uint16_t port)
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +0100104{
Neels Hofmeyr73828152016-02-23 15:10:33 +0100105 return ctrl_interface_setup_dynip(net, bind_addr, port,
106 bsc_ctrl_node_lookup);
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +0100107}