Harald Welte | 682ee5f | 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> |
Harald Welte | 682ee5f | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 28 | #include <openbsc/gsm_data.h> |
| 29 | #include <openbsc/debug.h> |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 30 | #include <openbsc/gsm_subscriber.h> |
Holger Hans Peter Freyther | 256a040 | 2010-06-15 20:11:16 +0800 | [diff] [blame] | 31 | #include <openbsc/bsc_nat.h> |
Harald Welte | 682ee5f | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 32 | |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 33 | #include <osmocom/vty/telnet_interface.h> |
| 34 | #include <osmocom/vty/command.h> |
| 35 | #include <osmocom/vty/buffer.h> |
| 36 | #include <osmocom/vty/vty.h> |
Harald Welte | 682ee5f | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 37 | |
| 38 | |
Holger Hans Peter Freyther | 3538c77 | 2010-06-08 16:11:06 +0800 | [diff] [blame] | 39 | enum node_type bsc_vty_go_parent(struct vty *vty) |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 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 | } |
| 53 | break; |
| 54 | case TRX_NODE: |
| 55 | vty->node = BTS_NODE; |
| 56 | { |
| 57 | /* set vty->index correctly ! */ |
| 58 | struct gsm_bts_trx *trx = vty->index; |
| 59 | vty->index = trx->bts; |
| 60 | } |
| 61 | break; |
| 62 | case TS_NODE: |
| 63 | vty->node = TRX_NODE; |
| 64 | { |
| 65 | /* set vty->index correctly ! */ |
| 66 | struct gsm_bts_trx_ts *ts = vty->index; |
| 67 | vty->index = ts->trx; |
| 68 | } |
| 69 | break; |
Harald Welte | c29ae4b | 2010-05-31 17:17:29 +0200 | [diff] [blame] | 70 | case OML_NODE: |
| 71 | vty->node = ENABLE_NODE; |
| 72 | talloc_free(vty->index); |
| 73 | vty->index = NULL; |
| 74 | break; |
Holger Hans Peter Freyther | 256a040 | 2010-06-15 20:11:16 +0800 | [diff] [blame] | 75 | case NAT_NODE: |
| 76 | vty->node = CONFIG_NODE; |
| 77 | vty->index = NULL; |
| 78 | break; |
| 79 | case BSC_NODE: |
| 80 | vty->node = NAT_NODE; |
| 81 | { |
| 82 | struct bsc_config *bsc_config = vty->index; |
| 83 | vty->index = bsc_config->nat; |
| 84 | } |
| 85 | break; |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 86 | default: |
| 87 | vty->node = CONFIG_NODE; |
| 88 | } |
| 89 | |
| 90 | return vty->node; |
| 91 | } |
| 92 | |
Harald Welte | 682ee5f | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 93 | /* Down vty node level. */ |
| 94 | gDEFUN(ournode_exit, |
| 95 | ournode_exit_cmd, "exit", "Exit current mode and down to previous mode\n") |
| 96 | { |
| 97 | switch (vty->node) { |
| 98 | case GSMNET_NODE: |
| 99 | vty->node = CONFIG_NODE; |
| 100 | vty->index = NULL; |
| 101 | break; |
| 102 | case BTS_NODE: |
| 103 | vty->node = GSMNET_NODE; |
| 104 | { |
| 105 | /* set vty->index correctly ! */ |
| 106 | struct gsm_bts *bts = vty->index; |
| 107 | vty->index = bts->network; |
| 108 | vty->index_sub = NULL; |
| 109 | } |
| 110 | break; |
| 111 | case TRX_NODE: |
| 112 | vty->node = BTS_NODE; |
| 113 | { |
| 114 | /* set vty->index correctly ! */ |
| 115 | struct gsm_bts_trx *trx = vty->index; |
| 116 | vty->index = trx->bts; |
| 117 | vty->index_sub = &trx->bts->description; |
| 118 | } |
| 119 | break; |
| 120 | case TS_NODE: |
| 121 | vty->node = TRX_NODE; |
| 122 | { |
| 123 | /* set vty->index correctly ! */ |
| 124 | struct gsm_bts_trx_ts *ts = vty->index; |
| 125 | vty->index = ts->trx; |
| 126 | vty->index_sub = &ts->trx->description; |
| 127 | } |
| 128 | break; |
Holger Hans Peter Freyther | 256a040 | 2010-06-15 20:11:16 +0800 | [diff] [blame] | 129 | case BSC_NODE: |
| 130 | vty->node = NAT_NODE; |
| 131 | { |
| 132 | struct bsc_config *bsc_config = vty->index; |
| 133 | vty->index = bsc_config->nat; |
| 134 | } |
| 135 | break; |
Harald Welte | 682ee5f | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 136 | case MGCP_NODE: |
| 137 | case GBPROXY_NODE: |
| 138 | case SGSN_NODE: |
| 139 | case NS_NODE: |
Harald Welte | 4b32698 | 2010-05-17 23:20:56 +0200 | [diff] [blame] | 140 | case BSSGP_NODE: |
Holger Hans Peter Freyther | 256a040 | 2010-06-15 20:11:16 +0800 | [diff] [blame] | 141 | case NAT_NODE: |
Harald Welte | 682ee5f | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 142 | vty->node = CONFIG_NODE; |
| 143 | vty->index = NULL; |
| 144 | break; |
Harald Welte | c29ae4b | 2010-05-31 17:17:29 +0200 | [diff] [blame] | 145 | case OML_NODE: |
| 146 | vty->node = ENABLE_NODE; |
| 147 | talloc_free(vty->index); |
| 148 | vty->index = NULL; |
| 149 | break; |
Harald Welte | 682ee5f | 2010-05-16 22:02:16 +0200 | [diff] [blame] | 150 | default: |
| 151 | break; |
| 152 | } |
| 153 | return CMD_SUCCESS; |
| 154 | } |
| 155 | |
| 156 | /* End of configuration. */ |
| 157 | gDEFUN(ournode_end, |
| 158 | ournode_end_cmd, "end", "End current mode and change to enable mode.") |
| 159 | { |
| 160 | switch (vty->node) { |
| 161 | case VIEW_NODE: |
| 162 | case ENABLE_NODE: |
| 163 | /* Nothing to do. */ |
| 164 | break; |
| 165 | case CONFIG_NODE: |
| 166 | case GSMNET_NODE: |
| 167 | case BTS_NODE: |
| 168 | case TRX_NODE: |
| 169 | case TS_NODE: |
| 170 | case MGCP_NODE: |
| 171 | case GBPROXY_NODE: |
| 172 | case SGSN_NODE: |
| 173 | case NS_NODE: |
| 174 | case VTY_NODE: |
| 175 | vty_config_unlock(vty); |
| 176 | vty->node = ENABLE_NODE; |
| 177 | vty->index = NULL; |
| 178 | vty->index_sub = NULL; |
| 179 | break; |
| 180 | default: |
| 181 | break; |
| 182 | } |
| 183 | return CMD_SUCCESS; |
| 184 | } |
| 185 | |