blob: 34743bea1c55f9121fe9104a6309fb4a8e685ba4 [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 Welte1bc77352009-03-10 19:47:51 +000090 vty_out(vty, " E1 Line %u, Timeslot %u, Type %s%s",
91 e1l->ts->line->num, e1l->ts->num,
92 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000093 vty_out(vty, " E1 TEI %u, SAPI %u%s\n",
94 e1l->tei, e1l->sapi, VTY_NEWLINE);
95}
96
97static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
98{
99 vty_out(vty, "BTS %u is of %s type, has LAC %u, TSC %u and %u TRX%s",
100 bts->nr, btstype2str(bts->type), bts->location_area_code,
101 bts->tsc, bts->num_trx, VTY_NEWLINE);
102 vty_out(vty, " NM State: ");
103 net_dump_nmstate(vty, &bts->nm_state);
104 vty_out(vty, " Site Mgr NM State: ");
105 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
106 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
107 bts->paging.available_slots, VTY_NEWLINE);
108 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
109 e1isl_dump_vty(vty, bts->oml_link);
110 /* FIXME: oml_link, chan_desc */
111}
112
113DEFUN(show_bts, show_bts_cmd, "show bts [number]",
114 SHOW_STR "Display information about a BTS\n"
115 "BTS number")
116{
117 struct gsm_network *net = gsmnet;
118 int bts_nr;
119
120 if (argc != 0) {
121 /* use the BTS number that the user has specified */
122 bts_nr = atoi(argv[0]);
123 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000124 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000125 VTY_NEWLINE);
126 return CMD_WARNING;
127 }
128 bts_dump_vty(vty, &net->bts[bts_nr]);
129 return CMD_SUCCESS;
130 }
131 /* print all BTS's */
132 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
133 bts_dump_vty(vty, &net->bts[bts_nr]);
134
135 return CMD_SUCCESS;
136}
137
138static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
139{
140 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
141 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
142 vty_out(vty, " NM State: ");
143 net_dump_nmstate(vty, &trx->nm_state);
144 vty_out(vty, " Baseband Transceiver NM State: ");
145 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
146 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
147 e1isl_dump_vty(vty, trx->rsl_link);
148}
149
150DEFUN(show_trx,
151 show_trx_cmd,
152 "show trx [bts_nr] [trx_nr]",
153 SHOW_STR "Display information about a TRX\n")
154{
155 struct gsm_network *net = gsmnet;
156 struct gsm_bts *bts = NULL;
157 struct gsm_bts_trx *trx;
158 int bts_nr, trx_nr;
159
160 if (argc >= 1) {
161 /* use the BTS number that the user has specified */
162 bts_nr = atoi(argv[0]);
163 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000164 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000165 VTY_NEWLINE);
166 return CMD_WARNING;
167 }
168 bts = &net->bts[bts_nr];
169 }
170 if (argc >= 2) {
171 trx_nr = atoi(argv[1]);
172 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000173 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000174 VTY_NEWLINE);
175 return CMD_WARNING;
176 }
177 trx = &bts->trx[trx_nr];
178 trx_dump_vty(vty, trx);
179 return CMD_SUCCESS;
180 }
181 if (bts) {
182 /* print all TRX in this BTS */
183 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
184 trx = &bts->trx[trx_nr];
185 trx_dump_vty(vty, trx);
186 }
187 return CMD_SUCCESS;
188 }
189
190 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
191 bts = &net->bts[bts_nr];
192 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
193 trx = &bts->trx[trx_nr];
194 trx_dump_vty(vty, trx);
195 }
196 }
197
198 return CMD_SUCCESS;
199}
200
201static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
202{
203 struct in_addr ia;
204
205 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
206 ts->nr, ts->trx->nr, ts->trx->bts->nr,
207 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
208 vty_out(vty, " NM State: ");
209 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000210 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);
Harald Welteef235b52009-03-10 12:34:02 +0000216 } else {
217 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
218 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
219 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000220 }
221}
222
223DEFUN(show_ts,
224 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000225 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000226 SHOW_STR "Display information about a TS\n")
227{
228 struct gsm_network *net = gsmnet;
229 struct gsm_bts *bts;
230 struct gsm_bts_trx *trx;
231 struct gsm_bts_trx_ts *ts;
232 int bts_nr, trx_nr, ts_nr;
233
234 if (argc >= 1) {
235 /* use the BTS number that the user has specified */
236 bts_nr = atoi(argv[0]);
237 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000238 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000239 VTY_NEWLINE);
240 return CMD_WARNING;
241 }
242 bts = &net->bts[bts_nr];
243 }
244 if (argc >= 2) {
245 trx_nr = atoi(argv[1]);
246 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000247 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000248 VTY_NEWLINE);
249 return CMD_WARNING;
250 }
251 trx = &bts->trx[trx_nr];
252 }
253 if (argc >= 3) {
254 ts_nr = atoi(argv[2]);
255 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000256 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000257 VTY_NEWLINE);
258 return CMD_WARNING;
259 }
260 ts = &trx->ts[ts_nr];
261 ts_dump_vty(vty, ts);
262 return CMD_SUCCESS;
263 }
264 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
265 bts = &net->bts[bts_nr];
266 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
267 trx = &bts->trx[trx_nr];
268 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
269 ts = &trx->ts[ts_nr];
270 ts_dump_vty(vty, ts);
271 }
272 }
273 }
274
275 return CMD_SUCCESS;
276}
277
278static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
279{
280 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000281 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000282 if (subscr->extension)
283 vty_out(vty, " Extension: %s%s", subscr->extension,
284 VTY_NEWLINE);
285 if (subscr->imsi)
286 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
287 if (subscr->tmsi)
288 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
289}
290
291static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
292{
293 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
294 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
295 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
296 VTY_NEWLINE);
297 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
298 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
299 lchan->ms_power, VTY_NEWLINE);
300 if (lchan->subscr) {
301 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
302 subscr_dump_vty(vty, lchan->subscr);
303 } else
304 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
305}
306
307static void call_dump_vty(struct vty *vty, struct gsm_call *call)
308{
309 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
310 call->type, call->state, call->transaction_id, VTY_NEWLINE);
311
312 if (call->local_lchan) {
313 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
314 lchan_dump_vty(vty, call->local_lchan);
315 } else
316 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
317
318 if (call->remote_lchan) {
319 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
320 lchan_dump_vty(vty, call->remote_lchan);
321 } else
322 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
323
324 if (call->called_subscr) {
325 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
326 subscr_dump_vty(vty, call->called_subscr);
327 } else
328 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
329}
330
331DEFUN(show_lchan,
332 show_lchan_cmd,
333 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
334 SHOW_STR "Display information about a logical channel\n")
335{
336 struct gsm_network *net = gsmnet;
337 struct gsm_bts *bts;
338 struct gsm_bts_trx *trx;
339 struct gsm_bts_trx_ts *ts;
340 struct gsm_lchan *lchan;
341 int bts_nr, trx_nr, ts_nr, lchan_nr;
342
343 if (argc >= 1) {
344 /* use the BTS number that the user has specified */
345 bts_nr = atoi(argv[0]);
346 if (bts_nr >= net->num_bts) {
347 vty_out(vty, "%% can't find BTS %s%s", argv[0],
348 VTY_NEWLINE);
349 return CMD_WARNING;
350 }
351 bts = &net->bts[bts_nr];
352 }
353 if (argc >= 2) {
354 trx_nr = atoi(argv[1]);
355 if (trx_nr >= bts->num_trx) {
356 vty_out(vty, "%% can't find TRX %s%s", argv[1],
357 VTY_NEWLINE);
358 return CMD_WARNING;
359 }
360 trx = &bts->trx[trx_nr];
361 }
362 if (argc >= 3) {
363 ts_nr = atoi(argv[2]);
364 if (ts_nr >= TRX_NR_TS) {
365 vty_out(vty, "%% can't find TS %s%s", argv[2],
366 VTY_NEWLINE);
367 return CMD_WARNING;
368 }
369 ts = &trx->ts[ts_nr];
370 }
371 if (argc >= 4) {
372 lchan_nr = atoi(argv[3]);
373 if (lchan_nr >= TS_MAX_LCHAN) {
374 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
375 VTY_NEWLINE);
376 return CMD_WARNING;
377 }
378 lchan = &ts->lchan[lchan_nr];
379 lchan_dump_vty(vty, lchan);
380 return CMD_SUCCESS;
381 }
382 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
383 bts = &net->bts[bts_nr];
384 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
385 trx = &bts->trx[trx_nr];
386 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
387 ts = &trx->ts[ts_nr];
388 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
389 lchan_nr++) {
390 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000391 if (lchan->type == GSM_LCHAN_NONE)
392 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000393 lchan_dump_vty(vty, lchan);
394 }
395 }
396 }
397 }
398
399 return CMD_SUCCESS;
400}
401
Harald Welte1bc77352009-03-10 19:47:51 +0000402static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
403{
404 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
405}
406
407DEFUN(show_e1drv,
408 show_e1drv_cmd,
409 "show e1_driver",
410 SHOW_STR "Display information about available E1 drivers\n")
411{
412 struct e1inp_driver *drv;
413
414 llist_for_each_entry(drv, &e1inp_driver_list, list)
415 e1drv_dump_vty(vty, drv);
416
417 return CMD_SUCCESS;
418}
419
Harald Welte68628e82009-03-10 12:17:57 +0000420static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
421{
422 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
423 line->num, line->name ? line->name : "",
424 line->driver->name, VTY_NEWLINE);
425}
426
427DEFUN(show_e1line,
428 show_e1line_cmd,
429 "show e1_line [line_nr]",
430 SHOW_STR "Display information about a E1 line\n")
431{
Harald Welte1bc77352009-03-10 19:47:51 +0000432 struct e1inp_line *line;
433
434 if (argc >= 1) {
435 int num = atoi(argv[0]);
436 llist_for_each_entry(line, &e1inp_line_list, list) {
437 if (line->num == num) {
438 e1line_dump_vty(vty, line);
439 return CMD_SUCCESS;
440 }
441 }
442 return CMD_WARNING;
443 }
444
445 llist_for_each_entry(line, &e1inp_line_list, list)
446 e1line_dump_vty(vty, line);
447
448 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000449}
450
451static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
452{
Harald Welte1bc77352009-03-10 19:47:51 +0000453 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
454 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
455 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000456}
457
458DEFUN(show_e1ts,
459 show_e1ts_cmd,
460 "show e1_timeslot [line_nr] [ts_nr]",
461 SHOW_STR "Display information about a E1 timeslot\n")
462{
Harald Welte1bc77352009-03-10 19:47:51 +0000463 struct e1inp_line *line;
464 struct e1inp_ts *ts;
465 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000466
Harald Welte1bc77352009-03-10 19:47:51 +0000467 if (argc == 0) {
468 llist_for_each_entry(line, &e1inp_line_list, list) {
469 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
470 ts = &line->ts[ts_nr];
471 e1ts_dump_vty(vty, ts);
472 }
473 }
474 return CMD_SUCCESS;
475 }
476 if (argc >= 1) {
477 int num = atoi(argv[0]);
478 llist_for_each_entry(line, &e1inp_line_list, list) {
479 if (line->num == num)
480 break;
481 }
482 if (!line || line->num != num) {
483 vty_out(vty, "E1 line %s is invalid%s",
484 argv[0], VTY_NEWLINE);
485 return CMD_WARNING;
486 }
487 }
488 if (argc >= 2) {
489 ts_nr = atoi(argv[1]);
490 if (ts_nr > NUM_E1_TS) {
491 vty_out(vty, "E1 timeslot %s is invalid%s",
492 argv[1], VTY_NEWLINE);
493 return CMD_WARNING;
494 }
495 ts = &line->ts[ts_nr];
496 e1ts_dump_vty(vty, ts);
497 return CMD_SUCCESS;
498 } else {
499 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
500 ts = &line->ts[ts_nr];
501 e1ts_dump_vty(vty, ts);
502 }
503 return CMD_SUCCESS;
504 }
505 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000506}
507
Harald Weltef5025b62009-03-28 16:55:11 +0000508void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
509{
510 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
511 subscr_dump_vty(vty, pag->subscr);
512}
513
514void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
515{
516 struct gsm_paging_request *pag;
517
518 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
519 paging_dump_vty(vty, pag);
520}
521
522DEFUN(show_paging,
523 show_paging_cmd,
524 "show paging [bts_nr]",
525 SHOW_STR "Display information about pating reuqests of a BTS\n")
526{
527 struct gsm_network *net = gsmnet;
528 struct gsm_bts *bts;
529 int bts_nr;
530
531 if (argc >= 1) {
532 /* use the BTS number that the user has specified */
533 bts_nr = atoi(argv[0]);
534 if (bts_nr >= net->num_bts) {
535 vty_out(vty, "%% can't find BTS %s%s", argv[0],
536 VTY_NEWLINE);
537 return CMD_WARNING;
538 }
539 bts = &net->bts[bts_nr];
540 bts_paging_dump_vty(vty, bts);
541
542 return CMD_SUCCESS;
543 }
544 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
545 bts = &net->bts[bts_nr];
546 bts_paging_dump_vty(vty, bts);
547 }
548
549 return CMD_SUCCESS;
550}
551
Harald Welte5258fc42009-03-28 19:07:53 +0000552/* per-BTS configuration */
553DEFUN(cfg_bts,
554 cfg_bts_cmd,
555 "bts BTS_NR",
556 "Select a BTS to configure\n")
557{
558 int bts_nr = atoi(argv[0]);
559 struct gsm_bts *bts;
560
561 if (bts_nr >= GSM_MAX_BTS) {
562 vty_out(vty, "%% This Version of OpenBSC only supports %u BTS%s",
563 GSM_MAX_BTS, VTY_NEWLINE);
564 return CMD_WARNING;
565 }
566 bts = &gsmnet->bts[bts_nr];
567 if (bts_nr >= gsmnet->num_bts)
568 gsmnet->num_bts = bts_nr + 1;
569
570 vty->index = bts;
571 vty->node = BTS_NODE;
572
573 return CMD_SUCCESS;
574}
575
576DEFUN(cfg_bts_type,
577 cfg_bts_type_cmd,
578 "type TYPE",
579 "Set the BTS type\n")
580{
581 struct gsm_bts *bts = vty->index;
582
583 //bts->type =
584 return CMD_SUCCESS;
585}
586
587DEFUN(cfg_bts_lac,
588 cfg_bts_lac_cmd,
589 "location_area_code <0-255>",
590 "Set the Location Area Code (LAC) of this BTS\n")
591{
592 struct gsm_bts *bts = vty->index;
593 int lac = atoi(argv[0]);
594
595 if (lac < 0 || lac > 0xff) {
596 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
597 lac, VTY_NEWLINE);
598 return CMD_WARNING;
599 }
600 bts->location_area_code = lac;
601
602 return CMD_SUCCESS;
603}
604
605DEFUN(cfg_bts_tsc,
606 cfg_bts_tsc_cmd,
607 "training_sequence_code <0-255>",
608 "Set the Training Sequence Code (TSC) of this BTS\n")
609{
610 struct gsm_bts *bts = vty->index;
611 int tsc = atoi(argv[0]);
612
613 if (tsc < 0 || tsc > 0xff) {
614 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
615 tsc, VTY_NEWLINE);
616 return CMD_WARNING;
617 }
618 bts->tsc = tsc;
619
620 return CMD_SUCCESS;
621}
622
623/* per TRX configuration */
624DEFUN(cfg_trx,
625 cfg_trx_cmd,
626 "trx TRX_NR",
627 "Select a TRX to configure")
628{
629 int trx_nr = atoi(argv[0]);
630 struct gsm_bts *bts = vty->index;
631 struct gsm_bts_trx *trx;
632
633 if (trx_nr > BTS_MAX_TRX) {
634 vty_out(vty, "%% This version of OpenBSC only supports %u TRX%s",
635 BTS_MAX_TRX+1, VTY_NEWLINE);
636 return CMD_WARNING;
637 }
638
639 if (trx_nr >= bts->num_trx)
640 bts->num_trx = trx_nr+1;
641
642 trx = &bts->trx[trx_nr];
643
644 vty->index = trx;
645 vty->node = TRX_NODE;
646
647 return CMD_SUCCESS;
648}
649
650DEFUN(cfg_trx_arfcn,
651 cfg_trx_arfcn_cmd,
652 "arfcn <1-1024>",
653 "Set the ARFCN for this TRX\n")
654{
655 int arfcn = atoi(argv[0]);
656 struct gsm_bts_trx *trx = vty->index;
657
658 /* FIXME: check if this ARFCN is supported by this TRX */
659
660 trx->arfcn = arfcn;
661
662 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
663 /* FIXME: use OML layer to update the ARFCN */
664 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
665
666 return CMD_SUCCESS;
667}
668
669/* per TS configuration */
670DEFUN(cfg_ts,
671 cfg_ts_cmd,
672 "timeslot TS_NR",
673 "Select a Timeslot to configure")
674{
675 int ts_nr = atoi(argv[0]);
676 struct gsm_bts_trx *trx = vty->index;
677 struct gsm_bts_trx_ts *ts;
678
679 if (ts_nr >= TRX_NR_TS) {
680 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
681 TRX_NR_TS, VTY_NEWLINE);
682 return CMD_WARNING;
683 }
684
685 ts = &trx->ts[ts_nr];
686
687 vty->index = ts;
688 vty->node = TS_NODE;
689
690 return CMD_SUCCESS;
691}
692
693
Harald Welte68628e82009-03-10 12:17:57 +0000694int bsc_vty_init(struct gsm_network *net)
695{
696 gsmnet = net;
697
698 cmd_init(1);
699 vty_init();
700
701 install_element(VIEW_NODE, &show_net_cmd);
702 install_element(VIEW_NODE, &show_bts_cmd);
703 install_element(VIEW_NODE, &show_trx_cmd);
704 install_element(VIEW_NODE, &show_ts_cmd);
705 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +0000706
707 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000708 install_element(VIEW_NODE, &show_e1line_cmd);
709 install_element(VIEW_NODE, &show_e1ts_cmd);
710
Harald Weltef5025b62009-03-28 16:55:11 +0000711 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +0000712
713 install_element(CONFIG_NODE, &cfg_bts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000714 install_node(&bts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000715 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000716 install_element(BTS_NODE, &cfg_bts_type_cmd);
717 install_element(BTS_NODE, &cfg_bts_lac_cmd);
718 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000719
Harald Welte5258fc42009-03-28 19:07:53 +0000720 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000721 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000722 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000723 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000724
Harald Welte5258fc42009-03-28 19:07:53 +0000725 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000726 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000727 install_default(TS_NODE);
Harald Welte68628e82009-03-10 12:17:57 +0000728
729 return 0;
730}