blob: 51c8028422139130f537c4988830d03807c694a5 [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001/* 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>
Harald Welte684b9752009-08-09 15:13:54 +020026#include <vty/buffer.h>
Harald Welte59b04682009-06-10 05:40:52 +080027#include <vty/vty.h>
28
29#include <arpa/inet.h>
30
31#include <openbsc/linuxlist.h>
32#include <openbsc/gsm_data.h>
Harald Welte59b04682009-06-10 05:40:52 +080033#include <openbsc/e1_input.h>
34#include <openbsc/abis_nm.h>
Harald Welte684b9752009-08-09 15:13:54 +020035#include <openbsc/gsm_utils.h>
Harald Weltefe96f382009-12-22 13:09:29 +010036#include <openbsc/chan_alloc.h>
Harald Welte44007742009-12-22 21:43:14 +010037#include <openbsc/meas_rep.h>
Harald Welte59b04682009-06-10 05:40:52 +080038#include <openbsc/db.h>
Harald Weltee87eb462009-08-07 13:29:14 +020039#include <openbsc/talloc.h>
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +010040#include <openbsc/telnet_interface.h>
Harald Welte59b04682009-06-10 05:40:52 +080041
42static struct gsm_network *gsmnet;
43
Harald Weltee87eb462009-08-07 13:29:14 +020044struct cmd_node net_node = {
45 GSMNET_NODE,
46 "%s(network)#",
47 1,
48};
49
Harald Welte59b04682009-06-10 05:40:52 +080050struct cmd_node bts_node = {
51 BTS_NODE,
52 "%s(bts)#",
53 1,
54};
55
56struct cmd_node trx_node = {
57 TRX_NODE,
58 "%s(trx)#",
59 1,
60};
61
62struct cmd_node ts_node = {
63 TS_NODE,
64 "%s(ts)#",
65 1,
66};
67
Harald Welte59b04682009-06-10 05:40:52 +080068static int dummy_config_write(struct vty *v)
69{
70 return CMD_SUCCESS;
71}
72
73static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
74{
75 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
76 nm_opstate_name(nms->operational), nms->administrative,
77 nm_avail_name(nms->availability), VTY_NEWLINE);
78}
79
Harald Weltefe96f382009-12-22 13:09:29 +010080static void dump_pchan_load_vty(struct vty *vty, char *prefix,
81 const struct pchan_load *pl)
82{
83 int i;
84
85 for (i = 0; i < ARRAY_SIZE(pl->pchan); i++) {
86 const struct load_counter *lc = &pl->pchan[i];
87 unsigned int percent;
88
89 if (lc->total == 0)
90 continue;
91
92 percent = (lc->used * 100) / lc->total;
93
94 vty_out(vty, "%s%20s: %3u%% (%u/%u)%s", prefix,
95 gsm_pchan_name(i), percent, lc->used, lc->total,
96 VTY_NEWLINE);
97 }
98}
99
Harald Welte59b04682009-06-10 05:40:52 +0800100static void net_dump_vty(struct vty *vty, struct gsm_network *net)
101{
Harald Weltefe96f382009-12-22 13:09:29 +0100102 struct pchan_load pl;
103
Harald Welte59b04682009-06-10 05:40:52 +0800104 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
105 "and has %u BTS%s", net->country_code, net->network_code,
106 net->num_bts, VTY_NEWLINE);
107 vty_out(vty, " Long network name: '%s'%s",
108 net->name_long, VTY_NEWLINE);
109 vty_out(vty, " Short network name: '%s'%s",
110 net->name_short, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200111 vty_out(vty, " Authentication policy: %s%s",
112 gsm_auth_policy_name(net->auth_policy), VTY_NEWLINE);
Harald Welte59936d72009-11-18 20:33:19 +0100113 vty_out(vty, " Location updating reject cause: %u%s",
114 net->reject_cause, VTY_NEWLINE);
Harald Weltecca253a2009-08-30 15:47:06 +0900115 vty_out(vty, " Encryption: A5/%u%s", net->a5_encryption,
116 VTY_NEWLINE);
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +0100117 vty_out(vty, " NECI (TCH/H): %u%s", net->neci,
118 VTY_NEWLINE);
Harald Welte52af1952009-12-13 10:53:12 +0100119 vty_out(vty, " RRLP Mode: %s%s", rrlp_mode_name(net->rrlp.mode),
120 VTY_NEWLINE);
Harald Weltea310f3e2009-12-14 09:00:24 +0100121 vty_out(vty, " MM Info: %s%s", net->send_mm_info ? "On" : "Off",
122 VTY_NEWLINE);
Harald Welte0af9c9f2009-12-19 21:41:52 +0100123 vty_out(vty, " Handover: %s%s", net->handover.active ? "On" : "Off",
124 VTY_NEWLINE);
Harald Weltefe96f382009-12-22 13:09:29 +0100125 network_chan_load(&pl, net);
126 vty_out(vty, " Current Channel Load:%s", VTY_NEWLINE);
127 dump_pchan_load_vty(vty, " ", &pl);
Harald Welte59b04682009-06-10 05:40:52 +0800128}
129
130DEFUN(show_net, show_net_cmd, "show network",
131 SHOW_STR "Display information about a GSM NETWORK\n")
132{
133 struct gsm_network *net = gsmnet;
134 net_dump_vty(vty, net);
135
136 return CMD_SUCCESS;
137}
138
139static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
140{
141 struct e1inp_line *line;
142
143 if (!e1l) {
144 vty_out(vty, " None%s", VTY_NEWLINE);
145 return;
146 }
147
148 line = e1l->ts->line;
149
150 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
151 line->num, line->driver->name, e1l->ts->num,
152 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
153 vty_out(vty, " E1 TEI %u, SAPI %u%s",
154 e1l->tei, e1l->sapi, VTY_NEWLINE);
155}
156
157static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
158{
Harald Weltefe96f382009-12-22 13:09:29 +0100159 struct pchan_load pl;
160
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +0200161 vty_out(vty, "BTS %u is of %s type in band %s, has CI %u LAC %u, "
Harald Welte91afe4c2009-06-20 18:15:19 +0200162 "BSIC %u, TSC %u and %u TRX%s",
163 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +0200164 bts->cell_identity,
Harald Welte91afe4c2009-06-20 18:15:19 +0200165 bts->location_area_code, bts->bsic, bts->tsc,
166 bts->num_trx, VTY_NEWLINE);
Harald Welte8e9d1792009-12-12 15:38:16 +0100167 vty_out(vty, "MS Max power: %u dBm%s", bts->ms_max_power, VTY_NEWLINE);
Harald Welteb761bf82009-12-12 18:17:25 +0100168 vty_out(vty, "Minimum Rx Level for Access: %i dBm%s",
Harald Welte8e9d1792009-12-12 15:38:16 +0100169 rxlev2dbm(bts->si_common.cell_sel_par.rxlev_acc_min),
170 VTY_NEWLINE);
171 vty_out(vty, "Cell Reselection Hysteresis: %u dBm%s",
Harald Welteb761bf82009-12-12 18:17:25 +0100172 bts->si_common.cell_sel_par.cell_resel_hyst*2, VTY_NEWLINE);
Sylvain Munaut8e2d8de2009-12-22 13:43:26 +0100173 vty_out(vty, "RACH TX-Integer: %u%s", bts->si_common.rach_control.tx_integer,
174 VTY_NEWLINE);
175 vty_out(vty, "RACH Max transmissions: %u%s",
176 rach_max_trans_raw2val(bts->si_common.rach_control.max_trans),
177 VTY_NEWLINE);
Harald Welte8c973ba2009-12-21 23:08:18 +0100178 if (bts->si_common.rach_control.cell_bar)
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200179 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800180 if (is_ipaccess_bts(bts))
Harald Welte25572872009-10-20 00:22:00 +0200181 vty_out(vty, " Unit ID: %u/%u/0, OML Stream ID 0x%02x%s",
Harald Welte59b04682009-06-10 05:40:52 +0800182 bts->ip_access.site_id, bts->ip_access.bts_id,
Harald Welte25572872009-10-20 00:22:00 +0200183 bts->oml_tei, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800184 vty_out(vty, " NM State: ");
185 net_dump_nmstate(vty, &bts->nm_state);
186 vty_out(vty, " Site Mgr NM State: ");
187 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
188 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
189 bts->paging.available_slots, VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200190 if (!is_ipaccess_bts(bts)) {
191 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
192 e1isl_dump_vty(vty, bts->oml_link);
193 }
Harald Welte59b04682009-06-10 05:40:52 +0800194 /* FIXME: oml_link, chan_desc */
Harald Weltefe96f382009-12-22 13:09:29 +0100195 memset(&pl, 0, sizeof(pl));
196 bts_chan_load(&pl, bts);
197 vty_out(vty, " Current Channel Load:%s", VTY_NEWLINE);
198 dump_pchan_load_vty(vty, " ", &pl);
Harald Welte59b04682009-06-10 05:40:52 +0800199}
200
201DEFUN(show_bts, show_bts_cmd, "show bts [number]",
202 SHOW_STR "Display information about a BTS\n"
203 "BTS number")
204{
205 struct gsm_network *net = gsmnet;
206 int bts_nr;
207
208 if (argc != 0) {
209 /* use the BTS number that the user has specified */
210 bts_nr = atoi(argv[0]);
211 if (bts_nr > net->num_bts) {
212 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
213 VTY_NEWLINE);
214 return CMD_WARNING;
215 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200216 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte59b04682009-06-10 05:40:52 +0800217 return CMD_SUCCESS;
218 }
219 /* print all BTS's */
220 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee712a5f2009-06-21 16:17:15 +0200221 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte59b04682009-06-10 05:40:52 +0800222
223 return CMD_SUCCESS;
224}
225
Harald Welte62868882009-08-08 16:12:58 +0200226/* utility functions */
227static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
228 const char *ts, const char *ss)
229{
230 e1_link->e1_nr = atoi(line);
231 e1_link->e1_ts = atoi(ts);
232 if (!strcmp(ss, "full"))
233 e1_link->e1_ts_ss = 255;
234 else
235 e1_link->e1_ts_ss = atoi(ss);
236}
237
238static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
239 const char *prefix)
240{
241 if (!e1_link->e1_ts)
242 return;
243
244 if (e1_link->e1_ts_ss == 255)
245 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
246 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
247 else
248 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
249 prefix, e1_link->e1_nr, e1_link->e1_ts,
250 e1_link->e1_ts_ss, VTY_NEWLINE);
251}
252
253
Harald Welte97ceef92009-08-06 19:06:46 +0200254static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
255{
Harald Welte62868882009-08-08 16:12:58 +0200256 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
257 if (ts->pchan != GSM_PCHAN_NONE)
258 vty_out(vty, " phys_chan_config %s%s",
259 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
260 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte97ceef92009-08-06 19:06:46 +0200261}
262
263static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
264{
265 int i;
266
Harald Weltee87eb462009-08-07 13:29:14 +0200267 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
268 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
Harald Welte (local)b709bfe2009-12-27 20:56:38 +0100269 vty_out(vty, " nominal power %u%s", trx->nominal_power, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200270 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200271 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
272 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte97ceef92009-08-06 19:06:46 +0200273
274 for (i = 0; i < TRX_NR_TS; i++)
275 config_write_ts_single(vty, &trx->ts[i]);
276}
277
278static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
279{
280 struct gsm_bts_trx *trx;
281
Harald Weltee87eb462009-08-07 13:29:14 +0200282 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
283 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
284 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
Holger Hans Peter Freyther6d82b7c2009-11-19 16:38:49 +0100285 vty_out(vty, " cell_identity %u%s", bts->cell_identity, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200286 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte97ceef92009-08-06 19:06:46 +0200287 VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200288 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
289 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte (local)cbd46102009-08-13 10:14:26 +0200290 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Welteb761bf82009-12-12 18:17:25 +0100291 vty_out(vty, " cell reselection hysteresis %u%s",
292 bts->si_common.cell_sel_par.cell_resel_hyst*2, VTY_NEWLINE);
293 vty_out(vty, " rxlev access min %u%s",
294 bts->si_common.cell_sel_par.rxlev_acc_min, VTY_NEWLINE);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530295 if (bts->si_common.chan_desc.t3212)
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +0200296 vty_out(vty, " periodic location update %u%s",
Harald Weltea54a2bb2009-12-01 18:04:30 +0530297 bts->si_common.chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte3e774612009-08-10 13:48:16 +0200298 vty_out(vty, " channel allocator %s%s",
299 bts->chan_alloc_reverse ? "descending" : "ascending",
300 VTY_NEWLINE);
Sylvain Munaut8e2d8de2009-12-22 13:43:26 +0100301 vty_out(vty, " rach tx integer %u%s",
302 bts->si_common.rach_control.tx_integer, VTY_NEWLINE);
303 vty_out(vty, " rach max transmission %u%s",
304 rach_max_trans_raw2val(bts->si_common.rach_control.max_trans),
305 VTY_NEWLINE);
Harald Welte8c973ba2009-12-21 23:08:18 +0100306 if (bts->si_common.rach_control.cell_bar)
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200307 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200308 if (is_ipaccess_bts(bts)) {
Harald Weltee87eb462009-08-07 13:29:14 +0200309 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Welte3ffe1b32009-08-07 00:25:23 +0200310 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200311 vty_out(vty, " oml ip.access stream_id %u%s", bts->oml_tei, VTY_NEWLINE);
312 } else {
Harald Welte62868882009-08-08 16:12:58 +0200313 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
314 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
315 }
Harald Welte97ceef92009-08-06 19:06:46 +0200316
317 llist_for_each_entry(trx, &bts->trx_list, list)
318 config_write_trx_single(vty, trx);
319}
320
321static int config_write_bts(struct vty *v)
322{
323 struct gsm_bts *bts;
324
325 llist_for_each_entry(bts, &gsmnet->bts_list, list)
326 config_write_bts_single(v, bts);
327
328 return CMD_SUCCESS;
329}
330
Harald Weltee87eb462009-08-07 13:29:14 +0200331static int config_write_net(struct vty *vty)
332{
333 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200334 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200335 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200336 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
337 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200338 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte59936d72009-11-18 20:33:19 +0100339 vty_out(vty, " location updating reject cause %u%s",
340 gsmnet->reject_cause, VTY_NEWLINE);
Harald Weltecca253a2009-08-30 15:47:06 +0900341 vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
Holger Hans Peter Freyther6b4f5462009-11-19 16:37:48 +0100342 vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
Harald Welte52af1952009-12-13 10:53:12 +0100343 vty_out(vty, " rrlp mode %s%s", rrlp_mode_name(gsmnet->rrlp.mode),
344 VTY_NEWLINE);
Harald Weltea310f3e2009-12-14 09:00:24 +0100345 vty_out(vty, " mm info %u%s", gsmnet->send_mm_info, VTY_NEWLINE);
Harald Welte0af9c9f2009-12-19 21:41:52 +0100346 vty_out(vty, " handover %u%s", gsmnet->handover.active, VTY_NEWLINE);
Harald Weltea8062f12009-12-21 16:51:50 +0100347 vty_out(vty, " handover window rxlev averaging %u%s",
348 gsmnet->handover.win_rxlev_avg, VTY_NEWLINE);
349 vty_out(vty, " handover window rxqual averaging %u%s",
350 gsmnet->handover.win_rxqual_avg, VTY_NEWLINE);
351 vty_out(vty, " handover window rxlev neighbor averaging %u%s",
352 gsmnet->handover.win_rxlev_avg_neigh, VTY_NEWLINE);
353 vty_out(vty, " handover power budget interval %u%s",
354 gsmnet->handover.pwr_interval, VTY_NEWLINE);
355 vty_out(vty, " handover power budget hysteresis %u%s",
356 gsmnet->handover.pwr_hysteresis, VTY_NEWLINE);
357 vty_out(vty, " handover maximum distance %u%s",
358 gsmnet->handover.max_distance, VTY_NEWLINE);
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100359 vty_out(vty, " timer t3101 %u%s", gsmnet->T3101, VTY_NEWLINE);
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +0100360 vty_out(vty, " timer t3103 %u%s", gsmnet->T3103, VTY_NEWLINE);
361 vty_out(vty, " timer t3105 %u%s", gsmnet->T3105, VTY_NEWLINE);
362 vty_out(vty, " timer t3107 %u%s", gsmnet->T3107, VTY_NEWLINE);
363 vty_out(vty, " timer t3109 %u%s", gsmnet->T3109, VTY_NEWLINE);
364 vty_out(vty, " timer t3111 %u%s", gsmnet->T3111, VTY_NEWLINE);
365 vty_out(vty, " timer t3113 %u%s", gsmnet->T3113, VTY_NEWLINE);
366 vty_out(vty, " timer t3115 %u%s", gsmnet->T3115, VTY_NEWLINE);
367 vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
368 vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
369 vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200370
371 return CMD_SUCCESS;
372}
Harald Welte97ceef92009-08-06 19:06:46 +0200373
Harald Welte59b04682009-06-10 05:40:52 +0800374static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
375{
376 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
377 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Welte91afe4c2009-06-20 18:15:19 +0200378 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte62868882009-08-08 16:12:58 +0200379 "resulting BS power: %d dBm%s",
Harald Welte91afe4c2009-06-20 18:15:19 +0200380 trx->nominal_power, trx->max_power_red,
Harald Welte62868882009-08-08 16:12:58 +0200381 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800382 vty_out(vty, " NM State: ");
383 net_dump_nmstate(vty, &trx->nm_state);
384 vty_out(vty, " Baseband Transceiver NM State: ");
385 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
Harald Welte25572872009-10-20 00:22:00 +0200386 if (is_ipaccess_bts(trx->bts)) {
387 vty_out(vty, " ip.access stream ID: 0x%02x%s",
388 trx->rsl_tei, VTY_NEWLINE);
389 } else {
390 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
391 e1isl_dump_vty(vty, trx->rsl_link);
392 }
Harald Welte59b04682009-06-10 05:40:52 +0800393}
394
395DEFUN(show_trx,
396 show_trx_cmd,
397 "show trx [bts_nr] [trx_nr]",
398 SHOW_STR "Display information about a TRX\n")
399{
400 struct gsm_network *net = gsmnet;
401 struct gsm_bts *bts = NULL;
402 struct gsm_bts_trx *trx;
403 int bts_nr, trx_nr;
404
405 if (argc >= 1) {
406 /* use the BTS number that the user has specified */
407 bts_nr = atoi(argv[0]);
408 if (bts_nr >= net->num_bts) {
409 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
410 VTY_NEWLINE);
411 return CMD_WARNING;
412 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200413 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800414 }
415 if (argc >= 2) {
416 trx_nr = atoi(argv[1]);
417 if (trx_nr >= bts->num_trx) {
418 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
419 VTY_NEWLINE);
420 return CMD_WARNING;
421 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200422 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800423 trx_dump_vty(vty, trx);
424 return CMD_SUCCESS;
425 }
426 if (bts) {
427 /* print all TRX in this BTS */
428 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200429 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800430 trx_dump_vty(vty, trx);
431 }
432 return CMD_SUCCESS;
433 }
434
435 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200436 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800437 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200438 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800439 trx_dump_vty(vty, trx);
440 }
441 }
442
443 return CMD_SUCCESS;
444}
445
Harald Welte97ceef92009-08-06 19:06:46 +0200446
Harald Welte59b04682009-06-10 05:40:52 +0800447static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
448{
Harald Welte59b04682009-06-10 05:40:52 +0800449 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
450 ts->nr, ts->trx->nr, ts->trx->bts->nr,
451 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
452 vty_out(vty, " NM State: ");
453 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte87504212009-12-02 01:56:49 +0530454 if (!is_ipaccess_bts(ts->trx->bts))
Harald Welte59b04682009-06-10 05:40:52 +0800455 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
456 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
457 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800458}
459
460DEFUN(show_ts,
461 show_ts_cmd,
462 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
463 SHOW_STR "Display information about a TS\n")
464{
465 struct gsm_network *net = gsmnet;
466 struct gsm_bts *bts;
467 struct gsm_bts_trx *trx;
468 struct gsm_bts_trx_ts *ts;
469 int bts_nr, trx_nr, ts_nr;
470
471 if (argc >= 1) {
472 /* use the BTS number that the user has specified */
473 bts_nr = atoi(argv[0]);
474 if (bts_nr >= net->num_bts) {
475 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
476 VTY_NEWLINE);
477 return CMD_WARNING;
478 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200479 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800480 }
481 if (argc >= 2) {
482 trx_nr = atoi(argv[1]);
483 if (trx_nr >= bts->num_trx) {
484 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
485 VTY_NEWLINE);
486 return CMD_WARNING;
487 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200488 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800489 }
490 if (argc >= 3) {
491 ts_nr = atoi(argv[2]);
492 if (ts_nr >= TRX_NR_TS) {
493 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
494 VTY_NEWLINE);
495 return CMD_WARNING;
496 }
497 ts = &trx->ts[ts_nr];
498 ts_dump_vty(vty, ts);
499 return CMD_SUCCESS;
500 }
501 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200502 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800503 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200504 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800505 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
506 ts = &trx->ts[ts_nr];
507 ts_dump_vty(vty, ts);
508 }
509 }
510 }
511
512 return CMD_SUCCESS;
513}
514
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +0200515void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte59b04682009-06-10 05:40:52 +0800516{
Harald Welte91afe4c2009-06-20 18:15:19 +0200517 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte59b04682009-06-10 05:40:52 +0800518 subscr->authorized, VTY_NEWLINE);
519 if (subscr->name)
520 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
521 if (subscr->extension)
522 vty_out(vty, " Extension: %s%s", subscr->extension,
523 VTY_NEWLINE);
524 if (subscr->imsi)
525 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200526 if (subscr->tmsi != GSM_RESERVED_TMSI)
527 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte270c06c2009-08-15 03:24:51 +0200528 VTY_NEWLINE);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +0200529 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800530}
531
Harald Welte44007742009-12-22 21:43:14 +0100532static void meas_rep_dump_uni_vty(struct vty *vty,
533 struct gsm_meas_rep_unidir *mru,
534 const char *prefix,
535 const char *dir)
536{
537 vty_out(vty, "%s RXL-FULL-%s: %4d dBm, RXL-SUB-%s: %4d dBm ",
538 prefix, dir, rxlev2dbm(mru->full.rx_lev),
539 dir, rxlev2dbm(mru->sub.rx_lev));
540 vty_out(vty, "RXQ-FULL-%s: %d, RXQ-SUB-%s: %d%s",
541 dir, mru->full.rx_qual, dir, mru->sub.rx_qual,
542 VTY_NEWLINE);
543}
544
545static void meas_rep_dump_vty(struct vty *vty, struct gsm_meas_rep *mr,
546 const char *prefix)
547{
548 vty_out(vty, "%sMeasurement Report:%s", prefix, VTY_NEWLINE);
549 vty_out(vty, "%s Flags: %s%s%s%s%s", prefix,
550 mr->flags & MEAS_REP_F_UL_DTX ? "DTXu " : "",
551 mr->flags & MEAS_REP_F_DL_DTX ? "DTXd " : "",
552 mr->flags & MEAS_REP_F_FPC ? "FPC " : "",
553 mr->flags & MEAS_REP_F_DL_VALID ? " " : "DLinval ",
554 VTY_NEWLINE);
555 if (mr->flags & MEAS_REP_F_MS_TO)
556 vty_out(vty, "%s MS Timing Offset: %u%s", prefix,
557 mr->ms_timing_offset, VTY_NEWLINE);
558 if (mr->flags & MEAS_REP_F_MS_L1)
559 vty_out(vty, "%s L1 MS Power: %u dBm, Timing Advance: %u%s",
560 prefix, mr->ms_l1.pwr, mr->ms_l1.ta, VTY_NEWLINE);
561 if (mr->flags & MEAS_REP_F_DL_VALID)
562 meas_rep_dump_uni_vty(vty, &mr->dl, prefix, "dl");
563 meas_rep_dump_uni_vty(vty, &mr->ul, prefix, "ul");
564}
565
Harald Welte59b04682009-06-10 05:40:52 +0800566static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
567{
Harald Welte44007742009-12-22 21:43:14 +0100568 int idx;
569
Harald Welte59b04682009-06-10 05:40:52 +0800570 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
571 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
Harald Welte (local)02204d02009-12-27 18:05:25 +0100572 lchan->ts->trx->bts->nr, gsm_lchant_name(lchan->type),
Harald Welte59b04682009-06-10 05:40:52 +0800573 VTY_NEWLINE);
574 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
Harald Welteb761bf82009-12-12 18:17:25 +0100575 vty_out(vty, " BS Power: %u dBm, MS Power: %u dBm%s",
576 lchan->ts->trx->nominal_power - lchan->ts->trx->max_power_red
577 - lchan->bs_power*2,
578 ms_pwr_dbm(lchan->ts->trx->bts->band, lchan->ms_power),
579 VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800580 if (lchan->subscr) {
581 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
582 subscr_dump_vty(vty, lchan->subscr);
583 } else
584 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
Harald Welte87504212009-12-02 01:56:49 +0530585 if (is_ipaccess_bts(lchan->ts->trx->bts)) {
586 struct in_addr ia;
587 ia.s_addr = lchan->abis_ip.bound_ip;
588 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
589 inet_ntoa(ia), lchan->abis_ip.bound_port,
590 lchan->abis_ip.rtp_payload2, lchan->abis_ip.conn_id,
591 VTY_NEWLINE);
592 }
Harald Welte44007742009-12-22 21:43:14 +0100593
594 /* we want to report the last measurement report */
595 idx = calc_initial_idx(ARRAY_SIZE(lchan->meas_rep),
596 lchan->meas_rep_idx, 1);
597 meas_rep_dump_vty(vty, &lchan->meas_rep[idx], " ");
Harald Welte59b04682009-06-10 05:40:52 +0800598}
599
Harald Welte03740842009-06-10 23:11:52 +0800600#if 0
601TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte59b04682009-06-10 05:40:52 +0800602static void call_dump_vty(struct vty *vty, struct gsm_call *call)
603{
604 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
605 call->type, call->state, call->transaction_id, VTY_NEWLINE);
606
607 if (call->local_lchan) {
608 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
609 lchan_dump_vty(vty, call->local_lchan);
610 } else
611 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
612
613 if (call->remote_lchan) {
614 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
615 lchan_dump_vty(vty, call->remote_lchan);
616 } else
617 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
618
619 if (call->called_subscr) {
620 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
621 subscr_dump_vty(vty, call->called_subscr);
622 } else
623 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
624}
Harald Welte03740842009-06-10 23:11:52 +0800625#endif
Harald Welte59b04682009-06-10 05:40:52 +0800626
627DEFUN(show_lchan,
628 show_lchan_cmd,
629 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
630 SHOW_STR "Display information about a logical channel\n")
631{
632 struct gsm_network *net = gsmnet;
633 struct gsm_bts *bts;
634 struct gsm_bts_trx *trx;
635 struct gsm_bts_trx_ts *ts;
636 struct gsm_lchan *lchan;
637 int bts_nr, trx_nr, ts_nr, lchan_nr;
638
639 if (argc >= 1) {
640 /* use the BTS number that the user has specified */
641 bts_nr = atoi(argv[0]);
642 if (bts_nr >= net->num_bts) {
643 vty_out(vty, "%% can't find BTS %s%s", argv[0],
644 VTY_NEWLINE);
645 return CMD_WARNING;
646 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200647 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800648 }
649 if (argc >= 2) {
650 trx_nr = atoi(argv[1]);
651 if (trx_nr >= bts->num_trx) {
652 vty_out(vty, "%% can't find TRX %s%s", argv[1],
653 VTY_NEWLINE);
654 return CMD_WARNING;
655 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200656 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800657 }
658 if (argc >= 3) {
659 ts_nr = atoi(argv[2]);
660 if (ts_nr >= TRX_NR_TS) {
661 vty_out(vty, "%% can't find TS %s%s", argv[2],
662 VTY_NEWLINE);
663 return CMD_WARNING;
664 }
665 ts = &trx->ts[ts_nr];
666 }
667 if (argc >= 4) {
668 lchan_nr = atoi(argv[3]);
669 if (lchan_nr >= TS_MAX_LCHAN) {
670 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
671 VTY_NEWLINE);
672 return CMD_WARNING;
673 }
674 lchan = &ts->lchan[lchan_nr];
675 lchan_dump_vty(vty, lchan);
676 return CMD_SUCCESS;
677 }
678 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200679 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800680 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200681 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800682 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
683 ts = &trx->ts[ts_nr];
684 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
685 lchan_nr++) {
686 lchan = &ts->lchan[lchan_nr];
687 if (lchan->type == GSM_LCHAN_NONE)
688 continue;
689 lchan_dump_vty(vty, lchan);
690 }
691 }
692 }
693 }
694
695 return CMD_SUCCESS;
696}
697
698static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
699{
700 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
701}
702
703DEFUN(show_e1drv,
704 show_e1drv_cmd,
705 "show e1_driver",
706 SHOW_STR "Display information about available E1 drivers\n")
707{
708 struct e1inp_driver *drv;
709
710 llist_for_each_entry(drv, &e1inp_driver_list, list)
711 e1drv_dump_vty(vty, drv);
712
713 return CMD_SUCCESS;
714}
715
716static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
717{
718 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
719 line->num, line->name ? line->name : "",
720 line->driver->name, VTY_NEWLINE);
721}
722
723DEFUN(show_e1line,
724 show_e1line_cmd,
725 "show e1_line [line_nr]",
726 SHOW_STR "Display information about a E1 line\n")
727{
728 struct e1inp_line *line;
729
730 if (argc >= 1) {
731 int num = atoi(argv[0]);
732 llist_for_each_entry(line, &e1inp_line_list, list) {
733 if (line->num == num) {
734 e1line_dump_vty(vty, line);
735 return CMD_SUCCESS;
736 }
737 }
738 return CMD_WARNING;
739 }
740
741 llist_for_each_entry(line, &e1inp_line_list, list)
742 e1line_dump_vty(vty, line);
743
744 return CMD_SUCCESS;
745}
746
747static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
748{
Harald Welte62868882009-08-08 16:12:58 +0200749 if (ts->type == E1INP_TS_TYPE_NONE)
750 return;
Harald Welte59b04682009-06-10 05:40:52 +0800751 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
752 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
753 VTY_NEWLINE);
754}
755
756DEFUN(show_e1ts,
757 show_e1ts_cmd,
758 "show e1_timeslot [line_nr] [ts_nr]",
759 SHOW_STR "Display information about a E1 timeslot\n")
760{
Harald Welte49c79562009-11-17 06:12:16 +0100761 struct e1inp_line *line = NULL;
Harald Welte59b04682009-06-10 05:40:52 +0800762 struct e1inp_ts *ts;
763 int ts_nr;
764
765 if (argc == 0) {
766 llist_for_each_entry(line, &e1inp_line_list, list) {
767 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
768 ts = &line->ts[ts_nr];
769 e1ts_dump_vty(vty, ts);
770 }
771 }
772 return CMD_SUCCESS;
773 }
774 if (argc >= 1) {
775 int num = atoi(argv[0]);
776 llist_for_each_entry(line, &e1inp_line_list, list) {
777 if (line->num == num)
778 break;
779 }
780 if (!line || line->num != num) {
781 vty_out(vty, "E1 line %s is invalid%s",
782 argv[0], VTY_NEWLINE);
783 return CMD_WARNING;
784 }
785 }
786 if (argc >= 2) {
787 ts_nr = atoi(argv[1]);
788 if (ts_nr > NUM_E1_TS) {
789 vty_out(vty, "E1 timeslot %s is invalid%s",
790 argv[1], VTY_NEWLINE);
791 return CMD_WARNING;
792 }
793 ts = &line->ts[ts_nr];
794 e1ts_dump_vty(vty, ts);
795 return CMD_SUCCESS;
796 } else {
797 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
798 ts = &line->ts[ts_nr];
799 e1ts_dump_vty(vty, ts);
800 }
801 return CMD_SUCCESS;
802 }
803 return CMD_SUCCESS;
804}
805
806static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
807{
808 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
809 subscr_dump_vty(vty, pag->subscr);
810}
811
812static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
813{
814 struct gsm_paging_request *pag;
815
816 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
817 paging_dump_vty(vty, pag);
818}
819
820DEFUN(show_paging,
821 show_paging_cmd,
822 "show paging [bts_nr]",
823 SHOW_STR "Display information about paging reuqests of a BTS\n")
824{
825 struct gsm_network *net = gsmnet;
826 struct gsm_bts *bts;
827 int bts_nr;
828
829 if (argc >= 1) {
830 /* use the BTS number that the user has specified */
831 bts_nr = atoi(argv[0]);
832 if (bts_nr >= net->num_bts) {
833 vty_out(vty, "%% can't find BTS %s%s", argv[0],
834 VTY_NEWLINE);
835 return CMD_WARNING;
836 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200837 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800838 bts_paging_dump_vty(vty, bts);
839
840 return CMD_SUCCESS;
841 }
842 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200843 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800844 bts_paging_dump_vty(vty, bts);
845 }
846
847 return CMD_SUCCESS;
848}
849
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100850static void _vty_output(struct debug_target *tgt, const char *line)
851{
852 struct vty *vty = tgt->tgt_vty.vty;
853 vty_out(vty, "%s", line);
854 /* This is an ugly hack, but there is no easy way... */
855 if (strchr(line, '\n'))
856 vty_out(vty, "\r");
857}
858
859struct debug_target *debug_target_create_vty(struct vty *vty)
860{
861 struct debug_target *target;
862
863 target = debug_target_create();
864 if (!target)
865 return NULL;
866
867 target->tgt_vty.vty = vty;
868 target->output = _vty_output;
869 return target;
870}
871
872DEFUN(enable_logging,
873 enable_logging_cmd,
874 "logging enable",
875 "Enables logging to this vty\n")
876{
877 struct telnet_connection *conn;
878
879 conn = (struct telnet_connection *) vty->priv;
880 if (conn->dbg) {
881 vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE);
882 return CMD_WARNING;
883 }
884
885 conn->dbg = debug_target_create_vty(vty);
886 if (!conn->dbg)
887 return CMD_WARNING;
888
889 debug_add_target(conn->dbg);
890 return CMD_SUCCESS;
891}
892
893DEFUN(logging_fltr_imsi,
894 logging_fltr_imsi_cmd,
895 "logging filter imsi IMSI",
896 "Print all messages related to a IMSI\n")
897{
898 struct telnet_connection *conn;
899
900 conn = (struct telnet_connection *) vty->priv;
901 if (!conn->dbg) {
902 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
903 return CMD_WARNING;
904 }
905
906 debug_set_imsi_filter(conn->dbg, argv[0]);
907 return CMD_SUCCESS;
908}
909
910DEFUN(logging_fltr_all,
911 logging_fltr_all_cmd,
912 "logging filter all <0-1>",
913 "Print all messages to the console\n")
914{
915 struct telnet_connection *conn;
916
917 conn = (struct telnet_connection *) vty->priv;
918 if (!conn->dbg) {
919 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
920 return CMD_WARNING;
921 }
922
923 debug_set_all_filter(conn->dbg, atoi(argv[0]));
924 return CMD_SUCCESS;
925}
926
927DEFUN(logging_use_clr,
928 logging_use_clr_cmd,
Harald Welte (local)0bb88162009-12-26 19:45:22 +0100929 "logging color <0-1>",
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100930 "Use color for printing messages\n")
931{
932 struct telnet_connection *conn;
933
934 conn = (struct telnet_connection *) vty->priv;
935 if (!conn->dbg) {
936 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
937 return CMD_WARNING;
938 }
939
940 debug_set_use_color(conn->dbg, atoi(argv[0]));
941 return CMD_SUCCESS;
942}
943
944DEFUN(logging_prnt_timestamp,
945 logging_prnt_timestamp_cmd,
Harald Welte (local)0bb88162009-12-26 19:45:22 +0100946 "logging timestamp <0-1>",
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100947 "Print the timestamp of each message\n")
948{
949 struct telnet_connection *conn;
950
951 conn = (struct telnet_connection *) vty->priv;
952 if (!conn->dbg) {
953 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
954 return CMD_WARNING;
955 }
956
957 debug_set_print_timestamp(conn->dbg, atoi(argv[0]));
958 return CMD_SUCCESS;
959}
960
Harald Welte (local)0bb88162009-12-26 19:45:22 +0100961#define VTY_DEBUG_CATEGORIES "(rll|cc|mm|rr|rsl|nm|sms|pag|mncc|inp|mi|mib|mux|meas|sccp|msc|mgcp|ho|db|ref)"
962DEFUN(logging_level,
963 logging_level_cmd,
964 "logging level " VTY_DEBUG_CATEGORIES " <0-8>",
965 "Set the log level for a specified category\n")
966{
967 struct telnet_connection *conn;
968 int category = debug_parse_category(argv[0]);
969
970 conn = (struct telnet_connection *) vty->priv;
971 if (!conn->dbg) {
972 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
973 return CMD_WARNING;
974 }
975
976 if (category < 0) {
977 vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
978 return CMD_WARNING;
979 }
980
981 conn->dbg->categories[category].enabled = 1;
982 conn->dbg->categories[category].loglevel = atoi(argv[1]);
983
984 return CMD_SUCCESS;
985}
986
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100987DEFUN(logging_set_category_mask,
988 logging_set_category_mask_cmd,
989 "logging set debug mask MASK",
990 "Decide which categories to output.\n")
991{
992 struct telnet_connection *conn;
993
994 conn = (struct telnet_connection *) vty->priv;
995 if (!conn->dbg) {
996 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
997 return CMD_WARNING;
998 }
999
1000 debug_parse_category_mask(conn->dbg, argv[0]);
1001 return CMD_SUCCESS;
1002}
1003
1004DEFUN(logging_set_log_level,
1005 logging_set_log_level_cmd,
1006 "logging set log level <0-8>",
1007 "Set the global log level. The value 0 implies no filtering.\n")
1008{
1009 struct telnet_connection *conn;
1010
1011 conn = (struct telnet_connection *) vty->priv;
1012 if (!conn->dbg) {
1013 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
1014 return CMD_WARNING;
1015 }
1016
1017 debug_set_log_level(conn->dbg, atoi(argv[0]));
1018 return CMD_SUCCESS;
1019}
1020
1021DEFUN(diable_logging,
1022 disable_logging_cmd,
1023 "logging disable",
1024 "Disables logging to this vty\n")
1025{
1026 struct telnet_connection *conn;
1027
1028 conn = (struct telnet_connection *) vty->priv;
1029 if (!conn->dbg) {
1030 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
1031 return CMD_WARNING;
1032 }
1033
1034 debug_del_target(conn->dbg);
1035 talloc_free(conn->dbg);
1036 conn->dbg = NULL;
1037 return CMD_SUCCESS;
1038}
1039
Harald Welte3edc5a92009-12-22 00:41:05 +01001040DEFUN(show_stats,
1041 show_stats_cmd,
1042 "show statistics",
1043 SHOW_STR "Display network statistics\n")
1044{
1045 struct gsm_network *net = gsmnet;
1046
Harald Welte2f404622009-12-22 21:47:48 +01001047 vty_out(vty, "Channel Requests : %lu total, %lu no channel%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001048 counter_get(net->stats.chreq.total),
1049 counter_get(net->stats.chreq.no_channel), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001050 vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001051 counter_get(net->stats.loc_upd_type.attach),
1052 counter_get(net->stats.loc_upd_type.normal),
1053 counter_get(net->stats.loc_upd_type.periodic), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001054 vty_out(vty, "IMSI Detach Indications : %lu%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001055 counter_get(net->stats.loc_upd_type.detach), VTY_NEWLINE);
Harald Welte3edc5a92009-12-22 00:41:05 +01001056 vty_out(vty, "Location Update Response: %lu accept, %lu reject%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001057 counter_get(net->stats.loc_upd_resp.accept),
1058 counter_get(net->stats.loc_upd_resp.reject), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001059 vty_out(vty, "Paging : %lu attempted, %lu complete, %lu expired%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001060 counter_get(net->stats.paging.attempted),
1061 counter_get(net->stats.paging.completed),
1062 counter_get(net->stats.paging.expired), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001063 vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, "
Harald Weltebdbb7442009-12-22 19:07:32 +01001064 "%lu completed, %lu failed%s",
1065 counter_get(net->stats.handover.attempted),
1066 counter_get(net->stats.handover.no_channel),
1067 counter_get(net->stats.handover.timeout),
1068 counter_get(net->stats.handover.completed),
1069 counter_get(net->stats.handover.failed), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001070 vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001071 counter_get(net->stats.sms.submitted),
1072 counter_get(net->stats.sms.no_receiver), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001073 vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001074 counter_get(net->stats.sms.delivered),
1075 counter_get(net->stats.sms.rp_err_mem),
1076 counter_get(net->stats.sms.rp_err_other), VTY_NEWLINE);
Harald Welte3edc5a92009-12-22 00:41:05 +01001077 return CMD_SUCCESS;
1078}
1079
Harald Weltee87eb462009-08-07 13:29:14 +02001080DEFUN(cfg_net,
1081 cfg_net_cmd,
1082 "network",
1083 "Configure the GSM network")
1084{
1085 vty->index = gsmnet;
1086 vty->node = GSMNET_NODE;
1087
1088 return CMD_SUCCESS;
1089}
1090
1091
1092DEFUN(cfg_net_ncc,
1093 cfg_net_ncc_cmd,
1094 "network country code <1-999>",
1095 "Set the GSM network country code")
1096{
1097 gsmnet->country_code = atoi(argv[0]);
1098
1099 return CMD_SUCCESS;
1100}
1101
1102DEFUN(cfg_net_mnc,
1103 cfg_net_mnc_cmd,
1104 "mobile network code <1-999>",
1105 "Set the GSM mobile network code")
1106{
1107 gsmnet->network_code = atoi(argv[0]);
1108
1109 return CMD_SUCCESS;
1110}
1111
1112DEFUN(cfg_net_name_short,
1113 cfg_net_name_short_cmd,
1114 "short name NAME",
1115 "Set the short GSM network name")
1116{
1117 if (gsmnet->name_short)
1118 talloc_free(gsmnet->name_short);
1119
1120 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
1121
1122 return CMD_SUCCESS;
1123}
1124
1125DEFUN(cfg_net_name_long,
1126 cfg_net_name_long_cmd,
1127 "long name NAME",
1128 "Set the long GSM network name")
1129{
1130 if (gsmnet->name_long)
1131 talloc_free(gsmnet->name_long);
1132
1133 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
1134
1135 return CMD_SUCCESS;
1136}
Harald Welte59b04682009-06-10 05:40:52 +08001137
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001138DEFUN(cfg_net_auth_policy,
1139 cfg_net_auth_policy_cmd,
1140 "auth policy (closed|accept-all|token)",
1141 "Set the GSM network authentication policy\n")
1142{
1143 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
1144
1145 gsmnet->auth_policy = policy;
1146
1147 return CMD_SUCCESS;
1148}
1149
Harald Welte59936d72009-11-18 20:33:19 +01001150DEFUN(cfg_net_reject_cause,
1151 cfg_net_reject_cause_cmd,
1152 "location updating reject cause <2-111>",
1153 "Set the reject cause of location updating reject\n")
1154{
1155 gsmnet->reject_cause = atoi(argv[0]);
1156
1157 return CMD_SUCCESS;
1158}
1159
Harald Weltecca253a2009-08-30 15:47:06 +09001160DEFUN(cfg_net_encryption,
1161 cfg_net_encryption_cmd,
1162 "encryption a5 (0|1|2)",
1163 "Enable or disable encryption (A5) for this network\n")
1164{
Andreas.Eversberg53293292009-11-17 09:55:26 +01001165 gsmnet->a5_encryption= atoi(argv[0]);
Harald Weltecca253a2009-08-30 15:47:06 +09001166
1167 return CMD_SUCCESS;
1168}
1169
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001170DEFUN(cfg_net_neci,
1171 cfg_net_neci_cmd,
1172 "neci (0|1)",
1173 "Set if NECI of cell selection is to be set")
1174{
1175 gsmnet->neci = atoi(argv[0]);
1176 return CMD_SUCCESS;
1177}
1178
Harald Welte52af1952009-12-13 10:53:12 +01001179DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd,
1180 "rrlp mode (none|ms-based|ms-preferred|ass-preferred)",
1181 "Set the Radio Resource Location Protocol Mode")
1182{
1183 gsmnet->rrlp.mode = rrlp_mode_parse(argv[0]);
1184
1185 return CMD_SUCCESS;
1186}
1187
Harald Weltea310f3e2009-12-14 09:00:24 +01001188DEFUN(cfg_net_mm_info, cfg_net_mm_info_cmd,
1189 "mm info (0|1)",
1190 "Whether to send MM INFO after LOC UPD ACCEPT")
1191{
1192 gsmnet->send_mm_info = atoi(argv[0]);
1193
1194 return CMD_SUCCESS;
1195}
1196
Harald Welte0af9c9f2009-12-19 21:41:52 +01001197DEFUN(cfg_net_handover, cfg_net_handover_cmd,
1198 "handover (0|1)",
1199 "Whether or not to use in-call handover")
1200{
Harald Welteaa2c3032009-12-20 13:51:01 +01001201 if (ipacc_rtp_direct) {
1202 vty_out(vty, "%% Cannot enable handover unless RTP Proxy mode "
1203 "is enabled by using the -P command line option%s",
1204 VTY_NEWLINE);
1205 return CMD_WARNING;
1206 }
Harald Welte0af9c9f2009-12-19 21:41:52 +01001207 gsmnet->handover.active = atoi(argv[0]);
1208
1209 return CMD_SUCCESS;
1210}
1211
Harald Weltea8062f12009-12-21 16:51:50 +01001212DEFUN(cfg_net_ho_win_rxlev_avg, cfg_net_ho_win_rxlev_avg_cmd,
1213 "handover window rxlev averaging <1-10>",
1214 "How many RxLev measurements are used for averaging")
1215{
1216 gsmnet->handover.win_rxlev_avg = atoi(argv[0]);
1217 return CMD_SUCCESS;
1218}
1219
1220DEFUN(cfg_net_ho_win_rxqual_avg, cfg_net_ho_win_rxqual_avg_cmd,
1221 "handover window rxqual averaging <1-10>",
1222 "How many RxQual measurements are used for averaging")
1223{
1224 gsmnet->handover.win_rxqual_avg = atoi(argv[0]);
1225 return CMD_SUCCESS;
1226}
1227
1228DEFUN(cfg_net_ho_win_rxlev_neigh_avg, cfg_net_ho_win_rxlev_avg_neigh_cmd,
1229 "handover window rxlev neighbor averaging <1-10>",
1230 "How many RxQual measurements are used for averaging")
1231{
1232 gsmnet->handover.win_rxlev_avg_neigh = atoi(argv[0]);
1233 return CMD_SUCCESS;
1234}
1235
1236DEFUN(cfg_net_ho_pwr_interval, cfg_net_ho_pwr_interval_cmd,
1237 "handover power budget interval <1-99>",
1238 "How often to check if we have a better cell (SACCH frames)")
1239{
1240 gsmnet->handover.pwr_interval = atoi(argv[0]);
1241 return CMD_SUCCESS;
1242}
1243
1244DEFUN(cfg_net_ho_pwr_hysteresis, cfg_net_ho_pwr_hysteresis_cmd,
1245 "handover power budget hysteresis <0-999>",
1246 "How many dB does a neighbor to be stronger to become a HO candidate")
1247{
1248 gsmnet->handover.pwr_hysteresis = atoi(argv[0]);
1249 return CMD_SUCCESS;
1250}
1251
1252DEFUN(cfg_net_ho_max_distance, cfg_net_ho_max_distance_cmd,
1253 "handover maximum distance <0-9999>",
1254 "How big is the maximum timing advance before HO is forced")
1255{
1256 gsmnet->handover.max_distance = atoi(argv[0]);
1257 return CMD_SUCCESS;
1258}
Harald Welte0af9c9f2009-12-19 21:41:52 +01001259
Holger Hans Peter Freyther13ae9802009-12-22 08:27:21 +01001260#define DECLARE_TIMER(number, doc) \
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001261 DEFUN(cfg_net_T##number, \
1262 cfg_net_T##number##_cmd, \
1263 "timer t" #number " <0-65535>", \
Holger Hans Peter Freyther13ae9802009-12-22 08:27:21 +01001264 doc) \
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001265{ \
1266 int value = atoi(argv[0]); \
1267 \
1268 if (value < 0 || value > 65535) { \
1269 vty_out(vty, "Timer value %s out of range.%s", \
1270 argv[0], VTY_NEWLINE); \
1271 return CMD_WARNING; \
1272 } \
1273 \
1274 gsmnet->T##number = value; \
1275 return CMD_SUCCESS; \
1276}
1277
Holger Hans Peter Freyther13ae9802009-12-22 08:27:21 +01001278DECLARE_TIMER(3101, "Set the timeout value for IMMEDIATE ASSIGNMENT.")
1279DECLARE_TIMER(3103, "Set the timeout value for HANDOVER.")
1280DECLARE_TIMER(3105, "Currently not used.")
1281DECLARE_TIMER(3107, "Currently not used.")
1282DECLARE_TIMER(3109, "Currently not used.")
1283DECLARE_TIMER(3111, "Currently not used.")
1284DECLARE_TIMER(3113, "Set the time to try paging a subscriber.")
1285DECLARE_TIMER(3115, "Currently not used.")
1286DECLARE_TIMER(3117, "Currently not used.")
1287DECLARE_TIMER(3119, "Currently not used.")
1288DECLARE_TIMER(3141, "Currently not used.")
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001289
1290
Harald Welte59b04682009-06-10 05:40:52 +08001291/* per-BTS configuration */
1292DEFUN(cfg_bts,
1293 cfg_bts_cmd,
1294 "bts BTS_NR",
1295 "Select a BTS to configure\n")
1296{
1297 int bts_nr = atoi(argv[0]);
1298 struct gsm_bts *bts;
1299
Harald Weltee712a5f2009-06-21 16:17:15 +02001300 if (bts_nr > gsmnet->num_bts) {
1301 vty_out(vty, "%% The next unused BTS number is %u%s",
1302 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001303 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001304 } else if (bts_nr == gsmnet->num_bts) {
1305 /* allocate a new one */
1306 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
1307 HARDCODED_TSC, HARDCODED_BSIC);
1308 } else
1309 bts = gsm_bts_num(gsmnet, bts_nr);
1310
1311 if (!bts)
1312 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001313
1314 vty->index = bts;
1315 vty->node = BTS_NODE;
1316
1317 return CMD_SUCCESS;
1318}
1319
1320DEFUN(cfg_bts_type,
1321 cfg_bts_type_cmd,
1322 "type TYPE",
1323 "Set the BTS type\n")
1324{
1325 struct gsm_bts *bts = vty->index;
1326
Harald Welte (local)b709bfe2009-12-27 20:56:38 +01001327 gsm_set_bts_type(bts, parse_btstype(argv[0]));
Harald Welte25572872009-10-20 00:22:00 +02001328
Harald Welte59b04682009-06-10 05:40:52 +08001329 return CMD_SUCCESS;
1330}
1331
Harald Welte91afe4c2009-06-20 18:15:19 +02001332DEFUN(cfg_bts_band,
1333 cfg_bts_band_cmd,
1334 "band BAND",
1335 "Set the frequency band of this BTS\n")
1336{
1337 struct gsm_bts *bts = vty->index;
Harald Welte62868882009-08-08 16:12:58 +02001338 int band = gsm_band_parse(argv[0]);
Harald Welte91afe4c2009-06-20 18:15:19 +02001339
1340 if (band < 0) {
1341 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
1342 band, VTY_NEWLINE);
1343 return CMD_WARNING;
1344 }
1345
1346 bts->band = band;
1347
1348 return CMD_SUCCESS;
1349}
1350
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +02001351DEFUN(cfg_bts_ci,
1352 cfg_bts_ci_cmd,
1353 "cell_identity <0-65535>",
1354 "Set the Cell identity of this BTS\n")
1355{
1356 struct gsm_bts *bts = vty->index;
1357 int ci = atoi(argv[0]);
1358
1359 if (ci < 0 || ci > 0xffff) {
1360 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
1361 ci, VTY_NEWLINE);
1362 return CMD_WARNING;
1363 }
1364 bts->cell_identity = ci;
1365
1366 return CMD_SUCCESS;
1367}
1368
Harald Welte59b04682009-06-10 05:40:52 +08001369DEFUN(cfg_bts_lac,
1370 cfg_bts_lac_cmd,
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +02001371 "location_area_code <0-65535>",
Harald Welte59b04682009-06-10 05:40:52 +08001372 "Set the Location Area Code (LAC) of this BTS\n")
1373{
1374 struct gsm_bts *bts = vty->index;
1375 int lac = atoi(argv[0]);
1376
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +02001377 if (lac < 0 || lac > 0xffff) {
1378 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte59b04682009-06-10 05:40:52 +08001379 lac, VTY_NEWLINE);
1380 return CMD_WARNING;
1381 }
Holger Hans Peter Freyther6c6ab862009-10-01 04:07:15 +02001382
1383 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
1384 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
1385 lac, VTY_NEWLINE);
1386 return CMD_WARNING;
1387 }
1388
Harald Welte59b04682009-06-10 05:40:52 +08001389 bts->location_area_code = lac;
1390
1391 return CMD_SUCCESS;
1392}
1393
Harald Weltea54a2bb2009-12-01 18:04:30 +05301394
Harald Welte59b04682009-06-10 05:40:52 +08001395DEFUN(cfg_bts_tsc,
1396 cfg_bts_tsc_cmd,
1397 "training_sequence_code <0-255>",
1398 "Set the Training Sequence Code (TSC) of this BTS\n")
1399{
1400 struct gsm_bts *bts = vty->index;
1401 int tsc = atoi(argv[0]);
1402
1403 if (tsc < 0 || tsc > 0xff) {
1404 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
1405 tsc, VTY_NEWLINE);
1406 return CMD_WARNING;
1407 }
1408 bts->tsc = tsc;
1409
1410 return CMD_SUCCESS;
1411}
1412
1413DEFUN(cfg_bts_bsic,
1414 cfg_bts_bsic_cmd,
1415 "base_station_id_code <0-63>",
1416 "Set the Base Station Identity Code (BSIC) of this BTS\n")
1417{
1418 struct gsm_bts *bts = vty->index;
1419 int bsic = atoi(argv[0]);
1420
1421 if (bsic < 0 || bsic > 0x3f) {
Harald Welte62868882009-08-08 16:12:58 +02001422 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte59b04682009-06-10 05:40:52 +08001423 bsic, VTY_NEWLINE);
1424 return CMD_WARNING;
1425 }
1426 bts->bsic = bsic;
1427
1428 return CMD_SUCCESS;
1429}
1430
1431
1432DEFUN(cfg_bts_unit_id,
1433 cfg_bts_unit_id_cmd,
Harald Weltef515aa02009-08-07 13:27:09 +02001434 "ip.access unit_id <0-65534> <0-255>",
1435 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte59b04682009-06-10 05:40:52 +08001436{
1437 struct gsm_bts *bts = vty->index;
1438 int site_id = atoi(argv[0]);
1439 int bts_id = atoi(argv[1]);
1440
Harald Weltef515aa02009-08-07 13:27:09 +02001441 if (!is_ipaccess_bts(bts)) {
1442 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1443 return CMD_WARNING;
1444 }
1445
Harald Welte59b04682009-06-10 05:40:52 +08001446 bts->ip_access.site_id = site_id;
1447 bts->ip_access.bts_id = bts_id;
1448
1449 return CMD_SUCCESS;
1450}
1451
Harald Welte25572872009-10-20 00:22:00 +02001452DEFUN(cfg_bts_stream_id,
1453 cfg_bts_stream_id_cmd,
1454 "oml ip.access stream_id <0-255>",
1455 "Set the ip.access Stream ID of the OML link of this BTS\n")
1456{
1457 struct gsm_bts *bts = vty->index;
1458 int stream_id = atoi(argv[0]);
1459
1460 if (!is_ipaccess_bts(bts)) {
1461 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1462 return CMD_WARNING;
1463 }
1464
1465 bts->oml_tei = stream_id;
1466
1467 return CMD_SUCCESS;
1468}
1469
1470
Harald Welte62868882009-08-08 16:12:58 +02001471DEFUN(cfg_bts_oml_e1,
1472 cfg_bts_oml_e1_cmd,
1473 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1474 "E1 interface to be used for OML\n")
1475{
1476 struct gsm_bts *bts = vty->index;
1477
1478 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
1479
1480 return CMD_SUCCESS;
1481}
1482
1483
1484DEFUN(cfg_bts_oml_e1_tei,
1485 cfg_bts_oml_e1_tei_cmd,
1486 "oml e1 tei <0-63>",
1487 "Set the TEI to be used for OML")
1488{
1489 struct gsm_bts *bts = vty->index;
1490
1491 bts->oml_tei = atoi(argv[0]);
1492
1493 return CMD_SUCCESS;
1494}
1495
Harald Welte3e774612009-08-10 13:48:16 +02001496DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1497 "channel allocator (ascending|descending)",
1498 "Should the channel allocator allocate in reverse TRX order?")
1499{
1500 struct gsm_bts *bts = vty->index;
1501
1502 if (!strcmp(argv[0], "ascending"))
1503 bts->chan_alloc_reverse = 0;
1504 else
1505 bts->chan_alloc_reverse = 1;
1506
1507 return CMD_SUCCESS;
1508}
1509
Sylvain Munaut8e2d8de2009-12-22 13:43:26 +01001510DEFUN(cfg_bts_rach_tx_integer,
1511 cfg_bts_rach_tx_integer_cmd,
1512 "rach tx integer <0-15>",
1513 "Set the raw tx integer value in RACH Control parameters IE")
1514{
1515 struct gsm_bts *bts = vty->index;
1516 bts->si_common.rach_control.tx_integer = atoi(argv[0]) & 0xf;
1517 return CMD_SUCCESS;
1518}
1519
1520DEFUN(cfg_bts_rach_max_trans,
1521 cfg_bts_rach_max_trans_cmd,
1522 "rach max transmission (1|2|4|7)",
1523 "Set the maximum number of RACH burst transmissions")
1524{
1525 struct gsm_bts *bts = vty->index;
1526 bts->si_common.rach_control.max_trans = rach_max_trans_val2raw(atoi(argv[0]));
1527 return CMD_SUCCESS;
1528}
1529
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001530DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1531 "cell barred (0|1)",
1532 "Should this cell be barred from access?")
1533{
1534 struct gsm_bts *bts = vty->index;
1535
Harald Welte8c973ba2009-12-21 23:08:18 +01001536 bts->si_common.rach_control.cell_bar = atoi(argv[0]);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001537
1538 return CMD_SUCCESS;
1539}
1540
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001541DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1542 "ms max power <0-40>",
1543 "Maximum transmit power of the MS")
1544{
1545 struct gsm_bts *bts = vty->index;
1546
1547 bts->ms_max_power = atoi(argv[0]);
1548
1549 return CMD_SUCCESS;
1550}
1551
Harald Welteb761bf82009-12-12 18:17:25 +01001552DEFUN(cfg_bts_cell_resel_hyst, cfg_bts_cell_resel_hyst_cmd,
1553 "cell reselection hysteresis <0-14>",
1554 "Cell Re-Selection Hysteresis in dB")
1555{
1556 struct gsm_bts *bts = vty->index;
1557
1558 bts->si_common.cell_sel_par.cell_resel_hyst = atoi(argv[0])/2;
1559
1560 return CMD_SUCCESS;
1561}
1562
1563DEFUN(cfg_bts_rxlev_acc_min, cfg_bts_rxlev_acc_min_cmd,
1564 "rxlev access min <0-63>",
1565 "Minimum RxLev needed for cell access (better than -110dBm)")
1566{
1567 struct gsm_bts *bts = vty->index;
1568
1569 bts->si_common.cell_sel_par.rxlev_acc_min = atoi(argv[0]);
1570
1571 return CMD_SUCCESS;
1572}
1573
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001574DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1575 "periodic location update <0-1530>",
1576 "Periodic Location Updating Interval in Minutes")
1577{
1578 struct gsm_bts *bts = vty->index;
1579
Harald Weltea54a2bb2009-12-01 18:04:30 +05301580 bts->si_common.chan_desc.t3212 = atoi(argv[0]) / 10;
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001581
1582 return CMD_SUCCESS;
1583}
1584
Harald Welte3e774612009-08-10 13:48:16 +02001585
Harald Welte59b04682009-06-10 05:40:52 +08001586/* per TRX configuration */
1587DEFUN(cfg_trx,
1588 cfg_trx_cmd,
1589 "trx TRX_NR",
1590 "Select a TRX to configure")
1591{
1592 int trx_nr = atoi(argv[0]);
1593 struct gsm_bts *bts = vty->index;
1594 struct gsm_bts_trx *trx;
1595
Harald Weltee712a5f2009-06-21 16:17:15 +02001596 if (trx_nr > bts->num_trx) {
1597 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1598 bts->num_trx, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001599 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001600 } else if (trx_nr == bts->num_trx) {
1601 /* we need to allocate a new one */
1602 trx = gsm_bts_trx_alloc(bts);
1603 } else
1604 trx = gsm_bts_trx_num(bts, trx_nr);
1605
1606 if (!trx)
1607 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001608
1609 vty->index = trx;
1610 vty->node = TRX_NODE;
1611
1612 return CMD_SUCCESS;
1613}
1614
1615DEFUN(cfg_trx_arfcn,
1616 cfg_trx_arfcn_cmd,
1617 "arfcn <1-1024>",
1618 "Set the ARFCN for this TRX\n")
1619{
1620 int arfcn = atoi(argv[0]);
1621 struct gsm_bts_trx *trx = vty->index;
1622
1623 /* FIXME: check if this ARFCN is supported by this TRX */
1624
1625 trx->arfcn = arfcn;
1626
1627 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1628 /* FIXME: use OML layer to update the ARFCN */
1629 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1630
1631 return CMD_SUCCESS;
1632}
1633
Harald Welte (local)b709bfe2009-12-27 20:56:38 +01001634DEFUN(cfg_trx_nominal_power,
1635 cfg_trx_nominal_power_cmd,
1636 "nominal power <0-100>",
1637 "Nominal TRX RF Power in dB\n")
1638{
1639 struct gsm_bts_trx *trx = vty->index;
1640
1641 trx->nominal_power = atoi(argv[0]);
1642
1643 return CMD_SUCCESS;
1644}
1645
Harald Welte91afe4c2009-06-20 18:15:19 +02001646DEFUN(cfg_trx_max_power_red,
1647 cfg_trx_max_power_red_cmd,
1648 "max_power_red <0-100>",
1649 "Reduction of maximum BS RF Power in dB\n")
1650{
1651 int maxpwr_r = atoi(argv[0]);
1652 struct gsm_bts_trx *trx = vty->index;
Harald Welte01acd742009-11-18 09:20:22 +01001653 int upper_limit = 24; /* default 12.21 max power red. */
Harald Welte91afe4c2009-06-20 18:15:19 +02001654
1655 /* FIXME: check if our BTS type supports more than 12 */
1656 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1657 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1658 maxpwr_r, VTY_NEWLINE);
1659 return CMD_WARNING;
1660 }
1661 if (maxpwr_r & 1) {
1662 vty_out(vty, "%% Power %d dB is not an even value%s",
1663 maxpwr_r, VTY_NEWLINE);
1664 return CMD_WARNING;
1665 }
1666
1667 trx->max_power_red = maxpwr_r;
1668
1669 /* FIXME: make sure we update this using OML */
1670
1671 return CMD_SUCCESS;
1672}
1673
Harald Welte62868882009-08-08 16:12:58 +02001674DEFUN(cfg_trx_rsl_e1,
1675 cfg_trx_rsl_e1_cmd,
1676 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1677 "E1 interface to be used for RSL\n")
1678{
1679 struct gsm_bts_trx *trx = vty->index;
1680
1681 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1682
1683 return CMD_SUCCESS;
1684}
1685
1686DEFUN(cfg_trx_rsl_e1_tei,
1687 cfg_trx_rsl_e1_tei_cmd,
1688 "rsl e1 tei <0-63>",
1689 "Set the TEI to be used for RSL")
1690{
1691 struct gsm_bts_trx *trx = vty->index;
1692
1693 trx->rsl_tei = atoi(argv[0]);
1694
1695 return CMD_SUCCESS;
1696}
1697
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001698DEFUN(cfg_trx_rf_locked,
1699 cfg_trx_rf_locked_cmd,
1700 "rf_locked (0|1)",
1701 "Turn off RF of the TRX.\n")
1702{
1703 int locked = atoi(argv[0]);
1704 struct gsm_bts_trx *trx = vty->index;
1705
1706 gsm_trx_lock_rf(trx, locked);
1707 return CMD_SUCCESS;
1708}
Harald Welte62868882009-08-08 16:12:58 +02001709
Harald Welte59b04682009-06-10 05:40:52 +08001710/* per TS configuration */
1711DEFUN(cfg_ts,
1712 cfg_ts_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001713 "timeslot <0-7>",
Harald Welte59b04682009-06-10 05:40:52 +08001714 "Select a Timeslot to configure")
1715{
1716 int ts_nr = atoi(argv[0]);
1717 struct gsm_bts_trx *trx = vty->index;
1718 struct gsm_bts_trx_ts *ts;
1719
1720 if (ts_nr >= TRX_NR_TS) {
1721 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1722 TRX_NR_TS, VTY_NEWLINE);
1723 return CMD_WARNING;
1724 }
1725
1726 ts = &trx->ts[ts_nr];
1727
1728 vty->index = ts;
1729 vty->node = TS_NODE;
1730
1731 return CMD_SUCCESS;
1732}
1733
Harald Welte3ffe1b32009-08-07 00:25:23 +02001734DEFUN(cfg_ts_pchan,
1735 cfg_ts_pchan_cmd,
1736 "phys_chan_config PCHAN",
1737 "Physical Channel configuration (TCH/SDCCH/...)")
1738{
1739 struct gsm_bts_trx_ts *ts = vty->index;
1740 int pchanc;
1741
1742 pchanc = gsm_pchan_parse(argv[0]);
1743 if (pchanc < 0)
1744 return CMD_WARNING;
1745
1746 ts->pchan = pchanc;
1747
1748 return CMD_SUCCESS;
1749}
1750
1751DEFUN(cfg_ts_e1_subslot,
1752 cfg_ts_e1_subslot_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001753 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Welte3ffe1b32009-08-07 00:25:23 +02001754 "E1 sub-slot connected to this on-air timeslot")
1755{
1756 struct gsm_bts_trx_ts *ts = vty->index;
1757
Harald Welte62868882009-08-08 16:12:58 +02001758 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001759
1760 return CMD_SUCCESS;
1761}
Harald Welte59b04682009-06-10 05:40:52 +08001762
Harald Welte59b04682009-06-10 05:40:52 +08001763int bsc_vty_init(struct gsm_network *net)
1764{
1765 gsmnet = net;
1766
1767 cmd_init(1);
1768 vty_init();
1769
1770 install_element(VIEW_NODE, &show_net_cmd);
1771 install_element(VIEW_NODE, &show_bts_cmd);
1772 install_element(VIEW_NODE, &show_trx_cmd);
1773 install_element(VIEW_NODE, &show_ts_cmd);
1774 install_element(VIEW_NODE, &show_lchan_cmd);
1775
1776 install_element(VIEW_NODE, &show_e1drv_cmd);
1777 install_element(VIEW_NODE, &show_e1line_cmd);
1778 install_element(VIEW_NODE, &show_e1ts_cmd);
1779
1780 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte3edc5a92009-12-22 00:41:05 +01001781 install_element(VIEW_NODE, &show_stats_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001782
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +01001783 install_element(VIEW_NODE, &enable_logging_cmd);
1784 install_element(VIEW_NODE, &disable_logging_cmd);
1785 install_element(VIEW_NODE, &logging_fltr_imsi_cmd);
1786 install_element(VIEW_NODE, &logging_fltr_all_cmd);
1787 install_element(VIEW_NODE, &logging_use_clr_cmd);
1788 install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
1789 install_element(VIEW_NODE, &logging_set_category_mask_cmd);
Harald Welte (local)0bb88162009-12-26 19:45:22 +01001790 install_element(VIEW_NODE, &logging_level_cmd);
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +01001791
Harald Weltee87eb462009-08-07 13:29:14 +02001792 install_element(CONFIG_NODE, &cfg_net_cmd);
1793 install_node(&net_node, config_write_net);
1794 install_default(GSMNET_NODE);
Harald Welte62868882009-08-08 16:12:58 +02001795 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001796 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1797 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1798 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001799 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte59936d72009-11-18 20:33:19 +01001800 install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd);
Harald Weltecca253a2009-08-30 15:47:06 +09001801 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001802 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Harald Welte52af1952009-12-13 10:53:12 +01001803 install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd);
Harald Welte284ddba2009-12-14 17:49:15 +01001804 install_element(GSMNET_NODE, &cfg_net_mm_info_cmd);
Harald Welte0af9c9f2009-12-19 21:41:52 +01001805 install_element(GSMNET_NODE, &cfg_net_handover_cmd);
Harald Weltea8062f12009-12-21 16:51:50 +01001806 install_element(GSMNET_NODE, &cfg_net_ho_win_rxlev_avg_cmd);
1807 install_element(GSMNET_NODE, &cfg_net_ho_win_rxqual_avg_cmd);
1808 install_element(GSMNET_NODE, &cfg_net_ho_win_rxlev_avg_neigh_cmd);
1809 install_element(GSMNET_NODE, &cfg_net_ho_pwr_interval_cmd);
1810 install_element(GSMNET_NODE, &cfg_net_ho_pwr_hysteresis_cmd);
1811 install_element(GSMNET_NODE, &cfg_net_ho_max_distance_cmd);
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001812 install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +01001813 install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
1814 install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
1815 install_element(GSMNET_NODE, &cfg_net_T3107_cmd);
1816 install_element(GSMNET_NODE, &cfg_net_T3109_cmd);
1817 install_element(GSMNET_NODE, &cfg_net_T3111_cmd);
1818 install_element(GSMNET_NODE, &cfg_net_T3113_cmd);
1819 install_element(GSMNET_NODE, &cfg_net_T3115_cmd);
1820 install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
1821 install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
1822 install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001823
1824 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte97ceef92009-08-06 19:06:46 +02001825 install_node(&bts_node, config_write_bts);
Harald Welte59b04682009-06-10 05:40:52 +08001826 install_default(BTS_NODE);
1827 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Welte91afe4c2009-06-20 18:15:19 +02001828 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +02001829 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001830 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1831 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001832 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001833 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte25572872009-10-20 00:22:00 +02001834 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001835 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1836 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001837 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Sylvain Munaut8e2d8de2009-12-22 13:43:26 +01001838 install_element(BTS_NODE, &cfg_bts_rach_tx_integer_cmd);
1839 install_element(BTS_NODE, &cfg_bts_rach_max_trans_cmd);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001840 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001841 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001842 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welteb761bf82009-12-12 18:17:25 +01001843 install_element(BTS_NODE, &cfg_bts_cell_resel_hyst_cmd);
1844 install_element(BTS_NODE, &cfg_bts_rxlev_acc_min_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001845
Harald Welte59b04682009-06-10 05:40:52 +08001846
1847 install_element(BTS_NODE, &cfg_trx_cmd);
1848 install_node(&trx_node, dummy_config_write);
1849 install_default(TRX_NODE);
1850 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte (local)b709bfe2009-12-27 20:56:38 +01001851 install_element(TRX_NODE, &cfg_trx_nominal_power_cmd);
Harald Welte7f597bc2009-06-20 22:36:12 +02001852 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001853 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1854 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001855 install_element(TRX_NODE, &cfg_trx_rf_locked_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001856
1857 install_element(TRX_NODE, &cfg_ts_cmd);
1858 install_node(&ts_node, dummy_config_write);
1859 install_default(TS_NODE);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001860 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1861 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001862
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +02001863 bsc_vty_init_extra(net);
Harald Welte59b04682009-06-10 05:40:52 +08001864
1865 return 0;
1866}