Harald Welte | 51c8238 | 2011-02-12 14:44:16 +0100 | [diff] [blame] | 1 | /* VTY interface for A-bis OM2000 */ |
| 2 | |
| 3 | /* (C) 2010-2011 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 Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 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 Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <unistd.h> |
| 24 | #include <errno.h> |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | #include <arpa/inet.h> |
| 28 | |
| 29 | #include <openbsc/gsm_data.h> |
| 30 | #include <osmocore/msgb.h> |
| 31 | #include <osmocore/tlv.h> |
| 32 | #include <osmocore/talloc.h> |
| 33 | #include <openbsc/debug.h> |
| 34 | #include <openbsc/signal.h> |
| 35 | #include <openbsc/abis_om2000.h> |
| 36 | #include <openbsc/vty.h> |
| 37 | |
| 38 | #include <osmocom/vty/vty.h> |
| 39 | #include <osmocom/vty/command.h> |
| 40 | #include <osmocom/vty/logging.h> |
| 41 | #include <osmocom/vty/telnet_interface.h> |
| 42 | |
| 43 | extern struct gsm_network *bsc_gsmnet; |
| 44 | |
| 45 | static struct cmd_node om2k_node = { |
| 46 | OM2K_NODE, |
Harald Welte | b0ec9e3 | 2011-02-12 20:50:58 +0100 | [diff] [blame] | 47 | "%s(om2k)# ", |
Harald Welte | 51c8238 | 2011-02-12 14:44:16 +0100 | [diff] [blame] | 48 | 1, |
| 49 | }; |
| 50 | |
| 51 | struct oml_node_state { |
| 52 | struct gsm_bts *bts; |
| 53 | struct abis_om2k_mo mo; |
| 54 | }; |
| 55 | |
| 56 | static int dummy_config_write(struct vty *v) |
| 57 | { |
| 58 | return CMD_SUCCESS; |
| 59 | } |
| 60 | |
| 61 | /* FIXME: auto-generate those strings from the value_string lists */ |
| 62 | #define OM2K_OBJCLASS_VTY "(trxc|ts|tf|is|con|dp|cf|tx|rx)" |
Harald Welte | 9c0958b | 2011-02-13 22:51:03 +0100 | [diff] [blame] | 63 | #define OM2K_OBJCLASS_VTY_HELP "TRX Controller\n" \ |
| 64 | "Timeslot\n" \ |
| 65 | "Timing Function\n" \ |
| 66 | "Interface Switch\n" \ |
| 67 | "Abis Concentrator\n" \ |
| 68 | "Digital Path\n" \ |
| 69 | "Central Function\n" \ |
| 70 | "Transmitter\n" \ |
| 71 | "Receiver\n" |
Harald Welte | 51c8238 | 2011-02-12 14:44:16 +0100 | [diff] [blame] | 72 | |
| 73 | DEFUN(om2k_class_inst, om2k_class_inst_cmd, |
| 74 | "bts <0-255> om2000 class " OM2K_OBJCLASS_VTY |
| 75 | " <0-255> <0-255> <0-255>", |
| 76 | "BTS related commands\n" "BTS Number\n" |
| 77 | "Manipulate the OM2000 managed objects\n" |
| 78 | "Object Class\n" OM2K_OBJCLASS_VTY_HELP |
| 79 | "BTS Number\n" "Associated SO Instance\n" "Instance Number\n") |
| 80 | { |
| 81 | struct gsm_bts *bts; |
| 82 | struct oml_node_state *oms; |
| 83 | int bts_nr = atoi(argv[0]); |
| 84 | |
| 85 | bts = gsm_bts_num(bsc_gsmnet, bts_nr); |
| 86 | if (!bts) { |
| 87 | vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); |
| 88 | return CMD_WARNING; |
| 89 | } |
| 90 | |
| 91 | if (bts->type != GSM_BTS_TYPE_RBS2000) { |
| 92 | vty_out(vty, "%% BTS %d not an Ericsson RBS%s", |
| 93 | bts_nr, VTY_NEWLINE); |
| 94 | return CMD_WARNING; |
| 95 | } |
| 96 | |
| 97 | oms = talloc_zero(tall_bsc_ctx, struct oml_node_state); |
| 98 | if (!oms) |
| 99 | return CMD_WARNING; |
| 100 | |
| 101 | oms->bts = bts; |
| 102 | oms->mo.class = get_string_value(om2k_mo_class_short_vals, argv[1]); |
| 103 | oms->mo.bts = atoi(argv[2]); |
| 104 | oms->mo.assoc_so = atoi(argv[3]); |
| 105 | oms->mo.inst = atoi(argv[4]); |
| 106 | |
| 107 | vty->index = oms; |
| 108 | vty->node = OM2K_NODE; |
| 109 | |
| 110 | return CMD_SUCCESS; |
| 111 | |
| 112 | } |
| 113 | |
| 114 | DEFUN(om2k_classnum_inst, om2k_classnum_inst_cmd, |
| 115 | "bts <0-255> om2000 class <0-255> <0-255> <0-255> <0-255>", |
| 116 | "BTS related commands\n" "BTS Number\n" |
| 117 | "Manipulate the OML managed objects\n" |
| 118 | "Object Class\n" "Object Class\n" |
| 119 | "BTS Number\n" "Associated SO Instance\n" "Instance Number\n") |
| 120 | { |
| 121 | struct gsm_bts *bts; |
| 122 | struct oml_node_state *oms; |
| 123 | int bts_nr = atoi(argv[0]); |
| 124 | |
| 125 | bts = gsm_bts_num(bsc_gsmnet, bts_nr); |
| 126 | if (!bts) { |
| 127 | vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); |
| 128 | return CMD_WARNING; |
| 129 | } |
| 130 | |
| 131 | oms = talloc_zero(tall_bsc_ctx, struct oml_node_state); |
| 132 | if (!oms) |
| 133 | return CMD_WARNING; |
| 134 | |
| 135 | oms->bts = bts; |
| 136 | oms->mo.class = atoi(argv[1]); |
| 137 | oms->mo.bts = atoi(argv[2]); |
| 138 | oms->mo.assoc_so = atoi(argv[3]); |
| 139 | oms->mo.inst = atoi(argv[4]); |
| 140 | |
| 141 | vty->index = oms; |
| 142 | vty->node = OM2K_NODE; |
| 143 | |
| 144 | return CMD_SUCCESS; |
| 145 | } |
| 146 | |
| 147 | DEFUN(om2k_reset, om2k_reset_cmd, |
| 148 | "reset-command", |
| 149 | "Reset the MO\n") |
| 150 | { |
| 151 | struct oml_node_state *oms = vty->index; |
| 152 | |
| 153 | abis_om2k_tx_reset_cmd(oms->bts, &oms->mo); |
| 154 | return CMD_SUCCESS; |
| 155 | } |
| 156 | |
| 157 | DEFUN(om2k_start, om2k_start_cmd, |
| 158 | "start-request", |
| 159 | "Start the MO\n") |
| 160 | { |
| 161 | struct oml_node_state *oms = vty->index; |
| 162 | |
| 163 | abis_om2k_tx_start_req(oms->bts, &oms->mo); |
| 164 | return CMD_SUCCESS; |
| 165 | } |
| 166 | |
| 167 | DEFUN(om2k_status, om2k_status_cmd, |
| 168 | "status-request", |
| 169 | "Get the MO Status\n") |
| 170 | { |
| 171 | struct oml_node_state *oms = vty->index; |
| 172 | |
| 173 | abis_om2k_tx_status_req(oms->bts, &oms->mo); |
| 174 | return CMD_SUCCESS; |
| 175 | } |
| 176 | |
Harald Welte | 6fec79d | 2011-02-12 14:57:17 +0100 | [diff] [blame] | 177 | DEFUN(om2k_connect, om2k_connect_cmd, |
| 178 | "connect-command", |
| 179 | "Connect the MO\n") |
| 180 | { |
| 181 | struct oml_node_state *oms = vty->index; |
| 182 | |
| 183 | abis_om2k_tx_connect_cmd(oms->bts, &oms->mo); |
| 184 | return CMD_SUCCESS; |
| 185 | } |
| 186 | |
| 187 | DEFUN(om2k_disconnect, om2k_disconnect_cmd, |
| 188 | "disconnect-command", |
| 189 | "Disconnect the MO\n") |
| 190 | { |
| 191 | struct oml_node_state *oms = vty->index; |
| 192 | |
| 193 | abis_om2k_tx_disconnect_cmd(oms->bts, &oms->mo); |
| 194 | return CMD_SUCCESS; |
| 195 | } |
| 196 | |
Harald Welte | 0741ffe | 2011-02-12 18:48:53 +0100 | [diff] [blame] | 197 | DEFUN(om2k_enable, om2k_enable_cmd, |
| 198 | "enable-request", |
| 199 | "Enable the MO\n") |
| 200 | { |
| 201 | struct oml_node_state *oms = vty->index; |
| 202 | |
| 203 | abis_om2k_tx_enable_req(oms->bts, &oms->mo); |
| 204 | return CMD_SUCCESS; |
| 205 | } |
| 206 | |
| 207 | DEFUN(om2k_disable, om2k_disable_cmd, |
| 208 | "disable-request", |
| 209 | "Disable the MO\n") |
| 210 | { |
| 211 | struct oml_node_state *oms = vty->index; |
| 212 | |
| 213 | abis_om2k_tx_disable_req(oms->bts, &oms->mo); |
| 214 | return CMD_SUCCESS; |
| 215 | } |
| 216 | |
Harald Welte | 6fec79d | 2011-02-12 14:57:17 +0100 | [diff] [blame] | 217 | DEFUN(om2k_op_info, om2k_op_info_cmd, |
| 218 | "operational-info <0-1>", |
| 219 | "Set operational information\n") |
| 220 | { |
| 221 | struct oml_node_state *oms = vty->index; |
| 222 | int oper = atoi(argv[0]); |
| 223 | |
| 224 | abis_om2k_tx_op_info(oms->bts, &oms->mo, oper); |
| 225 | return CMD_SUCCESS; |
| 226 | } |
| 227 | |
Harald Welte | 8024d8f | 2011-02-12 15:07:30 +0100 | [diff] [blame] | 228 | DEFUN(om2k_test, om2k_test_cmd, |
| 229 | "test-request", |
| 230 | "Test the MO\n") |
| 231 | { |
| 232 | struct oml_node_state *oms = vty->index; |
| 233 | |
| 234 | abis_om2k_tx_test_req(oms->bts, &oms->mo); |
| 235 | return CMD_SUCCESS; |
| 236 | } |
| 237 | |
Harald Welte | a02085d | 2011-02-13 22:45:02 +0100 | [diff] [blame] | 238 | struct con_conn_group { |
| 239 | struct llist_head list; |
| 240 | |
| 241 | uint8_t cg; |
| 242 | uint16_t ccp; |
| 243 | uint8_t tag; |
| 244 | uint8_t tei; |
| 245 | }; |
| 246 | |
| 247 | static void add_con_list(struct gsm_bts *bts, uint8_t cg, uint16_t ccp, |
| 248 | uint8_t tag, uint8_t tei) |
| 249 | { |
| 250 | struct con_conn_group *ent = talloc_zero(bts, struct con_conn_group); |
| 251 | |
| 252 | ent->cg = cg; |
| 253 | ent->ccp = ccp; |
| 254 | ent->tag = tag; |
| 255 | ent->tei = tei; |
| 256 | |
| 257 | llist_add(&ent->list, &bts->rbs2000.con.conn_groups); |
| 258 | } |
| 259 | |
| 260 | static int del_con_list(struct gsm_bts *bts, uint8_t cg, uint16_t ccp, |
| 261 | uint8_t tag, uint8_t tei) |
| 262 | { |
| 263 | struct con_conn_group *grp, *grp2; |
| 264 | |
| 265 | llist_for_each_entry_safe(grp, grp2, &bts->rbs2000.con.conn_groups, list) { |
| 266 | if (grp->cg == cg && grp->ccp == ccp && grp->tag == tag |
| 267 | && grp->tei == tei) { |
| 268 | llist_del(&grp->list); |
| 269 | talloc_free(grp); |
| 270 | return 0; |
| 271 | } |
| 272 | } |
| 273 | return -ENOENT; |
| 274 | } |
| 275 | |
| 276 | #define CON_LIST_HELP "CON connetiton list\n" \ |
| 277 | "Add entry to CON list\n" \ |
| 278 | "Delete entry from CON list\n" \ |
| 279 | "Connection Group Number\n" \ |
| 280 | "CON Connection Point\n" \ |
| 281 | |
| 282 | DEFUN(om2k_con_list_dec, om2k_con_list_dec_cmd, |
| 283 | "con-connection-list (add|del) <1-255> <0-1023> deconcentrated", |
| 284 | CON_LIST_HELP "De-concentrated in/outlet\n") |
| 285 | { |
| 286 | struct oml_node_state *oms = vty->index; |
| 287 | struct gsm_bts *bts = oms->bts; |
| 288 | uint8_t cg = atoi(argv[1]); |
| 289 | uint16_t ccp = atoi(argv[2]); |
| 290 | |
| 291 | if (!strcmp(argv[0], "add")) |
| 292 | add_con_list(bts, cg, ccp, 0, 0xff); |
| 293 | else { |
| 294 | if (del_con_list(bts, cg, ccp, 0, 0xff) < 0) { |
| 295 | vty_out(vty, "%% No matching CON list entry%s", |
| 296 | VTY_NEWLINE); |
| 297 | return CMD_WARNING; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | return CMD_SUCCESS; |
| 302 | } |
| 303 | |
| 304 | DEFUN(om2k_con_list_tei, om2k_con_list_tei_cmd, |
| 305 | "con-connection-list (add|del) <1-255> <0-1023> tei <0-63>", |
| 306 | CON_LIST_HELP "Concentrated in/outlet with TEI\n" "TEI Number\n") |
| 307 | { |
| 308 | struct oml_node_state *oms = vty->index; |
| 309 | struct gsm_bts *bts = oms->bts; |
| 310 | uint8_t cg = atoi(argv[1]); |
| 311 | uint16_t ccp = atoi(argv[2]); |
| 312 | uint8_t tei = atoi(argv[3]); |
| 313 | |
| 314 | if (!strcmp(argv[0], "add")) |
| 315 | add_con_list(bts, cg, ccp, cg, tei); |
| 316 | else { |
| 317 | if (del_con_list(bts, cg, ccp, cg, tei) < 0) { |
| 318 | vty_out(vty, "%% No matching CON list entry%s", |
| 319 | VTY_NEWLINE); |
| 320 | return CMD_WARNING; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | return CMD_SUCCESS; |
| 325 | } |
| 326 | |
Harald Welte | 8bcb1a0 | 2011-02-12 20:23:40 +0100 | [diff] [blame] | 327 | static void om2k_fill_is_conn_grp(struct om2k_is_conn_grp *grp, uint16_t icp1, |
| 328 | uint16_t icp2, uint8_t cont_idx) |
| 329 | { |
| 330 | grp->icp1 = htons(icp1); |
| 331 | grp->icp2 = htons(icp2); |
| 332 | grp->cont_idx = cont_idx; |
| 333 | } |
| 334 | |
Harald Welte | a8e6a65 | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 335 | struct is_conn_group { |
| 336 | struct llist_head list; |
| 337 | uint16_t icp1; |
| 338 | uint16_t icp2; |
| 339 | uint8_t ci; |
| 340 | }; |
| 341 | |
| 342 | DEFUN(om2k_is_conn_list, om2k_is_conn_list_cmd, |
| 343 | "is-connection-list (add|del) <0-2047> <0-2047> <0-255>", |
| 344 | "Interface Switch Connnection List\n" |
| 345 | "Add to IS list\n" "Delete from IS list\n" |
| 346 | "ICP1\n" "ICP2\n" "Contiguity Index\n") |
Harald Welte | 8bcb1a0 | 2011-02-12 20:23:40 +0100 | [diff] [blame] | 347 | { |
| 348 | struct oml_node_state *oms = vty->index; |
Harald Welte | a8e6a65 | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 349 | struct gsm_bts *bts = oms->bts; |
| 350 | uint16_t icp1 = atoi(argv[1]); |
| 351 | uint16_t icp2 = atoi(argv[2]); |
| 352 | uint8_t ci = atoi(argv[3]); |
| 353 | struct is_conn_group *grp, *grp2; |
Harald Welte | 8bcb1a0 | 2011-02-12 20:23:40 +0100 | [diff] [blame] | 354 | |
Harald Welte | a8e6a65 | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 355 | if (!strcmp(argv[0], "add")) { |
| 356 | grp = talloc_zero(bts, struct is_conn_group); |
| 357 | grp->icp1 = icp1; |
| 358 | grp->icp2 = icp2; |
| 359 | grp->ci = ci; |
| 360 | llist_add(&grp->list, &bts->rbs2000.is.conn_groups); |
| 361 | } else { |
| 362 | llist_for_each_entry_safe(grp, grp2, &bts->rbs2000.is.conn_groups, list) { |
| 363 | if (grp->icp1 == icp1 && grp->icp2 == icp2 |
| 364 | && grp->ci == ci) { |
| 365 | llist_del(&grp->list); |
| 366 | talloc_free(grp); |
| 367 | return CMD_SUCCESS; |
| 368 | } |
| 369 | } |
| 370 | vty_out(vty, "%% No matching IS Conn Group found!%s", |
| 371 | VTY_NEWLINE); |
| 372 | return CMD_WARNING; |
| 373 | } |
Harald Welte | 8bcb1a0 | 2011-02-12 20:23:40 +0100 | [diff] [blame] | 374 | |
Harald Welte | a8e6a65 | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 375 | return CMD_SUCCESS; |
| 376 | } |
| 377 | |
| 378 | |
| 379 | DEFUN(om2k_is_conf_req, om2k_is_conf_req_cmd, |
| 380 | "is-conf-req", |
| 381 | "Send IS Configuration Request\n") |
| 382 | { |
| 383 | struct oml_node_state *oms = vty->index; |
| 384 | struct gsm_bts *bts = oms->bts; |
| 385 | struct is_conn_group *grp; |
| 386 | unsigned int num_grps = 0, i = 0; |
| 387 | struct om2k_is_conn_grp *o2grps; |
| 388 | |
| 389 | /* count number of groups in linked list */ |
| 390 | llist_for_each_entry(grp, &bts->rbs2000.is.conn_groups, list) |
| 391 | num_grps++; |
| 392 | |
| 393 | if (!num_grps) { |
| 394 | vty_out(vty, "%% No IS connection groups configured!%s", |
| 395 | VTY_NEWLINE); |
| 396 | return CMD_WARNING; |
| 397 | } |
| 398 | |
| 399 | /* allocate buffer for oml group array */ |
| 400 | o2grps = talloc_zero_array(bts, struct om2k_is_conn_grp, num_grps); |
| 401 | |
| 402 | /* fill array with data from linked list */ |
| 403 | llist_for_each_entry(grp, &bts->rbs2000.is.conn_groups, list) |
| 404 | om2k_fill_is_conn_grp(&o2grps[i++], grp->icp1, grp->icp2, grp->ci); |
| 405 | |
| 406 | /* send the actual OML request */ |
| 407 | abis_om2k_tx_is_conf_req(oms->bts, o2grps, num_grps); |
| 408 | |
| 409 | talloc_free(o2grps); |
| 410 | |
Harald Welte | 8bcb1a0 | 2011-02-12 20:23:40 +0100 | [diff] [blame] | 411 | return CMD_SUCCESS; |
| 412 | } |
Harald Welte | 6fec79d | 2011-02-12 14:57:17 +0100 | [diff] [blame] | 413 | |
Harald Welte | 51c8238 | 2011-02-12 14:44:16 +0100 | [diff] [blame] | 414 | int abis_om2k_vty_init(void) |
| 415 | { |
| 416 | install_element(ENABLE_NODE, &om2k_class_inst_cmd); |
| 417 | install_element(ENABLE_NODE, &om2k_classnum_inst_cmd); |
| 418 | install_node(&om2k_node, dummy_config_write); |
| 419 | |
| 420 | install_default(OM2K_NODE); |
| 421 | install_element(OM2K_NODE, &ournode_exit_cmd); |
| 422 | install_element(OM2K_NODE, &om2k_reset_cmd); |
| 423 | install_element(OM2K_NODE, &om2k_start_cmd); |
| 424 | install_element(OM2K_NODE, &om2k_status_cmd); |
Harald Welte | 6fec79d | 2011-02-12 14:57:17 +0100 | [diff] [blame] | 425 | install_element(OM2K_NODE, &om2k_connect_cmd); |
| 426 | install_element(OM2K_NODE, &om2k_disconnect_cmd); |
Harald Welte | 0741ffe | 2011-02-12 18:48:53 +0100 | [diff] [blame] | 427 | install_element(OM2K_NODE, &om2k_enable_cmd); |
| 428 | install_element(OM2K_NODE, &om2k_disable_cmd); |
Harald Welte | 6fec79d | 2011-02-12 14:57:17 +0100 | [diff] [blame] | 429 | install_element(OM2K_NODE, &om2k_op_info_cmd); |
Harald Welte | 8024d8f | 2011-02-12 15:07:30 +0100 | [diff] [blame] | 430 | install_element(OM2K_NODE, &om2k_test_cmd); |
Harald Welte | 8bcb1a0 | 2011-02-12 20:23:40 +0100 | [diff] [blame] | 431 | install_element(OM2K_NODE, &om2k_is_conf_req_cmd); |
Harald Welte | a8e6a65 | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 432 | install_element(OM2K_NODE, &om2k_is_conn_list_cmd); |
Harald Welte | a02085d | 2011-02-13 22:45:02 +0100 | [diff] [blame] | 433 | install_element(OM2K_NODE, &om2k_con_list_dec_cmd); |
| 434 | install_element(OM2K_NODE, &om2k_con_list_tei_cmd); |
Harald Welte | 51c8238 | 2011-02-12 14:44:16 +0100 | [diff] [blame] | 435 | |
| 436 | return 0; |
| 437 | } |