blob: 0ebd2bd9d2d02f4a320da8cdec121514ace29036 [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 Welte (local)5dececf2009-08-12 13:28:23 +0200131 if (bts->cell_barred)
132 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000133 if (is_ipaccess_bts(bts))
Harald Welte8175e952009-10-20 00:22:00 +0200134 vty_out(vty, " Unit ID: %u/%u/0, OML Stream ID 0x%02x%s",
Harald Welte4cc34222009-05-01 15:12:31 +0000135 bts->ip_access.site_id, bts->ip_access.bts_id,
Harald Welte8175e952009-10-20 00:22:00 +0200136 bts->oml_tei, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000137 vty_out(vty, " NM State: ");
138 net_dump_nmstate(vty, &bts->nm_state);
139 vty_out(vty, " Site Mgr NM State: ");
140 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
141 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
142 bts->paging.available_slots, VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200143 if (!is_ipaccess_bts(bts)) {
144 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
145 e1isl_dump_vty(vty, bts->oml_link);
146 }
Harald Welte68628e82009-03-10 12:17:57 +0000147 /* FIXME: oml_link, chan_desc */
148}
149
150DEFUN(show_bts, show_bts_cmd, "show bts [number]",
151 SHOW_STR "Display information about a BTS\n"
152 "BTS number")
153{
154 struct gsm_network *net = gsmnet;
155 int bts_nr;
156
157 if (argc != 0) {
158 /* use the BTS number that the user has specified */
159 bts_nr = atoi(argv[0]);
160 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000161 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000162 VTY_NEWLINE);
163 return CMD_WARNING;
164 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200165 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000166 return CMD_SUCCESS;
167 }
168 /* print all BTS's */
169 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200170 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000171
172 return CMD_SUCCESS;
173}
174
Harald Welte42581822009-08-08 16:12:58 +0200175/* utility functions */
176static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
177 const char *ts, const char *ss)
178{
179 e1_link->e1_nr = atoi(line);
180 e1_link->e1_ts = atoi(ts);
181 if (!strcmp(ss, "full"))
182 e1_link->e1_ts_ss = 255;
183 else
184 e1_link->e1_ts_ss = atoi(ss);
185}
186
187static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
188 const char *prefix)
189{
190 if (!e1_link->e1_ts)
191 return;
192
193 if (e1_link->e1_ts_ss == 255)
194 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
195 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
196 else
197 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
198 prefix, e1_link->e1_nr, e1_link->e1_ts,
199 e1_link->e1_ts_ss, VTY_NEWLINE);
200}
201
202
Harald Welte67ce0732009-08-06 19:06:46 +0200203static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
204{
Harald Welte42581822009-08-08 16:12:58 +0200205 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
206 if (ts->pchan != GSM_PCHAN_NONE)
207 vty_out(vty, " phys_chan_config %s%s",
208 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
209 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte67ce0732009-08-06 19:06:46 +0200210}
211
212static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
213{
214 int i;
215
Harald Welte5013b2a2009-08-07 13:29:14 +0200216 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
217 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
218 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200219 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
220 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200221
222 for (i = 0; i < TRX_NR_TS; i++)
223 config_write_ts_single(vty, &trx->ts[i]);
224}
225
226static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
227{
228 struct gsm_bts_trx *trx;
229
Harald Welte5013b2a2009-08-07 13:29:14 +0200230 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
231 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
232 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
Holger Hans Peter Freytherf926ed62009-11-19 16:38:49 +0100233 vty_out(vty, " cell_identity %u%s", bts->cell_identity, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200234 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200235 VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200236 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
237 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200238 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Weltea43f7892009-12-01 18:04:30 +0530239 if (bts->si_common.chan_desc.t3212)
Harald Welte (local)efc92312009-08-14 23:09:25 +0200240 vty_out(vty, " periodic location update %u%s",
Harald Weltea43f7892009-12-01 18:04:30 +0530241 bts->si_common.chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte7a8fa412009-08-10 13:48:16 +0200242 vty_out(vty, " channel allocator %s%s",
243 bts->chan_alloc_reverse ? "descending" : "ascending",
244 VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200245 if (bts->cell_barred)
246 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200247 if (is_ipaccess_bts(bts)) {
Harald Welte5013b2a2009-08-07 13:29:14 +0200248 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200249 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200250 vty_out(vty, " oml ip.access stream_id %u%s", bts->oml_tei, VTY_NEWLINE);
251 } else {
Harald Welte42581822009-08-08 16:12:58 +0200252 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
253 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
254 }
Harald Welte67ce0732009-08-06 19:06:46 +0200255
256 llist_for_each_entry(trx, &bts->trx_list, list)
257 config_write_trx_single(vty, trx);
258}
259
260static int config_write_bts(struct vty *v)
261{
262 struct gsm_bts *bts;
263
264 llist_for_each_entry(bts, &gsmnet->bts_list, list)
265 config_write_bts_single(v, bts);
266
267 return CMD_SUCCESS;
268}
269
Harald Welte5013b2a2009-08-07 13:29:14 +0200270static int config_write_net(struct vty *vty)
271{
272 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200273 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200274 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200275 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
276 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +0200277 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte1085c092009-11-18 20:33:19 +0100278 vty_out(vty, " location updating reject cause %u%s",
279 gsmnet->reject_cause, VTY_NEWLINE);
Harald Welte4381cfe2009-08-30 15:47:06 +0900280 vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
Holger Hans Peter Freytherd54c3372009-11-19 16:37:48 +0100281 vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100282 vty_out(vty, " timer t3101 %u%s", gsmnet->T3101, VTY_NEWLINE);
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100283 vty_out(vty, " timer t3103 %u%s", gsmnet->T3103, VTY_NEWLINE);
284 vty_out(vty, " timer t3105 %u%s", gsmnet->T3105, VTY_NEWLINE);
285 vty_out(vty, " timer t3107 %u%s", gsmnet->T3107, VTY_NEWLINE);
286 vty_out(vty, " timer t3109 %u%s", gsmnet->T3109, VTY_NEWLINE);
287 vty_out(vty, " timer t3111 %u%s", gsmnet->T3111, VTY_NEWLINE);
288 vty_out(vty, " timer t3113 %u%s", gsmnet->T3113, VTY_NEWLINE);
289 vty_out(vty, " timer t3115 %u%s", gsmnet->T3115, VTY_NEWLINE);
290 vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
291 vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
292 vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200293
294 return CMD_SUCCESS;
295}
Harald Welte67ce0732009-08-06 19:06:46 +0200296
Harald Welte68628e82009-03-10 12:17:57 +0000297static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
298{
299 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
300 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200301 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200302 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200303 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200304 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000305 vty_out(vty, " NM State: ");
306 net_dump_nmstate(vty, &trx->nm_state);
307 vty_out(vty, " Baseband Transceiver NM State: ");
308 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
Harald Welte8175e952009-10-20 00:22:00 +0200309 if (is_ipaccess_bts(trx->bts)) {
310 vty_out(vty, " ip.access stream ID: 0x%02x%s",
311 trx->rsl_tei, VTY_NEWLINE);
312 } else {
313 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
314 e1isl_dump_vty(vty, trx->rsl_link);
315 }
Harald Welte68628e82009-03-10 12:17:57 +0000316}
317
318DEFUN(show_trx,
319 show_trx_cmd,
320 "show trx [bts_nr] [trx_nr]",
321 SHOW_STR "Display information about a TRX\n")
322{
323 struct gsm_network *net = gsmnet;
324 struct gsm_bts *bts = NULL;
325 struct gsm_bts_trx *trx;
326 int bts_nr, trx_nr;
327
328 if (argc >= 1) {
329 /* use the BTS number that the user has specified */
330 bts_nr = atoi(argv[0]);
331 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000332 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000333 VTY_NEWLINE);
334 return CMD_WARNING;
335 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200336 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000337 }
338 if (argc >= 2) {
339 trx_nr = atoi(argv[1]);
340 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000341 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000342 VTY_NEWLINE);
343 return CMD_WARNING;
344 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200345 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000346 trx_dump_vty(vty, trx);
347 return CMD_SUCCESS;
348 }
349 if (bts) {
350 /* print all TRX in this BTS */
351 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200352 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000353 trx_dump_vty(vty, trx);
354 }
355 return CMD_SUCCESS;
356 }
357
358 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200359 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000360 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200361 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000362 trx_dump_vty(vty, trx);
363 }
364 }
365
366 return CMD_SUCCESS;
367}
368
Harald Welte67ce0732009-08-06 19:06:46 +0200369
Harald Welte68628e82009-03-10 12:17:57 +0000370static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
371{
Harald Welte68628e82009-03-10 12:17:57 +0000372 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
373 ts->nr, ts->trx->nr, ts->trx->bts->nr,
374 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
375 vty_out(vty, " NM State: ");
376 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte2c828992009-12-02 01:56:49 +0530377 if (!is_ipaccess_bts(ts->trx->bts))
Harald Welteef235b52009-03-10 12:34:02 +0000378 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
379 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
380 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000381}
382
383DEFUN(show_ts,
384 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000385 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000386 SHOW_STR "Display information about a TS\n")
387{
388 struct gsm_network *net = gsmnet;
389 struct gsm_bts *bts;
390 struct gsm_bts_trx *trx;
391 struct gsm_bts_trx_ts *ts;
392 int bts_nr, trx_nr, ts_nr;
393
394 if (argc >= 1) {
395 /* use the BTS number that the user has specified */
396 bts_nr = atoi(argv[0]);
397 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000398 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000399 VTY_NEWLINE);
400 return CMD_WARNING;
401 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200402 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000403 }
404 if (argc >= 2) {
405 trx_nr = atoi(argv[1]);
406 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000407 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000408 VTY_NEWLINE);
409 return CMD_WARNING;
410 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200411 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000412 }
413 if (argc >= 3) {
414 ts_nr = atoi(argv[2]);
415 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000416 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000417 VTY_NEWLINE);
418 return CMD_WARNING;
419 }
420 ts = &trx->ts[ts_nr];
421 ts_dump_vty(vty, ts);
422 return CMD_SUCCESS;
423 }
424 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200425 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000426 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200427 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000428 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
429 ts = &trx->ts[ts_nr];
430 ts_dump_vty(vty, ts);
431 }
432 }
433 }
434
435 return CMD_SUCCESS;
436}
437
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200438void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte68628e82009-03-10 12:17:57 +0000439{
Harald Weltefcd24452009-06-20 18:15:19 +0200440 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000441 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000442 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000443 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000444 if (subscr->extension)
445 vty_out(vty, " Extension: %s%s", subscr->extension,
446 VTY_NEWLINE);
447 if (subscr->imsi)
448 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200449 if (subscr->tmsi != GSM_RESERVED_TMSI)
450 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte731fd912009-08-15 03:24:51 +0200451 VTY_NEWLINE);
Harald Welte (local)15920de2009-08-14 20:27:16 +0200452 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000453}
454
455static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
456{
457 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
458 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
459 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
460 VTY_NEWLINE);
461 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
462 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
463 lchan->ms_power, VTY_NEWLINE);
464 if (lchan->subscr) {
465 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
466 subscr_dump_vty(vty, lchan->subscr);
467 } else
468 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
Harald Welte2c828992009-12-02 01:56:49 +0530469 if (is_ipaccess_bts(lchan->ts->trx->bts)) {
470 struct in_addr ia;
471 ia.s_addr = lchan->abis_ip.bound_ip;
472 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
473 inet_ntoa(ia), lchan->abis_ip.bound_port,
474 lchan->abis_ip.rtp_payload2, lchan->abis_ip.conn_id,
475 VTY_NEWLINE);
476 }
Harald Welte68628e82009-03-10 12:17:57 +0000477}
478
Harald Welte4bfdfe72009-06-10 23:11:52 +0800479#if 0
480TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000481static void call_dump_vty(struct vty *vty, struct gsm_call *call)
482{
483 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
484 call->type, call->state, call->transaction_id, VTY_NEWLINE);
485
486 if (call->local_lchan) {
487 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
488 lchan_dump_vty(vty, call->local_lchan);
489 } else
490 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
491
492 if (call->remote_lchan) {
493 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
494 lchan_dump_vty(vty, call->remote_lchan);
495 } else
496 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
497
498 if (call->called_subscr) {
499 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
500 subscr_dump_vty(vty, call->called_subscr);
501 } else
502 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
503}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800504#endif
Harald Welte68628e82009-03-10 12:17:57 +0000505
506DEFUN(show_lchan,
507 show_lchan_cmd,
508 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
509 SHOW_STR "Display information about a logical channel\n")
510{
511 struct gsm_network *net = gsmnet;
512 struct gsm_bts *bts;
513 struct gsm_bts_trx *trx;
514 struct gsm_bts_trx_ts *ts;
515 struct gsm_lchan *lchan;
516 int bts_nr, trx_nr, ts_nr, lchan_nr;
517
518 if (argc >= 1) {
519 /* use the BTS number that the user has specified */
520 bts_nr = atoi(argv[0]);
521 if (bts_nr >= net->num_bts) {
522 vty_out(vty, "%% can't find BTS %s%s", argv[0],
523 VTY_NEWLINE);
524 return CMD_WARNING;
525 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200526 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000527 }
528 if (argc >= 2) {
529 trx_nr = atoi(argv[1]);
530 if (trx_nr >= bts->num_trx) {
531 vty_out(vty, "%% can't find TRX %s%s", argv[1],
532 VTY_NEWLINE);
533 return CMD_WARNING;
534 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200535 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000536 }
537 if (argc >= 3) {
538 ts_nr = atoi(argv[2]);
539 if (ts_nr >= TRX_NR_TS) {
540 vty_out(vty, "%% can't find TS %s%s", argv[2],
541 VTY_NEWLINE);
542 return CMD_WARNING;
543 }
544 ts = &trx->ts[ts_nr];
545 }
546 if (argc >= 4) {
547 lchan_nr = atoi(argv[3]);
548 if (lchan_nr >= TS_MAX_LCHAN) {
549 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
550 VTY_NEWLINE);
551 return CMD_WARNING;
552 }
553 lchan = &ts->lchan[lchan_nr];
554 lchan_dump_vty(vty, lchan);
555 return CMD_SUCCESS;
556 }
557 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200558 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000559 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200560 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000561 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
562 ts = &trx->ts[ts_nr];
563 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
564 lchan_nr++) {
565 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000566 if (lchan->type == GSM_LCHAN_NONE)
567 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000568 lchan_dump_vty(vty, lchan);
569 }
570 }
571 }
572 }
573
574 return CMD_SUCCESS;
575}
576
Harald Welte1bc77352009-03-10 19:47:51 +0000577static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
578{
579 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
580}
581
582DEFUN(show_e1drv,
583 show_e1drv_cmd,
584 "show e1_driver",
585 SHOW_STR "Display information about available E1 drivers\n")
586{
587 struct e1inp_driver *drv;
588
589 llist_for_each_entry(drv, &e1inp_driver_list, list)
590 e1drv_dump_vty(vty, drv);
591
592 return CMD_SUCCESS;
593}
594
Harald Welte68628e82009-03-10 12:17:57 +0000595static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
596{
597 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
598 line->num, line->name ? line->name : "",
599 line->driver->name, VTY_NEWLINE);
600}
601
602DEFUN(show_e1line,
603 show_e1line_cmd,
604 "show e1_line [line_nr]",
605 SHOW_STR "Display information about a E1 line\n")
606{
Harald Welte1bc77352009-03-10 19:47:51 +0000607 struct e1inp_line *line;
608
609 if (argc >= 1) {
610 int num = atoi(argv[0]);
611 llist_for_each_entry(line, &e1inp_line_list, list) {
612 if (line->num == num) {
613 e1line_dump_vty(vty, line);
614 return CMD_SUCCESS;
615 }
616 }
617 return CMD_WARNING;
618 }
619
620 llist_for_each_entry(line, &e1inp_line_list, list)
621 e1line_dump_vty(vty, line);
622
623 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000624}
625
626static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
627{
Harald Welte42581822009-08-08 16:12:58 +0200628 if (ts->type == E1INP_TS_TYPE_NONE)
629 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000630 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
631 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
632 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000633}
634
635DEFUN(show_e1ts,
636 show_e1ts_cmd,
637 "show e1_timeslot [line_nr] [ts_nr]",
638 SHOW_STR "Display information about a E1 timeslot\n")
639{
Harald Welte986c3d72009-11-17 06:12:16 +0100640 struct e1inp_line *line = NULL;
Harald Welte1bc77352009-03-10 19:47:51 +0000641 struct e1inp_ts *ts;
642 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000643
Harald Welte1bc77352009-03-10 19:47:51 +0000644 if (argc == 0) {
645 llist_for_each_entry(line, &e1inp_line_list, list) {
646 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
647 ts = &line->ts[ts_nr];
648 e1ts_dump_vty(vty, ts);
649 }
650 }
651 return CMD_SUCCESS;
652 }
653 if (argc >= 1) {
654 int num = atoi(argv[0]);
655 llist_for_each_entry(line, &e1inp_line_list, list) {
656 if (line->num == num)
657 break;
658 }
659 if (!line || line->num != num) {
660 vty_out(vty, "E1 line %s is invalid%s",
661 argv[0], VTY_NEWLINE);
662 return CMD_WARNING;
663 }
664 }
665 if (argc >= 2) {
666 ts_nr = atoi(argv[1]);
667 if (ts_nr > NUM_E1_TS) {
668 vty_out(vty, "E1 timeslot %s is invalid%s",
669 argv[1], VTY_NEWLINE);
670 return CMD_WARNING;
671 }
672 ts = &line->ts[ts_nr];
673 e1ts_dump_vty(vty, ts);
674 return CMD_SUCCESS;
675 } else {
676 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
677 ts = &line->ts[ts_nr];
678 e1ts_dump_vty(vty, ts);
679 }
680 return CMD_SUCCESS;
681 }
682 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000683}
684
Harald Weltebe4b7302009-05-23 16:59:33 +0000685static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000686{
687 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
688 subscr_dump_vty(vty, pag->subscr);
689}
690
Harald Weltebe4b7302009-05-23 16:59:33 +0000691static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000692{
693 struct gsm_paging_request *pag;
694
695 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
696 paging_dump_vty(vty, pag);
697}
698
699DEFUN(show_paging,
700 show_paging_cmd,
701 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000702 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000703{
704 struct gsm_network *net = gsmnet;
705 struct gsm_bts *bts;
706 int bts_nr;
707
708 if (argc >= 1) {
709 /* use the BTS number that the user has specified */
710 bts_nr = atoi(argv[0]);
711 if (bts_nr >= net->num_bts) {
712 vty_out(vty, "%% can't find BTS %s%s", argv[0],
713 VTY_NEWLINE);
714 return CMD_WARNING;
715 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200716 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000717 bts_paging_dump_vty(vty, bts);
718
719 return CMD_SUCCESS;
720 }
721 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
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
726 return CMD_SUCCESS;
727}
728
Harald Welte5013b2a2009-08-07 13:29:14 +0200729DEFUN(cfg_net,
730 cfg_net_cmd,
731 "network",
732 "Configure the GSM network")
733{
734 vty->index = gsmnet;
735 vty->node = GSMNET_NODE;
736
737 return CMD_SUCCESS;
738}
739
740
741DEFUN(cfg_net_ncc,
742 cfg_net_ncc_cmd,
743 "network country code <1-999>",
744 "Set the GSM network country code")
745{
746 gsmnet->country_code = atoi(argv[0]);
747
748 return CMD_SUCCESS;
749}
750
751DEFUN(cfg_net_mnc,
752 cfg_net_mnc_cmd,
753 "mobile network code <1-999>",
754 "Set the GSM mobile network code")
755{
756 gsmnet->network_code = atoi(argv[0]);
757
758 return CMD_SUCCESS;
759}
760
761DEFUN(cfg_net_name_short,
762 cfg_net_name_short_cmd,
763 "short name NAME",
764 "Set the short GSM network name")
765{
766 if (gsmnet->name_short)
767 talloc_free(gsmnet->name_short);
768
769 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
770
771 return CMD_SUCCESS;
772}
773
774DEFUN(cfg_net_name_long,
775 cfg_net_name_long_cmd,
776 "long name NAME",
777 "Set the long GSM network name")
778{
779 if (gsmnet->name_long)
780 talloc_free(gsmnet->name_long);
781
782 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
783
784 return CMD_SUCCESS;
785}
Harald Welte40f82892009-05-23 17:31:39 +0000786
Harald Welte (local)69de3972009-08-12 14:42:23 +0200787DEFUN(cfg_net_auth_policy,
788 cfg_net_auth_policy_cmd,
789 "auth policy (closed|accept-all|token)",
790 "Set the GSM network authentication policy\n")
791{
792 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
793
794 gsmnet->auth_policy = policy;
795
796 return CMD_SUCCESS;
797}
798
Harald Welte1085c092009-11-18 20:33:19 +0100799DEFUN(cfg_net_reject_cause,
800 cfg_net_reject_cause_cmd,
801 "location updating reject cause <2-111>",
802 "Set the reject cause of location updating reject\n")
803{
804 gsmnet->reject_cause = atoi(argv[0]);
805
806 return CMD_SUCCESS;
807}
808
Harald Welte4381cfe2009-08-30 15:47:06 +0900809DEFUN(cfg_net_encryption,
810 cfg_net_encryption_cmd,
811 "encryption a5 (0|1|2)",
812 "Enable or disable encryption (A5) for this network\n")
813{
Andreas.Eversberg1059deb2009-11-17 09:55:26 +0100814 gsmnet->a5_encryption= atoi(argv[0]);
Harald Welte4381cfe2009-08-30 15:47:06 +0900815
816 return CMD_SUCCESS;
817}
818
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100819DEFUN(cfg_net_neci,
820 cfg_net_neci_cmd,
821 "neci (0|1)",
822 "Set if NECI of cell selection is to be set")
823{
824 gsmnet->neci = atoi(argv[0]);
825 return CMD_SUCCESS;
826}
827
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100828#define DECLARE_TIMER(number) \
829 DEFUN(cfg_net_T##number, \
830 cfg_net_T##number##_cmd, \
831 "timer t" #number " <0-65535>", \
832 "Set the T" #number " value.") \
833{ \
834 int value = atoi(argv[0]); \
835 \
836 if (value < 0 || value > 65535) { \
837 vty_out(vty, "Timer value %s out of range.%s", \
838 argv[0], VTY_NEWLINE); \
839 return CMD_WARNING; \
840 } \
841 \
842 gsmnet->T##number = value; \
843 return CMD_SUCCESS; \
844}
845
846DECLARE_TIMER(3101)
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100847DECLARE_TIMER(3103)
848DECLARE_TIMER(3105)
849DECLARE_TIMER(3107)
850DECLARE_TIMER(3109)
851DECLARE_TIMER(3111)
852DECLARE_TIMER(3113)
853DECLARE_TIMER(3115)
854DECLARE_TIMER(3117)
855DECLARE_TIMER(3119)
856DECLARE_TIMER(3141)
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100857
858
Harald Welte5258fc42009-03-28 19:07:53 +0000859/* per-BTS configuration */
860DEFUN(cfg_bts,
861 cfg_bts_cmd,
862 "bts BTS_NR",
863 "Select a BTS to configure\n")
864{
865 int bts_nr = atoi(argv[0]);
866 struct gsm_bts *bts;
867
Harald Weltee441d9c2009-06-21 16:17:15 +0200868 if (bts_nr > gsmnet->num_bts) {
869 vty_out(vty, "%% The next unused BTS number is %u%s",
870 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000871 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200872 } else if (bts_nr == gsmnet->num_bts) {
873 /* allocate a new one */
874 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
875 HARDCODED_TSC, HARDCODED_BSIC);
876 } else
877 bts = gsm_bts_num(gsmnet, bts_nr);
878
879 if (!bts)
880 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000881
882 vty->index = bts;
883 vty->node = BTS_NODE;
884
885 return CMD_SUCCESS;
886}
887
888DEFUN(cfg_bts_type,
889 cfg_bts_type_cmd,
890 "type TYPE",
891 "Set the BTS type\n")
892{
893 struct gsm_bts *bts = vty->index;
894
Harald Weltea6fd58e2009-08-07 00:25:23 +0200895 bts->type = parse_btstype(argv[0]);
896
Harald Welte8175e952009-10-20 00:22:00 +0200897 if (is_ipaccess_bts(bts)) {
898 /* Set the default OML Stream ID to 0xff */
899 bts->oml_tei = 0xff;
900 }
901
Harald Welte5258fc42009-03-28 19:07:53 +0000902 return CMD_SUCCESS;
903}
904
Harald Weltefcd24452009-06-20 18:15:19 +0200905DEFUN(cfg_bts_band,
906 cfg_bts_band_cmd,
907 "band BAND",
908 "Set the frequency band of this BTS\n")
909{
910 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200911 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200912
913 if (band < 0) {
914 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
915 band, VTY_NEWLINE);
916 return CMD_WARNING;
917 }
918
919 bts->band = band;
920
921 return CMD_SUCCESS;
922}
923
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200924DEFUN(cfg_bts_ci,
925 cfg_bts_ci_cmd,
926 "cell_identity <0-65535>",
927 "Set the Cell identity of this BTS\n")
928{
929 struct gsm_bts *bts = vty->index;
930 int ci = atoi(argv[0]);
931
932 if (ci < 0 || ci > 0xffff) {
933 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
934 ci, VTY_NEWLINE);
935 return CMD_WARNING;
936 }
937 bts->cell_identity = ci;
938
939 return CMD_SUCCESS;
940}
941
Harald Welte5258fc42009-03-28 19:07:53 +0000942DEFUN(cfg_bts_lac,
943 cfg_bts_lac_cmd,
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200944 "location_area_code <0-65535>",
Harald Welte5258fc42009-03-28 19:07:53 +0000945 "Set the Location Area Code (LAC) of this BTS\n")
946{
947 struct gsm_bts *bts = vty->index;
948 int lac = atoi(argv[0]);
949
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200950 if (lac < 0 || lac > 0xffff) {
951 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte5258fc42009-03-28 19:07:53 +0000952 lac, VTY_NEWLINE);
953 return CMD_WARNING;
954 }
Holger Hans Peter Freythere48b9562009-10-01 04:07:15 +0200955
956 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
957 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
958 lac, VTY_NEWLINE);
959 return CMD_WARNING;
960 }
961
Harald Welte5258fc42009-03-28 19:07:53 +0000962 bts->location_area_code = lac;
963
964 return CMD_SUCCESS;
965}
966
Harald Weltea43f7892009-12-01 18:04:30 +0530967
Harald Welte5258fc42009-03-28 19:07:53 +0000968DEFUN(cfg_bts_tsc,
969 cfg_bts_tsc_cmd,
970 "training_sequence_code <0-255>",
971 "Set the Training Sequence Code (TSC) of this BTS\n")
972{
973 struct gsm_bts *bts = vty->index;
974 int tsc = atoi(argv[0]);
975
976 if (tsc < 0 || tsc > 0xff) {
977 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
978 tsc, VTY_NEWLINE);
979 return CMD_WARNING;
980 }
981 bts->tsc = tsc;
982
983 return CMD_SUCCESS;
984}
985
Harald Welte78f2f502009-05-23 16:56:52 +0000986DEFUN(cfg_bts_bsic,
987 cfg_bts_bsic_cmd,
988 "base_station_id_code <0-63>",
989 "Set the Base Station Identity Code (BSIC) of this BTS\n")
990{
991 struct gsm_bts *bts = vty->index;
992 int bsic = atoi(argv[0]);
993
994 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200995 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000996 bsic, VTY_NEWLINE);
997 return CMD_WARNING;
998 }
999 bts->bsic = bsic;
1000
1001 return CMD_SUCCESS;
1002}
1003
1004
Harald Welte4cc34222009-05-01 15:12:31 +00001005DEFUN(cfg_bts_unit_id,
1006 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +02001007 "ip.access unit_id <0-65534> <0-255>",
1008 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +00001009{
1010 struct gsm_bts *bts = vty->index;
1011 int site_id = atoi(argv[0]);
1012 int bts_id = atoi(argv[1]);
1013
Harald Welte07dc73d2009-08-07 13:27:09 +02001014 if (!is_ipaccess_bts(bts)) {
1015 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1016 return CMD_WARNING;
1017 }
1018
Harald Welte4cc34222009-05-01 15:12:31 +00001019 bts->ip_access.site_id = site_id;
1020 bts->ip_access.bts_id = bts_id;
1021
1022 return CMD_SUCCESS;
1023}
1024
Harald Welte8175e952009-10-20 00:22:00 +02001025DEFUN(cfg_bts_stream_id,
1026 cfg_bts_stream_id_cmd,
1027 "oml ip.access stream_id <0-255>",
1028 "Set the ip.access Stream ID of the OML link of this BTS\n")
1029{
1030 struct gsm_bts *bts = vty->index;
1031 int stream_id = atoi(argv[0]);
1032
1033 if (!is_ipaccess_bts(bts)) {
1034 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
1035 return CMD_WARNING;
1036 }
1037
1038 bts->oml_tei = stream_id;
1039
1040 return CMD_SUCCESS;
1041}
1042
1043
Harald Welte42581822009-08-08 16:12:58 +02001044DEFUN(cfg_bts_oml_e1,
1045 cfg_bts_oml_e1_cmd,
1046 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1047 "E1 interface to be used for OML\n")
1048{
1049 struct gsm_bts *bts = vty->index;
1050
1051 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
1052
1053 return CMD_SUCCESS;
1054}
1055
1056
1057DEFUN(cfg_bts_oml_e1_tei,
1058 cfg_bts_oml_e1_tei_cmd,
1059 "oml e1 tei <0-63>",
1060 "Set the TEI to be used for OML")
1061{
1062 struct gsm_bts *bts = vty->index;
1063
1064 bts->oml_tei = atoi(argv[0]);
1065
1066 return CMD_SUCCESS;
1067}
1068
Harald Welte7a8fa412009-08-10 13:48:16 +02001069DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1070 "channel allocator (ascending|descending)",
1071 "Should the channel allocator allocate in reverse TRX order?")
1072{
1073 struct gsm_bts *bts = vty->index;
1074
1075 if (!strcmp(argv[0], "ascending"))
1076 bts->chan_alloc_reverse = 0;
1077 else
1078 bts->chan_alloc_reverse = 1;
1079
1080 return CMD_SUCCESS;
1081}
1082
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001083DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1084 "cell barred (0|1)",
1085 "Should this cell be barred from access?")
1086{
1087 struct gsm_bts *bts = vty->index;
1088
1089 bts->cell_barred = atoi(argv[0]);
1090
1091 return CMD_SUCCESS;
1092}
1093
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001094DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1095 "ms max power <0-40>",
1096 "Maximum transmit power of the MS")
1097{
1098 struct gsm_bts *bts = vty->index;
1099
1100 bts->ms_max_power = atoi(argv[0]);
1101
1102 return CMD_SUCCESS;
1103}
1104
Harald Welte (local)efc92312009-08-14 23:09:25 +02001105DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1106 "periodic location update <0-1530>",
1107 "Periodic Location Updating Interval in Minutes")
1108{
1109 struct gsm_bts *bts = vty->index;
1110
Harald Weltea43f7892009-12-01 18:04:30 +05301111 bts->si_common.chan_desc.t3212 = atoi(argv[0]) / 10;
Harald Welte (local)efc92312009-08-14 23:09:25 +02001112
1113 return CMD_SUCCESS;
1114}
1115
Harald Welte7a8fa412009-08-10 13:48:16 +02001116
Harald Welte5258fc42009-03-28 19:07:53 +00001117/* per TRX configuration */
1118DEFUN(cfg_trx,
1119 cfg_trx_cmd,
1120 "trx TRX_NR",
1121 "Select a TRX to configure")
1122{
1123 int trx_nr = atoi(argv[0]);
1124 struct gsm_bts *bts = vty->index;
1125 struct gsm_bts_trx *trx;
1126
Harald Weltee441d9c2009-06-21 16:17:15 +02001127 if (trx_nr > bts->num_trx) {
1128 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1129 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +00001130 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +02001131 } else if (trx_nr == bts->num_trx) {
1132 /* we need to allocate a new one */
1133 trx = gsm_bts_trx_alloc(bts);
1134 } else
1135 trx = gsm_bts_trx_num(bts, trx_nr);
1136
1137 if (!trx)
1138 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001139
1140 vty->index = trx;
1141 vty->node = TRX_NODE;
1142
1143 return CMD_SUCCESS;
1144}
1145
1146DEFUN(cfg_trx_arfcn,
1147 cfg_trx_arfcn_cmd,
1148 "arfcn <1-1024>",
1149 "Set the ARFCN for this TRX\n")
1150{
1151 int arfcn = atoi(argv[0]);
1152 struct gsm_bts_trx *trx = vty->index;
1153
1154 /* FIXME: check if this ARFCN is supported by this TRX */
1155
1156 trx->arfcn = arfcn;
1157
1158 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1159 /* FIXME: use OML layer to update the ARFCN */
1160 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1161
1162 return CMD_SUCCESS;
1163}
1164
Harald Weltefcd24452009-06-20 18:15:19 +02001165DEFUN(cfg_trx_max_power_red,
1166 cfg_trx_max_power_red_cmd,
1167 "max_power_red <0-100>",
1168 "Reduction of maximum BS RF Power in dB\n")
1169{
1170 int maxpwr_r = atoi(argv[0]);
1171 struct gsm_bts_trx *trx = vty->index;
Harald Welte61a83b22009-11-18 09:20:22 +01001172 int upper_limit = 24; /* default 12.21 max power red. */
Harald Weltefcd24452009-06-20 18:15:19 +02001173
1174 /* FIXME: check if our BTS type supports more than 12 */
1175 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1176 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1177 maxpwr_r, VTY_NEWLINE);
1178 return CMD_WARNING;
1179 }
1180 if (maxpwr_r & 1) {
1181 vty_out(vty, "%% Power %d dB is not an even value%s",
1182 maxpwr_r, VTY_NEWLINE);
1183 return CMD_WARNING;
1184 }
1185
1186 trx->max_power_red = maxpwr_r;
1187
1188 /* FIXME: make sure we update this using OML */
1189
1190 return CMD_SUCCESS;
1191}
1192
Harald Welte42581822009-08-08 16:12:58 +02001193DEFUN(cfg_trx_rsl_e1,
1194 cfg_trx_rsl_e1_cmd,
1195 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1196 "E1 interface to be used for RSL\n")
1197{
1198 struct gsm_bts_trx *trx = vty->index;
1199
1200 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1201
1202 return CMD_SUCCESS;
1203}
1204
1205DEFUN(cfg_trx_rsl_e1_tei,
1206 cfg_trx_rsl_e1_tei_cmd,
1207 "rsl e1 tei <0-63>",
1208 "Set the TEI to be used for RSL")
1209{
1210 struct gsm_bts_trx *trx = vty->index;
1211
1212 trx->rsl_tei = atoi(argv[0]);
1213
1214 return CMD_SUCCESS;
1215}
1216
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +01001217DEFUN(cfg_trx_rf_locked,
1218 cfg_trx_rf_locked_cmd,
1219 "rf_locked (0|1)",
1220 "Turn off RF of the TRX.\n")
1221{
1222 int locked = atoi(argv[0]);
1223 struct gsm_bts_trx *trx = vty->index;
1224
1225 gsm_trx_lock_rf(trx, locked);
1226 return CMD_SUCCESS;
1227}
Harald Welte42581822009-08-08 16:12:58 +02001228
Harald Welte5258fc42009-03-28 19:07:53 +00001229/* per TS configuration */
1230DEFUN(cfg_ts,
1231 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001232 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001233 "Select a Timeslot to configure")
1234{
1235 int ts_nr = atoi(argv[0]);
1236 struct gsm_bts_trx *trx = vty->index;
1237 struct gsm_bts_trx_ts *ts;
1238
1239 if (ts_nr >= TRX_NR_TS) {
1240 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1241 TRX_NR_TS, VTY_NEWLINE);
1242 return CMD_WARNING;
1243 }
1244
1245 ts = &trx->ts[ts_nr];
1246
1247 vty->index = ts;
1248 vty->node = TS_NODE;
1249
1250 return CMD_SUCCESS;
1251}
1252
Harald Weltea6fd58e2009-08-07 00:25:23 +02001253DEFUN(cfg_ts_pchan,
1254 cfg_ts_pchan_cmd,
1255 "phys_chan_config PCHAN",
1256 "Physical Channel configuration (TCH/SDCCH/...)")
1257{
1258 struct gsm_bts_trx_ts *ts = vty->index;
1259 int pchanc;
1260
1261 pchanc = gsm_pchan_parse(argv[0]);
1262 if (pchanc < 0)
1263 return CMD_WARNING;
1264
1265 ts->pchan = pchanc;
1266
1267 return CMD_SUCCESS;
1268}
1269
1270DEFUN(cfg_ts_e1_subslot,
1271 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001272 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001273 "E1 sub-slot connected to this on-air timeslot")
1274{
1275 struct gsm_bts_trx_ts *ts = vty->index;
1276
Harald Welte42581822009-08-08 16:12:58 +02001277 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001278
1279 return CMD_SUCCESS;
1280}
Harald Welte5258fc42009-03-28 19:07:53 +00001281
Harald Welte68628e82009-03-10 12:17:57 +00001282int bsc_vty_init(struct gsm_network *net)
1283{
1284 gsmnet = net;
1285
1286 cmd_init(1);
1287 vty_init();
1288
1289 install_element(VIEW_NODE, &show_net_cmd);
1290 install_element(VIEW_NODE, &show_bts_cmd);
1291 install_element(VIEW_NODE, &show_trx_cmd);
1292 install_element(VIEW_NODE, &show_ts_cmd);
1293 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001294
1295 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001296 install_element(VIEW_NODE, &show_e1line_cmd);
1297 install_element(VIEW_NODE, &show_e1ts_cmd);
1298
Harald Weltef5025b62009-03-28 16:55:11 +00001299 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001300
Harald Welte5013b2a2009-08-07 13:29:14 +02001301 install_element(CONFIG_NODE, &cfg_net_cmd);
1302 install_node(&net_node, config_write_net);
1303 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001304 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001305 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1306 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1307 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001308 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte1085c092009-11-18 20:33:19 +01001309 install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd);
Harald Welte4381cfe2009-08-30 15:47:06 +09001310 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001311 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001312 install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001313 install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
1314 install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
1315 install_element(GSMNET_NODE, &cfg_net_T3107_cmd);
1316 install_element(GSMNET_NODE, &cfg_net_T3109_cmd);
1317 install_element(GSMNET_NODE, &cfg_net_T3111_cmd);
1318 install_element(GSMNET_NODE, &cfg_net_T3113_cmd);
1319 install_element(GSMNET_NODE, &cfg_net_T3115_cmd);
1320 install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
1321 install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
1322 install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001323
1324 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001325 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001326 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001327 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001328 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +02001329 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001330 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1331 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001332 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001333 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte8175e952009-10-20 00:22:00 +02001334 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001335 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1336 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001337 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001338 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001339 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)efc92312009-08-14 23:09:25 +02001340 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001341
Harald Welte68628e82009-03-10 12:17:57 +00001342
Harald Welte5258fc42009-03-28 19:07:53 +00001343 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001344 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001345 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001346 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001347 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001348 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1349 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +01001350 install_element(TRX_NODE, &cfg_trx_rf_locked_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001351
Harald Welte5258fc42009-03-28 19:07:53 +00001352 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001353 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001354 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001355 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1356 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001357
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02001358 bsc_vty_init_extra(net);
Harald Welte40f82892009-05-23 17:31:39 +00001359
Harald Welte68628e82009-03-10 12:17:57 +00001360 return 0;
1361}