blob: 233e2dbd5654a0bf962abd49fcba1d6f7b92f4b2 [file] [log] [blame]
Harald Welte68628e82009-03-10 12:17:57 +00001/* OpenBSC interface to quagga VTY */
2/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <stdlib.h>
22#include <unistd.h>
23#include <sys/types.h>
24
25#include <vty/command.h>
26#include <vty/vty.h>
27
28#include <arpa/inet.h>
29
30#include <openbsc/gsm_data.h>
31#include <openbsc/gsm_subscriber.h>
32#include <openbsc/e1_input.h>
33
34static struct gsm_network *gsmnet;
35
36struct cmd_node bts_node = {
37 BTS_NODE,
38 "%s(bts)#",
39 1,
40};
41
42struct cmd_node trx_node = {
43 TRX_NODE,
44 "%s(trx)#",
45 1,
46};
47
48struct cmd_node ts_node = {
49 TS_NODE,
50 "%s(ts)#",
51 1,
52};
53
54static int dummy_config_write(struct vty *v)
55{
56 return CMD_SUCCESS;
57}
58
59static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
60{
61 vty_out(vty,"Operational %u, Administrative %u, Availability %u%s",
62 nms->operational, nms->administrative, nms->availability,
63 VTY_NEWLINE);
64}
65
66static void net_dump_vty(struct vty *vty, struct gsm_network *net)
67{
68 vty_out(vty, "BSC is on CC %u, NC %u and has %u BTS%s",
69 net->country_code, net->network_code, net->num_bts,
70 VTY_NEWLINE);
71 vty_out(vty, " Long network name: %s%s",
72 net->name_long, VTY_NEWLINE);
73 vty_out(vty, " Short network name: %s%s",
74 net->name_short, VTY_NEWLINE);
75}
76
77DEFUN(show_net, show_net_cmd, "show network",
78 SHOW_STR "Display information about a GSM NETWORK\n")
79{
80 struct gsm_network *net = gsmnet;
81 net_dump_vty(vty, net);
82
83 return CMD_SUCCESS;
84}
85
86static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
87{
88 vty_out(vty, " E1 Line %u, Timeslot %u, Type %u%s",
89 e1l->ts->line->num, e1l->ts->num, e1l->type, VTY_NEWLINE);
90 vty_out(vty, " E1 TEI %u, SAPI %u%s\n",
91 e1l->tei, e1l->sapi, VTY_NEWLINE);
92}
93
94static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
95{
96 vty_out(vty, "BTS %u is of %s type, has LAC %u, TSC %u and %u TRX%s",
97 bts->nr, btstype2str(bts->type), bts->location_area_code,
98 bts->tsc, bts->num_trx, VTY_NEWLINE);
99 vty_out(vty, " NM State: ");
100 net_dump_nmstate(vty, &bts->nm_state);
101 vty_out(vty, " Site Mgr NM State: ");
102 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
103 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
104 bts->paging.available_slots, VTY_NEWLINE);
105 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
106 e1isl_dump_vty(vty, bts->oml_link);
107 /* FIXME: oml_link, chan_desc */
108}
109
110DEFUN(show_bts, show_bts_cmd, "show bts [number]",
111 SHOW_STR "Display information about a BTS\n"
112 "BTS number")
113{
114 struct gsm_network *net = gsmnet;
115 int bts_nr;
116
117 if (argc != 0) {
118 /* use the BTS number that the user has specified */
119 bts_nr = atoi(argv[0]);
120 if (bts_nr > net->num_bts) {
121 vty_out(vty, "%% can't find BTS %s%s", argv[0],
122 VTY_NEWLINE);
123 return CMD_WARNING;
124 }
125 bts_dump_vty(vty, &net->bts[bts_nr]);
126 return CMD_SUCCESS;
127 }
128 /* print all BTS's */
129 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
130 bts_dump_vty(vty, &net->bts[bts_nr]);
131
132 return CMD_SUCCESS;
133}
134
135static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
136{
137 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
138 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
139 vty_out(vty, " NM State: ");
140 net_dump_nmstate(vty, &trx->nm_state);
141 vty_out(vty, " Baseband Transceiver NM State: ");
142 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
143 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
144 e1isl_dump_vty(vty, trx->rsl_link);
145}
146
147DEFUN(show_trx,
148 show_trx_cmd,
149 "show trx [bts_nr] [trx_nr]",
150 SHOW_STR "Display information about a TRX\n")
151{
152 struct gsm_network *net = gsmnet;
153 struct gsm_bts *bts = NULL;
154 struct gsm_bts_trx *trx;
155 int bts_nr, trx_nr;
156
157 if (argc >= 1) {
158 /* use the BTS number that the user has specified */
159 bts_nr = atoi(argv[0]);
160 if (bts_nr >= net->num_bts) {
161 vty_out(vty, "%% can't find BTS %s%s", argv[0],
162 VTY_NEWLINE);
163 return CMD_WARNING;
164 }
165 bts = &net->bts[bts_nr];
166 }
167 if (argc >= 2) {
168 trx_nr = atoi(argv[1]);
169 if (trx_nr >= bts->num_trx) {
170 vty_out(vty, "%% can't find TRX %s%s", argv[1],
171 VTY_NEWLINE);
172 return CMD_WARNING;
173 }
174 trx = &bts->trx[trx_nr];
175 trx_dump_vty(vty, trx);
176 return CMD_SUCCESS;
177 }
178 if (bts) {
179 /* print all TRX in this BTS */
180 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
181 trx = &bts->trx[trx_nr];
182 trx_dump_vty(vty, trx);
183 }
184 return CMD_SUCCESS;
185 }
186
187 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
188 bts = &net->bts[bts_nr];
189 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
190 trx = &bts->trx[trx_nr];
191 trx_dump_vty(vty, trx);
192 }
193 }
194
195 return CMD_SUCCESS;
196}
197
198static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
199{
200 struct in_addr ia;
201
202 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
203 ts->nr, ts->trx->nr, ts->trx->bts->nr,
204 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
205 vty_out(vty, " NM State: ");
206 net_dump_nmstate(vty, &ts->nm_state);
207 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
208 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
209 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
210 if (is_ipaccess_bts(ts->trx->bts)) {
211 ia.s_addr = ts->abis_ip.bound_ip;
212 vty_out(vty, " Bound IP: %s Port %u FC=%u F8=%u%s",
213 inet_ntoa(ia), ts->abis_ip.bound_port,
214 ts->abis_ip.attr_fc, ts->abis_ip.attr_f8,
215 VTY_NEWLINE);
216 }
217}
218
219DEFUN(show_ts,
220 show_ts_cmd,
221 "show ts [bts_nr] [trx_nr] [ts_nr]",
222 SHOW_STR "Display information about a TS\n")
223{
224 struct gsm_network *net = gsmnet;
225 struct gsm_bts *bts;
226 struct gsm_bts_trx *trx;
227 struct gsm_bts_trx_ts *ts;
228 int bts_nr, trx_nr, ts_nr;
229
230 if (argc >= 1) {
231 /* use the BTS number that the user has specified */
232 bts_nr = atoi(argv[0]);
233 if (bts_nr >= net->num_bts) {
234 vty_out(vty, "%% can't find BTS %s%s", argv[0],
235 VTY_NEWLINE);
236 return CMD_WARNING;
237 }
238 bts = &net->bts[bts_nr];
239 }
240 if (argc >= 2) {
241 trx_nr = atoi(argv[1]);
242 if (trx_nr >= bts->num_trx) {
243 vty_out(vty, "%% can't find TRX %s%s", argv[1],
244 VTY_NEWLINE);
245 return CMD_WARNING;
246 }
247 trx = &bts->trx[trx_nr];
248 }
249 if (argc >= 3) {
250 ts_nr = atoi(argv[2]);
251 if (ts_nr >= TRX_NR_TS) {
252 vty_out(vty, "%% can't find TS %s%s", argv[2],
253 VTY_NEWLINE);
254 return CMD_WARNING;
255 }
256 ts = &trx->ts[ts_nr];
257 ts_dump_vty(vty, ts);
258 return CMD_SUCCESS;
259 }
260 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
261 bts = &net->bts[bts_nr];
262 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
263 trx = &bts->trx[trx_nr];
264 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
265 ts = &trx->ts[ts_nr];
266 ts_dump_vty(vty, ts);
267 }
268 }
269 }
270
271 return CMD_SUCCESS;
272}
273
274static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
275{
276 if (subscr->name)
277 vty_out(vty, " Name: %s%s", subscr->name, VTY_NEWLINE);
278 if (subscr->extension)
279 vty_out(vty, " Extension: %s%s", subscr->extension,
280 VTY_NEWLINE);
281 if (subscr->imsi)
282 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
283 if (subscr->tmsi)
284 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
285}
286
287static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
288{
289 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
290 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
291 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
292 VTY_NEWLINE);
293 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
294 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
295 lchan->ms_power, VTY_NEWLINE);
296 if (lchan->subscr) {
297 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
298 subscr_dump_vty(vty, lchan->subscr);
299 } else
300 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
301}
302
303static void call_dump_vty(struct vty *vty, struct gsm_call *call)
304{
305 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
306 call->type, call->state, call->transaction_id, VTY_NEWLINE);
307
308 if (call->local_lchan) {
309 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
310 lchan_dump_vty(vty, call->local_lchan);
311 } else
312 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
313
314 if (call->remote_lchan) {
315 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
316 lchan_dump_vty(vty, call->remote_lchan);
317 } else
318 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
319
320 if (call->called_subscr) {
321 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
322 subscr_dump_vty(vty, call->called_subscr);
323 } else
324 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
325}
326
327DEFUN(show_lchan,
328 show_lchan_cmd,
329 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
330 SHOW_STR "Display information about a logical channel\n")
331{
332 struct gsm_network *net = gsmnet;
333 struct gsm_bts *bts;
334 struct gsm_bts_trx *trx;
335 struct gsm_bts_trx_ts *ts;
336 struct gsm_lchan *lchan;
337 int bts_nr, trx_nr, ts_nr, lchan_nr;
338
339 if (argc >= 1) {
340 /* use the BTS number that the user has specified */
341 bts_nr = atoi(argv[0]);
342 if (bts_nr >= net->num_bts) {
343 vty_out(vty, "%% can't find BTS %s%s", argv[0],
344 VTY_NEWLINE);
345 return CMD_WARNING;
346 }
347 bts = &net->bts[bts_nr];
348 }
349 if (argc >= 2) {
350 trx_nr = atoi(argv[1]);
351 if (trx_nr >= bts->num_trx) {
352 vty_out(vty, "%% can't find TRX %s%s", argv[1],
353 VTY_NEWLINE);
354 return CMD_WARNING;
355 }
356 trx = &bts->trx[trx_nr];
357 }
358 if (argc >= 3) {
359 ts_nr = atoi(argv[2]);
360 if (ts_nr >= TRX_NR_TS) {
361 vty_out(vty, "%% can't find TS %s%s", argv[2],
362 VTY_NEWLINE);
363 return CMD_WARNING;
364 }
365 ts = &trx->ts[ts_nr];
366 }
367 if (argc >= 4) {
368 lchan_nr = atoi(argv[3]);
369 if (lchan_nr >= TS_MAX_LCHAN) {
370 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
371 VTY_NEWLINE);
372 return CMD_WARNING;
373 }
374 lchan = &ts->lchan[lchan_nr];
375 lchan_dump_vty(vty, lchan);
376 return CMD_SUCCESS;
377 }
378 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
379 bts = &net->bts[bts_nr];
380 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
381 trx = &bts->trx[trx_nr];
382 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
383 ts = &trx->ts[ts_nr];
384 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
385 lchan_nr++) {
386 lchan = &ts->lchan[lchan_nr];
387 lchan_dump_vty(vty, lchan);
388 }
389 }
390 }
391 }
392
393 return CMD_SUCCESS;
394}
395
396static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
397{
398 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
399 line->num, line->name ? line->name : "",
400 line->driver->name, VTY_NEWLINE);
401}
402
403DEFUN(show_e1line,
404 show_e1line_cmd,
405 "show e1_line [line_nr]",
406 SHOW_STR "Display information about a E1 line\n")
407{
408
409}
410
411static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
412{
413 vty_out(vty, "E1 Timeslot %u of Line %u is Type %u%s",
414 ts->num, ts->line->num, ts->type, VTY_NEWLINE);
415}
416
417DEFUN(show_e1ts,
418 show_e1ts_cmd,
419 "show e1_timeslot [line_nr] [ts_nr]",
420 SHOW_STR "Display information about a E1 timeslot\n")
421{
422
423}
424
425int bsc_vty_init(struct gsm_network *net)
426{
427 gsmnet = net;
428
429 cmd_init(1);
430 vty_init();
431
432 install_element(VIEW_NODE, &show_net_cmd);
433 install_element(VIEW_NODE, &show_bts_cmd);
434 install_element(VIEW_NODE, &show_trx_cmd);
435 install_element(VIEW_NODE, &show_ts_cmd);
436 install_element(VIEW_NODE, &show_lchan_cmd);
437 install_element(VIEW_NODE, &show_e1line_cmd);
438 install_element(VIEW_NODE, &show_e1ts_cmd);
439
440#if 0
441 install_node(&bts_node, dummy_config_write);
442 install_element(BTS_NODE, &show_bts_cmd);
443 install_default(BTS_NODE);
444
445 install_node(&trx_node, dummy_config_write);
446 install_element(TRX_NODE, &show_trx_cmd);
447 install_default(TRX_NODE);
448
449 install_node(&ts_node, dummy_config_write);
450 install_element(TS_NODE, &show_ts_cmd);
451 install_default(TS_NODE);
452#endif
453
454 return 0;
455}