blob: 1443791f02696ccfda19583b433eadbe6c0d2f11 [file] [log] [blame]
Harald Welte5bc61dc2010-05-16 22:02:16 +02001/* OpenBSC VTY common helpers */
2/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
3 * (C) 2009-2010 by Holger Hans Peter Freyther
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Harald Welte5bc61dc2010-05-16 22:02:16 +02009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Harald Welte5bc61dc2010-05-16 22:02:16 +020015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte5bc61dc2010-05-16 22:02:16 +020018 *
19 */
20
21#include <stdlib.h>
22#include <string.h>
23
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010024#include <osmocom/core/talloc.h>
Harald Welte5bc61dc2010-05-16 22:02:16 +020025
26#include <openbsc/vty.h>
Harald Welte5bc61dc2010-05-16 22:02:16 +020027#include <openbsc/gsm_data.h>
28#include <openbsc/debug.h>
Harald Welte4b037e42010-05-19 19:45:32 +020029#include <openbsc/gsm_subscriber.h>
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +080030#include <openbsc/bsc_nat.h>
Harald Welteeae68292016-11-11 19:41:59 +010031#include <openbsc/abis_om2000.h>
Harald Welte5bc61dc2010-05-16 22:02:16 +020032
Harald Welte4b037e42010-05-19 19:45:32 +020033#include <osmocom/vty/telnet_interface.h>
34#include <osmocom/vty/command.h>
35#include <osmocom/vty/buffer.h>
36#include <osmocom/vty/vty.h>
Philipp Maierefe85d32017-04-09 12:32:51 +020037#include <osmocom/sigtran/osmo_ss7.h>
Harald Welte5bc61dc2010-05-16 22:02:16 +020038
39
Holger Hans Peter Freyther3e4e8cf2015-09-24 15:38:38 +020040int bsc_vty_go_parent(struct vty *vty)
Harald Welte4b037e42010-05-19 19:45:32 +020041{
42 switch (vty->node) {
43 case GSMNET_NODE:
44 vty->node = CONFIG_NODE;
45 vty->index = NULL;
46 break;
47 case BTS_NODE:
48 vty->node = GSMNET_NODE;
49 {
50 /* set vty->index correctly ! */
51 struct gsm_bts *bts = vty->index;
52 vty->index = bts->network;
Harald Welte5bc61dc2010-05-16 22:02:16 +020053 vty->index_sub = NULL;
54 }
55 break;
56 case TRX_NODE:
57 vty->node = BTS_NODE;
58 {
59 /* set vty->index correctly ! */
60 struct gsm_bts_trx *trx = vty->index;
61 vty->index = trx->bts;
62 vty->index_sub = &trx->bts->description;
63 }
64 break;
65 case TS_NODE:
66 vty->node = TRX_NODE;
67 {
68 /* set vty->index correctly ! */
69 struct gsm_bts_trx_ts *ts = vty->index;
70 vty->index = ts->trx;
71 vty->index_sub = &ts->trx->description;
72 }
73 break;
Jacob Erlbeck190acf62013-09-02 13:17:15 +020074 case OML_NODE:
75 case OM2K_NODE:
76 vty->node = ENABLE_NODE;
77 /* NOTE: this only works because it's not part of the config
78 * tree, where outer commands are searched via vty_go_parent()
79 * and only (!) executed when a matching one is found.
80 */
81 talloc_free(vty->index);
82 vty->index = NULL;
83 break;
Harald Welteeae68292016-11-11 19:41:59 +010084 case OM2K_CON_GROUP_NODE:
85 vty->node = BTS_NODE;
86 {
87 struct con_group *cg = vty->index;
88 struct gsm_bts *bts = cg->bts;
89 vty->index = bts;
90 vty->index_sub = &bts->description;
91 }
92 break;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +080093 case NAT_BSC_NODE:
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +080094 vty->node = NAT_NODE;
95 {
96 struct bsc_config *bsc_config = vty->index;
97 vty->index = bsc_config->nat;
98 }
99 break;
Holger Hans Peter Freyther6860c442011-05-02 19:16:13 +0200100 case PGROUP_NODE:
101 vty->node = NAT_NODE;
Jacob Erlbeck190acf62013-09-02 13:17:15 +0200102 vty->index = NULL;
103 break;
104 case TRUNK_NODE:
105 vty->node = MGCP_NODE;
106 vty->index = NULL;
Holger Hans Peter Freyther6860c442011-05-02 19:16:13 +0200107 break;
Harald Welte338e3b32012-11-20 22:22:04 +0100108 case SMPP_ESME_NODE:
109 vty->node = SMPP_NODE;
110 vty->index = NULL;
111 break;
112 case SMPP_NODE:
Harald Welte5bc61dc2010-05-16 22:02:16 +0200113 case MGCP_NODE:
114 case GBPROXY_NODE:
115 case SGSN_NODE:
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +0800116 case NAT_NODE:
Holger Hans Peter Freyther8b902d72011-06-04 20:22:49 +0200117 case BSC_NODE:
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800118 case MSC_NODE:
Harald Welteab386e62011-09-01 18:18:43 +0200119 case MNCC_INT_NODE:
Holger Hans Peter Freyther925c57f2015-01-27 10:58:29 +0100120 case NITB_NODE:
Philipp Maierefe85d32017-04-09 12:32:51 +0200121 vty->node = CONFIG_NODE;
Jacob Erlbeck190acf62013-09-02 13:17:15 +0200122 vty->index = NULL;
Philipp Maierefe85d32017-04-09 12:32:51 +0200123 break;
124 case SUBSCR_NODE:
125 vty->node = ENABLE_NODE;
126 vty->index = NULL;
127 break;
128 default:
129 osmo_ss7_vty_go_parent(vty);
Harald Welte5bc61dc2010-05-16 22:02:16 +0200130 }
Jacob Erlbeck190acf62013-09-02 13:17:15 +0200131
132 return vty->node;
133}
134
Holger Hans Peter Freyther7a2c86b2010-08-26 15:38:42 +0800135int bsc_vty_is_config_node(struct vty *vty, int node)
136{
Philipp Maierefe85d32017-04-09 12:32:51 +0200137 /* Check if libosmo-sccp declares the node in
138 * question as config node */
139 if (osmo_ss7_is_config_node(vty, node))
140 return 1;
141
Holger Hans Peter Freyther7a2c86b2010-08-26 15:38:42 +0800142 switch (node) {
143 /* add items that are not config */
144 case OML_NODE:
Harald Welte810e3232011-02-12 15:00:35 +0100145 case OM2K_NODE:
Holger Hans Peter Freyther7a2c86b2010-08-26 15:38:42 +0800146 case SUBSCR_NODE:
Holger Hans Peter Freyther6ffca132010-09-04 11:15:27 +0800147 case CONFIG_NODE:
Holger Hans Peter Freyther7a2c86b2010-08-26 15:38:42 +0800148 return 0;
149
150 default:
151 return 1;
152 }
153}