blob: 6ec0a4a2119f2640a01e9da6317eb0f544d29d58 [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)"
Harald Weltecfaabbb2012-08-16 23:23:50 +020066#define NM_OBJCLASS_VTY_HELP "Site Manager Object\n" \
67 "BTS Object\n" \
68 "Radio Carrier Object\n" \
69 "Baseband Transceiver Object\n" \
70 "Channel (Timeslot) Object\n" \
71 "Adjacent Object (Siemens)\n" \
72 "Handover Object (Siemens)\n" \
73 "Power Control Object (Siemens)\n" \
74 "BTSE Object (Siemens)\n" \
75 "Rack Object (Siemens)\n" \
76 "Test Object (Siemens)\n" \
77 "ENVABTSE Object (Siemens)\n" \
78 "BPORT Object (Siemens)\n" \
79 "GPRS NSE Object (ip.access/osmo-bts)\n" \
80 "GPRS Cell Object (ip.acecss/osmo-bts)\n" \
81 "GPRS NSVC Object (ip.acecss/osmo-bts)\n" \
82 "SIEMENSHW Object (Siemens)\n"
83
Harald Welte81c9b9c2010-05-31 16:40:40 +020084
85DEFUN(oml_class_inst, oml_class_inst_cmd,
86 "bts <0-255> oml class " NM_OBJCLASS_VTY
87 " instance <0-255> <0-255> <0-255>",
88 "BTS related commands\n" "BTS Number\n"
89 "Manipulate the OML managed objects\n"
90 "Object Class\n" NM_OBJCLASS_VTY_HELP
91 "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n")
92{
93 struct gsm_bts *bts;
94 struct oml_node_state *oms;
95 int bts_nr = atoi(argv[0]);
96
Neels Hofmeyr663debc2016-05-09 21:18:08 +020097 bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr);
Harald Welte81c9b9c2010-05-31 16:40:40 +020098 if (!bts) {
99 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
100 return CMD_WARNING;
101 }
102
103 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
104 if (!oms)
105 return CMD_WARNING;
106
107 oms->bts = bts;
Harald Weltecdc59ff2011-05-23 20:42:26 +0200108 oms->obj_class = get_string_value(abis_nm_obj_class_names, argv[1]);
Harald Welte81c9b9c2010-05-31 16:40:40 +0200109 oms->obj_inst[0] = atoi(argv[2]);
110 oms->obj_inst[1] = atoi(argv[3]);
111 oms->obj_inst[2] = atoi(argv[4]);
112
113 vty->index = oms;
114 vty->node = OML_NODE;
115
116 return CMD_SUCCESS;
117
118}
119
120DEFUN(oml_classnum_inst, oml_classnum_inst_cmd,
121 "bts <0-255> oml class <0-255> instance <0-255> <0-255> <0-255>",
122 "BTS related commands\n" "BTS Number\n"
123 "Manipulate the OML managed objects\n"
124 "Object Class\n" "Object Class\n"
125 "Object Instance\n" "BTS Number\n" "TRX Number\n" "TS Number\n")
126{
127 struct gsm_bts *bts;
128 struct oml_node_state *oms;
129 int bts_nr = atoi(argv[0]);
130
Neels Hofmeyr663debc2016-05-09 21:18:08 +0200131 bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr);
Harald Welte81c9b9c2010-05-31 16:40:40 +0200132 if (!bts) {
133 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
134 return CMD_WARNING;
135 }
136
137 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
138 if (!oms)
139 return CMD_WARNING;
140
141 oms->bts = bts;
142 oms->obj_class = atoi(argv[1]);
143 oms->obj_inst[0] = atoi(argv[2]);
144 oms->obj_inst[1] = atoi(argv[3]);
145 oms->obj_inst[2] = atoi(argv[4]);
146
147 vty->index = oms;
148 vty->node = OML_NODE;
149
150 return CMD_SUCCESS;
151}
152
Harald Welte81c9b9c2010-05-31 16:40:40 +0200153DEFUN(oml_chg_adm_state, oml_chg_adm_state_cmd,
154 "change-adm-state (locked|unlocked|shutdown|null)",
155 "Change the Administrative State\n"
156 "Locked\n" "Unlocked\n" "Shutdown\n" "NULL\n")
157{
158 struct oml_node_state *oms = vty->index;
159 enum abis_nm_adm_state state;
160
Harald Weltecdc59ff2011-05-23 20:42:26 +0200161 state = get_string_value(abis_nm_adm_state_names, argv[0]);
Harald Welte81c9b9c2010-05-31 16:40:40 +0200162
163 abis_nm_chg_adm_state(oms->bts, oms->obj_class, oms->obj_inst[0],
164 oms->obj_inst[1], oms->obj_inst[2], state);
165
166 return CMD_SUCCESS;
167}
168
169DEFUN(oml_opstart, oml_opstart_cmd,
170 "opstart", "Send an OPSTART message to the object")
171{
172 struct oml_node_state *oms = vty->index;
173
174 abis_nm_opstart(oms->bts, oms->obj_class, oms->obj_inst[0],
175 oms->obj_inst[1], oms->obj_inst[2]);
176
177 return CMD_SUCCESS;
178}
179
180int abis_nm_vty_init(void)
181{
182 install_element(ENABLE_NODE, &oml_class_inst_cmd);
183 install_element(ENABLE_NODE, &oml_classnum_inst_cmd);
184 install_node(&oml_node, dummy_config_write);
185
Jacob Erlbeck36722e12013-10-29 09:30:30 +0100186 vty_install_default(OML_NODE);
Harald Welte81c9b9c2010-05-31 16:40:40 +0200187 install_element(OML_NODE, &oml_chg_adm_state_cmd);
188 install_element(OML_NODE, &oml_opstart_cmd);
189
190 return 0;
191}