blob: 05b0070a10b65320ed1aa5e0bdba67c348e09eca [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>
33#include <openbsc/gsm_subscriber.h>
34#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000035#include <openbsc/abis_nm.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020036#include <openbsc/gsm_utils.h>
Harald Welte40f82892009-05-23 17:31:39 +000037#include <openbsc/db.h>
Harald Welte5013b2a2009-08-07 13:29:14 +020038#include <openbsc/talloc.h>
Harald Welte68628e82009-03-10 12:17:57 +000039
40static struct gsm_network *gsmnet;
41
Harald Welte5013b2a2009-08-07 13:29:14 +020042struct cmd_node net_node = {
43 GSMNET_NODE,
44 "%s(network)#",
45 1,
46};
47
Harald Welte68628e82009-03-10 12:17:57 +000048struct cmd_node bts_node = {
49 BTS_NODE,
50 "%s(bts)#",
51 1,
52};
53
54struct cmd_node trx_node = {
55 TRX_NODE,
56 "%s(trx)#",
57 1,
58};
59
60struct cmd_node ts_node = {
61 TS_NODE,
62 "%s(ts)#",
63 1,
64};
65
Harald Welte40f82892009-05-23 17:31:39 +000066struct cmd_node subscr_node = {
67 SUBSCR_NODE,
68 "%s(subscriber)#",
69 1,
70};
71
Harald Welte68628e82009-03-10 12:17:57 +000072static int dummy_config_write(struct vty *v)
73{
74 return CMD_SUCCESS;
75}
76
77static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
78{
Harald Welte1bc77352009-03-10 19:47:51 +000079 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
80 nm_opstate_name(nms->operational), nms->administrative,
81 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000082}
83
84static void net_dump_vty(struct vty *vty, struct gsm_network *net)
85{
Harald Welteef235b52009-03-10 12:34:02 +000086 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
87 "and has %u BTS%s", net->country_code, net->network_code,
88 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000089 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000090 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000091 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000092 net->name_short, VTY_NEWLINE);
93}
94
95DEFUN(show_net, show_net_cmd, "show network",
96 SHOW_STR "Display information about a GSM NETWORK\n")
97{
98 struct gsm_network *net = gsmnet;
99 net_dump_vty(vty, net);
100
101 return CMD_SUCCESS;
102}
103
104static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
105{
Harald Welteedb37782009-05-01 14:59:07 +0000106 struct e1inp_line *line;
107
108 if (!e1l) {
109 vty_out(vty, " None%s", VTY_NEWLINE);
110 return;
111 }
112
113 line = e1l->ts->line;
114
115 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
116 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000117 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000118 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000119 e1l->tei, e1l->sapi, VTY_NEWLINE);
120}
121
122static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
123{
Harald Weltefcd24452009-06-20 18:15:19 +0200124 vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, "
125 "BSIC %u, TSC %u and %u TRX%s",
126 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
127 bts->location_area_code, bts->bsic, bts->tsc,
128 bts->num_trx, VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000129 if (is_ipaccess_bts(bts))
130 vty_out(vty, " Unit ID: %u/%u/0%s",
131 bts->ip_access.site_id, bts->ip_access.bts_id,
132 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000133 vty_out(vty, " NM State: ");
134 net_dump_nmstate(vty, &bts->nm_state);
135 vty_out(vty, " Site Mgr NM State: ");
136 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
137 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
138 bts->paging.available_slots, VTY_NEWLINE);
139 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
140 e1isl_dump_vty(vty, bts->oml_link);
141 /* FIXME: oml_link, chan_desc */
142}
143
144DEFUN(show_bts, show_bts_cmd, "show bts [number]",
145 SHOW_STR "Display information about a BTS\n"
146 "BTS number")
147{
148 struct gsm_network *net = gsmnet;
149 int bts_nr;
150
151 if (argc != 0) {
152 /* use the BTS number that the user has specified */
153 bts_nr = atoi(argv[0]);
154 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000155 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000156 VTY_NEWLINE);
157 return CMD_WARNING;
158 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200159 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000160 return CMD_SUCCESS;
161 }
162 /* print all BTS's */
163 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200164 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000165
166 return CMD_SUCCESS;
167}
168
Harald Welte42581822009-08-08 16:12:58 +0200169/* utility functions */
170static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
171 const char *ts, const char *ss)
172{
173 e1_link->e1_nr = atoi(line);
174 e1_link->e1_ts = atoi(ts);
175 if (!strcmp(ss, "full"))
176 e1_link->e1_ts_ss = 255;
177 else
178 e1_link->e1_ts_ss = atoi(ss);
179}
180
181static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
182 const char *prefix)
183{
184 if (!e1_link->e1_ts)
185 return;
186
187 if (e1_link->e1_ts_ss == 255)
188 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
189 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
190 else
191 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
192 prefix, e1_link->e1_nr, e1_link->e1_ts,
193 e1_link->e1_ts_ss, VTY_NEWLINE);
194}
195
196
Harald Welte67ce0732009-08-06 19:06:46 +0200197static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
198{
Harald Welte42581822009-08-08 16:12:58 +0200199 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
200 if (ts->pchan != GSM_PCHAN_NONE)
201 vty_out(vty, " phys_chan_config %s%s",
202 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
203 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte67ce0732009-08-06 19:06:46 +0200204}
205
206static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
207{
208 int i;
209
Harald Welte5013b2a2009-08-07 13:29:14 +0200210 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
211 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
212 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200213 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
214 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200215
216 for (i = 0; i < TRX_NR_TS; i++)
217 config_write_ts_single(vty, &trx->ts[i]);
218}
219
220static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
221{
222 struct gsm_bts_trx *trx;
223
Harald Welte5013b2a2009-08-07 13:29:14 +0200224 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
225 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
226 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
227 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200228 VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200229 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
230 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200231 if (is_ipaccess_bts(bts))
Harald Welte5013b2a2009-08-07 13:29:14 +0200232 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200233 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200234 else {
235 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
236 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
237 }
Harald Welte67ce0732009-08-06 19:06:46 +0200238
239 llist_for_each_entry(trx, &bts->trx_list, list)
240 config_write_trx_single(vty, trx);
241}
242
243static int config_write_bts(struct vty *v)
244{
245 struct gsm_bts *bts;
246
247 llist_for_each_entry(bts, &gsmnet->bts_list, list)
248 config_write_bts_single(v, bts);
249
250 return CMD_SUCCESS;
251}
252
Harald Welte5013b2a2009-08-07 13:29:14 +0200253static int config_write_net(struct vty *vty)
254{
255 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200256 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200257 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200258 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
259 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200260
261 return CMD_SUCCESS;
262}
Harald Welte67ce0732009-08-06 19:06:46 +0200263
Harald Welte68628e82009-03-10 12:17:57 +0000264static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
265{
266 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
267 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200268 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200269 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200270 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200271 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000272 vty_out(vty, " NM State: ");
273 net_dump_nmstate(vty, &trx->nm_state);
274 vty_out(vty, " Baseband Transceiver NM State: ");
275 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
276 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
277 e1isl_dump_vty(vty, trx->rsl_link);
278}
279
280DEFUN(show_trx,
281 show_trx_cmd,
282 "show trx [bts_nr] [trx_nr]",
283 SHOW_STR "Display information about a TRX\n")
284{
285 struct gsm_network *net = gsmnet;
286 struct gsm_bts *bts = NULL;
287 struct gsm_bts_trx *trx;
288 int bts_nr, trx_nr;
289
290 if (argc >= 1) {
291 /* use the BTS number that the user has specified */
292 bts_nr = atoi(argv[0]);
293 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000294 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000295 VTY_NEWLINE);
296 return CMD_WARNING;
297 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200298 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000299 }
300 if (argc >= 2) {
301 trx_nr = atoi(argv[1]);
302 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000303 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000304 VTY_NEWLINE);
305 return CMD_WARNING;
306 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200307 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000308 trx_dump_vty(vty, trx);
309 return CMD_SUCCESS;
310 }
311 if (bts) {
312 /* print all TRX in this BTS */
313 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200314 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000315 trx_dump_vty(vty, trx);
316 }
317 return CMD_SUCCESS;
318 }
319
320 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200321 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000322 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200323 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000324 trx_dump_vty(vty, trx);
325 }
326 }
327
328 return CMD_SUCCESS;
329}
330
Harald Welte67ce0732009-08-06 19:06:46 +0200331
Harald Welte68628e82009-03-10 12:17:57 +0000332static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
333{
334 struct in_addr ia;
335
336 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
337 ts->nr, ts->trx->nr, ts->trx->bts->nr,
338 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
339 vty_out(vty, " NM State: ");
340 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000341 if (is_ipaccess_bts(ts->trx->bts)) {
342 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200343 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000344 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200345 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000346 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000347 } else {
348 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
349 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
350 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000351 }
352}
353
354DEFUN(show_ts,
355 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000356 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000357 SHOW_STR "Display information about a TS\n")
358{
359 struct gsm_network *net = gsmnet;
360 struct gsm_bts *bts;
361 struct gsm_bts_trx *trx;
362 struct gsm_bts_trx_ts *ts;
363 int bts_nr, trx_nr, ts_nr;
364
365 if (argc >= 1) {
366 /* use the BTS number that the user has specified */
367 bts_nr = atoi(argv[0]);
368 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000369 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000370 VTY_NEWLINE);
371 return CMD_WARNING;
372 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200373 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000374 }
375 if (argc >= 2) {
376 trx_nr = atoi(argv[1]);
377 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000378 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000379 VTY_NEWLINE);
380 return CMD_WARNING;
381 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200382 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000383 }
384 if (argc >= 3) {
385 ts_nr = atoi(argv[2]);
386 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000387 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000388 VTY_NEWLINE);
389 return CMD_WARNING;
390 }
391 ts = &trx->ts[ts_nr];
392 ts_dump_vty(vty, ts);
393 return CMD_SUCCESS;
394 }
395 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200396 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000397 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200398 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000399 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
400 ts = &trx->ts[ts_nr];
401 ts_dump_vty(vty, ts);
402 }
403 }
404 }
405
406 return CMD_SUCCESS;
407}
408
409static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
410{
Harald Weltefcd24452009-06-20 18:15:19 +0200411 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000412 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000413 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000414 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000415 if (subscr->extension)
416 vty_out(vty, " Extension: %s%s", subscr->extension,
417 VTY_NEWLINE);
418 if (subscr->imsi)
419 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
420 if (subscr->tmsi)
421 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
422}
423
424static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
425{
426 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
427 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
428 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
429 VTY_NEWLINE);
430 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
431 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
432 lchan->ms_power, VTY_NEWLINE);
433 if (lchan->subscr) {
434 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
435 subscr_dump_vty(vty, lchan->subscr);
436 } else
437 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
438}
439
Harald Welte4bfdfe72009-06-10 23:11:52 +0800440#if 0
441TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000442static void call_dump_vty(struct vty *vty, struct gsm_call *call)
443{
444 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
445 call->type, call->state, call->transaction_id, VTY_NEWLINE);
446
447 if (call->local_lchan) {
448 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
449 lchan_dump_vty(vty, call->local_lchan);
450 } else
451 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
452
453 if (call->remote_lchan) {
454 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
455 lchan_dump_vty(vty, call->remote_lchan);
456 } else
457 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
458
459 if (call->called_subscr) {
460 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
461 subscr_dump_vty(vty, call->called_subscr);
462 } else
463 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
464}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800465#endif
Harald Welte68628e82009-03-10 12:17:57 +0000466
467DEFUN(show_lchan,
468 show_lchan_cmd,
469 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
470 SHOW_STR "Display information about a logical channel\n")
471{
472 struct gsm_network *net = gsmnet;
473 struct gsm_bts *bts;
474 struct gsm_bts_trx *trx;
475 struct gsm_bts_trx_ts *ts;
476 struct gsm_lchan *lchan;
477 int bts_nr, trx_nr, ts_nr, lchan_nr;
478
479 if (argc >= 1) {
480 /* use the BTS number that the user has specified */
481 bts_nr = atoi(argv[0]);
482 if (bts_nr >= net->num_bts) {
483 vty_out(vty, "%% can't find BTS %s%s", argv[0],
484 VTY_NEWLINE);
485 return CMD_WARNING;
486 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200487 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000488 }
489 if (argc >= 2) {
490 trx_nr = atoi(argv[1]);
491 if (trx_nr >= bts->num_trx) {
492 vty_out(vty, "%% can't find TRX %s%s", argv[1],
493 VTY_NEWLINE);
494 return CMD_WARNING;
495 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200496 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000497 }
498 if (argc >= 3) {
499 ts_nr = atoi(argv[2]);
500 if (ts_nr >= TRX_NR_TS) {
501 vty_out(vty, "%% can't find TS %s%s", argv[2],
502 VTY_NEWLINE);
503 return CMD_WARNING;
504 }
505 ts = &trx->ts[ts_nr];
506 }
507 if (argc >= 4) {
508 lchan_nr = atoi(argv[3]);
509 if (lchan_nr >= TS_MAX_LCHAN) {
510 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
511 VTY_NEWLINE);
512 return CMD_WARNING;
513 }
514 lchan = &ts->lchan[lchan_nr];
515 lchan_dump_vty(vty, lchan);
516 return CMD_SUCCESS;
517 }
518 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200519 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000520 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200521 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000522 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
523 ts = &trx->ts[ts_nr];
524 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
525 lchan_nr++) {
526 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000527 if (lchan->type == GSM_LCHAN_NONE)
528 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000529 lchan_dump_vty(vty, lchan);
530 }
531 }
532 }
533 }
534
535 return CMD_SUCCESS;
536}
537
Harald Welte1bc77352009-03-10 19:47:51 +0000538static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
539{
540 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
541}
542
543DEFUN(show_e1drv,
544 show_e1drv_cmd,
545 "show e1_driver",
546 SHOW_STR "Display information about available E1 drivers\n")
547{
548 struct e1inp_driver *drv;
549
550 llist_for_each_entry(drv, &e1inp_driver_list, list)
551 e1drv_dump_vty(vty, drv);
552
553 return CMD_SUCCESS;
554}
555
Harald Welte68628e82009-03-10 12:17:57 +0000556static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
557{
558 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
559 line->num, line->name ? line->name : "",
560 line->driver->name, VTY_NEWLINE);
561}
562
563DEFUN(show_e1line,
564 show_e1line_cmd,
565 "show e1_line [line_nr]",
566 SHOW_STR "Display information about a E1 line\n")
567{
Harald Welte1bc77352009-03-10 19:47:51 +0000568 struct e1inp_line *line;
569
570 if (argc >= 1) {
571 int num = atoi(argv[0]);
572 llist_for_each_entry(line, &e1inp_line_list, list) {
573 if (line->num == num) {
574 e1line_dump_vty(vty, line);
575 return CMD_SUCCESS;
576 }
577 }
578 return CMD_WARNING;
579 }
580
581 llist_for_each_entry(line, &e1inp_line_list, list)
582 e1line_dump_vty(vty, line);
583
584 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000585}
586
587static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
588{
Harald Welte42581822009-08-08 16:12:58 +0200589 if (ts->type == E1INP_TS_TYPE_NONE)
590 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000591 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
592 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
593 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000594}
595
596DEFUN(show_e1ts,
597 show_e1ts_cmd,
598 "show e1_timeslot [line_nr] [ts_nr]",
599 SHOW_STR "Display information about a E1 timeslot\n")
600{
Harald Welte1bc77352009-03-10 19:47:51 +0000601 struct e1inp_line *line;
602 struct e1inp_ts *ts;
603 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000604
Harald Welte1bc77352009-03-10 19:47:51 +0000605 if (argc == 0) {
606 llist_for_each_entry(line, &e1inp_line_list, list) {
607 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
608 ts = &line->ts[ts_nr];
609 e1ts_dump_vty(vty, ts);
610 }
611 }
612 return CMD_SUCCESS;
613 }
614 if (argc >= 1) {
615 int num = atoi(argv[0]);
616 llist_for_each_entry(line, &e1inp_line_list, list) {
617 if (line->num == num)
618 break;
619 }
620 if (!line || line->num != num) {
621 vty_out(vty, "E1 line %s is invalid%s",
622 argv[0], VTY_NEWLINE);
623 return CMD_WARNING;
624 }
625 }
626 if (argc >= 2) {
627 ts_nr = atoi(argv[1]);
628 if (ts_nr > NUM_E1_TS) {
629 vty_out(vty, "E1 timeslot %s is invalid%s",
630 argv[1], VTY_NEWLINE);
631 return CMD_WARNING;
632 }
633 ts = &line->ts[ts_nr];
634 e1ts_dump_vty(vty, ts);
635 return CMD_SUCCESS;
636 } else {
637 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
638 ts = &line->ts[ts_nr];
639 e1ts_dump_vty(vty, ts);
640 }
641 return CMD_SUCCESS;
642 }
643 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000644}
645
Harald Weltebe4b7302009-05-23 16:59:33 +0000646static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000647{
648 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
649 subscr_dump_vty(vty, pag->subscr);
650}
651
Harald Weltebe4b7302009-05-23 16:59:33 +0000652static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000653{
654 struct gsm_paging_request *pag;
655
656 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
657 paging_dump_vty(vty, pag);
658}
659
660DEFUN(show_paging,
661 show_paging_cmd,
662 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000663 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000664{
665 struct gsm_network *net = gsmnet;
666 struct gsm_bts *bts;
667 int bts_nr;
668
669 if (argc >= 1) {
670 /* use the BTS number that the user has specified */
671 bts_nr = atoi(argv[0]);
672 if (bts_nr >= net->num_bts) {
673 vty_out(vty, "%% can't find BTS %s%s", argv[0],
674 VTY_NEWLINE);
675 return CMD_WARNING;
676 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200677 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000678 bts_paging_dump_vty(vty, bts);
679
680 return CMD_SUCCESS;
681 }
682 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200683 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000684 bts_paging_dump_vty(vty, bts);
685 }
686
687 return CMD_SUCCESS;
688}
689
Harald Welte40f82892009-05-23 17:31:39 +0000690/* per-subscriber configuration */
691DEFUN(cfg_subscr,
692 cfg_subscr_cmd,
693 "subscriber IMSI",
694 "Select a Subscriber to configure\n")
695{
696 const char *imsi = argv[0];
697 struct gsm_subscriber *subscr;
698
Harald Welte761e9442009-07-23 19:21:02 +0200699 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000700 if (!subscr) {
701 vty_out(vty, "%% No subscriber for IMSI %s%s",
702 imsi, VTY_NEWLINE);
703 return CMD_WARNING;
704 }
705
706 vty->index = subscr;
707 vty->node = SUBSCR_NODE;
708
709 return CMD_SUCCESS;
710}
711
Harald Welte5013b2a2009-08-07 13:29:14 +0200712DEFUN(cfg_net,
713 cfg_net_cmd,
714 "network",
715 "Configure the GSM network")
716{
717 vty->index = gsmnet;
718 vty->node = GSMNET_NODE;
719
720 return CMD_SUCCESS;
721}
722
723
724DEFUN(cfg_net_ncc,
725 cfg_net_ncc_cmd,
726 "network country code <1-999>",
727 "Set the GSM network country code")
728{
729 gsmnet->country_code = atoi(argv[0]);
730
731 return CMD_SUCCESS;
732}
733
734DEFUN(cfg_net_mnc,
735 cfg_net_mnc_cmd,
736 "mobile network code <1-999>",
737 "Set the GSM mobile network code")
738{
739 gsmnet->network_code = atoi(argv[0]);
740
741 return CMD_SUCCESS;
742}
743
744DEFUN(cfg_net_name_short,
745 cfg_net_name_short_cmd,
746 "short name NAME",
747 "Set the short GSM network name")
748{
749 if (gsmnet->name_short)
750 talloc_free(gsmnet->name_short);
751
752 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
753
754 return CMD_SUCCESS;
755}
756
757DEFUN(cfg_net_name_long,
758 cfg_net_name_long_cmd,
759 "long name NAME",
760 "Set the long GSM network name")
761{
762 if (gsmnet->name_long)
763 talloc_free(gsmnet->name_long);
764
765 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
766
767 return CMD_SUCCESS;
768}
Harald Welte40f82892009-05-23 17:31:39 +0000769
Harald Welte5258fc42009-03-28 19:07:53 +0000770/* per-BTS configuration */
771DEFUN(cfg_bts,
772 cfg_bts_cmd,
773 "bts BTS_NR",
774 "Select a BTS to configure\n")
775{
776 int bts_nr = atoi(argv[0]);
777 struct gsm_bts *bts;
778
Harald Weltee441d9c2009-06-21 16:17:15 +0200779 if (bts_nr > gsmnet->num_bts) {
780 vty_out(vty, "%% The next unused BTS number is %u%s",
781 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000782 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200783 } else if (bts_nr == gsmnet->num_bts) {
784 /* allocate a new one */
785 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
786 HARDCODED_TSC, HARDCODED_BSIC);
787 } else
788 bts = gsm_bts_num(gsmnet, bts_nr);
789
790 if (!bts)
791 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000792
793 vty->index = bts;
794 vty->node = BTS_NODE;
795
796 return CMD_SUCCESS;
797}
798
799DEFUN(cfg_bts_type,
800 cfg_bts_type_cmd,
801 "type TYPE",
802 "Set the BTS type\n")
803{
804 struct gsm_bts *bts = vty->index;
805
Harald Weltea6fd58e2009-08-07 00:25:23 +0200806 bts->type = parse_btstype(argv[0]);
807
Harald Welte5258fc42009-03-28 19:07:53 +0000808 return CMD_SUCCESS;
809}
810
Harald Weltefcd24452009-06-20 18:15:19 +0200811DEFUN(cfg_bts_band,
812 cfg_bts_band_cmd,
813 "band BAND",
814 "Set the frequency band of this BTS\n")
815{
816 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200817 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200818
819 if (band < 0) {
820 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
821 band, VTY_NEWLINE);
822 return CMD_WARNING;
823 }
824
825 bts->band = band;
826
827 return CMD_SUCCESS;
828}
829
Harald Welte5258fc42009-03-28 19:07:53 +0000830DEFUN(cfg_bts_lac,
831 cfg_bts_lac_cmd,
832 "location_area_code <0-255>",
833 "Set the Location Area Code (LAC) of this BTS\n")
834{
835 struct gsm_bts *bts = vty->index;
836 int lac = atoi(argv[0]);
837
838 if (lac < 0 || lac > 0xff) {
839 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
840 lac, VTY_NEWLINE);
841 return CMD_WARNING;
842 }
843 bts->location_area_code = lac;
844
845 return CMD_SUCCESS;
846}
847
848DEFUN(cfg_bts_tsc,
849 cfg_bts_tsc_cmd,
850 "training_sequence_code <0-255>",
851 "Set the Training Sequence Code (TSC) of this BTS\n")
852{
853 struct gsm_bts *bts = vty->index;
854 int tsc = atoi(argv[0]);
855
856 if (tsc < 0 || tsc > 0xff) {
857 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
858 tsc, VTY_NEWLINE);
859 return CMD_WARNING;
860 }
861 bts->tsc = tsc;
862
863 return CMD_SUCCESS;
864}
865
Harald Welte78f2f502009-05-23 16:56:52 +0000866DEFUN(cfg_bts_bsic,
867 cfg_bts_bsic_cmd,
868 "base_station_id_code <0-63>",
869 "Set the Base Station Identity Code (BSIC) of this BTS\n")
870{
871 struct gsm_bts *bts = vty->index;
872 int bsic = atoi(argv[0]);
873
874 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200875 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000876 bsic, VTY_NEWLINE);
877 return CMD_WARNING;
878 }
879 bts->bsic = bsic;
880
881 return CMD_SUCCESS;
882}
883
884
Harald Welte4cc34222009-05-01 15:12:31 +0000885DEFUN(cfg_bts_unit_id,
886 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200887 "ip.access unit_id <0-65534> <0-255>",
888 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000889{
890 struct gsm_bts *bts = vty->index;
891 int site_id = atoi(argv[0]);
892 int bts_id = atoi(argv[1]);
893
894 if (site_id < 0 || site_id > 65534) {
895 vty_out(vty, "%% Site ID %d is not in the valid range%s",
896 site_id, VTY_NEWLINE);
897 return CMD_WARNING;
898 }
899 if (site_id < 0 || site_id > 255) {
900 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
901 bts_id, VTY_NEWLINE);
902 return CMD_WARNING;
903 }
Harald Welte07dc73d2009-08-07 13:27:09 +0200904
905 if (!is_ipaccess_bts(bts)) {
906 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
907 return CMD_WARNING;
908 }
909
Harald Welte4cc34222009-05-01 15:12:31 +0000910 bts->ip_access.site_id = site_id;
911 bts->ip_access.bts_id = bts_id;
912
913 return CMD_SUCCESS;
914}
915
Harald Welte42581822009-08-08 16:12:58 +0200916DEFUN(cfg_bts_oml_e1,
917 cfg_bts_oml_e1_cmd,
918 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
919 "E1 interface to be used for OML\n")
920{
921 struct gsm_bts *bts = vty->index;
922
923 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
924
925 return CMD_SUCCESS;
926}
927
928
929DEFUN(cfg_bts_oml_e1_tei,
930 cfg_bts_oml_e1_tei_cmd,
931 "oml e1 tei <0-63>",
932 "Set the TEI to be used for OML")
933{
934 struct gsm_bts *bts = vty->index;
935
936 bts->oml_tei = atoi(argv[0]);
937
938 return CMD_SUCCESS;
939}
940
Harald Welte5258fc42009-03-28 19:07:53 +0000941/* per TRX configuration */
942DEFUN(cfg_trx,
943 cfg_trx_cmd,
944 "trx TRX_NR",
945 "Select a TRX to configure")
946{
947 int trx_nr = atoi(argv[0]);
948 struct gsm_bts *bts = vty->index;
949 struct gsm_bts_trx *trx;
950
Harald Weltee441d9c2009-06-21 16:17:15 +0200951 if (trx_nr > bts->num_trx) {
952 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
953 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000954 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200955 } else if (trx_nr == bts->num_trx) {
956 /* we need to allocate a new one */
957 trx = gsm_bts_trx_alloc(bts);
958 } else
959 trx = gsm_bts_trx_num(bts, trx_nr);
960
961 if (!trx)
962 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000963
964 vty->index = trx;
965 vty->node = TRX_NODE;
966
967 return CMD_SUCCESS;
968}
969
970DEFUN(cfg_trx_arfcn,
971 cfg_trx_arfcn_cmd,
972 "arfcn <1-1024>",
973 "Set the ARFCN for this TRX\n")
974{
975 int arfcn = atoi(argv[0]);
976 struct gsm_bts_trx *trx = vty->index;
977
978 /* FIXME: check if this ARFCN is supported by this TRX */
979
980 trx->arfcn = arfcn;
981
982 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
983 /* FIXME: use OML layer to update the ARFCN */
984 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
985
986 return CMD_SUCCESS;
987}
988
Harald Weltefcd24452009-06-20 18:15:19 +0200989DEFUN(cfg_trx_max_power_red,
990 cfg_trx_max_power_red_cmd,
991 "max_power_red <0-100>",
992 "Reduction of maximum BS RF Power in dB\n")
993{
994 int maxpwr_r = atoi(argv[0]);
995 struct gsm_bts_trx *trx = vty->index;
996 int upper_limit = 12; /* default 12.21 max power red. */
997
998 /* FIXME: check if our BTS type supports more than 12 */
999 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1000 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1001 maxpwr_r, VTY_NEWLINE);
1002 return CMD_WARNING;
1003 }
1004 if (maxpwr_r & 1) {
1005 vty_out(vty, "%% Power %d dB is not an even value%s",
1006 maxpwr_r, VTY_NEWLINE);
1007 return CMD_WARNING;
1008 }
1009
1010 trx->max_power_red = maxpwr_r;
1011
1012 /* FIXME: make sure we update this using OML */
1013
1014 return CMD_SUCCESS;
1015}
1016
Harald Welte42581822009-08-08 16:12:58 +02001017DEFUN(cfg_trx_rsl_e1,
1018 cfg_trx_rsl_e1_cmd,
1019 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1020 "E1 interface to be used for RSL\n")
1021{
1022 struct gsm_bts_trx *trx = vty->index;
1023
1024 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1025
1026 return CMD_SUCCESS;
1027}
1028
1029DEFUN(cfg_trx_rsl_e1_tei,
1030 cfg_trx_rsl_e1_tei_cmd,
1031 "rsl e1 tei <0-63>",
1032 "Set the TEI to be used for RSL")
1033{
1034 struct gsm_bts_trx *trx = vty->index;
1035
1036 trx->rsl_tei = atoi(argv[0]);
1037
1038 return CMD_SUCCESS;
1039}
1040
1041
Harald Welte5258fc42009-03-28 19:07:53 +00001042/* per TS configuration */
1043DEFUN(cfg_ts,
1044 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001045 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001046 "Select a Timeslot to configure")
1047{
1048 int ts_nr = atoi(argv[0]);
1049 struct gsm_bts_trx *trx = vty->index;
1050 struct gsm_bts_trx_ts *ts;
1051
1052 if (ts_nr >= TRX_NR_TS) {
1053 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1054 TRX_NR_TS, VTY_NEWLINE);
1055 return CMD_WARNING;
1056 }
1057
1058 ts = &trx->ts[ts_nr];
1059
1060 vty->index = ts;
1061 vty->node = TS_NODE;
1062
1063 return CMD_SUCCESS;
1064}
1065
Harald Weltea6fd58e2009-08-07 00:25:23 +02001066DEFUN(cfg_ts_pchan,
1067 cfg_ts_pchan_cmd,
1068 "phys_chan_config PCHAN",
1069 "Physical Channel configuration (TCH/SDCCH/...)")
1070{
1071 struct gsm_bts_trx_ts *ts = vty->index;
1072 int pchanc;
1073
1074 pchanc = gsm_pchan_parse(argv[0]);
1075 if (pchanc < 0)
1076 return CMD_WARNING;
1077
1078 ts->pchan = pchanc;
1079
1080 return CMD_SUCCESS;
1081}
1082
1083DEFUN(cfg_ts_e1_subslot,
1084 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001085 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001086 "E1 sub-slot connected to this on-air timeslot")
1087{
1088 struct gsm_bts_trx_ts *ts = vty->index;
1089
Harald Welte42581822009-08-08 16:12:58 +02001090 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001091
1092 return CMD_SUCCESS;
1093}
Harald Welte5258fc42009-03-28 19:07:53 +00001094
Harald Welte40f82892009-05-23 17:31:39 +00001095/* Subscriber */
1096DEFUN(show_subscr,
1097 show_subscr_cmd,
1098 "show subscriber [IMSI]",
1099 SHOW_STR "Display information about a subscriber\n")
1100{
1101 const char *imsi;
1102 struct gsm_subscriber *subscr;
1103
1104 if (argc >= 1) {
1105 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +02001106 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +00001107 if (!subscr) {
1108 vty_out(vty, "%% unknown subscriber%s",
1109 VTY_NEWLINE);
1110 return CMD_WARNING;
1111 }
1112 subscr_dump_vty(vty, subscr);
1113
1114 return CMD_SUCCESS;
1115 }
1116
1117 /* FIXME: iterate over all subscribers ? */
1118 return CMD_WARNING;
1119
1120 return CMD_SUCCESS;
1121}
1122
Harald Welte76042182009-08-08 16:03:15 +02001123DEFUN(sms_send_pend,
1124 sms_send_pend_cmd,
1125 "sms send pending MIN_ID",
1126 "Send all pending SMS starting from MIN_ID")
1127{
1128 struct gsm_sms *sms;
1129
1130 sms = db_sms_get_unsent(gsmnet, atoi(argv[0]));
1131 if (!sms)
1132 return CMD_WARNING;
1133
1134 if (!sms->receiver) {
1135 sms_free(sms);
1136 return CMD_WARNING;
1137 }
1138
1139 gsm411_send_sms_subscr(sms->receiver, sms);
1140
1141 return CMD_SUCCESS;
1142}
1143
Harald Weltef9daefd2009-08-09 15:13:54 +02001144static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1145{
1146 struct buffer *b = buffer_new(1024);
1147 int i;
1148
1149 if (!b)
1150 return NULL;
1151
1152 for (i = base; i < argc; i++) {
1153 buffer_putstr(b, argv[i]);
1154 buffer_putc(b, ' ');
1155 }
1156 buffer_putc(b, '\0');
1157
1158 return b;
1159}
1160
1161static int _send_sms_buffer(struct gsm_subscriber *receiver,
1162 struct buffer *b)
1163{
1164 struct gsm_sms *sms = sms_alloc();
1165
1166 if (!sms)
1167 return CMD_WARNING;
1168
1169 if (!receiver->lac) {
1170 /* subscriber currently not attached, store in database? */
1171 subscr_put(sms->receiver);
1172 return CMD_WARNING;
1173 }
1174
1175 sms->receiver = receiver;
1176 strncpy(sms->text, buffer_getstr(b), sizeof(sms->text)-1);
1177
1178 /* FIXME: don't use ID 1 static */
1179 sms->sender = subscr_get_by_id(gsmnet, 1);
1180 sms->reply_path_req = 0;
1181 sms->status_rep_req = 0;
1182 sms->ud_hdr_ind = 0;
1183 sms->protocol_id = 0; /* implicit */
1184 sms->data_coding_scheme = 0; /* default 7bit */
1185 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1186 /* Generate user_data */
1187 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1188
1189 gsm411_send_sms_subscr(sms->receiver, sms);
1190
1191 return CMD_SUCCESS;
1192}
1193
Harald Welte76042182009-08-08 16:03:15 +02001194DEFUN(sms_send_ext,
1195 sms_send_ext_cmd,
1196 "sms send extension EXTEN .LINE",
1197 "Send a message to a subscriber identified by EXTEN")
1198{
Harald Weltef9daefd2009-08-09 15:13:54 +02001199 struct gsm_subscriber *receiver;
1200 struct buffer *b;
1201 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001202
Harald Weltef9daefd2009-08-09 15:13:54 +02001203 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1204 if (!receiver)
1205 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001206
Harald Weltef9daefd2009-08-09 15:13:54 +02001207 b = argv_to_buffer(argc, argv, 1);
1208 rc = _send_sms_buffer(receiver, b);
1209 buffer_free(b);
1210
1211 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001212}
1213
1214DEFUN(sms_send_imsi,
1215 sms_send_imsi_cmd,
1216 "sms send imsi IMSI .LINE",
1217 "Send a message to a subscriber identified by IMSI")
1218{
Harald Weltef9daefd2009-08-09 15:13:54 +02001219 struct gsm_subscriber *receiver;
1220 struct buffer *b;
1221 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001222
Harald Weltef9daefd2009-08-09 15:13:54 +02001223 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1224 if (!receiver)
1225 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001226
Harald Weltef9daefd2009-08-09 15:13:54 +02001227 b = argv_to_buffer(argc, argv, 1);
1228 rc = _send_sms_buffer(receiver, b);
1229 buffer_free(b);
1230
1231 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001232}
1233
1234
Harald Welte40f82892009-05-23 17:31:39 +00001235DEFUN(cfg_subscr_name,
1236 cfg_subscr_name_cmd,
1237 "name NAME",
1238 "Set the name of the subscriber")
1239{
1240 const char *name = argv[0];
1241 struct gsm_subscriber *subscr = vty->index;
1242
1243 strncpy(subscr->name, name, sizeof(subscr->name));
1244
1245 db_sync_subscriber(subscr);
1246
1247 return CMD_SUCCESS;
1248}
1249
1250DEFUN(cfg_subscr_extension,
1251 cfg_subscr_extension_cmd,
1252 "extension EXTENSION",
1253 "Set the extension of the subscriber")
1254{
1255 const char *name = argv[0];
1256 struct gsm_subscriber *subscr = vty->index;
1257
1258 strncpy(subscr->extension, name, sizeof(subscr->extension));
1259
1260 db_sync_subscriber(subscr);
1261
1262 return CMD_SUCCESS;
1263}
1264
1265DEFUN(cfg_subscr_authorized,
1266 cfg_subscr_authorized_cmd,
1267 "auth <0-1>",
1268 "Set the authorization status of the subscriber")
1269{
1270 int auth = atoi(argv[0]);
1271 struct gsm_subscriber *subscr = vty->index;
1272
1273 if (auth)
1274 subscr->authorized = 1;
1275 else
1276 subscr->authorized = 0;
1277
1278 db_sync_subscriber(subscr);
1279
1280 return CMD_SUCCESS;
1281}
1282
Harald Welte68628e82009-03-10 12:17:57 +00001283int bsc_vty_init(struct gsm_network *net)
1284{
1285 gsmnet = net;
1286
1287 cmd_init(1);
1288 vty_init();
1289
1290 install_element(VIEW_NODE, &show_net_cmd);
1291 install_element(VIEW_NODE, &show_bts_cmd);
1292 install_element(VIEW_NODE, &show_trx_cmd);
1293 install_element(VIEW_NODE, &show_ts_cmd);
1294 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001295
1296 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001297 install_element(VIEW_NODE, &show_e1line_cmd);
1298 install_element(VIEW_NODE, &show_e1ts_cmd);
1299
Harald Weltef5025b62009-03-28 16:55:11 +00001300 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001301
Harald Welte40f82892009-05-23 17:31:39 +00001302 install_element(VIEW_NODE, &show_subscr_cmd);
1303
Harald Welte76042182009-08-08 16:03:15 +02001304 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001305 install_element(VIEW_NODE, &sms_send_ext_cmd);
1306 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001307
Harald Welte5013b2a2009-08-07 13:29:14 +02001308 install_element(CONFIG_NODE, &cfg_net_cmd);
1309 install_node(&net_node, config_write_net);
1310 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001311 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001312 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1313 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1314 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
1315
1316 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001317 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001318 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001319 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001320 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001321 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1322 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001323 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001324 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001325 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1326 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001327
Harald Welte5258fc42009-03-28 19:07:53 +00001328 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001329 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001330 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001331 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001332 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001333 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1334 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001335
Harald Welte5258fc42009-03-28 19:07:53 +00001336 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001337 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001338 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001339 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1340 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001341
Harald Welte40f82892009-05-23 17:31:39 +00001342 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1343 install_node(&subscr_node, dummy_config_write);
1344 install_default(SUBSCR_NODE);
1345 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1346 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1347 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1348
Harald Welte68628e82009-03-10 12:17:57 +00001349 return 0;
1350}