blob: 6ac4a9e6b58fe5a0fd764a029144b4340d5c9718 [file] [log] [blame]
Harald Welte81c9b9c2010-05-31 16:40:40 +02001/* 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
Harald Welte9af6ddf2011-01-01 15:25:50 +01008 * 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
Harald Welte81c9b9c2010-05-31 16:40:40 +020010 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte81c9b9c2010-05-31 16:40:40 +020016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * 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/>.
Harald Welte81c9b9c2010-05-31 16:40:40 +020019 *
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
Holger Hans Peter Freytherf2c1f252011-05-23 21:42:57 +020029#include <osmocom/gsm/abis_nm.h>
30
Harald Welte81c9b9c2010-05-31 16:40:40 +020031#include <openbsc/gsm_data.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010032#include <osmocom/core/msgb.h>
33#include <osmocom/gsm/tlv.h>
34#include <osmocom/core/talloc.h>
Harald Welte81c9b9c2010-05-31 16:40:40 +020035#include <openbsc/debug.h>
36#include <openbsc/signal.h>
37#include <openbsc/abis_nm.h>
38#include <openbsc/vty.h>
39
40#include <osmocom/vty/vty.h>
41#include <osmocom/vty/command.h>
42#include <osmocom/vty/logging.h>
43#include <osmocom/vty/telnet_interface.h>
44
45extern struct gsm_network *bsc_gsmnet;
46
47static struct cmd_node oml_node = {
48 OML_NODE,
49 "%s(oml)# ",
50 1,
51};
52
53struct oml_node_state {
54 struct gsm_bts *bts;
55 uint8_t obj_class;
56 uint8_t obj_inst[3];
57};
58
59static int dummy_config_write(struct vty *v)
60{
61 return CMD_SUCCESS;
62}
63
64/* FIXME: auto-generate those strings from the value_string lists */
65#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)"
66#define NM_OBJCLASS_VTY_HELP "FIXME"
67
68DEFUN(oml_class_inst, oml_class_inst_cmd,
69 "bts <0-255> oml class " NM_OBJCLASS_VTY
70 " instance <0-255> <0-255> <0-255>",
71 "BTS related commands\n" "BTS Number\n"
72 "Manipulate the OML managed objects\n"
73 "Object Class\n" NM_OBJCLASS_VTY_HELP
74 "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n")
75{
76 struct gsm_bts *bts;
77 struct oml_node_state *oms;
78 int bts_nr = atoi(argv[0]);
79
80 bts = gsm_bts_num(bsc_gsmnet, bts_nr);
81 if (!bts) {
82 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
83 return CMD_WARNING;
84 }
85
86 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
87 if (!oms)
88 return CMD_WARNING;
89
90 oms->bts = bts;
Harald Weltecdc59ff2011-05-23 20:42:26 +020091 oms->obj_class = get_string_value(abis_nm_obj_class_names, argv[1]);
Harald Welte81c9b9c2010-05-31 16:40:40 +020092 oms->obj_inst[0] = atoi(argv[2]);
93 oms->obj_inst[1] = atoi(argv[3]);
94 oms->obj_inst[2] = atoi(argv[4]);
95
96 vty->index = oms;
97 vty->node = OML_NODE;
98
99 return CMD_SUCCESS;
100
101}
102
103DEFUN(oml_classnum_inst, oml_classnum_inst_cmd,
104 "bts <0-255> oml class <0-255> instance <0-255> <0-255> <0-255>",
105 "BTS related commands\n" "BTS Number\n"
106 "Manipulate the OML managed objects\n"
107 "Object Class\n" "Object Class\n"
108 "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n")
109{
110 struct gsm_bts *bts;
111 struct oml_node_state *oms;
112 int bts_nr = atoi(argv[0]);
113
114 bts = gsm_bts_num(bsc_gsmnet, bts_nr);
115 if (!bts) {
116 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
117 return CMD_WARNING;
118 }
119
120 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
121 if (!oms)
122 return CMD_WARNING;
123
124 oms->bts = bts;
125 oms->obj_class = atoi(argv[1]);
126 oms->obj_inst[0] = atoi(argv[2]);
127 oms->obj_inst[1] = atoi(argv[3]);
128 oms->obj_inst[2] = atoi(argv[4]);
129
130 vty->index = oms;
131 vty->node = OML_NODE;
132
133 return CMD_SUCCESS;
134}
135
Harald Welte81c9b9c2010-05-31 16:40:40 +0200136DEFUN(oml_chg_adm_state, oml_chg_adm_state_cmd,
137 "change-adm-state (locked|unlocked|shutdown|null)",
138 "Change the Administrative State\n"
139 "Locked\n" "Unlocked\n" "Shutdown\n" "NULL\n")
140{
141 struct oml_node_state *oms = vty->index;
142 enum abis_nm_adm_state state;
143
Harald Weltecdc59ff2011-05-23 20:42:26 +0200144 state = get_string_value(abis_nm_adm_state_names, argv[0]);
Harald Welte81c9b9c2010-05-31 16:40:40 +0200145
146 abis_nm_chg_adm_state(oms->bts, oms->obj_class, oms->obj_inst[0],
147 oms->obj_inst[1], oms->obj_inst[2], state);
148
149 return CMD_SUCCESS;
150}
151
152DEFUN(oml_opstart, oml_opstart_cmd,
153 "opstart", "Send an OPSTART message to the object")
154{
155 struct oml_node_state *oms = vty->index;
156
157 abis_nm_opstart(oms->bts, oms->obj_class, oms->obj_inst[0],
158 oms->obj_inst[1], oms->obj_inst[2]);
159
160 return CMD_SUCCESS;
161}
162
163int abis_nm_vty_init(void)
164{
165 install_element(ENABLE_NODE, &oml_class_inst_cmd);
166 install_element(ENABLE_NODE, &oml_classnum_inst_cmd);
167 install_node(&oml_node, dummy_config_write);
168
169 install_default(OML_NODE);
170 install_element(OML_NODE, &ournode_exit_cmd);
Harald Welte81c9b9c2010-05-31 16:40:40 +0200171 install_element(OML_NODE, &oml_chg_adm_state_cmd);
172 install_element(OML_NODE, &oml_opstart_cmd);
173
174 return 0;
175}