blob: 809598fa47eb7f82608d351022c22f518d826388 [file] [log] [blame]
Harald Welte68628e82009-03-10 12:17:57 +00001/* OpenBSC interface to quagga VTY */
2/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <stdlib.h>
22#include <unistd.h>
23#include <sys/types.h>
24
25#include <vty/command.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020026#include <vty/buffer.h>
Harald Welte68628e82009-03-10 12:17:57 +000027#include <vty/vty.h>
28
29#include <arpa/inet.h>
30
Harald Welte1bc77352009-03-10 19:47:51 +000031#include <openbsc/linuxlist.h>
Harald Welte68628e82009-03-10 12:17:57 +000032#include <openbsc/gsm_data.h>
Harald Welte68628e82009-03-10 12:17:57 +000033#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000034#include <openbsc/abis_nm.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020035#include <openbsc/gsm_utils.h>
Harald Welte40f82892009-05-23 17:31:39 +000036#include <openbsc/db.h>
Harald Welte5013b2a2009-08-07 13:29:14 +020037#include <openbsc/talloc.h>
Harald Welte68628e82009-03-10 12:17:57 +000038
39static struct gsm_network *gsmnet;
40
Harald Welte5013b2a2009-08-07 13:29:14 +020041struct cmd_node net_node = {
42 GSMNET_NODE,
43 "%s(network)#",
44 1,
45};
46
Harald Welte68628e82009-03-10 12:17:57 +000047struct 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
65static 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{
Harald Welte1bc77352009-03-10 19:47:51 +000072 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);
Harald Welte68628e82009-03-10 12:17:57 +000075}
76
77static void net_dump_vty(struct vty *vty, struct gsm_network *net)
78{
Harald Welteef235b52009-03-10 12:34:02 +000079 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);
Harald Welte1bc77352009-03-10 19:47:51 +000082 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000083 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000084 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000085 net->name_short, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +020086 vty_out(vty, " Authentication policy: %s%s",
87 gsm_auth_policy_name(net->auth_policy), VTY_NEWLINE);
Harald Welte1085c092009-11-18 20:33:19 +010088 vty_out(vty, " Location updating reject cause: %u%s",
89 net->reject_cause, VTY_NEWLINE);
Harald Welte4381cfe2009-08-30 15:47:06 +090090 vty_out(vty, " Encryption: A5/%u%s", net->a5_encryption,
91 VTY_NEWLINE);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +010092 vty_out(vty, " NECI (TCH/H): %u%s", net->neci,
93 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000094}
95
96DEFUN(show_net, show_net_cmd, "show network",
97 SHOW_STR "Display information about a GSM NETWORK\n")
98{
99 struct gsm_network *net = gsmnet;
100 net_dump_vty(vty, net);
101
102 return CMD_SUCCESS;
103}
104
105static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
106{
Harald Welteedb37782009-05-01 14:59:07 +0000107 struct e1inp_line *line;
108
109 if (!e1l) {
110 vty_out(vty, " None%s", VTY_NEWLINE);
111 return;
112 }
113
114 line = e1l->ts->line;
115
116 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
117 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000118 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000119 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000120 e1l->tei, e1l->sapi, VTY_NEWLINE);
121}
122
123static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
124{
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200125 vty_out(vty, "BTS %u is of %s type in band %s, has CI %u LAC %u, "
Harald Weltefcd24452009-06-20 18:15:19 +0200126 "BSIC %u, TSC %u and %u TRX%s",
127 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200128 bts->cell_identity,
Harald Weltefcd24452009-06-20 18:15:19 +0200129 bts->location_area_code, bts->bsic, bts->tsc,
130 bts->num_trx, VTY_NEWLINE);
Harald Welte1d8dbc42009-12-12 15:38:16 +0100131 vty_out(vty, "MS Max power: %u dBm%s", bts->ms_max_power, VTY_NEWLINE);
132 vty_out(vty, "Minimum Rx Level for Access: %u dBm%s",
133 rxlev2dbm(bts->si_common.cell_sel_par.rxlev_acc_min),
134 VTY_NEWLINE);
135 vty_out(vty, "Cell Reselection Hysteresis: %u dBm%s",
136 bts->si_common.cell_sel_par.cell_resel_hyst, VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200137 if (bts->cell_barred)
138 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000139 if (is_ipaccess_bts(bts))
Harald Welte8175e952009-10-20 00:22:00 +0200140 vty_out(vty, " Unit ID: %u/%u/0, OML Stream ID 0x%02x%s",
Harald Welte4cc34222009-05-01 15:12:31 +0000141 bts->ip_access.site_id, bts->ip_access.bts_id,
Harald Welte8175e952009-10-20 00:22:00 +0200142 bts->oml_tei, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000143 vty_out(vty, " NM State: ");
144 net_dump_nmstate(vty, &bts->nm_state);
145 vty_out(vty, " Site Mgr NM State: ");
146 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
147 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
148 bts->paging.available_slots, VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200149 if (!is_ipaccess_bts(bts)) {
150 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
151 e1isl_dump_vty(vty, bts->oml_link);
152 }
Harald Welte68628e82009-03-10 12:17:57 +0000153 /* FIXME: oml_link, chan_desc */
154}
155
156DEFUN(show_bts, show_bts_cmd, "show bts [number]",
157 SHOW_STR "Display information about a BTS\n"
158 "BTS number")
159{
160 struct gsm_network *net = gsmnet;
161 int bts_nr;
162
163 if (argc != 0) {
164 /* use the BTS number that the user has specified */
165 bts_nr = atoi(argv[0]);
166 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000167 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000168 VTY_NEWLINE);
169 return CMD_WARNING;
170 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200171 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000172 return CMD_SUCCESS;
173 }
174 /* print all BTS's */
175 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200176 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000177
178 return CMD_SUCCESS;
179}
180
Harald Welte42581822009-08-08 16:12:58 +0200181/* utility functions */
182static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
183 const char *ts, const char *ss)
184{
185 e1_link->e1_nr = atoi(line);
186 e1_link->e1_ts = atoi(ts);
187 if (!strcmp(ss, "full"))
188 e1_link->e1_ts_ss = 255;
189 else
190 e1_link->e1_ts_ss = atoi(ss);
191}
192
193static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
194 const char *prefix)
195{
196 if (!e1_link->e1_ts)
197 return;
198
199 if (e1_link->e1_ts_ss == 255)
200 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
201 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
202 else
203 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
204 prefix, e1_link->e1_nr, e1_link->e1_ts,
205 e1_link->e1_ts_ss, VTY_NEWLINE);
206}
207
208
Harald Welte67ce0732009-08-06 19:06:46 +0200209static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
210{
Harald Welte42581822009-08-08 16:12:58 +0200211 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
212 if (ts->pchan != GSM_PCHAN_NONE)
213 vty_out(vty, " phys_chan_config %s%s",
214 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
215 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte67ce0732009-08-06 19:06:46 +0200216}
217
218static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
219{
220 int i;
221
Harald Welte5013b2a2009-08-07 13:29:14 +0200222 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
223 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
224 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200225 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
226 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200227
228 for (i = 0; i < TRX_NR_TS; i++)
229 config_write_ts_single(vty, &trx->ts[i]);
230}
231
232static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
233{
234 struct gsm_bts_trx *trx;
235
Harald Welte5013b2a2009-08-07 13:29:14 +0200236 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
237 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
238 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
Holger Hans Peter Freytherf926ed62009-11-19 16:38:49 +0100239 vty_out(vty, " cell_identity %u%s", bts->cell_identity, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200240 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200241 VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200242 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
243 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200244 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Weltea43f7892009-12-01 18:04:30 +0530245 if (bts->si_common.chan_desc.t3212)
Harald Welte (local)efc92312009-08-14 23:09:25 +0200246 vty_out(vty, " periodic location update %u%s",
Harald Weltea43f7892009-12-01 18:04:30 +0530247 bts->si_common.chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte7a8fa412009-08-10 13:48:16 +0200248 vty_out(vty, " channel allocator %s%s",
249 bts->chan_alloc_reverse ? "descending" : "ascending",
250 VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200251 if (bts->cell_barred)
252 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200253 if (is_ipaccess_bts(bts)) {
Harald Welte5013b2a2009-08-07 13:29:14 +0200254 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200255 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200256 vty_out(vty, " oml ip.access stream_id %u%s", bts->oml_tei, VTY_NEWLINE);
257 } else {
Harald Welte42581822009-08-08 16:12:58 +0200258 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
259 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
260 }
Harald Welte67ce0732009-08-06 19:06:46 +0200261
262 llist_for_each_entry(trx, &bts->trx_list, list)
263 config_write_trx_single(vty, trx);
264}
265
266static int config_write_bts(struct vty *v)
267{
268 struct gsm_bts *bts;
269
270 llist_for_each_entry(bts, &gsmnet->bts_list, list)
271 config_write_bts_single(v, bts);
272
273 return CMD_SUCCESS;
274}
275
Harald Welte5013b2a2009-08-07 13:29:14 +0200276static int config_write_net(struct vty *vty)
277{
278 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200279 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200280 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200281 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
282 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +0200283 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte1085c092009-11-18 20:33:19 +0100284 vty_out(vty, " location updating reject cause %u%s",
285 gsmnet->reject_cause, VTY_NEWLINE);
Harald Welte4381cfe2009-08-30 15:47:06 +0900286 vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
Holger Hans Peter Freytherd54c3372009-11-19 16:37:48 +0100287 vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100288 vty_out(vty, " timer t3101 %u%s", gsmnet->T3101, VTY_NEWLINE);
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100289 vty_out(vty, " timer t3103 %u%s", gsmnet->T3103, VTY_NEWLINE);
290 vty_out(vty, " timer t3105 %u%s", gsmnet->T3105, VTY_NEWLINE);
291 vty_out(vty, " timer t3107 %u%s", gsmnet->T3107, VTY_NEWLINE);
292 vty_out(vty, " timer t3109 %u%s", gsmnet->T3109, VTY_NEWLINE);
293 vty_out(vty, " timer t3111 %u%s", gsmnet->T3111, VTY_NEWLINE);
294 vty_out(vty, " timer t3113 %u%s", gsmnet->T3113, VTY_NEWLINE);
295 vty_out(vty, " timer t3115 %u%s", gsmnet->T3115, VTY_NEWLINE);
296 vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
297 vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
298 vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200299
300 return CMD_SUCCESS;
301}
Harald Welte67ce0732009-08-06 19:06:46 +0200302
Harald Welte68628e82009-03-10 12:17:57 +0000303static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
304{
305 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
306 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200307 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200308 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200309 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200310 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000311 vty_out(vty, " NM State: ");
312 net_dump_nmstate(vty, &trx->nm_state);
313 vty_out(vty, " Baseband Transceiver NM State: ");
314 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
Harald Welte8175e952009-10-20 00:22:00 +0200315 if (is_ipaccess_bts(trx->bts)) {
316 vty_out(vty, " ip.access stream ID: 0x%02x%s",
317 trx->rsl_tei, VTY_NEWLINE);
318 } else {
319 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
320 e1isl_dump_vty(vty, trx->rsl_link);
321 }
Harald Welte68628e82009-03-10 12:17:57 +0000322}
323
324DEFUN(show_trx,
325 show_trx_cmd,
326 "show trx [bts_nr] [trx_nr]",
327 SHOW_STR "Display information about a TRX\n")
328{
329 struct gsm_network *net = gsmnet;
330 struct gsm_bts *bts = NULL;
331 struct gsm_bts_trx *trx;
332 int bts_nr, trx_nr;
333
334 if (argc >= 1) {
335 /* use the BTS number that the user has specified */
336 bts_nr = atoi(argv[0]);
337 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000338 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000339 VTY_NEWLINE);
340 return CMD_WARNING;
341 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200342 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000343 }
344 if (argc >= 2) {
345 trx_nr = atoi(argv[1]);
346 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000347 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000348 VTY_NEWLINE);
349 return CMD_WARNING;
350 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200351 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000352 trx_dump_vty(vty, trx);
353 return CMD_SUCCESS;
354 }
355 if (bts) {
356 /* print all TRX in this BTS */
357 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200358 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000359 trx_dump_vty(vty, trx);
360 }
361 return CMD_SUCCESS;
362 }
363
364 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200365 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000366 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200367 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000368 trx_dump_vty(vty, trx);
369 }
370 }
371
372 return CMD_SUCCESS;
373}
374
Harald Welte67ce0732009-08-06 19:06:46 +0200375
Harald Welte68628e82009-03-10 12:17:57 +0000376static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
377{
Harald Welte68628e82009-03-10 12:17:57 +0000378 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
379 ts->nr, ts->trx->nr, ts->trx->bts->nr,
380 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
381 vty_out(vty, " NM State: ");
382 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte2c828992009-12-02 01:56:49 +0530383 if (!is_ipaccess_bts(ts->trx->bts))
Harald Welteef235b52009-03-10 12:34:02 +0000384 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
385 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
386 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000387}
388
389DEFUN(show_ts,
390 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000391 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000392 SHOW_STR "Display information about a TS\n")
393{
394 struct gsm_network *net = gsmnet;
395 struct gsm_bts *bts;
396 struct gsm_bts_trx *trx;
397 struct gsm_bts_trx_ts *ts;
398 int bts_nr, trx_nr, ts_nr;
399
400 if (argc >= 1) {
401 /* use the BTS number that the user has specified */
402 bts_nr = atoi(argv[0]);
403 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000404 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000405 VTY_NEWLINE);
406 return CMD_WARNING;
407 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200408 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000409 }
410 if (argc >= 2) {
411 trx_nr = atoi(argv[1]);
412 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000413 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000414 VTY_NEWLINE);
415 return CMD_WARNING;
416 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200417 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000418 }
419 if (argc >= 3) {
420 ts_nr = atoi(argv[2]);
421 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000422 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000423 VTY_NEWLINE);
424 return CMD_WARNING;
425 }
426 ts = &trx->ts[ts_nr];
427 ts_dump_vty(vty, ts);
428 return CMD_SUCCESS;
429 }
430 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200431 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000432 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200433 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000434 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
435 ts = &trx->ts[ts_nr];
436 ts_dump_vty(vty, ts);
437 }
438 }
439 }
440
441 return CMD_SUCCESS;
442}
443
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200444void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte68628e82009-03-10 12:17:57 +0000445{
Harald Weltefcd24452009-06-20 18:15:19 +0200446 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000447 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000448 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000449 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000450 if (subscr->extension)
451 vty_out(vty, " Extension: %s%s", subscr->extension,
452 VTY_NEWLINE);
453 if (subscr->imsi)
454 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200455 if (subscr->tmsi != GSM_RESERVED_TMSI)
456 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte731fd912009-08-15 03:24:51 +0200457 VTY_NEWLINE);
Harald Welte (local)15920de2009-08-14 20:27:16 +0200458 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000459}
460
461static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
462{
463 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
464 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
465 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
466 VTY_NEWLINE);
467 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
468 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
469 lchan->ms_power, VTY_NEWLINE);
470 if (lchan->subscr) {
471 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
472 subscr_dump_vty(vty, lchan->subscr);
473 } else
474 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
Harald Welte2c828992009-12-02 01:56:49 +0530475 if (is_ipaccess_bts(lchan->ts->trx->bts)) {
476 struct in_addr ia;
477 ia.s_addr = lchan->abis_ip.bound_ip;
478 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
479 inet_ntoa(ia), lchan->abis_ip.bound_port,
480 lchan->abis_ip.rtp_payload2, lchan->abis_ip.conn_id,
481 VTY_NEWLINE);
482 }
Harald Welte68628e82009-03-10 12:17:57 +0000483}
484
Harald Welte4bfdfe72009-06-10 23:11:52 +0800485#if 0
486TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000487static void call_dump_vty(struct vty *vty, struct gsm_call *call)
488{
489 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
490 call->type, call->state, call->transaction_id, VTY_NEWLINE);
491
492 if (call->local_lchan) {
493 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
494 lchan_dump_vty(vty, call->local_lchan);
495 } else
496 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
497
498 if (call->remote_lchan) {
499 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
500 lchan_dump_vty(vty, call->remote_lchan);
501 } else
502 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
503
504 if (call->called_subscr) {
505 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
506 subscr_dump_vty(vty, call->called_subscr);
507 } else
508 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
509}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800510#endif
Harald Welte68628e82009-03-10 12:17:57 +0000511
512DEFUN(show_lchan,
513 show_lchan_cmd,
514 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
515 SHOW_STR "Display information about a logical channel\n")
516{
517 struct gsm_network *net = gsmnet;
518 struct gsm_bts *bts;
519 struct gsm_bts_trx *trx;
520 struct gsm_bts_trx_ts *ts;
521 struct gsm_lchan *lchan;
522 int bts_nr, trx_nr, ts_nr, lchan_nr;
523
524 if (argc >= 1) {
525 /* use the BTS number that the user has specified */
526 bts_nr = atoi(argv[0]);
527 if (bts_nr >= net->num_bts) {
528 vty_out(vty, "%% can't find BTS %s%s", argv[0],
529 VTY_NEWLINE);
530 return CMD_WARNING;
531 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200532 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000533 }
534 if (argc >= 2) {
535 trx_nr = atoi(argv[1]);
536 if (trx_nr >= bts->num_trx) {
537 vty_out(vty, "%% can't find TRX %s%s", argv[1],
538 VTY_NEWLINE);
539 return CMD_WARNING;
540 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200541 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000542 }
543 if (argc >= 3) {
544 ts_nr = atoi(argv[2]);
545 if (ts_nr >= TRX_NR_TS) {
546 vty_out(vty, "%% can't find TS %s%s", argv[2],
547 VTY_NEWLINE);
548 return CMD_WARNING;
549 }
550 ts = &trx->ts[ts_nr];
551 }
552 if (argc >= 4) {
553 lchan_nr = atoi(argv[3]);
554 if (lchan_nr >= TS_MAX_LCHAN) {
555 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
556 VTY_NEWLINE);
557 return CMD_WARNING;
558 }
559 lchan = &ts->lchan[lchan_nr];
560 lchan_dump_vty(vty, lchan);
561 return CMD_SUCCESS;
562 }
563 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200564 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000565 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200566 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000567 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
568 ts = &trx->ts[ts_nr];
569 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
570 lchan_nr++) {
571 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000572 if (lchan->type == GSM_LCHAN_NONE)
573 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000574 lchan_dump_vty(vty, lchan);
575 }
576 }
577 }
578 }
579
580 return CMD_SUCCESS;
581}
582
Harald Welte1bc77352009-03-10 19:47:51 +0000583static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
584{
585 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
586}
587
588DEFUN(show_e1drv,
589 show_e1drv_cmd,
590 "show e1_driver",
591 SHOW_STR "Display information about available E1 drivers\n")
592{
593 struct e1inp_driver *drv;
594
595 llist_for_each_entry(drv, &e1inp_driver_list, list)
596 e1drv_dump_vty(vty, drv);
597
598 return CMD_SUCCESS;
599}
600
Harald Welte68628e82009-03-10 12:17:57 +0000601static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
602{
603 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
604 line->num, line->name ? line->name : "",
605 line->driver->name, VTY_NEWLINE);
606}
607
608DEFUN(show_e1line,
609 show_e1line_cmd,
610 "show e1_line [line_nr]",
611 SHOW_STR "Display information about a E1 line\n")
612{
Harald Welte1bc77352009-03-10 19:47:51 +0000613 struct e1inp_line *line;
614
615 if (argc >= 1) {
616 int num = atoi(argv[0]);
617 llist_for_each_entry(line, &e1inp_line_list, list) {
618 if (line->num == num) {
619 e1line_dump_vty(vty, line);
620 return CMD_SUCCESS;
621 }
622 }
623 return CMD_WARNING;
624 }
625
626 llist_for_each_entry(line, &e1inp_line_list, list)
627 e1line_dump_vty(vty, line);
628
629 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000630}
631
632static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
633{
Harald Welte42581822009-08-08 16:12:58 +0200634 if (ts->type == E1INP_TS_TYPE_NONE)
635 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000636 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
637 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
638 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000639}
640
641DEFUN(show_e1ts,
642 show_e1ts_cmd,
643 "show e1_timeslot [line_nr] [ts_nr]",
644 SHOW_STR "Display information about a E1 timeslot\n")
645{
Harald Welte986c3d72009-11-17 06:12:16 +0100646 struct e1inp_line *line = NULL;
Harald Welte1bc77352009-03-10 19:47:51 +0000647 struct e1inp_ts *ts;
648 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000649
Harald Welte1bc77352009-03-10 19:47:51 +0000650 if (argc == 0) {
651 llist_for_each_entry(line, &e1inp_line_list, list) {
652 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
653 ts = &line->ts[ts_nr];
654 e1ts_dump_vty(vty, ts);
655 }
656 }
657 return CMD_SUCCESS;
658 }
659 if (argc >= 1) {
660 int num = atoi(argv[0]);
661 llist_for_each_entry(line, &e1inp_line_list, list) {
662 if (line->num == num)
663 break;
664 }
665 if (!line || line->num != num) {
666 vty_out(vty, "E1 line %s is invalid%s",
667 argv[0], VTY_NEWLINE);
668 return CMD_WARNING;
669 }
670 }
671 if (argc >= 2) {
672 ts_nr = atoi(argv[1]);
673 if (ts_nr > NUM_E1_TS) {
674 vty_out(vty, "E1 timeslot %s is invalid%s",
675 argv[1], VTY_NEWLINE);
676 return CMD_WARNING;
677 }
678 ts = &line->ts[ts_nr];
679 e1ts_dump_vty(vty, ts);
680 return CMD_SUCCESS;
681 } else {
682 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
683 ts = &line->ts[ts_nr];
684 e1ts_dump_vty(vty, ts);
685 }
686 return CMD_SUCCESS;
687 }
688 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000689}
690
Harald Weltebe4b7302009-05-23 16:59:33 +0000691static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000692{
693 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
694 subscr_dump_vty(vty, pag->subscr);
695}
696
Harald Weltebe4b7302009-05-23 16:59:33 +0000697static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000698{
699 struct gsm_paging_request *pag;
700
701 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
702 paging_dump_vty(vty, pag);
703}
704
705DEFUN(show_paging,
706 show_paging_cmd,
707 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000708 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000709{
710 struct gsm_network *net = gsmnet;
711 struct gsm_bts *bts;
712 int bts_nr;
713
714 if (argc >= 1) {
715 /* use the BTS number that the user has specified */
716 bts_nr = atoi(argv[0]);
717 if (bts_nr >= net->num_bts) {
718 vty_out(vty, "%% can't find BTS %s%s", argv[0],
719 VTY_NEWLINE);
720 return CMD_WARNING;
721 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200722 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000723 bts_paging_dump_vty(vty, bts);
724
725 return CMD_SUCCESS;
726 }
727 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200728 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000729 bts_paging_dump_vty(vty, bts);
730 }
731
732 return CMD_SUCCESS;
733}
734
Harald Welte5013b2a2009-08-07 13:29:14 +0200735DEFUN(cfg_net,
736 cfg_net_cmd,
737 "network",
738 "Configure the GSM network")
739{
740 vty->index = gsmnet;
741 vty->node = GSMNET_NODE;
742
743 return CMD_SUCCESS;
744}
745
746
747DEFUN(cfg_net_ncc,
748 cfg_net_ncc_cmd,
749 "network country code <1-999>",
750 "Set the GSM network country code")
751{
752 gsmnet->country_code = atoi(argv[0]);
753
754 return CMD_SUCCESS;
755}
756
757DEFUN(cfg_net_mnc,
758 cfg_net_mnc_cmd,
759 "mobile network code <1-999>",
760 "Set the GSM mobile network code")
761{
762 gsmnet->network_code = atoi(argv[0]);
763
764 return CMD_SUCCESS;
765}
766
767DEFUN(cfg_net_name_short,
768 cfg_net_name_short_cmd,
769 "short name NAME",
770 "Set the short GSM network name")
771{
772 if (gsmnet->name_short)
773 talloc_free(gsmnet->name_short);
774
775 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
776
777 return CMD_SUCCESS;
778}
779
780DEFUN(cfg_net_name_long,
781 cfg_net_name_long_cmd,
782 "long name NAME",
783 "Set the long GSM network name")
784{
785 if (gsmnet->name_long)
786 talloc_free(gsmnet->name_long);
787
788 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
789
790 return CMD_SUCCESS;
791}
Harald Welte40f82892009-05-23 17:31:39 +0000792
Harald Welte (local)69de3972009-08-12 14:42:23 +0200793DEFUN(cfg_net_auth_policy,
794 cfg_net_auth_policy_cmd,
795 "auth policy (closed|accept-all|token)",
796 "Set the GSM network authentication policy\n")
797{
798 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
799
800 gsmnet->auth_policy = policy;
801
802 return CMD_SUCCESS;
803}
804
Harald Welte1085c092009-11-18 20:33:19 +0100805DEFUN(cfg_net_reject_cause,
806 cfg_net_reject_cause_cmd,
807 "location updating reject cause <2-111>",
808 "Set the reject cause of location updating reject\n")
809{
810 gsmnet->reject_cause = atoi(argv[0]);
811
812 return CMD_SUCCESS;
813}
814
Harald Welte4381cfe2009-08-30 15:47:06 +0900815DEFUN(cfg_net_encryption,
816 cfg_net_encryption_cmd,
817 "encryption a5 (0|1|2)",
818 "Enable or disable encryption (A5) for this network\n")
819{
Andreas.Eversberg1059deb2009-11-17 09:55:26 +0100820 gsmnet->a5_encryption= atoi(argv[0]);
Harald Welte4381cfe2009-08-30 15:47:06 +0900821
822 return CMD_SUCCESS;
823}
824
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100825DEFUN(cfg_net_neci,
826 cfg_net_neci_cmd,
827 "neci (0|1)",
828 "Set if NECI of cell selection is to be set")
829{
830 gsmnet->neci = atoi(argv[0]);
831 return CMD_SUCCESS;
832}
833
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100834#define DECLARE_TIMER(number) \
835 DEFUN(cfg_net_T##number, \
836 cfg_net_T##number##_cmd, \
837 "timer t" #number " <0-65535>", \
838 "Set the T" #number " value.") \
839{ \
840 int value = atoi(argv[0]); \
841 \
842 if (value < 0 || value > 65535) { \
843 vty_out(vty, "Timer value %s out of range.%s", \
844 argv[0], VTY_NEWLINE); \
845 return CMD_WARNING; \
846 } \
847 \
848 gsmnet->T##number = value; \
849 return CMD_SUCCESS; \
850}
851
852DECLARE_TIMER(3101)
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100853DECLARE_TIMER(3103)
854DECLARE_TIMER(3105)
855DECLARE_TIMER(3107)
856DECLARE_TIMER(3109)
857DECLARE_TIMER(3111)
858DECLARE_TIMER(3113)
859DECLARE_TIMER(3115)
860DECLARE_TIMER(3117)
861DECLARE_TIMER(3119)
862DECLARE_TIMER(3141)
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100863
864
Harald Welte5258fc42009-03-28 19:07:53 +0000865/* per-BTS configuration */
866DEFUN(cfg_bts,
867 cfg_bts_cmd,
868 "bts BTS_NR",
869 "Select a BTS to configure\n")
870{
871 int bts_nr = atoi(argv[0]);
872 struct gsm_bts *bts;
873
Harald Weltee441d9c2009-06-21 16:17:15 +0200874 if (bts_nr > gsmnet->num_bts) {
875 vty_out(vty, "%% The next unused BTS number is %u%s",
876 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000877 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200878 } else if (bts_nr == gsmnet->num_bts) {
879 /* allocate a new one */
880 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
881 HARDCODED_TSC, HARDCODED_BSIC);
882 } else
883 bts = gsm_bts_num(gsmnet, bts_nr);
884
885 if (!bts)
886 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000887
888 vty->index = bts;
889 vty->node = BTS_NODE;
890
891 return CMD_SUCCESS;
892}
893
894DEFUN(cfg_bts_type,
895 cfg_bts_type_cmd,
896 "type TYPE",
897 "Set the BTS type\n")
898{
899 struct gsm_bts *bts = vty->index;
900
Harald Weltea6fd58e2009-08-07 00:25:23 +0200901 bts->type = parse_btstype(argv[0]);
902
Harald Welte8175e952009-10-20 00:22:00 +0200903 if (is_ipaccess_bts(bts)) {
904 /* Set the default OML Stream ID to 0xff */
905 bts->oml_tei = 0xff;
906 }
907
Harald Welte5258fc42009-03-28 19:07:53 +0000908 return CMD_SUCCESS;
909}
910
Harald Weltefcd24452009-06-20 18:15:19 +0200911DEFUN(cfg_bts_band,
912 cfg_bts_band_cmd,
913 "band BAND",
914 "Set the frequency band of this BTS\n")
915{
916 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200917 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200918
919 if (band < 0) {
920 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
921 band, VTY_NEWLINE);
922 return CMD_WARNING;
923 }
924
925 bts->band = band;
926
927 return CMD_SUCCESS;
928}
929
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200930DEFUN(cfg_bts_ci,
931 cfg_bts_ci_cmd,
932 "cell_identity <0-65535>",
933 "Set the Cell identity of this BTS\n")
934{
935 struct gsm_bts *bts = vty->index;
936 int ci = atoi(argv[0]);
937
938 if (ci < 0 || ci > 0xffff) {
939 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
940 ci, VTY_NEWLINE);
941 return CMD_WARNING;
942 }
943 bts->cell_identity = ci;
944
945 return CMD_SUCCESS;
946}
947
Harald Welte5258fc42009-03-28 19:07:53 +0000948DEFUN(cfg_bts_lac,
949 cfg_bts_lac_cmd,
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200950 "location_area_code <0-65535>",
Harald Welte5258fc42009-03-28 19:07:53 +0000951 "Set the Location Area Code (LAC) of this BTS\n")
952{
953 struct gsm_bts *bts = vty->index;
954 int lac = atoi(argv[0]);
955
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200956 if (lac < 0 || lac > 0xffff) {
957 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte5258fc42009-03-28 19:07:53 +0000958 lac, VTY_NEWLINE);
959 return CMD_WARNING;
960 }
Holger Hans Peter Freythere48b9562009-10-01 04:07:15 +0200961
962 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
963 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
964 lac, VTY_NEWLINE);
965 return CMD_WARNING;
966 }
967
Harald Welte5258fc42009-03-28 19:07:53 +0000968 bts->location_area_code = lac;
969
970 return CMD_SUCCESS;
971}
972
Harald Weltea43f7892009-12-01 18:04:30 +0530973
Harald Welte5258fc42009-03-28 19:07:53 +0000974DEFUN(cfg_bts_tsc,
975 cfg_bts_tsc_cmd,
976 "training_sequence_code <0-255>",
977 "Set the Training Sequence Code (TSC) of this BTS\n")
978{
979 struct gsm_bts *bts = vty->index;
980 int tsc = atoi(argv[0]);
981
982 if (tsc < 0 || tsc > 0xff) {
983 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
984 tsc, VTY_NEWLINE);
985 return CMD_WARNING;
986 }
987 bts->tsc = tsc;
988
989 return CMD_SUCCESS;
990}
991
Harald Welte78f2f502009-05-23 16:56:52 +0000992DEFUN(cfg_bts_bsic,
993 cfg_bts_bsic_cmd,
994 "base_station_id_code <0-63>",
995 "Set the Base Station Identity Code (BSIC) of this BTS\n")
996{
997 struct gsm_bts *bts = vty->index;
998 int bsic = atoi(argv[0]);
999
1000 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +02001001 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +00001002 bsic, VTY_NEWLINE);
1003 return CMD_WARNING;
1004 }
1005 bts->bsic = bsic;
1006
1007 return CMD_SUCCESS;
1008}
1009
1010
Harald Welte4cc34222009-05-01 15:12:31 +00001011DEFUN(cfg_bts_unit_id,
1012 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +02001013 "ip.access unit_id <0-65534> <0-255>",
1014 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +00001015{
1016 struct gsm_bts *bts = vty->index;
1017 int site_id = atoi(argv[0]);
1018 int bts_id = atoi(argv[1]);
1019
Harald Welte07dc73d2009-08-07 13:27:09 +02001020 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
Harald Welte4cc34222009-05-01 15:12:31 +00001025 bts->ip_access.site_id = site_id;
1026 bts->ip_access.bts_id = bts_id;
1027
1028 return CMD_SUCCESS;
1029}
1030
Harald Welte8175e952009-10-20 00:22:00 +02001031DEFUN(cfg_bts_stream_id,
1032 cfg_bts_stream_id_cmd,
1033 "oml ip.access stream_id <0-255>",
1034 "Set the ip.access Stream ID of the OML link of this BTS\n")
1035{
1036 struct gsm_bts *bts = vty->index;
1037 int stream_id = atoi(argv[0]);
1038
1039 if (!is_ipaccess_bts(bts)) {
1040 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1041 return CMD_WARNING;
1042 }
1043
1044 bts->oml_tei = stream_id;
1045
1046 return CMD_SUCCESS;
1047}
1048
1049
Harald Welte42581822009-08-08 16:12:58 +02001050DEFUN(cfg_bts_oml_e1,
1051 cfg_bts_oml_e1_cmd,
1052 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1053 "E1 interface to be used for OML\n")
1054{
1055 struct gsm_bts *bts = vty->index;
1056
1057 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
1058
1059 return CMD_SUCCESS;
1060}
1061
1062
1063DEFUN(cfg_bts_oml_e1_tei,
1064 cfg_bts_oml_e1_tei_cmd,
1065 "oml e1 tei <0-63>",
1066 "Set the TEI to be used for OML")
1067{
1068 struct gsm_bts *bts = vty->index;
1069
1070 bts->oml_tei = atoi(argv[0]);
1071
1072 return CMD_SUCCESS;
1073}
1074
Harald Welte7a8fa412009-08-10 13:48:16 +02001075DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1076 "channel allocator (ascending|descending)",
1077 "Should the channel allocator allocate in reverse TRX order?")
1078{
1079 struct gsm_bts *bts = vty->index;
1080
1081 if (!strcmp(argv[0], "ascending"))
1082 bts->chan_alloc_reverse = 0;
1083 else
1084 bts->chan_alloc_reverse = 1;
1085
1086 return CMD_SUCCESS;
1087}
1088
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001089DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1090 "cell barred (0|1)",
1091 "Should this cell be barred from access?")
1092{
1093 struct gsm_bts *bts = vty->index;
1094
1095 bts->cell_barred = atoi(argv[0]);
1096
1097 return CMD_SUCCESS;
1098}
1099
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001100DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1101 "ms max power <0-40>",
1102 "Maximum transmit power of the MS")
1103{
1104 struct gsm_bts *bts = vty->index;
1105
1106 bts->ms_max_power = atoi(argv[0]);
1107
1108 return CMD_SUCCESS;
1109}
1110
Harald Welte (local)efc92312009-08-14 23:09:25 +02001111DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1112 "periodic location update <0-1530>",
1113 "Periodic Location Updating Interval in Minutes")
1114{
1115 struct gsm_bts *bts = vty->index;
1116
Harald Weltea43f7892009-12-01 18:04:30 +05301117 bts->si_common.chan_desc.t3212 = atoi(argv[0]) / 10;
Harald Welte (local)efc92312009-08-14 23:09:25 +02001118
1119 return CMD_SUCCESS;
1120}
1121
Harald Welte7a8fa412009-08-10 13:48:16 +02001122
Harald Welte5258fc42009-03-28 19:07:53 +00001123/* per TRX configuration */
1124DEFUN(cfg_trx,
1125 cfg_trx_cmd,
1126 "trx TRX_NR",
1127 "Select a TRX to configure")
1128{
1129 int trx_nr = atoi(argv[0]);
1130 struct gsm_bts *bts = vty->index;
1131 struct gsm_bts_trx *trx;
1132
Harald Weltee441d9c2009-06-21 16:17:15 +02001133 if (trx_nr > bts->num_trx) {
1134 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1135 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +00001136 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +02001137 } else if (trx_nr == bts->num_trx) {
1138 /* we need to allocate a new one */
1139 trx = gsm_bts_trx_alloc(bts);
1140 } else
1141 trx = gsm_bts_trx_num(bts, trx_nr);
1142
1143 if (!trx)
1144 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001145
1146 vty->index = trx;
1147 vty->node = TRX_NODE;
1148
1149 return CMD_SUCCESS;
1150}
1151
1152DEFUN(cfg_trx_arfcn,
1153 cfg_trx_arfcn_cmd,
1154 "arfcn <1-1024>",
1155 "Set the ARFCN for this TRX\n")
1156{
1157 int arfcn = atoi(argv[0]);
1158 struct gsm_bts_trx *trx = vty->index;
1159
1160 /* FIXME: check if this ARFCN is supported by this TRX */
1161
1162 trx->arfcn = arfcn;
1163
1164 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1165 /* FIXME: use OML layer to update the ARFCN */
1166 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1167
1168 return CMD_SUCCESS;
1169}
1170
Harald Weltefcd24452009-06-20 18:15:19 +02001171DEFUN(cfg_trx_max_power_red,
1172 cfg_trx_max_power_red_cmd,
1173 "max_power_red <0-100>",
1174 "Reduction of maximum BS RF Power in dB\n")
1175{
1176 int maxpwr_r = atoi(argv[0]);
1177 struct gsm_bts_trx *trx = vty->index;
Harald Welte61a83b22009-11-18 09:20:22 +01001178 int upper_limit = 24; /* default 12.21 max power red. */
Harald Weltefcd24452009-06-20 18:15:19 +02001179
1180 /* FIXME: check if our BTS type supports more than 12 */
1181 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1182 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1183 maxpwr_r, VTY_NEWLINE);
1184 return CMD_WARNING;
1185 }
1186 if (maxpwr_r & 1) {
1187 vty_out(vty, "%% Power %d dB is not an even value%s",
1188 maxpwr_r, VTY_NEWLINE);
1189 return CMD_WARNING;
1190 }
1191
1192 trx->max_power_red = maxpwr_r;
1193
1194 /* FIXME: make sure we update this using OML */
1195
1196 return CMD_SUCCESS;
1197}
1198
Harald Welte42581822009-08-08 16:12:58 +02001199DEFUN(cfg_trx_rsl_e1,
1200 cfg_trx_rsl_e1_cmd,
1201 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1202 "E1 interface to be used for RSL\n")
1203{
1204 struct gsm_bts_trx *trx = vty->index;
1205
1206 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1207
1208 return CMD_SUCCESS;
1209}
1210
1211DEFUN(cfg_trx_rsl_e1_tei,
1212 cfg_trx_rsl_e1_tei_cmd,
1213 "rsl e1 tei <0-63>",
1214 "Set the TEI to be used for RSL")
1215{
1216 struct gsm_bts_trx *trx = vty->index;
1217
1218 trx->rsl_tei = atoi(argv[0]);
1219
1220 return CMD_SUCCESS;
1221}
1222
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +01001223DEFUN(cfg_trx_rf_locked,
1224 cfg_trx_rf_locked_cmd,
1225 "rf_locked (0|1)",
1226 "Turn off RF of the TRX.\n")
1227{
1228 int locked = atoi(argv[0]);
1229 struct gsm_bts_trx *trx = vty->index;
1230
1231 gsm_trx_lock_rf(trx, locked);
1232 return CMD_SUCCESS;
1233}
Harald Welte42581822009-08-08 16:12:58 +02001234
Harald Welte5258fc42009-03-28 19:07:53 +00001235/* per TS configuration */
1236DEFUN(cfg_ts,
1237 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001238 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001239 "Select a Timeslot to configure")
1240{
1241 int ts_nr = atoi(argv[0]);
1242 struct gsm_bts_trx *trx = vty->index;
1243 struct gsm_bts_trx_ts *ts;
1244
1245 if (ts_nr >= TRX_NR_TS) {
1246 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1247 TRX_NR_TS, VTY_NEWLINE);
1248 return CMD_WARNING;
1249 }
1250
1251 ts = &trx->ts[ts_nr];
1252
1253 vty->index = ts;
1254 vty->node = TS_NODE;
1255
1256 return CMD_SUCCESS;
1257}
1258
Harald Weltea6fd58e2009-08-07 00:25:23 +02001259DEFUN(cfg_ts_pchan,
1260 cfg_ts_pchan_cmd,
1261 "phys_chan_config PCHAN",
1262 "Physical Channel configuration (TCH/SDCCH/...)")
1263{
1264 struct gsm_bts_trx_ts *ts = vty->index;
1265 int pchanc;
1266
1267 pchanc = gsm_pchan_parse(argv[0]);
1268 if (pchanc < 0)
1269 return CMD_WARNING;
1270
1271 ts->pchan = pchanc;
1272
1273 return CMD_SUCCESS;
1274}
1275
1276DEFUN(cfg_ts_e1_subslot,
1277 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001278 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001279 "E1 sub-slot connected to this on-air timeslot")
1280{
1281 struct gsm_bts_trx_ts *ts = vty->index;
1282
Harald Welte42581822009-08-08 16:12:58 +02001283 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001284
1285 return CMD_SUCCESS;
1286}
Harald Welte5258fc42009-03-28 19:07:53 +00001287
Harald Welte68628e82009-03-10 12:17:57 +00001288int bsc_vty_init(struct gsm_network *net)
1289{
1290 gsmnet = net;
1291
1292 cmd_init(1);
1293 vty_init();
1294
1295 install_element(VIEW_NODE, &show_net_cmd);
1296 install_element(VIEW_NODE, &show_bts_cmd);
1297 install_element(VIEW_NODE, &show_trx_cmd);
1298 install_element(VIEW_NODE, &show_ts_cmd);
1299 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001300
1301 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001302 install_element(VIEW_NODE, &show_e1line_cmd);
1303 install_element(VIEW_NODE, &show_e1ts_cmd);
1304
Harald Weltef5025b62009-03-28 16:55:11 +00001305 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001306
Harald Welte5013b2a2009-08-07 13:29:14 +02001307 install_element(CONFIG_NODE, &cfg_net_cmd);
1308 install_node(&net_node, config_write_net);
1309 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001310 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001311 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1312 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1313 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001314 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte1085c092009-11-18 20:33:19 +01001315 install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd);
Harald Welte4381cfe2009-08-30 15:47:06 +09001316 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001317 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001318 install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001319 install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
1320 install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
1321 install_element(GSMNET_NODE, &cfg_net_T3107_cmd);
1322 install_element(GSMNET_NODE, &cfg_net_T3109_cmd);
1323 install_element(GSMNET_NODE, &cfg_net_T3111_cmd);
1324 install_element(GSMNET_NODE, &cfg_net_T3113_cmd);
1325 install_element(GSMNET_NODE, &cfg_net_T3115_cmd);
1326 install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
1327 install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
1328 install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001329
1330 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001331 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001332 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001333 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001334 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +02001335 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001336 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1337 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001338 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001339 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte8175e952009-10-20 00:22:00 +02001340 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001341 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1342 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001343 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001344 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001345 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)efc92312009-08-14 23:09:25 +02001346 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001347
Harald Welte68628e82009-03-10 12:17:57 +00001348
Harald Welte5258fc42009-03-28 19:07:53 +00001349 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001350 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001351 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001352 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001353 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001354 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1355 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +01001356 install_element(TRX_NODE, &cfg_trx_rf_locked_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001357
Harald Welte5258fc42009-03-28 19:07:53 +00001358 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001359 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001360 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001361 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1362 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001363
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02001364 bsc_vty_init_extra(net);
Harald Welte40f82892009-05-23 17:31:39 +00001365
Harald Welte68628e82009-03-10 12:17:57 +00001366 return 0;
1367}