blob: 0c724d63b93ce4d9d54e28b31a4f44e8f1051720 [file] [log] [blame]
Harald Welte682ee5f2010-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 Welte682ee5f2010-05-16 22:02:16 +020028#include <openbsc/gsm_data.h>
29#include <openbsc/debug.h>
Harald Weltebd9591f2010-05-19 19:45:32 +020030#include <openbsc/gsm_subscriber.h>
Harald Welte682ee5f2010-05-16 22:02:16 +020031
Harald Weltebd9591f2010-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 Welte682ee5f2010-05-16 22:02:16 +020036
37
Harald Weltebd9591f2010-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;
Harald Weltebd9591f2010-05-19 19:45:32 +020069 default:
70 vty->node = CONFIG_NODE;
71 }
72
73 return vty->node;
74}
75
Harald Welte682ee5f2010-05-16 22:02:16 +020076/* Down vty node level. */
77gDEFUN(ournode_exit,
78 ournode_exit_cmd, "exit", "Exit current mode and down to previous mode\n")
79{
80 switch (vty->node) {
81 case GSMNET_NODE:
82 vty->node = CONFIG_NODE;
83 vty->index = NULL;
84 break;
85 case BTS_NODE:
86 vty->node = GSMNET_NODE;
87 {
88 /* set vty->index correctly ! */
89 struct gsm_bts *bts = vty->index;
90 vty->index = bts->network;
91 vty->index_sub = NULL;
92 }
93 break;
94 case TRX_NODE:
95 vty->node = BTS_NODE;
96 {
97 /* set vty->index correctly ! */
98 struct gsm_bts_trx *trx = vty->index;
99 vty->index = trx->bts;
100 vty->index_sub = &trx->bts->description;
101 }
102 break;
103 case TS_NODE:
104 vty->node = TRX_NODE;
105 {
106 /* set vty->index correctly ! */
107 struct gsm_bts_trx_ts *ts = vty->index;
108 vty->index = ts->trx;
109 vty->index_sub = &ts->trx->description;
110 }
111 break;
112 case MGCP_NODE:
113 case GBPROXY_NODE:
114 case SGSN_NODE:
115 case NS_NODE:
Harald Welte4b326982010-05-17 23:20:56 +0200116 case BSSGP_NODE:
Harald Welte682ee5f2010-05-16 22:02:16 +0200117 vty->node = CONFIG_NODE;
118 vty->index = NULL;
119 break;
120 default:
121 break;
122 }
123 return CMD_SUCCESS;
124}
125
126/* End of configuration. */
127gDEFUN(ournode_end,
128 ournode_end_cmd, "end", "End current mode and change to enable mode.")
129{
130 switch (vty->node) {
131 case VIEW_NODE:
132 case ENABLE_NODE:
133 /* Nothing to do. */
134 break;
135 case CONFIG_NODE:
136 case GSMNET_NODE:
137 case BTS_NODE:
138 case TRX_NODE:
139 case TS_NODE:
140 case MGCP_NODE:
141 case GBPROXY_NODE:
142 case SGSN_NODE:
143 case NS_NODE:
144 case VTY_NODE:
145 vty_config_unlock(vty);
146 vty->node = ENABLE_NODE;
147 vty->index = NULL;
148 vty->index_sub = NULL;
149 break;
150 default:
151 break;
152 }
153 return CMD_SUCCESS;
154}
155