Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 1 | /* 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 Welte | ba874b8 | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | |
| 26 | #include <osmocom/vty/command.h> |
| 27 | #include <osmocom/ctrl/control_if.h> |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 28 | #include <openbsc/debug.h> |
Harald Welte | ba874b8 | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 29 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 30 | |
| 31 | extern vector ctrl_node_vec; |
| 32 | |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 33 | /*! \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 Welte | 02cc2b6 | 2014-08-21 15:10:13 +0200 | [diff] [blame] | 40 | static int bsc_ctrl_node_lookup(void *data, vector vline, int *node_type, |
| 41 | void **node_data, int *i) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 42 | { |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 43 | 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 Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 47 | 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 Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 54 | if (*node_type != CTRL_NODE_ROOT || !net) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 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")) { |
Harald Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 66 | if (*node_type != CTRL_NODE_BTS || !*node_data) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 67 | goto err_missing; |
Harald Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 68 | bts = *node_data; |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 69 | (*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 Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 79 | if (*node_type != CTRL_NODE_TRX || !*node_data) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 80 | goto err_missing; |
Harald Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 81 | trx = *node_data; |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 82 | (*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; |
| 96 | err_missing: |
| 97 | return -ENODEV; |
| 98 | err_index: |
| 99 | return -ERANGE; |
| 100 | } |
| 101 | |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 102 | struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port) |
| 103 | { |
Harald Welte | 74d4adc | 2014-08-21 15:25:25 +0200 | [diff] [blame] | 104 | return ctrl_interface_setup(net, port, bsc_ctrl_node_lookup); |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 105 | } |