blob: 1f2f93b19142c64c7a90a43c34fdae7e86dc998c [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>
28#include <openbsc/telnet_interface.h>
29#include <openbsc/gsm_data.h>
30#include <openbsc/debug.h>
31
32#include <vty/command.h>
33#include <vty/buffer.h>
34#include <vty/vty.h>
35
36
37/* Down vty node level. */
38gDEFUN(ournode_exit,
39 ournode_exit_cmd, "exit", "Exit current mode and down to previous mode\n")
40{
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 vty->index_sub = NULL;
53 }
54 break;
55 case TRX_NODE:
56 vty->node = BTS_NODE;
57 {
58 /* set vty->index correctly ! */
59 struct gsm_bts_trx *trx = vty->index;
60 vty->index = trx->bts;
61 vty->index_sub = &trx->bts->description;
62 }
63 break;
64 case TS_NODE:
65 vty->node = TRX_NODE;
66 {
67 /* set vty->index correctly ! */
68 struct gsm_bts_trx_ts *ts = vty->index;
69 vty->index = ts->trx;
70 vty->index_sub = &ts->trx->description;
71 }
72 break;
73 case MGCP_NODE:
74 case GBPROXY_NODE:
75 case SGSN_NODE:
76 case NS_NODE:
77 vty->node = CONFIG_NODE;
78 vty->index = NULL;
79 break;
80 default:
81 break;
82 }
83 return CMD_SUCCESS;
84}
85
86/* End of configuration. */
87gDEFUN(ournode_end,
88 ournode_end_cmd, "end", "End current mode and change to enable mode.")
89{
90 switch (vty->node) {
91 case VIEW_NODE:
92 case ENABLE_NODE:
93 /* Nothing to do. */
94 break;
95 case CONFIG_NODE:
96 case GSMNET_NODE:
97 case BTS_NODE:
98 case TRX_NODE:
99 case TS_NODE:
100 case MGCP_NODE:
101 case GBPROXY_NODE:
102 case SGSN_NODE:
103 case NS_NODE:
104 case VTY_NODE:
105 vty_config_unlock(vty);
106 vty->node = ENABLE_NODE;
107 vty->index = NULL;
108 vty->index_sub = NULL;
109 break;
110 default:
111 break;
112 }
113 return CMD_SUCCESS;
114}
115