blob: 39fc4142901a083a23cc898d25c9cb00e0bfbc2a [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 Welte59b04682009-06-10 05:40:52 +080036#include <openbsc/db.h>
Harald Weltee87eb462009-08-07 13:29:14 +020037#include <openbsc/talloc.h>
Harald Welte59b04682009-06-10 05:40:52 +080038
39static struct gsm_network *gsmnet;
40
Harald Weltee87eb462009-08-07 13:29:14 +020041struct cmd_node net_node = {
42 GSMNET_NODE,
43 "%s(network)#",
44 1,
45};
46
Harald Welte59b04682009-06-10 05:40:52 +080047struct cmd_node bts_node = {
48 BTS_NODE,
49 "%s(bts)#",
50 1,
51};
52
53struct cmd_node trx_node = {
54 TRX_NODE,
55 "%s(trx)#",
56 1,
57};
58
59struct cmd_node ts_node = {
60 TS_NODE,
61 "%s(ts)#",
62 1,
63};
64
Harald Welte59b04682009-06-10 05:40:52 +080065static int dummy_config_write(struct vty *v)
66{
67 return CMD_SUCCESS;
68}
69
70static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
71{
72 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
73 nm_opstate_name(nms->operational), nms->administrative,
74 nm_avail_name(nms->availability), VTY_NEWLINE);
75}
76
77static void net_dump_vty(struct vty *vty, struct gsm_network *net)
78{
79 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
80 "and has %u BTS%s", net->country_code, net->network_code,
81 net->num_bts, VTY_NEWLINE);
82 vty_out(vty, " Long network name: '%s'%s",
83 net->name_long, VTY_NEWLINE);
84 vty_out(vty, " Short network name: '%s'%s",
85 net->name_short, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +020086 vty_out(vty, " Authentication policy: %s%s",
87 gsm_auth_policy_name(net->auth_policy), VTY_NEWLINE);
Harald Weltecca253a2009-08-30 15:47:06 +090088 vty_out(vty, " Encryption: A5/%u%s", net->a5_encryption,
89 VTY_NEWLINE);
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +010090 vty_out(vty, " NECI (TCH/H): %u%s", net->neci,
91 VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +080092}
93
94DEFUN(show_net, show_net_cmd, "show network",
95 SHOW_STR "Display information about a GSM NETWORK\n")
96{
97 struct gsm_network *net = gsmnet;
98 net_dump_vty(vty, net);
99
100 return CMD_SUCCESS;
101}
102
103static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
104{
105 struct e1inp_line *line;
106
107 if (!e1l) {
108 vty_out(vty, " None%s", VTY_NEWLINE);
109 return;
110 }
111
112 line = e1l->ts->line;
113
114 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
115 line->num, line->driver->name, e1l->ts->num,
116 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
117 vty_out(vty, " E1 TEI %u, SAPI %u%s",
118 e1l->tei, e1l->sapi, VTY_NEWLINE);
119}
120
121static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
122{
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +0200123 vty_out(vty, "BTS %u is of %s type in band %s, has CI %u LAC %u, "
Harald Welte91afe4c2009-06-20 18:15:19 +0200124 "BSIC %u, TSC %u and %u TRX%s",
125 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +0200126 bts->cell_identity,
Harald Welte91afe4c2009-06-20 18:15:19 +0200127 bts->location_area_code, bts->bsic, bts->tsc,
128 bts->num_trx, VTY_NEWLINE);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200129 if (bts->cell_barred)
130 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800131 if (is_ipaccess_bts(bts))
Harald Welte25572872009-10-20 00:22:00 +0200132 vty_out(vty, " Unit ID: %u/%u/0, OML Stream ID 0x%02x%s",
Harald Welte59b04682009-06-10 05:40:52 +0800133 bts->ip_access.site_id, bts->ip_access.bts_id,
Harald Welte25572872009-10-20 00:22:00 +0200134 bts->oml_tei, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800135 vty_out(vty, " NM State: ");
136 net_dump_nmstate(vty, &bts->nm_state);
137 vty_out(vty, " Site Mgr NM State: ");
138 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
139 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
140 bts->paging.available_slots, VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200141 if (!is_ipaccess_bts(bts)) {
142 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
143 e1isl_dump_vty(vty, bts->oml_link);
144 }
Harald Welte59b04682009-06-10 05:40:52 +0800145 /* FIXME: oml_link, chan_desc */
146}
147
148DEFUN(show_bts, show_bts_cmd, "show bts [number]",
149 SHOW_STR "Display information about a BTS\n"
150 "BTS number")
151{
152 struct gsm_network *net = gsmnet;
153 int bts_nr;
154
155 if (argc != 0) {
156 /* use the BTS number that the user has specified */
157 bts_nr = atoi(argv[0]);
158 if (bts_nr > net->num_bts) {
159 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
160 VTY_NEWLINE);
161 return CMD_WARNING;
162 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200163 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte59b04682009-06-10 05:40:52 +0800164 return CMD_SUCCESS;
165 }
166 /* print all BTS's */
167 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee712a5f2009-06-21 16:17:15 +0200168 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte59b04682009-06-10 05:40:52 +0800169
170 return CMD_SUCCESS;
171}
172
Harald Welte62868882009-08-08 16:12:58 +0200173/* utility functions */
174static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
175 const char *ts, const char *ss)
176{
177 e1_link->e1_nr = atoi(line);
178 e1_link->e1_ts = atoi(ts);
179 if (!strcmp(ss, "full"))
180 e1_link->e1_ts_ss = 255;
181 else
182 e1_link->e1_ts_ss = atoi(ss);
183}
184
185static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
186 const char *prefix)
187{
188 if (!e1_link->e1_ts)
189 return;
190
191 if (e1_link->e1_ts_ss == 255)
192 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
193 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
194 else
195 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
196 prefix, e1_link->e1_nr, e1_link->e1_ts,
197 e1_link->e1_ts_ss, VTY_NEWLINE);
198}
199
200
Harald Welte97ceef92009-08-06 19:06:46 +0200201static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
202{
Harald Welte62868882009-08-08 16:12:58 +0200203 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
204 if (ts->pchan != GSM_PCHAN_NONE)
205 vty_out(vty, " phys_chan_config %s%s",
206 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
207 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte97ceef92009-08-06 19:06:46 +0200208}
209
210static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
211{
212 int i;
213
Harald Weltee87eb462009-08-07 13:29:14 +0200214 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
215 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
216 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200217 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
218 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte97ceef92009-08-06 19:06:46 +0200219
220 for (i = 0; i < TRX_NR_TS; i++)
221 config_write_ts_single(vty, &trx->ts[i]);
222}
223
224static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
225{
226 struct gsm_bts_trx *trx;
227
Harald Weltee87eb462009-08-07 13:29:14 +0200228 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
229 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
230 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
Holger Hans Peter Freyther6d82b7c2009-11-19 16:38:49 +0100231 vty_out(vty, " cell_identity %u%s", bts->cell_identity, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200232 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte97ceef92009-08-06 19:06:46 +0200233 VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200234 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
235 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte (local)cbd46102009-08-13 10:14:26 +0200236 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530237 if (bts->si_common.chan_desc.t3212)
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +0200238 vty_out(vty, " periodic location update %u%s",
Harald Weltea54a2bb2009-12-01 18:04:30 +0530239 bts->si_common.chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte3e774612009-08-10 13:48:16 +0200240 vty_out(vty, " channel allocator %s%s",
241 bts->chan_alloc_reverse ? "descending" : "ascending",
242 VTY_NEWLINE);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200243 if (bts->cell_barred)
244 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200245 if (is_ipaccess_bts(bts)) {
Harald Weltee87eb462009-08-07 13:29:14 +0200246 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Welte3ffe1b32009-08-07 00:25:23 +0200247 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte25572872009-10-20 00:22:00 +0200248 vty_out(vty, " oml ip.access stream_id %u%s", bts->oml_tei, VTY_NEWLINE);
249 } else {
Harald Welte62868882009-08-08 16:12:58 +0200250 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
251 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
252 }
Harald Welte97ceef92009-08-06 19:06:46 +0200253
254 llist_for_each_entry(trx, &bts->trx_list, list)
255 config_write_trx_single(vty, trx);
256}
257
258static int config_write_bts(struct vty *v)
259{
260 struct gsm_bts *bts;
261
262 llist_for_each_entry(bts, &gsmnet->bts_list, list)
263 config_write_bts_single(v, bts);
264
265 return CMD_SUCCESS;
266}
267
Harald Weltee87eb462009-08-07 13:29:14 +0200268static int config_write_net(struct vty *vty)
269{
270 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200271 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200272 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200273 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
274 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200275 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Weltecca253a2009-08-30 15:47:06 +0900276 vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
Holger Hans Peter Freyther6b4f5462009-11-19 16:37:48 +0100277 vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100278 vty_out(vty, " timer t3101 %u%s", gsmnet->T3101, VTY_NEWLINE);
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +0100279 vty_out(vty, " timer t3103 %u%s", gsmnet->T3103, VTY_NEWLINE);
280 vty_out(vty, " timer t3105 %u%s", gsmnet->T3105, VTY_NEWLINE);
281 vty_out(vty, " timer t3107 %u%s", gsmnet->T3107, VTY_NEWLINE);
282 vty_out(vty, " timer t3109 %u%s", gsmnet->T3109, VTY_NEWLINE);
283 vty_out(vty, " timer t3111 %u%s", gsmnet->T3111, VTY_NEWLINE);
284 vty_out(vty, " timer t3113 %u%s", gsmnet->T3113, VTY_NEWLINE);
285 vty_out(vty, " timer t3115 %u%s", gsmnet->T3115, VTY_NEWLINE);
286 vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
287 vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
288 vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200289
290 return CMD_SUCCESS;
291}
Harald Welte97ceef92009-08-06 19:06:46 +0200292
Harald Welte59b04682009-06-10 05:40:52 +0800293static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
294{
295 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
296 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Welte91afe4c2009-06-20 18:15:19 +0200297 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte62868882009-08-08 16:12:58 +0200298 "resulting BS power: %d dBm%s",
Harald Welte91afe4c2009-06-20 18:15:19 +0200299 trx->nominal_power, trx->max_power_red,
Harald Welte62868882009-08-08 16:12:58 +0200300 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800301 vty_out(vty, " NM State: ");
302 net_dump_nmstate(vty, &trx->nm_state);
303 vty_out(vty, " Baseband Transceiver NM State: ");
304 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
Harald Welte25572872009-10-20 00:22:00 +0200305 if (is_ipaccess_bts(trx->bts)) {
306 vty_out(vty, " ip.access stream ID: 0x%02x%s",
307 trx->rsl_tei, VTY_NEWLINE);
308 } else {
309 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
310 e1isl_dump_vty(vty, trx->rsl_link);
311 }
Harald Welte59b04682009-06-10 05:40:52 +0800312}
313
314DEFUN(show_trx,
315 show_trx_cmd,
316 "show trx [bts_nr] [trx_nr]",
317 SHOW_STR "Display information about a TRX\n")
318{
319 struct gsm_network *net = gsmnet;
320 struct gsm_bts *bts = NULL;
321 struct gsm_bts_trx *trx;
322 int bts_nr, trx_nr;
323
324 if (argc >= 1) {
325 /* use the BTS number that the user has specified */
326 bts_nr = atoi(argv[0]);
327 if (bts_nr >= net->num_bts) {
328 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
329 VTY_NEWLINE);
330 return CMD_WARNING;
331 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200332 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800333 }
334 if (argc >= 2) {
335 trx_nr = atoi(argv[1]);
336 if (trx_nr >= bts->num_trx) {
337 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
338 VTY_NEWLINE);
339 return CMD_WARNING;
340 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200341 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800342 trx_dump_vty(vty, trx);
343 return CMD_SUCCESS;
344 }
345 if (bts) {
346 /* print all TRX in this BTS */
347 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200348 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800349 trx_dump_vty(vty, trx);
350 }
351 return CMD_SUCCESS;
352 }
353
354 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200355 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800356 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200357 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800358 trx_dump_vty(vty, trx);
359 }
360 }
361
362 return CMD_SUCCESS;
363}
364
Harald Welte97ceef92009-08-06 19:06:46 +0200365
Harald Welte59b04682009-06-10 05:40:52 +0800366static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
367{
Harald Welte59b04682009-06-10 05:40:52 +0800368 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
369 ts->nr, ts->trx->nr, ts->trx->bts->nr,
370 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
371 vty_out(vty, " NM State: ");
372 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte87504212009-12-02 01:56:49 +0530373 if (!is_ipaccess_bts(ts->trx->bts))
Harald Welte59b04682009-06-10 05:40:52 +0800374 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
375 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
376 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800377}
378
379DEFUN(show_ts,
380 show_ts_cmd,
381 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
382 SHOW_STR "Display information about a TS\n")
383{
384 struct gsm_network *net = gsmnet;
385 struct gsm_bts *bts;
386 struct gsm_bts_trx *trx;
387 struct gsm_bts_trx_ts *ts;
388 int bts_nr, trx_nr, ts_nr;
389
390 if (argc >= 1) {
391 /* use the BTS number that the user has specified */
392 bts_nr = atoi(argv[0]);
393 if (bts_nr >= net->num_bts) {
394 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
395 VTY_NEWLINE);
396 return CMD_WARNING;
397 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200398 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800399 }
400 if (argc >= 2) {
401 trx_nr = atoi(argv[1]);
402 if (trx_nr >= bts->num_trx) {
403 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
404 VTY_NEWLINE);
405 return CMD_WARNING;
406 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200407 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800408 }
409 if (argc >= 3) {
410 ts_nr = atoi(argv[2]);
411 if (ts_nr >= TRX_NR_TS) {
412 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
413 VTY_NEWLINE);
414 return CMD_WARNING;
415 }
416 ts = &trx->ts[ts_nr];
417 ts_dump_vty(vty, ts);
418 return CMD_SUCCESS;
419 }
420 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200421 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800422 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200423 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800424 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
425 ts = &trx->ts[ts_nr];
426 ts_dump_vty(vty, ts);
427 }
428 }
429 }
430
431 return CMD_SUCCESS;
432}
433
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +0200434void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte59b04682009-06-10 05:40:52 +0800435{
Harald Welte91afe4c2009-06-20 18:15:19 +0200436 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte59b04682009-06-10 05:40:52 +0800437 subscr->authorized, VTY_NEWLINE);
438 if (subscr->name)
439 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
440 if (subscr->extension)
441 vty_out(vty, " Extension: %s%s", subscr->extension,
442 VTY_NEWLINE);
443 if (subscr->imsi)
444 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200445 if (subscr->tmsi != GSM_RESERVED_TMSI)
446 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte270c06c2009-08-15 03:24:51 +0200447 VTY_NEWLINE);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +0200448 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800449}
450
451static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
452{
453 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
454 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
455 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
456 VTY_NEWLINE);
457 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
458 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
459 lchan->ms_power, VTY_NEWLINE);
460 if (lchan->subscr) {
461 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
462 subscr_dump_vty(vty, lchan->subscr);
463 } else
464 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
Harald Welte87504212009-12-02 01:56:49 +0530465 if (is_ipaccess_bts(lchan->ts->trx->bts)) {
466 struct in_addr ia;
467 ia.s_addr = lchan->abis_ip.bound_ip;
468 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
469 inet_ntoa(ia), lchan->abis_ip.bound_port,
470 lchan->abis_ip.rtp_payload2, lchan->abis_ip.conn_id,
471 VTY_NEWLINE);
472 }
Harald Welte59b04682009-06-10 05:40:52 +0800473}
474
Harald Welte03740842009-06-10 23:11:52 +0800475#if 0
476TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte59b04682009-06-10 05:40:52 +0800477static void call_dump_vty(struct vty *vty, struct gsm_call *call)
478{
479 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
480 call->type, call->state, call->transaction_id, VTY_NEWLINE);
481
482 if (call->local_lchan) {
483 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
484 lchan_dump_vty(vty, call->local_lchan);
485 } else
486 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
487
488 if (call->remote_lchan) {
489 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
490 lchan_dump_vty(vty, call->remote_lchan);
491 } else
492 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
493
494 if (call->called_subscr) {
495 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
496 subscr_dump_vty(vty, call->called_subscr);
497 } else
498 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
499}
Harald Welte03740842009-06-10 23:11:52 +0800500#endif
Harald Welte59b04682009-06-10 05:40:52 +0800501
502DEFUN(show_lchan,
503 show_lchan_cmd,
504 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
505 SHOW_STR "Display information about a logical channel\n")
506{
507 struct gsm_network *net = gsmnet;
508 struct gsm_bts *bts;
509 struct gsm_bts_trx *trx;
510 struct gsm_bts_trx_ts *ts;
511 struct gsm_lchan *lchan;
512 int bts_nr, trx_nr, ts_nr, lchan_nr;
513
514 if (argc >= 1) {
515 /* use the BTS number that the user has specified */
516 bts_nr = atoi(argv[0]);
517 if (bts_nr >= net->num_bts) {
518 vty_out(vty, "%% can't find BTS %s%s", argv[0],
519 VTY_NEWLINE);
520 return CMD_WARNING;
521 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200522 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800523 }
524 if (argc >= 2) {
525 trx_nr = atoi(argv[1]);
526 if (trx_nr >= bts->num_trx) {
527 vty_out(vty, "%% can't find TRX %s%s", argv[1],
528 VTY_NEWLINE);
529 return CMD_WARNING;
530 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200531 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800532 }
533 if (argc >= 3) {
534 ts_nr = atoi(argv[2]);
535 if (ts_nr >= TRX_NR_TS) {
536 vty_out(vty, "%% can't find TS %s%s", argv[2],
537 VTY_NEWLINE);
538 return CMD_WARNING;
539 }
540 ts = &trx->ts[ts_nr];
541 }
542 if (argc >= 4) {
543 lchan_nr = atoi(argv[3]);
544 if (lchan_nr >= TS_MAX_LCHAN) {
545 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
546 VTY_NEWLINE);
547 return CMD_WARNING;
548 }
549 lchan = &ts->lchan[lchan_nr];
550 lchan_dump_vty(vty, lchan);
551 return CMD_SUCCESS;
552 }
553 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200554 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800555 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200556 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800557 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
558 ts = &trx->ts[ts_nr];
559 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
560 lchan_nr++) {
561 lchan = &ts->lchan[lchan_nr];
562 if (lchan->type == GSM_LCHAN_NONE)
563 continue;
564 lchan_dump_vty(vty, lchan);
565 }
566 }
567 }
568 }
569
570 return CMD_SUCCESS;
571}
572
573static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
574{
575 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
576}
577
578DEFUN(show_e1drv,
579 show_e1drv_cmd,
580 "show e1_driver",
581 SHOW_STR "Display information about available E1 drivers\n")
582{
583 struct e1inp_driver *drv;
584
585 llist_for_each_entry(drv, &e1inp_driver_list, list)
586 e1drv_dump_vty(vty, drv);
587
588 return CMD_SUCCESS;
589}
590
591static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
592{
593 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
594 line->num, line->name ? line->name : "",
595 line->driver->name, VTY_NEWLINE);
596}
597
598DEFUN(show_e1line,
599 show_e1line_cmd,
600 "show e1_line [line_nr]",
601 SHOW_STR "Display information about a E1 line\n")
602{
603 struct e1inp_line *line;
604
605 if (argc >= 1) {
606 int num = atoi(argv[0]);
607 llist_for_each_entry(line, &e1inp_line_list, list) {
608 if (line->num == num) {
609 e1line_dump_vty(vty, line);
610 return CMD_SUCCESS;
611 }
612 }
613 return CMD_WARNING;
614 }
615
616 llist_for_each_entry(line, &e1inp_line_list, list)
617 e1line_dump_vty(vty, line);
618
619 return CMD_SUCCESS;
620}
621
622static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
623{
Harald Welte62868882009-08-08 16:12:58 +0200624 if (ts->type == E1INP_TS_TYPE_NONE)
625 return;
Harald Welte59b04682009-06-10 05:40:52 +0800626 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
627 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
628 VTY_NEWLINE);
629}
630
631DEFUN(show_e1ts,
632 show_e1ts_cmd,
633 "show e1_timeslot [line_nr] [ts_nr]",
634 SHOW_STR "Display information about a E1 timeslot\n")
635{
Harald Welte49c79562009-11-17 06:12:16 +0100636 struct e1inp_line *line = NULL;
Harald Welte59b04682009-06-10 05:40:52 +0800637 struct e1inp_ts *ts;
638 int ts_nr;
639
640 if (argc == 0) {
641 llist_for_each_entry(line, &e1inp_line_list, list) {
642 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
643 ts = &line->ts[ts_nr];
644 e1ts_dump_vty(vty, ts);
645 }
646 }
647 return CMD_SUCCESS;
648 }
649 if (argc >= 1) {
650 int num = atoi(argv[0]);
651 llist_for_each_entry(line, &e1inp_line_list, list) {
652 if (line->num == num)
653 break;
654 }
655 if (!line || line->num != num) {
656 vty_out(vty, "E1 line %s is invalid%s",
657 argv[0], VTY_NEWLINE);
658 return CMD_WARNING;
659 }
660 }
661 if (argc >= 2) {
662 ts_nr = atoi(argv[1]);
663 if (ts_nr > NUM_E1_TS) {
664 vty_out(vty, "E1 timeslot %s is invalid%s",
665 argv[1], VTY_NEWLINE);
666 return CMD_WARNING;
667 }
668 ts = &line->ts[ts_nr];
669 e1ts_dump_vty(vty, ts);
670 return CMD_SUCCESS;
671 } else {
672 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
673 ts = &line->ts[ts_nr];
674 e1ts_dump_vty(vty, ts);
675 }
676 return CMD_SUCCESS;
677 }
678 return CMD_SUCCESS;
679}
680
681static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
682{
683 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
684 subscr_dump_vty(vty, pag->subscr);
685}
686
687static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
688{
689 struct gsm_paging_request *pag;
690
691 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
692 paging_dump_vty(vty, pag);
693}
694
695DEFUN(show_paging,
696 show_paging_cmd,
697 "show paging [bts_nr]",
698 SHOW_STR "Display information about paging reuqests of a BTS\n")
699{
700 struct gsm_network *net = gsmnet;
701 struct gsm_bts *bts;
702 int bts_nr;
703
704 if (argc >= 1) {
705 /* use the BTS number that the user has specified */
706 bts_nr = atoi(argv[0]);
707 if (bts_nr >= net->num_bts) {
708 vty_out(vty, "%% can't find BTS %s%s", argv[0],
709 VTY_NEWLINE);
710 return CMD_WARNING;
711 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200712 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800713 bts_paging_dump_vty(vty, bts);
714
715 return CMD_SUCCESS;
716 }
717 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200718 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800719 bts_paging_dump_vty(vty, bts);
720 }
721
722 return CMD_SUCCESS;
723}
724
Harald Weltee87eb462009-08-07 13:29:14 +0200725DEFUN(cfg_net,
726 cfg_net_cmd,
727 "network",
728 "Configure the GSM network")
729{
730 vty->index = gsmnet;
731 vty->node = GSMNET_NODE;
732
733 return CMD_SUCCESS;
734}
735
736
737DEFUN(cfg_net_ncc,
738 cfg_net_ncc_cmd,
739 "network country code <1-999>",
740 "Set the GSM network country code")
741{
742 gsmnet->country_code = atoi(argv[0]);
743
744 return CMD_SUCCESS;
745}
746
747DEFUN(cfg_net_mnc,
748 cfg_net_mnc_cmd,
749 "mobile network code <1-999>",
750 "Set the GSM mobile network code")
751{
752 gsmnet->network_code = atoi(argv[0]);
753
754 return CMD_SUCCESS;
755}
756
757DEFUN(cfg_net_name_short,
758 cfg_net_name_short_cmd,
759 "short name NAME",
760 "Set the short GSM network name")
761{
762 if (gsmnet->name_short)
763 talloc_free(gsmnet->name_short);
764
765 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
766
767 return CMD_SUCCESS;
768}
769
770DEFUN(cfg_net_name_long,
771 cfg_net_name_long_cmd,
772 "long name NAME",
773 "Set the long GSM network name")
774{
775 if (gsmnet->name_long)
776 talloc_free(gsmnet->name_long);
777
778 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
779
780 return CMD_SUCCESS;
781}
Harald Welte59b04682009-06-10 05:40:52 +0800782
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200783DEFUN(cfg_net_auth_policy,
784 cfg_net_auth_policy_cmd,
785 "auth policy (closed|accept-all|token)",
786 "Set the GSM network authentication policy\n")
787{
788 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
789
790 gsmnet->auth_policy = policy;
791
792 return CMD_SUCCESS;
793}
794
Harald Weltecca253a2009-08-30 15:47:06 +0900795DEFUN(cfg_net_encryption,
796 cfg_net_encryption_cmd,
797 "encryption a5 (0|1|2)",
798 "Enable or disable encryption (A5) for this network\n")
799{
Andreas.Eversberg53293292009-11-17 09:55:26 +0100800 gsmnet->a5_encryption= atoi(argv[0]);
Harald Weltecca253a2009-08-30 15:47:06 +0900801
802 return CMD_SUCCESS;
803}
804
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +0100805DEFUN(cfg_net_neci,
806 cfg_net_neci_cmd,
807 "neci (0|1)",
808 "Set if NECI of cell selection is to be set")
809{
810 gsmnet->neci = atoi(argv[0]);
811 return CMD_SUCCESS;
812}
813
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100814#define DECLARE_TIMER(number) \
815 DEFUN(cfg_net_T##number, \
816 cfg_net_T##number##_cmd, \
817 "timer t" #number " <0-65535>", \
818 "Set the T" #number " value.") \
819{ \
820 int value = atoi(argv[0]); \
821 \
822 if (value < 0 || value > 65535) { \
823 vty_out(vty, "Timer value %s out of range.%s", \
824 argv[0], VTY_NEWLINE); \
825 return CMD_WARNING; \
826 } \
827 \
828 gsmnet->T##number = value; \
829 return CMD_SUCCESS; \
830}
831
832DECLARE_TIMER(3101)
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +0100833DECLARE_TIMER(3103)
834DECLARE_TIMER(3105)
835DECLARE_TIMER(3107)
836DECLARE_TIMER(3109)
837DECLARE_TIMER(3111)
838DECLARE_TIMER(3113)
839DECLARE_TIMER(3115)
840DECLARE_TIMER(3117)
841DECLARE_TIMER(3119)
842DECLARE_TIMER(3141)
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100843
844
Harald Welte59b04682009-06-10 05:40:52 +0800845/* per-BTS configuration */
846DEFUN(cfg_bts,
847 cfg_bts_cmd,
848 "bts BTS_NR",
849 "Select a BTS to configure\n")
850{
851 int bts_nr = atoi(argv[0]);
852 struct gsm_bts *bts;
853
Harald Weltee712a5f2009-06-21 16:17:15 +0200854 if (bts_nr > gsmnet->num_bts) {
855 vty_out(vty, "%% The next unused BTS number is %u%s",
856 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800857 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +0200858 } else if (bts_nr == gsmnet->num_bts) {
859 /* allocate a new one */
860 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
861 HARDCODED_TSC, HARDCODED_BSIC);
862 } else
863 bts = gsm_bts_num(gsmnet, bts_nr);
864
865 if (!bts)
866 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +0800867
868 vty->index = bts;
869 vty->node = BTS_NODE;
870
871 return CMD_SUCCESS;
872}
873
874DEFUN(cfg_bts_type,
875 cfg_bts_type_cmd,
876 "type TYPE",
877 "Set the BTS type\n")
878{
879 struct gsm_bts *bts = vty->index;
880
Harald Welte3ffe1b32009-08-07 00:25:23 +0200881 bts->type = parse_btstype(argv[0]);
882
Harald Welte25572872009-10-20 00:22:00 +0200883 if (is_ipaccess_bts(bts)) {
884 /* Set the default OML Stream ID to 0xff */
885 bts->oml_tei = 0xff;
886 }
887
Harald Welte59b04682009-06-10 05:40:52 +0800888 return CMD_SUCCESS;
889}
890
Harald Welte91afe4c2009-06-20 18:15:19 +0200891DEFUN(cfg_bts_band,
892 cfg_bts_band_cmd,
893 "band BAND",
894 "Set the frequency band of this BTS\n")
895{
896 struct gsm_bts *bts = vty->index;
Harald Welte62868882009-08-08 16:12:58 +0200897 int band = gsm_band_parse(argv[0]);
Harald Welte91afe4c2009-06-20 18:15:19 +0200898
899 if (band < 0) {
900 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
901 band, VTY_NEWLINE);
902 return CMD_WARNING;
903 }
904
905 bts->band = band;
906
907 return CMD_SUCCESS;
908}
909
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +0200910DEFUN(cfg_bts_ci,
911 cfg_bts_ci_cmd,
912 "cell_identity <0-65535>",
913 "Set the Cell identity of this BTS\n")
914{
915 struct gsm_bts *bts = vty->index;
916 int ci = atoi(argv[0]);
917
918 if (ci < 0 || ci > 0xffff) {
919 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
920 ci, VTY_NEWLINE);
921 return CMD_WARNING;
922 }
923 bts->cell_identity = ci;
924
925 return CMD_SUCCESS;
926}
927
Harald Welte59b04682009-06-10 05:40:52 +0800928DEFUN(cfg_bts_lac,
929 cfg_bts_lac_cmd,
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +0200930 "location_area_code <0-65535>",
Harald Welte59b04682009-06-10 05:40:52 +0800931 "Set the Location Area Code (LAC) of this BTS\n")
932{
933 struct gsm_bts *bts = vty->index;
934 int lac = atoi(argv[0]);
935
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +0200936 if (lac < 0 || lac > 0xffff) {
937 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte59b04682009-06-10 05:40:52 +0800938 lac, VTY_NEWLINE);
939 return CMD_WARNING;
940 }
Holger Hans Peter Freyther6c6ab862009-10-01 04:07:15 +0200941
942 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
943 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
944 lac, VTY_NEWLINE);
945 return CMD_WARNING;
946 }
947
Harald Welte59b04682009-06-10 05:40:52 +0800948 bts->location_area_code = lac;
949
950 return CMD_SUCCESS;
951}
952
Harald Weltea54a2bb2009-12-01 18:04:30 +0530953
Harald Welte59b04682009-06-10 05:40:52 +0800954DEFUN(cfg_bts_tsc,
955 cfg_bts_tsc_cmd,
956 "training_sequence_code <0-255>",
957 "Set the Training Sequence Code (TSC) of this BTS\n")
958{
959 struct gsm_bts *bts = vty->index;
960 int tsc = atoi(argv[0]);
961
962 if (tsc < 0 || tsc > 0xff) {
963 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
964 tsc, VTY_NEWLINE);
965 return CMD_WARNING;
966 }
967 bts->tsc = tsc;
968
969 return CMD_SUCCESS;
970}
971
972DEFUN(cfg_bts_bsic,
973 cfg_bts_bsic_cmd,
974 "base_station_id_code <0-63>",
975 "Set the Base Station Identity Code (BSIC) of this BTS\n")
976{
977 struct gsm_bts *bts = vty->index;
978 int bsic = atoi(argv[0]);
979
980 if (bsic < 0 || bsic > 0x3f) {
Harald Welte62868882009-08-08 16:12:58 +0200981 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte59b04682009-06-10 05:40:52 +0800982 bsic, VTY_NEWLINE);
983 return CMD_WARNING;
984 }
985 bts->bsic = bsic;
986
987 return CMD_SUCCESS;
988}
989
990
991DEFUN(cfg_bts_unit_id,
992 cfg_bts_unit_id_cmd,
Harald Weltef515aa02009-08-07 13:27:09 +0200993 "ip.access unit_id <0-65534> <0-255>",
994 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte59b04682009-06-10 05:40:52 +0800995{
996 struct gsm_bts *bts = vty->index;
997 int site_id = atoi(argv[0]);
998 int bts_id = atoi(argv[1]);
999
Harald Weltef515aa02009-08-07 13:27:09 +02001000 if (!is_ipaccess_bts(bts)) {
1001 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1002 return CMD_WARNING;
1003 }
1004
Harald Welte59b04682009-06-10 05:40:52 +08001005 bts->ip_access.site_id = site_id;
1006 bts->ip_access.bts_id = bts_id;
1007
1008 return CMD_SUCCESS;
1009}
1010
Harald Welte25572872009-10-20 00:22:00 +02001011DEFUN(cfg_bts_stream_id,
1012 cfg_bts_stream_id_cmd,
1013 "oml ip.access stream_id <0-255>",
1014 "Set the ip.access Stream ID of the OML link of this BTS\n")
1015{
1016 struct gsm_bts *bts = vty->index;
1017 int stream_id = atoi(argv[0]);
1018
1019 if (!is_ipaccess_bts(bts)) {
1020 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1021 return CMD_WARNING;
1022 }
1023
1024 bts->oml_tei = stream_id;
1025
1026 return CMD_SUCCESS;
1027}
1028
1029
Harald Welte62868882009-08-08 16:12:58 +02001030DEFUN(cfg_bts_oml_e1,
1031 cfg_bts_oml_e1_cmd,
1032 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1033 "E1 interface to be used for OML\n")
1034{
1035 struct gsm_bts *bts = vty->index;
1036
1037 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
1038
1039 return CMD_SUCCESS;
1040}
1041
1042
1043DEFUN(cfg_bts_oml_e1_tei,
1044 cfg_bts_oml_e1_tei_cmd,
1045 "oml e1 tei <0-63>",
1046 "Set the TEI to be used for OML")
1047{
1048 struct gsm_bts *bts = vty->index;
1049
1050 bts->oml_tei = atoi(argv[0]);
1051
1052 return CMD_SUCCESS;
1053}
1054
Harald Welte3e774612009-08-10 13:48:16 +02001055DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1056 "channel allocator (ascending|descending)",
1057 "Should the channel allocator allocate in reverse TRX order?")
1058{
1059 struct gsm_bts *bts = vty->index;
1060
1061 if (!strcmp(argv[0], "ascending"))
1062 bts->chan_alloc_reverse = 0;
1063 else
1064 bts->chan_alloc_reverse = 1;
1065
1066 return CMD_SUCCESS;
1067}
1068
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001069DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1070 "cell barred (0|1)",
1071 "Should this cell be barred from access?")
1072{
1073 struct gsm_bts *bts = vty->index;
1074
1075 bts->cell_barred = atoi(argv[0]);
1076
1077 return CMD_SUCCESS;
1078}
1079
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001080DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1081 "ms max power <0-40>",
1082 "Maximum transmit power of the MS")
1083{
1084 struct gsm_bts *bts = vty->index;
1085
1086 bts->ms_max_power = atoi(argv[0]);
1087
1088 return CMD_SUCCESS;
1089}
1090
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001091DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1092 "periodic location update <0-1530>",
1093 "Periodic Location Updating Interval in Minutes")
1094{
1095 struct gsm_bts *bts = vty->index;
1096
Harald Weltea54a2bb2009-12-01 18:04:30 +05301097 bts->si_common.chan_desc.t3212 = atoi(argv[0]) / 10;
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001098
1099 return CMD_SUCCESS;
1100}
1101
Harald Welte3e774612009-08-10 13:48:16 +02001102
Harald Welte59b04682009-06-10 05:40:52 +08001103/* per TRX configuration */
1104DEFUN(cfg_trx,
1105 cfg_trx_cmd,
1106 "trx TRX_NR",
1107 "Select a TRX to configure")
1108{
1109 int trx_nr = atoi(argv[0]);
1110 struct gsm_bts *bts = vty->index;
1111 struct gsm_bts_trx *trx;
1112
Harald Weltee712a5f2009-06-21 16:17:15 +02001113 if (trx_nr > bts->num_trx) {
1114 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1115 bts->num_trx, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001116 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001117 } else if (trx_nr == bts->num_trx) {
1118 /* we need to allocate a new one */
1119 trx = gsm_bts_trx_alloc(bts);
1120 } else
1121 trx = gsm_bts_trx_num(bts, trx_nr);
1122
1123 if (!trx)
1124 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001125
1126 vty->index = trx;
1127 vty->node = TRX_NODE;
1128
1129 return CMD_SUCCESS;
1130}
1131
1132DEFUN(cfg_trx_arfcn,
1133 cfg_trx_arfcn_cmd,
1134 "arfcn <1-1024>",
1135 "Set the ARFCN for this TRX\n")
1136{
1137 int arfcn = atoi(argv[0]);
1138 struct gsm_bts_trx *trx = vty->index;
1139
1140 /* FIXME: check if this ARFCN is supported by this TRX */
1141
1142 trx->arfcn = arfcn;
1143
1144 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1145 /* FIXME: use OML layer to update the ARFCN */
1146 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1147
1148 return CMD_SUCCESS;
1149}
1150
Harald Welte91afe4c2009-06-20 18:15:19 +02001151DEFUN(cfg_trx_max_power_red,
1152 cfg_trx_max_power_red_cmd,
1153 "max_power_red <0-100>",
1154 "Reduction of maximum BS RF Power in dB\n")
1155{
1156 int maxpwr_r = atoi(argv[0]);
1157 struct gsm_bts_trx *trx = vty->index;
Harald Welte01acd742009-11-18 09:20:22 +01001158 int upper_limit = 24; /* default 12.21 max power red. */
Harald Welte91afe4c2009-06-20 18:15:19 +02001159
1160 /* FIXME: check if our BTS type supports more than 12 */
1161 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1162 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1163 maxpwr_r, VTY_NEWLINE);
1164 return CMD_WARNING;
1165 }
1166 if (maxpwr_r & 1) {
1167 vty_out(vty, "%% Power %d dB is not an even value%s",
1168 maxpwr_r, VTY_NEWLINE);
1169 return CMD_WARNING;
1170 }
1171
1172 trx->max_power_red = maxpwr_r;
1173
1174 /* FIXME: make sure we update this using OML */
1175
1176 return CMD_SUCCESS;
1177}
1178
Harald Welte62868882009-08-08 16:12:58 +02001179DEFUN(cfg_trx_rsl_e1,
1180 cfg_trx_rsl_e1_cmd,
1181 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1182 "E1 interface to be used for RSL\n")
1183{
1184 struct gsm_bts_trx *trx = vty->index;
1185
1186 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1187
1188 return CMD_SUCCESS;
1189}
1190
1191DEFUN(cfg_trx_rsl_e1_tei,
1192 cfg_trx_rsl_e1_tei_cmd,
1193 "rsl e1 tei <0-63>",
1194 "Set the TEI to be used for RSL")
1195{
1196 struct gsm_bts_trx *trx = vty->index;
1197
1198 trx->rsl_tei = atoi(argv[0]);
1199
1200 return CMD_SUCCESS;
1201}
1202
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001203DEFUN(cfg_trx_rf_locked,
1204 cfg_trx_rf_locked_cmd,
1205 "rf_locked (0|1)",
1206 "Turn off RF of the TRX.\n")
1207{
1208 int locked = atoi(argv[0]);
1209 struct gsm_bts_trx *trx = vty->index;
1210
1211 gsm_trx_lock_rf(trx, locked);
1212 return CMD_SUCCESS;
1213}
Harald Welte62868882009-08-08 16:12:58 +02001214
Harald Welte59b04682009-06-10 05:40:52 +08001215/* per TS configuration */
1216DEFUN(cfg_ts,
1217 cfg_ts_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001218 "timeslot <0-7>",
Harald Welte59b04682009-06-10 05:40:52 +08001219 "Select a Timeslot to configure")
1220{
1221 int ts_nr = atoi(argv[0]);
1222 struct gsm_bts_trx *trx = vty->index;
1223 struct gsm_bts_trx_ts *ts;
1224
1225 if (ts_nr >= TRX_NR_TS) {
1226 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1227 TRX_NR_TS, VTY_NEWLINE);
1228 return CMD_WARNING;
1229 }
1230
1231 ts = &trx->ts[ts_nr];
1232
1233 vty->index = ts;
1234 vty->node = TS_NODE;
1235
1236 return CMD_SUCCESS;
1237}
1238
Harald Welte3ffe1b32009-08-07 00:25:23 +02001239DEFUN(cfg_ts_pchan,
1240 cfg_ts_pchan_cmd,
1241 "phys_chan_config PCHAN",
1242 "Physical Channel configuration (TCH/SDCCH/...)")
1243{
1244 struct gsm_bts_trx_ts *ts = vty->index;
1245 int pchanc;
1246
1247 pchanc = gsm_pchan_parse(argv[0]);
1248 if (pchanc < 0)
1249 return CMD_WARNING;
1250
1251 ts->pchan = pchanc;
1252
1253 return CMD_SUCCESS;
1254}
1255
1256DEFUN(cfg_ts_e1_subslot,
1257 cfg_ts_e1_subslot_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001258 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Welte3ffe1b32009-08-07 00:25:23 +02001259 "E1 sub-slot connected to this on-air timeslot")
1260{
1261 struct gsm_bts_trx_ts *ts = vty->index;
1262
Harald Welte62868882009-08-08 16:12:58 +02001263 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001264
1265 return CMD_SUCCESS;
1266}
Harald Welte59b04682009-06-10 05:40:52 +08001267
Harald Welte59b04682009-06-10 05:40:52 +08001268int bsc_vty_init(struct gsm_network *net)
1269{
1270 gsmnet = net;
1271
1272 cmd_init(1);
1273 vty_init();
1274
1275 install_element(VIEW_NODE, &show_net_cmd);
1276 install_element(VIEW_NODE, &show_bts_cmd);
1277 install_element(VIEW_NODE, &show_trx_cmd);
1278 install_element(VIEW_NODE, &show_ts_cmd);
1279 install_element(VIEW_NODE, &show_lchan_cmd);
1280
1281 install_element(VIEW_NODE, &show_e1drv_cmd);
1282 install_element(VIEW_NODE, &show_e1line_cmd);
1283 install_element(VIEW_NODE, &show_e1ts_cmd);
1284
1285 install_element(VIEW_NODE, &show_paging_cmd);
1286
Harald Weltee87eb462009-08-07 13:29:14 +02001287 install_element(CONFIG_NODE, &cfg_net_cmd);
1288 install_node(&net_node, config_write_net);
1289 install_default(GSMNET_NODE);
Harald Welte62868882009-08-08 16:12:58 +02001290 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001291 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1292 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1293 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001294 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Weltecca253a2009-08-30 15:47:06 +09001295 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001296 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001297 install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +01001298 install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
1299 install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
1300 install_element(GSMNET_NODE, &cfg_net_T3107_cmd);
1301 install_element(GSMNET_NODE, &cfg_net_T3109_cmd);
1302 install_element(GSMNET_NODE, &cfg_net_T3111_cmd);
1303 install_element(GSMNET_NODE, &cfg_net_T3113_cmd);
1304 install_element(GSMNET_NODE, &cfg_net_T3115_cmd);
1305 install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
1306 install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
1307 install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001308
1309 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte97ceef92009-08-06 19:06:46 +02001310 install_node(&bts_node, config_write_bts);
Harald Welte59b04682009-06-10 05:40:52 +08001311 install_default(BTS_NODE);
1312 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Welte91afe4c2009-06-20 18:15:19 +02001313 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +02001314 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001315 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1316 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001317 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001318 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte25572872009-10-20 00:22:00 +02001319 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001320 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1321 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001322 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001323 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001324 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001325 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001326
Harald Welte59b04682009-06-10 05:40:52 +08001327
1328 install_element(BTS_NODE, &cfg_trx_cmd);
1329 install_node(&trx_node, dummy_config_write);
1330 install_default(TRX_NODE);
1331 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte7f597bc2009-06-20 22:36:12 +02001332 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001333 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1334 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001335 install_element(TRX_NODE, &cfg_trx_rf_locked_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001336
1337 install_element(TRX_NODE, &cfg_ts_cmd);
1338 install_node(&ts_node, dummy_config_write);
1339 install_default(TS_NODE);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001340 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1341 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001342
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +02001343 bsc_vty_init_extra(net);
Harald Welte59b04682009-06-10 05:40:52 +08001344
1345 return 0;
1346}