blob: b4aa9f4f5c7bfc0aa5e1e9c768c699633f982939 [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>
26#include <vty/vty.h>
27
28#include <arpa/inet.h>
29
Harald Welte1bc77352009-03-10 19:47:51 +000030#include <openbsc/linuxlist.h>
Harald Welte68628e82009-03-10 12:17:57 +000031#include <openbsc/gsm_data.h>
32#include <openbsc/gsm_subscriber.h>
33#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000034#include <openbsc/abis_nm.h>
Harald Welte40f82892009-05-23 17:31:39 +000035#include <openbsc/db.h>
Harald Welte5013b2a2009-08-07 13:29:14 +020036#include <openbsc/talloc.h>
Harald Welte68628e82009-03-10 12:17:57 +000037
38static struct gsm_network *gsmnet;
39
Harald Welte5013b2a2009-08-07 13:29:14 +020040struct cmd_node net_node = {
41 GSMNET_NODE,
42 "%s(network)#",
43 1,
44};
45
Harald Welte68628e82009-03-10 12:17:57 +000046struct cmd_node bts_node = {
47 BTS_NODE,
48 "%s(bts)#",
49 1,
50};
51
52struct cmd_node trx_node = {
53 TRX_NODE,
54 "%s(trx)#",
55 1,
56};
57
58struct cmd_node ts_node = {
59 TS_NODE,
60 "%s(ts)#",
61 1,
62};
63
Harald Welte40f82892009-05-23 17:31:39 +000064struct cmd_node subscr_node = {
65 SUBSCR_NODE,
66 "%s(subscriber)#",
67 1,
68};
69
Harald Welte68628e82009-03-10 12:17:57 +000070static int dummy_config_write(struct vty *v)
71{
72 return CMD_SUCCESS;
73}
74
75static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
76{
Harald Welte1bc77352009-03-10 19:47:51 +000077 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
78 nm_opstate_name(nms->operational), nms->administrative,
79 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000080}
81
82static void net_dump_vty(struct vty *vty, struct gsm_network *net)
83{
Harald Welteef235b52009-03-10 12:34:02 +000084 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
85 "and has %u BTS%s", net->country_code, net->network_code,
86 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000087 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000088 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000089 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000090 net->name_short, VTY_NEWLINE);
91}
92
93DEFUN(show_net, show_net_cmd, "show network",
94 SHOW_STR "Display information about a GSM NETWORK\n")
95{
96 struct gsm_network *net = gsmnet;
97 net_dump_vty(vty, net);
98
99 return CMD_SUCCESS;
100}
101
102static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
103{
Harald Welteedb37782009-05-01 14:59:07 +0000104 struct e1inp_line *line;
105
106 if (!e1l) {
107 vty_out(vty, " None%s", VTY_NEWLINE);
108 return;
109 }
110
111 line = e1l->ts->line;
112
113 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
114 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000115 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000116 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000117 e1l->tei, e1l->sapi, VTY_NEWLINE);
118}
119
120static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
121{
Harald Weltefcd24452009-06-20 18:15:19 +0200122 vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, "
123 "BSIC %u, TSC %u and %u TRX%s",
124 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
125 bts->location_area_code, bts->bsic, bts->tsc,
126 bts->num_trx, VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000127 if (is_ipaccess_bts(bts))
128 vty_out(vty, " Unit ID: %u/%u/0%s",
129 bts->ip_access.site_id, bts->ip_access.bts_id,
130 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000131 vty_out(vty, " NM State: ");
132 net_dump_nmstate(vty, &bts->nm_state);
133 vty_out(vty, " Site Mgr NM State: ");
134 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
135 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
136 bts->paging.available_slots, VTY_NEWLINE);
137 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
138 e1isl_dump_vty(vty, bts->oml_link);
139 /* FIXME: oml_link, chan_desc */
140}
141
142DEFUN(show_bts, show_bts_cmd, "show bts [number]",
143 SHOW_STR "Display information about a BTS\n"
144 "BTS number")
145{
146 struct gsm_network *net = gsmnet;
147 int bts_nr;
148
149 if (argc != 0) {
150 /* use the BTS number that the user has specified */
151 bts_nr = atoi(argv[0]);
152 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000153 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000154 VTY_NEWLINE);
155 return CMD_WARNING;
156 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200157 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000158 return CMD_SUCCESS;
159 }
160 /* print all BTS's */
161 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200162 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000163
164 return CMD_SUCCESS;
165}
166
Harald Welte42581822009-08-08 16:12:58 +0200167/* utility functions */
168static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
169 const char *ts, const char *ss)
170{
171 e1_link->e1_nr = atoi(line);
172 e1_link->e1_ts = atoi(ts);
173 if (!strcmp(ss, "full"))
174 e1_link->e1_ts_ss = 255;
175 else
176 e1_link->e1_ts_ss = atoi(ss);
177}
178
179static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
180 const char *prefix)
181{
182 if (!e1_link->e1_ts)
183 return;
184
185 if (e1_link->e1_ts_ss == 255)
186 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
187 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
188 else
189 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
190 prefix, e1_link->e1_nr, e1_link->e1_ts,
191 e1_link->e1_ts_ss, VTY_NEWLINE);
192}
193
194
Harald Welte67ce0732009-08-06 19:06:46 +0200195static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
196{
Harald Welte42581822009-08-08 16:12:58 +0200197 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
198 if (ts->pchan != GSM_PCHAN_NONE)
199 vty_out(vty, " phys_chan_config %s%s",
200 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
201 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte67ce0732009-08-06 19:06:46 +0200202}
203
204static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
205{
206 int i;
207
Harald Welte5013b2a2009-08-07 13:29:14 +0200208 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
209 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
210 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200211 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
212 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200213
214 for (i = 0; i < TRX_NR_TS; i++)
215 config_write_ts_single(vty, &trx->ts[i]);
216}
217
218static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
219{
220 struct gsm_bts_trx *trx;
221
Harald Welte5013b2a2009-08-07 13:29:14 +0200222 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
223 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
224 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
225 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200226 VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200227 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
228 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200229 if (is_ipaccess_bts(bts))
Harald Welte5013b2a2009-08-07 13:29:14 +0200230 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200231 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200232 else {
233 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
234 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
235 }
Harald Welte67ce0732009-08-06 19:06:46 +0200236
237 llist_for_each_entry(trx, &bts->trx_list, list)
238 config_write_trx_single(vty, trx);
239}
240
241static int config_write_bts(struct vty *v)
242{
243 struct gsm_bts *bts;
244
245 llist_for_each_entry(bts, &gsmnet->bts_list, list)
246 config_write_bts_single(v, bts);
247
248 return CMD_SUCCESS;
249}
250
Harald Welte5013b2a2009-08-07 13:29:14 +0200251static int config_write_net(struct vty *vty)
252{
253 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200254 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200255 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200256 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
257 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200258
259 return CMD_SUCCESS;
260}
Harald Welte67ce0732009-08-06 19:06:46 +0200261
Harald Welte68628e82009-03-10 12:17:57 +0000262static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
263{
264 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
265 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200266 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200267 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200268 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200269 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000270 vty_out(vty, " NM State: ");
271 net_dump_nmstate(vty, &trx->nm_state);
272 vty_out(vty, " Baseband Transceiver NM State: ");
273 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
274 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
275 e1isl_dump_vty(vty, trx->rsl_link);
276}
277
278DEFUN(show_trx,
279 show_trx_cmd,
280 "show trx [bts_nr] [trx_nr]",
281 SHOW_STR "Display information about a TRX\n")
282{
283 struct gsm_network *net = gsmnet;
284 struct gsm_bts *bts = NULL;
285 struct gsm_bts_trx *trx;
286 int bts_nr, trx_nr;
287
288 if (argc >= 1) {
289 /* use the BTS number that the user has specified */
290 bts_nr = atoi(argv[0]);
291 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000292 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000293 VTY_NEWLINE);
294 return CMD_WARNING;
295 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200296 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000297 }
298 if (argc >= 2) {
299 trx_nr = atoi(argv[1]);
300 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000301 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000302 VTY_NEWLINE);
303 return CMD_WARNING;
304 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200305 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000306 trx_dump_vty(vty, trx);
307 return CMD_SUCCESS;
308 }
309 if (bts) {
310 /* print all TRX in this BTS */
311 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200312 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000313 trx_dump_vty(vty, trx);
314 }
315 return CMD_SUCCESS;
316 }
317
318 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200319 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000320 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200321 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000322 trx_dump_vty(vty, trx);
323 }
324 }
325
326 return CMD_SUCCESS;
327}
328
Harald Welte67ce0732009-08-06 19:06:46 +0200329
Harald Welte68628e82009-03-10 12:17:57 +0000330static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
331{
332 struct in_addr ia;
333
334 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
335 ts->nr, ts->trx->nr, ts->trx->bts->nr,
336 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
337 vty_out(vty, " NM State: ");
338 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000339 if (is_ipaccess_bts(ts->trx->bts)) {
340 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200341 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000342 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200343 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000344 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000345 } else {
346 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
347 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
348 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000349 }
350}
351
352DEFUN(show_ts,
353 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000354 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000355 SHOW_STR "Display information about a TS\n")
356{
357 struct gsm_network *net = gsmnet;
358 struct gsm_bts *bts;
359 struct gsm_bts_trx *trx;
360 struct gsm_bts_trx_ts *ts;
361 int bts_nr, trx_nr, ts_nr;
362
363 if (argc >= 1) {
364 /* use the BTS number that the user has specified */
365 bts_nr = atoi(argv[0]);
366 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000367 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000368 VTY_NEWLINE);
369 return CMD_WARNING;
370 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200371 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000372 }
373 if (argc >= 2) {
374 trx_nr = atoi(argv[1]);
375 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000376 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000377 VTY_NEWLINE);
378 return CMD_WARNING;
379 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200380 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000381 }
382 if (argc >= 3) {
383 ts_nr = atoi(argv[2]);
384 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000385 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000386 VTY_NEWLINE);
387 return CMD_WARNING;
388 }
389 ts = &trx->ts[ts_nr];
390 ts_dump_vty(vty, ts);
391 return CMD_SUCCESS;
392 }
393 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200394 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000395 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200396 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000397 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
398 ts = &trx->ts[ts_nr];
399 ts_dump_vty(vty, ts);
400 }
401 }
402 }
403
404 return CMD_SUCCESS;
405}
406
407static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
408{
Harald Weltefcd24452009-06-20 18:15:19 +0200409 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000410 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000411 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000412 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000413 if (subscr->extension)
414 vty_out(vty, " Extension: %s%s", subscr->extension,
415 VTY_NEWLINE);
416 if (subscr->imsi)
417 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
418 if (subscr->tmsi)
419 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
420}
421
422static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
423{
424 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
425 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
426 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
427 VTY_NEWLINE);
428 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
429 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
430 lchan->ms_power, VTY_NEWLINE);
431 if (lchan->subscr) {
432 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
433 subscr_dump_vty(vty, lchan->subscr);
434 } else
435 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
436}
437
Harald Welte4bfdfe72009-06-10 23:11:52 +0800438#if 0
439TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000440static void call_dump_vty(struct vty *vty, struct gsm_call *call)
441{
442 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
443 call->type, call->state, call->transaction_id, VTY_NEWLINE);
444
445 if (call->local_lchan) {
446 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
447 lchan_dump_vty(vty, call->local_lchan);
448 } else
449 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
450
451 if (call->remote_lchan) {
452 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
453 lchan_dump_vty(vty, call->remote_lchan);
454 } else
455 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
456
457 if (call->called_subscr) {
458 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
459 subscr_dump_vty(vty, call->called_subscr);
460 } else
461 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
462}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800463#endif
Harald Welte68628e82009-03-10 12:17:57 +0000464
465DEFUN(show_lchan,
466 show_lchan_cmd,
467 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
468 SHOW_STR "Display information about a logical channel\n")
469{
470 struct gsm_network *net = gsmnet;
471 struct gsm_bts *bts;
472 struct gsm_bts_trx *trx;
473 struct gsm_bts_trx_ts *ts;
474 struct gsm_lchan *lchan;
475 int bts_nr, trx_nr, ts_nr, lchan_nr;
476
477 if (argc >= 1) {
478 /* use the BTS number that the user has specified */
479 bts_nr = atoi(argv[0]);
480 if (bts_nr >= net->num_bts) {
481 vty_out(vty, "%% can't find BTS %s%s", argv[0],
482 VTY_NEWLINE);
483 return CMD_WARNING;
484 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200485 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000486 }
487 if (argc >= 2) {
488 trx_nr = atoi(argv[1]);
489 if (trx_nr >= bts->num_trx) {
490 vty_out(vty, "%% can't find TRX %s%s", argv[1],
491 VTY_NEWLINE);
492 return CMD_WARNING;
493 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200494 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000495 }
496 if (argc >= 3) {
497 ts_nr = atoi(argv[2]);
498 if (ts_nr >= TRX_NR_TS) {
499 vty_out(vty, "%% can't find TS %s%s", argv[2],
500 VTY_NEWLINE);
501 return CMD_WARNING;
502 }
503 ts = &trx->ts[ts_nr];
504 }
505 if (argc >= 4) {
506 lchan_nr = atoi(argv[3]);
507 if (lchan_nr >= TS_MAX_LCHAN) {
508 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
509 VTY_NEWLINE);
510 return CMD_WARNING;
511 }
512 lchan = &ts->lchan[lchan_nr];
513 lchan_dump_vty(vty, lchan);
514 return CMD_SUCCESS;
515 }
516 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200517 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000518 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200519 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000520 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
521 ts = &trx->ts[ts_nr];
522 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
523 lchan_nr++) {
524 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000525 if (lchan->type == GSM_LCHAN_NONE)
526 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000527 lchan_dump_vty(vty, lchan);
528 }
529 }
530 }
531 }
532
533 return CMD_SUCCESS;
534}
535
Harald Welte1bc77352009-03-10 19:47:51 +0000536static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
537{
538 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
539}
540
541DEFUN(show_e1drv,
542 show_e1drv_cmd,
543 "show e1_driver",
544 SHOW_STR "Display information about available E1 drivers\n")
545{
546 struct e1inp_driver *drv;
547
548 llist_for_each_entry(drv, &e1inp_driver_list, list)
549 e1drv_dump_vty(vty, drv);
550
551 return CMD_SUCCESS;
552}
553
Harald Welte68628e82009-03-10 12:17:57 +0000554static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
555{
556 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
557 line->num, line->name ? line->name : "",
558 line->driver->name, VTY_NEWLINE);
559}
560
561DEFUN(show_e1line,
562 show_e1line_cmd,
563 "show e1_line [line_nr]",
564 SHOW_STR "Display information about a E1 line\n")
565{
Harald Welte1bc77352009-03-10 19:47:51 +0000566 struct e1inp_line *line;
567
568 if (argc >= 1) {
569 int num = atoi(argv[0]);
570 llist_for_each_entry(line, &e1inp_line_list, list) {
571 if (line->num == num) {
572 e1line_dump_vty(vty, line);
573 return CMD_SUCCESS;
574 }
575 }
576 return CMD_WARNING;
577 }
578
579 llist_for_each_entry(line, &e1inp_line_list, list)
580 e1line_dump_vty(vty, line);
581
582 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000583}
584
585static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
586{
Harald Welte42581822009-08-08 16:12:58 +0200587 if (ts->type == E1INP_TS_TYPE_NONE)
588 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000589 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
590 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
591 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000592}
593
594DEFUN(show_e1ts,
595 show_e1ts_cmd,
596 "show e1_timeslot [line_nr] [ts_nr]",
597 SHOW_STR "Display information about a E1 timeslot\n")
598{
Harald Welte1bc77352009-03-10 19:47:51 +0000599 struct e1inp_line *line;
600 struct e1inp_ts *ts;
601 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000602
Harald Welte1bc77352009-03-10 19:47:51 +0000603 if (argc == 0) {
604 llist_for_each_entry(line, &e1inp_line_list, list) {
605 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
606 ts = &line->ts[ts_nr];
607 e1ts_dump_vty(vty, ts);
608 }
609 }
610 return CMD_SUCCESS;
611 }
612 if (argc >= 1) {
613 int num = atoi(argv[0]);
614 llist_for_each_entry(line, &e1inp_line_list, list) {
615 if (line->num == num)
616 break;
617 }
618 if (!line || line->num != num) {
619 vty_out(vty, "E1 line %s is invalid%s",
620 argv[0], VTY_NEWLINE);
621 return CMD_WARNING;
622 }
623 }
624 if (argc >= 2) {
625 ts_nr = atoi(argv[1]);
626 if (ts_nr > NUM_E1_TS) {
627 vty_out(vty, "E1 timeslot %s is invalid%s",
628 argv[1], VTY_NEWLINE);
629 return CMD_WARNING;
630 }
631 ts = &line->ts[ts_nr];
632 e1ts_dump_vty(vty, ts);
633 return CMD_SUCCESS;
634 } else {
635 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
636 ts = &line->ts[ts_nr];
637 e1ts_dump_vty(vty, ts);
638 }
639 return CMD_SUCCESS;
640 }
641 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000642}
643
Harald Weltebe4b7302009-05-23 16:59:33 +0000644static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000645{
646 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
647 subscr_dump_vty(vty, pag->subscr);
648}
649
Harald Weltebe4b7302009-05-23 16:59:33 +0000650static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000651{
652 struct gsm_paging_request *pag;
653
654 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
655 paging_dump_vty(vty, pag);
656}
657
658DEFUN(show_paging,
659 show_paging_cmd,
660 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000661 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000662{
663 struct gsm_network *net = gsmnet;
664 struct gsm_bts *bts;
665 int bts_nr;
666
667 if (argc >= 1) {
668 /* use the BTS number that the user has specified */
669 bts_nr = atoi(argv[0]);
670 if (bts_nr >= net->num_bts) {
671 vty_out(vty, "%% can't find BTS %s%s", argv[0],
672 VTY_NEWLINE);
673 return CMD_WARNING;
674 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200675 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000676 bts_paging_dump_vty(vty, bts);
677
678 return CMD_SUCCESS;
679 }
680 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200681 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000682 bts_paging_dump_vty(vty, bts);
683 }
684
685 return CMD_SUCCESS;
686}
687
Harald Welte40f82892009-05-23 17:31:39 +0000688/* per-subscriber configuration */
689DEFUN(cfg_subscr,
690 cfg_subscr_cmd,
691 "subscriber IMSI",
692 "Select a Subscriber to configure\n")
693{
694 const char *imsi = argv[0];
695 struct gsm_subscriber *subscr;
696
Harald Welte761e9442009-07-23 19:21:02 +0200697 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000698 if (!subscr) {
699 vty_out(vty, "%% No subscriber for IMSI %s%s",
700 imsi, VTY_NEWLINE);
701 return CMD_WARNING;
702 }
703
704 vty->index = subscr;
705 vty->node = SUBSCR_NODE;
706
707 return CMD_SUCCESS;
708}
709
Harald Welte5013b2a2009-08-07 13:29:14 +0200710DEFUN(cfg_net,
711 cfg_net_cmd,
712 "network",
713 "Configure the GSM network")
714{
715 vty->index = gsmnet;
716 vty->node = GSMNET_NODE;
717
718 return CMD_SUCCESS;
719}
720
721
722DEFUN(cfg_net_ncc,
723 cfg_net_ncc_cmd,
724 "network country code <1-999>",
725 "Set the GSM network country code")
726{
727 gsmnet->country_code = atoi(argv[0]);
728
729 return CMD_SUCCESS;
730}
731
732DEFUN(cfg_net_mnc,
733 cfg_net_mnc_cmd,
734 "mobile network code <1-999>",
735 "Set the GSM mobile network code")
736{
737 gsmnet->network_code = atoi(argv[0]);
738
739 return CMD_SUCCESS;
740}
741
742DEFUN(cfg_net_name_short,
743 cfg_net_name_short_cmd,
744 "short name NAME",
745 "Set the short GSM network name")
746{
747 if (gsmnet->name_short)
748 talloc_free(gsmnet->name_short);
749
750 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
751
752 return CMD_SUCCESS;
753}
754
755DEFUN(cfg_net_name_long,
756 cfg_net_name_long_cmd,
757 "long name NAME",
758 "Set the long GSM network name")
759{
760 if (gsmnet->name_long)
761 talloc_free(gsmnet->name_long);
762
763 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
764
765 return CMD_SUCCESS;
766}
Harald Welte40f82892009-05-23 17:31:39 +0000767
Harald Welte5258fc42009-03-28 19:07:53 +0000768/* per-BTS configuration */
769DEFUN(cfg_bts,
770 cfg_bts_cmd,
771 "bts BTS_NR",
772 "Select a BTS to configure\n")
773{
774 int bts_nr = atoi(argv[0]);
775 struct gsm_bts *bts;
776
Harald Weltee441d9c2009-06-21 16:17:15 +0200777 if (bts_nr > gsmnet->num_bts) {
778 vty_out(vty, "%% The next unused BTS number is %u%s",
779 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000780 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200781 } else if (bts_nr == gsmnet->num_bts) {
782 /* allocate a new one */
783 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
784 HARDCODED_TSC, HARDCODED_BSIC);
785 } else
786 bts = gsm_bts_num(gsmnet, bts_nr);
787
788 if (!bts)
789 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000790
791 vty->index = bts;
792 vty->node = BTS_NODE;
793
794 return CMD_SUCCESS;
795}
796
797DEFUN(cfg_bts_type,
798 cfg_bts_type_cmd,
799 "type TYPE",
800 "Set the BTS type\n")
801{
802 struct gsm_bts *bts = vty->index;
803
Harald Weltea6fd58e2009-08-07 00:25:23 +0200804 bts->type = parse_btstype(argv[0]);
805
Harald Welte5258fc42009-03-28 19:07:53 +0000806 return CMD_SUCCESS;
807}
808
Harald Weltefcd24452009-06-20 18:15:19 +0200809DEFUN(cfg_bts_band,
810 cfg_bts_band_cmd,
811 "band BAND",
812 "Set the frequency band of this BTS\n")
813{
814 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200815 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200816
817 if (band < 0) {
818 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
819 band, VTY_NEWLINE);
820 return CMD_WARNING;
821 }
822
823 bts->band = band;
824
825 return CMD_SUCCESS;
826}
827
Harald Welte5258fc42009-03-28 19:07:53 +0000828DEFUN(cfg_bts_lac,
829 cfg_bts_lac_cmd,
830 "location_area_code <0-255>",
831 "Set the Location Area Code (LAC) of this BTS\n")
832{
833 struct gsm_bts *bts = vty->index;
834 int lac = atoi(argv[0]);
835
836 if (lac < 0 || lac > 0xff) {
837 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
838 lac, VTY_NEWLINE);
839 return CMD_WARNING;
840 }
841 bts->location_area_code = lac;
842
843 return CMD_SUCCESS;
844}
845
846DEFUN(cfg_bts_tsc,
847 cfg_bts_tsc_cmd,
848 "training_sequence_code <0-255>",
849 "Set the Training Sequence Code (TSC) of this BTS\n")
850{
851 struct gsm_bts *bts = vty->index;
852 int tsc = atoi(argv[0]);
853
854 if (tsc < 0 || tsc > 0xff) {
855 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
856 tsc, VTY_NEWLINE);
857 return CMD_WARNING;
858 }
859 bts->tsc = tsc;
860
861 return CMD_SUCCESS;
862}
863
Harald Welte78f2f502009-05-23 16:56:52 +0000864DEFUN(cfg_bts_bsic,
865 cfg_bts_bsic_cmd,
866 "base_station_id_code <0-63>",
867 "Set the Base Station Identity Code (BSIC) of this BTS\n")
868{
869 struct gsm_bts *bts = vty->index;
870 int bsic = atoi(argv[0]);
871
872 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200873 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000874 bsic, VTY_NEWLINE);
875 return CMD_WARNING;
876 }
877 bts->bsic = bsic;
878
879 return CMD_SUCCESS;
880}
881
882
Harald Welte4cc34222009-05-01 15:12:31 +0000883DEFUN(cfg_bts_unit_id,
884 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200885 "ip.access unit_id <0-65534> <0-255>",
886 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000887{
888 struct gsm_bts *bts = vty->index;
889 int site_id = atoi(argv[0]);
890 int bts_id = atoi(argv[1]);
891
892 if (site_id < 0 || site_id > 65534) {
893 vty_out(vty, "%% Site ID %d is not in the valid range%s",
894 site_id, VTY_NEWLINE);
895 return CMD_WARNING;
896 }
897 if (site_id < 0 || site_id > 255) {
898 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
899 bts_id, VTY_NEWLINE);
900 return CMD_WARNING;
901 }
Harald Welte07dc73d2009-08-07 13:27:09 +0200902
903 if (!is_ipaccess_bts(bts)) {
904 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
905 return CMD_WARNING;
906 }
907
Harald Welte4cc34222009-05-01 15:12:31 +0000908 bts->ip_access.site_id = site_id;
909 bts->ip_access.bts_id = bts_id;
910
911 return CMD_SUCCESS;
912}
913
Harald Welte42581822009-08-08 16:12:58 +0200914DEFUN(cfg_bts_oml_e1,
915 cfg_bts_oml_e1_cmd,
916 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
917 "E1 interface to be used for OML\n")
918{
919 struct gsm_bts *bts = vty->index;
920
921 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
922
923 return CMD_SUCCESS;
924}
925
926
927DEFUN(cfg_bts_oml_e1_tei,
928 cfg_bts_oml_e1_tei_cmd,
929 "oml e1 tei <0-63>",
930 "Set the TEI to be used for OML")
931{
932 struct gsm_bts *bts = vty->index;
933
934 bts->oml_tei = atoi(argv[0]);
935
936 return CMD_SUCCESS;
937}
938
Harald Welte5258fc42009-03-28 19:07:53 +0000939/* per TRX configuration */
940DEFUN(cfg_trx,
941 cfg_trx_cmd,
942 "trx TRX_NR",
943 "Select a TRX to configure")
944{
945 int trx_nr = atoi(argv[0]);
946 struct gsm_bts *bts = vty->index;
947 struct gsm_bts_trx *trx;
948
Harald Weltee441d9c2009-06-21 16:17:15 +0200949 if (trx_nr > bts->num_trx) {
950 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
951 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000952 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200953 } else if (trx_nr == bts->num_trx) {
954 /* we need to allocate a new one */
955 trx = gsm_bts_trx_alloc(bts);
956 } else
957 trx = gsm_bts_trx_num(bts, trx_nr);
958
959 if (!trx)
960 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000961
962 vty->index = trx;
963 vty->node = TRX_NODE;
964
965 return CMD_SUCCESS;
966}
967
968DEFUN(cfg_trx_arfcn,
969 cfg_trx_arfcn_cmd,
970 "arfcn <1-1024>",
971 "Set the ARFCN for this TRX\n")
972{
973 int arfcn = atoi(argv[0]);
974 struct gsm_bts_trx *trx = vty->index;
975
976 /* FIXME: check if this ARFCN is supported by this TRX */
977
978 trx->arfcn = arfcn;
979
980 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
981 /* FIXME: use OML layer to update the ARFCN */
982 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
983
984 return CMD_SUCCESS;
985}
986
Harald Weltefcd24452009-06-20 18:15:19 +0200987DEFUN(cfg_trx_max_power_red,
988 cfg_trx_max_power_red_cmd,
989 "max_power_red <0-100>",
990 "Reduction of maximum BS RF Power in dB\n")
991{
992 int maxpwr_r = atoi(argv[0]);
993 struct gsm_bts_trx *trx = vty->index;
994 int upper_limit = 12; /* default 12.21 max power red. */
995
996 /* FIXME: check if our BTS type supports more than 12 */
997 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
998 vty_out(vty, "%% Power %d dB is not in the valid range%s",
999 maxpwr_r, VTY_NEWLINE);
1000 return CMD_WARNING;
1001 }
1002 if (maxpwr_r & 1) {
1003 vty_out(vty, "%% Power %d dB is not an even value%s",
1004 maxpwr_r, VTY_NEWLINE);
1005 return CMD_WARNING;
1006 }
1007
1008 trx->max_power_red = maxpwr_r;
1009
1010 /* FIXME: make sure we update this using OML */
1011
1012 return CMD_SUCCESS;
1013}
1014
Harald Welte42581822009-08-08 16:12:58 +02001015DEFUN(cfg_trx_rsl_e1,
1016 cfg_trx_rsl_e1_cmd,
1017 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1018 "E1 interface to be used for RSL\n")
1019{
1020 struct gsm_bts_trx *trx = vty->index;
1021
1022 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1023
1024 return CMD_SUCCESS;
1025}
1026
1027DEFUN(cfg_trx_rsl_e1_tei,
1028 cfg_trx_rsl_e1_tei_cmd,
1029 "rsl e1 tei <0-63>",
1030 "Set the TEI to be used for RSL")
1031{
1032 struct gsm_bts_trx *trx = vty->index;
1033
1034 trx->rsl_tei = atoi(argv[0]);
1035
1036 return CMD_SUCCESS;
1037}
1038
1039
Harald Welte5258fc42009-03-28 19:07:53 +00001040/* per TS configuration */
1041DEFUN(cfg_ts,
1042 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001043 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001044 "Select a Timeslot to configure")
1045{
1046 int ts_nr = atoi(argv[0]);
1047 struct gsm_bts_trx *trx = vty->index;
1048 struct gsm_bts_trx_ts *ts;
1049
1050 if (ts_nr >= TRX_NR_TS) {
1051 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1052 TRX_NR_TS, VTY_NEWLINE);
1053 return CMD_WARNING;
1054 }
1055
1056 ts = &trx->ts[ts_nr];
1057
1058 vty->index = ts;
1059 vty->node = TS_NODE;
1060
1061 return CMD_SUCCESS;
1062}
1063
Harald Weltea6fd58e2009-08-07 00:25:23 +02001064DEFUN(cfg_ts_pchan,
1065 cfg_ts_pchan_cmd,
1066 "phys_chan_config PCHAN",
1067 "Physical Channel configuration (TCH/SDCCH/...)")
1068{
1069 struct gsm_bts_trx_ts *ts = vty->index;
1070 int pchanc;
1071
1072 pchanc = gsm_pchan_parse(argv[0]);
1073 if (pchanc < 0)
1074 return CMD_WARNING;
1075
1076 ts->pchan = pchanc;
1077
1078 return CMD_SUCCESS;
1079}
1080
1081DEFUN(cfg_ts_e1_subslot,
1082 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001083 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001084 "E1 sub-slot connected to this on-air timeslot")
1085{
1086 struct gsm_bts_trx_ts *ts = vty->index;
1087
Harald Welte42581822009-08-08 16:12:58 +02001088 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001089
1090 return CMD_SUCCESS;
1091}
Harald Welte5258fc42009-03-28 19:07:53 +00001092
Harald Welte40f82892009-05-23 17:31:39 +00001093/* Subscriber */
1094DEFUN(show_subscr,
1095 show_subscr_cmd,
1096 "show subscriber [IMSI]",
1097 SHOW_STR "Display information about a subscriber\n")
1098{
1099 const char *imsi;
1100 struct gsm_subscriber *subscr;
1101
1102 if (argc >= 1) {
1103 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +02001104 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +00001105 if (!subscr) {
1106 vty_out(vty, "%% unknown subscriber%s",
1107 VTY_NEWLINE);
1108 return CMD_WARNING;
1109 }
1110 subscr_dump_vty(vty, subscr);
1111
1112 return CMD_SUCCESS;
1113 }
1114
1115 /* FIXME: iterate over all subscribers ? */
1116 return CMD_WARNING;
1117
1118 return CMD_SUCCESS;
1119}
1120
Harald Welte76042182009-08-08 16:03:15 +02001121DEFUN(sms_send_pend,
1122 sms_send_pend_cmd,
1123 "sms send pending MIN_ID",
1124 "Send all pending SMS starting from MIN_ID")
1125{
1126 struct gsm_sms *sms;
1127
1128 sms = db_sms_get_unsent(gsmnet, atoi(argv[0]));
1129 if (!sms)
1130 return CMD_WARNING;
1131
1132 if (!sms->receiver) {
1133 sms_free(sms);
1134 return CMD_WARNING;
1135 }
1136
1137 gsm411_send_sms_subscr(sms->receiver, sms);
1138
1139 return CMD_SUCCESS;
1140}
1141
1142DEFUN(sms_send_ext,
1143 sms_send_ext_cmd,
1144 "sms send extension EXTEN .LINE",
1145 "Send a message to a subscriber identified by EXTEN")
1146{
1147 struct gsm_sms *sms;
1148
1149 //gsm411_send_sms_subscr(sms->receiver, sms);
1150
1151 return CMD_SUCCESS;
1152}
1153
1154DEFUN(sms_send_imsi,
1155 sms_send_imsi_cmd,
1156 "sms send imsi IMSI .LINE",
1157 "Send a message to a subscriber identified by IMSI")
1158{
1159 struct gsm_sms *sms;
1160
1161 //gsm411_send_sms_subscr(sms->receiver, sms);
1162
1163 return CMD_SUCCESS;
1164}
1165
1166
Harald Welte40f82892009-05-23 17:31:39 +00001167DEFUN(cfg_subscr_name,
1168 cfg_subscr_name_cmd,
1169 "name NAME",
1170 "Set the name of the subscriber")
1171{
1172 const char *name = argv[0];
1173 struct gsm_subscriber *subscr = vty->index;
1174
1175 strncpy(subscr->name, name, sizeof(subscr->name));
1176
1177 db_sync_subscriber(subscr);
1178
1179 return CMD_SUCCESS;
1180}
1181
1182DEFUN(cfg_subscr_extension,
1183 cfg_subscr_extension_cmd,
1184 "extension EXTENSION",
1185 "Set the extension of the subscriber")
1186{
1187 const char *name = argv[0];
1188 struct gsm_subscriber *subscr = vty->index;
1189
1190 strncpy(subscr->extension, name, sizeof(subscr->extension));
1191
1192 db_sync_subscriber(subscr);
1193
1194 return CMD_SUCCESS;
1195}
1196
1197DEFUN(cfg_subscr_authorized,
1198 cfg_subscr_authorized_cmd,
1199 "auth <0-1>",
1200 "Set the authorization status of the subscriber")
1201{
1202 int auth = atoi(argv[0]);
1203 struct gsm_subscriber *subscr = vty->index;
1204
1205 if (auth)
1206 subscr->authorized = 1;
1207 else
1208 subscr->authorized = 0;
1209
1210 db_sync_subscriber(subscr);
1211
1212 return CMD_SUCCESS;
1213}
1214
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 Welte40f82892009-05-23 17:31:39 +00001234 install_element(VIEW_NODE, &show_subscr_cmd);
1235
Harald Welte76042182009-08-08 16:03:15 +02001236 install_element(VIEW_NODE, &sms_send_pend_cmd);
1237#if 0
1238 install_element(VIEW_NODE, &sms_send_ext_cmd);
1239 install_element(VIEW_NODE, &sms_send_imsi_cmd);
1240#endif
1241
Harald Welte5013b2a2009-08-07 13:29:14 +02001242 install_element(CONFIG_NODE, &cfg_net_cmd);
1243 install_node(&net_node, config_write_net);
1244 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001245 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001246 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1247 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1248 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
1249
1250 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001251 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001252 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001253 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001254 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001255 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1256 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001257 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001258 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001259 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1260 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001261
Harald Welte5258fc42009-03-28 19:07:53 +00001262 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001263 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001264 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001265 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001266 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001267 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1268 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001269
Harald Welte5258fc42009-03-28 19:07:53 +00001270 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001271 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001272 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001273 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1274 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001275
Harald Welte40f82892009-05-23 17:31:39 +00001276 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1277 install_node(&subscr_node, dummy_config_write);
1278 install_default(SUBSCR_NODE);
1279 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1280 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1281 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1282
Harald Welte68628e82009-03-10 12:17:57 +00001283 return 0;
1284}