blob: abc1a66b3105fa90fb585a8cb808e5c7bbf14567 [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{
Harald Welteef235b52009-03-10 12:34:02 +000068 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
69 "and has %u BTS%s", net->country_code, net->network_code,
70 net->num_bts, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000071 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);
Harald Welte68628e82009-03-10 12:17:57 +0000207 if (is_ipaccess_bts(ts->trx->bts)) {
208 ia.s_addr = ts->abis_ip.bound_ip;
209 vty_out(vty, " Bound IP: %s Port %u FC=%u F8=%u%s",
210 inet_ntoa(ia), ts->abis_ip.bound_port,
211 ts->abis_ip.attr_fc, ts->abis_ip.attr_f8,
212 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000213 } else {
214 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
215 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
216 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000217 }
218}
219
220DEFUN(show_ts,
221 show_ts_cmd,
222 "show ts [bts_nr] [trx_nr] [ts_nr]",
223 SHOW_STR "Display information about a TS\n")
224{
225 struct gsm_network *net = gsmnet;
226 struct gsm_bts *bts;
227 struct gsm_bts_trx *trx;
228 struct gsm_bts_trx_ts *ts;
229 int bts_nr, trx_nr, ts_nr;
230
231 if (argc >= 1) {
232 /* use the BTS number that the user has specified */
233 bts_nr = atoi(argv[0]);
234 if (bts_nr >= net->num_bts) {
235 vty_out(vty, "%% can't find BTS %s%s", argv[0],
236 VTY_NEWLINE);
237 return CMD_WARNING;
238 }
239 bts = &net->bts[bts_nr];
240 }
241 if (argc >= 2) {
242 trx_nr = atoi(argv[1]);
243 if (trx_nr >= bts->num_trx) {
244 vty_out(vty, "%% can't find TRX %s%s", argv[1],
245 VTY_NEWLINE);
246 return CMD_WARNING;
247 }
248 trx = &bts->trx[trx_nr];
249 }
250 if (argc >= 3) {
251 ts_nr = atoi(argv[2]);
252 if (ts_nr >= TRX_NR_TS) {
253 vty_out(vty, "%% can't find TS %s%s", argv[2],
254 VTY_NEWLINE);
255 return CMD_WARNING;
256 }
257 ts = &trx->ts[ts_nr];
258 ts_dump_vty(vty, ts);
259 return CMD_SUCCESS;
260 }
261 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
262 bts = &net->bts[bts_nr];
263 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
264 trx = &bts->trx[trx_nr];
265 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
266 ts = &trx->ts[ts_nr];
267 ts_dump_vty(vty, ts);
268 }
269 }
270 }
271
272 return CMD_SUCCESS;
273}
274
275static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
276{
277 if (subscr->name)
278 vty_out(vty, " Name: %s%s", subscr->name, VTY_NEWLINE);
279 if (subscr->extension)
280 vty_out(vty, " Extension: %s%s", subscr->extension,
281 VTY_NEWLINE);
282 if (subscr->imsi)
283 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
284 if (subscr->tmsi)
285 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
286}
287
288static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
289{
290 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
291 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
292 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
293 VTY_NEWLINE);
294 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
295 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
296 lchan->ms_power, VTY_NEWLINE);
297 if (lchan->subscr) {
298 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
299 subscr_dump_vty(vty, lchan->subscr);
300 } else
301 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
302}
303
304static void call_dump_vty(struct vty *vty, struct gsm_call *call)
305{
306 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
307 call->type, call->state, call->transaction_id, VTY_NEWLINE);
308
309 if (call->local_lchan) {
310 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
311 lchan_dump_vty(vty, call->local_lchan);
312 } else
313 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
314
315 if (call->remote_lchan) {
316 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
317 lchan_dump_vty(vty, call->remote_lchan);
318 } else
319 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
320
321 if (call->called_subscr) {
322 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
323 subscr_dump_vty(vty, call->called_subscr);
324 } else
325 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
326}
327
328DEFUN(show_lchan,
329 show_lchan_cmd,
330 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
331 SHOW_STR "Display information about a logical channel\n")
332{
333 struct gsm_network *net = gsmnet;
334 struct gsm_bts *bts;
335 struct gsm_bts_trx *trx;
336 struct gsm_bts_trx_ts *ts;
337 struct gsm_lchan *lchan;
338 int bts_nr, trx_nr, ts_nr, lchan_nr;
339
340 if (argc >= 1) {
341 /* use the BTS number that the user has specified */
342 bts_nr = atoi(argv[0]);
343 if (bts_nr >= net->num_bts) {
344 vty_out(vty, "%% can't find BTS %s%s", argv[0],
345 VTY_NEWLINE);
346 return CMD_WARNING;
347 }
348 bts = &net->bts[bts_nr];
349 }
350 if (argc >= 2) {
351 trx_nr = atoi(argv[1]);
352 if (trx_nr >= bts->num_trx) {
353 vty_out(vty, "%% can't find TRX %s%s", argv[1],
354 VTY_NEWLINE);
355 return CMD_WARNING;
356 }
357 trx = &bts->trx[trx_nr];
358 }
359 if (argc >= 3) {
360 ts_nr = atoi(argv[2]);
361 if (ts_nr >= TRX_NR_TS) {
362 vty_out(vty, "%% can't find TS %s%s", argv[2],
363 VTY_NEWLINE);
364 return CMD_WARNING;
365 }
366 ts = &trx->ts[ts_nr];
367 }
368 if (argc >= 4) {
369 lchan_nr = atoi(argv[3]);
370 if (lchan_nr >= TS_MAX_LCHAN) {
371 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
372 VTY_NEWLINE);
373 return CMD_WARNING;
374 }
375 lchan = &ts->lchan[lchan_nr];
376 lchan_dump_vty(vty, lchan);
377 return CMD_SUCCESS;
378 }
379 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
380 bts = &net->bts[bts_nr];
381 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
382 trx = &bts->trx[trx_nr];
383 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
384 ts = &trx->ts[ts_nr];
385 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
386 lchan_nr++) {
387 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000388 if (lchan->type == GSM_LCHAN_NONE)
389 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000390 lchan_dump_vty(vty, lchan);
391 }
392 }
393 }
394 }
395
396 return CMD_SUCCESS;
397}
398
399static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
400{
401 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
402 line->num, line->name ? line->name : "",
403 line->driver->name, VTY_NEWLINE);
404}
405
406DEFUN(show_e1line,
407 show_e1line_cmd,
408 "show e1_line [line_nr]",
409 SHOW_STR "Display information about a E1 line\n")
410{
411
412}
413
414static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
415{
416 vty_out(vty, "E1 Timeslot %u of Line %u is Type %u%s",
417 ts->num, ts->line->num, ts->type, VTY_NEWLINE);
418}
419
420DEFUN(show_e1ts,
421 show_e1ts_cmd,
422 "show e1_timeslot [line_nr] [ts_nr]",
423 SHOW_STR "Display information about a E1 timeslot\n")
424{
425
426}
427
428int bsc_vty_init(struct gsm_network *net)
429{
430 gsmnet = net;
431
432 cmd_init(1);
433 vty_init();
434
435 install_element(VIEW_NODE, &show_net_cmd);
436 install_element(VIEW_NODE, &show_bts_cmd);
437 install_element(VIEW_NODE, &show_trx_cmd);
438 install_element(VIEW_NODE, &show_ts_cmd);
439 install_element(VIEW_NODE, &show_lchan_cmd);
440 install_element(VIEW_NODE, &show_e1line_cmd);
441 install_element(VIEW_NODE, &show_e1ts_cmd);
442
443#if 0
444 install_node(&bts_node, dummy_config_write);
445 install_element(BTS_NODE, &show_bts_cmd);
446 install_default(BTS_NODE);
447
448 install_node(&trx_node, dummy_config_write);
449 install_element(TRX_NODE, &show_trx_cmd);
450 install_default(TRX_NODE);
451
452 install_node(&ts_node, dummy_config_write);
453 install_element(TS_NODE, &show_ts_cmd);
454 install_default(TS_NODE);
455#endif
456
457 return 0;
458}