blob: 38d1ba4eaa0bcd52d8bc0956b4090da0221eed40 [file] [log] [blame]
Stefan Sperling55a954b2018-01-03 16:59:44 +01001/* SNMP-like status interface. Look-up of BTS/TRX/MSC
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +01002 *
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>
Stefan Sperling55a954b2018-01-03 16:59:44 +010028#include <osmocom/bsc/ctrl.h>
Neels Hofmeyrc0164792017-09-04 15:15:32 +020029#include <osmocom/bsc/debug.h>
30#include <osmocom/bsc/gsm_data.h>
Stefan Sperling55a954b2018-01-03 16:59:44 +010031#include <osmocom/bsc/bsc_msc_data.h>
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +010032
33extern vector ctrl_node_vec;
34
Stefan Sperling55a954b2018-01-03 16:59:44 +010035/*! \brief control interface lookup function for bsc/bts/msc gsm_data
Harald Weltea67455f2014-08-21 14:24:01 +020036 * \param[in] data Private data passed to controlif_setup()
37 * \param[in] vline Vector of the line holding the command string
38 * \param[out] node_type type (CTRL_NODE_) that was determined
39 * \param[out] node_data private dta of node that was determined
40 * \param i Current index into vline, up to which it is parsed
41 */
Harald Welte02cc2b62014-08-21 15:10:13 +020042static int bsc_ctrl_node_lookup(void *data, vector vline, int *node_type,
43 void **node_data, int *i)
Harald Weltea67455f2014-08-21 14:24:01 +020044{
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +010045 struct gsm_network *net = data;
46 struct gsm_bts *bts = NULL;
47 struct gsm_bts_trx *trx = NULL;
48 struct gsm_bts_trx_ts *ts = NULL;
Stefan Sperling55a954b2018-01-03 16:59:44 +010049 struct bsc_msc_data *msc = NULL;
Harald Weltea67455f2014-08-21 14:24:01 +020050 char *token = vector_slot(vline, *i);
51 long num;
52
53 /* TODO: We need to make sure that the following chars are digits
54 * and/or use strtol to check if number conversion was successful
55 * Right now something like net.bts_stats will not work */
56 if (!strcmp(token, "bts")) {
Harald Weltee2631872014-08-21 18:25:11 +020057 if (*node_type != CTRL_NODE_ROOT || !net)
Harald Weltea67455f2014-08-21 14:24:01 +020058 goto err_missing;
59 (*i)++;
60 if (!ctrl_parse_get_num(vline, *i, &num))
61 goto err_index;
62
63 bts = gsm_bts_num(net, num);
64 if (!bts)
65 goto err_missing;
66 *node_data = bts;
67 *node_type = CTRL_NODE_BTS;
68 } else if (!strcmp(token, "trx")) {
Harald Weltee2631872014-08-21 18:25:11 +020069 if (*node_type != CTRL_NODE_BTS || !*node_data)
Harald Weltea67455f2014-08-21 14:24:01 +020070 goto err_missing;
Harald Weltee2631872014-08-21 18:25:11 +020071 bts = *node_data;
Harald Weltea67455f2014-08-21 14:24:01 +020072 (*i)++;
73 if (!ctrl_parse_get_num(vline, *i, &num))
74 goto err_index;
75
76 trx = gsm_bts_trx_num(bts, num);
77 if (!trx)
78 goto err_missing;
79 *node_data = trx;
80 *node_type = CTRL_NODE_TRX;
81 } else if (!strcmp(token, "ts")) {
Harald Weltee2631872014-08-21 18:25:11 +020082 if (*node_type != CTRL_NODE_TRX || !*node_data)
Harald Weltea67455f2014-08-21 14:24:01 +020083 goto err_missing;
Harald Weltee2631872014-08-21 18:25:11 +020084 trx = *node_data;
Harald Weltea67455f2014-08-21 14:24:01 +020085 (*i)++;
86 if (!ctrl_parse_get_num(vline, *i, &num))
87 goto err_index;
88
89 if ((num >= 0) && (num < TRX_NR_TS))
90 ts = &trx->ts[num];
91 if (!ts)
92 goto err_missing;
93 *node_data = ts;
94 *node_type = CTRL_NODE_TS;
Stefan Sperling55a954b2018-01-03 16:59:44 +010095 } else if (!strcmp(token, "msc")) {
96 if (*node_type != CTRL_NODE_ROOT || !net)
97 goto err_missing;
98 (*i)++;
99 if (!ctrl_parse_get_num(vline, *i, &num))
100 goto err_index;
101
102 msc = osmo_msc_data_find(net, num);
103 if (!msc)
104 goto err_missing;
105 *node_data = msc;
106 *node_type = CTRL_NODE_MSC;
Harald Weltea67455f2014-08-21 14:24:01 +0200107 } else
108 return 0;
109
110 return 1;
111err_missing:
112 return -ENODEV;
113err_index:
114 return -ERANGE;
115}
116
Neels Hofmeyr73828152016-02-23 15:10:33 +0100117struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net,
118 const char *bind_addr, uint16_t port)
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +0100119{
Stefan Sperling55a954b2018-01-03 16:59:44 +0100120 return ctrl_interface_setup_dynip2(net, bind_addr, port,
121 bsc_ctrl_node_lookup,
122 _LAST_CTRL_NODE_BSC);
Holger Hans Peter Freyther49f9e5b2014-03-23 16:25:16 +0100123}