blob: 9d22146756767fc57fd96325433c25146c2d3fa4 [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
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <stdlib.h>
23#include <string.h>
24
25#include <osmocore/talloc.h>
26
27#include <openbsc/vty.h>
Harald Welte5bc61dc2010-05-16 22:02:16 +020028#include <openbsc/gsm_data.h>
29#include <openbsc/debug.h>
Harald Welte4b037e42010-05-19 19:45:32 +020030#include <openbsc/gsm_subscriber.h>
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +080031#include <openbsc/bsc_nat.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>
Harald Welte5bc61dc2010-05-16 22:02:16 +020037
38
Holger Hans Peter Freyther57da4472010-06-08 16:11:06 +080039enum node_type bsc_vty_go_parent(struct vty *vty)
Harald Welte4b037e42010-05-19 19:45:32 +020040{
41 switch (vty->node) {
42 case GSMNET_NODE:
43 vty->node = CONFIG_NODE;
44 vty->index = NULL;
45 break;
46 case BTS_NODE:
47 vty->node = GSMNET_NODE;
48 {
49 /* set vty->index correctly ! */
50 struct gsm_bts *bts = vty->index;
51 vty->index = bts->network;
52 }
53 break;
54 case TRX_NODE:
55 vty->node = BTS_NODE;
56 {
57 /* set vty->index correctly ! */
58 struct gsm_bts_trx *trx = vty->index;
59 vty->index = trx->bts;
60 }
61 break;
62 case TS_NODE:
63 vty->node = TRX_NODE;
64 {
65 /* set vty->index correctly ! */
66 struct gsm_bts_trx_ts *ts = vty->index;
67 vty->index = ts->trx;
68 }
69 break;
Harald Welte64632322010-05-31 17:17:29 +020070 case OML_NODE:
71 vty->node = ENABLE_NODE;
72 talloc_free(vty->index);
73 vty->index = NULL;
74 break;
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +080075 case NAT_NODE:
76 vty->node = CONFIG_NODE;
77 vty->index = NULL;
78 break;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +080079 case NAT_BSC_NODE:
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +080080 vty->node = NAT_NODE;
81 {
82 struct bsc_config *bsc_config = vty->index;
83 vty->index = bsc_config->nat;
84 }
85 break;
Harald Welte4b037e42010-05-19 19:45:32 +020086 default:
87 vty->node = CONFIG_NODE;
88 }
89
90 return vty->node;
91}
92
Harald Welte5bc61dc2010-05-16 22:02:16 +020093/* Down vty node level. */
94gDEFUN(ournode_exit,
95 ournode_exit_cmd, "exit", "Exit current mode and down to previous mode\n")
96{
97 switch (vty->node) {
98 case GSMNET_NODE:
99 vty->node = CONFIG_NODE;
100 vty->index = NULL;
101 break;
102 case BTS_NODE:
103 vty->node = GSMNET_NODE;
104 {
105 /* set vty->index correctly ! */
106 struct gsm_bts *bts = vty->index;
107 vty->index = bts->network;
108 vty->index_sub = NULL;
109 }
110 break;
111 case TRX_NODE:
112 vty->node = BTS_NODE;
113 {
114 /* set vty->index correctly ! */
115 struct gsm_bts_trx *trx = vty->index;
116 vty->index = trx->bts;
117 vty->index_sub = &trx->bts->description;
118 }
119 break;
120 case TS_NODE:
121 vty->node = TRX_NODE;
122 {
123 /* set vty->index correctly ! */
124 struct gsm_bts_trx_ts *ts = vty->index;
125 vty->index = ts->trx;
126 vty->index_sub = &ts->trx->description;
127 }
128 break;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800129 case NAT_BSC_NODE:
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +0800130 vty->node = NAT_NODE;
131 {
132 struct bsc_config *bsc_config = vty->index;
133 vty->index = bsc_config->nat;
134 }
135 break;
Harald Welte5bc61dc2010-05-16 22:02:16 +0200136 case MGCP_NODE:
137 case GBPROXY_NODE:
138 case SGSN_NODE:
139 case NS_NODE:
Harald Welte5fa2f442010-05-17 23:20:56 +0200140 case BSSGP_NODE:
Holger Hans Peter Freytherab52c842010-06-15 20:11:16 +0800141 case NAT_NODE:
Harald Welte5bc61dc2010-05-16 22:02:16 +0200142 vty->node = CONFIG_NODE;
143 vty->index = NULL;
144 break;
Harald Welte64632322010-05-31 17:17:29 +0200145 case OML_NODE:
146 vty->node = ENABLE_NODE;
147 talloc_free(vty->index);
148 vty->index = NULL;
149 break;
Harald Welte5bc61dc2010-05-16 22:02:16 +0200150 default:
151 break;
152 }
153 return CMD_SUCCESS;
154}
155
156/* End of configuration. */
157gDEFUN(ournode_end,
158 ournode_end_cmd, "end", "End current mode and change to enable mode.")
159{
160 switch (vty->node) {
161 case VIEW_NODE:
162 case ENABLE_NODE:
163 /* Nothing to do. */
164 break;
165 case CONFIG_NODE:
166 case GSMNET_NODE:
167 case BTS_NODE:
168 case TRX_NODE:
169 case TS_NODE:
170 case MGCP_NODE:
171 case GBPROXY_NODE:
172 case SGSN_NODE:
173 case NS_NODE:
174 case VTY_NODE:
Holger Hans Peter Freyther5654c5b2010-07-31 04:50:21 +0800175 case NAT_NODE:
176 case NAT_BSC_NODE:
Harald Welte5bc61dc2010-05-16 22:02:16 +0200177 vty_config_unlock(vty);
178 vty->node = ENABLE_NODE;
179 vty->index = NULL;
180 vty->index_sub = NULL;
181 break;
182 default:
183 break;
184 }
185 return CMD_SUCCESS;
186}
187
Holger Hans Peter Freyther7a2c86b2010-08-26 15:38:42 +0800188int bsc_vty_is_config_node(struct vty *vty, int node)
189{
190 switch (node) {
191 /* add items that are not config */
192 case OML_NODE:
193 case SUBSCR_NODE:
194 return 0;
195
196 default:
197 return 1;
198 }
199}