blob: 3b150b2eab1032563d2063a7cdae92e73a0dd031 [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{
368 struct in_addr ia;
369
370 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
371 ts->nr, ts->trx->nr, ts->trx->bts->nr,
372 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
373 vty_out(vty, " NM State: ");
374 net_dump_nmstate(vty, &ts->nm_state);
375 if (is_ipaccess_bts(ts->trx->bts)) {
376 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte8cdeaad2009-07-12 09:50:35 +0200377 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte59b04682009-06-10 05:40:52 +0800378 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte8cdeaad2009-07-12 09:50:35 +0200379 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte59b04682009-06-10 05:40:52 +0800380 VTY_NEWLINE);
381 } else {
382 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
383 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
384 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
385 }
386}
387
388DEFUN(show_ts,
389 show_ts_cmd,
390 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
391 SHOW_STR "Display information about a TS\n")
392{
393 struct gsm_network *net = gsmnet;
394 struct gsm_bts *bts;
395 struct gsm_bts_trx *trx;
396 struct gsm_bts_trx_ts *ts;
397 int bts_nr, trx_nr, ts_nr;
398
399 if (argc >= 1) {
400 /* use the BTS number that the user has specified */
401 bts_nr = atoi(argv[0]);
402 if (bts_nr >= net->num_bts) {
403 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
404 VTY_NEWLINE);
405 return CMD_WARNING;
406 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200407 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800408 }
409 if (argc >= 2) {
410 trx_nr = atoi(argv[1]);
411 if (trx_nr >= bts->num_trx) {
412 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
413 VTY_NEWLINE);
414 return CMD_WARNING;
415 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200416 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800417 }
418 if (argc >= 3) {
419 ts_nr = atoi(argv[2]);
420 if (ts_nr >= TRX_NR_TS) {
421 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
422 VTY_NEWLINE);
423 return CMD_WARNING;
424 }
425 ts = &trx->ts[ts_nr];
426 ts_dump_vty(vty, ts);
427 return CMD_SUCCESS;
428 }
429 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200430 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800431 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200432 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800433 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
434 ts = &trx->ts[ts_nr];
435 ts_dump_vty(vty, ts);
436 }
437 }
438 }
439
440 return CMD_SUCCESS;
441}
442
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +0200443void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte59b04682009-06-10 05:40:52 +0800444{
Harald Welte91afe4c2009-06-20 18:15:19 +0200445 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte59b04682009-06-10 05:40:52 +0800446 subscr->authorized, VTY_NEWLINE);
447 if (subscr->name)
448 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
449 if (subscr->extension)
450 vty_out(vty, " Extension: %s%s", subscr->extension,
451 VTY_NEWLINE);
452 if (subscr->imsi)
453 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200454 if (subscr->tmsi != GSM_RESERVED_TMSI)
455 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte270c06c2009-08-15 03:24:51 +0200456 VTY_NEWLINE);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +0200457 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800458}
459
460static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
461{
462 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
463 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
464 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
465 VTY_NEWLINE);
466 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
467 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
468 lchan->ms_power, VTY_NEWLINE);
469 if (lchan->subscr) {
470 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
471 subscr_dump_vty(vty, lchan->subscr);
472 } else
473 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
474}
475
Harald Welte03740842009-06-10 23:11:52 +0800476#if 0
477TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte59b04682009-06-10 05:40:52 +0800478static void call_dump_vty(struct vty *vty, struct gsm_call *call)
479{
480 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
481 call->type, call->state, call->transaction_id, VTY_NEWLINE);
482
483 if (call->local_lchan) {
484 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
485 lchan_dump_vty(vty, call->local_lchan);
486 } else
487 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
488
489 if (call->remote_lchan) {
490 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
491 lchan_dump_vty(vty, call->remote_lchan);
492 } else
493 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
494
495 if (call->called_subscr) {
496 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
497 subscr_dump_vty(vty, call->called_subscr);
498 } else
499 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
500}
Harald Welte03740842009-06-10 23:11:52 +0800501#endif
Harald Welte59b04682009-06-10 05:40:52 +0800502
503DEFUN(show_lchan,
504 show_lchan_cmd,
505 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
506 SHOW_STR "Display information about a logical channel\n")
507{
508 struct gsm_network *net = gsmnet;
509 struct gsm_bts *bts;
510 struct gsm_bts_trx *trx;
511 struct gsm_bts_trx_ts *ts;
512 struct gsm_lchan *lchan;
513 int bts_nr, trx_nr, ts_nr, lchan_nr;
514
515 if (argc >= 1) {
516 /* use the BTS number that the user has specified */
517 bts_nr = atoi(argv[0]);
518 if (bts_nr >= net->num_bts) {
519 vty_out(vty, "%% can't find BTS %s%s", argv[0],
520 VTY_NEWLINE);
521 return CMD_WARNING;
522 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200523 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800524 }
525 if (argc >= 2) {
526 trx_nr = atoi(argv[1]);
527 if (trx_nr >= bts->num_trx) {
528 vty_out(vty, "%% can't find TRX %s%s", argv[1],
529 VTY_NEWLINE);
530 return CMD_WARNING;
531 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200532 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800533 }
534 if (argc >= 3) {
535 ts_nr = atoi(argv[2]);
536 if (ts_nr >= TRX_NR_TS) {
537 vty_out(vty, "%% can't find TS %s%s", argv[2],
538 VTY_NEWLINE);
539 return CMD_WARNING;
540 }
541 ts = &trx->ts[ts_nr];
542 }
543 if (argc >= 4) {
544 lchan_nr = atoi(argv[3]);
545 if (lchan_nr >= TS_MAX_LCHAN) {
546 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
547 VTY_NEWLINE);
548 return CMD_WARNING;
549 }
550 lchan = &ts->lchan[lchan_nr];
551 lchan_dump_vty(vty, lchan);
552 return CMD_SUCCESS;
553 }
554 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200555 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800556 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200557 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800558 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
559 ts = &trx->ts[ts_nr];
560 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
561 lchan_nr++) {
562 lchan = &ts->lchan[lchan_nr];
563 if (lchan->type == GSM_LCHAN_NONE)
564 continue;
565 lchan_dump_vty(vty, lchan);
566 }
567 }
568 }
569 }
570
571 return CMD_SUCCESS;
572}
573
574static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
575{
576 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
577}
578
579DEFUN(show_e1drv,
580 show_e1drv_cmd,
581 "show e1_driver",
582 SHOW_STR "Display information about available E1 drivers\n")
583{
584 struct e1inp_driver *drv;
585
586 llist_for_each_entry(drv, &e1inp_driver_list, list)
587 e1drv_dump_vty(vty, drv);
588
589 return CMD_SUCCESS;
590}
591
592static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
593{
594 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
595 line->num, line->name ? line->name : "",
596 line->driver->name, VTY_NEWLINE);
597}
598
599DEFUN(show_e1line,
600 show_e1line_cmd,
601 "show e1_line [line_nr]",
602 SHOW_STR "Display information about a E1 line\n")
603{
604 struct e1inp_line *line;
605
606 if (argc >= 1) {
607 int num = atoi(argv[0]);
608 llist_for_each_entry(line, &e1inp_line_list, list) {
609 if (line->num == num) {
610 e1line_dump_vty(vty, line);
611 return CMD_SUCCESS;
612 }
613 }
614 return CMD_WARNING;
615 }
616
617 llist_for_each_entry(line, &e1inp_line_list, list)
618 e1line_dump_vty(vty, line);
619
620 return CMD_SUCCESS;
621}
622
623static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
624{
Harald Welte62868882009-08-08 16:12:58 +0200625 if (ts->type == E1INP_TS_TYPE_NONE)
626 return;
Harald Welte59b04682009-06-10 05:40:52 +0800627 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
628 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
629 VTY_NEWLINE);
630}
631
632DEFUN(show_e1ts,
633 show_e1ts_cmd,
634 "show e1_timeslot [line_nr] [ts_nr]",
635 SHOW_STR "Display information about a E1 timeslot\n")
636{
Harald Welte49c79562009-11-17 06:12:16 +0100637 struct e1inp_line *line = NULL;
Harald Welte59b04682009-06-10 05:40:52 +0800638 struct e1inp_ts *ts;
639 int ts_nr;
640
641 if (argc == 0) {
642 llist_for_each_entry(line, &e1inp_line_list, list) {
643 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
644 ts = &line->ts[ts_nr];
645 e1ts_dump_vty(vty, ts);
646 }
647 }
648 return CMD_SUCCESS;
649 }
650 if (argc >= 1) {
651 int num = atoi(argv[0]);
652 llist_for_each_entry(line, &e1inp_line_list, list) {
653 if (line->num == num)
654 break;
655 }
656 if (!line || line->num != num) {
657 vty_out(vty, "E1 line %s is invalid%s",
658 argv[0], VTY_NEWLINE);
659 return CMD_WARNING;
660 }
661 }
662 if (argc >= 2) {
663 ts_nr = atoi(argv[1]);
664 if (ts_nr > NUM_E1_TS) {
665 vty_out(vty, "E1 timeslot %s is invalid%s",
666 argv[1], VTY_NEWLINE);
667 return CMD_WARNING;
668 }
669 ts = &line->ts[ts_nr];
670 e1ts_dump_vty(vty, ts);
671 return CMD_SUCCESS;
672 } else {
673 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
674 ts = &line->ts[ts_nr];
675 e1ts_dump_vty(vty, ts);
676 }
677 return CMD_SUCCESS;
678 }
679 return CMD_SUCCESS;
680}
681
682static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
683{
684 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
685 subscr_dump_vty(vty, pag->subscr);
686}
687
688static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
689{
690 struct gsm_paging_request *pag;
691
692 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
693 paging_dump_vty(vty, pag);
694}
695
696DEFUN(show_paging,
697 show_paging_cmd,
698 "show paging [bts_nr]",
699 SHOW_STR "Display information about paging reuqests of a BTS\n")
700{
701 struct gsm_network *net = gsmnet;
702 struct gsm_bts *bts;
703 int bts_nr;
704
705 if (argc >= 1) {
706 /* use the BTS number that the user has specified */
707 bts_nr = atoi(argv[0]);
708 if (bts_nr >= net->num_bts) {
709 vty_out(vty, "%% can't find BTS %s%s", argv[0],
710 VTY_NEWLINE);
711 return CMD_WARNING;
712 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200713 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800714 bts_paging_dump_vty(vty, bts);
715
716 return CMD_SUCCESS;
717 }
718 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200719 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800720 bts_paging_dump_vty(vty, bts);
721 }
722
723 return CMD_SUCCESS;
724}
725
Harald Weltee87eb462009-08-07 13:29:14 +0200726DEFUN(cfg_net,
727 cfg_net_cmd,
728 "network",
729 "Configure the GSM network")
730{
731 vty->index = gsmnet;
732 vty->node = GSMNET_NODE;
733
734 return CMD_SUCCESS;
735}
736
737
738DEFUN(cfg_net_ncc,
739 cfg_net_ncc_cmd,
740 "network country code <1-999>",
741 "Set the GSM network country code")
742{
743 gsmnet->country_code = atoi(argv[0]);
744
745 return CMD_SUCCESS;
746}
747
748DEFUN(cfg_net_mnc,
749 cfg_net_mnc_cmd,
750 "mobile network code <1-999>",
751 "Set the GSM mobile network code")
752{
753 gsmnet->network_code = atoi(argv[0]);
754
755 return CMD_SUCCESS;
756}
757
758DEFUN(cfg_net_name_short,
759 cfg_net_name_short_cmd,
760 "short name NAME",
761 "Set the short GSM network name")
762{
763 if (gsmnet->name_short)
764 talloc_free(gsmnet->name_short);
765
766 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
767
768 return CMD_SUCCESS;
769}
770
771DEFUN(cfg_net_name_long,
772 cfg_net_name_long_cmd,
773 "long name NAME",
774 "Set the long GSM network name")
775{
776 if (gsmnet->name_long)
777 talloc_free(gsmnet->name_long);
778
779 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
780
781 return CMD_SUCCESS;
782}
Harald Welte59b04682009-06-10 05:40:52 +0800783
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200784DEFUN(cfg_net_auth_policy,
785 cfg_net_auth_policy_cmd,
786 "auth policy (closed|accept-all|token)",
787 "Set the GSM network authentication policy\n")
788{
789 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
790
791 gsmnet->auth_policy = policy;
792
793 return CMD_SUCCESS;
794}
795
Harald Weltecca253a2009-08-30 15:47:06 +0900796DEFUN(cfg_net_encryption,
797 cfg_net_encryption_cmd,
798 "encryption a5 (0|1|2)",
799 "Enable or disable encryption (A5) for this network\n")
800{
Andreas.Eversberg53293292009-11-17 09:55:26 +0100801 gsmnet->a5_encryption= atoi(argv[0]);
Harald Weltecca253a2009-08-30 15:47:06 +0900802
803 return CMD_SUCCESS;
804}
805
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +0100806DEFUN(cfg_net_neci,
807 cfg_net_neci_cmd,
808 "neci (0|1)",
809 "Set if NECI of cell selection is to be set")
810{
811 gsmnet->neci = atoi(argv[0]);
812 return CMD_SUCCESS;
813}
814
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100815#define DECLARE_TIMER(number) \
816 DEFUN(cfg_net_T##number, \
817 cfg_net_T##number##_cmd, \
818 "timer t" #number " <0-65535>", \
819 "Set the T" #number " value.") \
820{ \
821 int value = atoi(argv[0]); \
822 \
823 if (value < 0 || value > 65535) { \
824 vty_out(vty, "Timer value %s out of range.%s", \
825 argv[0], VTY_NEWLINE); \
826 return CMD_WARNING; \
827 } \
828 \
829 gsmnet->T##number = value; \
830 return CMD_SUCCESS; \
831}
832
833DECLARE_TIMER(3101)
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +0100834DECLARE_TIMER(3103)
835DECLARE_TIMER(3105)
836DECLARE_TIMER(3107)
837DECLARE_TIMER(3109)
838DECLARE_TIMER(3111)
839DECLARE_TIMER(3113)
840DECLARE_TIMER(3115)
841DECLARE_TIMER(3117)
842DECLARE_TIMER(3119)
843DECLARE_TIMER(3141)
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100844
845
Harald Welte59b04682009-06-10 05:40:52 +0800846/* per-BTS configuration */
847DEFUN(cfg_bts,
848 cfg_bts_cmd,
849 "bts BTS_NR",
850 "Select a BTS to configure\n")
851{
852 int bts_nr = atoi(argv[0]);
853 struct gsm_bts *bts;
854
Harald Weltee712a5f2009-06-21 16:17:15 +0200855 if (bts_nr > gsmnet->num_bts) {
856 vty_out(vty, "%% The next unused BTS number is %u%s",
857 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800858 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +0200859 } else if (bts_nr == gsmnet->num_bts) {
860 /* allocate a new one */
861 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
862 HARDCODED_TSC, HARDCODED_BSIC);
863 } else
864 bts = gsm_bts_num(gsmnet, bts_nr);
865
866 if (!bts)
867 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +0800868
869 vty->index = bts;
870 vty->node = BTS_NODE;
871
872 return CMD_SUCCESS;
873}
874
875DEFUN(cfg_bts_type,
876 cfg_bts_type_cmd,
877 "type TYPE",
878 "Set the BTS type\n")
879{
880 struct gsm_bts *bts = vty->index;
881
Harald Welte3ffe1b32009-08-07 00:25:23 +0200882 bts->type = parse_btstype(argv[0]);
883
Harald Welte25572872009-10-20 00:22:00 +0200884 if (is_ipaccess_bts(bts)) {
885 /* Set the default OML Stream ID to 0xff */
886 bts->oml_tei = 0xff;
887 }
888
Harald Welte59b04682009-06-10 05:40:52 +0800889 return CMD_SUCCESS;
890}
891
Harald Welte91afe4c2009-06-20 18:15:19 +0200892DEFUN(cfg_bts_band,
893 cfg_bts_band_cmd,
894 "band BAND",
895 "Set the frequency band of this BTS\n")
896{
897 struct gsm_bts *bts = vty->index;
Harald Welte62868882009-08-08 16:12:58 +0200898 int band = gsm_band_parse(argv[0]);
Harald Welte91afe4c2009-06-20 18:15:19 +0200899
900 if (band < 0) {
901 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
902 band, VTY_NEWLINE);
903 return CMD_WARNING;
904 }
905
906 bts->band = band;
907
908 return CMD_SUCCESS;
909}
910
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +0200911DEFUN(cfg_bts_ci,
912 cfg_bts_ci_cmd,
913 "cell_identity <0-65535>",
914 "Set the Cell identity of this BTS\n")
915{
916 struct gsm_bts *bts = vty->index;
917 int ci = atoi(argv[0]);
918
919 if (ci < 0 || ci > 0xffff) {
920 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
921 ci, VTY_NEWLINE);
922 return CMD_WARNING;
923 }
924 bts->cell_identity = ci;
925
926 return CMD_SUCCESS;
927}
928
Harald Welte59b04682009-06-10 05:40:52 +0800929DEFUN(cfg_bts_lac,
930 cfg_bts_lac_cmd,
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +0200931 "location_area_code <0-65535>",
Harald Welte59b04682009-06-10 05:40:52 +0800932 "Set the Location Area Code (LAC) of this BTS\n")
933{
934 struct gsm_bts *bts = vty->index;
935 int lac = atoi(argv[0]);
936
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +0200937 if (lac < 0 || lac > 0xffff) {
938 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte59b04682009-06-10 05:40:52 +0800939 lac, VTY_NEWLINE);
940 return CMD_WARNING;
941 }
Holger Hans Peter Freyther6c6ab862009-10-01 04:07:15 +0200942
943 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
944 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
945 lac, VTY_NEWLINE);
946 return CMD_WARNING;
947 }
948
Harald Welte59b04682009-06-10 05:40:52 +0800949 bts->location_area_code = lac;
950
951 return CMD_SUCCESS;
952}
953
Harald Weltea54a2bb2009-12-01 18:04:30 +0530954
Harald Welte59b04682009-06-10 05:40:52 +0800955DEFUN(cfg_bts_tsc,
956 cfg_bts_tsc_cmd,
957 "training_sequence_code <0-255>",
958 "Set the Training Sequence Code (TSC) of this BTS\n")
959{
960 struct gsm_bts *bts = vty->index;
961 int tsc = atoi(argv[0]);
962
963 if (tsc < 0 || tsc > 0xff) {
964 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
965 tsc, VTY_NEWLINE);
966 return CMD_WARNING;
967 }
968 bts->tsc = tsc;
969
970 return CMD_SUCCESS;
971}
972
973DEFUN(cfg_bts_bsic,
974 cfg_bts_bsic_cmd,
975 "base_station_id_code <0-63>",
976 "Set the Base Station Identity Code (BSIC) of this BTS\n")
977{
978 struct gsm_bts *bts = vty->index;
979 int bsic = atoi(argv[0]);
980
981 if (bsic < 0 || bsic > 0x3f) {
Harald Welte62868882009-08-08 16:12:58 +0200982 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte59b04682009-06-10 05:40:52 +0800983 bsic, VTY_NEWLINE);
984 return CMD_WARNING;
985 }
986 bts->bsic = bsic;
987
988 return CMD_SUCCESS;
989}
990
991
992DEFUN(cfg_bts_unit_id,
993 cfg_bts_unit_id_cmd,
Harald Weltef515aa02009-08-07 13:27:09 +0200994 "ip.access unit_id <0-65534> <0-255>",
995 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte59b04682009-06-10 05:40:52 +0800996{
997 struct gsm_bts *bts = vty->index;
998 int site_id = atoi(argv[0]);
999 int bts_id = atoi(argv[1]);
1000
Harald Weltef515aa02009-08-07 13:27:09 +02001001 if (!is_ipaccess_bts(bts)) {
1002 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1003 return CMD_WARNING;
1004 }
1005
Harald Welte59b04682009-06-10 05:40:52 +08001006 bts->ip_access.site_id = site_id;
1007 bts->ip_access.bts_id = bts_id;
1008
1009 return CMD_SUCCESS;
1010}
1011
Harald Welte25572872009-10-20 00:22:00 +02001012DEFUN(cfg_bts_stream_id,
1013 cfg_bts_stream_id_cmd,
1014 "oml ip.access stream_id <0-255>",
1015 "Set the ip.access Stream ID of the OML link of this BTS\n")
1016{
1017 struct gsm_bts *bts = vty->index;
1018 int stream_id = atoi(argv[0]);
1019
1020 if (!is_ipaccess_bts(bts)) {
1021 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1022 return CMD_WARNING;
1023 }
1024
1025 bts->oml_tei = stream_id;
1026
1027 return CMD_SUCCESS;
1028}
1029
1030
Harald Welte62868882009-08-08 16:12:58 +02001031DEFUN(cfg_bts_oml_e1,
1032 cfg_bts_oml_e1_cmd,
1033 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1034 "E1 interface to be used for OML\n")
1035{
1036 struct gsm_bts *bts = vty->index;
1037
1038 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
1039
1040 return CMD_SUCCESS;
1041}
1042
1043
1044DEFUN(cfg_bts_oml_e1_tei,
1045 cfg_bts_oml_e1_tei_cmd,
1046 "oml e1 tei <0-63>",
1047 "Set the TEI to be used for OML")
1048{
1049 struct gsm_bts *bts = vty->index;
1050
1051 bts->oml_tei = atoi(argv[0]);
1052
1053 return CMD_SUCCESS;
1054}
1055
Harald Welte3e774612009-08-10 13:48:16 +02001056DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1057 "channel allocator (ascending|descending)",
1058 "Should the channel allocator allocate in reverse TRX order?")
1059{
1060 struct gsm_bts *bts = vty->index;
1061
1062 if (!strcmp(argv[0], "ascending"))
1063 bts->chan_alloc_reverse = 0;
1064 else
1065 bts->chan_alloc_reverse = 1;
1066
1067 return CMD_SUCCESS;
1068}
1069
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001070DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1071 "cell barred (0|1)",
1072 "Should this cell be barred from access?")
1073{
1074 struct gsm_bts *bts = vty->index;
1075
1076 bts->cell_barred = atoi(argv[0]);
1077
1078 return CMD_SUCCESS;
1079}
1080
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001081DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1082 "ms max power <0-40>",
1083 "Maximum transmit power of the MS")
1084{
1085 struct gsm_bts *bts = vty->index;
1086
1087 bts->ms_max_power = atoi(argv[0]);
1088
1089 return CMD_SUCCESS;
1090}
1091
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001092DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1093 "periodic location update <0-1530>",
1094 "Periodic Location Updating Interval in Minutes")
1095{
1096 struct gsm_bts *bts = vty->index;
1097
Harald Weltea54a2bb2009-12-01 18:04:30 +05301098 bts->si_common.chan_desc.t3212 = atoi(argv[0]) / 10;
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001099
1100 return CMD_SUCCESS;
1101}
1102
Harald Welte3e774612009-08-10 13:48:16 +02001103
Harald Welte59b04682009-06-10 05:40:52 +08001104/* per TRX configuration */
1105DEFUN(cfg_trx,
1106 cfg_trx_cmd,
1107 "trx TRX_NR",
1108 "Select a TRX to configure")
1109{
1110 int trx_nr = atoi(argv[0]);
1111 struct gsm_bts *bts = vty->index;
1112 struct gsm_bts_trx *trx;
1113
Harald Weltee712a5f2009-06-21 16:17:15 +02001114 if (trx_nr > bts->num_trx) {
1115 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1116 bts->num_trx, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001117 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001118 } else if (trx_nr == bts->num_trx) {
1119 /* we need to allocate a new one */
1120 trx = gsm_bts_trx_alloc(bts);
1121 } else
1122 trx = gsm_bts_trx_num(bts, trx_nr);
1123
1124 if (!trx)
1125 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001126
1127 vty->index = trx;
1128 vty->node = TRX_NODE;
1129
1130 return CMD_SUCCESS;
1131}
1132
1133DEFUN(cfg_trx_arfcn,
1134 cfg_trx_arfcn_cmd,
1135 "arfcn <1-1024>",
1136 "Set the ARFCN for this TRX\n")
1137{
1138 int arfcn = atoi(argv[0]);
1139 struct gsm_bts_trx *trx = vty->index;
1140
1141 /* FIXME: check if this ARFCN is supported by this TRX */
1142
1143 trx->arfcn = arfcn;
1144
1145 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1146 /* FIXME: use OML layer to update the ARFCN */
1147 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1148
1149 return CMD_SUCCESS;
1150}
1151
Harald Welte91afe4c2009-06-20 18:15:19 +02001152DEFUN(cfg_trx_max_power_red,
1153 cfg_trx_max_power_red_cmd,
1154 "max_power_red <0-100>",
1155 "Reduction of maximum BS RF Power in dB\n")
1156{
1157 int maxpwr_r = atoi(argv[0]);
1158 struct gsm_bts_trx *trx = vty->index;
Harald Welte01acd742009-11-18 09:20:22 +01001159 int upper_limit = 24; /* default 12.21 max power red. */
Harald Welte91afe4c2009-06-20 18:15:19 +02001160
1161 /* FIXME: check if our BTS type supports more than 12 */
1162 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1163 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1164 maxpwr_r, VTY_NEWLINE);
1165 return CMD_WARNING;
1166 }
1167 if (maxpwr_r & 1) {
1168 vty_out(vty, "%% Power %d dB is not an even value%s",
1169 maxpwr_r, VTY_NEWLINE);
1170 return CMD_WARNING;
1171 }
1172
1173 trx->max_power_red = maxpwr_r;
1174
1175 /* FIXME: make sure we update this using OML */
1176
1177 return CMD_SUCCESS;
1178}
1179
Harald Welte62868882009-08-08 16:12:58 +02001180DEFUN(cfg_trx_rsl_e1,
1181 cfg_trx_rsl_e1_cmd,
1182 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1183 "E1 interface to be used for RSL\n")
1184{
1185 struct gsm_bts_trx *trx = vty->index;
1186
1187 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1188
1189 return CMD_SUCCESS;
1190}
1191
1192DEFUN(cfg_trx_rsl_e1_tei,
1193 cfg_trx_rsl_e1_tei_cmd,
1194 "rsl e1 tei <0-63>",
1195 "Set the TEI to be used for RSL")
1196{
1197 struct gsm_bts_trx *trx = vty->index;
1198
1199 trx->rsl_tei = atoi(argv[0]);
1200
1201 return CMD_SUCCESS;
1202}
1203
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001204DEFUN(cfg_trx_rf_locked,
1205 cfg_trx_rf_locked_cmd,
1206 "rf_locked (0|1)",
1207 "Turn off RF of the TRX.\n")
1208{
1209 int locked = atoi(argv[0]);
1210 struct gsm_bts_trx *trx = vty->index;
1211
1212 gsm_trx_lock_rf(trx, locked);
1213 return CMD_SUCCESS;
1214}
Harald Welte62868882009-08-08 16:12:58 +02001215
Harald Welte59b04682009-06-10 05:40:52 +08001216/* per TS configuration */
1217DEFUN(cfg_ts,
1218 cfg_ts_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001219 "timeslot <0-7>",
Harald Welte59b04682009-06-10 05:40:52 +08001220 "Select a Timeslot to configure")
1221{
1222 int ts_nr = atoi(argv[0]);
1223 struct gsm_bts_trx *trx = vty->index;
1224 struct gsm_bts_trx_ts *ts;
1225
1226 if (ts_nr >= TRX_NR_TS) {
1227 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1228 TRX_NR_TS, VTY_NEWLINE);
1229 return CMD_WARNING;
1230 }
1231
1232 ts = &trx->ts[ts_nr];
1233
1234 vty->index = ts;
1235 vty->node = TS_NODE;
1236
1237 return CMD_SUCCESS;
1238}
1239
Harald Welte3ffe1b32009-08-07 00:25:23 +02001240DEFUN(cfg_ts_pchan,
1241 cfg_ts_pchan_cmd,
1242 "phys_chan_config PCHAN",
1243 "Physical Channel configuration (TCH/SDCCH/...)")
1244{
1245 struct gsm_bts_trx_ts *ts = vty->index;
1246 int pchanc;
1247
1248 pchanc = gsm_pchan_parse(argv[0]);
1249 if (pchanc < 0)
1250 return CMD_WARNING;
1251
1252 ts->pchan = pchanc;
1253
1254 return CMD_SUCCESS;
1255}
1256
1257DEFUN(cfg_ts_e1_subslot,
1258 cfg_ts_e1_subslot_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001259 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Welte3ffe1b32009-08-07 00:25:23 +02001260 "E1 sub-slot connected to this on-air timeslot")
1261{
1262 struct gsm_bts_trx_ts *ts = vty->index;
1263
Harald Welte62868882009-08-08 16:12:58 +02001264 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001265
1266 return CMD_SUCCESS;
1267}
Harald Welte59b04682009-06-10 05:40:52 +08001268
Harald Welte59b04682009-06-10 05:40:52 +08001269int bsc_vty_init(struct gsm_network *net)
1270{
1271 gsmnet = net;
1272
1273 cmd_init(1);
1274 vty_init();
1275
1276 install_element(VIEW_NODE, &show_net_cmd);
1277 install_element(VIEW_NODE, &show_bts_cmd);
1278 install_element(VIEW_NODE, &show_trx_cmd);
1279 install_element(VIEW_NODE, &show_ts_cmd);
1280 install_element(VIEW_NODE, &show_lchan_cmd);
1281
1282 install_element(VIEW_NODE, &show_e1drv_cmd);
1283 install_element(VIEW_NODE, &show_e1line_cmd);
1284 install_element(VIEW_NODE, &show_e1ts_cmd);
1285
1286 install_element(VIEW_NODE, &show_paging_cmd);
1287
Harald Weltee87eb462009-08-07 13:29:14 +02001288 install_element(CONFIG_NODE, &cfg_net_cmd);
1289 install_node(&net_node, config_write_net);
1290 install_default(GSMNET_NODE);
Harald Welte62868882009-08-08 16:12:58 +02001291 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001292 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1293 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1294 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001295 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Weltecca253a2009-08-30 15:47:06 +09001296 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001297 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001298 install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +01001299 install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
1300 install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
1301 install_element(GSMNET_NODE, &cfg_net_T3107_cmd);
1302 install_element(GSMNET_NODE, &cfg_net_T3109_cmd);
1303 install_element(GSMNET_NODE, &cfg_net_T3111_cmd);
1304 install_element(GSMNET_NODE, &cfg_net_T3113_cmd);
1305 install_element(GSMNET_NODE, &cfg_net_T3115_cmd);
1306 install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
1307 install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
1308 install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001309
1310 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte97ceef92009-08-06 19:06:46 +02001311 install_node(&bts_node, config_write_bts);
Harald Welte59b04682009-06-10 05:40:52 +08001312 install_default(BTS_NODE);
1313 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Welte91afe4c2009-06-20 18:15:19 +02001314 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +02001315 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001316 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1317 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001318 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001319 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte25572872009-10-20 00:22:00 +02001320 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001321 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1322 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001323 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001324 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001325 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001326 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001327
Harald Welte59b04682009-06-10 05:40:52 +08001328
1329 install_element(BTS_NODE, &cfg_trx_cmd);
1330 install_node(&trx_node, dummy_config_write);
1331 install_default(TRX_NODE);
1332 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte7f597bc2009-06-20 22:36:12 +02001333 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001334 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1335 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +01001336 install_element(TRX_NODE, &cfg_trx_rf_locked_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001337
1338 install_element(TRX_NODE, &cfg_ts_cmd);
1339 install_node(&ts_node, dummy_config_write);
1340 install_default(TS_NODE);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001341 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1342 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001343
Holger Hans Peter Freytherbdae6f92009-08-10 10:17:50 +02001344 bsc_vty_init_extra(net);
Harald Welte59b04682009-06-10 05:40:52 +08001345
1346 return 0;
1347}