blob: 5712ca1c74a08b12d56477aa626e76bde5775aff [file] [log] [blame]
Harald Welte68628e82009-03-10 12:17:57 +00001/* OpenBSC interface to quagga VTY */
2/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <stdlib.h>
22#include <unistd.h>
23#include <sys/types.h>
24
25#include <vty/command.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020026#include <vty/buffer.h>
Harald Welte68628e82009-03-10 12:17:57 +000027#include <vty/vty.h>
28
29#include <arpa/inet.h>
30
Harald Welte1bc77352009-03-10 19:47:51 +000031#include <openbsc/linuxlist.h>
Harald Welte68628e82009-03-10 12:17:57 +000032#include <openbsc/gsm_data.h>
Harald Welte68628e82009-03-10 12:17:57 +000033#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000034#include <openbsc/abis_nm.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020035#include <openbsc/gsm_utils.h>
Harald Welte40f82892009-05-23 17:31:39 +000036#include <openbsc/db.h>
Harald Welte5013b2a2009-08-07 13:29:14 +020037#include <openbsc/talloc.h>
Harald Welte68628e82009-03-10 12:17:57 +000038
39static struct gsm_network *gsmnet;
40
Harald Welte5013b2a2009-08-07 13:29:14 +020041struct cmd_node net_node = {
42 GSMNET_NODE,
43 "%s(network)#",
44 1,
45};
46
Harald Welte68628e82009-03-10 12:17:57 +000047struct cmd_node bts_node = {
48 BTS_NODE,
49 "%s(bts)#",
50 1,
51};
52
53struct cmd_node trx_node = {
54 TRX_NODE,
55 "%s(trx)#",
56 1,
57};
58
59struct cmd_node ts_node = {
60 TS_NODE,
61 "%s(ts)#",
62 1,
63};
64
65static int dummy_config_write(struct vty *v)
66{
67 return CMD_SUCCESS;
68}
69
70static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
71{
Harald Welte1bc77352009-03-10 19:47:51 +000072 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
73 nm_opstate_name(nms->operational), nms->administrative,
74 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000075}
76
77static void net_dump_vty(struct vty *vty, struct gsm_network *net)
78{
Harald Welteef235b52009-03-10 12:34:02 +000079 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
80 "and has %u BTS%s", net->country_code, net->network_code,
81 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000082 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000083 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000084 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000085 net->name_short, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +020086 vty_out(vty, " Authentication policy: %s%s",
87 gsm_auth_policy_name(net->auth_policy), VTY_NEWLINE);
Harald Welte4381cfe2009-08-30 15:47:06 +090088 vty_out(vty, " Encryption: A5/%u%s", net->a5_encryption,
89 VTY_NEWLINE);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +010090 vty_out(vty, " NECI (TCH/H): %u%s", net->neci,
91 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000092}
93
94DEFUN(show_net, show_net_cmd, "show network",
95 SHOW_STR "Display information about a GSM NETWORK\n")
96{
97 struct gsm_network *net = gsmnet;
98 net_dump_vty(vty, net);
99
100 return CMD_SUCCESS;
101}
102
103static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
104{
Harald Welteedb37782009-05-01 14:59:07 +0000105 struct e1inp_line *line;
106
107 if (!e1l) {
108 vty_out(vty, " None%s", VTY_NEWLINE);
109 return;
110 }
111
112 line = e1l->ts->line;
113
114 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
115 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000116 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000117 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000118 e1l->tei, e1l->sapi, VTY_NEWLINE);
119}
120
121static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
122{
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200123 vty_out(vty, "BTS %u is of %s type in band %s, has CI %u LAC %u, "
Harald Weltefcd24452009-06-20 18:15:19 +0200124 "BSIC %u, TSC %u and %u TRX%s",
125 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200126 bts->cell_identity,
Harald Weltefcd24452009-06-20 18:15:19 +0200127 bts->location_area_code, bts->bsic, bts->tsc,
128 bts->num_trx, VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200129 if (bts->cell_barred)
130 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000131 if (is_ipaccess_bts(bts))
Harald Welte8175e952009-10-20 00:22:00 +0200132 vty_out(vty, " Unit ID: %u/%u/0, OML Stream ID 0x%02x%s",
Harald Welte4cc34222009-05-01 15:12:31 +0000133 bts->ip_access.site_id, bts->ip_access.bts_id,
Harald Welte8175e952009-10-20 00:22:00 +0200134 bts->oml_tei, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000135 vty_out(vty, " NM State: ");
136 net_dump_nmstate(vty, &bts->nm_state);
137 vty_out(vty, " Site Mgr NM State: ");
138 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
139 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
140 bts->paging.available_slots, VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200141 if (!is_ipaccess_bts(bts)) {
142 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
143 e1isl_dump_vty(vty, bts->oml_link);
144 }
Harald Welte68628e82009-03-10 12:17:57 +0000145 /* FIXME: oml_link, chan_desc */
146}
147
148DEFUN(show_bts, show_bts_cmd, "show bts [number]",
149 SHOW_STR "Display information about a BTS\n"
150 "BTS number")
151{
152 struct gsm_network *net = gsmnet;
153 int bts_nr;
154
155 if (argc != 0) {
156 /* use the BTS number that the user has specified */
157 bts_nr = atoi(argv[0]);
158 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000159 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000160 VTY_NEWLINE);
161 return CMD_WARNING;
162 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200163 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000164 return CMD_SUCCESS;
165 }
166 /* print all BTS's */
167 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200168 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000169
170 return CMD_SUCCESS;
171}
172
Harald Welte42581822009-08-08 16:12:58 +0200173/* utility functions */
174static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
175 const char *ts, const char *ss)
176{
177 e1_link->e1_nr = atoi(line);
178 e1_link->e1_ts = atoi(ts);
179 if (!strcmp(ss, "full"))
180 e1_link->e1_ts_ss = 255;
181 else
182 e1_link->e1_ts_ss = atoi(ss);
183}
184
185static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
186 const char *prefix)
187{
188 if (!e1_link->e1_ts)
189 return;
190
191 if (e1_link->e1_ts_ss == 255)
192 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
193 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
194 else
195 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
196 prefix, e1_link->e1_nr, e1_link->e1_ts,
197 e1_link->e1_ts_ss, VTY_NEWLINE);
198}
199
200
Harald Welte67ce0732009-08-06 19:06:46 +0200201static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
202{
Harald Welte42581822009-08-08 16:12:58 +0200203 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
204 if (ts->pchan != GSM_PCHAN_NONE)
205 vty_out(vty, " phys_chan_config %s%s",
206 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
207 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte67ce0732009-08-06 19:06:46 +0200208}
209
210static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
211{
212 int i;
213
Harald Welte5013b2a2009-08-07 13:29:14 +0200214 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
215 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
216 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200217 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
218 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200219
220 for (i = 0; i < TRX_NR_TS; i++)
221 config_write_ts_single(vty, &trx->ts[i]);
222}
223
224static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
225{
226 struct gsm_bts_trx *trx;
227
Harald Welte5013b2a2009-08-07 13:29:14 +0200228 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
229 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
230 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
Holger Hans Peter Freytherf926ed62009-11-19 16:38:49 +0100231 vty_out(vty, " cell_identity %u%s", bts->cell_identity, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200232 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200233 VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200234 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
235 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200236 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Welte (local)efc92312009-08-14 23:09:25 +0200237 if (bts->chan_desc.t3212)
238 vty_out(vty, " periodic location update %u%s",
239 bts->chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte7a8fa412009-08-10 13:48:16 +0200240 vty_out(vty, " channel allocator %s%s",
241 bts->chan_alloc_reverse ? "descending" : "ascending",
242 VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200243 if (bts->cell_barred)
244 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200245 if (is_ipaccess_bts(bts)) {
Harald Welte5013b2a2009-08-07 13:29:14 +0200246 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200247 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte8175e952009-10-20 00:22:00 +0200248 vty_out(vty, " oml ip.access stream_id %u%s", bts->oml_tei, VTY_NEWLINE);
249 } else {
Harald Welte42581822009-08-08 16:12:58 +0200250 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
251 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
252 }
Harald Welte67ce0732009-08-06 19:06:46 +0200253
254 llist_for_each_entry(trx, &bts->trx_list, list)
255 config_write_trx_single(vty, trx);
256}
257
258static int config_write_bts(struct vty *v)
259{
260 struct gsm_bts *bts;
261
262 llist_for_each_entry(bts, &gsmnet->bts_list, list)
263 config_write_bts_single(v, bts);
264
265 return CMD_SUCCESS;
266}
267
Harald Welte5013b2a2009-08-07 13:29:14 +0200268static int config_write_net(struct vty *vty)
269{
270 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200271 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200272 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200273 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
274 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +0200275 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte4381cfe2009-08-30 15:47:06 +0900276 vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
Holger Hans Peter Freytherd54c3372009-11-19 16:37:48 +0100277 vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200278
279 return CMD_SUCCESS;
280}
Harald Welte67ce0732009-08-06 19:06:46 +0200281
Harald Welte68628e82009-03-10 12:17:57 +0000282static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
283{
284 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
285 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200286 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200287 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200288 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200289 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000290 vty_out(vty, " NM State: ");
291 net_dump_nmstate(vty, &trx->nm_state);
292 vty_out(vty, " Baseband Transceiver NM State: ");
293 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
Harald Welte8175e952009-10-20 00:22:00 +0200294 if (is_ipaccess_bts(trx->bts)) {
295 vty_out(vty, " ip.access stream ID: 0x%02x%s",
296 trx->rsl_tei, VTY_NEWLINE);
297 } else {
298 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
299 e1isl_dump_vty(vty, trx->rsl_link);
300 }
Harald Welte68628e82009-03-10 12:17:57 +0000301}
302
303DEFUN(show_trx,
304 show_trx_cmd,
305 "show trx [bts_nr] [trx_nr]",
306 SHOW_STR "Display information about a TRX\n")
307{
308 struct gsm_network *net = gsmnet;
309 struct gsm_bts *bts = NULL;
310 struct gsm_bts_trx *trx;
311 int bts_nr, trx_nr;
312
313 if (argc >= 1) {
314 /* use the BTS number that the user has specified */
315 bts_nr = atoi(argv[0]);
316 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000317 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000318 VTY_NEWLINE);
319 return CMD_WARNING;
320 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200321 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000322 }
323 if (argc >= 2) {
324 trx_nr = atoi(argv[1]);
325 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000326 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000327 VTY_NEWLINE);
328 return CMD_WARNING;
329 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200330 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000331 trx_dump_vty(vty, trx);
332 return CMD_SUCCESS;
333 }
334 if (bts) {
335 /* print all TRX in this BTS */
336 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200337 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000338 trx_dump_vty(vty, trx);
339 }
340 return CMD_SUCCESS;
341 }
342
343 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200344 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000345 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200346 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000347 trx_dump_vty(vty, trx);
348 }
349 }
350
351 return CMD_SUCCESS;
352}
353
Harald Welte67ce0732009-08-06 19:06:46 +0200354
Harald Welte68628e82009-03-10 12:17:57 +0000355static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
356{
357 struct in_addr ia;
358
359 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
360 ts->nr, ts->trx->nr, ts->trx->bts->nr,
361 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
362 vty_out(vty, " NM State: ");
363 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000364 if (is_ipaccess_bts(ts->trx->bts)) {
365 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200366 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000367 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200368 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000369 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000370 } else {
371 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
372 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
373 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000374 }
375}
376
377DEFUN(show_ts,
378 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000379 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000380 SHOW_STR "Display information about a TS\n")
381{
382 struct gsm_network *net = gsmnet;
383 struct gsm_bts *bts;
384 struct gsm_bts_trx *trx;
385 struct gsm_bts_trx_ts *ts;
386 int bts_nr, trx_nr, ts_nr;
387
388 if (argc >= 1) {
389 /* use the BTS number that the user has specified */
390 bts_nr = atoi(argv[0]);
391 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000392 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000393 VTY_NEWLINE);
394 return CMD_WARNING;
395 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200396 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000397 }
398 if (argc >= 2) {
399 trx_nr = atoi(argv[1]);
400 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000401 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000402 VTY_NEWLINE);
403 return CMD_WARNING;
404 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200405 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000406 }
407 if (argc >= 3) {
408 ts_nr = atoi(argv[2]);
409 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000410 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000411 VTY_NEWLINE);
412 return CMD_WARNING;
413 }
414 ts = &trx->ts[ts_nr];
415 ts_dump_vty(vty, ts);
416 return CMD_SUCCESS;
417 }
418 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200419 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000420 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200421 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000422 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
423 ts = &trx->ts[ts_nr];
424 ts_dump_vty(vty, ts);
425 }
426 }
427 }
428
429 return CMD_SUCCESS;
430}
431
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200432void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
Harald Welte68628e82009-03-10 12:17:57 +0000433{
Harald Weltefcd24452009-06-20 18:15:19 +0200434 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000435 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000436 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000437 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000438 if (subscr->extension)
439 vty_out(vty, " Extension: %s%s", subscr->extension,
440 VTY_NEWLINE);
441 if (subscr->imsi)
442 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200443 if (subscr->tmsi != GSM_RESERVED_TMSI)
444 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
Harald Welte731fd912009-08-15 03:24:51 +0200445 VTY_NEWLINE);
Harald Welte (local)15920de2009-08-14 20:27:16 +0200446 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000447}
448
449static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
450{
451 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
452 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
453 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
454 VTY_NEWLINE);
455 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
456 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
457 lchan->ms_power, VTY_NEWLINE);
458 if (lchan->subscr) {
459 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
460 subscr_dump_vty(vty, lchan->subscr);
461 } else
462 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
463}
464
Harald Welte4bfdfe72009-06-10 23:11:52 +0800465#if 0
466TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000467static void call_dump_vty(struct vty *vty, struct gsm_call *call)
468{
469 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
470 call->type, call->state, call->transaction_id, VTY_NEWLINE);
471
472 if (call->local_lchan) {
473 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
474 lchan_dump_vty(vty, call->local_lchan);
475 } else
476 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
477
478 if (call->remote_lchan) {
479 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
480 lchan_dump_vty(vty, call->remote_lchan);
481 } else
482 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
483
484 if (call->called_subscr) {
485 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
486 subscr_dump_vty(vty, call->called_subscr);
487 } else
488 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
489}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800490#endif
Harald Welte68628e82009-03-10 12:17:57 +0000491
492DEFUN(show_lchan,
493 show_lchan_cmd,
494 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
495 SHOW_STR "Display information about a logical channel\n")
496{
497 struct gsm_network *net = gsmnet;
498 struct gsm_bts *bts;
499 struct gsm_bts_trx *trx;
500 struct gsm_bts_trx_ts *ts;
501 struct gsm_lchan *lchan;
502 int bts_nr, trx_nr, ts_nr, lchan_nr;
503
504 if (argc >= 1) {
505 /* use the BTS number that the user has specified */
506 bts_nr = atoi(argv[0]);
507 if (bts_nr >= net->num_bts) {
508 vty_out(vty, "%% can't find BTS %s%s", argv[0],
509 VTY_NEWLINE);
510 return CMD_WARNING;
511 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200512 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000513 }
514 if (argc >= 2) {
515 trx_nr = atoi(argv[1]);
516 if (trx_nr >= bts->num_trx) {
517 vty_out(vty, "%% can't find TRX %s%s", argv[1],
518 VTY_NEWLINE);
519 return CMD_WARNING;
520 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200521 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000522 }
523 if (argc >= 3) {
524 ts_nr = atoi(argv[2]);
525 if (ts_nr >= TRX_NR_TS) {
526 vty_out(vty, "%% can't find TS %s%s", argv[2],
527 VTY_NEWLINE);
528 return CMD_WARNING;
529 }
530 ts = &trx->ts[ts_nr];
531 }
532 if (argc >= 4) {
533 lchan_nr = atoi(argv[3]);
534 if (lchan_nr >= TS_MAX_LCHAN) {
535 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
536 VTY_NEWLINE);
537 return CMD_WARNING;
538 }
539 lchan = &ts->lchan[lchan_nr];
540 lchan_dump_vty(vty, lchan);
541 return CMD_SUCCESS;
542 }
543 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200544 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000545 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200546 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000547 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
548 ts = &trx->ts[ts_nr];
549 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
550 lchan_nr++) {
551 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000552 if (lchan->type == GSM_LCHAN_NONE)
553 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000554 lchan_dump_vty(vty, lchan);
555 }
556 }
557 }
558 }
559
560 return CMD_SUCCESS;
561}
562
Harald Welte1bc77352009-03-10 19:47:51 +0000563static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
564{
565 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
566}
567
568DEFUN(show_e1drv,
569 show_e1drv_cmd,
570 "show e1_driver",
571 SHOW_STR "Display information about available E1 drivers\n")
572{
573 struct e1inp_driver *drv;
574
575 llist_for_each_entry(drv, &e1inp_driver_list, list)
576 e1drv_dump_vty(vty, drv);
577
578 return CMD_SUCCESS;
579}
580
Harald Welte68628e82009-03-10 12:17:57 +0000581static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
582{
583 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
584 line->num, line->name ? line->name : "",
585 line->driver->name, VTY_NEWLINE);
586}
587
588DEFUN(show_e1line,
589 show_e1line_cmd,
590 "show e1_line [line_nr]",
591 SHOW_STR "Display information about a E1 line\n")
592{
Harald Welte1bc77352009-03-10 19:47:51 +0000593 struct e1inp_line *line;
594
595 if (argc >= 1) {
596 int num = atoi(argv[0]);
597 llist_for_each_entry(line, &e1inp_line_list, list) {
598 if (line->num == num) {
599 e1line_dump_vty(vty, line);
600 return CMD_SUCCESS;
601 }
602 }
603 return CMD_WARNING;
604 }
605
606 llist_for_each_entry(line, &e1inp_line_list, list)
607 e1line_dump_vty(vty, line);
608
609 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000610}
611
612static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
613{
Harald Welte42581822009-08-08 16:12:58 +0200614 if (ts->type == E1INP_TS_TYPE_NONE)
615 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000616 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
617 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
618 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000619}
620
621DEFUN(show_e1ts,
622 show_e1ts_cmd,
623 "show e1_timeslot [line_nr] [ts_nr]",
624 SHOW_STR "Display information about a E1 timeslot\n")
625{
Harald Welte986c3d72009-11-17 06:12:16 +0100626 struct e1inp_line *line = NULL;
Harald Welte1bc77352009-03-10 19:47:51 +0000627 struct e1inp_ts *ts;
628 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000629
Harald Welte1bc77352009-03-10 19:47:51 +0000630 if (argc == 0) {
631 llist_for_each_entry(line, &e1inp_line_list, list) {
632 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
633 ts = &line->ts[ts_nr];
634 e1ts_dump_vty(vty, ts);
635 }
636 }
637 return CMD_SUCCESS;
638 }
639 if (argc >= 1) {
640 int num = atoi(argv[0]);
641 llist_for_each_entry(line, &e1inp_line_list, list) {
642 if (line->num == num)
643 break;
644 }
645 if (!line || line->num != num) {
646 vty_out(vty, "E1 line %s is invalid%s",
647 argv[0], VTY_NEWLINE);
648 return CMD_WARNING;
649 }
650 }
651 if (argc >= 2) {
652 ts_nr = atoi(argv[1]);
653 if (ts_nr > NUM_E1_TS) {
654 vty_out(vty, "E1 timeslot %s is invalid%s",
655 argv[1], VTY_NEWLINE);
656 return CMD_WARNING;
657 }
658 ts = &line->ts[ts_nr];
659 e1ts_dump_vty(vty, ts);
660 return CMD_SUCCESS;
661 } else {
662 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
663 ts = &line->ts[ts_nr];
664 e1ts_dump_vty(vty, ts);
665 }
666 return CMD_SUCCESS;
667 }
668 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000669}
670
Harald Weltebe4b7302009-05-23 16:59:33 +0000671static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000672{
673 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
674 subscr_dump_vty(vty, pag->subscr);
675}
676
Harald Weltebe4b7302009-05-23 16:59:33 +0000677static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000678{
679 struct gsm_paging_request *pag;
680
681 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
682 paging_dump_vty(vty, pag);
683}
684
685DEFUN(show_paging,
686 show_paging_cmd,
687 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000688 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000689{
690 struct gsm_network *net = gsmnet;
691 struct gsm_bts *bts;
692 int bts_nr;
693
694 if (argc >= 1) {
695 /* use the BTS number that the user has specified */
696 bts_nr = atoi(argv[0]);
697 if (bts_nr >= net->num_bts) {
698 vty_out(vty, "%% can't find BTS %s%s", argv[0],
699 VTY_NEWLINE);
700 return CMD_WARNING;
701 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200702 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000703 bts_paging_dump_vty(vty, bts);
704
705 return CMD_SUCCESS;
706 }
707 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200708 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000709 bts_paging_dump_vty(vty, bts);
710 }
711
712 return CMD_SUCCESS;
713}
714
Harald Welte5013b2a2009-08-07 13:29:14 +0200715DEFUN(cfg_net,
716 cfg_net_cmd,
717 "network",
718 "Configure the GSM network")
719{
720 vty->index = gsmnet;
721 vty->node = GSMNET_NODE;
722
723 return CMD_SUCCESS;
724}
725
726
727DEFUN(cfg_net_ncc,
728 cfg_net_ncc_cmd,
729 "network country code <1-999>",
730 "Set the GSM network country code")
731{
732 gsmnet->country_code = atoi(argv[0]);
733
734 return CMD_SUCCESS;
735}
736
737DEFUN(cfg_net_mnc,
738 cfg_net_mnc_cmd,
739 "mobile network code <1-999>",
740 "Set the GSM mobile network code")
741{
742 gsmnet->network_code = atoi(argv[0]);
743
744 return CMD_SUCCESS;
745}
746
747DEFUN(cfg_net_name_short,
748 cfg_net_name_short_cmd,
749 "short name NAME",
750 "Set the short GSM network name")
751{
752 if (gsmnet->name_short)
753 talloc_free(gsmnet->name_short);
754
755 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
756
757 return CMD_SUCCESS;
758}
759
760DEFUN(cfg_net_name_long,
761 cfg_net_name_long_cmd,
762 "long name NAME",
763 "Set the long GSM network name")
764{
765 if (gsmnet->name_long)
766 talloc_free(gsmnet->name_long);
767
768 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
769
770 return CMD_SUCCESS;
771}
Harald Welte40f82892009-05-23 17:31:39 +0000772
Harald Welte (local)69de3972009-08-12 14:42:23 +0200773DEFUN(cfg_net_auth_policy,
774 cfg_net_auth_policy_cmd,
775 "auth policy (closed|accept-all|token)",
776 "Set the GSM network authentication policy\n")
777{
778 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
779
780 gsmnet->auth_policy = policy;
781
782 return CMD_SUCCESS;
783}
784
Harald Welte4381cfe2009-08-30 15:47:06 +0900785DEFUN(cfg_net_encryption,
786 cfg_net_encryption_cmd,
787 "encryption a5 (0|1|2)",
788 "Enable or disable encryption (A5) for this network\n")
789{
Andreas.Eversberg1059deb2009-11-17 09:55:26 +0100790 gsmnet->a5_encryption= atoi(argv[0]);
Harald Welte4381cfe2009-08-30 15:47:06 +0900791
792 return CMD_SUCCESS;
793}
794
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100795DEFUN(cfg_net_neci,
796 cfg_net_neci_cmd,
797 "neci (0|1)",
798 "Set if NECI of cell selection is to be set")
799{
800 gsmnet->neci = atoi(argv[0]);
801 return CMD_SUCCESS;
802}
803
Harald Welte5258fc42009-03-28 19:07:53 +0000804/* per-BTS configuration */
805DEFUN(cfg_bts,
806 cfg_bts_cmd,
807 "bts BTS_NR",
808 "Select a BTS to configure\n")
809{
810 int bts_nr = atoi(argv[0]);
811 struct gsm_bts *bts;
812
Harald Weltee441d9c2009-06-21 16:17:15 +0200813 if (bts_nr > gsmnet->num_bts) {
814 vty_out(vty, "%% The next unused BTS number is %u%s",
815 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000816 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200817 } else if (bts_nr == gsmnet->num_bts) {
818 /* allocate a new one */
819 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
820 HARDCODED_TSC, HARDCODED_BSIC);
821 } else
822 bts = gsm_bts_num(gsmnet, bts_nr);
823
824 if (!bts)
825 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000826
827 vty->index = bts;
828 vty->node = BTS_NODE;
829
830 return CMD_SUCCESS;
831}
832
833DEFUN(cfg_bts_type,
834 cfg_bts_type_cmd,
835 "type TYPE",
836 "Set the BTS type\n")
837{
838 struct gsm_bts *bts = vty->index;
839
Harald Weltea6fd58e2009-08-07 00:25:23 +0200840 bts->type = parse_btstype(argv[0]);
841
Harald Welte8175e952009-10-20 00:22:00 +0200842 if (is_ipaccess_bts(bts)) {
843 /* Set the default OML Stream ID to 0xff */
844 bts->oml_tei = 0xff;
845 }
846
Harald Welte5258fc42009-03-28 19:07:53 +0000847 return CMD_SUCCESS;
848}
849
Harald Weltefcd24452009-06-20 18:15:19 +0200850DEFUN(cfg_bts_band,
851 cfg_bts_band_cmd,
852 "band BAND",
853 "Set the frequency band of this BTS\n")
854{
855 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200856 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200857
858 if (band < 0) {
859 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
860 band, VTY_NEWLINE);
861 return CMD_WARNING;
862 }
863
864 bts->band = band;
865
866 return CMD_SUCCESS;
867}
868
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200869DEFUN(cfg_bts_ci,
870 cfg_bts_ci_cmd,
871 "cell_identity <0-65535>",
872 "Set the Cell identity of this BTS\n")
873{
874 struct gsm_bts *bts = vty->index;
875 int ci = atoi(argv[0]);
876
877 if (ci < 0 || ci > 0xffff) {
878 vty_out(vty, "%% CI %d is not in the valid range (0-65535)%s",
879 ci, VTY_NEWLINE);
880 return CMD_WARNING;
881 }
882 bts->cell_identity = ci;
883
884 return CMD_SUCCESS;
885}
886
Harald Welte5258fc42009-03-28 19:07:53 +0000887DEFUN(cfg_bts_lac,
888 cfg_bts_lac_cmd,
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200889 "location_area_code <0-65535>",
Harald Welte5258fc42009-03-28 19:07:53 +0000890 "Set the Location Area Code (LAC) of this BTS\n")
891{
892 struct gsm_bts *bts = vty->index;
893 int lac = atoi(argv[0]);
894
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200895 if (lac < 0 || lac > 0xffff) {
896 vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
Harald Welte5258fc42009-03-28 19:07:53 +0000897 lac, VTY_NEWLINE);
898 return CMD_WARNING;
899 }
Holger Hans Peter Freythere48b9562009-10-01 04:07:15 +0200900
901 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
902 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
903 lac, VTY_NEWLINE);
904 return CMD_WARNING;
905 }
906
Harald Welte5258fc42009-03-28 19:07:53 +0000907 bts->location_area_code = lac;
908
909 return CMD_SUCCESS;
910}
911
912DEFUN(cfg_bts_tsc,
913 cfg_bts_tsc_cmd,
914 "training_sequence_code <0-255>",
915 "Set the Training Sequence Code (TSC) of this BTS\n")
916{
917 struct gsm_bts *bts = vty->index;
918 int tsc = atoi(argv[0]);
919
920 if (tsc < 0 || tsc > 0xff) {
921 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
922 tsc, VTY_NEWLINE);
923 return CMD_WARNING;
924 }
925 bts->tsc = tsc;
926
927 return CMD_SUCCESS;
928}
929
Harald Welte78f2f502009-05-23 16:56:52 +0000930DEFUN(cfg_bts_bsic,
931 cfg_bts_bsic_cmd,
932 "base_station_id_code <0-63>",
933 "Set the Base Station Identity Code (BSIC) of this BTS\n")
934{
935 struct gsm_bts *bts = vty->index;
936 int bsic = atoi(argv[0]);
937
938 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200939 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000940 bsic, VTY_NEWLINE);
941 return CMD_WARNING;
942 }
943 bts->bsic = bsic;
944
945 return CMD_SUCCESS;
946}
947
948
Harald Welte4cc34222009-05-01 15:12:31 +0000949DEFUN(cfg_bts_unit_id,
950 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200951 "ip.access unit_id <0-65534> <0-255>",
952 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000953{
954 struct gsm_bts *bts = vty->index;
955 int site_id = atoi(argv[0]);
956 int bts_id = atoi(argv[1]);
957
Harald Welte07dc73d2009-08-07 13:27:09 +0200958 if (!is_ipaccess_bts(bts)) {
959 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
960 return CMD_WARNING;
961 }
962
Harald Welte4cc34222009-05-01 15:12:31 +0000963 bts->ip_access.site_id = site_id;
964 bts->ip_access.bts_id = bts_id;
965
966 return CMD_SUCCESS;
967}
968
Harald Welte8175e952009-10-20 00:22:00 +0200969DEFUN(cfg_bts_stream_id,
970 cfg_bts_stream_id_cmd,
971 "oml ip.access stream_id <0-255>",
972 "Set the ip.access Stream ID of the OML link of this BTS\n")
973{
974 struct gsm_bts *bts = vty->index;
975 int stream_id = atoi(argv[0]);
976
977 if (!is_ipaccess_bts(bts)) {
978 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
979 return CMD_WARNING;
980 }
981
982 bts->oml_tei = stream_id;
983
984 return CMD_SUCCESS;
985}
986
987
Harald Welte42581822009-08-08 16:12:58 +0200988DEFUN(cfg_bts_oml_e1,
989 cfg_bts_oml_e1_cmd,
990 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
991 "E1 interface to be used for OML\n")
992{
993 struct gsm_bts *bts = vty->index;
994
995 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
996
997 return CMD_SUCCESS;
998}
999
1000
1001DEFUN(cfg_bts_oml_e1_tei,
1002 cfg_bts_oml_e1_tei_cmd,
1003 "oml e1 tei <0-63>",
1004 "Set the TEI to be used for OML")
1005{
1006 struct gsm_bts *bts = vty->index;
1007
1008 bts->oml_tei = atoi(argv[0]);
1009
1010 return CMD_SUCCESS;
1011}
1012
Harald Welte7a8fa412009-08-10 13:48:16 +02001013DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
1014 "channel allocator (ascending|descending)",
1015 "Should the channel allocator allocate in reverse TRX order?")
1016{
1017 struct gsm_bts *bts = vty->index;
1018
1019 if (!strcmp(argv[0], "ascending"))
1020 bts->chan_alloc_reverse = 0;
1021 else
1022 bts->chan_alloc_reverse = 1;
1023
1024 return CMD_SUCCESS;
1025}
1026
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001027DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
1028 "cell barred (0|1)",
1029 "Should this cell be barred from access?")
1030{
1031 struct gsm_bts *bts = vty->index;
1032
1033 bts->cell_barred = atoi(argv[0]);
1034
1035 return CMD_SUCCESS;
1036}
1037
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001038DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
1039 "ms max power <0-40>",
1040 "Maximum transmit power of the MS")
1041{
1042 struct gsm_bts *bts = vty->index;
1043
1044 bts->ms_max_power = atoi(argv[0]);
1045
1046 return CMD_SUCCESS;
1047}
1048
Harald Welte (local)efc92312009-08-14 23:09:25 +02001049DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
1050 "periodic location update <0-1530>",
1051 "Periodic Location Updating Interval in Minutes")
1052{
1053 struct gsm_bts *bts = vty->index;
1054
1055 bts->chan_desc.t3212 = atoi(argv[0]) / 10;
1056
1057 return CMD_SUCCESS;
1058}
1059
Harald Welte7a8fa412009-08-10 13:48:16 +02001060
Harald Welte5258fc42009-03-28 19:07:53 +00001061/* per TRX configuration */
1062DEFUN(cfg_trx,
1063 cfg_trx_cmd,
1064 "trx TRX_NR",
1065 "Select a TRX to configure")
1066{
1067 int trx_nr = atoi(argv[0]);
1068 struct gsm_bts *bts = vty->index;
1069 struct gsm_bts_trx *trx;
1070
Harald Weltee441d9c2009-06-21 16:17:15 +02001071 if (trx_nr > bts->num_trx) {
1072 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1073 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +00001074 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +02001075 } else if (trx_nr == bts->num_trx) {
1076 /* we need to allocate a new one */
1077 trx = gsm_bts_trx_alloc(bts);
1078 } else
1079 trx = gsm_bts_trx_num(bts, trx_nr);
1080
1081 if (!trx)
1082 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001083
1084 vty->index = trx;
1085 vty->node = TRX_NODE;
1086
1087 return CMD_SUCCESS;
1088}
1089
1090DEFUN(cfg_trx_arfcn,
1091 cfg_trx_arfcn_cmd,
1092 "arfcn <1-1024>",
1093 "Set the ARFCN for this TRX\n")
1094{
1095 int arfcn = atoi(argv[0]);
1096 struct gsm_bts_trx *trx = vty->index;
1097
1098 /* FIXME: check if this ARFCN is supported by this TRX */
1099
1100 trx->arfcn = arfcn;
1101
1102 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1103 /* FIXME: use OML layer to update the ARFCN */
1104 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1105
1106 return CMD_SUCCESS;
1107}
1108
Harald Weltefcd24452009-06-20 18:15:19 +02001109DEFUN(cfg_trx_max_power_red,
1110 cfg_trx_max_power_red_cmd,
1111 "max_power_red <0-100>",
1112 "Reduction of maximum BS RF Power in dB\n")
1113{
1114 int maxpwr_r = atoi(argv[0]);
1115 struct gsm_bts_trx *trx = vty->index;
Harald Welte61a83b22009-11-18 09:20:22 +01001116 int upper_limit = 24; /* default 12.21 max power red. */
Harald Weltefcd24452009-06-20 18:15:19 +02001117
1118 /* FIXME: check if our BTS type supports more than 12 */
1119 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1120 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1121 maxpwr_r, VTY_NEWLINE);
1122 return CMD_WARNING;
1123 }
1124 if (maxpwr_r & 1) {
1125 vty_out(vty, "%% Power %d dB is not an even value%s",
1126 maxpwr_r, VTY_NEWLINE);
1127 return CMD_WARNING;
1128 }
1129
1130 trx->max_power_red = maxpwr_r;
1131
1132 /* FIXME: make sure we update this using OML */
1133
1134 return CMD_SUCCESS;
1135}
1136
Harald Welte42581822009-08-08 16:12:58 +02001137DEFUN(cfg_trx_rsl_e1,
1138 cfg_trx_rsl_e1_cmd,
1139 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1140 "E1 interface to be used for RSL\n")
1141{
1142 struct gsm_bts_trx *trx = vty->index;
1143
1144 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1145
1146 return CMD_SUCCESS;
1147}
1148
1149DEFUN(cfg_trx_rsl_e1_tei,
1150 cfg_trx_rsl_e1_tei_cmd,
1151 "rsl e1 tei <0-63>",
1152 "Set the TEI to be used for RSL")
1153{
1154 struct gsm_bts_trx *trx = vty->index;
1155
1156 trx->rsl_tei = atoi(argv[0]);
1157
1158 return CMD_SUCCESS;
1159}
1160
1161
Harald Welte5258fc42009-03-28 19:07:53 +00001162/* per TS configuration */
1163DEFUN(cfg_ts,
1164 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001165 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001166 "Select a Timeslot to configure")
1167{
1168 int ts_nr = atoi(argv[0]);
1169 struct gsm_bts_trx *trx = vty->index;
1170 struct gsm_bts_trx_ts *ts;
1171
1172 if (ts_nr >= TRX_NR_TS) {
1173 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1174 TRX_NR_TS, VTY_NEWLINE);
1175 return CMD_WARNING;
1176 }
1177
1178 ts = &trx->ts[ts_nr];
1179
1180 vty->index = ts;
1181 vty->node = TS_NODE;
1182
1183 return CMD_SUCCESS;
1184}
1185
Harald Weltea6fd58e2009-08-07 00:25:23 +02001186DEFUN(cfg_ts_pchan,
1187 cfg_ts_pchan_cmd,
1188 "phys_chan_config PCHAN",
1189 "Physical Channel configuration (TCH/SDCCH/...)")
1190{
1191 struct gsm_bts_trx_ts *ts = vty->index;
1192 int pchanc;
1193
1194 pchanc = gsm_pchan_parse(argv[0]);
1195 if (pchanc < 0)
1196 return CMD_WARNING;
1197
1198 ts->pchan = pchanc;
1199
1200 return CMD_SUCCESS;
1201}
1202
1203DEFUN(cfg_ts_e1_subslot,
1204 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001205 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001206 "E1 sub-slot connected to this on-air timeslot")
1207{
1208 struct gsm_bts_trx_ts *ts = vty->index;
1209
Harald Welte42581822009-08-08 16:12:58 +02001210 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001211
1212 return CMD_SUCCESS;
1213}
Harald Welte5258fc42009-03-28 19:07:53 +00001214
Harald Welte68628e82009-03-10 12:17:57 +00001215int bsc_vty_init(struct gsm_network *net)
1216{
1217 gsmnet = net;
1218
1219 cmd_init(1);
1220 vty_init();
1221
1222 install_element(VIEW_NODE, &show_net_cmd);
1223 install_element(VIEW_NODE, &show_bts_cmd);
1224 install_element(VIEW_NODE, &show_trx_cmd);
1225 install_element(VIEW_NODE, &show_ts_cmd);
1226 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001227
1228 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001229 install_element(VIEW_NODE, &show_e1line_cmd);
1230 install_element(VIEW_NODE, &show_e1ts_cmd);
1231
Harald Weltef5025b62009-03-28 16:55:11 +00001232 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001233
Harald Welte5013b2a2009-08-07 13:29:14 +02001234 install_element(CONFIG_NODE, &cfg_net_cmd);
1235 install_node(&net_node, config_write_net);
1236 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001237 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001238 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1239 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1240 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001241 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte4381cfe2009-08-30 15:47:06 +09001242 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001243 install_element(GSMNET_NODE, &cfg_net_neci_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001244
1245 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001246 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001247 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001248 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001249 install_element(BTS_NODE, &cfg_bts_band_cmd);
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +02001250 install_element(BTS_NODE, &cfg_bts_ci_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001251 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1252 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001253 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001254 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte8175e952009-10-20 00:22:00 +02001255 install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001256 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1257 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001258 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001259 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001260 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)efc92312009-08-14 23:09:25 +02001261 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001262
Harald Welte68628e82009-03-10 12:17:57 +00001263
Harald Welte5258fc42009-03-28 19:07:53 +00001264 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001265 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001266 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001267 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001268 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001269 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1270 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001271
Harald Welte5258fc42009-03-28 19:07:53 +00001272 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001273 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001274 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001275 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1276 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001277
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02001278 bsc_vty_init_extra(net);
Harald Welte40f82892009-05-23 17:31:39 +00001279
Harald Welte68628e82009-03-10 12:17:57 +00001280 return 0;
1281}