Harald Welte | 81c9b9c | 2010-05-31 16:40:40 +0200 | [diff] [blame] | 1 | /* VTY interface for A-bis OML (Netowrk Management) */ |
| 2 | |
| 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <unistd.h> |
| 25 | #include <errno.h> |
| 26 | #include <stdint.h> |
| 27 | |
| 28 | #include <arpa/inet.h> |
| 29 | |
| 30 | #include <openbsc/gsm_data.h> |
| 31 | #include <osmocore/msgb.h> |
| 32 | #include <osmocore/tlv.h> |
| 33 | #include <osmocore/talloc.h> |
| 34 | #include <openbsc/debug.h> |
| 35 | #include <openbsc/signal.h> |
| 36 | #include <openbsc/abis_nm.h> |
| 37 | #include <openbsc/vty.h> |
| 38 | |
| 39 | #include <osmocom/vty/vty.h> |
| 40 | #include <osmocom/vty/command.h> |
| 41 | #include <osmocom/vty/logging.h> |
| 42 | #include <osmocom/vty/telnet_interface.h> |
| 43 | |
| 44 | extern struct gsm_network *bsc_gsmnet; |
| 45 | |
| 46 | static struct cmd_node oml_node = { |
| 47 | OML_NODE, |
| 48 | "%s(oml)# ", |
| 49 | 1, |
| 50 | }; |
| 51 | |
| 52 | struct oml_node_state { |
| 53 | struct gsm_bts *bts; |
| 54 | uint8_t obj_class; |
| 55 | uint8_t obj_inst[3]; |
| 56 | }; |
| 57 | |
| 58 | static int dummy_config_write(struct vty *v) |
| 59 | { |
| 60 | return CMD_SUCCESS; |
| 61 | } |
| 62 | |
| 63 | /* FIXME: auto-generate those strings from the value_string lists */ |
| 64 | #define NM_OBJCLASS_VTY "(site-manager|bts|radio-carrier|baseband-transceiver|channel|adjc|handover|power-contorl|btse|rack|test|envabtse|bport|gprs-nse|gprs-cell|gprs-nsvc|siemenshw)" |
| 65 | #define NM_OBJCLASS_VTY_HELP "FIXME" |
| 66 | |
| 67 | DEFUN(oml_class_inst, oml_class_inst_cmd, |
| 68 | "bts <0-255> oml class " NM_OBJCLASS_VTY |
| 69 | " instance <0-255> <0-255> <0-255>", |
| 70 | "BTS related commands\n" "BTS Number\n" |
| 71 | "Manipulate the OML managed objects\n" |
| 72 | "Object Class\n" NM_OBJCLASS_VTY_HELP |
| 73 | "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n") |
| 74 | { |
| 75 | struct gsm_bts *bts; |
| 76 | struct oml_node_state *oms; |
| 77 | int bts_nr = atoi(argv[0]); |
| 78 | |
| 79 | bts = gsm_bts_num(bsc_gsmnet, bts_nr); |
| 80 | if (!bts) { |
| 81 | vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); |
| 82 | return CMD_WARNING; |
| 83 | } |
| 84 | |
| 85 | oms = talloc_zero(tall_bsc_ctx, struct oml_node_state); |
| 86 | if (!oms) |
| 87 | return CMD_WARNING; |
| 88 | |
| 89 | oms->bts = bts; |
| 90 | oms->obj_class = get_string_value(abis_nm_obj_class_names, argv[1]); |
| 91 | oms->obj_inst[0] = atoi(argv[2]); |
| 92 | oms->obj_inst[1] = atoi(argv[3]); |
| 93 | oms->obj_inst[2] = atoi(argv[4]); |
| 94 | |
| 95 | vty->index = oms; |
| 96 | vty->node = OML_NODE; |
| 97 | |
| 98 | return CMD_SUCCESS; |
| 99 | |
| 100 | } |
| 101 | |
| 102 | DEFUN(oml_classnum_inst, oml_classnum_inst_cmd, |
| 103 | "bts <0-255> oml class <0-255> instance <0-255> <0-255> <0-255>", |
| 104 | "BTS related commands\n" "BTS Number\n" |
| 105 | "Manipulate the OML managed objects\n" |
| 106 | "Object Class\n" "Object Class\n" |
| 107 | "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n") |
| 108 | { |
| 109 | struct gsm_bts *bts; |
| 110 | struct oml_node_state *oms; |
| 111 | int bts_nr = atoi(argv[0]); |
| 112 | |
| 113 | bts = gsm_bts_num(bsc_gsmnet, bts_nr); |
| 114 | if (!bts) { |
| 115 | vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); |
| 116 | return CMD_WARNING; |
| 117 | } |
| 118 | |
| 119 | oms = talloc_zero(tall_bsc_ctx, struct oml_node_state); |
| 120 | if (!oms) |
| 121 | return CMD_WARNING; |
| 122 | |
| 123 | oms->bts = bts; |
| 124 | oms->obj_class = atoi(argv[1]); |
| 125 | oms->obj_inst[0] = atoi(argv[2]); |
| 126 | oms->obj_inst[1] = atoi(argv[3]); |
| 127 | oms->obj_inst[2] = atoi(argv[4]); |
| 128 | |
| 129 | vty->index = oms; |
| 130 | vty->node = OML_NODE; |
| 131 | |
| 132 | return CMD_SUCCESS; |
| 133 | } |
| 134 | |
| 135 | DEFUN(oml_attrib_get, oml_attrib_get_cmd, |
| 136 | "attribute get <0-255>", |
| 137 | "OML Attribute Actions\n" "Get a single OML Attribute\n" |
| 138 | "OML Attribute Number\n") |
| 139 | { |
| 140 | struct oml_node_state *oms = vty->index; |
| 141 | |
| 142 | /* FIXME */ |
| 143 | return CMD_SUCCESS; |
| 144 | } |
| 145 | |
| 146 | DEFUN(oml_attrib_set, oml_attrib_set_cmd, |
| 147 | "attribute set <0-255> .HEX", |
| 148 | "OML Attribute Actions\n" "Set a single OML Attribute\n" |
| 149 | "OML Attribute Number\n") |
| 150 | { |
| 151 | struct oml_node_state *oms = vty->index; |
| 152 | |
| 153 | /* FIXME */ |
| 154 | return CMD_SUCCESS; |
| 155 | } |
| 156 | |
| 157 | DEFUN(oml_chg_adm_state, oml_chg_adm_state_cmd, |
| 158 | "change-adm-state (locked|unlocked|shutdown|null)", |
| 159 | "Change the Administrative State\n" |
| 160 | "Locked\n" "Unlocked\n" "Shutdown\n" "NULL\n") |
| 161 | { |
| 162 | struct oml_node_state *oms = vty->index; |
| 163 | enum abis_nm_adm_state state; |
| 164 | |
| 165 | state = get_string_value(abis_nm_adm_state_names, argv[0]); |
| 166 | |
| 167 | abis_nm_chg_adm_state(oms->bts, oms->obj_class, oms->obj_inst[0], |
| 168 | oms->obj_inst[1], oms->obj_inst[2], state); |
| 169 | |
| 170 | return CMD_SUCCESS; |
| 171 | } |
| 172 | |
| 173 | DEFUN(oml_opstart, oml_opstart_cmd, |
| 174 | "opstart", "Send an OPSTART message to the object") |
| 175 | { |
| 176 | struct oml_node_state *oms = vty->index; |
| 177 | |
| 178 | abis_nm_opstart(oms->bts, oms->obj_class, oms->obj_inst[0], |
| 179 | oms->obj_inst[1], oms->obj_inst[2]); |
| 180 | |
| 181 | return CMD_SUCCESS; |
| 182 | } |
| 183 | |
| 184 | int abis_nm_vty_init(void) |
| 185 | { |
| 186 | install_element(ENABLE_NODE, &oml_class_inst_cmd); |
| 187 | install_element(ENABLE_NODE, &oml_classnum_inst_cmd); |
| 188 | install_node(&oml_node, dummy_config_write); |
| 189 | |
| 190 | install_default(OML_NODE); |
| 191 | install_element(OML_NODE, &ournode_exit_cmd); |
| 192 | install_element(OML_NODE, &oml_attrib_get_cmd); |
| 193 | install_element(OML_NODE, &oml_attrib_set_cmd); |
| 194 | install_element(OML_NODE, &oml_chg_adm_state_cmd); |
| 195 | install_element(OML_NODE, &oml_opstart_cmd); |
| 196 | |
| 197 | return 0; |
| 198 | } |