blob: 440209a68b46128979b4d2a374364d9aefa86b11 [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;
Harald Welte64632322010-05-31 17:17:29 +020069 case OML_NODE:
70 vty->node = ENABLE_NODE;
71 talloc_free(vty->index);
72 vty->index = NULL;
73 break;
Harald Welte4b037e42010-05-19 19:45:32 +020074 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;
Harald Welte64632322010-05-31 17:17:29 +0200125 case OML_NODE:
126 vty->node = ENABLE_NODE;
127 talloc_free(vty->index);
128 vty->index = NULL;
129 break;
Harald Welte5bc61dc2010-05-16 22:02:16 +0200130 default:
131 break;
132 }
133 return CMD_SUCCESS;
134}
135
136/* End of configuration. */
137gDEFUN(ournode_end,
138 ournode_end_cmd, "end", "End current mode and change to enable mode.")
139{
140 switch (vty->node) {
141 case VIEW_NODE:
142 case ENABLE_NODE:
143 /* Nothing to do. */
144 break;
145 case CONFIG_NODE:
146 case GSMNET_NODE:
147 case BTS_NODE:
148 case TRX_NODE:
149 case TS_NODE:
150 case MGCP_NODE:
151 case GBPROXY_NODE:
152 case SGSN_NODE:
153 case NS_NODE:
154 case VTY_NODE:
155 vty_config_unlock(vty);
156 vty->node = ENABLE_NODE;
157 vty->index = NULL;
158 vty->index_sub = NULL;
159 break;
160 default:
161 break;
162 }
163 return CMD_SUCCESS;
164}
165