blob: b480c3d63a78c018e8dee9486f44a99f318398e2 [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 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200150 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000151 return CMD_SUCCESS;
152 }
153 /* print all BTS's */
154 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200155 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000156
157 return CMD_SUCCESS;
158}
159
Harald Welte67ce0732009-08-06 19:06:46 +0200160static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
161{
162 vty_out(vty, "\t\tts %u%s", ts->nr, VTY_NEWLINE);
163 vty_out(vty, "\t\t\tphys_chan_config %s%s", gsm_pchan_name(ts->pchan),
164 VTY_NEWLINE);
165 vty_out(vty, "\t\t\te1_subslot %u %u %u%s", ts->e1_link.e1_nr,
166 ts->e1_link.e1_ts, ts->e1_link.e1_ts_ss, VTY_NEWLINE);
167}
168
169static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
170{
171 int i;
172
173 vty_out(vty, "\ttrx %u%s", trx->nr, VTY_NEWLINE);
174 vty_out(vty, "\t\tarfcn %u%s", trx->arfcn, VTY_NEWLINE);
175 vty_out(vty, "\t\tmax_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
176
177 for (i = 0; i < TRX_NR_TS; i++)
178 config_write_ts_single(vty, &trx->ts[i]);
179}
180
181static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
182{
183 struct gsm_bts_trx *trx;
184
185 vty_out(vty, "bts %u%s", bts->nr, VTY_NEWLINE);
186 vty_out(vty, "\ttype %s%s", btstype2str(bts->type), VTY_NEWLINE);
187 vty_out(vty, "\tband %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
188 vty_out(vty, "\tlocation_area_code %u%s", bts->location_area_code,
189 VTY_NEWLINE);
190 vty_out(vty, "\ttraining_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
191 vty_out(vty, "\tbase_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
192 vty_out(vty, "\tunit_id %u %u%s",
193 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
194
195 llist_for_each_entry(trx, &bts->trx_list, list)
196 config_write_trx_single(vty, trx);
197}
198
199static int config_write_bts(struct vty *v)
200{
201 struct gsm_bts *bts;
202
203 llist_for_each_entry(bts, &gsmnet->bts_list, list)
204 config_write_bts_single(v, bts);
205
206 return CMD_SUCCESS;
207}
208
209
Harald Welte68628e82009-03-10 12:17:57 +0000210static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
211{
212 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
213 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200214 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
215 "resulting BS power: %d dBm\n",
216 trx->nominal_power, trx->max_power_red,
217 trx->nominal_power - trx->max_power_red);
Harald Welte68628e82009-03-10 12:17:57 +0000218 vty_out(vty, " NM State: ");
219 net_dump_nmstate(vty, &trx->nm_state);
220 vty_out(vty, " Baseband Transceiver NM State: ");
221 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
222 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
223 e1isl_dump_vty(vty, trx->rsl_link);
224}
225
226DEFUN(show_trx,
227 show_trx_cmd,
228 "show trx [bts_nr] [trx_nr]",
229 SHOW_STR "Display information about a TRX\n")
230{
231 struct gsm_network *net = gsmnet;
232 struct gsm_bts *bts = NULL;
233 struct gsm_bts_trx *trx;
234 int bts_nr, trx_nr;
235
236 if (argc >= 1) {
237 /* use the BTS number that the user has specified */
238 bts_nr = atoi(argv[0]);
239 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000240 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000241 VTY_NEWLINE);
242 return CMD_WARNING;
243 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200244 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000245 }
246 if (argc >= 2) {
247 trx_nr = atoi(argv[1]);
248 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000249 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000250 VTY_NEWLINE);
251 return CMD_WARNING;
252 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200253 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000254 trx_dump_vty(vty, trx);
255 return CMD_SUCCESS;
256 }
257 if (bts) {
258 /* print all TRX in this BTS */
259 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200260 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000261 trx_dump_vty(vty, trx);
262 }
263 return CMD_SUCCESS;
264 }
265
266 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200267 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000268 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200269 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000270 trx_dump_vty(vty, trx);
271 }
272 }
273
274 return CMD_SUCCESS;
275}
276
Harald Welte67ce0732009-08-06 19:06:46 +0200277
Harald Welte68628e82009-03-10 12:17:57 +0000278static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
279{
280 struct in_addr ia;
281
282 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
283 ts->nr, ts->trx->nr, ts->trx->bts->nr,
284 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
285 vty_out(vty, " NM State: ");
286 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000287 if (is_ipaccess_bts(ts->trx->bts)) {
288 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200289 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000290 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200291 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000292 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000293 } else {
294 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
295 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
296 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000297 }
298}
299
300DEFUN(show_ts,
301 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000302 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000303 SHOW_STR "Display information about a TS\n")
304{
305 struct gsm_network *net = gsmnet;
306 struct gsm_bts *bts;
307 struct gsm_bts_trx *trx;
308 struct gsm_bts_trx_ts *ts;
309 int bts_nr, trx_nr, ts_nr;
310
311 if (argc >= 1) {
312 /* use the BTS number that the user has specified */
313 bts_nr = atoi(argv[0]);
314 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000315 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000316 VTY_NEWLINE);
317 return CMD_WARNING;
318 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200319 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000320 }
321 if (argc >= 2) {
322 trx_nr = atoi(argv[1]);
323 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000324 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000325 VTY_NEWLINE);
326 return CMD_WARNING;
327 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200328 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000329 }
330 if (argc >= 3) {
331 ts_nr = atoi(argv[2]);
332 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000333 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000334 VTY_NEWLINE);
335 return CMD_WARNING;
336 }
337 ts = &trx->ts[ts_nr];
338 ts_dump_vty(vty, ts);
339 return CMD_SUCCESS;
340 }
341 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200342 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000343 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200344 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000345 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
346 ts = &trx->ts[ts_nr];
347 ts_dump_vty(vty, ts);
348 }
349 }
350 }
351
352 return CMD_SUCCESS;
353}
354
355static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
356{
Harald Weltefcd24452009-06-20 18:15:19 +0200357 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000358 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000359 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000360 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000361 if (subscr->extension)
362 vty_out(vty, " Extension: %s%s", subscr->extension,
363 VTY_NEWLINE);
364 if (subscr->imsi)
365 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
366 if (subscr->tmsi)
367 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
368}
369
370static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
371{
372 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
373 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
374 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
375 VTY_NEWLINE);
376 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
377 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
378 lchan->ms_power, VTY_NEWLINE);
379 if (lchan->subscr) {
380 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
381 subscr_dump_vty(vty, lchan->subscr);
382 } else
383 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
384}
385
Harald Welte4bfdfe72009-06-10 23:11:52 +0800386#if 0
387TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000388static void call_dump_vty(struct vty *vty, struct gsm_call *call)
389{
390 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
391 call->type, call->state, call->transaction_id, VTY_NEWLINE);
392
393 if (call->local_lchan) {
394 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
395 lchan_dump_vty(vty, call->local_lchan);
396 } else
397 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
398
399 if (call->remote_lchan) {
400 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
401 lchan_dump_vty(vty, call->remote_lchan);
402 } else
403 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
404
405 if (call->called_subscr) {
406 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
407 subscr_dump_vty(vty, call->called_subscr);
408 } else
409 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
410}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800411#endif
Harald Welte68628e82009-03-10 12:17:57 +0000412
413DEFUN(show_lchan,
414 show_lchan_cmd,
415 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
416 SHOW_STR "Display information about a logical channel\n")
417{
418 struct gsm_network *net = gsmnet;
419 struct gsm_bts *bts;
420 struct gsm_bts_trx *trx;
421 struct gsm_bts_trx_ts *ts;
422 struct gsm_lchan *lchan;
423 int bts_nr, trx_nr, ts_nr, lchan_nr;
424
425 if (argc >= 1) {
426 /* use the BTS number that the user has specified */
427 bts_nr = atoi(argv[0]);
428 if (bts_nr >= net->num_bts) {
429 vty_out(vty, "%% can't find BTS %s%s", argv[0],
430 VTY_NEWLINE);
431 return CMD_WARNING;
432 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200433 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000434 }
435 if (argc >= 2) {
436 trx_nr = atoi(argv[1]);
437 if (trx_nr >= bts->num_trx) {
438 vty_out(vty, "%% can't find TRX %s%s", argv[1],
439 VTY_NEWLINE);
440 return CMD_WARNING;
441 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200442 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000443 }
444 if (argc >= 3) {
445 ts_nr = atoi(argv[2]);
446 if (ts_nr >= TRX_NR_TS) {
447 vty_out(vty, "%% can't find TS %s%s", argv[2],
448 VTY_NEWLINE);
449 return CMD_WARNING;
450 }
451 ts = &trx->ts[ts_nr];
452 }
453 if (argc >= 4) {
454 lchan_nr = atoi(argv[3]);
455 if (lchan_nr >= TS_MAX_LCHAN) {
456 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
457 VTY_NEWLINE);
458 return CMD_WARNING;
459 }
460 lchan = &ts->lchan[lchan_nr];
461 lchan_dump_vty(vty, lchan);
462 return CMD_SUCCESS;
463 }
464 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200465 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000466 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200467 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000468 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
469 ts = &trx->ts[ts_nr];
470 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
471 lchan_nr++) {
472 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000473 if (lchan->type == GSM_LCHAN_NONE)
474 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000475 lchan_dump_vty(vty, lchan);
476 }
477 }
478 }
479 }
480
481 return CMD_SUCCESS;
482}
483
Harald Welte1bc77352009-03-10 19:47:51 +0000484static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
485{
486 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
487}
488
489DEFUN(show_e1drv,
490 show_e1drv_cmd,
491 "show e1_driver",
492 SHOW_STR "Display information about available E1 drivers\n")
493{
494 struct e1inp_driver *drv;
495
496 llist_for_each_entry(drv, &e1inp_driver_list, list)
497 e1drv_dump_vty(vty, drv);
498
499 return CMD_SUCCESS;
500}
501
Harald Welte68628e82009-03-10 12:17:57 +0000502static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
503{
504 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
505 line->num, line->name ? line->name : "",
506 line->driver->name, VTY_NEWLINE);
507}
508
509DEFUN(show_e1line,
510 show_e1line_cmd,
511 "show e1_line [line_nr]",
512 SHOW_STR "Display information about a E1 line\n")
513{
Harald Welte1bc77352009-03-10 19:47:51 +0000514 struct e1inp_line *line;
515
516 if (argc >= 1) {
517 int num = atoi(argv[0]);
518 llist_for_each_entry(line, &e1inp_line_list, list) {
519 if (line->num == num) {
520 e1line_dump_vty(vty, line);
521 return CMD_SUCCESS;
522 }
523 }
524 return CMD_WARNING;
525 }
526
527 llist_for_each_entry(line, &e1inp_line_list, list)
528 e1line_dump_vty(vty, line);
529
530 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000531}
532
533static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
534{
Harald Welte1bc77352009-03-10 19:47:51 +0000535 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
536 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
537 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000538}
539
540DEFUN(show_e1ts,
541 show_e1ts_cmd,
542 "show e1_timeslot [line_nr] [ts_nr]",
543 SHOW_STR "Display information about a E1 timeslot\n")
544{
Harald Welte1bc77352009-03-10 19:47:51 +0000545 struct e1inp_line *line;
546 struct e1inp_ts *ts;
547 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000548
Harald Welte1bc77352009-03-10 19:47:51 +0000549 if (argc == 0) {
550 llist_for_each_entry(line, &e1inp_line_list, list) {
551 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
552 ts = &line->ts[ts_nr];
553 e1ts_dump_vty(vty, ts);
554 }
555 }
556 return CMD_SUCCESS;
557 }
558 if (argc >= 1) {
559 int num = atoi(argv[0]);
560 llist_for_each_entry(line, &e1inp_line_list, list) {
561 if (line->num == num)
562 break;
563 }
564 if (!line || line->num != num) {
565 vty_out(vty, "E1 line %s is invalid%s",
566 argv[0], VTY_NEWLINE);
567 return CMD_WARNING;
568 }
569 }
570 if (argc >= 2) {
571 ts_nr = atoi(argv[1]);
572 if (ts_nr > NUM_E1_TS) {
573 vty_out(vty, "E1 timeslot %s is invalid%s",
574 argv[1], VTY_NEWLINE);
575 return CMD_WARNING;
576 }
577 ts = &line->ts[ts_nr];
578 e1ts_dump_vty(vty, ts);
579 return CMD_SUCCESS;
580 } else {
581 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
582 ts = &line->ts[ts_nr];
583 e1ts_dump_vty(vty, ts);
584 }
585 return CMD_SUCCESS;
586 }
587 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000588}
589
Harald Weltebe4b7302009-05-23 16:59:33 +0000590static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000591{
592 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
593 subscr_dump_vty(vty, pag->subscr);
594}
595
Harald Weltebe4b7302009-05-23 16:59:33 +0000596static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000597{
598 struct gsm_paging_request *pag;
599
600 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
601 paging_dump_vty(vty, pag);
602}
603
604DEFUN(show_paging,
605 show_paging_cmd,
606 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000607 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000608{
609 struct gsm_network *net = gsmnet;
610 struct gsm_bts *bts;
611 int bts_nr;
612
613 if (argc >= 1) {
614 /* use the BTS number that the user has specified */
615 bts_nr = atoi(argv[0]);
616 if (bts_nr >= net->num_bts) {
617 vty_out(vty, "%% can't find BTS %s%s", argv[0],
618 VTY_NEWLINE);
619 return CMD_WARNING;
620 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200621 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000622 bts_paging_dump_vty(vty, bts);
623
624 return CMD_SUCCESS;
625 }
626 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200627 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000628 bts_paging_dump_vty(vty, bts);
629 }
630
631 return CMD_SUCCESS;
632}
633
Harald Welte40f82892009-05-23 17:31:39 +0000634/* per-subscriber configuration */
635DEFUN(cfg_subscr,
636 cfg_subscr_cmd,
637 "subscriber IMSI",
638 "Select a Subscriber to configure\n")
639{
640 const char *imsi = argv[0];
641 struct gsm_subscriber *subscr;
642
Harald Welte761e9442009-07-23 19:21:02 +0200643 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000644 if (!subscr) {
645 vty_out(vty, "%% No subscriber for IMSI %s%s",
646 imsi, VTY_NEWLINE);
647 return CMD_WARNING;
648 }
649
650 vty->index = subscr;
651 vty->node = SUBSCR_NODE;
652
653 return CMD_SUCCESS;
654}
655
656
Harald Welte5258fc42009-03-28 19:07:53 +0000657/* per-BTS configuration */
658DEFUN(cfg_bts,
659 cfg_bts_cmd,
660 "bts BTS_NR",
661 "Select a BTS to configure\n")
662{
663 int bts_nr = atoi(argv[0]);
664 struct gsm_bts *bts;
665
Harald Weltee441d9c2009-06-21 16:17:15 +0200666 if (bts_nr > gsmnet->num_bts) {
667 vty_out(vty, "%% The next unused BTS number is %u%s",
668 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000669 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200670 } else if (bts_nr == gsmnet->num_bts) {
671 /* allocate a new one */
672 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
673 HARDCODED_TSC, HARDCODED_BSIC);
674 } else
675 bts = gsm_bts_num(gsmnet, bts_nr);
676
677 if (!bts)
678 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000679
680 vty->index = bts;
681 vty->node = BTS_NODE;
682
683 return CMD_SUCCESS;
684}
685
686DEFUN(cfg_bts_type,
687 cfg_bts_type_cmd,
688 "type TYPE",
689 "Set the BTS type\n")
690{
691 struct gsm_bts *bts = vty->index;
692
Harald Weltefcd24452009-06-20 18:15:19 +0200693 /* FIXME: implementation */
Harald Welte5258fc42009-03-28 19:07:53 +0000694 //bts->type =
695 return CMD_SUCCESS;
696}
697
Harald Weltefcd24452009-06-20 18:15:19 +0200698DEFUN(cfg_bts_band,
699 cfg_bts_band_cmd,
700 "band BAND",
701 "Set the frequency band of this BTS\n")
702{
703 struct gsm_bts *bts = vty->index;
704 int band = gsm_band_parse(atoi(argv[0]));
705
706 if (band < 0) {
707 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
708 band, VTY_NEWLINE);
709 return CMD_WARNING;
710 }
711
712 bts->band = band;
713
714 return CMD_SUCCESS;
715}
716
Harald Welte5258fc42009-03-28 19:07:53 +0000717DEFUN(cfg_bts_lac,
718 cfg_bts_lac_cmd,
719 "location_area_code <0-255>",
720 "Set the Location Area Code (LAC) of this BTS\n")
721{
722 struct gsm_bts *bts = vty->index;
723 int lac = atoi(argv[0]);
724
725 if (lac < 0 || lac > 0xff) {
726 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
727 lac, VTY_NEWLINE);
728 return CMD_WARNING;
729 }
730 bts->location_area_code = lac;
731
732 return CMD_SUCCESS;
733}
734
735DEFUN(cfg_bts_tsc,
736 cfg_bts_tsc_cmd,
737 "training_sequence_code <0-255>",
738 "Set the Training Sequence Code (TSC) of this BTS\n")
739{
740 struct gsm_bts *bts = vty->index;
741 int tsc = atoi(argv[0]);
742
743 if (tsc < 0 || tsc > 0xff) {
744 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
745 tsc, VTY_NEWLINE);
746 return CMD_WARNING;
747 }
748 bts->tsc = tsc;
749
750 return CMD_SUCCESS;
751}
752
Harald Welte78f2f502009-05-23 16:56:52 +0000753DEFUN(cfg_bts_bsic,
754 cfg_bts_bsic_cmd,
755 "base_station_id_code <0-63>",
756 "Set the Base Station Identity Code (BSIC) of this BTS\n")
757{
758 struct gsm_bts *bts = vty->index;
759 int bsic = atoi(argv[0]);
760
761 if (bsic < 0 || bsic > 0x3f) {
762 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
763 bsic, VTY_NEWLINE);
764 return CMD_WARNING;
765 }
766 bts->bsic = bsic;
767
768 return CMD_SUCCESS;
769}
770
771
Harald Welte4cc34222009-05-01 15:12:31 +0000772DEFUN(cfg_bts_unit_id,
773 cfg_bts_unit_id_cmd,
774 "unit_id <0-65534> <0-255>",
775 "Set the BTS Unit ID of this BTS\n")
776{
777 struct gsm_bts *bts = vty->index;
778 int site_id = atoi(argv[0]);
779 int bts_id = atoi(argv[1]);
780
781 if (site_id < 0 || site_id > 65534) {
782 vty_out(vty, "%% Site ID %d is not in the valid range%s",
783 site_id, VTY_NEWLINE);
784 return CMD_WARNING;
785 }
786 if (site_id < 0 || site_id > 255) {
787 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
788 bts_id, VTY_NEWLINE);
789 return CMD_WARNING;
790 }
791 bts->ip_access.site_id = site_id;
792 bts->ip_access.bts_id = bts_id;
793
794 return CMD_SUCCESS;
795}
796
Harald Welte5258fc42009-03-28 19:07:53 +0000797/* per TRX configuration */
798DEFUN(cfg_trx,
799 cfg_trx_cmd,
800 "trx TRX_NR",
801 "Select a TRX to configure")
802{
803 int trx_nr = atoi(argv[0]);
804 struct gsm_bts *bts = vty->index;
805 struct gsm_bts_trx *trx;
806
Harald Weltee441d9c2009-06-21 16:17:15 +0200807 if (trx_nr > bts->num_trx) {
808 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
809 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000810 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200811 } else if (trx_nr == bts->num_trx) {
812 /* we need to allocate a new one */
813 trx = gsm_bts_trx_alloc(bts);
814 } else
815 trx = gsm_bts_trx_num(bts, trx_nr);
816
817 if (!trx)
818 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000819
820 vty->index = trx;
821 vty->node = TRX_NODE;
822
823 return CMD_SUCCESS;
824}
825
826DEFUN(cfg_trx_arfcn,
827 cfg_trx_arfcn_cmd,
828 "arfcn <1-1024>",
829 "Set the ARFCN for this TRX\n")
830{
831 int arfcn = atoi(argv[0]);
832 struct gsm_bts_trx *trx = vty->index;
833
834 /* FIXME: check if this ARFCN is supported by this TRX */
835
836 trx->arfcn = arfcn;
837
838 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
839 /* FIXME: use OML layer to update the ARFCN */
840 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
841
842 return CMD_SUCCESS;
843}
844
Harald Weltefcd24452009-06-20 18:15:19 +0200845DEFUN(cfg_trx_max_power_red,
846 cfg_trx_max_power_red_cmd,
847 "max_power_red <0-100>",
848 "Reduction of maximum BS RF Power in dB\n")
849{
850 int maxpwr_r = atoi(argv[0]);
851 struct gsm_bts_trx *trx = vty->index;
852 int upper_limit = 12; /* default 12.21 max power red. */
853
854 /* FIXME: check if our BTS type supports more than 12 */
855 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
856 vty_out(vty, "%% Power %d dB is not in the valid range%s",
857 maxpwr_r, VTY_NEWLINE);
858 return CMD_WARNING;
859 }
860 if (maxpwr_r & 1) {
861 vty_out(vty, "%% Power %d dB is not an even value%s",
862 maxpwr_r, VTY_NEWLINE);
863 return CMD_WARNING;
864 }
865
866 trx->max_power_red = maxpwr_r;
867
868 /* FIXME: make sure we update this using OML */
869
870 return CMD_SUCCESS;
871}
872
Harald Welte5258fc42009-03-28 19:07:53 +0000873/* per TS configuration */
874DEFUN(cfg_ts,
875 cfg_ts_cmd,
876 "timeslot TS_NR",
877 "Select a Timeslot to configure")
878{
879 int ts_nr = atoi(argv[0]);
880 struct gsm_bts_trx *trx = vty->index;
881 struct gsm_bts_trx_ts *ts;
882
883 if (ts_nr >= TRX_NR_TS) {
884 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
885 TRX_NR_TS, VTY_NEWLINE);
886 return CMD_WARNING;
887 }
888
889 ts = &trx->ts[ts_nr];
890
891 vty->index = ts;
892 vty->node = TS_NODE;
893
894 return CMD_SUCCESS;
895}
896
897
Harald Welte40f82892009-05-23 17:31:39 +0000898/* Subscriber */
899DEFUN(show_subscr,
900 show_subscr_cmd,
901 "show subscriber [IMSI]",
902 SHOW_STR "Display information about a subscriber\n")
903{
904 const char *imsi;
905 struct gsm_subscriber *subscr;
906
907 if (argc >= 1) {
908 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +0200909 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000910 if (!subscr) {
911 vty_out(vty, "%% unknown subscriber%s",
912 VTY_NEWLINE);
913 return CMD_WARNING;
914 }
915 subscr_dump_vty(vty, subscr);
916
917 return CMD_SUCCESS;
918 }
919
920 /* FIXME: iterate over all subscribers ? */
921 return CMD_WARNING;
922
923 return CMD_SUCCESS;
924}
925
926DEFUN(cfg_subscr_name,
927 cfg_subscr_name_cmd,
928 "name NAME",
929 "Set the name of the subscriber")
930{
931 const char *name = argv[0];
932 struct gsm_subscriber *subscr = vty->index;
933
934 strncpy(subscr->name, name, sizeof(subscr->name));
935
936 db_sync_subscriber(subscr);
937
938 return CMD_SUCCESS;
939}
940
941DEFUN(cfg_subscr_extension,
942 cfg_subscr_extension_cmd,
943 "extension EXTENSION",
944 "Set the extension of the subscriber")
945{
946 const char *name = argv[0];
947 struct gsm_subscriber *subscr = vty->index;
948
949 strncpy(subscr->extension, name, sizeof(subscr->extension));
950
951 db_sync_subscriber(subscr);
952
953 return CMD_SUCCESS;
954}
955
956DEFUN(cfg_subscr_authorized,
957 cfg_subscr_authorized_cmd,
958 "auth <0-1>",
959 "Set the authorization status of the subscriber")
960{
961 int auth = atoi(argv[0]);
962 struct gsm_subscriber *subscr = vty->index;
963
964 if (auth)
965 subscr->authorized = 1;
966 else
967 subscr->authorized = 0;
968
969 db_sync_subscriber(subscr);
970
971 return CMD_SUCCESS;
972}
973
Harald Welte68628e82009-03-10 12:17:57 +0000974int bsc_vty_init(struct gsm_network *net)
975{
976 gsmnet = net;
977
978 cmd_init(1);
979 vty_init();
980
981 install_element(VIEW_NODE, &show_net_cmd);
982 install_element(VIEW_NODE, &show_bts_cmd);
983 install_element(VIEW_NODE, &show_trx_cmd);
984 install_element(VIEW_NODE, &show_ts_cmd);
985 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +0000986
987 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +0000988 install_element(VIEW_NODE, &show_e1line_cmd);
989 install_element(VIEW_NODE, &show_e1ts_cmd);
990
Harald Weltef5025b62009-03-28 16:55:11 +0000991 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +0000992
Harald Welte40f82892009-05-23 17:31:39 +0000993 install_element(VIEW_NODE, &show_subscr_cmd);
994
Harald Welte5258fc42009-03-28 19:07:53 +0000995 install_element(CONFIG_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +0200996 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +0000997 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +0000998 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +0200999 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001000 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1001 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001002 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001003
Harald Welte5258fc42009-03-28 19:07:53 +00001004 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001005 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001006 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001007 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001008 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001009
Harald Welte5258fc42009-03-28 19:07:53 +00001010 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001011 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001012 install_default(TS_NODE);
Harald Welte68628e82009-03-10 12:17:57 +00001013
Harald Welte40f82892009-05-23 17:31:39 +00001014 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1015 install_node(&subscr_node, dummy_config_write);
1016 install_default(SUBSCR_NODE);
1017 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1018 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1019 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1020
Harald Welte68628e82009-03-10 12:17:57 +00001021 return 0;
1022}