blob: 0d66cb3a68e62cded1b5a033cd838b47936a56d4 [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);
269 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200270 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
271 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte97ceef92009-08-06 19:06:46 +0200272
273 for (i = 0; i < TRX_NR_TS; i++)
274 config_write_ts_single(vty, &trx->ts[i]);
275}
276
277static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
278{
279 struct gsm_bts_trx *trx;
280
Harald Weltee87eb462009-08-07 13:29:14 +0200281 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
282 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
283 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
Holger Hans Peter Freyther6d82b7c2009-11-19 16:38:49 +0100284 vty_out(vty, " cell_identity %u%s", bts->cell_identity, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200285 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte97ceef92009-08-06 19:06:46 +0200286 VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200287 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
288 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte (local)cbd46102009-08-13 10:14:26 +0200289 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Welteb761bf82009-12-12 18:17:25 +0100290 vty_out(vty, " cell reselection hysteresis %u%s",
291 bts->si_common.cell_sel_par.cell_resel_hyst*2, VTY_NEWLINE);
292 vty_out(vty, " rxlev access min %u%s",
293 bts->si_common.cell_sel_par.rxlev_acc_min, VTY_NEWLINE);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530294 if (bts->si_common.chan_desc.t3212)
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +0200295 vty_out(vty, " periodic location update %u%s",
Harald Weltea54a2bb2009-12-01 18:04:30 +0530296 bts->si_common.chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte3e774612009-08-10 13:48:16 +0200297 vty_out(vty, " channel allocator %s%s",
298 bts->chan_alloc_reverse ? "descending" : "ascending",
299 VTY_NEWLINE);
Sylvain Munaut8e2d8de2009-12-22 13:43:26 +0100300 vty_out(vty, " rach tx integer %u%s",
301 bts->si_common.rach_control.tx_integer, VTY_NEWLINE);
302 vty_out(vty, " rach max transmission %u%s",
303 rach_max_trans_raw2val(bts->si_common.rach_control.max_trans),
304 VTY_NEWLINE);
Harald Welte8c973ba2009-12-21 23:08:18 +0100305 if (bts->si_common.rach_control.cell_bar)
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200306 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200307 if (is_ipaccess_bts(bts)) {
Harald Weltee87eb462009-08-07 13:29:14 +0200308 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Welte3ffe1b32009-08-07 00:25:23 +0200309 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200310 vty_out(vty, " oml ip.access stream_id %u%s", bts->oml_tei, VTY_NEWLINE);
311 } else {
Harald Welte62868882009-08-08 16:12:58 +0200312 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
313 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
314 }
Harald Welte97ceef92009-08-06 19:06:46 +0200315
316 llist_for_each_entry(trx, &bts->trx_list, list)
317 config_write_trx_single(vty, trx);
318}
319
320static int config_write_bts(struct vty *v)
321{
322 struct gsm_bts *bts;
323
324 llist_for_each_entry(bts, &gsmnet->bts_list, list)
325 config_write_bts_single(v, bts);
326
327 return CMD_SUCCESS;
328}
329
Harald Weltee87eb462009-08-07 13:29:14 +0200330static int config_write_net(struct vty *vty)
331{
332 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200333 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200334 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200335 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
336 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200337 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte59936d72009-11-18 20:33:19 +0100338 vty_out(vty, " location updating reject cause %u%s",
339 gsmnet->reject_cause, VTY_NEWLINE);
Harald Weltecca253a2009-08-30 15:47:06 +0900340 vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
Holger Hans Peter Freyther6b4f5462009-11-19 16:37:48 +0100341 vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
Harald Welte52af1952009-12-13 10:53:12 +0100342 vty_out(vty, " rrlp mode %s%s", rrlp_mode_name(gsmnet->rrlp.mode),
343 VTY_NEWLINE);
Harald Weltea310f3e2009-12-14 09:00:24 +0100344 vty_out(vty, " mm info %u%s", gsmnet->send_mm_info, VTY_NEWLINE);
Harald Welte0af9c9f2009-12-19 21:41:52 +0100345 vty_out(vty, " handover %u%s", gsmnet->handover.active, VTY_NEWLINE);
Harald Weltea8062f12009-12-21 16:51:50 +0100346 vty_out(vty, " handover window rxlev averaging %u%s",
347 gsmnet->handover.win_rxlev_avg, VTY_NEWLINE);
348 vty_out(vty, " handover window rxqual averaging %u%s",
349 gsmnet->handover.win_rxqual_avg, VTY_NEWLINE);
350 vty_out(vty, " handover window rxlev neighbor averaging %u%s",
351 gsmnet->handover.win_rxlev_avg_neigh, VTY_NEWLINE);
352 vty_out(vty, " handover power budget interval %u%s",
353 gsmnet->handover.pwr_interval, VTY_NEWLINE);
354 vty_out(vty, " handover power budget hysteresis %u%s",
355 gsmnet->handover.pwr_hysteresis, VTY_NEWLINE);
356 vty_out(vty, " handover maximum distance %u%s",
357 gsmnet->handover.max_distance, VTY_NEWLINE);
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100358 vty_out(vty, " timer t3101 %u%s", gsmnet->T3101, VTY_NEWLINE);
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +0100359 vty_out(vty, " timer t3103 %u%s", gsmnet->T3103, VTY_NEWLINE);
360 vty_out(vty, " timer t3105 %u%s", gsmnet->T3105, VTY_NEWLINE);
361 vty_out(vty, " timer t3107 %u%s", gsmnet->T3107, VTY_NEWLINE);
362 vty_out(vty, " timer t3109 %u%s", gsmnet->T3109, VTY_NEWLINE);
363 vty_out(vty, " timer t3111 %u%s", gsmnet->T3111, VTY_NEWLINE);
364 vty_out(vty, " timer t3113 %u%s", gsmnet->T3113, VTY_NEWLINE);
365 vty_out(vty, " timer t3115 %u%s", gsmnet->T3115, VTY_NEWLINE);
366 vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
367 vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
368 vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200369
370 return CMD_SUCCESS;
371}
Harald Welte97ceef92009-08-06 19:06:46 +0200372
Harald Welte59b04682009-06-10 05:40:52 +0800373static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
374{
375 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
376 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Welte91afe4c2009-06-20 18:15:19 +0200377 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte62868882009-08-08 16:12:58 +0200378 "resulting BS power: %d dBm%s",
Harald Welte91afe4c2009-06-20 18:15:19 +0200379 trx->nominal_power, trx->max_power_red,
Harald Welte62868882009-08-08 16:12:58 +0200380 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800381 vty_out(vty, " NM State: ");
382 net_dump_nmstate(vty, &trx->nm_state);
383 vty_out(vty, " Baseband Transceiver NM State: ");
384 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
Harald Welte25572872009-10-20 00:22:00 +0200385 if (is_ipaccess_bts(trx->bts)) {
386 vty_out(vty, " ip.access stream ID: 0x%02x%s",
387 trx->rsl_tei, VTY_NEWLINE);
388 } else {
389 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
390 e1isl_dump_vty(vty, trx->rsl_link);
391 }
Harald Welte59b04682009-06-10 05:40:52 +0800392}
393
394DEFUN(show_trx,
395 show_trx_cmd,
396 "show trx [bts_nr] [trx_nr]",
397 SHOW_STR "Display information about a TRX\n")
398{
399 struct gsm_network *net = gsmnet;
400 struct gsm_bts *bts = NULL;
401 struct gsm_bts_trx *trx;
402 int bts_nr, trx_nr;
403
404 if (argc >= 1) {
405 /* use the BTS number that the user has specified */
406 bts_nr = atoi(argv[0]);
407 if (bts_nr >= net->num_bts) {
408 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
409 VTY_NEWLINE);
410 return CMD_WARNING;
411 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200412 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800413 }
414 if (argc >= 2) {
415 trx_nr = atoi(argv[1]);
416 if (trx_nr >= bts->num_trx) {
417 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
418 VTY_NEWLINE);
419 return CMD_WARNING;
420 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200421 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800422 trx_dump_vty(vty, trx);
423 return CMD_SUCCESS;
424 }
425 if (bts) {
426 /* print all TRX in this BTS */
427 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200428 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800429 trx_dump_vty(vty, trx);
430 }
431 return CMD_SUCCESS;
432 }
433
434 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200435 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800436 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200437 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800438 trx_dump_vty(vty, trx);
439 }
440 }
441
442 return CMD_SUCCESS;
443}
444
Harald Welte97ceef92009-08-06 19:06:46 +0200445
Harald Welte59b04682009-06-10 05:40:52 +0800446static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
447{
Harald Welte59b04682009-06-10 05:40:52 +0800448 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
449 ts->nr, ts->trx->nr, ts->trx->bts->nr,
450 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
451 vty_out(vty, " NM State: ");
452 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte87504212009-12-02 01:56:49 +0530453 if (!is_ipaccess_bts(ts->trx->bts))
Harald Welte59b04682009-06-10 05:40:52 +0800454 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
455 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
456 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800457}
458
459DEFUN(show_ts,
460 show_ts_cmd,
461 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
462 SHOW_STR "Display information about a TS\n")
463{
464 struct gsm_network *net = gsmnet;
465 struct gsm_bts *bts;
466 struct gsm_bts_trx *trx;
467 struct gsm_bts_trx_ts *ts;
468 int bts_nr, trx_nr, ts_nr;
469
470 if (argc >= 1) {
471 /* use the BTS number that the user has specified */
472 bts_nr = atoi(argv[0]);
473 if (bts_nr >= net->num_bts) {
474 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
475 VTY_NEWLINE);
476 return CMD_WARNING;
477 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200478 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800479 }
480 if (argc >= 2) {
481 trx_nr = atoi(argv[1]);
482 if (trx_nr >= bts->num_trx) {
483 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
484 VTY_NEWLINE);
485 return CMD_WARNING;
486 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200487 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800488 }
489 if (argc >= 3) {
490 ts_nr = atoi(argv[2]);
491 if (ts_nr >= TRX_NR_TS) {
492 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
493 VTY_NEWLINE);
494 return CMD_WARNING;
495 }
496 ts = &trx->ts[ts_nr];
497 ts_dump_vty(vty, ts);
498 return CMD_SUCCESS;
499 }
500 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200501 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800502 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200503 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800504 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
505 ts = &trx->ts[ts_nr];
506 ts_dump_vty(vty, ts);
507 }
508 }
509 }
510
511 return CMD_SUCCESS;
512}
513
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +0200514void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte59b04682009-06-10 05:40:52 +0800515{
Harald Welte91afe4c2009-06-20 18:15:19 +0200516 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte59b04682009-06-10 05:40:52 +0800517 subscr->authorized, VTY_NEWLINE);
518 if (subscr->name)
519 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
520 if (subscr->extension)
521 vty_out(vty, " Extension: %s%s", subscr->extension,
522 VTY_NEWLINE);
523 if (subscr->imsi)
524 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200525 if (subscr->tmsi != GSM_RESERVED_TMSI)
526 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte270c06c2009-08-15 03:24:51 +0200527 VTY_NEWLINE);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +0200528 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800529}
530
Harald Welte44007742009-12-22 21:43:14 +0100531static void meas_rep_dump_uni_vty(struct vty *vty,
532 struct gsm_meas_rep_unidir *mru,
533 const char *prefix,
534 const char *dir)
535{
536 vty_out(vty, "%s RXL-FULL-%s: %4d dBm, RXL-SUB-%s: %4d dBm ",
537 prefix, dir, rxlev2dbm(mru->full.rx_lev),
538 dir, rxlev2dbm(mru->sub.rx_lev));
539 vty_out(vty, "RXQ-FULL-%s: %d, RXQ-SUB-%s: %d%s",
540 dir, mru->full.rx_qual, dir, mru->sub.rx_qual,
541 VTY_NEWLINE);
542}
543
544static void meas_rep_dump_vty(struct vty *vty, struct gsm_meas_rep *mr,
545 const char *prefix)
546{
547 vty_out(vty, "%sMeasurement Report:%s", prefix, VTY_NEWLINE);
548 vty_out(vty, "%s Flags: %s%s%s%s%s", prefix,
549 mr->flags & MEAS_REP_F_UL_DTX ? "DTXu " : "",
550 mr->flags & MEAS_REP_F_DL_DTX ? "DTXd " : "",
551 mr->flags & MEAS_REP_F_FPC ? "FPC " : "",
552 mr->flags & MEAS_REP_F_DL_VALID ? " " : "DLinval ",
553 VTY_NEWLINE);
554 if (mr->flags & MEAS_REP_F_MS_TO)
555 vty_out(vty, "%s MS Timing Offset: %u%s", prefix,
556 mr->ms_timing_offset, VTY_NEWLINE);
557 if (mr->flags & MEAS_REP_F_MS_L1)
558 vty_out(vty, "%s L1 MS Power: %u dBm, Timing Advance: %u%s",
559 prefix, mr->ms_l1.pwr, mr->ms_l1.ta, VTY_NEWLINE);
560 if (mr->flags & MEAS_REP_F_DL_VALID)
561 meas_rep_dump_uni_vty(vty, &mr->dl, prefix, "dl");
562 meas_rep_dump_uni_vty(vty, &mr->ul, prefix, "ul");
563}
564
Harald Welte59b04682009-06-10 05:40:52 +0800565static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
566{
Harald Welte44007742009-12-22 21:43:14 +0100567 int idx;
568
Harald Welte59b04682009-06-10 05:40:52 +0800569 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
570 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
Harald Welte (local)02204d02009-12-27 18:05:25 +0100571 lchan->ts->trx->bts->nr, gsm_lchant_name(lchan->type),
Harald Welte59b04682009-06-10 05:40:52 +0800572 VTY_NEWLINE);
573 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
Harald Welteb761bf82009-12-12 18:17:25 +0100574 vty_out(vty, " BS Power: %u dBm, MS Power: %u dBm%s",
575 lchan->ts->trx->nominal_power - lchan->ts->trx->max_power_red
576 - lchan->bs_power*2,
577 ms_pwr_dbm(lchan->ts->trx->bts->band, lchan->ms_power),
578 VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800579 if (lchan->subscr) {
580 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
581 subscr_dump_vty(vty, lchan->subscr);
582 } else
583 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
Harald Welte87504212009-12-02 01:56:49 +0530584 if (is_ipaccess_bts(lchan->ts->trx->bts)) {
585 struct in_addr ia;
586 ia.s_addr = lchan->abis_ip.bound_ip;
587 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
588 inet_ntoa(ia), lchan->abis_ip.bound_port,
589 lchan->abis_ip.rtp_payload2, lchan->abis_ip.conn_id,
590 VTY_NEWLINE);
591 }
Harald Welte44007742009-12-22 21:43:14 +0100592
593 /* we want to report the last measurement report */
594 idx = calc_initial_idx(ARRAY_SIZE(lchan->meas_rep),
595 lchan->meas_rep_idx, 1);
596 meas_rep_dump_vty(vty, &lchan->meas_rep[idx], " ");
Harald Welte59b04682009-06-10 05:40:52 +0800597}
598
Harald Welte03740842009-06-10 23:11:52 +0800599#if 0
600TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte59b04682009-06-10 05:40:52 +0800601static void call_dump_vty(struct vty *vty, struct gsm_call *call)
602{
603 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
604 call->type, call->state, call->transaction_id, VTY_NEWLINE);
605
606 if (call->local_lchan) {
607 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
608 lchan_dump_vty(vty, call->local_lchan);
609 } else
610 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
611
612 if (call->remote_lchan) {
613 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
614 lchan_dump_vty(vty, call->remote_lchan);
615 } else
616 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
617
618 if (call->called_subscr) {
619 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
620 subscr_dump_vty(vty, call->called_subscr);
621 } else
622 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
623}
Harald Welte03740842009-06-10 23:11:52 +0800624#endif
Harald Welte59b04682009-06-10 05:40:52 +0800625
626DEFUN(show_lchan,
627 show_lchan_cmd,
628 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
629 SHOW_STR "Display information about a logical channel\n")
630{
631 struct gsm_network *net = gsmnet;
632 struct gsm_bts *bts;
633 struct gsm_bts_trx *trx;
634 struct gsm_bts_trx_ts *ts;
635 struct gsm_lchan *lchan;
636 int bts_nr, trx_nr, ts_nr, lchan_nr;
637
638 if (argc >= 1) {
639 /* use the BTS number that the user has specified */
640 bts_nr = atoi(argv[0]);
641 if (bts_nr >= net->num_bts) {
642 vty_out(vty, "%% can't find BTS %s%s", argv[0],
643 VTY_NEWLINE);
644 return CMD_WARNING;
645 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200646 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800647 }
648 if (argc >= 2) {
649 trx_nr = atoi(argv[1]);
650 if (trx_nr >= bts->num_trx) {
651 vty_out(vty, "%% can't find TRX %s%s", argv[1],
652 VTY_NEWLINE);
653 return CMD_WARNING;
654 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200655 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800656 }
657 if (argc >= 3) {
658 ts_nr = atoi(argv[2]);
659 if (ts_nr >= TRX_NR_TS) {
660 vty_out(vty, "%% can't find TS %s%s", argv[2],
661 VTY_NEWLINE);
662 return CMD_WARNING;
663 }
664 ts = &trx->ts[ts_nr];
665 }
666 if (argc >= 4) {
667 lchan_nr = atoi(argv[3]);
668 if (lchan_nr >= TS_MAX_LCHAN) {
669 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
670 VTY_NEWLINE);
671 return CMD_WARNING;
672 }
673 lchan = &ts->lchan[lchan_nr];
674 lchan_dump_vty(vty, lchan);
675 return CMD_SUCCESS;
676 }
677 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200678 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800679 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200680 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800681 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
682 ts = &trx->ts[ts_nr];
683 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
684 lchan_nr++) {
685 lchan = &ts->lchan[lchan_nr];
686 if (lchan->type == GSM_LCHAN_NONE)
687 continue;
688 lchan_dump_vty(vty, lchan);
689 }
690 }
691 }
692 }
693
694 return CMD_SUCCESS;
695}
696
697static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
698{
699 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
700}
701
702DEFUN(show_e1drv,
703 show_e1drv_cmd,
704 "show e1_driver",
705 SHOW_STR "Display information about available E1 drivers\n")
706{
707 struct e1inp_driver *drv;
708
709 llist_for_each_entry(drv, &e1inp_driver_list, list)
710 e1drv_dump_vty(vty, drv);
711
712 return CMD_SUCCESS;
713}
714
715static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
716{
717 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
718 line->num, line->name ? line->name : "",
719 line->driver->name, VTY_NEWLINE);
720}
721
722DEFUN(show_e1line,
723 show_e1line_cmd,
724 "show e1_line [line_nr]",
725 SHOW_STR "Display information about a E1 line\n")
726{
727 struct e1inp_line *line;
728
729 if (argc >= 1) {
730 int num = atoi(argv[0]);
731 llist_for_each_entry(line, &e1inp_line_list, list) {
732 if (line->num == num) {
733 e1line_dump_vty(vty, line);
734 return CMD_SUCCESS;
735 }
736 }
737 return CMD_WARNING;
738 }
739
740 llist_for_each_entry(line, &e1inp_line_list, list)
741 e1line_dump_vty(vty, line);
742
743 return CMD_SUCCESS;
744}
745
746static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
747{
Harald Welte62868882009-08-08 16:12:58 +0200748 if (ts->type == E1INP_TS_TYPE_NONE)
749 return;
Harald Welte59b04682009-06-10 05:40:52 +0800750 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
751 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
752 VTY_NEWLINE);
753}
754
755DEFUN(show_e1ts,
756 show_e1ts_cmd,
757 "show e1_timeslot [line_nr] [ts_nr]",
758 SHOW_STR "Display information about a E1 timeslot\n")
759{
Harald Welte49c79562009-11-17 06:12:16 +0100760 struct e1inp_line *line = NULL;
Harald Welte59b04682009-06-10 05:40:52 +0800761 struct e1inp_ts *ts;
762 int ts_nr;
763
764 if (argc == 0) {
765 llist_for_each_entry(line, &e1inp_line_list, list) {
766 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
767 ts = &line->ts[ts_nr];
768 e1ts_dump_vty(vty, ts);
769 }
770 }
771 return CMD_SUCCESS;
772 }
773 if (argc >= 1) {
774 int num = atoi(argv[0]);
775 llist_for_each_entry(line, &e1inp_line_list, list) {
776 if (line->num == num)
777 break;
778 }
779 if (!line || line->num != num) {
780 vty_out(vty, "E1 line %s is invalid%s",
781 argv[0], VTY_NEWLINE);
782 return CMD_WARNING;
783 }
784 }
785 if (argc >= 2) {
786 ts_nr = atoi(argv[1]);
787 if (ts_nr > NUM_E1_TS) {
788 vty_out(vty, "E1 timeslot %s is invalid%s",
789 argv[1], VTY_NEWLINE);
790 return CMD_WARNING;
791 }
792 ts = &line->ts[ts_nr];
793 e1ts_dump_vty(vty, ts);
794 return CMD_SUCCESS;
795 } else {
796 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
797 ts = &line->ts[ts_nr];
798 e1ts_dump_vty(vty, ts);
799 }
800 return CMD_SUCCESS;
801 }
802 return CMD_SUCCESS;
803}
804
805static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
806{
807 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
808 subscr_dump_vty(vty, pag->subscr);
809}
810
811static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
812{
813 struct gsm_paging_request *pag;
814
815 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
816 paging_dump_vty(vty, pag);
817}
818
819DEFUN(show_paging,
820 show_paging_cmd,
821 "show paging [bts_nr]",
822 SHOW_STR "Display information about paging reuqests of a BTS\n")
823{
824 struct gsm_network *net = gsmnet;
825 struct gsm_bts *bts;
826 int bts_nr;
827
828 if (argc >= 1) {
829 /* use the BTS number that the user has specified */
830 bts_nr = atoi(argv[0]);
831 if (bts_nr >= net->num_bts) {
832 vty_out(vty, "%% can't find BTS %s%s", argv[0],
833 VTY_NEWLINE);
834 return CMD_WARNING;
835 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200836 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800837 bts_paging_dump_vty(vty, bts);
838
839 return CMD_SUCCESS;
840 }
841 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200842 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800843 bts_paging_dump_vty(vty, bts);
844 }
845
846 return CMD_SUCCESS;
847}
848
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100849static void _vty_output(struct debug_target *tgt, const char *line)
850{
851 struct vty *vty = tgt->tgt_vty.vty;
852 vty_out(vty, "%s", line);
853 /* This is an ugly hack, but there is no easy way... */
854 if (strchr(line, '\n'))
855 vty_out(vty, "\r");
856}
857
858struct debug_target *debug_target_create_vty(struct vty *vty)
859{
860 struct debug_target *target;
861
862 target = debug_target_create();
863 if (!target)
864 return NULL;
865
866 target->tgt_vty.vty = vty;
867 target->output = _vty_output;
868 return target;
869}
870
871DEFUN(enable_logging,
872 enable_logging_cmd,
873 "logging enable",
874 "Enables logging to this vty\n")
875{
876 struct telnet_connection *conn;
877
878 conn = (struct telnet_connection *) vty->priv;
879 if (conn->dbg) {
880 vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE);
881 return CMD_WARNING;
882 }
883
884 conn->dbg = debug_target_create_vty(vty);
885 if (!conn->dbg)
886 return CMD_WARNING;
887
888 debug_add_target(conn->dbg);
889 return CMD_SUCCESS;
890}
891
892DEFUN(logging_fltr_imsi,
893 logging_fltr_imsi_cmd,
894 "logging filter imsi IMSI",
895 "Print all messages related to a IMSI\n")
896{
897 struct telnet_connection *conn;
898
899 conn = (struct telnet_connection *) vty->priv;
900 if (!conn->dbg) {
901 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
902 return CMD_WARNING;
903 }
904
905 debug_set_imsi_filter(conn->dbg, argv[0]);
906 return CMD_SUCCESS;
907}
908
909DEFUN(logging_fltr_all,
910 logging_fltr_all_cmd,
911 "logging filter all <0-1>",
912 "Print all messages to the console\n")
913{
914 struct telnet_connection *conn;
915
916 conn = (struct telnet_connection *) vty->priv;
917 if (!conn->dbg) {
918 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
919 return CMD_WARNING;
920 }
921
922 debug_set_all_filter(conn->dbg, atoi(argv[0]));
923 return CMD_SUCCESS;
924}
925
926DEFUN(logging_use_clr,
927 logging_use_clr_cmd,
Harald Welte (local)0bb88162009-12-26 19:45:22 +0100928 "logging color <0-1>",
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100929 "Use color for printing messages\n")
930{
931 struct telnet_connection *conn;
932
933 conn = (struct telnet_connection *) vty->priv;
934 if (!conn->dbg) {
935 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
936 return CMD_WARNING;
937 }
938
939 debug_set_use_color(conn->dbg, atoi(argv[0]));
940 return CMD_SUCCESS;
941}
942
943DEFUN(logging_prnt_timestamp,
944 logging_prnt_timestamp_cmd,
Harald Welte (local)0bb88162009-12-26 19:45:22 +0100945 "logging timestamp <0-1>",
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100946 "Print the timestamp of each message\n")
947{
948 struct telnet_connection *conn;
949
950 conn = (struct telnet_connection *) vty->priv;
951 if (!conn->dbg) {
952 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
953 return CMD_WARNING;
954 }
955
956 debug_set_print_timestamp(conn->dbg, atoi(argv[0]));
957 return CMD_SUCCESS;
958}
959
Harald Welte (local)0bb88162009-12-26 19:45:22 +0100960#define VTY_DEBUG_CATEGORIES "(rll|cc|mm|rr|rsl|nm|sms|pag|mncc|inp|mi|mib|mux|meas|sccp|msc|mgcp|ho|db|ref)"
961DEFUN(logging_level,
962 logging_level_cmd,
963 "logging level " VTY_DEBUG_CATEGORIES " <0-8>",
964 "Set the log level for a specified category\n")
965{
966 struct telnet_connection *conn;
967 int category = debug_parse_category(argv[0]);
968
969 conn = (struct telnet_connection *) vty->priv;
970 if (!conn->dbg) {
971 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
972 return CMD_WARNING;
973 }
974
975 if (category < 0) {
976 vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
977 return CMD_WARNING;
978 }
979
980 conn->dbg->categories[category].enabled = 1;
981 conn->dbg->categories[category].loglevel = atoi(argv[1]);
982
983 return CMD_SUCCESS;
984}
985
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100986DEFUN(logging_set_category_mask,
987 logging_set_category_mask_cmd,
988 "logging set debug mask MASK",
989 "Decide which categories to output.\n")
990{
991 struct telnet_connection *conn;
992
993 conn = (struct telnet_connection *) vty->priv;
994 if (!conn->dbg) {
995 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
996 return CMD_WARNING;
997 }
998
999 debug_parse_category_mask(conn->dbg, argv[0]);
1000 return CMD_SUCCESS;
1001}
1002
1003DEFUN(logging_set_log_level,
1004 logging_set_log_level_cmd,
1005 "logging set log level <0-8>",
1006 "Set the global log level. The value 0 implies no filtering.\n")
1007{
1008 struct telnet_connection *conn;
1009
1010 conn = (struct telnet_connection *) vty->priv;
1011 if (!conn->dbg) {
1012 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
1013 return CMD_WARNING;
1014 }
1015
1016 debug_set_log_level(conn->dbg, atoi(argv[0]));
1017 return CMD_SUCCESS;
1018}
1019
1020DEFUN(diable_logging,
1021 disable_logging_cmd,
1022 "logging disable",
1023 "Disables logging to this vty\n")
1024{
1025 struct telnet_connection *conn;
1026
1027 conn = (struct telnet_connection *) vty->priv;
1028 if (!conn->dbg) {
1029 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
1030 return CMD_WARNING;
1031 }
1032
1033 debug_del_target(conn->dbg);
1034 talloc_free(conn->dbg);
1035 conn->dbg = NULL;
1036 return CMD_SUCCESS;
1037}
1038
Harald Welte3edc5a92009-12-22 00:41:05 +01001039DEFUN(show_stats,
1040 show_stats_cmd,
1041 "show statistics",
1042 SHOW_STR "Display network statistics\n")
1043{
1044 struct gsm_network *net = gsmnet;
1045
Harald Welte2f404622009-12-22 21:47:48 +01001046 vty_out(vty, "Channel Requests : %lu total, %lu no channel%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001047 counter_get(net->stats.chreq.total),
1048 counter_get(net->stats.chreq.no_channel), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001049 vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001050 counter_get(net->stats.loc_upd_type.attach),
1051 counter_get(net->stats.loc_upd_type.normal),
1052 counter_get(net->stats.loc_upd_type.periodic), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001053 vty_out(vty, "IMSI Detach Indications : %lu%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001054 counter_get(net->stats.loc_upd_type.detach), VTY_NEWLINE);
Harald Welte3edc5a92009-12-22 00:41:05 +01001055 vty_out(vty, "Location Update Response: %lu accept, %lu reject%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001056 counter_get(net->stats.loc_upd_resp.accept),
1057 counter_get(net->stats.loc_upd_resp.reject), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001058 vty_out(vty, "Paging : %lu attempted, %lu complete, %lu expired%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001059 counter_get(net->stats.paging.attempted),
1060 counter_get(net->stats.paging.completed),
1061 counter_get(net->stats.paging.expired), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001062 vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, "
Harald Weltebdbb7442009-12-22 19:07:32 +01001063 "%lu completed, %lu failed%s",
1064 counter_get(net->stats.handover.attempted),
1065 counter_get(net->stats.handover.no_channel),
1066 counter_get(net->stats.handover.timeout),
1067 counter_get(net->stats.handover.completed),
1068 counter_get(net->stats.handover.failed), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001069 vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001070 counter_get(net->stats.sms.submitted),
1071 counter_get(net->stats.sms.no_receiver), VTY_NEWLINE);
Harald Welte2f404622009-12-22 21:47:48 +01001072 vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s",
Harald Weltebdbb7442009-12-22 19:07:32 +01001073 counter_get(net->stats.sms.delivered),
1074 counter_get(net->stats.sms.rp_err_mem),
1075 counter_get(net->stats.sms.rp_err_other), VTY_NEWLINE);
Harald Welte3edc5a92009-12-22 00:41:05 +01001076 return CMD_SUCCESS;
1077}
1078
Harald Weltee87eb462009-08-07 13:29:14 +02001079DEFUN(cfg_net,
1080 cfg_net_cmd,
1081 "network",
1082 "Configure the GSM network")
1083{
1084 vty->index = gsmnet;
1085 vty->node = GSMNET_NODE;
1086
1087 return CMD_SUCCESS;
1088}
1089
1090
1091DEFUN(cfg_net_ncc,
1092 cfg_net_ncc_cmd,
1093 "network country code <1-999>",
1094 "Set the GSM network country code")
1095{
1096 gsmnet->country_code = atoi(argv[0]);
1097
1098 return CMD_SUCCESS;
1099}
1100
1101DEFUN(cfg_net_mnc,
1102 cfg_net_mnc_cmd,
1103 "mobile network code <1-999>",
1104 "Set the GSM mobile network code")
1105{
1106 gsmnet->network_code = atoi(argv[0]);
1107
1108 return CMD_SUCCESS;
1109}
1110
1111DEFUN(cfg_net_name_short,
1112 cfg_net_name_short_cmd,
1113 "short name NAME",
1114 "Set the short GSM network name")
1115{
1116 if (gsmnet->name_short)
1117 talloc_free(gsmnet->name_short);
1118
1119 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
1120
1121 return CMD_SUCCESS;
1122}
1123
1124DEFUN(cfg_net_name_long,
1125 cfg_net_name_long_cmd,
1126 "long name NAME",
1127 "Set the long GSM network name")
1128{
1129 if (gsmnet->name_long)
1130 talloc_free(gsmnet->name_long);
1131
1132 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
1133
1134 return CMD_SUCCESS;
1135}
Harald Welte59b04682009-06-10 05:40:52 +08001136
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001137DEFUN(cfg_net_auth_policy,
1138 cfg_net_auth_policy_cmd,
1139 "auth policy (closed|accept-all|token)",
1140 "Set the GSM network authentication policy\n")
1141{
1142 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
1143
1144 gsmnet->auth_policy = policy;
1145
1146 return CMD_SUCCESS;
1147}
1148
Harald Welte59936d72009-11-18 20:33:19 +01001149DEFUN(cfg_net_reject_cause,
1150 cfg_net_reject_cause_cmd,
1151 "location updating reject cause <2-111>",
1152 "Set the reject cause of location updating reject\n")
1153{
1154 gsmnet->reject_cause = atoi(argv[0]);
1155
1156 return CMD_SUCCESS;
1157}
1158
Harald Weltecca253a2009-08-30 15:47:06 +09001159DEFUN(cfg_net_encryption,
1160 cfg_net_encryption_cmd,
1161 "encryption a5 (0|1|2)",
1162 "Enable or disable encryption (A5) for this network\n")
1163{
Andreas.Eversberg53293292009-11-17 09:55:26 +01001164 gsmnet->a5_encryption= atoi(argv[0]);
Harald Weltecca253a2009-08-30 15:47:06 +09001165
1166 return CMD_SUCCESS;
1167}
1168
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001169DEFUN(cfg_net_neci,
1170 cfg_net_neci_cmd,
1171 "neci (0|1)",
1172 "Set if NECI of cell selection is to be set")
1173{
1174 gsmnet->neci = atoi(argv[0]);
1175 return CMD_SUCCESS;
1176}
1177
Harald Welte52af1952009-12-13 10:53:12 +01001178DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd,
1179 "rrlp mode (none|ms-based|ms-preferred|ass-preferred)",
1180 "Set the Radio Resource Location Protocol Mode")
1181{
1182 gsmnet->rrlp.mode = rrlp_mode_parse(argv[0]);
1183
1184 return CMD_SUCCESS;
1185}
1186
Harald Weltea310f3e2009-12-14 09:00:24 +01001187DEFUN(cfg_net_mm_info, cfg_net_mm_info_cmd,
1188 "mm info (0|1)",
1189 "Whether to send MM INFO after LOC UPD ACCEPT")
1190{
1191 gsmnet->send_mm_info = atoi(argv[0]);
1192
1193 return CMD_SUCCESS;
1194}
1195
Harald Welte0af9c9f2009-12-19 21:41:52 +01001196DEFUN(cfg_net_handover, cfg_net_handover_cmd,
1197 "handover (0|1)",
1198 "Whether or not to use in-call handover")
1199{
Harald Welteaa2c3032009-12-20 13:51:01 +01001200 if (ipacc_rtp_direct) {
1201 vty_out(vty, "%% Cannot enable handover unless RTP Proxy mode "
1202 "is enabled by using the -P command line option%s",
1203 VTY_NEWLINE);
1204 return CMD_WARNING;
1205 }
Harald Welte0af9c9f2009-12-19 21:41:52 +01001206 gsmnet->handover.active = atoi(argv[0]);
1207
1208 return CMD_SUCCESS;
1209}
1210
Harald Weltea8062f12009-12-21 16:51:50 +01001211DEFUN(cfg_net_ho_win_rxlev_avg, cfg_net_ho_win_rxlev_avg_cmd,
1212 "handover window rxlev averaging <1-10>",
1213 "How many RxLev measurements are used for averaging")
1214{
1215 gsmnet->handover.win_rxlev_avg = atoi(argv[0]);
1216 return CMD_SUCCESS;
1217}
1218
1219DEFUN(cfg_net_ho_win_rxqual_avg, cfg_net_ho_win_rxqual_avg_cmd,
1220 "handover window rxqual averaging <1-10>",
1221 "How many RxQual measurements are used for averaging")
1222{
1223 gsmnet->handover.win_rxqual_avg = atoi(argv[0]);
1224 return CMD_SUCCESS;
1225}
1226
1227DEFUN(cfg_net_ho_win_rxlev_neigh_avg, cfg_net_ho_win_rxlev_avg_neigh_cmd,
1228 "handover window rxlev neighbor averaging <1-10>",
1229 "How many RxQual measurements are used for averaging")
1230{
1231 gsmnet->handover.win_rxlev_avg_neigh = atoi(argv[0]);
1232 return CMD_SUCCESS;
1233}
1234
1235DEFUN(cfg_net_ho_pwr_interval, cfg_net_ho_pwr_interval_cmd,
1236 "handover power budget interval <1-99>",
1237 "How often to check if we have a better cell (SACCH frames)")
1238{
1239 gsmnet->handover.pwr_interval = atoi(argv[0]);
1240 return CMD_SUCCESS;
1241}
1242
1243DEFUN(cfg_net_ho_pwr_hysteresis, cfg_net_ho_pwr_hysteresis_cmd,
1244 "handover power budget hysteresis <0-999>",
1245 "How many dB does a neighbor to be stronger to become a HO candidate")
1246{
1247 gsmnet->handover.pwr_hysteresis = atoi(argv[0]);
1248 return CMD_SUCCESS;
1249}
1250
1251DEFUN(cfg_net_ho_max_distance, cfg_net_ho_max_distance_cmd,
1252 "handover maximum distance <0-9999>",
1253 "How big is the maximum timing advance before HO is forced")
1254{
1255 gsmnet->handover.max_distance = atoi(argv[0]);
1256 return CMD_SUCCESS;
1257}
Harald Welte0af9c9f2009-12-19 21:41:52 +01001258
Holger Hans Peter Freyther13ae9802009-12-22 08:27:21 +01001259#define DECLARE_TIMER(number, doc) \
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001260 DEFUN(cfg_net_T##number, \
1261 cfg_net_T##number##_cmd, \
1262 "timer t" #number " <0-65535>", \
Holger Hans Peter Freyther13ae9802009-12-22 08:27:21 +01001263 doc) \
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001264{ \
1265 int value = atoi(argv[0]); \
1266 \
1267 if (value < 0 || value > 65535) { \
1268 vty_out(vty, "Timer value %s out of range.%s", \
1269 argv[0], VTY_NEWLINE); \
1270 return CMD_WARNING; \
1271 } \
1272 \
1273 gsmnet->T##number = value; \
1274 return CMD_SUCCESS; \
1275}
1276
Holger Hans Peter Freyther13ae9802009-12-22 08:27:21 +01001277DECLARE_TIMER(3101, "Set the timeout value for IMMEDIATE ASSIGNMENT.")
1278DECLARE_TIMER(3103, "Set the timeout value for HANDOVER.")
1279DECLARE_TIMER(3105, "Currently not used.")
1280DECLARE_TIMER(3107, "Currently not used.")
1281DECLARE_TIMER(3109, "Currently not used.")
1282DECLARE_TIMER(3111, "Currently not used.")
1283DECLARE_TIMER(3113, "Set the time to try paging a subscriber.")
1284DECLARE_TIMER(3115, "Currently not used.")
1285DECLARE_TIMER(3117, "Currently not used.")
1286DECLARE_TIMER(3119, "Currently not used.")
1287DECLARE_TIMER(3141, "Currently not used.")
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001288
1289
Harald Welte59b04682009-06-10 05:40:52 +08001290/* per-BTS configuration */
1291DEFUN(cfg_bts,
1292 cfg_bts_cmd,
1293 "bts BTS_NR",
1294 "Select a BTS to configure\n")
1295{
1296 int bts_nr = atoi(argv[0]);
1297 struct gsm_bts *bts;
1298
Harald Weltee712a5f2009-06-21 16:17:15 +02001299 if (bts_nr > gsmnet->num_bts) {
1300 vty_out(vty, "%% The next unused BTS number is %u%s",
1301 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001302 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001303 } else if (bts_nr == gsmnet->num_bts) {
1304 /* allocate a new one */
1305 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
1306 HARDCODED_TSC, HARDCODED_BSIC);
1307 } else
1308 bts = gsm_bts_num(gsmnet, bts_nr);
1309
1310 if (!bts)
1311 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001312
1313 vty->index = bts;
1314 vty->node = BTS_NODE;
1315
1316 return CMD_SUCCESS;
1317}
1318
1319DEFUN(cfg_bts_type,
1320 cfg_bts_type_cmd,
1321 "type TYPE",
1322 "Set the BTS type\n")
1323{
1324 struct gsm_bts *bts = vty->index;
1325
Harald Welte3ffe1b32009-08-07 00:25:23 +02001326 bts->type = parse_btstype(argv[0]);
1327
Harald Welte25572872009-10-20 00:22:00 +02001328 if (is_ipaccess_bts(bts)) {
1329 /* Set the default OML Stream ID to 0xff */
1330 bts->oml_tei = 0xff;
1331 }
1332
Harald Welte59b04682009-06-10 05:40:52 +08001333 return CMD_SUCCESS;
1334}
1335
Harald Welte91afe4c2009-06-20 18:15:19 +02001336DEFUN(cfg_bts_band,
1337 cfg_bts_band_cmd,
1338 "band BAND",
1339 "Set the frequency band of this BTS\n")
1340{
1341 struct gsm_bts *bts = vty->index;
Harald Welte62868882009-08-08 16:12:58 +02001342 int band = gsm_band_parse(argv[0]);
Harald Welte91afe4c2009-06-20 18:15:19 +02001343
1344 if (band < 0) {
1345 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
1346 band, VTY_NEWLINE);
1347 return CMD_WARNING;
1348 }
1349
1350 bts->band = band;
1351
1352 return CMD_SUCCESS;
1353}
1354
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +02001355DEFUN(cfg_bts_ci,
1356 cfg_bts_ci_cmd,
1357 "cell_identity <0-65535>",
1358 "Set the Cell identity of this BTS\n")
1359{
1360 struct gsm_bts *bts = vty->index;
1361 int ci = atoi(argv[0]);
1362
1363 if (ci < 0 || ci > 0xffff) {
1364 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
1365 ci, VTY_NEWLINE);
1366 return CMD_WARNING;
1367 }
1368 bts->cell_identity = ci;
1369
1370 return CMD_SUCCESS;
1371}
1372
Harald Welte59b04682009-06-10 05:40:52 +08001373DEFUN(cfg_bts_lac,
1374 cfg_bts_lac_cmd,
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +02001375 "location_area_code <0-65535>",
Harald Welte59b04682009-06-10 05:40:52 +08001376 "Set the Location Area Code (LAC) of this BTS\n")
1377{
1378 struct gsm_bts *bts = vty->index;
1379 int lac = atoi(argv[0]);
1380
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +02001381 if (lac < 0 || lac > 0xffff) {
1382 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte59b04682009-06-10 05:40:52 +08001383 lac, VTY_NEWLINE);
1384 return CMD_WARNING;
1385 }
Holger Hans Peter Freyther6c6ab862009-10-01 04:07:15 +02001386
1387 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
1388 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
1389 lac, VTY_NEWLINE);
1390 return CMD_WARNING;
1391 }
1392
Harald Welte59b04682009-06-10 05:40:52 +08001393 bts->location_area_code = lac;
1394
1395 return CMD_SUCCESS;
1396}
1397
Harald Weltea54a2bb2009-12-01 18:04:30 +05301398
Harald Welte59b04682009-06-10 05:40:52 +08001399DEFUN(cfg_bts_tsc,
1400 cfg_bts_tsc_cmd,
1401 "training_sequence_code <0-255>",
1402 "Set the Training Sequence Code (TSC) of this BTS\n")
1403{
1404 struct gsm_bts *bts = vty->index;
1405 int tsc = atoi(argv[0]);
1406
1407 if (tsc < 0 || tsc > 0xff) {
1408 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
1409 tsc, VTY_NEWLINE);
1410 return CMD_WARNING;
1411 }
1412 bts->tsc = tsc;
1413
1414 return CMD_SUCCESS;
1415}
1416
1417DEFUN(cfg_bts_bsic,
1418 cfg_bts_bsic_cmd,
1419 "base_station_id_code <0-63>",
1420 "Set the Base Station Identity Code (BSIC) of this BTS\n")
1421{
1422 struct gsm_bts *bts = vty->index;
1423 int bsic = atoi(argv[0]);
1424
1425 if (bsic < 0 || bsic > 0x3f) {
Harald Welte62868882009-08-08 16:12:58 +02001426 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte59b04682009-06-10 05:40:52 +08001427 bsic, VTY_NEWLINE);
1428 return CMD_WARNING;
1429 }
1430 bts->bsic = bsic;
1431
1432 return CMD_SUCCESS;
1433}
1434
1435
1436DEFUN(cfg_bts_unit_id,
1437 cfg_bts_unit_id_cmd,
Harald Weltef515aa02009-08-07 13:27:09 +02001438 "ip.access unit_id <0-65534> <0-255>",
1439 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte59b04682009-06-10 05:40:52 +08001440{
1441 struct gsm_bts *bts = vty->index;
1442 int site_id = atoi(argv[0]);
1443 int bts_id = atoi(argv[1]);
1444
Harald Weltef515aa02009-08-07 13:27:09 +02001445 if (!is_ipaccess_bts(bts)) {
1446 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1447 return CMD_WARNING;
1448 }
1449
Harald Welte59b04682009-06-10 05:40:52 +08001450 bts->ip_access.site_id = site_id;
1451 bts->ip_access.bts_id = bts_id;
1452
1453 return CMD_SUCCESS;
1454}
1455
Harald Welte25572872009-10-20 00:22:00 +02001456DEFUN(cfg_bts_stream_id,
1457 cfg_bts_stream_id_cmd,
1458 "oml ip.access stream_id <0-255>",
1459 "Set the ip.access Stream ID of the OML link of this BTS\n")
1460{
1461 struct gsm_bts *bts = vty->index;
1462 int stream_id = atoi(argv[0]);
1463
1464 if (!is_ipaccess_bts(bts)) {
1465 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1466 return CMD_WARNING;
1467 }
1468
1469 bts->oml_tei = stream_id;
1470
1471 return CMD_SUCCESS;
1472}
1473
1474
Harald Welte62868882009-08-08 16:12:58 +02001475DEFUN(cfg_bts_oml_e1,
1476 cfg_bts_oml_e1_cmd,
1477 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1478 "E1 interface to be used for OML\n")
1479{
1480 struct gsm_bts *bts = vty->index;
1481
1482 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
1483
1484 return CMD_SUCCESS;
1485}
1486
1487
1488DEFUN(cfg_bts_oml_e1_tei,
1489 cfg_bts_oml_e1_tei_cmd,
1490 "oml e1 tei <0-63>",
1491 "Set the TEI to be used for OML")
1492{
1493 struct gsm_bts *bts = vty->index;
1494
1495 bts->oml_tei = atoi(argv[0]);
1496
1497 return CMD_SUCCESS;
1498}
1499
Harald Welte3e774612009-08-10 13:48:16 +02001500DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1501 "channel allocator (ascending|descending)",
1502 "Should the channel allocator allocate in reverse TRX order?")
1503{
1504 struct gsm_bts *bts = vty->index;
1505
1506 if (!strcmp(argv[0], "ascending"))
1507 bts->chan_alloc_reverse = 0;
1508 else
1509 bts->chan_alloc_reverse = 1;
1510
1511 return CMD_SUCCESS;
1512}
1513
Sylvain Munaut8e2d8de2009-12-22 13:43:26 +01001514DEFUN(cfg_bts_rach_tx_integer,
1515 cfg_bts_rach_tx_integer_cmd,
1516 "rach tx integer <0-15>",
1517 "Set the raw tx integer value in RACH Control parameters IE")
1518{
1519 struct gsm_bts *bts = vty->index;
1520 bts->si_common.rach_control.tx_integer = atoi(argv[0]) & 0xf;
1521 return CMD_SUCCESS;
1522}
1523
1524DEFUN(cfg_bts_rach_max_trans,
1525 cfg_bts_rach_max_trans_cmd,
1526 "rach max transmission (1|2|4|7)",
1527 "Set the maximum number of RACH burst transmissions")
1528{
1529 struct gsm_bts *bts = vty->index;
1530 bts->si_common.rach_control.max_trans = rach_max_trans_val2raw(atoi(argv[0]));
1531 return CMD_SUCCESS;
1532}
1533
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001534DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1535 "cell barred (0|1)",
1536 "Should this cell be barred from access?")
1537{
1538 struct gsm_bts *bts = vty->index;
1539
Harald Welte8c973ba2009-12-21 23:08:18 +01001540 bts->si_common.rach_control.cell_bar = atoi(argv[0]);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001541
1542 return CMD_SUCCESS;
1543}
1544
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001545DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1546 "ms max power <0-40>",
1547 "Maximum transmit power of the MS")
1548{
1549 struct gsm_bts *bts = vty->index;
1550
1551 bts->ms_max_power = atoi(argv[0]);
1552
1553 return CMD_SUCCESS;
1554}
1555
Harald Welteb761bf82009-12-12 18:17:25 +01001556DEFUN(cfg_bts_cell_resel_hyst, cfg_bts_cell_resel_hyst_cmd,
1557 "cell reselection hysteresis <0-14>",
1558 "Cell Re-Selection Hysteresis in dB")
1559{
1560 struct gsm_bts *bts = vty->index;
1561
1562 bts->si_common.cell_sel_par.cell_resel_hyst = atoi(argv[0])/2;
1563
1564 return CMD_SUCCESS;
1565}
1566
1567DEFUN(cfg_bts_rxlev_acc_min, cfg_bts_rxlev_acc_min_cmd,
1568 "rxlev access min <0-63>",
1569 "Minimum RxLev needed for cell access (better than -110dBm)")
1570{
1571 struct gsm_bts *bts = vty->index;
1572
1573 bts->si_common.cell_sel_par.rxlev_acc_min = atoi(argv[0]);
1574
1575 return CMD_SUCCESS;
1576}
1577
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001578DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1579 "periodic location update <0-1530>",
1580 "Periodic Location Updating Interval in Minutes")
1581{
1582 struct gsm_bts *bts = vty->index;
1583
Harald Weltea54a2bb2009-12-01 18:04:30 +05301584 bts->si_common.chan_desc.t3212 = atoi(argv[0]) / 10;
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001585
1586 return CMD_SUCCESS;
1587}
1588
Harald Welte3e774612009-08-10 13:48:16 +02001589
Harald Welte59b04682009-06-10 05:40:52 +08001590/* per TRX configuration */
1591DEFUN(cfg_trx,
1592 cfg_trx_cmd,
1593 "trx TRX_NR",
1594 "Select a TRX to configure")
1595{
1596 int trx_nr = atoi(argv[0]);
1597 struct gsm_bts *bts = vty->index;
1598 struct gsm_bts_trx *trx;
1599
Harald Weltee712a5f2009-06-21 16:17:15 +02001600 if (trx_nr > bts->num_trx) {
1601 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1602 bts->num_trx, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001603 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001604 } else if (trx_nr == bts->num_trx) {
1605 /* we need to allocate a new one */
1606 trx = gsm_bts_trx_alloc(bts);
1607 } else
1608 trx = gsm_bts_trx_num(bts, trx_nr);
1609
1610 if (!trx)
1611 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001612
1613 vty->index = trx;
1614 vty->node = TRX_NODE;
1615
1616 return CMD_SUCCESS;
1617}
1618
1619DEFUN(cfg_trx_arfcn,
1620 cfg_trx_arfcn_cmd,
1621 "arfcn <1-1024>",
1622 "Set the ARFCN for this TRX\n")
1623{
1624 int arfcn = atoi(argv[0]);
1625 struct gsm_bts_trx *trx = vty->index;
1626
1627 /* FIXME: check if this ARFCN is supported by this TRX */
1628
1629 trx->arfcn = arfcn;
1630
1631 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1632 /* FIXME: use OML layer to update the ARFCN */
1633 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1634
1635 return CMD_SUCCESS;
1636}
1637
Harald Welte91afe4c2009-06-20 18:15:19 +02001638DEFUN(cfg_trx_max_power_red,
1639 cfg_trx_max_power_red_cmd,
1640 "max_power_red <0-100>",
1641 "Reduction of maximum BS RF Power in dB\n")
1642{
1643 int maxpwr_r = atoi(argv[0]);
1644 struct gsm_bts_trx *trx = vty->index;
Harald Welte01acd742009-11-18 09:20:22 +01001645 int upper_limit = 24; /* default 12.21 max power red. */
Harald Welte91afe4c2009-06-20 18:15:19 +02001646
1647 /* FIXME: check if our BTS type supports more than 12 */
1648 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1649 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1650 maxpwr_r, VTY_NEWLINE);
1651 return CMD_WARNING;
1652 }
1653 if (maxpwr_r & 1) {
1654 vty_out(vty, "%% Power %d dB is not an even value%s",
1655 maxpwr_r, VTY_NEWLINE);
1656 return CMD_WARNING;
1657 }
1658
1659 trx->max_power_red = maxpwr_r;
1660
1661 /* FIXME: make sure we update this using OML */
1662
1663 return CMD_SUCCESS;
1664}
1665
Harald Welte62868882009-08-08 16:12:58 +02001666DEFUN(cfg_trx_rsl_e1,
1667 cfg_trx_rsl_e1_cmd,
1668 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1669 "E1 interface to be used for RSL\n")
1670{
1671 struct gsm_bts_trx *trx = vty->index;
1672
1673 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1674
1675 return CMD_SUCCESS;
1676}
1677
1678DEFUN(cfg_trx_rsl_e1_tei,
1679 cfg_trx_rsl_e1_tei_cmd,
1680 "rsl e1 tei <0-63>",
1681 "Set the TEI to be used for RSL")
1682{
1683 struct gsm_bts_trx *trx = vty->index;
1684
1685 trx->rsl_tei = atoi(argv[0]);
1686
1687 return CMD_SUCCESS;
1688}
1689
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001690DEFUN(cfg_trx_rf_locked,
1691 cfg_trx_rf_locked_cmd,
1692 "rf_locked (0|1)",
1693 "Turn off RF of the TRX.\n")
1694{
1695 int locked = atoi(argv[0]);
1696 struct gsm_bts_trx *trx = vty->index;
1697
1698 gsm_trx_lock_rf(trx, locked);
1699 return CMD_SUCCESS;
1700}
Harald Welte62868882009-08-08 16:12:58 +02001701
Harald Welte59b04682009-06-10 05:40:52 +08001702/* per TS configuration */
1703DEFUN(cfg_ts,
1704 cfg_ts_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001705 "timeslot <0-7>",
Harald Welte59b04682009-06-10 05:40:52 +08001706 "Select a Timeslot to configure")
1707{
1708 int ts_nr = atoi(argv[0]);
1709 struct gsm_bts_trx *trx = vty->index;
1710 struct gsm_bts_trx_ts *ts;
1711
1712 if (ts_nr >= TRX_NR_TS) {
1713 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1714 TRX_NR_TS, VTY_NEWLINE);
1715 return CMD_WARNING;
1716 }
1717
1718 ts = &trx->ts[ts_nr];
1719
1720 vty->index = ts;
1721 vty->node = TS_NODE;
1722
1723 return CMD_SUCCESS;
1724}
1725
Harald Welte3ffe1b32009-08-07 00:25:23 +02001726DEFUN(cfg_ts_pchan,
1727 cfg_ts_pchan_cmd,
1728 "phys_chan_config PCHAN",
1729 "Physical Channel configuration (TCH/SDCCH/...)")
1730{
1731 struct gsm_bts_trx_ts *ts = vty->index;
1732 int pchanc;
1733
1734 pchanc = gsm_pchan_parse(argv[0]);
1735 if (pchanc < 0)
1736 return CMD_WARNING;
1737
1738 ts->pchan = pchanc;
1739
1740 return CMD_SUCCESS;
1741}
1742
1743DEFUN(cfg_ts_e1_subslot,
1744 cfg_ts_e1_subslot_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001745 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Welte3ffe1b32009-08-07 00:25:23 +02001746 "E1 sub-slot connected to this on-air timeslot")
1747{
1748 struct gsm_bts_trx_ts *ts = vty->index;
1749
Harald Welte62868882009-08-08 16:12:58 +02001750 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001751
1752 return CMD_SUCCESS;
1753}
Harald Welte59b04682009-06-10 05:40:52 +08001754
Harald Welte59b04682009-06-10 05:40:52 +08001755int bsc_vty_init(struct gsm_network *net)
1756{
1757 gsmnet = net;
1758
1759 cmd_init(1);
1760 vty_init();
1761
1762 install_element(VIEW_NODE, &show_net_cmd);
1763 install_element(VIEW_NODE, &show_bts_cmd);
1764 install_element(VIEW_NODE, &show_trx_cmd);
1765 install_element(VIEW_NODE, &show_ts_cmd);
1766 install_element(VIEW_NODE, &show_lchan_cmd);
1767
1768 install_element(VIEW_NODE, &show_e1drv_cmd);
1769 install_element(VIEW_NODE, &show_e1line_cmd);
1770 install_element(VIEW_NODE, &show_e1ts_cmd);
1771
1772 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte3edc5a92009-12-22 00:41:05 +01001773 install_element(VIEW_NODE, &show_stats_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001774
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +01001775 install_element(VIEW_NODE, &enable_logging_cmd);
1776 install_element(VIEW_NODE, &disable_logging_cmd);
1777 install_element(VIEW_NODE, &logging_fltr_imsi_cmd);
1778 install_element(VIEW_NODE, &logging_fltr_all_cmd);
1779 install_element(VIEW_NODE, &logging_use_clr_cmd);
1780 install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
1781 install_element(VIEW_NODE, &logging_set_category_mask_cmd);
Harald Welte (local)0bb88162009-12-26 19:45:22 +01001782 install_element(VIEW_NODE, &logging_level_cmd);
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +01001783
Harald Weltee87eb462009-08-07 13:29:14 +02001784 install_element(CONFIG_NODE, &cfg_net_cmd);
1785 install_node(&net_node, config_write_net);
1786 install_default(GSMNET_NODE);
Harald Welte62868882009-08-08 16:12:58 +02001787 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001788 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1789 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1790 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001791 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte59936d72009-11-18 20:33:19 +01001792 install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd);
Harald Weltecca253a2009-08-30 15:47:06 +09001793 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001794 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Harald Welte52af1952009-12-13 10:53:12 +01001795 install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd);
Harald Welte284ddba2009-12-14 17:49:15 +01001796 install_element(GSMNET_NODE, &cfg_net_mm_info_cmd);
Harald Welte0af9c9f2009-12-19 21:41:52 +01001797 install_element(GSMNET_NODE, &cfg_net_handover_cmd);
Harald Weltea8062f12009-12-21 16:51:50 +01001798 install_element(GSMNET_NODE, &cfg_net_ho_win_rxlev_avg_cmd);
1799 install_element(GSMNET_NODE, &cfg_net_ho_win_rxqual_avg_cmd);
1800 install_element(GSMNET_NODE, &cfg_net_ho_win_rxlev_avg_neigh_cmd);
1801 install_element(GSMNET_NODE, &cfg_net_ho_pwr_interval_cmd);
1802 install_element(GSMNET_NODE, &cfg_net_ho_pwr_hysteresis_cmd);
1803 install_element(GSMNET_NODE, &cfg_net_ho_max_distance_cmd);
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001804 install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +01001805 install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
1806 install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
1807 install_element(GSMNET_NODE, &cfg_net_T3107_cmd);
1808 install_element(GSMNET_NODE, &cfg_net_T3109_cmd);
1809 install_element(GSMNET_NODE, &cfg_net_T3111_cmd);
1810 install_element(GSMNET_NODE, &cfg_net_T3113_cmd);
1811 install_element(GSMNET_NODE, &cfg_net_T3115_cmd);
1812 install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
1813 install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
1814 install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001815
1816 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte97ceef92009-08-06 19:06:46 +02001817 install_node(&bts_node, config_write_bts);
Harald Welte59b04682009-06-10 05:40:52 +08001818 install_default(BTS_NODE);
1819 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Welte91afe4c2009-06-20 18:15:19 +02001820 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +02001821 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001822 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1823 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001824 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001825 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte25572872009-10-20 00:22:00 +02001826 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001827 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1828 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001829 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Sylvain Munaut8e2d8de2009-12-22 13:43:26 +01001830 install_element(BTS_NODE, &cfg_bts_rach_tx_integer_cmd);
1831 install_element(BTS_NODE, &cfg_bts_rach_max_trans_cmd);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001832 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001833 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001834 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welteb761bf82009-12-12 18:17:25 +01001835 install_element(BTS_NODE, &cfg_bts_cell_resel_hyst_cmd);
1836 install_element(BTS_NODE, &cfg_bts_rxlev_acc_min_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001837
Harald Welte59b04682009-06-10 05:40:52 +08001838
1839 install_element(BTS_NODE, &cfg_trx_cmd);
1840 install_node(&trx_node, dummy_config_write);
1841 install_default(TRX_NODE);
1842 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte7f597bc2009-06-20 22:36:12 +02001843 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001844 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1845 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001846 install_element(TRX_NODE, &cfg_trx_rf_locked_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001847
1848 install_element(TRX_NODE, &cfg_ts_cmd);
1849 install_node(&ts_node, dummy_config_write);
1850 install_default(TS_NODE);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001851 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1852 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001853
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +02001854 bsc_vty_init_extra(net);
Harald Welte59b04682009-06-10 05:40:52 +08001855
1856 return 0;
1857}