blob: 44531dd505f47942330976cd5bf9325695024d23 [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 Welte78f2f502009-05-23 16:56:52 +0000115 vty_out(vty, "BTS %u is of %s type, has LAC %u, BSIC %u, TSC %u and %u TRX%s",
Harald Welte68628e82009-03-10 12:17:57 +0000116 bts->nr, btstype2str(bts->type), bts->location_area_code,
Harald Welte78f2f502009-05-23 16:56:52 +0000117 bts->bsic, bts->tsc, bts->num_trx, VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000118 if (is_ipaccess_bts(bts))
119 vty_out(vty, " Unit ID: %u/%u/0%s",
120 bts->ip_access.site_id, bts->ip_access.bts_id,
121 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000122 vty_out(vty, " NM State: ");
123 net_dump_nmstate(vty, &bts->nm_state);
124 vty_out(vty, " Site Mgr NM State: ");
125 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
126 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
127 bts->paging.available_slots, VTY_NEWLINE);
128 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
129 e1isl_dump_vty(vty, bts->oml_link);
130 /* FIXME: oml_link, chan_desc */
131}
132
133DEFUN(show_bts, show_bts_cmd, "show bts [number]",
134 SHOW_STR "Display information about a BTS\n"
135 "BTS number")
136{
137 struct gsm_network *net = gsmnet;
138 int bts_nr;
139
140 if (argc != 0) {
141 /* use the BTS number that the user has specified */
142 bts_nr = atoi(argv[0]);
143 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000144 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000145 VTY_NEWLINE);
146 return CMD_WARNING;
147 }
148 bts_dump_vty(vty, &net->bts[bts_nr]);
149 return CMD_SUCCESS;
150 }
151 /* print all BTS's */
152 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
153 bts_dump_vty(vty, &net->bts[bts_nr]);
154
155 return CMD_SUCCESS;
156}
157
158static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
159{
160 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
161 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
162 vty_out(vty, " NM State: ");
163 net_dump_nmstate(vty, &trx->nm_state);
164 vty_out(vty, " Baseband Transceiver NM State: ");
165 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
166 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
167 e1isl_dump_vty(vty, trx->rsl_link);
168}
169
170DEFUN(show_trx,
171 show_trx_cmd,
172 "show trx [bts_nr] [trx_nr]",
173 SHOW_STR "Display information about a TRX\n")
174{
175 struct gsm_network *net = gsmnet;
176 struct gsm_bts *bts = NULL;
177 struct gsm_bts_trx *trx;
178 int bts_nr, trx_nr;
179
180 if (argc >= 1) {
181 /* use the BTS number that the user has specified */
182 bts_nr = atoi(argv[0]);
183 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000184 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000185 VTY_NEWLINE);
186 return CMD_WARNING;
187 }
188 bts = &net->bts[bts_nr];
189 }
190 if (argc >= 2) {
191 trx_nr = atoi(argv[1]);
192 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000193 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000194 VTY_NEWLINE);
195 return CMD_WARNING;
196 }
197 trx = &bts->trx[trx_nr];
198 trx_dump_vty(vty, trx);
199 return CMD_SUCCESS;
200 }
201 if (bts) {
202 /* print all TRX in this BTS */
203 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
204 trx = &bts->trx[trx_nr];
205 trx_dump_vty(vty, trx);
206 }
207 return CMD_SUCCESS;
208 }
209
210 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
211 bts = &net->bts[bts_nr];
212 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
213 trx = &bts->trx[trx_nr];
214 trx_dump_vty(vty, trx);
215 }
216 }
217
218 return CMD_SUCCESS;
219}
220
221static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
222{
223 struct in_addr ia;
224
225 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
226 ts->nr, ts->trx->nr, ts->trx->bts->nr,
227 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
228 vty_out(vty, " NM State: ");
229 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000230 if (is_ipaccess_bts(ts->trx->bts)) {
231 ia.s_addr = ts->abis_ip.bound_ip;
232 vty_out(vty, " Bound IP: %s Port %u FC=%u F8=%u%s",
233 inet_ntoa(ia), ts->abis_ip.bound_port,
234 ts->abis_ip.attr_fc, ts->abis_ip.attr_f8,
235 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000236 } else {
237 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
238 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
239 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000240 }
241}
242
243DEFUN(show_ts,
244 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000245 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000246 SHOW_STR "Display information about a TS\n")
247{
248 struct gsm_network *net = gsmnet;
249 struct gsm_bts *bts;
250 struct gsm_bts_trx *trx;
251 struct gsm_bts_trx_ts *ts;
252 int bts_nr, trx_nr, ts_nr;
253
254 if (argc >= 1) {
255 /* use the BTS number that the user has specified */
256 bts_nr = atoi(argv[0]);
257 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000258 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000259 VTY_NEWLINE);
260 return CMD_WARNING;
261 }
262 bts = &net->bts[bts_nr];
263 }
264 if (argc >= 2) {
265 trx_nr = atoi(argv[1]);
266 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000267 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000268 VTY_NEWLINE);
269 return CMD_WARNING;
270 }
271 trx = &bts->trx[trx_nr];
272 }
273 if (argc >= 3) {
274 ts_nr = atoi(argv[2]);
275 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000276 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000277 VTY_NEWLINE);
278 return CMD_WARNING;
279 }
280 ts = &trx->ts[ts_nr];
281 ts_dump_vty(vty, ts);
282 return CMD_SUCCESS;
283 }
284 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
285 bts = &net->bts[bts_nr];
286 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
287 trx = &bts->trx[trx_nr];
288 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
289 ts = &trx->ts[ts_nr];
290 ts_dump_vty(vty, ts);
291 }
292 }
293 }
294
295 return CMD_SUCCESS;
296}
297
298static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
299{
Harald Welte40f82892009-05-23 17:31:39 +0000300 vty_out(vty, " ID: %lu, Authorized: %d%s", subscr->id,
301 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000302 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000303 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000304 if (subscr->extension)
305 vty_out(vty, " Extension: %s%s", subscr->extension,
306 VTY_NEWLINE);
307 if (subscr->imsi)
308 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
309 if (subscr->tmsi)
310 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
311}
312
313static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
314{
315 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
316 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
317 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
318 VTY_NEWLINE);
319 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
320 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
321 lchan->ms_power, VTY_NEWLINE);
322 if (lchan->subscr) {
323 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
324 subscr_dump_vty(vty, lchan->subscr);
325 } else
326 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
327}
328
329static void call_dump_vty(struct vty *vty, struct gsm_call *call)
330{
331 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
332 call->type, call->state, call->transaction_id, VTY_NEWLINE);
333
334 if (call->local_lchan) {
335 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
336 lchan_dump_vty(vty, call->local_lchan);
337 } else
338 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
339
340 if (call->remote_lchan) {
341 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
342 lchan_dump_vty(vty, call->remote_lchan);
343 } else
344 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
345
346 if (call->called_subscr) {
347 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
348 subscr_dump_vty(vty, call->called_subscr);
349 } else
350 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
351}
352
353DEFUN(show_lchan,
354 show_lchan_cmd,
355 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
356 SHOW_STR "Display information about a logical channel\n")
357{
358 struct gsm_network *net = gsmnet;
359 struct gsm_bts *bts;
360 struct gsm_bts_trx *trx;
361 struct gsm_bts_trx_ts *ts;
362 struct gsm_lchan *lchan;
363 int bts_nr, trx_nr, ts_nr, lchan_nr;
364
365 if (argc >= 1) {
366 /* use the BTS number that the user has specified */
367 bts_nr = atoi(argv[0]);
368 if (bts_nr >= net->num_bts) {
369 vty_out(vty, "%% can't find BTS %s%s", argv[0],
370 VTY_NEWLINE);
371 return CMD_WARNING;
372 }
373 bts = &net->bts[bts_nr];
374 }
375 if (argc >= 2) {
376 trx_nr = atoi(argv[1]);
377 if (trx_nr >= bts->num_trx) {
378 vty_out(vty, "%% can't find TRX %s%s", argv[1],
379 VTY_NEWLINE);
380 return CMD_WARNING;
381 }
382 trx = &bts->trx[trx_nr];
383 }
384 if (argc >= 3) {
385 ts_nr = atoi(argv[2]);
386 if (ts_nr >= TRX_NR_TS) {
387 vty_out(vty, "%% can't find TS %s%s", argv[2],
388 VTY_NEWLINE);
389 return CMD_WARNING;
390 }
391 ts = &trx->ts[ts_nr];
392 }
393 if (argc >= 4) {
394 lchan_nr = atoi(argv[3]);
395 if (lchan_nr >= TS_MAX_LCHAN) {
396 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
397 VTY_NEWLINE);
398 return CMD_WARNING;
399 }
400 lchan = &ts->lchan[lchan_nr];
401 lchan_dump_vty(vty, lchan);
402 return CMD_SUCCESS;
403 }
404 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
405 bts = &net->bts[bts_nr];
406 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
407 trx = &bts->trx[trx_nr];
408 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
409 ts = &trx->ts[ts_nr];
410 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
411 lchan_nr++) {
412 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000413 if (lchan->type == GSM_LCHAN_NONE)
414 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000415 lchan_dump_vty(vty, lchan);
416 }
417 }
418 }
419 }
420
421 return CMD_SUCCESS;
422}
423
Harald Welte1bc77352009-03-10 19:47:51 +0000424static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
425{
426 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
427}
428
429DEFUN(show_e1drv,
430 show_e1drv_cmd,
431 "show e1_driver",
432 SHOW_STR "Display information about available E1 drivers\n")
433{
434 struct e1inp_driver *drv;
435
436 llist_for_each_entry(drv, &e1inp_driver_list, list)
437 e1drv_dump_vty(vty, drv);
438
439 return CMD_SUCCESS;
440}
441
Harald Welte68628e82009-03-10 12:17:57 +0000442static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
443{
444 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
445 line->num, line->name ? line->name : "",
446 line->driver->name, VTY_NEWLINE);
447}
448
449DEFUN(show_e1line,
450 show_e1line_cmd,
451 "show e1_line [line_nr]",
452 SHOW_STR "Display information about a E1 line\n")
453{
Harald Welte1bc77352009-03-10 19:47:51 +0000454 struct e1inp_line *line;
455
456 if (argc >= 1) {
457 int num = atoi(argv[0]);
458 llist_for_each_entry(line, &e1inp_line_list, list) {
459 if (line->num == num) {
460 e1line_dump_vty(vty, line);
461 return CMD_SUCCESS;
462 }
463 }
464 return CMD_WARNING;
465 }
466
467 llist_for_each_entry(line, &e1inp_line_list, list)
468 e1line_dump_vty(vty, line);
469
470 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000471}
472
473static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
474{
Harald Welte1bc77352009-03-10 19:47:51 +0000475 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
476 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
477 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000478}
479
480DEFUN(show_e1ts,
481 show_e1ts_cmd,
482 "show e1_timeslot [line_nr] [ts_nr]",
483 SHOW_STR "Display information about a E1 timeslot\n")
484{
Harald Welte1bc77352009-03-10 19:47:51 +0000485 struct e1inp_line *line;
486 struct e1inp_ts *ts;
487 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000488
Harald Welte1bc77352009-03-10 19:47:51 +0000489 if (argc == 0) {
490 llist_for_each_entry(line, &e1inp_line_list, list) {
491 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
492 ts = &line->ts[ts_nr];
493 e1ts_dump_vty(vty, ts);
494 }
495 }
496 return CMD_SUCCESS;
497 }
498 if (argc >= 1) {
499 int num = atoi(argv[0]);
500 llist_for_each_entry(line, &e1inp_line_list, list) {
501 if (line->num == num)
502 break;
503 }
504 if (!line || line->num != num) {
505 vty_out(vty, "E1 line %s is invalid%s",
506 argv[0], VTY_NEWLINE);
507 return CMD_WARNING;
508 }
509 }
510 if (argc >= 2) {
511 ts_nr = atoi(argv[1]);
512 if (ts_nr > NUM_E1_TS) {
513 vty_out(vty, "E1 timeslot %s is invalid%s",
514 argv[1], VTY_NEWLINE);
515 return CMD_WARNING;
516 }
517 ts = &line->ts[ts_nr];
518 e1ts_dump_vty(vty, ts);
519 return CMD_SUCCESS;
520 } else {
521 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
522 ts = &line->ts[ts_nr];
523 e1ts_dump_vty(vty, ts);
524 }
525 return CMD_SUCCESS;
526 }
527 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000528}
529
Harald Weltebe4b7302009-05-23 16:59:33 +0000530static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000531{
532 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
533 subscr_dump_vty(vty, pag->subscr);
534}
535
Harald Weltebe4b7302009-05-23 16:59:33 +0000536static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000537{
538 struct gsm_paging_request *pag;
539
540 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
541 paging_dump_vty(vty, pag);
542}
543
544DEFUN(show_paging,
545 show_paging_cmd,
546 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000547 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000548{
549 struct gsm_network *net = gsmnet;
550 struct gsm_bts *bts;
551 int bts_nr;
552
553 if (argc >= 1) {
554 /* use the BTS number that the user has specified */
555 bts_nr = atoi(argv[0]);
556 if (bts_nr >= net->num_bts) {
557 vty_out(vty, "%% can't find BTS %s%s", argv[0],
558 VTY_NEWLINE);
559 return CMD_WARNING;
560 }
561 bts = &net->bts[bts_nr];
562 bts_paging_dump_vty(vty, bts);
563
564 return CMD_SUCCESS;
565 }
566 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
567 bts = &net->bts[bts_nr];
568 bts_paging_dump_vty(vty, bts);
569 }
570
571 return CMD_SUCCESS;
572}
573
Harald Welte40f82892009-05-23 17:31:39 +0000574/* per-subscriber configuration */
575DEFUN(cfg_subscr,
576 cfg_subscr_cmd,
577 "subscriber IMSI",
578 "Select a Subscriber to configure\n")
579{
580 const char *imsi = argv[0];
581 struct gsm_subscriber *subscr;
582
583 subscr = subscr_get_by_imsi(imsi);
584 if (!subscr) {
585 vty_out(vty, "%% No subscriber for IMSI %s%s",
586 imsi, VTY_NEWLINE);
587 return CMD_WARNING;
588 }
589
590 vty->index = subscr;
591 vty->node = SUBSCR_NODE;
592
593 return CMD_SUCCESS;
594}
595
596
Harald Welte5258fc42009-03-28 19:07:53 +0000597/* per-BTS configuration */
598DEFUN(cfg_bts,
599 cfg_bts_cmd,
600 "bts BTS_NR",
601 "Select a BTS to configure\n")
602{
603 int bts_nr = atoi(argv[0]);
604 struct gsm_bts *bts;
605
606 if (bts_nr >= GSM_MAX_BTS) {
607 vty_out(vty, "%% This Version of OpenBSC only supports %u BTS%s",
608 GSM_MAX_BTS, VTY_NEWLINE);
609 return CMD_WARNING;
610 }
611 bts = &gsmnet->bts[bts_nr];
612 if (bts_nr >= gsmnet->num_bts)
613 gsmnet->num_bts = bts_nr + 1;
614
615 vty->index = bts;
616 vty->node = BTS_NODE;
617
618 return CMD_SUCCESS;
619}
620
621DEFUN(cfg_bts_type,
622 cfg_bts_type_cmd,
623 "type TYPE",
624 "Set the BTS type\n")
625{
626 struct gsm_bts *bts = vty->index;
627
628 //bts->type =
629 return CMD_SUCCESS;
630}
631
632DEFUN(cfg_bts_lac,
633 cfg_bts_lac_cmd,
634 "location_area_code <0-255>",
635 "Set the Location Area Code (LAC) of this BTS\n")
636{
637 struct gsm_bts *bts = vty->index;
638 int lac = atoi(argv[0]);
639
640 if (lac < 0 || lac > 0xff) {
641 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
642 lac, VTY_NEWLINE);
643 return CMD_WARNING;
644 }
645 bts->location_area_code = lac;
646
647 return CMD_SUCCESS;
648}
649
650DEFUN(cfg_bts_tsc,
651 cfg_bts_tsc_cmd,
652 "training_sequence_code <0-255>",
653 "Set the Training Sequence Code (TSC) of this BTS\n")
654{
655 struct gsm_bts *bts = vty->index;
656 int tsc = atoi(argv[0]);
657
658 if (tsc < 0 || tsc > 0xff) {
659 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
660 tsc, VTY_NEWLINE);
661 return CMD_WARNING;
662 }
663 bts->tsc = tsc;
664
665 return CMD_SUCCESS;
666}
667
Harald Welte78f2f502009-05-23 16:56:52 +0000668DEFUN(cfg_bts_bsic,
669 cfg_bts_bsic_cmd,
670 "base_station_id_code <0-63>",
671 "Set the Base Station Identity Code (BSIC) of this BTS\n")
672{
673 struct gsm_bts *bts = vty->index;
674 int bsic = atoi(argv[0]);
675
676 if (bsic < 0 || bsic > 0x3f) {
677 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
678 bsic, VTY_NEWLINE);
679 return CMD_WARNING;
680 }
681 bts->bsic = bsic;
682
683 return CMD_SUCCESS;
684}
685
686
Harald Welte4cc34222009-05-01 15:12:31 +0000687DEFUN(cfg_bts_unit_id,
688 cfg_bts_unit_id_cmd,
689 "unit_id <0-65534> <0-255>",
690 "Set the BTS Unit ID of this BTS\n")
691{
692 struct gsm_bts *bts = vty->index;
693 int site_id = atoi(argv[0]);
694 int bts_id = atoi(argv[1]);
695
696 if (site_id < 0 || site_id > 65534) {
697 vty_out(vty, "%% Site ID %d is not in the valid range%s",
698 site_id, VTY_NEWLINE);
699 return CMD_WARNING;
700 }
701 if (site_id < 0 || site_id > 255) {
702 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
703 bts_id, VTY_NEWLINE);
704 return CMD_WARNING;
705 }
706 bts->ip_access.site_id = site_id;
707 bts->ip_access.bts_id = bts_id;
708
709 return CMD_SUCCESS;
710}
711
Harald Welte5258fc42009-03-28 19:07:53 +0000712/* per TRX configuration */
713DEFUN(cfg_trx,
714 cfg_trx_cmd,
715 "trx TRX_NR",
716 "Select a TRX to configure")
717{
718 int trx_nr = atoi(argv[0]);
719 struct gsm_bts *bts = vty->index;
720 struct gsm_bts_trx *trx;
721
722 if (trx_nr > BTS_MAX_TRX) {
723 vty_out(vty, "%% This version of OpenBSC only supports %u TRX%s",
724 BTS_MAX_TRX+1, VTY_NEWLINE);
725 return CMD_WARNING;
726 }
727
728 if (trx_nr >= bts->num_trx)
729 bts->num_trx = trx_nr+1;
730
731 trx = &bts->trx[trx_nr];
732
733 vty->index = trx;
734 vty->node = TRX_NODE;
735
736 return CMD_SUCCESS;
737}
738
739DEFUN(cfg_trx_arfcn,
740 cfg_trx_arfcn_cmd,
741 "arfcn <1-1024>",
742 "Set the ARFCN for this TRX\n")
743{
744 int arfcn = atoi(argv[0]);
745 struct gsm_bts_trx *trx = vty->index;
746
747 /* FIXME: check if this ARFCN is supported by this TRX */
748
749 trx->arfcn = arfcn;
750
751 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
752 /* FIXME: use OML layer to update the ARFCN */
753 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
754
755 return CMD_SUCCESS;
756}
757
758/* per TS configuration */
759DEFUN(cfg_ts,
760 cfg_ts_cmd,
761 "timeslot TS_NR",
762 "Select a Timeslot to configure")
763{
764 int ts_nr = atoi(argv[0]);
765 struct gsm_bts_trx *trx = vty->index;
766 struct gsm_bts_trx_ts *ts;
767
768 if (ts_nr >= TRX_NR_TS) {
769 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
770 TRX_NR_TS, VTY_NEWLINE);
771 return CMD_WARNING;
772 }
773
774 ts = &trx->ts[ts_nr];
775
776 vty->index = ts;
777 vty->node = TS_NODE;
778
779 return CMD_SUCCESS;
780}
781
782
Harald Welte40f82892009-05-23 17:31:39 +0000783/* Subscriber */
784DEFUN(show_subscr,
785 show_subscr_cmd,
786 "show subscriber [IMSI]",
787 SHOW_STR "Display information about a subscriber\n")
788{
789 const char *imsi;
790 struct gsm_subscriber *subscr;
791
792 if (argc >= 1) {
793 imsi = argv[0];
794 subscr = subscr_get_by_imsi(imsi);
795 if (!subscr) {
796 vty_out(vty, "%% unknown subscriber%s",
797 VTY_NEWLINE);
798 return CMD_WARNING;
799 }
800 subscr_dump_vty(vty, subscr);
801
802 return CMD_SUCCESS;
803 }
804
805 /* FIXME: iterate over all subscribers ? */
806 return CMD_WARNING;
807
808 return CMD_SUCCESS;
809}
810
811DEFUN(cfg_subscr_name,
812 cfg_subscr_name_cmd,
813 "name NAME",
814 "Set the name of the subscriber")
815{
816 const char *name = argv[0];
817 struct gsm_subscriber *subscr = vty->index;
818
819 strncpy(subscr->name, name, sizeof(subscr->name));
820
821 db_sync_subscriber(subscr);
822
823 return CMD_SUCCESS;
824}
825
826DEFUN(cfg_subscr_extension,
827 cfg_subscr_extension_cmd,
828 "extension EXTENSION",
829 "Set the extension of the subscriber")
830{
831 const char *name = argv[0];
832 struct gsm_subscriber *subscr = vty->index;
833
834 strncpy(subscr->extension, name, sizeof(subscr->extension));
835
836 db_sync_subscriber(subscr);
837
838 return CMD_SUCCESS;
839}
840
841DEFUN(cfg_subscr_authorized,
842 cfg_subscr_authorized_cmd,
843 "auth <0-1>",
844 "Set the authorization status of the subscriber")
845{
846 int auth = atoi(argv[0]);
847 struct gsm_subscriber *subscr = vty->index;
848
849 if (auth)
850 subscr->authorized = 1;
851 else
852 subscr->authorized = 0;
853
854 db_sync_subscriber(subscr);
855
856 return CMD_SUCCESS;
857}
858
Harald Welte68628e82009-03-10 12:17:57 +0000859int bsc_vty_init(struct gsm_network *net)
860{
861 gsmnet = net;
862
863 cmd_init(1);
864 vty_init();
865
866 install_element(VIEW_NODE, &show_net_cmd);
867 install_element(VIEW_NODE, &show_bts_cmd);
868 install_element(VIEW_NODE, &show_trx_cmd);
869 install_element(VIEW_NODE, &show_ts_cmd);
870 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +0000871
872 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000873 install_element(VIEW_NODE, &show_e1line_cmd);
874 install_element(VIEW_NODE, &show_e1ts_cmd);
875
Harald Weltef5025b62009-03-28 16:55:11 +0000876 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +0000877
Harald Welte40f82892009-05-23 17:31:39 +0000878 install_element(VIEW_NODE, &show_subscr_cmd);
879
Harald Welte5258fc42009-03-28 19:07:53 +0000880 install_element(CONFIG_NODE, &cfg_bts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000881 install_node(&bts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000882 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000883 install_element(BTS_NODE, &cfg_bts_type_cmd);
884 install_element(BTS_NODE, &cfg_bts_lac_cmd);
885 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +0000886 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000887
Harald Welte5258fc42009-03-28 19:07:53 +0000888 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000889 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000890 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000891 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000892
Harald Welte5258fc42009-03-28 19:07:53 +0000893 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000894 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +0000895 install_default(TS_NODE);
Harald Welte68628e82009-03-10 12:17:57 +0000896
Harald Welte40f82892009-05-23 17:31:39 +0000897 install_element(CONFIG_NODE, &cfg_subscr_cmd);
898 install_node(&subscr_node, dummy_config_write);
899 install_default(SUBSCR_NODE);
900 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
901 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
902 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
903
Harald Welte68628e82009-03-10 12:17:57 +0000904 return 0;
905}