Harald Welte | 5bc61dc | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 1 | /* 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. */ |
| 38 | gDEFUN(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: |
Harald Welte | 5fa2f44 | 2010-05-17 23:20:56 +0200 | [diff] [blame] | 77 | case BSSGP_NODE: |
Harald Welte | 5bc61dc | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 78 | vty->node = CONFIG_NODE; |
| 79 | vty->index = NULL; |
| 80 | break; |
| 81 | default: |
| 82 | break; |
| 83 | } |
| 84 | return CMD_SUCCESS; |
| 85 | } |
| 86 | |
| 87 | /* End of configuration. */ |
| 88 | gDEFUN(ournode_end, |
| 89 | ournode_end_cmd, "end", "End current mode and change to enable mode.") |
| 90 | { |
| 91 | switch (vty->node) { |
| 92 | case VIEW_NODE: |
| 93 | case ENABLE_NODE: |
| 94 | /* Nothing to do. */ |
| 95 | break; |
| 96 | case CONFIG_NODE: |
| 97 | case GSMNET_NODE: |
| 98 | case BTS_NODE: |
| 99 | case TRX_NODE: |
| 100 | case TS_NODE: |
| 101 | case MGCP_NODE: |
| 102 | case GBPROXY_NODE: |
| 103 | case SGSN_NODE: |
| 104 | case NS_NODE: |
| 105 | case VTY_NODE: |
| 106 | vty_config_unlock(vty); |
| 107 | vty->node = ENABLE_NODE; |
| 108 | vty->index = NULL; |
| 109 | vty->index_sub = NULL; |
| 110 | break; |
| 111 | default: |
| 112 | break; |
| 113 | } |
| 114 | return CMD_SUCCESS; |
| 115 | } |
| 116 | |