blob: e08a5e2c01783354603f379beea96ae11a5476f4 [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
Harald Welte1bc77352009-03-10 19:47:51 +000030#include <openbsc/linuxlist.h>
Harald Welte68628e82009-03-10 12:17:57 +000031#include <openbsc/gsm_data.h>
32#include <openbsc/gsm_subscriber.h>
33#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000034#include <openbsc/abis_nm.h>
Harald Welte68628e82009-03-10 12:17:57 +000035
36static struct gsm_network *gsmnet;
37
38struct cmd_node bts_node = {
39 BTS_NODE,
40 "%s(bts)#",
41 1,
42};
43
44struct cmd_node trx_node = {
45 TRX_NODE,
46 "%s(trx)#",
47 1,
48};
49
50struct cmd_node ts_node = {
51 TS_NODE,
52 "%s(ts)#",
53 1,
54};
55
56static int dummy_config_write(struct vty *v)
57{
58 return CMD_SUCCESS;
59}
60
61static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
62{
Harald Welte1bc77352009-03-10 19:47:51 +000063 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
64 nm_opstate_name(nms->operational), nms->administrative,
65 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000066}
67
68static void net_dump_vty(struct vty *vty, struct gsm_network *net)
69{
Harald Welteef235b52009-03-10 12:34:02 +000070 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
71 "and has %u BTS%s", net->country_code, net->network_code,
72 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000073 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000074 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000075 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000076 net->name_short, VTY_NEWLINE);
77}
78
79DEFUN(show_net, show_net_cmd, "show network",
80 SHOW_STR "Display information about a GSM NETWORK\n")
81{
82 struct gsm_network *net = gsmnet;
83 net_dump_vty(vty, net);
84
85 return CMD_SUCCESS;
86}
87
88static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
89{
Harald Welteedb37782009-05-01 14:59:07 +000090 struct e1inp_line *line;
91
92 if (!e1l) {
93 vty_out(vty, " None%s", VTY_NEWLINE);
94 return;
95 }
96
97 line = e1l->ts->line;
98
99 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
100 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000101 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000102 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000103 e1l->tei, e1l->sapi, VTY_NEWLINE);
104}
105
106static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
107{
108 vty_out(vty, "BTS %u is of %s type, has LAC %u, TSC %u and %u TRX%s",
109 bts->nr, btstype2str(bts->type), bts->location_area_code,
110 bts->tsc, bts->num_trx, VTY_NEWLINE);
111 vty_out(vty, " NM State: ");
112 net_dump_nmstate(vty, &bts->nm_state);
113 vty_out(vty, " Site Mgr NM State: ");
114 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
115 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
116 bts->paging.available_slots, VTY_NEWLINE);
117 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
118 e1isl_dump_vty(vty, bts->oml_link);
Harald Welteedb37782009-05-01 14:59:07 +0000119 if (is_ipaccess_bts(bts))
120 vty_out(vty, " Unit ID: %u/%u/0%s",
121 bts->ip_access.site_id, bts->ip_access.bts_id,
122 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000123 /* FIXME: oml_link, chan_desc */
124}
125
126DEFUN(show_bts, show_bts_cmd, "show bts [number]",
127 SHOW_STR "Display information about a BTS\n"
128 "BTS number")
129{
130 struct gsm_network *net = gsmnet;
131 int bts_nr;
132
133 if (argc != 0) {
134 /* use the BTS number that the user has specified */
135 bts_nr = atoi(argv[0]);
136 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000137 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000138 VTY_NEWLINE);
139 return CMD_WARNING;
140 }
141 bts_dump_vty(vty, &net->bts[bts_nr]);
142 return CMD_SUCCESS;
143 }
144 /* print all BTS's */
145 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
146 bts_dump_vty(vty, &net->bts[bts_nr]);
147
148 return CMD_SUCCESS;
149}
150
151static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
152{
153 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
154 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
155 vty_out(vty, " NM State: ");
156 net_dump_nmstate(vty, &trx->nm_state);
157 vty_out(vty, " Baseband Transceiver NM State: ");
158 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
159 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
160 e1isl_dump_vty(vty, trx->rsl_link);
161}
162
163DEFUN(show_trx,
164 show_trx_cmd,
165 "show trx [bts_nr] [trx_nr]",
166 SHOW_STR "Display information about a TRX\n")
167{
168 struct gsm_network *net = gsmnet;
169 struct gsm_bts *bts = NULL;
170 struct gsm_bts_trx *trx;
171 int bts_nr, trx_nr;
172
173 if (argc >= 1) {
174 /* use the BTS number that the user has specified */
175 bts_nr = atoi(argv[0]);
176 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000177 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000178 VTY_NEWLINE);
179 return CMD_WARNING;
180 }
181 bts = &net->bts[bts_nr];
182 }
183 if (argc >= 2) {
184 trx_nr = atoi(argv[1]);
185 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000186 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000187 VTY_NEWLINE);
188 return CMD_WARNING;
189 }
190 trx = &bts->trx[trx_nr];
191 trx_dump_vty(vty, trx);
192 return CMD_SUCCESS;
193 }
194 if (bts) {
195 /* print all TRX in this BTS */
196 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
197 trx = &bts->trx[trx_nr];
198 trx_dump_vty(vty, trx);
199 }
200 return CMD_SUCCESS;
201 }
202
203 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
204 bts = &net->bts[bts_nr];
205 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
206 trx = &bts->trx[trx_nr];
207 trx_dump_vty(vty, trx);
208 }
209 }
210
211 return CMD_SUCCESS;
212}
213
214static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
215{
216 struct in_addr ia;
217
218 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
219 ts->nr, ts->trx->nr, ts->trx->bts->nr,
220 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
221 vty_out(vty, " NM State: ");
222 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000223 if (is_ipaccess_bts(ts->trx->bts)) {
224 ia.s_addr = ts->abis_ip.bound_ip;
225 vty_out(vty, " Bound IP: %s Port %u FC=%u F8=%u%s",
226 inet_ntoa(ia), ts->abis_ip.bound_port,
227 ts->abis_ip.attr_fc, ts->abis_ip.attr_f8,
228 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000229 } else {
230 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
231 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
232 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000233 }
234}
235
236DEFUN(show_ts,
237 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000238 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000239 SHOW_STR "Display information about a TS\n")
240{
241 struct gsm_network *net = gsmnet;
242 struct gsm_bts *bts;
243 struct gsm_bts_trx *trx;
244 struct gsm_bts_trx_ts *ts;
245 int bts_nr, trx_nr, ts_nr;
246
247 if (argc >= 1) {
248 /* use the BTS number that the user has specified */
249 bts_nr = atoi(argv[0]);
250 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000251 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000252 VTY_NEWLINE);
253 return CMD_WARNING;
254 }
255 bts = &net->bts[bts_nr];
256 }
257 if (argc >= 2) {
258 trx_nr = atoi(argv[1]);
259 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000260 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000261 VTY_NEWLINE);
262 return CMD_WARNING;
263 }
264 trx = &bts->trx[trx_nr];
265 }
266 if (argc >= 3) {
267 ts_nr = atoi(argv[2]);
268 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000269 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000270 VTY_NEWLINE);
271 return CMD_WARNING;
272 }
273 ts = &trx->ts[ts_nr];
274 ts_dump_vty(vty, ts);
275 return CMD_SUCCESS;
276 }
277 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
278 bts = &net->bts[bts_nr];
279 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
280 trx = &bts->trx[trx_nr];
281 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
282 ts = &trx->ts[ts_nr];
283 ts_dump_vty(vty, ts);
284 }
285 }
286 }
287
288 return CMD_SUCCESS;
289}
290
291static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
292{
293 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000294 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000295 if (subscr->extension)
296 vty_out(vty, " Extension: %s%s", subscr->extension,
297 VTY_NEWLINE);
298 if (subscr->imsi)
299 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
300 if (subscr->tmsi)
301 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
302}
303
304static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
305{
306 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
307 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
308 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
309 VTY_NEWLINE);
310 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
311 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
312 lchan->ms_power, VTY_NEWLINE);
313 if (lchan->subscr) {
314 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
315 subscr_dump_vty(vty, lchan->subscr);
316 } else
317 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
318}
319
320static void call_dump_vty(struct vty *vty, struct gsm_call *call)
321{
322 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
323 call->type, call->state, call->transaction_id, VTY_NEWLINE);
324
325 if (call->local_lchan) {
326 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
327 lchan_dump_vty(vty, call->local_lchan);
328 } else
329 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
330
331 if (call->remote_lchan) {
332 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
333 lchan_dump_vty(vty, call->remote_lchan);
334 } else
335 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
336
337 if (call->called_subscr) {
338 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
339 subscr_dump_vty(vty, call->called_subscr);
340 } else
341 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
342}
343
344DEFUN(show_lchan,
345 show_lchan_cmd,
346 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
347 SHOW_STR "Display information about a logical channel\n")
348{
349 struct gsm_network *net = gsmnet;
350 struct gsm_bts *bts;
351 struct gsm_bts_trx *trx;
352 struct gsm_bts_trx_ts *ts;
353 struct gsm_lchan *lchan;
354 int bts_nr, trx_nr, ts_nr, lchan_nr;
355
356 if (argc >= 1) {
357 /* use the BTS number that the user has specified */
358 bts_nr = atoi(argv[0]);
359 if (bts_nr >= net->num_bts) {
360 vty_out(vty, "%% can't find BTS %s%s", argv[0],
361 VTY_NEWLINE);
362 return CMD_WARNING;
363 }
364 bts = &net->bts[bts_nr];
365 }
366 if (argc >= 2) {
367 trx_nr = atoi(argv[1]);
368 if (trx_nr >= bts->num_trx) {
369 vty_out(vty, "%% can't find TRX %s%s", argv[1],
370 VTY_NEWLINE);
371 return CMD_WARNING;
372 }
373 trx = &bts->trx[trx_nr];
374 }
375 if (argc >= 3) {
376 ts_nr = atoi(argv[2]);
377 if (ts_nr >= TRX_NR_TS) {
378 vty_out(vty, "%% can't find TS %s%s", argv[2],
379 VTY_NEWLINE);
380 return CMD_WARNING;
381 }
382 ts = &trx->ts[ts_nr];
383 }
384 if (argc >= 4) {
385 lchan_nr = atoi(argv[3]);
386 if (lchan_nr >= TS_MAX_LCHAN) {
387 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
388 VTY_NEWLINE);
389 return CMD_WARNING;
390 }
391 lchan = &ts->lchan[lchan_nr];
392 lchan_dump_vty(vty, lchan);
393 return CMD_SUCCESS;
394 }
395 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
396 bts = &net->bts[bts_nr];
397 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
398 trx = &bts->trx[trx_nr];
399 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
400 ts = &trx->ts[ts_nr];
401 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
402 lchan_nr++) {
403 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000404 if (lchan->type == GSM_LCHAN_NONE)
405 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000406 lchan_dump_vty(vty, lchan);
407 }
408 }
409 }
410 }
411
412 return CMD_SUCCESS;
413}
414
Harald Welte1bc77352009-03-10 19:47:51 +0000415static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
416{
417 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
418}
419
420DEFUN(show_e1drv,
421 show_e1drv_cmd,
422 "show e1_driver",
423 SHOW_STR "Display information about available E1 drivers\n")
424{
425 struct e1inp_driver *drv;
426
427 llist_for_each_entry(drv, &e1inp_driver_list, list)
428 e1drv_dump_vty(vty, drv);
429
430 return CMD_SUCCESS;
431}
432
Harald Welte68628e82009-03-10 12:17:57 +0000433static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
434{
435 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
436 line->num, line->name ? line->name : "",
437 line->driver->name, VTY_NEWLINE);
438}
439
440DEFUN(show_e1line,
441 show_e1line_cmd,
442 "show e1_line [line_nr]",
443 SHOW_STR "Display information about a E1 line\n")
444{
Harald Welte1bc77352009-03-10 19:47:51 +0000445 struct e1inp_line *line;
446
447 if (argc >= 1) {
448 int num = atoi(argv[0]);
449 llist_for_each_entry(line, &e1inp_line_list, list) {
450 if (line->num == num) {
451 e1line_dump_vty(vty, line);
452 return CMD_SUCCESS;
453 }
454 }
455 return CMD_WARNING;
456 }
457
458 llist_for_each_entry(line, &e1inp_line_list, list)
459 e1line_dump_vty(vty, line);
460
461 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000462}
463
464static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
465{
Harald Welte1bc77352009-03-10 19:47:51 +0000466 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
467 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
468 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000469}
470
471DEFUN(show_e1ts,
472 show_e1ts_cmd,
473 "show e1_timeslot [line_nr] [ts_nr]",
474 SHOW_STR "Display information about a E1 timeslot\n")
475{
Harald Welte1bc77352009-03-10 19:47:51 +0000476 struct e1inp_line *line;
477 struct e1inp_ts *ts;
478 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000479
Harald Welte1bc77352009-03-10 19:47:51 +0000480 if (argc == 0) {
481 llist_for_each_entry(line, &e1inp_line_list, list) {
482 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
483 ts = &line->ts[ts_nr];
484 e1ts_dump_vty(vty, ts);
485 }
486 }
487 return CMD_SUCCESS;
488 }
489 if (argc >= 1) {
490 int num = atoi(argv[0]);
491 llist_for_each_entry(line, &e1inp_line_list, list) {
492 if (line->num == num)
493 break;
494 }
495 if (!line || line->num != num) {
496 vty_out(vty, "E1 line %s is invalid%s",
497 argv[0], VTY_NEWLINE);
498 return CMD_WARNING;
499 }
500 }
501 if (argc >= 2) {
502 ts_nr = atoi(argv[1]);
503 if (ts_nr > NUM_E1_TS) {
504 vty_out(vty, "E1 timeslot %s is invalid%s",
505 argv[1], VTY_NEWLINE);
506 return CMD_WARNING;
507 }
508 ts = &line->ts[ts_nr];
509 e1ts_dump_vty(vty, ts);
510 return CMD_SUCCESS;
511 } else {
512 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
513 ts = &line->ts[ts_nr];
514 e1ts_dump_vty(vty, ts);
515 }
516 return CMD_SUCCESS;
517 }
518 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000519}
520
Harald Weltef5025b62009-03-28 16:55:11 +0000521void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
522{
523 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
524 subscr_dump_vty(vty, pag->subscr);
525}
526
527void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
528{
529 struct gsm_paging_request *pag;
530
531 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
532 paging_dump_vty(vty, pag);
533}
534
535DEFUN(show_paging,
536 show_paging_cmd,
537 "show paging [bts_nr]",
538 SHOW_STR "Display information about pating reuqests of a BTS\n")
539{
540 struct gsm_network *net = gsmnet;
541 struct gsm_bts *bts;
542 int bts_nr;
543
544 if (argc >= 1) {
545 /* use the BTS number that the user has specified */
546 bts_nr = atoi(argv[0]);
547 if (bts_nr >= net->num_bts) {
548 vty_out(vty, "%% can't find BTS %s%s", argv[0],
549 VTY_NEWLINE);
550 return CMD_WARNING;
551 }
552 bts = &net->bts[bts_nr];
553 bts_paging_dump_vty(vty, bts);
554
555 return CMD_SUCCESS;
556 }
557 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
558 bts = &net->bts[bts_nr];
559 bts_paging_dump_vty(vty, bts);
560 }
561
562 return CMD_SUCCESS;
563}
564
Harald Welte5258fc42009-03-28 19:07:53 +0000565/* per-BTS configuration */
566DEFUN(cfg_bts,
567 cfg_bts_cmd,
568 "bts BTS_NR",
569 "Select a BTS to configure\n")
570{
571 int bts_nr = atoi(argv[0]);
572 struct gsm_bts *bts;
573
574 if (bts_nr >= GSM_MAX_BTS) {
575 vty_out(vty, "%% This Version of OpenBSC only supports %u BTS%s",
576 GSM_MAX_BTS, VTY_NEWLINE);
577 return CMD_WARNING;
578 }
579 bts = &gsmnet->bts[bts_nr];
580 if (bts_nr >= gsmnet->num_bts)
581 gsmnet->num_bts = bts_nr + 1;
582
583 vty->index = bts;
584 vty->node = BTS_NODE;
585
586 return CMD_SUCCESS;
587}
588
589DEFUN(cfg_bts_type,
590 cfg_bts_type_cmd,
591 "type TYPE",
592 "Set the BTS type\n")
593{
594 struct gsm_bts *bts = vty->index;
595
596 //bts->type =
597 return CMD_SUCCESS;
598}
599
600DEFUN(cfg_bts_lac,
601 cfg_bts_lac_cmd,
602 "location_area_code <0-255>",
603 "Set the Location Area Code (LAC) of this BTS\n")
604{
605 struct gsm_bts *bts = vty->index;
606 int lac = atoi(argv[0]);
607
608 if (lac < 0 || lac > 0xff) {
609 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
610 lac, VTY_NEWLINE);
611 return CMD_WARNING;
612 }
613 bts->location_area_code = lac;
614
615 return CMD_SUCCESS;
616}
617
618DEFUN(cfg_bts_tsc,
619 cfg_bts_tsc_cmd,
620 "training_sequence_code <0-255>",
621 "Set the Training Sequence Code (TSC) of this BTS\n")
622{
623 struct gsm_bts *bts = vty->index;
624 int tsc = atoi(argv[0]);
625
626 if (tsc < 0 || tsc > 0xff) {
627 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
628 tsc, VTY_NEWLINE);
629 return CMD_WARNING;
630 }
631 bts->tsc = tsc;
632
633 return CMD_SUCCESS;
634}
635
636/* per TRX configuration */
637DEFUN(cfg_trx,
638 cfg_trx_cmd,
639 "trx TRX_NR",
640 "Select a TRX to configure")
641{
642 int trx_nr = atoi(argv[0]);
643 struct gsm_bts *bts = vty->index;
644 struct gsm_bts_trx *trx;
645
646 if (trx_nr > BTS_MAX_TRX) {
647 vty_out(vty, "%% This version of OpenBSC only supports %u TRX%s",
648 BTS_MAX_TRX+1, VTY_NEWLINE);
649 return CMD_WARNING;
650 }
651
652 if (trx_nr >= bts->num_trx)
653 bts->num_trx = trx_nr+1;
654
655 trx = &bts->trx[trx_nr];
656
657 vty->index = trx;
658 vty->node = TRX_NODE;
659
660 return CMD_SUCCESS;
661}
662
663DEFUN(cfg_trx_arfcn,
664 cfg_trx_arfcn_cmd,
665 "arfcn <1-1024>",
666 "Set the ARFCN for this TRX\n")
667{
668 int arfcn = atoi(argv[0]);
669 struct gsm_bts_trx *trx = vty->index;
670
671 /* FIXME: check if this ARFCN is supported by this TRX */
672
673 trx->arfcn = arfcn;
674
675 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
676 /* FIXME: use OML layer to update the ARFCN */
677 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
678
679 return CMD_SUCCESS;
680}
681
682/* per TS configuration */
683DEFUN(cfg_ts,
684 cfg_ts_cmd,
685 "timeslot TS_NR",
686 "Select a Timeslot to configure")
687{
688 int ts_nr = atoi(argv[0]);
689 struct gsm_bts_trx *trx = vty->index;
690 struct gsm_bts_trx_ts *ts;
691
692 if (ts_nr >= TRX_NR_TS) {
693 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
694 TRX_NR_TS, VTY_NEWLINE);
695 return CMD_WARNING;
696 }
697
698 ts = &trx->ts[ts_nr];
699
700 vty->index = ts;
701 vty->node = TS_NODE;
702
703 return CMD_SUCCESS;
704}
705
706
Harald Welte68628e82009-03-10 12:17:57 +0000707int bsc_vty_init(struct gsm_network *net)
708{
709 gsmnet = net;
710
711 cmd_init(1);
712 vty_init();
713
714 install_element(VIEW_NODE, &show_net_cmd);
715 install_element(VIEW_NODE, &show_bts_cmd);
716 install_element(VIEW_NODE, &show_trx_cmd);
717 install_element(VIEW_NODE, &show_ts_cmd);
718 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +0000719
720 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000721 install_element(VIEW_NODE, &show_e1line_cmd);
722 install_element(VIEW_NODE, &show_e1ts_cmd);
723
Harald Weltef5025b62009-03-28 16:55:11 +0000724 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +0000725
726 install_element(CONFIG_NODE, &cfg_bts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000727 install_node(&bts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000728 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000729 install_element(BTS_NODE, &cfg_bts_type_cmd);
730 install_element(BTS_NODE, &cfg_bts_lac_cmd);
731 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000732
Harald Welte5258fc42009-03-28 19:07:53 +0000733 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000734 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000735 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000736 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000737
Harald Welte5258fc42009-03-28 19:07:53 +0000738 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000739 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000740 install_default(TS_NODE);
Harald Welte68628e82009-03-10 12:17:57 +0000741
742 return 0;
743}