blob: 54c9d5c6888438e28a1f4586c7e665c45ff912df [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 Freytherc4a49e32009-08-21 14:44:12 +0200231 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);
Harald Welte5013b2a2009-08-07 13:29:14 +0200277
278 return CMD_SUCCESS;
279}
Harald Welte67ce0732009-08-06 19:06:46 +0200280
Harald Welte68628e82009-03-10 12:17:57 +0000281static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
282{
283 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
284 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200285 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200286 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200287 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200288 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000289 vty_out(vty, " NM State: ");
290 net_dump_nmstate(vty, &trx->nm_state);
291 vty_out(vty, " Baseband Transceiver NM State: ");
292 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
Harald Welte8175e952009-10-20 00:22:00 +0200293 if (is_ipaccess_bts(trx->bts)) {
294 vty_out(vty, " ip.access stream ID: 0x%02x%s",
295 trx->rsl_tei, VTY_NEWLINE);
296 } else {
297 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
298 e1isl_dump_vty(vty, trx->rsl_link);
299 }
Harald Welte68628e82009-03-10 12:17:57 +0000300}
301
302DEFUN(show_trx,
303 show_trx_cmd,
304 "show trx [bts_nr] [trx_nr]",
305 SHOW_STR "Display information about a TRX\n")
306{
307 struct gsm_network *net = gsmnet;
308 struct gsm_bts *bts = NULL;
309 struct gsm_bts_trx *trx;
310 int bts_nr, trx_nr;
311
312 if (argc >= 1) {
313 /* use the BTS number that the user has specified */
314 bts_nr = atoi(argv[0]);
315 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000316 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000317 VTY_NEWLINE);
318 return CMD_WARNING;
319 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200320 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000321 }
322 if (argc >= 2) {
323 trx_nr = atoi(argv[1]);
324 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000325 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000326 VTY_NEWLINE);
327 return CMD_WARNING;
328 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200329 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000330 trx_dump_vty(vty, trx);
331 return CMD_SUCCESS;
332 }
333 if (bts) {
334 /* print all TRX in this BTS */
335 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200336 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000337 trx_dump_vty(vty, trx);
338 }
339 return CMD_SUCCESS;
340 }
341
342 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200343 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000344 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
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 }
348 }
349
350 return CMD_SUCCESS;
351}
352
Harald Welte67ce0732009-08-06 19:06:46 +0200353
Harald Welte68628e82009-03-10 12:17:57 +0000354static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
355{
356 struct in_addr ia;
357
358 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
359 ts->nr, ts->trx->nr, ts->trx->bts->nr,
360 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
361 vty_out(vty, " NM State: ");
362 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000363 if (is_ipaccess_bts(ts->trx->bts)) {
364 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200365 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000366 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200367 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000368 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000369 } else {
370 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
371 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
372 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000373 }
374}
375
376DEFUN(show_ts,
377 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000378 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000379 SHOW_STR "Display information about a TS\n")
380{
381 struct gsm_network *net = gsmnet;
382 struct gsm_bts *bts;
383 struct gsm_bts_trx *trx;
384 struct gsm_bts_trx_ts *ts;
385 int bts_nr, trx_nr, ts_nr;
386
387 if (argc >= 1) {
388 /* use the BTS number that the user has specified */
389 bts_nr = atoi(argv[0]);
390 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000391 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000392 VTY_NEWLINE);
393 return CMD_WARNING;
394 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200395 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000396 }
397 if (argc >= 2) {
398 trx_nr = atoi(argv[1]);
399 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000400 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000401 VTY_NEWLINE);
402 return CMD_WARNING;
403 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200404 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000405 }
406 if (argc >= 3) {
407 ts_nr = atoi(argv[2]);
408 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000409 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000410 VTY_NEWLINE);
411 return CMD_WARNING;
412 }
413 ts = &trx->ts[ts_nr];
414 ts_dump_vty(vty, ts);
415 return CMD_SUCCESS;
416 }
417 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200418 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000419 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200420 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000421 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
422 ts = &trx->ts[ts_nr];
423 ts_dump_vty(vty, ts);
424 }
425 }
426 }
427
428 return CMD_SUCCESS;
429}
430
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200431void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte68628e82009-03-10 12:17:57 +0000432{
Harald Weltefcd24452009-06-20 18:15:19 +0200433 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000434 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000435 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000436 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000437 if (subscr->extension)
438 vty_out(vty, " Extension: %s%s", subscr->extension,
439 VTY_NEWLINE);
440 if (subscr->imsi)
441 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200442 if (subscr->tmsi != GSM_RESERVED_TMSI)
443 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte731fd912009-08-15 03:24:51 +0200444 VTY_NEWLINE);
Harald Welte (local)15920de2009-08-14 20:27:16 +0200445 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000446}
447
448static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
449{
450 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
451 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
452 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
453 VTY_NEWLINE);
454 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
455 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
456 lchan->ms_power, VTY_NEWLINE);
457 if (lchan->subscr) {
458 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
459 subscr_dump_vty(vty, lchan->subscr);
460 } else
461 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
462}
463
Harald Welte4bfdfe72009-06-10 23:11:52 +0800464#if 0
465TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000466static void call_dump_vty(struct vty *vty, struct gsm_call *call)
467{
468 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
469 call->type, call->state, call->transaction_id, VTY_NEWLINE);
470
471 if (call->local_lchan) {
472 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
473 lchan_dump_vty(vty, call->local_lchan);
474 } else
475 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
476
477 if (call->remote_lchan) {
478 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
479 lchan_dump_vty(vty, call->remote_lchan);
480 } else
481 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
482
483 if (call->called_subscr) {
484 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
485 subscr_dump_vty(vty, call->called_subscr);
486 } else
487 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
488}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800489#endif
Harald Welte68628e82009-03-10 12:17:57 +0000490
491DEFUN(show_lchan,
492 show_lchan_cmd,
493 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
494 SHOW_STR "Display information about a logical channel\n")
495{
496 struct gsm_network *net = gsmnet;
497 struct gsm_bts *bts;
498 struct gsm_bts_trx *trx;
499 struct gsm_bts_trx_ts *ts;
500 struct gsm_lchan *lchan;
501 int bts_nr, trx_nr, ts_nr, lchan_nr;
502
503 if (argc >= 1) {
504 /* use the BTS number that the user has specified */
505 bts_nr = atoi(argv[0]);
506 if (bts_nr >= net->num_bts) {
507 vty_out(vty, "%% can't find BTS %s%s", argv[0],
508 VTY_NEWLINE);
509 return CMD_WARNING;
510 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200511 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000512 }
513 if (argc >= 2) {
514 trx_nr = atoi(argv[1]);
515 if (trx_nr >= bts->num_trx) {
516 vty_out(vty, "%% can't find TRX %s%s", argv[1],
517 VTY_NEWLINE);
518 return CMD_WARNING;
519 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200520 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000521 }
522 if (argc >= 3) {
523 ts_nr = atoi(argv[2]);
524 if (ts_nr >= TRX_NR_TS) {
525 vty_out(vty, "%% can't find TS %s%s", argv[2],
526 VTY_NEWLINE);
527 return CMD_WARNING;
528 }
529 ts = &trx->ts[ts_nr];
530 }
531 if (argc >= 4) {
532 lchan_nr = atoi(argv[3]);
533 if (lchan_nr >= TS_MAX_LCHAN) {
534 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
535 VTY_NEWLINE);
536 return CMD_WARNING;
537 }
538 lchan = &ts->lchan[lchan_nr];
539 lchan_dump_vty(vty, lchan);
540 return CMD_SUCCESS;
541 }
542 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200543 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000544 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200545 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000546 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
547 ts = &trx->ts[ts_nr];
548 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
549 lchan_nr++) {
550 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000551 if (lchan->type == GSM_LCHAN_NONE)
552 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000553 lchan_dump_vty(vty, lchan);
554 }
555 }
556 }
557 }
558
559 return CMD_SUCCESS;
560}
561
Harald Welte1bc77352009-03-10 19:47:51 +0000562static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
563{
564 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
565}
566
567DEFUN(show_e1drv,
568 show_e1drv_cmd,
569 "show e1_driver",
570 SHOW_STR "Display information about available E1 drivers\n")
571{
572 struct e1inp_driver *drv;
573
574 llist_for_each_entry(drv, &e1inp_driver_list, list)
575 e1drv_dump_vty(vty, drv);
576
577 return CMD_SUCCESS;
578}
579
Harald Welte68628e82009-03-10 12:17:57 +0000580static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
581{
582 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
583 line->num, line->name ? line->name : "",
584 line->driver->name, VTY_NEWLINE);
585}
586
587DEFUN(show_e1line,
588 show_e1line_cmd,
589 "show e1_line [line_nr]",
590 SHOW_STR "Display information about a E1 line\n")
591{
Harald Welte1bc77352009-03-10 19:47:51 +0000592 struct e1inp_line *line;
593
594 if (argc >= 1) {
595 int num = atoi(argv[0]);
596 llist_for_each_entry(line, &e1inp_line_list, list) {
597 if (line->num == num) {
598 e1line_dump_vty(vty, line);
599 return CMD_SUCCESS;
600 }
601 }
602 return CMD_WARNING;
603 }
604
605 llist_for_each_entry(line, &e1inp_line_list, list)
606 e1line_dump_vty(vty, line);
607
608 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000609}
610
611static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
612{
Harald Welte42581822009-08-08 16:12:58 +0200613 if (ts->type == E1INP_TS_TYPE_NONE)
614 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000615 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
616 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
617 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000618}
619
620DEFUN(show_e1ts,
621 show_e1ts_cmd,
622 "show e1_timeslot [line_nr] [ts_nr]",
623 SHOW_STR "Display information about a E1 timeslot\n")
624{
Harald Welte986c3d72009-11-17 06:12:16 +0100625 struct e1inp_line *line = NULL;
Harald Welte1bc77352009-03-10 19:47:51 +0000626 struct e1inp_ts *ts;
627 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000628
Harald Welte1bc77352009-03-10 19:47:51 +0000629 if (argc == 0) {
630 llist_for_each_entry(line, &e1inp_line_list, list) {
631 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
632 ts = &line->ts[ts_nr];
633 e1ts_dump_vty(vty, ts);
634 }
635 }
636 return CMD_SUCCESS;
637 }
638 if (argc >= 1) {
639 int num = atoi(argv[0]);
640 llist_for_each_entry(line, &e1inp_line_list, list) {
641 if (line->num == num)
642 break;
643 }
644 if (!line || line->num != num) {
645 vty_out(vty, "E1 line %s is invalid%s",
646 argv[0], VTY_NEWLINE);
647 return CMD_WARNING;
648 }
649 }
650 if (argc >= 2) {
651 ts_nr = atoi(argv[1]);
652 if (ts_nr > NUM_E1_TS) {
653 vty_out(vty, "E1 timeslot %s is invalid%s",
654 argv[1], VTY_NEWLINE);
655 return CMD_WARNING;
656 }
657 ts = &line->ts[ts_nr];
658 e1ts_dump_vty(vty, ts);
659 return CMD_SUCCESS;
660 } else {
661 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
662 ts = &line->ts[ts_nr];
663 e1ts_dump_vty(vty, ts);
664 }
665 return CMD_SUCCESS;
666 }
667 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000668}
669
Harald Weltebe4b7302009-05-23 16:59:33 +0000670static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000671{
672 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
673 subscr_dump_vty(vty, pag->subscr);
674}
675
Harald Weltebe4b7302009-05-23 16:59:33 +0000676static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000677{
678 struct gsm_paging_request *pag;
679
680 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
681 paging_dump_vty(vty, pag);
682}
683
684DEFUN(show_paging,
685 show_paging_cmd,
686 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000687 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000688{
689 struct gsm_network *net = gsmnet;
690 struct gsm_bts *bts;
691 int bts_nr;
692
693 if (argc >= 1) {
694 /* use the BTS number that the user has specified */
695 bts_nr = atoi(argv[0]);
696 if (bts_nr >= net->num_bts) {
697 vty_out(vty, "%% can't find BTS %s%s", argv[0],
698 VTY_NEWLINE);
699 return CMD_WARNING;
700 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200701 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000702 bts_paging_dump_vty(vty, bts);
703
704 return CMD_SUCCESS;
705 }
706 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200707 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000708 bts_paging_dump_vty(vty, bts);
709 }
710
711 return CMD_SUCCESS;
712}
713
Harald Welte5013b2a2009-08-07 13:29:14 +0200714DEFUN(cfg_net,
715 cfg_net_cmd,
716 "network",
717 "Configure the GSM network")
718{
719 vty->index = gsmnet;
720 vty->node = GSMNET_NODE;
721
722 return CMD_SUCCESS;
723}
724
725
726DEFUN(cfg_net_ncc,
727 cfg_net_ncc_cmd,
728 "network country code <1-999>",
729 "Set the GSM network country code")
730{
731 gsmnet->country_code = atoi(argv[0]);
732
733 return CMD_SUCCESS;
734}
735
736DEFUN(cfg_net_mnc,
737 cfg_net_mnc_cmd,
738 "mobile network code <1-999>",
739 "Set the GSM mobile network code")
740{
741 gsmnet->network_code = atoi(argv[0]);
742
743 return CMD_SUCCESS;
744}
745
746DEFUN(cfg_net_name_short,
747 cfg_net_name_short_cmd,
748 "short name NAME",
749 "Set the short GSM network name")
750{
751 if (gsmnet->name_short)
752 talloc_free(gsmnet->name_short);
753
754 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
755
756 return CMD_SUCCESS;
757}
758
759DEFUN(cfg_net_name_long,
760 cfg_net_name_long_cmd,
761 "long name NAME",
762 "Set the long GSM network name")
763{
764 if (gsmnet->name_long)
765 talloc_free(gsmnet->name_long);
766
767 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
768
769 return CMD_SUCCESS;
770}
Harald Welte40f82892009-05-23 17:31:39 +0000771
Harald Welte (local)69de3972009-08-12 14:42:23 +0200772DEFUN(cfg_net_auth_policy,
773 cfg_net_auth_policy_cmd,
774 "auth policy (closed|accept-all|token)",
775 "Set the GSM network authentication policy\n")
776{
777 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
778
779 gsmnet->auth_policy = policy;
780
781 return CMD_SUCCESS;
782}
783
Harald Welte4381cfe2009-08-30 15:47:06 +0900784DEFUN(cfg_net_encryption,
785 cfg_net_encryption_cmd,
786 "encryption a5 (0|1|2)",
787 "Enable or disable encryption (A5) for this network\n")
788{
789 gsmnet->auth_policy = atoi(argv[0]);
790
791 return CMD_SUCCESS;
792}
793
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100794DEFUN(cfg_net_neci,
795 cfg_net_neci_cmd,
796 "neci (0|1)",
797 "Set if NECI of cell selection is to be set")
798{
799 gsmnet->neci = atoi(argv[0]);
800 return CMD_SUCCESS;
801}
802
Harald Welte5258fc42009-03-28 19:07:53 +0000803/* per-BTS configuration */
804DEFUN(cfg_bts,
805 cfg_bts_cmd,
806 "bts BTS_NR",
807 "Select a BTS to configure\n")
808{
809 int bts_nr = atoi(argv[0]);
810 struct gsm_bts *bts;
811
Harald Weltee441d9c2009-06-21 16:17:15 +0200812 if (bts_nr > gsmnet->num_bts) {
813 vty_out(vty, "%% The next unused BTS number is %u%s",
814 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000815 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200816 } else if (bts_nr == gsmnet->num_bts) {
817 /* allocate a new one */
818 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
819 HARDCODED_TSC, HARDCODED_BSIC);
820 } else
821 bts = gsm_bts_num(gsmnet, bts_nr);
822
823 if (!bts)
824 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000825
826 vty->index = bts;
827 vty->node = BTS_NODE;
828
829 return CMD_SUCCESS;
830}
831
832DEFUN(cfg_bts_type,
833 cfg_bts_type_cmd,
834 "type TYPE",
835 "Set the BTS type\n")
836{
837 struct gsm_bts *bts = vty->index;
838
Harald Weltea6fd58e2009-08-07 00:25:23 +0200839 bts->type = parse_btstype(argv[0]);
840
Harald Welte8175e952009-10-20 00:22:00 +0200841 if (is_ipaccess_bts(bts)) {
842 /* Set the default OML Stream ID to 0xff */
843 bts->oml_tei = 0xff;
844 }
845
Harald Welte5258fc42009-03-28 19:07:53 +0000846 return CMD_SUCCESS;
847}
848
Harald Weltefcd24452009-06-20 18:15:19 +0200849DEFUN(cfg_bts_band,
850 cfg_bts_band_cmd,
851 "band BAND",
852 "Set the frequency band of this BTS\n")
853{
854 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200855 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200856
857 if (band < 0) {
858 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
859 band, VTY_NEWLINE);
860 return CMD_WARNING;
861 }
862
863 bts->band = band;
864
865 return CMD_SUCCESS;
866}
867
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200868DEFUN(cfg_bts_ci,
869 cfg_bts_ci_cmd,
870 "cell_identity <0-65535>",
871 "Set the Cell identity of this BTS\n")
872{
873 struct gsm_bts *bts = vty->index;
874 int ci = atoi(argv[0]);
875
876 if (ci < 0 || ci > 0xffff) {
877 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
878 ci, VTY_NEWLINE);
879 return CMD_WARNING;
880 }
881 bts->cell_identity = ci;
882
883 return CMD_SUCCESS;
884}
885
Harald Welte5258fc42009-03-28 19:07:53 +0000886DEFUN(cfg_bts_lac,
887 cfg_bts_lac_cmd,
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200888 "location_area_code <0-65535>",
Harald Welte5258fc42009-03-28 19:07:53 +0000889 "Set the Location Area Code (LAC) of this BTS\n")
890{
891 struct gsm_bts *bts = vty->index;
892 int lac = atoi(argv[0]);
893
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200894 if (lac < 0 || lac > 0xffff) {
895 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte5258fc42009-03-28 19:07:53 +0000896 lac, VTY_NEWLINE);
897 return CMD_WARNING;
898 }
Holger Hans Peter Freythere48b9562009-10-01 04:07:15 +0200899
900 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
901 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
902 lac, VTY_NEWLINE);
903 return CMD_WARNING;
904 }
905
Harald Welte5258fc42009-03-28 19:07:53 +0000906 bts->location_area_code = lac;
907
908 return CMD_SUCCESS;
909}
910
911DEFUN(cfg_bts_tsc,
912 cfg_bts_tsc_cmd,
913 "training_sequence_code <0-255>",
914 "Set the Training Sequence Code (TSC) of this BTS\n")
915{
916 struct gsm_bts *bts = vty->index;
917 int tsc = atoi(argv[0]);
918
919 if (tsc < 0 || tsc > 0xff) {
920 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
921 tsc, VTY_NEWLINE);
922 return CMD_WARNING;
923 }
924 bts->tsc = tsc;
925
926 return CMD_SUCCESS;
927}
928
Harald Welte78f2f502009-05-23 16:56:52 +0000929DEFUN(cfg_bts_bsic,
930 cfg_bts_bsic_cmd,
931 "base_station_id_code <0-63>",
932 "Set the Base Station Identity Code (BSIC) of this BTS\n")
933{
934 struct gsm_bts *bts = vty->index;
935 int bsic = atoi(argv[0]);
936
937 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200938 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000939 bsic, VTY_NEWLINE);
940 return CMD_WARNING;
941 }
942 bts->bsic = bsic;
943
944 return CMD_SUCCESS;
945}
946
947
Harald Welte4cc34222009-05-01 15:12:31 +0000948DEFUN(cfg_bts_unit_id,
949 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200950 "ip.access unit_id <0-65534> <0-255>",
951 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000952{
953 struct gsm_bts *bts = vty->index;
954 int site_id = atoi(argv[0]);
955 int bts_id = atoi(argv[1]);
956
Harald Welte07dc73d2009-08-07 13:27:09 +0200957 if (!is_ipaccess_bts(bts)) {
958 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
959 return CMD_WARNING;
960 }
961
Harald Welte4cc34222009-05-01 15:12:31 +0000962 bts->ip_access.site_id = site_id;
963 bts->ip_access.bts_id = bts_id;
964
965 return CMD_SUCCESS;
966}
967
Harald Welte8175e952009-10-20 00:22:00 +0200968DEFUN(cfg_bts_stream_id,
969 cfg_bts_stream_id_cmd,
970 "oml ip.access stream_id <0-255>",
971 "Set the ip.access Stream ID of the OML link of this BTS\n")
972{
973 struct gsm_bts *bts = vty->index;
974 int stream_id = atoi(argv[0]);
975
976 if (!is_ipaccess_bts(bts)) {
977 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
978 return CMD_WARNING;
979 }
980
981 bts->oml_tei = stream_id;
982
983 return CMD_SUCCESS;
984}
985
986
Harald Welte42581822009-08-08 16:12:58 +0200987DEFUN(cfg_bts_oml_e1,
988 cfg_bts_oml_e1_cmd,
989 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
990 "E1 interface to be used for OML\n")
991{
992 struct gsm_bts *bts = vty->index;
993
994 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
995
996 return CMD_SUCCESS;
997}
998
999
1000DEFUN(cfg_bts_oml_e1_tei,
1001 cfg_bts_oml_e1_tei_cmd,
1002 "oml e1 tei <0-63>",
1003 "Set the TEI to be used for OML")
1004{
1005 struct gsm_bts *bts = vty->index;
1006
1007 bts->oml_tei = atoi(argv[0]);
1008
1009 return CMD_SUCCESS;
1010}
1011
Harald Welte7a8fa412009-08-10 13:48:16 +02001012DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1013 "channel allocator (ascending|descending)",
1014 "Should the channel allocator allocate in reverse TRX order?")
1015{
1016 struct gsm_bts *bts = vty->index;
1017
1018 if (!strcmp(argv[0], "ascending"))
1019 bts->chan_alloc_reverse = 0;
1020 else
1021 bts->chan_alloc_reverse = 1;
1022
1023 return CMD_SUCCESS;
1024}
1025
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001026DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1027 "cell barred (0|1)",
1028 "Should this cell be barred from access?")
1029{
1030 struct gsm_bts *bts = vty->index;
1031
1032 bts->cell_barred = atoi(argv[0]);
1033
1034 return CMD_SUCCESS;
1035}
1036
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001037DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1038 "ms max power <0-40>",
1039 "Maximum transmit power of the MS")
1040{
1041 struct gsm_bts *bts = vty->index;
1042
1043 bts->ms_max_power = atoi(argv[0]);
1044
1045 return CMD_SUCCESS;
1046}
1047
Harald Welte (local)efc92312009-08-14 23:09:25 +02001048DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1049 "periodic location update <0-1530>",
1050 "Periodic Location Updating Interval in Minutes")
1051{
1052 struct gsm_bts *bts = vty->index;
1053
1054 bts->chan_desc.t3212 = atoi(argv[0]) / 10;
1055
1056 return CMD_SUCCESS;
1057}
1058
Harald Welte7a8fa412009-08-10 13:48:16 +02001059
Harald Welte5258fc42009-03-28 19:07:53 +00001060/* per TRX configuration */
1061DEFUN(cfg_trx,
1062 cfg_trx_cmd,
1063 "trx TRX_NR",
1064 "Select a TRX to configure")
1065{
1066 int trx_nr = atoi(argv[0]);
1067 struct gsm_bts *bts = vty->index;
1068 struct gsm_bts_trx *trx;
1069
Harald Weltee441d9c2009-06-21 16:17:15 +02001070 if (trx_nr > bts->num_trx) {
1071 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1072 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +00001073 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +02001074 } else if (trx_nr == bts->num_trx) {
1075 /* we need to allocate a new one */
1076 trx = gsm_bts_trx_alloc(bts);
1077 } else
1078 trx = gsm_bts_trx_num(bts, trx_nr);
1079
1080 if (!trx)
1081 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001082
1083 vty->index = trx;
1084 vty->node = TRX_NODE;
1085
1086 return CMD_SUCCESS;
1087}
1088
1089DEFUN(cfg_trx_arfcn,
1090 cfg_trx_arfcn_cmd,
1091 "arfcn <1-1024>",
1092 "Set the ARFCN for this TRX\n")
1093{
1094 int arfcn = atoi(argv[0]);
1095 struct gsm_bts_trx *trx = vty->index;
1096
1097 /* FIXME: check if this ARFCN is supported by this TRX */
1098
1099 trx->arfcn = arfcn;
1100
1101 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1102 /* FIXME: use OML layer to update the ARFCN */
1103 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1104
1105 return CMD_SUCCESS;
1106}
1107
Harald Weltefcd24452009-06-20 18:15:19 +02001108DEFUN(cfg_trx_max_power_red,
1109 cfg_trx_max_power_red_cmd,
1110 "max_power_red <0-100>",
1111 "Reduction of maximum BS RF Power in dB\n")
1112{
1113 int maxpwr_r = atoi(argv[0]);
1114 struct gsm_bts_trx *trx = vty->index;
1115 int upper_limit = 12; /* default 12.21 max power red. */
1116
1117 /* FIXME: check if our BTS type supports more than 12 */
1118 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1119 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1120 maxpwr_r, VTY_NEWLINE);
1121 return CMD_WARNING;
1122 }
1123 if (maxpwr_r & 1) {
1124 vty_out(vty, "%% Power %d dB is not an even value%s",
1125 maxpwr_r, VTY_NEWLINE);
1126 return CMD_WARNING;
1127 }
1128
1129 trx->max_power_red = maxpwr_r;
1130
1131 /* FIXME: make sure we update this using OML */
1132
1133 return CMD_SUCCESS;
1134}
1135
Harald Welte42581822009-08-08 16:12:58 +02001136DEFUN(cfg_trx_rsl_e1,
1137 cfg_trx_rsl_e1_cmd,
1138 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1139 "E1 interface to be used for RSL\n")
1140{
1141 struct gsm_bts_trx *trx = vty->index;
1142
1143 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1144
1145 return CMD_SUCCESS;
1146}
1147
1148DEFUN(cfg_trx_rsl_e1_tei,
1149 cfg_trx_rsl_e1_tei_cmd,
1150 "rsl e1 tei <0-63>",
1151 "Set the TEI to be used for RSL")
1152{
1153 struct gsm_bts_trx *trx = vty->index;
1154
1155 trx->rsl_tei = atoi(argv[0]);
1156
1157 return CMD_SUCCESS;
1158}
1159
1160
Harald Welte5258fc42009-03-28 19:07:53 +00001161/* per TS configuration */
1162DEFUN(cfg_ts,
1163 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001164 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001165 "Select a Timeslot to configure")
1166{
1167 int ts_nr = atoi(argv[0]);
1168 struct gsm_bts_trx *trx = vty->index;
1169 struct gsm_bts_trx_ts *ts;
1170
1171 if (ts_nr >= TRX_NR_TS) {
1172 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1173 TRX_NR_TS, VTY_NEWLINE);
1174 return CMD_WARNING;
1175 }
1176
1177 ts = &trx->ts[ts_nr];
1178
1179 vty->index = ts;
1180 vty->node = TS_NODE;
1181
1182 return CMD_SUCCESS;
1183}
1184
Harald Weltea6fd58e2009-08-07 00:25:23 +02001185DEFUN(cfg_ts_pchan,
1186 cfg_ts_pchan_cmd,
1187 "phys_chan_config PCHAN",
1188 "Physical Channel configuration (TCH/SDCCH/...)")
1189{
1190 struct gsm_bts_trx_ts *ts = vty->index;
1191 int pchanc;
1192
1193 pchanc = gsm_pchan_parse(argv[0]);
1194 if (pchanc < 0)
1195 return CMD_WARNING;
1196
1197 ts->pchan = pchanc;
1198
1199 return CMD_SUCCESS;
1200}
1201
1202DEFUN(cfg_ts_e1_subslot,
1203 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001204 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001205 "E1 sub-slot connected to this on-air timeslot")
1206{
1207 struct gsm_bts_trx_ts *ts = vty->index;
1208
Harald Welte42581822009-08-08 16:12:58 +02001209 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001210
1211 return CMD_SUCCESS;
1212}
Harald Welte5258fc42009-03-28 19:07:53 +00001213
Harald Welte68628e82009-03-10 12:17:57 +00001214int bsc_vty_init(struct gsm_network *net)
1215{
1216 gsmnet = net;
1217
1218 cmd_init(1);
1219 vty_init();
1220
1221 install_element(VIEW_NODE, &show_net_cmd);
1222 install_element(VIEW_NODE, &show_bts_cmd);
1223 install_element(VIEW_NODE, &show_trx_cmd);
1224 install_element(VIEW_NODE, &show_ts_cmd);
1225 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001226
1227 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001228 install_element(VIEW_NODE, &show_e1line_cmd);
1229 install_element(VIEW_NODE, &show_e1ts_cmd);
1230
Harald Weltef5025b62009-03-28 16:55:11 +00001231 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001232
Harald Welte5013b2a2009-08-07 13:29:14 +02001233 install_element(CONFIG_NODE, &cfg_net_cmd);
1234 install_node(&net_node, config_write_net);
1235 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001236 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001237 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1238 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1239 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001240 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte4381cfe2009-08-30 15:47:06 +09001241 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001242 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001243
1244 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001245 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001246 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001247 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001248 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +02001249 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001250 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1251 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001252 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001253 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte8175e952009-10-20 00:22:00 +02001254 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001255 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1256 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001257 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001258 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001259 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)efc92312009-08-14 23:09:25 +02001260 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001261
Harald Welte68628e82009-03-10 12:17:57 +00001262
Harald Welte5258fc42009-03-28 19:07:53 +00001263 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001264 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001265 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001266 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001267 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001268 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1269 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001270
Harald Welte5258fc42009-03-28 19:07:53 +00001271 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001272 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001273 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001274 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1275 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001276
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02001277 bsc_vty_init_extra(net);
Harald Welte40f82892009-05-23 17:31:39 +00001278
Harald Welte68628e82009-03-10 12:17:57 +00001279 return 0;
1280}