blob: f8bba2c44339c207fe2b093032f830a41becc934 [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 Welte4381cfe2009-08-30 15:47:06 +090088 vty_out(vty, " Encryption: A5/%u%s", net->a5_encryption,
89 VTY_NEWLINE);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +010090 vty_out(vty, " NECI (TCH/H): %u%s", net->neci,
91 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000092}
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{
Harald Welteedb37782009-05-01 14:59:07 +0000105 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,
Harald Welte1bc77352009-03-10 19:47:51 +0000116 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000117 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000118 e1l->tei, e1l->sapi, VTY_NEWLINE);
119}
120
121static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
122{
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200123 vty_out(vty, "BTS %u is of %s type in band %s, has CI %u LAC %u, "
Harald Weltefcd24452009-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 Freytherc4a49e32009-08-21 14:44:12 +0200126 bts->cell_identity,
Harald Weltefcd24452009-06-20 18:15:19 +0200127 bts->location_area_code, bts->bsic, bts->tsc,
128 bts->num_trx, VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200129 if (bts->cell_barred)
130 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000131 if (is_ipaccess_bts(bts))
Harald Welte8175e952009-10-20 00:22:00 +0200132 vty_out(vty, " Unit ID: %u/%u/0, OML Stream ID 0x%02x%s",
Harald Welte4cc34222009-05-01 15:12:31 +0000133 bts->ip_access.site_id, bts->ip_access.bts_id,
Harald Welte8175e952009-10-20 00:22:00 +0200134 bts->oml_tei, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000135 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 Welte8175e952009-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 Welte68628e82009-03-10 12:17:57 +0000145 /* 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) {
Harald Welte1bc77352009-03-10 19:47:51 +0000159 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000160 VTY_NEWLINE);
161 return CMD_WARNING;
162 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200163 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000164 return CMD_SUCCESS;
165 }
166 /* print all BTS's */
167 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200168 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000169
170 return CMD_SUCCESS;
171}
172
Harald Welte42581822009-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 Welte67ce0732009-08-06 19:06:46 +0200201static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
202{
Harald Welte42581822009-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 Welte67ce0732009-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 Welte5013b2a2009-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 Welte42581822009-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 Welte67ce0732009-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 Welte5013b2a2009-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 Freytherf926ed62009-11-19 16:38:49 +0100231 vty_out(vty, " cell_identity %u%s", bts->cell_identity, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200232 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200233 VTY_NEWLINE);
Harald Welte5013b2a2009-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)0e451d02009-08-13 10:14:26 +0200236 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Welte (local)efc92312009-08-14 23:09:25 +0200237 if (bts->chan_desc.t3212)
238 vty_out(vty, " periodic location update %u%s",
239 bts->chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte7a8fa412009-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)5dececf2009-08-12 13:28:23 +0200243 if (bts->cell_barred)
244 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200245 if (is_ipaccess_bts(bts)) {
Harald Welte5013b2a2009-08-07 13:29:14 +0200246 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200247 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200248 vty_out(vty, " oml ip.access stream_id %u%s", bts->oml_tei, VTY_NEWLINE);
249 } else {
Harald Welte42581822009-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 Welte67ce0732009-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 Welte5013b2a2009-08-07 13:29:14 +0200268static int config_write_net(struct vty *vty)
269{
270 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200271 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200272 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-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)69de3972009-08-12 14:42:23 +0200275 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte4381cfe2009-08-30 15:47:06 +0900276 vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
Holger Hans Peter Freytherd54c3372009-11-19 16:37:48 +0100277 vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100278 vty_out(vty, " timer t3101 %u%s", gsmnet->T3101, VTY_NEWLINE);
Holger Hans Peter Freyther23975e72009-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 Welte5013b2a2009-08-07 13:29:14 +0200289
290 return CMD_SUCCESS;
291}
Harald Welte67ce0732009-08-06 19:06:46 +0200292
Harald Welte68628e82009-03-10 12:17:57 +0000293static 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 Weltefcd24452009-06-20 18:15:19 +0200297 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200298 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200299 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200300 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000301 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 Welte8175e952009-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 Welte68628e82009-03-10 12:17:57 +0000312}
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) {
Harald Welte1bc77352009-03-10 19:47:51 +0000328 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000329 VTY_NEWLINE);
330 return CMD_WARNING;
331 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200332 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000333 }
334 if (argc >= 2) {
335 trx_nr = atoi(argv[1]);
336 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000337 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000338 VTY_NEWLINE);
339 return CMD_WARNING;
340 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200341 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000342 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 Weltee441d9c2009-06-21 16:17:15 +0200348 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000349 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 Weltee441d9c2009-06-21 16:17:15 +0200355 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000356 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200357 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000358 trx_dump_vty(vty, trx);
359 }
360 }
361
362 return CMD_SUCCESS;
363}
364
Harald Welte67ce0732009-08-06 19:06:46 +0200365
Harald Welte68628e82009-03-10 12:17:57 +0000366static 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);
Harald Welte68628e82009-03-10 12:17:57 +0000375 if (is_ipaccess_bts(ts->trx->bts)) {
376 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200377 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000378 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200379 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000380 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000381 } 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);
Harald Welte68628e82009-03-10 12:17:57 +0000385 }
386}
387
388DEFUN(show_ts,
389 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000390 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000391 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) {
Harald Welte1bc77352009-03-10 19:47:51 +0000403 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000404 VTY_NEWLINE);
405 return CMD_WARNING;
406 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200407 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000408 }
409 if (argc >= 2) {
410 trx_nr = atoi(argv[1]);
411 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000412 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000413 VTY_NEWLINE);
414 return CMD_WARNING;
415 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200416 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000417 }
418 if (argc >= 3) {
419 ts_nr = atoi(argv[2]);
420 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000421 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000422 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 Weltee441d9c2009-06-21 16:17:15 +0200430 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000431 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200432 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000433 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 Freythercfa90d42009-08-10 10:17:50 +0200443void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte68628e82009-03-10 12:17:57 +0000444{
Harald Weltefcd24452009-06-20 18:15:19 +0200445 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000446 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000447 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000448 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000449 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 Freyther22230252009-08-19 12:53:57 +0200454 if (subscr->tmsi != GSM_RESERVED_TMSI)
455 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte731fd912009-08-15 03:24:51 +0200456 VTY_NEWLINE);
Harald Welte (local)15920de2009-08-14 20:27:16 +0200457 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000458}
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 Welte4bfdfe72009-06-10 23:11:52 +0800476#if 0
477TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000478static 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 Welte4bfdfe72009-06-10 23:11:52 +0800501#endif
Harald Welte68628e82009-03-10 12:17:57 +0000502
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 Weltee441d9c2009-06-21 16:17:15 +0200523 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000524 }
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 Weltee441d9c2009-06-21 16:17:15 +0200532 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000533 }
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 Weltee441d9c2009-06-21 16:17:15 +0200555 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000556 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200557 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000558 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];
Harald Welteef235b52009-03-10 12:34:02 +0000563 if (lchan->type == GSM_LCHAN_NONE)
564 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000565 lchan_dump_vty(vty, lchan);
566 }
567 }
568 }
569 }
570
571 return CMD_SUCCESS;
572}
573
Harald Welte1bc77352009-03-10 19:47:51 +0000574static 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
Harald Welte68628e82009-03-10 12:17:57 +0000592static 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{
Harald Welte1bc77352009-03-10 19:47:51 +0000604 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;
Harald Welte68628e82009-03-10 12:17:57 +0000621}
622
623static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
624{
Harald Welte42581822009-08-08 16:12:58 +0200625 if (ts->type == E1INP_TS_TYPE_NONE)
626 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000627 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);
Harald Welte68628e82009-03-10 12:17:57 +0000630}
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 Welte986c3d72009-11-17 06:12:16 +0100637 struct e1inp_line *line = NULL;
Harald Welte1bc77352009-03-10 19:47:51 +0000638 struct e1inp_ts *ts;
639 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000640
Harald Welte1bc77352009-03-10 19:47:51 +0000641 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;
Harald Welte68628e82009-03-10 12:17:57 +0000680}
681
Harald Weltebe4b7302009-05-23 16:59:33 +0000682static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000683{
684 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
685 subscr_dump_vty(vty, pag->subscr);
686}
687
Harald Weltebe4b7302009-05-23 16:59:33 +0000688static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000689{
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]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000699 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000700{
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 Weltee441d9c2009-06-21 16:17:15 +0200713 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000714 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 Weltee441d9c2009-06-21 16:17:15 +0200719 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000720 bts_paging_dump_vty(vty, bts);
721 }
722
723 return CMD_SUCCESS;
724}
725
Harald Welte5013b2a2009-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 Welte40f82892009-05-23 17:31:39 +0000783
Harald Welte (local)69de3972009-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 Welte4381cfe2009-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.Eversberg1059deb2009-11-17 09:55:26 +0100801 gsmnet->a5_encryption= atoi(argv[0]);
Harald Welte4381cfe2009-08-30 15:47:06 +0900802
803 return CMD_SUCCESS;
804}
805
Holger Hans Peter Freytherf7d752f2009-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 Freytherc4d88ad2009-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 Freyther23975e72009-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 Freytherc4d88ad2009-11-21 21:18:38 +0100844
845
Harald Welte5258fc42009-03-28 19:07:53 +0000846/* 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 Weltee441d9c2009-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 Welte5258fc42009-03-28 19:07:53 +0000858 return CMD_WARNING;
Harald Weltee441d9c2009-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 Welte5258fc42009-03-28 19:07:53 +0000868
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 Weltea6fd58e2009-08-07 00:25:23 +0200882 bts->type = parse_btstype(argv[0]);
883
Harald Welte8175e952009-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 Welte5258fc42009-03-28 19:07:53 +0000889 return CMD_SUCCESS;
890}
891
Harald Weltefcd24452009-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 Welte42581822009-08-08 16:12:58 +0200898 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-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 Freytherc4a49e32009-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 Welte5258fc42009-03-28 19:07:53 +0000929DEFUN(cfg_bts_lac,
930 cfg_bts_lac_cmd,
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200931 "location_area_code <0-65535>",
Harald Welte5258fc42009-03-28 19:07:53 +0000932 "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 Freyther0b7f4b32009-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 Welte5258fc42009-03-28 19:07:53 +0000939 lac, VTY_NEWLINE);
940 return CMD_WARNING;
941 }
Holger Hans Peter Freythere48b9562009-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 Welte5258fc42009-03-28 19:07:53 +0000949 bts->location_area_code = lac;
950
951 return CMD_SUCCESS;
952}
953
954DEFUN(cfg_bts_tsc,
955 cfg_bts_tsc_cmd,
956 "training_sequence_code <0-255>",
957 "Set the Training Sequence Code (TSC) of this BTS\n")
958{
959 struct gsm_bts *bts = vty->index;
960 int tsc = atoi(argv[0]);
961
962 if (tsc < 0 || tsc > 0xff) {
963 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
964 tsc, VTY_NEWLINE);
965 return CMD_WARNING;
966 }
967 bts->tsc = tsc;
968
969 return CMD_SUCCESS;
970}
971
Harald Welte78f2f502009-05-23 16:56:52 +0000972DEFUN(cfg_bts_bsic,
973 cfg_bts_bsic_cmd,
974 "base_station_id_code <0-63>",
975 "Set the Base Station Identity Code (BSIC) of this BTS\n")
976{
977 struct gsm_bts *bts = vty->index;
978 int bsic = atoi(argv[0]);
979
980 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200981 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000982 bsic, VTY_NEWLINE);
983 return CMD_WARNING;
984 }
985 bts->bsic = bsic;
986
987 return CMD_SUCCESS;
988}
989
990
Harald Welte4cc34222009-05-01 15:12:31 +0000991DEFUN(cfg_bts_unit_id,
992 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200993 "ip.access unit_id <0-65534> <0-255>",
994 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000995{
996 struct gsm_bts *bts = vty->index;
997 int site_id = atoi(argv[0]);
998 int bts_id = atoi(argv[1]);
999
Harald Welte07dc73d2009-08-07 13:27:09 +02001000 if (!is_ipaccess_bts(bts)) {
1001 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1002 return CMD_WARNING;
1003 }
1004
Harald Welte4cc34222009-05-01 15:12:31 +00001005 bts->ip_access.site_id = site_id;
1006 bts->ip_access.bts_id = bts_id;
1007
1008 return CMD_SUCCESS;
1009}
1010
Harald Welte8175e952009-10-20 00:22:00 +02001011DEFUN(cfg_bts_stream_id,
1012 cfg_bts_stream_id_cmd,
1013 "oml ip.access stream_id <0-255>",
1014 "Set the ip.access Stream ID of the OML link of this BTS\n")
1015{
1016 struct gsm_bts *bts = vty->index;
1017 int stream_id = atoi(argv[0]);
1018
1019 if (!is_ipaccess_bts(bts)) {
1020 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1021 return CMD_WARNING;
1022 }
1023
1024 bts->oml_tei = stream_id;
1025
1026 return CMD_SUCCESS;
1027}
1028
1029
Harald Welte42581822009-08-08 16:12:58 +02001030DEFUN(cfg_bts_oml_e1,
1031 cfg_bts_oml_e1_cmd,
1032 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1033 "E1 interface to be used for OML\n")
1034{
1035 struct gsm_bts *bts = vty->index;
1036
1037 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
1038
1039 return CMD_SUCCESS;
1040}
1041
1042
1043DEFUN(cfg_bts_oml_e1_tei,
1044 cfg_bts_oml_e1_tei_cmd,
1045 "oml e1 tei <0-63>",
1046 "Set the TEI to be used for OML")
1047{
1048 struct gsm_bts *bts = vty->index;
1049
1050 bts->oml_tei = atoi(argv[0]);
1051
1052 return CMD_SUCCESS;
1053}
1054
Harald Welte7a8fa412009-08-10 13:48:16 +02001055DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1056 "channel allocator (ascending|descending)",
1057 "Should the channel allocator allocate in reverse TRX order?")
1058{
1059 struct gsm_bts *bts = vty->index;
1060
1061 if (!strcmp(argv[0], "ascending"))
1062 bts->chan_alloc_reverse = 0;
1063 else
1064 bts->chan_alloc_reverse = 1;
1065
1066 return CMD_SUCCESS;
1067}
1068
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001069DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1070 "cell barred (0|1)",
1071 "Should this cell be barred from access?")
1072{
1073 struct gsm_bts *bts = vty->index;
1074
1075 bts->cell_barred = atoi(argv[0]);
1076
1077 return CMD_SUCCESS;
1078}
1079
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001080DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1081 "ms max power <0-40>",
1082 "Maximum transmit power of the MS")
1083{
1084 struct gsm_bts *bts = vty->index;
1085
1086 bts->ms_max_power = atoi(argv[0]);
1087
1088 return CMD_SUCCESS;
1089}
1090
Harald Welte (local)efc92312009-08-14 23:09:25 +02001091DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1092 "periodic location update <0-1530>",
1093 "Periodic Location Updating Interval in Minutes")
1094{
1095 struct gsm_bts *bts = vty->index;
1096
1097 bts->chan_desc.t3212 = atoi(argv[0]) / 10;
1098
1099 return CMD_SUCCESS;
1100}
1101
Harald Welte7a8fa412009-08-10 13:48:16 +02001102
Harald Welte5258fc42009-03-28 19:07:53 +00001103/* per TRX configuration */
1104DEFUN(cfg_trx,
1105 cfg_trx_cmd,
1106 "trx TRX_NR",
1107 "Select a TRX to configure")
1108{
1109 int trx_nr = atoi(argv[0]);
1110 struct gsm_bts *bts = vty->index;
1111 struct gsm_bts_trx *trx;
1112
Harald Weltee441d9c2009-06-21 16:17:15 +02001113 if (trx_nr > bts->num_trx) {
1114 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1115 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +00001116 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +02001117 } else if (trx_nr == bts->num_trx) {
1118 /* we need to allocate a new one */
1119 trx = gsm_bts_trx_alloc(bts);
1120 } else
1121 trx = gsm_bts_trx_num(bts, trx_nr);
1122
1123 if (!trx)
1124 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001125
1126 vty->index = trx;
1127 vty->node = TRX_NODE;
1128
1129 return CMD_SUCCESS;
1130}
1131
1132DEFUN(cfg_trx_arfcn,
1133 cfg_trx_arfcn_cmd,
1134 "arfcn <1-1024>",
1135 "Set the ARFCN for this TRX\n")
1136{
1137 int arfcn = atoi(argv[0]);
1138 struct gsm_bts_trx *trx = vty->index;
1139
1140 /* FIXME: check if this ARFCN is supported by this TRX */
1141
1142 trx->arfcn = arfcn;
1143
1144 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1145 /* FIXME: use OML layer to update the ARFCN */
1146 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1147
1148 return CMD_SUCCESS;
1149}
1150
Harald Weltefcd24452009-06-20 18:15:19 +02001151DEFUN(cfg_trx_max_power_red,
1152 cfg_trx_max_power_red_cmd,
1153 "max_power_red <0-100>",
1154 "Reduction of maximum BS RF Power in dB\n")
1155{
1156 int maxpwr_r = atoi(argv[0]);
1157 struct gsm_bts_trx *trx = vty->index;
Harald Welte61a83b22009-11-18 09:20:22 +01001158 int upper_limit = 24; /* default 12.21 max power red. */
Harald Weltefcd24452009-06-20 18:15:19 +02001159
1160 /* FIXME: check if our BTS type supports more than 12 */
1161 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1162 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1163 maxpwr_r, VTY_NEWLINE);
1164 return CMD_WARNING;
1165 }
1166 if (maxpwr_r & 1) {
1167 vty_out(vty, "%% Power %d dB is not an even value%s",
1168 maxpwr_r, VTY_NEWLINE);
1169 return CMD_WARNING;
1170 }
1171
1172 trx->max_power_red = maxpwr_r;
1173
1174 /* FIXME: make sure we update this using OML */
1175
1176 return CMD_SUCCESS;
1177}
1178
Harald Welte42581822009-08-08 16:12:58 +02001179DEFUN(cfg_trx_rsl_e1,
1180 cfg_trx_rsl_e1_cmd,
1181 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1182 "E1 interface to be used for RSL\n")
1183{
1184 struct gsm_bts_trx *trx = vty->index;
1185
1186 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1187
1188 return CMD_SUCCESS;
1189}
1190
1191DEFUN(cfg_trx_rsl_e1_tei,
1192 cfg_trx_rsl_e1_tei_cmd,
1193 "rsl e1 tei <0-63>",
1194 "Set the TEI to be used for RSL")
1195{
1196 struct gsm_bts_trx *trx = vty->index;
1197
1198 trx->rsl_tei = atoi(argv[0]);
1199
1200 return CMD_SUCCESS;
1201}
1202
1203
Harald Welte5258fc42009-03-28 19:07:53 +00001204/* per TS configuration */
1205DEFUN(cfg_ts,
1206 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001207 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001208 "Select a Timeslot to configure")
1209{
1210 int ts_nr = atoi(argv[0]);
1211 struct gsm_bts_trx *trx = vty->index;
1212 struct gsm_bts_trx_ts *ts;
1213
1214 if (ts_nr >= TRX_NR_TS) {
1215 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1216 TRX_NR_TS, VTY_NEWLINE);
1217 return CMD_WARNING;
1218 }
1219
1220 ts = &trx->ts[ts_nr];
1221
1222 vty->index = ts;
1223 vty->node = TS_NODE;
1224
1225 return CMD_SUCCESS;
1226}
1227
Harald Weltea6fd58e2009-08-07 00:25:23 +02001228DEFUN(cfg_ts_pchan,
1229 cfg_ts_pchan_cmd,
1230 "phys_chan_config PCHAN",
1231 "Physical Channel configuration (TCH/SDCCH/...)")
1232{
1233 struct gsm_bts_trx_ts *ts = vty->index;
1234 int pchanc;
1235
1236 pchanc = gsm_pchan_parse(argv[0]);
1237 if (pchanc < 0)
1238 return CMD_WARNING;
1239
1240 ts->pchan = pchanc;
1241
1242 return CMD_SUCCESS;
1243}
1244
1245DEFUN(cfg_ts_e1_subslot,
1246 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001247 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001248 "E1 sub-slot connected to this on-air timeslot")
1249{
1250 struct gsm_bts_trx_ts *ts = vty->index;
1251
Harald Welte42581822009-08-08 16:12:58 +02001252 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001253
1254 return CMD_SUCCESS;
1255}
Harald Welte5258fc42009-03-28 19:07:53 +00001256
Harald Welte68628e82009-03-10 12:17:57 +00001257int bsc_vty_init(struct gsm_network *net)
1258{
1259 gsmnet = net;
1260
1261 cmd_init(1);
1262 vty_init();
1263
1264 install_element(VIEW_NODE, &show_net_cmd);
1265 install_element(VIEW_NODE, &show_bts_cmd);
1266 install_element(VIEW_NODE, &show_trx_cmd);
1267 install_element(VIEW_NODE, &show_ts_cmd);
1268 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001269
1270 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001271 install_element(VIEW_NODE, &show_e1line_cmd);
1272 install_element(VIEW_NODE, &show_e1ts_cmd);
1273
Harald Weltef5025b62009-03-28 16:55:11 +00001274 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001275
Harald Welte5013b2a2009-08-07 13:29:14 +02001276 install_element(CONFIG_NODE, &cfg_net_cmd);
1277 install_node(&net_node, config_write_net);
1278 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001279 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001280 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1281 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1282 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001283 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte4381cfe2009-08-30 15:47:06 +09001284 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001285 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001286 install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001287 install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
1288 install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
1289 install_element(GSMNET_NODE, &cfg_net_T3107_cmd);
1290 install_element(GSMNET_NODE, &cfg_net_T3109_cmd);
1291 install_element(GSMNET_NODE, &cfg_net_T3111_cmd);
1292 install_element(GSMNET_NODE, &cfg_net_T3113_cmd);
1293 install_element(GSMNET_NODE, &cfg_net_T3115_cmd);
1294 install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
1295 install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
1296 install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001297
1298 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001299 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001300 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001301 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001302 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +02001303 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001304 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1305 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001306 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001307 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte8175e952009-10-20 00:22:00 +02001308 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001309 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1310 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001311 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001312 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001313 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)efc92312009-08-14 23:09:25 +02001314 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001315
Harald Welte68628e82009-03-10 12:17:57 +00001316
Harald Welte5258fc42009-03-28 19:07:53 +00001317 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001318 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001319 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001320 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001321 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001322 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1323 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001324
Harald Welte5258fc42009-03-28 19:07:53 +00001325 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001326 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001327 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001328 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1329 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001330
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02001331 bsc_vty_init_extra(net);
Harald Welte40f82892009-05-23 17:31:39 +00001332
Harald Welte68628e82009-03-10 12:17:57 +00001333 return 0;
1334}