blob: eb0d29e3833d255c31ca62dd6fbad97d410e558a [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>
Harald Welte5bc61dc2010-05-16 22:02:16 +020031
Harald Welte4b037e42010-05-19 19:45:32 +020032#include <osmocom/vty/telnet_interface.h>
33#include <osmocom/vty/command.h>
34#include <osmocom/vty/buffer.h>
35#include <osmocom/vty/vty.h>
Harald Welte5bc61dc2010-05-16 22:02:16 +020036
37
Harald Welte4b037e42010-05-19 19:45:32 +020038int bsc_vty_go_parent(struct vty *vty)
39{
40 switch (vty->node) {
41 case GSMNET_NODE:
42 vty->node = CONFIG_NODE;
43 vty->index = NULL;
44 break;
45 case BTS_NODE:
46 vty->node = GSMNET_NODE;
47 {
48 /* set vty->index correctly ! */
49 struct gsm_bts *bts = vty->index;
50 vty->index = bts->network;
51 }
52 break;
53 case TRX_NODE:
54 vty->node = BTS_NODE;
55 {
56 /* set vty->index correctly ! */
57 struct gsm_bts_trx *trx = vty->index;
58 vty->index = trx->bts;
59 }
60 break;
61 case TS_NODE:
62 vty->node = TRX_NODE;
63 {
64 /* set vty->index correctly ! */
65 struct gsm_bts_trx_ts *ts = vty->index;
66 vty->index = ts->trx;
67 }
68 break;
69 case SUBSCR_NODE:
70 vty->node = VIEW_NODE;
71 subscr_put(vty->index);
72 vty->index = NULL;
73 break;
74 default:
75 vty->node = CONFIG_NODE;
76 }
77
78 return vty->node;
79}
80
Harald Welte5bc61dc2010-05-16 22:02:16 +020081/* Down vty node level. */
82gDEFUN(ournode_exit,
83 ournode_exit_cmd, "exit", "Exit current mode and down to previous mode\n")
84{
85 switch (vty->node) {
86 case GSMNET_NODE:
87 vty->node = CONFIG_NODE;
88 vty->index = NULL;
89 break;
90 case BTS_NODE:
91 vty->node = GSMNET_NODE;
92 {
93 /* set vty->index correctly ! */
94 struct gsm_bts *bts = vty->index;
95 vty->index = bts->network;
96 vty->index_sub = NULL;
97 }
98 break;
99 case TRX_NODE:
100 vty->node = BTS_NODE;
101 {
102 /* set vty->index correctly ! */
103 struct gsm_bts_trx *trx = vty->index;
104 vty->index = trx->bts;
105 vty->index_sub = &trx->bts->description;
106 }
107 break;
108 case TS_NODE:
109 vty->node = TRX_NODE;
110 {
111 /* set vty->index correctly ! */
112 struct gsm_bts_trx_ts *ts = vty->index;
113 vty->index = ts->trx;
114 vty->index_sub = &ts->trx->description;
115 }
116 break;
117 case MGCP_NODE:
118 case GBPROXY_NODE:
119 case SGSN_NODE:
120 case NS_NODE:
Harald Welte5fa2f442010-05-17 23:20:56 +0200121 case BSSGP_NODE:
Harald Welte5bc61dc2010-05-16 22:02:16 +0200122 vty->node = CONFIG_NODE;
123 vty->index = NULL;
124 break;
125 default:
126 break;
127 }
128 return CMD_SUCCESS;
129}
130
131/* End of configuration. */
132gDEFUN(ournode_end,
133 ournode_end_cmd, "end", "End current mode and change to enable mode.")
134{
135 switch (vty->node) {
136 case VIEW_NODE:
137 case ENABLE_NODE:
138 /* Nothing to do. */
139 break;
140 case CONFIG_NODE:
141 case GSMNET_NODE:
142 case BTS_NODE:
143 case TRX_NODE:
144 case TS_NODE:
145 case MGCP_NODE:
146 case GBPROXY_NODE:
147 case SGSN_NODE:
148 case NS_NODE:
149 case VTY_NODE:
150 vty_config_unlock(vty);
151 vty->node = ENABLE_NODE;
152 vty->index = NULL;
153 vty->index_sub = NULL;
154 break;
155 default:
156 break;
157 }
158 return CMD_SUCCESS;
159}
160