blob: 3a16b2b7f206131871e883689c49fdcbdae3b389 [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
29#include <openbsc/gsm_data.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010030#include <osmocom/core/msgb.h>
31#include <osmocom/gsm/tlv.h>
32#include <osmocom/core/talloc.h>
Harald Welte81c9b9c2010-05-31 16:40:40 +020033#include <openbsc/debug.h>
34#include <openbsc/signal.h>
35#include <openbsc/abis_nm.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
43extern struct gsm_network *bsc_gsmnet;
44
45static struct cmd_node oml_node = {
46 OML_NODE,
47 "%s(oml)# ",
48 1,
49};
50
51struct oml_node_state {
52 struct gsm_bts *bts;
53 uint8_t obj_class;
54 uint8_t obj_inst[3];
55};
56
57static int dummy_config_write(struct vty *v)
58{
59 return CMD_SUCCESS;
60}
61
62/* FIXME: auto-generate those strings from the value_string lists */
63#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)"
64#define NM_OBJCLASS_VTY_HELP "FIXME"
65
66DEFUN(oml_class_inst, oml_class_inst_cmd,
67 "bts <0-255> oml class " NM_OBJCLASS_VTY
68 " instance <0-255> <0-255> <0-255>",
69 "BTS related commands\n" "BTS Number\n"
70 "Manipulate the OML managed objects\n"
71 "Object Class\n" NM_OBJCLASS_VTY_HELP
72 "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n")
73{
74 struct gsm_bts *bts;
75 struct oml_node_state *oms;
76 int bts_nr = atoi(argv[0]);
77
78 bts = gsm_bts_num(bsc_gsmnet, bts_nr);
79 if (!bts) {
80 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
81 return CMD_WARNING;
82 }
83
84 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
85 if (!oms)
86 return CMD_WARNING;
87
88 oms->bts = bts;
89 oms->obj_class = get_string_value(abis_nm_obj_class_names, argv[1]);
90 oms->obj_inst[0] = atoi(argv[2]);
91 oms->obj_inst[1] = atoi(argv[3]);
92 oms->obj_inst[2] = atoi(argv[4]);
93
94 vty->index = oms;
95 vty->node = OML_NODE;
96
97 return CMD_SUCCESS;
98
99}
100
101DEFUN(oml_classnum_inst, oml_classnum_inst_cmd,
102 "bts <0-255> oml class <0-255> instance <0-255> <0-255> <0-255>",
103 "BTS related commands\n" "BTS Number\n"
104 "Manipulate the OML managed objects\n"
105 "Object Class\n" "Object Class\n"
106 "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n")
107{
108 struct gsm_bts *bts;
109 struct oml_node_state *oms;
110 int bts_nr = atoi(argv[0]);
111
112 bts = gsm_bts_num(bsc_gsmnet, bts_nr);
113 if (!bts) {
114 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
115 return CMD_WARNING;
116 }
117
118 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
119 if (!oms)
120 return CMD_WARNING;
121
122 oms->bts = bts;
123 oms->obj_class = atoi(argv[1]);
124 oms->obj_inst[0] = atoi(argv[2]);
125 oms->obj_inst[1] = atoi(argv[3]);
126 oms->obj_inst[2] = atoi(argv[4]);
127
128 vty->index = oms;
129 vty->node = OML_NODE;
130
131 return CMD_SUCCESS;
132}
133
134DEFUN(oml_attrib_get, oml_attrib_get_cmd,
135 "attribute get <0-255>",
136 "OML Attribute Actions\n" "Get a single OML Attribute\n"
137 "OML Attribute Number\n")
138{
139 struct oml_node_state *oms = vty->index;
140
141 /* FIXME */
142 return CMD_SUCCESS;
143}
144
145DEFUN(oml_attrib_set, oml_attrib_set_cmd,
146 "attribute set <0-255> .HEX",
147 "OML Attribute Actions\n" "Set a single OML Attribute\n"
148 "OML Attribute Number\n")
149{
150 struct oml_node_state *oms = vty->index;
151
152 /* FIXME */
153 return CMD_SUCCESS;
154}
155
156DEFUN(oml_chg_adm_state, oml_chg_adm_state_cmd,
157 "change-adm-state (locked|unlocked|shutdown|null)",
158 "Change the Administrative State\n"
159 "Locked\n" "Unlocked\n" "Shutdown\n" "NULL\n")
160{
161 struct oml_node_state *oms = vty->index;
162 enum abis_nm_adm_state state;
163
164 state = get_string_value(abis_nm_adm_state_names, argv[0]);
165
166 abis_nm_chg_adm_state(oms->bts, oms->obj_class, oms->obj_inst[0],
167 oms->obj_inst[1], oms->obj_inst[2], state);
168
169 return CMD_SUCCESS;
170}
171
172DEFUN(oml_opstart, oml_opstart_cmd,
173 "opstart", "Send an OPSTART message to the object")
174{
175 struct oml_node_state *oms = vty->index;
176
177 abis_nm_opstart(oms->bts, oms->obj_class, oms->obj_inst[0],
178 oms->obj_inst[1], oms->obj_inst[2]);
179
180 return CMD_SUCCESS;
181}
182
183int abis_nm_vty_init(void)
184{
185 install_element(ENABLE_NODE, &oml_class_inst_cmd);
186 install_element(ENABLE_NODE, &oml_classnum_inst_cmd);
187 install_node(&oml_node, dummy_config_write);
188
189 install_default(OML_NODE);
190 install_element(OML_NODE, &ournode_exit_cmd);
191 install_element(OML_NODE, &oml_attrib_get_cmd);
192 install_element(OML_NODE, &oml_attrib_set_cmd);
193 install_element(OML_NODE, &oml_chg_adm_state_cmd);
194 install_element(OML_NODE, &oml_opstart_cmd);
195
196 return 0;
197}