Stefan Sperling | 55a954b | 2018-01-03 16:59:44 +0100 | [diff] [blame] | 1 | /* SNMP-like status interface. Look-up of BTS/TRX/MSC |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 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> |
Stefan Sperling | 55a954b | 2018-01-03 16:59:44 +0100 | [diff] [blame] | 28 | #include <osmocom/bsc/ctrl.h> |
Neels Hofmeyr | c016479 | 2017-09-04 15:15:32 +0200 | [diff] [blame] | 29 | #include <osmocom/bsc/debug.h> |
| 30 | #include <osmocom/bsc/gsm_data.h> |
Stefan Sperling | 55a954b | 2018-01-03 16:59:44 +0100 | [diff] [blame] | 31 | #include <osmocom/bsc/bsc_msc_data.h> |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 32 | |
| 33 | extern vector ctrl_node_vec; |
| 34 | |
Stefan Sperling | 55a954b | 2018-01-03 16:59:44 +0100 | [diff] [blame] | 35 | /*! \brief control interface lookup function for bsc/bts/msc gsm_data |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 36 | * \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 Welte | 02cc2b6 | 2014-08-21 15:10:13 +0200 | [diff] [blame] | 42 | static int bsc_ctrl_node_lookup(void *data, vector vline, int *node_type, |
| 43 | void **node_data, int *i) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 44 | { |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 45 | 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 Sperling | 55a954b | 2018-01-03 16:59:44 +0100 | [diff] [blame] | 49 | struct bsc_msc_data *msc = NULL; |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 50 | 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 Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 57 | if (*node_type != CTRL_NODE_ROOT || !net) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 58 | 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 Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 69 | if (*node_type != CTRL_NODE_BTS || !*node_data) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 70 | goto err_missing; |
Harald Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 71 | bts = *node_data; |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 72 | (*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 Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 82 | if (*node_type != CTRL_NODE_TRX || !*node_data) |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 83 | goto err_missing; |
Harald Welte | e263187 | 2014-08-21 18:25:11 +0200 | [diff] [blame] | 84 | trx = *node_data; |
Harald Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 85 | (*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 Sperling | 55a954b | 2018-01-03 16:59:44 +0100 | [diff] [blame] | 95 | } 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 Welte | a67455f | 2014-08-21 14:24:01 +0200 | [diff] [blame] | 107 | } else |
| 108 | return 0; |
| 109 | |
| 110 | return 1; |
| 111 | err_missing: |
| 112 | return -ENODEV; |
| 113 | err_index: |
| 114 | return -ERANGE; |
| 115 | } |
| 116 | |
Neels Hofmeyr | 7382815 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 117 | struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, |
| 118 | const char *bind_addr, uint16_t port) |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 119 | { |
Stefan Sperling | 55a954b | 2018-01-03 16:59:44 +0100 | [diff] [blame] | 120 | return ctrl_interface_setup_dynip2(net, bind_addr, port, |
| 121 | bsc_ctrl_node_lookup, |
| 122 | _LAST_CTRL_NODE_BSC); |
Holger Hans Peter Freyther | 49f9e5b | 2014-03-23 16:25:16 +0100 | [diff] [blame] | 123 | } |