blob: a2b3e56205fdb068d143515712084c99d93ed546 [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 Welte40f82892009-05-23 17:31:39 +000035#include <openbsc/db.h>
Harald Welte68628e82009-03-10 12:17:57 +000036
37static struct gsm_network *gsmnet;
38
39struct cmd_node bts_node = {
40 BTS_NODE,
41 "%s(bts)#",
42 1,
43};
44
45struct cmd_node trx_node = {
46 TRX_NODE,
47 "%s(trx)#",
48 1,
49};
50
51struct cmd_node ts_node = {
52 TS_NODE,
53 "%s(ts)#",
54 1,
55};
56
Harald Welte40f82892009-05-23 17:31:39 +000057struct cmd_node subscr_node = {
58 SUBSCR_NODE,
59 "%s(subscriber)#",
60 1,
61};
62
Harald Welte68628e82009-03-10 12:17:57 +000063static int dummy_config_write(struct vty *v)
64{
65 return CMD_SUCCESS;
66}
67
68static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
69{
Harald Welte1bc77352009-03-10 19:47:51 +000070 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
71 nm_opstate_name(nms->operational), nms->administrative,
72 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000073}
74
75static void net_dump_vty(struct vty *vty, struct gsm_network *net)
76{
Harald Welteef235b52009-03-10 12:34:02 +000077 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
78 "and has %u BTS%s", net->country_code, net->network_code,
79 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000080 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000081 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000082 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000083 net->name_short, VTY_NEWLINE);
84}
85
86DEFUN(show_net, show_net_cmd, "show network",
87 SHOW_STR "Display information about a GSM NETWORK\n")
88{
89 struct gsm_network *net = gsmnet;
90 net_dump_vty(vty, net);
91
92 return CMD_SUCCESS;
93}
94
95static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
96{
Harald Welteedb37782009-05-01 14:59:07 +000097 struct e1inp_line *line;
98
99 if (!e1l) {
100 vty_out(vty, " None%s", VTY_NEWLINE);
101 return;
102 }
103
104 line = e1l->ts->line;
105
106 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
107 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000108 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000109 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000110 e1l->tei, e1l->sapi, VTY_NEWLINE);
111}
112
113static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
114{
Harald Weltefcd24452009-06-20 18:15:19 +0200115 vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, "
116 "BSIC %u, TSC %u and %u TRX%s",
117 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
118 bts->location_area_code, bts->bsic, bts->tsc,
119 bts->num_trx, VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000120 if (is_ipaccess_bts(bts))
121 vty_out(vty, " Unit ID: %u/%u/0%s",
122 bts->ip_access.site_id, bts->ip_access.bts_id,
123 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000124 vty_out(vty, " NM State: ");
125 net_dump_nmstate(vty, &bts->nm_state);
126 vty_out(vty, " Site Mgr NM State: ");
127 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
128 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
129 bts->paging.available_slots, VTY_NEWLINE);
130 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
131 e1isl_dump_vty(vty, bts->oml_link);
132 /* FIXME: oml_link, chan_desc */
133}
134
135DEFUN(show_bts, show_bts_cmd, "show bts [number]",
136 SHOW_STR "Display information about a BTS\n"
137 "BTS number")
138{
139 struct gsm_network *net = gsmnet;
140 int bts_nr;
141
142 if (argc != 0) {
143 /* use the BTS number that the user has specified */
144 bts_nr = atoi(argv[0]);
145 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000146 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000147 VTY_NEWLINE);
148 return CMD_WARNING;
149 }
150 bts_dump_vty(vty, &net->bts[bts_nr]);
151 return CMD_SUCCESS;
152 }
153 /* print all BTS's */
154 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
155 bts_dump_vty(vty, &net->bts[bts_nr]);
156
157 return CMD_SUCCESS;
158}
159
160static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
161{
162 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
163 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200164 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
165 "resulting BS power: %d dBm\n",
166 trx->nominal_power, trx->max_power_red,
167 trx->nominal_power - trx->max_power_red);
Harald Welte68628e82009-03-10 12:17:57 +0000168 vty_out(vty, " NM State: ");
169 net_dump_nmstate(vty, &trx->nm_state);
170 vty_out(vty, " Baseband Transceiver NM State: ");
171 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
172 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
173 e1isl_dump_vty(vty, trx->rsl_link);
174}
175
176DEFUN(show_trx,
177 show_trx_cmd,
178 "show trx [bts_nr] [trx_nr]",
179 SHOW_STR "Display information about a TRX\n")
180{
181 struct gsm_network *net = gsmnet;
182 struct gsm_bts *bts = NULL;
183 struct gsm_bts_trx *trx;
184 int bts_nr, trx_nr;
185
186 if (argc >= 1) {
187 /* use the BTS number that the user has specified */
188 bts_nr = atoi(argv[0]);
189 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000190 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000191 VTY_NEWLINE);
192 return CMD_WARNING;
193 }
194 bts = &net->bts[bts_nr];
195 }
196 if (argc >= 2) {
197 trx_nr = atoi(argv[1]);
198 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000199 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000200 VTY_NEWLINE);
201 return CMD_WARNING;
202 }
203 trx = &bts->trx[trx_nr];
204 trx_dump_vty(vty, trx);
205 return CMD_SUCCESS;
206 }
207 if (bts) {
208 /* print all TRX in this BTS */
209 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
210 trx = &bts->trx[trx_nr];
211 trx_dump_vty(vty, trx);
212 }
213 return CMD_SUCCESS;
214 }
215
216 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
217 bts = &net->bts[bts_nr];
218 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
219 trx = &bts->trx[trx_nr];
220 trx_dump_vty(vty, trx);
221 }
222 }
223
224 return CMD_SUCCESS;
225}
226
227static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
228{
229 struct in_addr ia;
230
231 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
232 ts->nr, ts->trx->nr, ts->trx->bts->nr,
233 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
234 vty_out(vty, " NM State: ");
235 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000236 if (is_ipaccess_bts(ts->trx->bts)) {
237 ia.s_addr = ts->abis_ip.bound_ip;
238 vty_out(vty, " Bound IP: %s Port %u FC=%u F8=%u%s",
239 inet_ntoa(ia), ts->abis_ip.bound_port,
240 ts->abis_ip.attr_fc, ts->abis_ip.attr_f8,
241 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000242 } else {
243 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
244 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
245 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000246 }
247}
248
249DEFUN(show_ts,
250 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000251 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000252 SHOW_STR "Display information about a TS\n")
253{
254 struct gsm_network *net = gsmnet;
255 struct gsm_bts *bts;
256 struct gsm_bts_trx *trx;
257 struct gsm_bts_trx_ts *ts;
258 int bts_nr, trx_nr, ts_nr;
259
260 if (argc >= 1) {
261 /* use the BTS number that the user has specified */
262 bts_nr = atoi(argv[0]);
263 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000264 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000265 VTY_NEWLINE);
266 return CMD_WARNING;
267 }
268 bts = &net->bts[bts_nr];
269 }
270 if (argc >= 2) {
271 trx_nr = atoi(argv[1]);
272 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000273 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000274 VTY_NEWLINE);
275 return CMD_WARNING;
276 }
277 trx = &bts->trx[trx_nr];
278 }
279 if (argc >= 3) {
280 ts_nr = atoi(argv[2]);
281 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000282 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000283 VTY_NEWLINE);
284 return CMD_WARNING;
285 }
286 ts = &trx->ts[ts_nr];
287 ts_dump_vty(vty, ts);
288 return CMD_SUCCESS;
289 }
290 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
291 bts = &net->bts[bts_nr];
292 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
293 trx = &bts->trx[trx_nr];
294 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
295 ts = &trx->ts[ts_nr];
296 ts_dump_vty(vty, ts);
297 }
298 }
299 }
300
301 return CMD_SUCCESS;
302}
303
304static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
305{
Harald Weltefcd24452009-06-20 18:15:19 +0200306 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000307 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000308 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000309 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000310 if (subscr->extension)
311 vty_out(vty, " Extension: %s%s", subscr->extension,
312 VTY_NEWLINE);
313 if (subscr->imsi)
314 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
315 if (subscr->tmsi)
316 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
317}
318
319static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
320{
321 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
322 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
323 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
324 VTY_NEWLINE);
325 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
326 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
327 lchan->ms_power, VTY_NEWLINE);
328 if (lchan->subscr) {
329 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
330 subscr_dump_vty(vty, lchan->subscr);
331 } else
332 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
333}
334
Harald Welte4bfdfe72009-06-10 23:11:52 +0800335#if 0
336TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000337static void call_dump_vty(struct vty *vty, struct gsm_call *call)
338{
339 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
340 call->type, call->state, call->transaction_id, VTY_NEWLINE);
341
342 if (call->local_lchan) {
343 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
344 lchan_dump_vty(vty, call->local_lchan);
345 } else
346 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
347
348 if (call->remote_lchan) {
349 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
350 lchan_dump_vty(vty, call->remote_lchan);
351 } else
352 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
353
354 if (call->called_subscr) {
355 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
356 subscr_dump_vty(vty, call->called_subscr);
357 } else
358 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
359}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800360#endif
Harald Welte68628e82009-03-10 12:17:57 +0000361
362DEFUN(show_lchan,
363 show_lchan_cmd,
364 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
365 SHOW_STR "Display information about a logical channel\n")
366{
367 struct gsm_network *net = gsmnet;
368 struct gsm_bts *bts;
369 struct gsm_bts_trx *trx;
370 struct gsm_bts_trx_ts *ts;
371 struct gsm_lchan *lchan;
372 int bts_nr, trx_nr, ts_nr, lchan_nr;
373
374 if (argc >= 1) {
375 /* use the BTS number that the user has specified */
376 bts_nr = atoi(argv[0]);
377 if (bts_nr >= net->num_bts) {
378 vty_out(vty, "%% can't find BTS %s%s", argv[0],
379 VTY_NEWLINE);
380 return CMD_WARNING;
381 }
382 bts = &net->bts[bts_nr];
383 }
384 if (argc >= 2) {
385 trx_nr = atoi(argv[1]);
386 if (trx_nr >= bts->num_trx) {
387 vty_out(vty, "%% can't find TRX %s%s", argv[1],
388 VTY_NEWLINE);
389 return CMD_WARNING;
390 }
391 trx = &bts->trx[trx_nr];
392 }
393 if (argc >= 3) {
394 ts_nr = atoi(argv[2]);
395 if (ts_nr >= TRX_NR_TS) {
396 vty_out(vty, "%% can't find TS %s%s", argv[2],
397 VTY_NEWLINE);
398 return CMD_WARNING;
399 }
400 ts = &trx->ts[ts_nr];
401 }
402 if (argc >= 4) {
403 lchan_nr = atoi(argv[3]);
404 if (lchan_nr >= TS_MAX_LCHAN) {
405 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
406 VTY_NEWLINE);
407 return CMD_WARNING;
408 }
409 lchan = &ts->lchan[lchan_nr];
410 lchan_dump_vty(vty, lchan);
411 return CMD_SUCCESS;
412 }
413 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
414 bts = &net->bts[bts_nr];
415 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
416 trx = &bts->trx[trx_nr];
417 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
418 ts = &trx->ts[ts_nr];
419 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
420 lchan_nr++) {
421 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000422 if (lchan->type == GSM_LCHAN_NONE)
423 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000424 lchan_dump_vty(vty, lchan);
425 }
426 }
427 }
428 }
429
430 return CMD_SUCCESS;
431}
432
Harald Welte1bc77352009-03-10 19:47:51 +0000433static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
434{
435 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
436}
437
438DEFUN(show_e1drv,
439 show_e1drv_cmd,
440 "show e1_driver",
441 SHOW_STR "Display information about available E1 drivers\n")
442{
443 struct e1inp_driver *drv;
444
445 llist_for_each_entry(drv, &e1inp_driver_list, list)
446 e1drv_dump_vty(vty, drv);
447
448 return CMD_SUCCESS;
449}
450
Harald Welte68628e82009-03-10 12:17:57 +0000451static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
452{
453 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
454 line->num, line->name ? line->name : "",
455 line->driver->name, VTY_NEWLINE);
456}
457
458DEFUN(show_e1line,
459 show_e1line_cmd,
460 "show e1_line [line_nr]",
461 SHOW_STR "Display information about a E1 line\n")
462{
Harald Welte1bc77352009-03-10 19:47:51 +0000463 struct e1inp_line *line;
464
465 if (argc >= 1) {
466 int num = atoi(argv[0]);
467 llist_for_each_entry(line, &e1inp_line_list, list) {
468 if (line->num == num) {
469 e1line_dump_vty(vty, line);
470 return CMD_SUCCESS;
471 }
472 }
473 return CMD_WARNING;
474 }
475
476 llist_for_each_entry(line, &e1inp_line_list, list)
477 e1line_dump_vty(vty, line);
478
479 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000480}
481
482static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
483{
Harald Welte1bc77352009-03-10 19:47:51 +0000484 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
485 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
486 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000487}
488
489DEFUN(show_e1ts,
490 show_e1ts_cmd,
491 "show e1_timeslot [line_nr] [ts_nr]",
492 SHOW_STR "Display information about a E1 timeslot\n")
493{
Harald Welte1bc77352009-03-10 19:47:51 +0000494 struct e1inp_line *line;
495 struct e1inp_ts *ts;
496 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000497
Harald Welte1bc77352009-03-10 19:47:51 +0000498 if (argc == 0) {
499 llist_for_each_entry(line, &e1inp_line_list, list) {
500 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
501 ts = &line->ts[ts_nr];
502 e1ts_dump_vty(vty, ts);
503 }
504 }
505 return CMD_SUCCESS;
506 }
507 if (argc >= 1) {
508 int num = atoi(argv[0]);
509 llist_for_each_entry(line, &e1inp_line_list, list) {
510 if (line->num == num)
511 break;
512 }
513 if (!line || line->num != num) {
514 vty_out(vty, "E1 line %s is invalid%s",
515 argv[0], VTY_NEWLINE);
516 return CMD_WARNING;
517 }
518 }
519 if (argc >= 2) {
520 ts_nr = atoi(argv[1]);
521 if (ts_nr > NUM_E1_TS) {
522 vty_out(vty, "E1 timeslot %s is invalid%s",
523 argv[1], VTY_NEWLINE);
524 return CMD_WARNING;
525 }
526 ts = &line->ts[ts_nr];
527 e1ts_dump_vty(vty, ts);
528 return CMD_SUCCESS;
529 } else {
530 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
531 ts = &line->ts[ts_nr];
532 e1ts_dump_vty(vty, ts);
533 }
534 return CMD_SUCCESS;
535 }
536 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000537}
538
Harald Weltebe4b7302009-05-23 16:59:33 +0000539static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000540{
541 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
542 subscr_dump_vty(vty, pag->subscr);
543}
544
Harald Weltebe4b7302009-05-23 16:59:33 +0000545static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000546{
547 struct gsm_paging_request *pag;
548
549 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
550 paging_dump_vty(vty, pag);
551}
552
553DEFUN(show_paging,
554 show_paging_cmd,
555 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000556 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000557{
558 struct gsm_network *net = gsmnet;
559 struct gsm_bts *bts;
560 int bts_nr;
561
562 if (argc >= 1) {
563 /* use the BTS number that the user has specified */
564 bts_nr = atoi(argv[0]);
565 if (bts_nr >= net->num_bts) {
566 vty_out(vty, "%% can't find BTS %s%s", argv[0],
567 VTY_NEWLINE);
568 return CMD_WARNING;
569 }
570 bts = &net->bts[bts_nr];
571 bts_paging_dump_vty(vty, bts);
572
573 return CMD_SUCCESS;
574 }
575 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
576 bts = &net->bts[bts_nr];
577 bts_paging_dump_vty(vty, bts);
578 }
579
580 return CMD_SUCCESS;
581}
582
Harald Welte40f82892009-05-23 17:31:39 +0000583/* per-subscriber configuration */
584DEFUN(cfg_subscr,
585 cfg_subscr_cmd,
586 "subscriber IMSI",
587 "Select a Subscriber to configure\n")
588{
589 const char *imsi = argv[0];
590 struct gsm_subscriber *subscr;
591
592 subscr = subscr_get_by_imsi(imsi);
593 if (!subscr) {
594 vty_out(vty, "%% No subscriber for IMSI %s%s",
595 imsi, VTY_NEWLINE);
596 return CMD_WARNING;
597 }
598
599 vty->index = subscr;
600 vty->node = SUBSCR_NODE;
601
602 return CMD_SUCCESS;
603}
604
605
Harald Welte5258fc42009-03-28 19:07:53 +0000606/* per-BTS configuration */
607DEFUN(cfg_bts,
608 cfg_bts_cmd,
609 "bts BTS_NR",
610 "Select a BTS to configure\n")
611{
612 int bts_nr = atoi(argv[0]);
613 struct gsm_bts *bts;
614
615 if (bts_nr >= GSM_MAX_BTS) {
616 vty_out(vty, "%% This Version of OpenBSC only supports %u BTS%s",
617 GSM_MAX_BTS, VTY_NEWLINE);
618 return CMD_WARNING;
619 }
620 bts = &gsmnet->bts[bts_nr];
621 if (bts_nr >= gsmnet->num_bts)
622 gsmnet->num_bts = bts_nr + 1;
623
624 vty->index = bts;
625 vty->node = BTS_NODE;
626
627 return CMD_SUCCESS;
628}
629
630DEFUN(cfg_bts_type,
631 cfg_bts_type_cmd,
632 "type TYPE",
633 "Set the BTS type\n")
634{
635 struct gsm_bts *bts = vty->index;
636
Harald Weltefcd24452009-06-20 18:15:19 +0200637 /* FIXME: implementation */
Harald Welte5258fc42009-03-28 19:07:53 +0000638 //bts->type =
639 return CMD_SUCCESS;
640}
641
Harald Weltefcd24452009-06-20 18:15:19 +0200642DEFUN(cfg_bts_band,
643 cfg_bts_band_cmd,
644 "band BAND",
645 "Set the frequency band of this BTS\n")
646{
647 struct gsm_bts *bts = vty->index;
648 int band = gsm_band_parse(atoi(argv[0]));
649
650 if (band < 0) {
651 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
652 band, VTY_NEWLINE);
653 return CMD_WARNING;
654 }
655
656 bts->band = band;
657
658 return CMD_SUCCESS;
659}
660
Harald Welte5258fc42009-03-28 19:07:53 +0000661DEFUN(cfg_bts_lac,
662 cfg_bts_lac_cmd,
663 "location_area_code <0-255>",
664 "Set the Location Area Code (LAC) of this BTS\n")
665{
666 struct gsm_bts *bts = vty->index;
667 int lac = atoi(argv[0]);
668
669 if (lac < 0 || lac > 0xff) {
670 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
671 lac, VTY_NEWLINE);
672 return CMD_WARNING;
673 }
674 bts->location_area_code = lac;
675
676 return CMD_SUCCESS;
677}
678
679DEFUN(cfg_bts_tsc,
680 cfg_bts_tsc_cmd,
681 "training_sequence_code <0-255>",
682 "Set the Training Sequence Code (TSC) of this BTS\n")
683{
684 struct gsm_bts *bts = vty->index;
685 int tsc = atoi(argv[0]);
686
687 if (tsc < 0 || tsc > 0xff) {
688 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
689 tsc, VTY_NEWLINE);
690 return CMD_WARNING;
691 }
692 bts->tsc = tsc;
693
694 return CMD_SUCCESS;
695}
696
Harald Welte78f2f502009-05-23 16:56:52 +0000697DEFUN(cfg_bts_bsic,
698 cfg_bts_bsic_cmd,
699 "base_station_id_code <0-63>",
700 "Set the Base Station Identity Code (BSIC) of this BTS\n")
701{
702 struct gsm_bts *bts = vty->index;
703 int bsic = atoi(argv[0]);
704
705 if (bsic < 0 || bsic > 0x3f) {
706 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
707 bsic, VTY_NEWLINE);
708 return CMD_WARNING;
709 }
710 bts->bsic = bsic;
711
712 return CMD_SUCCESS;
713}
714
715
Harald Welte4cc34222009-05-01 15:12:31 +0000716DEFUN(cfg_bts_unit_id,
717 cfg_bts_unit_id_cmd,
718 "unit_id <0-65534> <0-255>",
719 "Set the BTS Unit ID of this BTS\n")
720{
721 struct gsm_bts *bts = vty->index;
722 int site_id = atoi(argv[0]);
723 int bts_id = atoi(argv[1]);
724
725 if (site_id < 0 || site_id > 65534) {
726 vty_out(vty, "%% Site ID %d is not in the valid range%s",
727 site_id, VTY_NEWLINE);
728 return CMD_WARNING;
729 }
730 if (site_id < 0 || site_id > 255) {
731 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
732 bts_id, VTY_NEWLINE);
733 return CMD_WARNING;
734 }
735 bts->ip_access.site_id = site_id;
736 bts->ip_access.bts_id = bts_id;
737
738 return CMD_SUCCESS;
739}
740
Harald Welte5258fc42009-03-28 19:07:53 +0000741/* per TRX configuration */
742DEFUN(cfg_trx,
743 cfg_trx_cmd,
744 "trx TRX_NR",
745 "Select a TRX to configure")
746{
747 int trx_nr = atoi(argv[0]);
748 struct gsm_bts *bts = vty->index;
749 struct gsm_bts_trx *trx;
750
751 if (trx_nr > BTS_MAX_TRX) {
752 vty_out(vty, "%% This version of OpenBSC only supports %u TRX%s",
753 BTS_MAX_TRX+1, VTY_NEWLINE);
754 return CMD_WARNING;
755 }
756
757 if (trx_nr >= bts->num_trx)
758 bts->num_trx = trx_nr+1;
759
760 trx = &bts->trx[trx_nr];
761
762 vty->index = trx;
763 vty->node = TRX_NODE;
764
765 return CMD_SUCCESS;
766}
767
768DEFUN(cfg_trx_arfcn,
769 cfg_trx_arfcn_cmd,
770 "arfcn <1-1024>",
771 "Set the ARFCN for this TRX\n")
772{
773 int arfcn = atoi(argv[0]);
774 struct gsm_bts_trx *trx = vty->index;
775
776 /* FIXME: check if this ARFCN is supported by this TRX */
777
778 trx->arfcn = arfcn;
779
780 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
781 /* FIXME: use OML layer to update the ARFCN */
782 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
783
784 return CMD_SUCCESS;
785}
786
Harald Weltefcd24452009-06-20 18:15:19 +0200787DEFUN(cfg_trx_max_power_red,
788 cfg_trx_max_power_red_cmd,
789 "max_power_red <0-100>",
790 "Reduction of maximum BS RF Power in dB\n")
791{
792 int maxpwr_r = atoi(argv[0]);
793 struct gsm_bts_trx *trx = vty->index;
794 int upper_limit = 12; /* default 12.21 max power red. */
795
796 /* FIXME: check if our BTS type supports more than 12 */
797 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
798 vty_out(vty, "%% Power %d dB is not in the valid range%s",
799 maxpwr_r, VTY_NEWLINE);
800 return CMD_WARNING;
801 }
802 if (maxpwr_r & 1) {
803 vty_out(vty, "%% Power %d dB is not an even value%s",
804 maxpwr_r, VTY_NEWLINE);
805 return CMD_WARNING;
806 }
807
808 trx->max_power_red = maxpwr_r;
809
810 /* FIXME: make sure we update this using OML */
811
812 return CMD_SUCCESS;
813}
814
Harald Welte5258fc42009-03-28 19:07:53 +0000815/* per TS configuration */
816DEFUN(cfg_ts,
817 cfg_ts_cmd,
818 "timeslot TS_NR",
819 "Select a Timeslot to configure")
820{
821 int ts_nr = atoi(argv[0]);
822 struct gsm_bts_trx *trx = vty->index;
823 struct gsm_bts_trx_ts *ts;
824
825 if (ts_nr >= TRX_NR_TS) {
826 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
827 TRX_NR_TS, VTY_NEWLINE);
828 return CMD_WARNING;
829 }
830
831 ts = &trx->ts[ts_nr];
832
833 vty->index = ts;
834 vty->node = TS_NODE;
835
836 return CMD_SUCCESS;
837}
838
839
Harald Welte40f82892009-05-23 17:31:39 +0000840/* Subscriber */
841DEFUN(show_subscr,
842 show_subscr_cmd,
843 "show subscriber [IMSI]",
844 SHOW_STR "Display information about a subscriber\n")
845{
846 const char *imsi;
847 struct gsm_subscriber *subscr;
848
849 if (argc >= 1) {
850 imsi = argv[0];
851 subscr = subscr_get_by_imsi(imsi);
852 if (!subscr) {
853 vty_out(vty, "%% unknown subscriber%s",
854 VTY_NEWLINE);
855 return CMD_WARNING;
856 }
857 subscr_dump_vty(vty, subscr);
858
859 return CMD_SUCCESS;
860 }
861
862 /* FIXME: iterate over all subscribers ? */
863 return CMD_WARNING;
864
865 return CMD_SUCCESS;
866}
867
868DEFUN(cfg_subscr_name,
869 cfg_subscr_name_cmd,
870 "name NAME",
871 "Set the name of the subscriber")
872{
873 const char *name = argv[0];
874 struct gsm_subscriber *subscr = vty->index;
875
876 strncpy(subscr->name, name, sizeof(subscr->name));
877
878 db_sync_subscriber(subscr);
879
880 return CMD_SUCCESS;
881}
882
883DEFUN(cfg_subscr_extension,
884 cfg_subscr_extension_cmd,
885 "extension EXTENSION",
886 "Set the extension of the subscriber")
887{
888 const char *name = argv[0];
889 struct gsm_subscriber *subscr = vty->index;
890
891 strncpy(subscr->extension, name, sizeof(subscr->extension));
892
893 db_sync_subscriber(subscr);
894
895 return CMD_SUCCESS;
896}
897
898DEFUN(cfg_subscr_authorized,
899 cfg_subscr_authorized_cmd,
900 "auth <0-1>",
901 "Set the authorization status of the subscriber")
902{
903 int auth = atoi(argv[0]);
904 struct gsm_subscriber *subscr = vty->index;
905
906 if (auth)
907 subscr->authorized = 1;
908 else
909 subscr->authorized = 0;
910
911 db_sync_subscriber(subscr);
912
913 return CMD_SUCCESS;
914}
915
Harald Welte68628e82009-03-10 12:17:57 +0000916int bsc_vty_init(struct gsm_network *net)
917{
918 gsmnet = net;
919
920 cmd_init(1);
921 vty_init();
922
923 install_element(VIEW_NODE, &show_net_cmd);
924 install_element(VIEW_NODE, &show_bts_cmd);
925 install_element(VIEW_NODE, &show_trx_cmd);
926 install_element(VIEW_NODE, &show_ts_cmd);
927 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +0000928
929 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000930 install_element(VIEW_NODE, &show_e1line_cmd);
931 install_element(VIEW_NODE, &show_e1ts_cmd);
932
Harald Weltef5025b62009-03-28 16:55:11 +0000933 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +0000934
Harald Welte40f82892009-05-23 17:31:39 +0000935 install_element(VIEW_NODE, &show_subscr_cmd);
936
Harald Welte5258fc42009-03-28 19:07:53 +0000937 install_element(CONFIG_NODE, &cfg_bts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000938 install_node(&bts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000939 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000940 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +0200941 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +0000942 install_element(BTS_NODE, &cfg_bts_lac_cmd);
943 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +0000944 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000945
Harald Welte5258fc42009-03-28 19:07:53 +0000946 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000947 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000948 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000949 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +0200950 install_element(TRX_NODE, &cfg_trx_max_power_red);
Harald Welte68628e82009-03-10 12:17:57 +0000951
Harald Welte5258fc42009-03-28 19:07:53 +0000952 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000953 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000954 install_default(TS_NODE);
Harald Welte68628e82009-03-10 12:17:57 +0000955
Harald Welte40f82892009-05-23 17:31:39 +0000956 install_element(CONFIG_NODE, &cfg_subscr_cmd);
957 install_node(&subscr_node, dummy_config_write);
958 install_default(SUBSCR_NODE);
959 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
960 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
961 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
962
Harald Welte68628e82009-03-10 12:17:57 +0000963 return 0;
964}