blob: 462cc64ea225dbcf65ba4fd215be7d12429e0554 [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>
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +020034#include <openbsc/gsm_04_11.h>
Harald Welte68628e82009-03-10 12:17:57 +000035#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000036#include <openbsc/abis_nm.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020037#include <openbsc/gsm_utils.h>
Harald Welte40f82892009-05-23 17:31:39 +000038#include <openbsc/db.h>
Harald Welte5013b2a2009-08-07 13:29:14 +020039#include <openbsc/talloc.h>
Harald Welte68628e82009-03-10 12:17:57 +000040
41static struct gsm_network *gsmnet;
42
Harald Welte5013b2a2009-08-07 13:29:14 +020043struct cmd_node net_node = {
44 GSMNET_NODE,
45 "%s(network)#",
46 1,
47};
48
Harald Welte68628e82009-03-10 12:17:57 +000049struct cmd_node bts_node = {
50 BTS_NODE,
51 "%s(bts)#",
52 1,
53};
54
55struct cmd_node trx_node = {
56 TRX_NODE,
57 "%s(trx)#",
58 1,
59};
60
61struct cmd_node ts_node = {
62 TS_NODE,
63 "%s(ts)#",
64 1,
65};
66
Harald Welte40f82892009-05-23 17:31:39 +000067struct cmd_node subscr_node = {
68 SUBSCR_NODE,
69 "%s(subscriber)#",
70 1,
71};
72
Harald Welte68628e82009-03-10 12:17:57 +000073static int dummy_config_write(struct vty *v)
74{
75 return CMD_SUCCESS;
76}
77
78static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
79{
Harald Welte1bc77352009-03-10 19:47:51 +000080 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
81 nm_opstate_name(nms->operational), nms->administrative,
82 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000083}
84
85static void net_dump_vty(struct vty *vty, struct gsm_network *net)
86{
Harald Welteef235b52009-03-10 12:34:02 +000087 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
88 "and has %u BTS%s", net->country_code, net->network_code,
89 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000090 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000091 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000092 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000093 net->name_short, VTY_NEWLINE);
94}
95
96DEFUN(show_net, show_net_cmd, "show network",
97 SHOW_STR "Display information about a GSM NETWORK\n")
98{
99 struct gsm_network *net = gsmnet;
100 net_dump_vty(vty, net);
101
102 return CMD_SUCCESS;
103}
104
105static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
106{
Harald Welteedb37782009-05-01 14:59:07 +0000107 struct e1inp_line *line;
108
109 if (!e1l) {
110 vty_out(vty, " None%s", VTY_NEWLINE);
111 return;
112 }
113
114 line = e1l->ts->line;
115
116 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
117 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000118 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000119 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000120 e1l->tei, e1l->sapi, VTY_NEWLINE);
121}
122
123static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
124{
Harald Weltefcd24452009-06-20 18:15:19 +0200125 vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, "
126 "BSIC %u, TSC %u and %u TRX%s",
127 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
128 bts->location_area_code, bts->bsic, bts->tsc,
129 bts->num_trx, VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000130 if (is_ipaccess_bts(bts))
131 vty_out(vty, " Unit ID: %u/%u/0%s",
132 bts->ip_access.site_id, bts->ip_access.bts_id,
133 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000134 vty_out(vty, " NM State: ");
135 net_dump_nmstate(vty, &bts->nm_state);
136 vty_out(vty, " Site Mgr NM State: ");
137 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
138 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
139 bts->paging.available_slots, VTY_NEWLINE);
140 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
141 e1isl_dump_vty(vty, bts->oml_link);
142 /* FIXME: oml_link, chan_desc */
143}
144
145DEFUN(show_bts, show_bts_cmd, "show bts [number]",
146 SHOW_STR "Display information about a BTS\n"
147 "BTS number")
148{
149 struct gsm_network *net = gsmnet;
150 int bts_nr;
151
152 if (argc != 0) {
153 /* use the BTS number that the user has specified */
154 bts_nr = atoi(argv[0]);
155 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000156 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000157 VTY_NEWLINE);
158 return CMD_WARNING;
159 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200160 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000161 return CMD_SUCCESS;
162 }
163 /* print all BTS's */
164 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200165 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000166
167 return CMD_SUCCESS;
168}
169
Harald Welte42581822009-08-08 16:12:58 +0200170/* utility functions */
171static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
172 const char *ts, const char *ss)
173{
174 e1_link->e1_nr = atoi(line);
175 e1_link->e1_ts = atoi(ts);
176 if (!strcmp(ss, "full"))
177 e1_link->e1_ts_ss = 255;
178 else
179 e1_link->e1_ts_ss = atoi(ss);
180}
181
182static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
183 const char *prefix)
184{
185 if (!e1_link->e1_ts)
186 return;
187
188 if (e1_link->e1_ts_ss == 255)
189 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
190 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
191 else
192 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
193 prefix, e1_link->e1_nr, e1_link->e1_ts,
194 e1_link->e1_ts_ss, VTY_NEWLINE);
195}
196
197
Harald Welte67ce0732009-08-06 19:06:46 +0200198static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
199{
Harald Welte42581822009-08-08 16:12:58 +0200200 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
201 if (ts->pchan != GSM_PCHAN_NONE)
202 vty_out(vty, " phys_chan_config %s%s",
203 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
204 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte67ce0732009-08-06 19:06:46 +0200205}
206
207static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
208{
209 int i;
210
Harald Welte5013b2a2009-08-07 13:29:14 +0200211 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
212 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
213 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200214 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
215 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200216
217 for (i = 0; i < TRX_NR_TS; i++)
218 config_write_ts_single(vty, &trx->ts[i]);
219}
220
221static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
222{
223 struct gsm_bts_trx *trx;
224
Harald Welte5013b2a2009-08-07 13:29:14 +0200225 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
226 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
227 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
228 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200229 VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200230 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
231 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte7a8fa412009-08-10 13:48:16 +0200232 vty_out(vty, " channel allocator %s%s",
233 bts->chan_alloc_reverse ? "descending" : "ascending",
234 VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200235 if (is_ipaccess_bts(bts))
Harald Welte5013b2a2009-08-07 13:29:14 +0200236 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200237 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200238 else {
239 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
240 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
241 }
Harald Welte67ce0732009-08-06 19:06:46 +0200242
243 llist_for_each_entry(trx, &bts->trx_list, list)
244 config_write_trx_single(vty, trx);
245}
246
247static int config_write_bts(struct vty *v)
248{
249 struct gsm_bts *bts;
250
251 llist_for_each_entry(bts, &gsmnet->bts_list, list)
252 config_write_bts_single(v, bts);
253
254 return CMD_SUCCESS;
255}
256
Harald Welte5013b2a2009-08-07 13:29:14 +0200257static int config_write_net(struct vty *vty)
258{
259 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200260 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200261 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200262 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
263 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200264
265 return CMD_SUCCESS;
266}
Harald Welte67ce0732009-08-06 19:06:46 +0200267
Harald Welte68628e82009-03-10 12:17:57 +0000268static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
269{
270 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
271 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200272 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200273 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200274 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200275 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000276 vty_out(vty, " NM State: ");
277 net_dump_nmstate(vty, &trx->nm_state);
278 vty_out(vty, " Baseband Transceiver NM State: ");
279 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
280 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
281 e1isl_dump_vty(vty, trx->rsl_link);
282}
283
284DEFUN(show_trx,
285 show_trx_cmd,
286 "show trx [bts_nr] [trx_nr]",
287 SHOW_STR "Display information about a TRX\n")
288{
289 struct gsm_network *net = gsmnet;
290 struct gsm_bts *bts = NULL;
291 struct gsm_bts_trx *trx;
292 int bts_nr, trx_nr;
293
294 if (argc >= 1) {
295 /* use the BTS number that the user has specified */
296 bts_nr = atoi(argv[0]);
297 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000298 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000299 VTY_NEWLINE);
300 return CMD_WARNING;
301 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200302 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000303 }
304 if (argc >= 2) {
305 trx_nr = atoi(argv[1]);
306 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000307 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000308 VTY_NEWLINE);
309 return CMD_WARNING;
310 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200311 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000312 trx_dump_vty(vty, trx);
313 return CMD_SUCCESS;
314 }
315 if (bts) {
316 /* print all TRX in this BTS */
317 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200318 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000319 trx_dump_vty(vty, trx);
320 }
321 return CMD_SUCCESS;
322 }
323
324 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200325 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000326 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200327 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000328 trx_dump_vty(vty, trx);
329 }
330 }
331
332 return CMD_SUCCESS;
333}
334
Harald Welte67ce0732009-08-06 19:06:46 +0200335
Harald Welte68628e82009-03-10 12:17:57 +0000336static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
337{
338 struct in_addr ia;
339
340 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
341 ts->nr, ts->trx->nr, ts->trx->bts->nr,
342 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
343 vty_out(vty, " NM State: ");
344 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000345 if (is_ipaccess_bts(ts->trx->bts)) {
346 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200347 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000348 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200349 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000350 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000351 } else {
352 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
353 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
354 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000355 }
356}
357
358DEFUN(show_ts,
359 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000360 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000361 SHOW_STR "Display information about a TS\n")
362{
363 struct gsm_network *net = gsmnet;
364 struct gsm_bts *bts;
365 struct gsm_bts_trx *trx;
366 struct gsm_bts_trx_ts *ts;
367 int bts_nr, trx_nr, ts_nr;
368
369 if (argc >= 1) {
370 /* use the BTS number that the user has specified */
371 bts_nr = atoi(argv[0]);
372 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000373 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000374 VTY_NEWLINE);
375 return CMD_WARNING;
376 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200377 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000378 }
379 if (argc >= 2) {
380 trx_nr = atoi(argv[1]);
381 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000382 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000383 VTY_NEWLINE);
384 return CMD_WARNING;
385 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200386 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000387 }
388 if (argc >= 3) {
389 ts_nr = atoi(argv[2]);
390 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000391 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000392 VTY_NEWLINE);
393 return CMD_WARNING;
394 }
395 ts = &trx->ts[ts_nr];
396 ts_dump_vty(vty, ts);
397 return CMD_SUCCESS;
398 }
399 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200400 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000401 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200402 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000403 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
404 ts = &trx->ts[ts_nr];
405 ts_dump_vty(vty, ts);
406 }
407 }
408 }
409
410 return CMD_SUCCESS;
411}
412
413static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
414{
Harald Weltefcd24452009-06-20 18:15:19 +0200415 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000416 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000417 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000418 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000419 if (subscr->extension)
420 vty_out(vty, " Extension: %s%s", subscr->extension,
421 VTY_NEWLINE);
422 if (subscr->imsi)
423 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
424 if (subscr->tmsi)
425 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
426}
427
428static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
429{
430 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
431 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
432 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
433 VTY_NEWLINE);
434 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
435 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
436 lchan->ms_power, VTY_NEWLINE);
437 if (lchan->subscr) {
438 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
439 subscr_dump_vty(vty, lchan->subscr);
440 } else
441 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
442}
443
Harald Welte4bfdfe72009-06-10 23:11:52 +0800444#if 0
445TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000446static void call_dump_vty(struct vty *vty, struct gsm_call *call)
447{
448 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
449 call->type, call->state, call->transaction_id, VTY_NEWLINE);
450
451 if (call->local_lchan) {
452 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
453 lchan_dump_vty(vty, call->local_lchan);
454 } else
455 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
456
457 if (call->remote_lchan) {
458 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
459 lchan_dump_vty(vty, call->remote_lchan);
460 } else
461 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
462
463 if (call->called_subscr) {
464 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
465 subscr_dump_vty(vty, call->called_subscr);
466 } else
467 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
468}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800469#endif
Harald Welte68628e82009-03-10 12:17:57 +0000470
471DEFUN(show_lchan,
472 show_lchan_cmd,
473 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
474 SHOW_STR "Display information about a logical channel\n")
475{
476 struct gsm_network *net = gsmnet;
477 struct gsm_bts *bts;
478 struct gsm_bts_trx *trx;
479 struct gsm_bts_trx_ts *ts;
480 struct gsm_lchan *lchan;
481 int bts_nr, trx_nr, ts_nr, lchan_nr;
482
483 if (argc >= 1) {
484 /* use the BTS number that the user has specified */
485 bts_nr = atoi(argv[0]);
486 if (bts_nr >= net->num_bts) {
487 vty_out(vty, "%% can't find BTS %s%s", argv[0],
488 VTY_NEWLINE);
489 return CMD_WARNING;
490 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200491 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000492 }
493 if (argc >= 2) {
494 trx_nr = atoi(argv[1]);
495 if (trx_nr >= bts->num_trx) {
496 vty_out(vty, "%% can't find TRX %s%s", argv[1],
497 VTY_NEWLINE);
498 return CMD_WARNING;
499 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200500 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000501 }
502 if (argc >= 3) {
503 ts_nr = atoi(argv[2]);
504 if (ts_nr >= TRX_NR_TS) {
505 vty_out(vty, "%% can't find TS %s%s", argv[2],
506 VTY_NEWLINE);
507 return CMD_WARNING;
508 }
509 ts = &trx->ts[ts_nr];
510 }
511 if (argc >= 4) {
512 lchan_nr = atoi(argv[3]);
513 if (lchan_nr >= TS_MAX_LCHAN) {
514 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
515 VTY_NEWLINE);
516 return CMD_WARNING;
517 }
518 lchan = &ts->lchan[lchan_nr];
519 lchan_dump_vty(vty, lchan);
520 return CMD_SUCCESS;
521 }
522 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200523 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000524 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200525 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000526 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
527 ts = &trx->ts[ts_nr];
528 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
529 lchan_nr++) {
530 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000531 if (lchan->type == GSM_LCHAN_NONE)
532 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000533 lchan_dump_vty(vty, lchan);
534 }
535 }
536 }
537 }
538
539 return CMD_SUCCESS;
540}
541
Harald Welte1bc77352009-03-10 19:47:51 +0000542static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
543{
544 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
545}
546
547DEFUN(show_e1drv,
548 show_e1drv_cmd,
549 "show e1_driver",
550 SHOW_STR "Display information about available E1 drivers\n")
551{
552 struct e1inp_driver *drv;
553
554 llist_for_each_entry(drv, &e1inp_driver_list, list)
555 e1drv_dump_vty(vty, drv);
556
557 return CMD_SUCCESS;
558}
559
Harald Welte68628e82009-03-10 12:17:57 +0000560static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
561{
562 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
563 line->num, line->name ? line->name : "",
564 line->driver->name, VTY_NEWLINE);
565}
566
567DEFUN(show_e1line,
568 show_e1line_cmd,
569 "show e1_line [line_nr]",
570 SHOW_STR "Display information about a E1 line\n")
571{
Harald Welte1bc77352009-03-10 19:47:51 +0000572 struct e1inp_line *line;
573
574 if (argc >= 1) {
575 int num = atoi(argv[0]);
576 llist_for_each_entry(line, &e1inp_line_list, list) {
577 if (line->num == num) {
578 e1line_dump_vty(vty, line);
579 return CMD_SUCCESS;
580 }
581 }
582 return CMD_WARNING;
583 }
584
585 llist_for_each_entry(line, &e1inp_line_list, list)
586 e1line_dump_vty(vty, line);
587
588 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000589}
590
591static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
592{
Harald Welte42581822009-08-08 16:12:58 +0200593 if (ts->type == E1INP_TS_TYPE_NONE)
594 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000595 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
596 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
597 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000598}
599
600DEFUN(show_e1ts,
601 show_e1ts_cmd,
602 "show e1_timeslot [line_nr] [ts_nr]",
603 SHOW_STR "Display information about a E1 timeslot\n")
604{
Harald Welte1bc77352009-03-10 19:47:51 +0000605 struct e1inp_line *line;
606 struct e1inp_ts *ts;
607 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000608
Harald Welte1bc77352009-03-10 19:47:51 +0000609 if (argc == 0) {
610 llist_for_each_entry(line, &e1inp_line_list, list) {
611 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
612 ts = &line->ts[ts_nr];
613 e1ts_dump_vty(vty, ts);
614 }
615 }
616 return CMD_SUCCESS;
617 }
618 if (argc >= 1) {
619 int num = atoi(argv[0]);
620 llist_for_each_entry(line, &e1inp_line_list, list) {
621 if (line->num == num)
622 break;
623 }
624 if (!line || line->num != num) {
625 vty_out(vty, "E1 line %s is invalid%s",
626 argv[0], VTY_NEWLINE);
627 return CMD_WARNING;
628 }
629 }
630 if (argc >= 2) {
631 ts_nr = atoi(argv[1]);
632 if (ts_nr > NUM_E1_TS) {
633 vty_out(vty, "E1 timeslot %s is invalid%s",
634 argv[1], VTY_NEWLINE);
635 return CMD_WARNING;
636 }
637 ts = &line->ts[ts_nr];
638 e1ts_dump_vty(vty, ts);
639 return CMD_SUCCESS;
640 } else {
641 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
642 ts = &line->ts[ts_nr];
643 e1ts_dump_vty(vty, ts);
644 }
645 return CMD_SUCCESS;
646 }
647 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000648}
649
Harald Weltebe4b7302009-05-23 16:59:33 +0000650static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000651{
652 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
653 subscr_dump_vty(vty, pag->subscr);
654}
655
Harald Weltebe4b7302009-05-23 16:59:33 +0000656static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000657{
658 struct gsm_paging_request *pag;
659
660 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
661 paging_dump_vty(vty, pag);
662}
663
664DEFUN(show_paging,
665 show_paging_cmd,
666 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000667 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000668{
669 struct gsm_network *net = gsmnet;
670 struct gsm_bts *bts;
671 int bts_nr;
672
673 if (argc >= 1) {
674 /* use the BTS number that the user has specified */
675 bts_nr = atoi(argv[0]);
676 if (bts_nr >= net->num_bts) {
677 vty_out(vty, "%% can't find BTS %s%s", argv[0],
678 VTY_NEWLINE);
679 return CMD_WARNING;
680 }
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 return CMD_SUCCESS;
685 }
686 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200687 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000688 bts_paging_dump_vty(vty, bts);
689 }
690
691 return CMD_SUCCESS;
692}
693
Harald Welte40f82892009-05-23 17:31:39 +0000694/* per-subscriber configuration */
695DEFUN(cfg_subscr,
696 cfg_subscr_cmd,
697 "subscriber IMSI",
698 "Select a Subscriber to configure\n")
699{
700 const char *imsi = argv[0];
701 struct gsm_subscriber *subscr;
702
Harald Welte761e9442009-07-23 19:21:02 +0200703 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000704 if (!subscr) {
705 vty_out(vty, "%% No subscriber for IMSI %s%s",
706 imsi, VTY_NEWLINE);
707 return CMD_WARNING;
708 }
709
710 vty->index = subscr;
711 vty->node = SUBSCR_NODE;
712
713 return CMD_SUCCESS;
714}
715
Harald Welte5013b2a2009-08-07 13:29:14 +0200716DEFUN(cfg_net,
717 cfg_net_cmd,
718 "network",
719 "Configure the GSM network")
720{
721 vty->index = gsmnet;
722 vty->node = GSMNET_NODE;
723
724 return CMD_SUCCESS;
725}
726
727
728DEFUN(cfg_net_ncc,
729 cfg_net_ncc_cmd,
730 "network country code <1-999>",
731 "Set the GSM network country code")
732{
733 gsmnet->country_code = atoi(argv[0]);
734
735 return CMD_SUCCESS;
736}
737
738DEFUN(cfg_net_mnc,
739 cfg_net_mnc_cmd,
740 "mobile network code <1-999>",
741 "Set the GSM mobile network code")
742{
743 gsmnet->network_code = atoi(argv[0]);
744
745 return CMD_SUCCESS;
746}
747
748DEFUN(cfg_net_name_short,
749 cfg_net_name_short_cmd,
750 "short name NAME",
751 "Set the short GSM network name")
752{
753 if (gsmnet->name_short)
754 talloc_free(gsmnet->name_short);
755
756 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
757
758 return CMD_SUCCESS;
759}
760
761DEFUN(cfg_net_name_long,
762 cfg_net_name_long_cmd,
763 "long name NAME",
764 "Set the long GSM network name")
765{
766 if (gsmnet->name_long)
767 talloc_free(gsmnet->name_long);
768
769 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
770
771 return CMD_SUCCESS;
772}
Harald Welte40f82892009-05-23 17:31:39 +0000773
Harald Welte5258fc42009-03-28 19:07:53 +0000774/* per-BTS configuration */
775DEFUN(cfg_bts,
776 cfg_bts_cmd,
777 "bts BTS_NR",
778 "Select a BTS to configure\n")
779{
780 int bts_nr = atoi(argv[0]);
781 struct gsm_bts *bts;
782
Harald Weltee441d9c2009-06-21 16:17:15 +0200783 if (bts_nr > gsmnet->num_bts) {
784 vty_out(vty, "%% The next unused BTS number is %u%s",
785 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000786 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200787 } else if (bts_nr == gsmnet->num_bts) {
788 /* allocate a new one */
789 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
790 HARDCODED_TSC, HARDCODED_BSIC);
791 } else
792 bts = gsm_bts_num(gsmnet, bts_nr);
793
794 if (!bts)
795 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000796
797 vty->index = bts;
798 vty->node = BTS_NODE;
799
800 return CMD_SUCCESS;
801}
802
803DEFUN(cfg_bts_type,
804 cfg_bts_type_cmd,
805 "type TYPE",
806 "Set the BTS type\n")
807{
808 struct gsm_bts *bts = vty->index;
809
Harald Weltea6fd58e2009-08-07 00:25:23 +0200810 bts->type = parse_btstype(argv[0]);
811
Harald Welte5258fc42009-03-28 19:07:53 +0000812 return CMD_SUCCESS;
813}
814
Harald Weltefcd24452009-06-20 18:15:19 +0200815DEFUN(cfg_bts_band,
816 cfg_bts_band_cmd,
817 "band BAND",
818 "Set the frequency band of this BTS\n")
819{
820 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200821 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200822
823 if (band < 0) {
824 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
825 band, VTY_NEWLINE);
826 return CMD_WARNING;
827 }
828
829 bts->band = band;
830
831 return CMD_SUCCESS;
832}
833
Harald Welte5258fc42009-03-28 19:07:53 +0000834DEFUN(cfg_bts_lac,
835 cfg_bts_lac_cmd,
836 "location_area_code <0-255>",
837 "Set the Location Area Code (LAC) of this BTS\n")
838{
839 struct gsm_bts *bts = vty->index;
840 int lac = atoi(argv[0]);
841
842 if (lac < 0 || lac > 0xff) {
843 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
844 lac, VTY_NEWLINE);
845 return CMD_WARNING;
846 }
847 bts->location_area_code = lac;
848
849 return CMD_SUCCESS;
850}
851
852DEFUN(cfg_bts_tsc,
853 cfg_bts_tsc_cmd,
854 "training_sequence_code <0-255>",
855 "Set the Training Sequence Code (TSC) of this BTS\n")
856{
857 struct gsm_bts *bts = vty->index;
858 int tsc = atoi(argv[0]);
859
860 if (tsc < 0 || tsc > 0xff) {
861 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
862 tsc, VTY_NEWLINE);
863 return CMD_WARNING;
864 }
865 bts->tsc = tsc;
866
867 return CMD_SUCCESS;
868}
869
Harald Welte78f2f502009-05-23 16:56:52 +0000870DEFUN(cfg_bts_bsic,
871 cfg_bts_bsic_cmd,
872 "base_station_id_code <0-63>",
873 "Set the Base Station Identity Code (BSIC) of this BTS\n")
874{
875 struct gsm_bts *bts = vty->index;
876 int bsic = atoi(argv[0]);
877
878 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200879 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000880 bsic, VTY_NEWLINE);
881 return CMD_WARNING;
882 }
883 bts->bsic = bsic;
884
885 return CMD_SUCCESS;
886}
887
888
Harald Welte4cc34222009-05-01 15:12:31 +0000889DEFUN(cfg_bts_unit_id,
890 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200891 "ip.access unit_id <0-65534> <0-255>",
892 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000893{
894 struct gsm_bts *bts = vty->index;
895 int site_id = atoi(argv[0]);
896 int bts_id = atoi(argv[1]);
897
898 if (site_id < 0 || site_id > 65534) {
899 vty_out(vty, "%% Site ID %d is not in the valid range%s",
900 site_id, VTY_NEWLINE);
901 return CMD_WARNING;
902 }
903 if (site_id < 0 || site_id > 255) {
904 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
905 bts_id, VTY_NEWLINE);
906 return CMD_WARNING;
907 }
Harald Welte07dc73d2009-08-07 13:27:09 +0200908
909 if (!is_ipaccess_bts(bts)) {
910 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
911 return CMD_WARNING;
912 }
913
Harald Welte4cc34222009-05-01 15:12:31 +0000914 bts->ip_access.site_id = site_id;
915 bts->ip_access.bts_id = bts_id;
916
917 return CMD_SUCCESS;
918}
919
Harald Welte42581822009-08-08 16:12:58 +0200920DEFUN(cfg_bts_oml_e1,
921 cfg_bts_oml_e1_cmd,
922 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
923 "E1 interface to be used for OML\n")
924{
925 struct gsm_bts *bts = vty->index;
926
927 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
928
929 return CMD_SUCCESS;
930}
931
932
933DEFUN(cfg_bts_oml_e1_tei,
934 cfg_bts_oml_e1_tei_cmd,
935 "oml e1 tei <0-63>",
936 "Set the TEI to be used for OML")
937{
938 struct gsm_bts *bts = vty->index;
939
940 bts->oml_tei = atoi(argv[0]);
941
942 return CMD_SUCCESS;
943}
944
Harald Welte7a8fa412009-08-10 13:48:16 +0200945DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
946 "channel allocator (ascending|descending)",
947 "Should the channel allocator allocate in reverse TRX order?")
948{
949 struct gsm_bts *bts = vty->index;
950
951 if (!strcmp(argv[0], "ascending"))
952 bts->chan_alloc_reverse = 0;
953 else
954 bts->chan_alloc_reverse = 1;
955
956 return CMD_SUCCESS;
957}
958
959
Harald Welte5258fc42009-03-28 19:07:53 +0000960/* per TRX configuration */
961DEFUN(cfg_trx,
962 cfg_trx_cmd,
963 "trx TRX_NR",
964 "Select a TRX to configure")
965{
966 int trx_nr = atoi(argv[0]);
967 struct gsm_bts *bts = vty->index;
968 struct gsm_bts_trx *trx;
969
Harald Weltee441d9c2009-06-21 16:17:15 +0200970 if (trx_nr > bts->num_trx) {
971 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
972 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000973 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200974 } else if (trx_nr == bts->num_trx) {
975 /* we need to allocate a new one */
976 trx = gsm_bts_trx_alloc(bts);
977 } else
978 trx = gsm_bts_trx_num(bts, trx_nr);
979
980 if (!trx)
981 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000982
983 vty->index = trx;
984 vty->node = TRX_NODE;
985
986 return CMD_SUCCESS;
987}
988
989DEFUN(cfg_trx_arfcn,
990 cfg_trx_arfcn_cmd,
991 "arfcn <1-1024>",
992 "Set the ARFCN for this TRX\n")
993{
994 int arfcn = atoi(argv[0]);
995 struct gsm_bts_trx *trx = vty->index;
996
997 /* FIXME: check if this ARFCN is supported by this TRX */
998
999 trx->arfcn = arfcn;
1000
1001 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1002 /* FIXME: use OML layer to update the ARFCN */
1003 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1004
1005 return CMD_SUCCESS;
1006}
1007
Harald Weltefcd24452009-06-20 18:15:19 +02001008DEFUN(cfg_trx_max_power_red,
1009 cfg_trx_max_power_red_cmd,
1010 "max_power_red <0-100>",
1011 "Reduction of maximum BS RF Power in dB\n")
1012{
1013 int maxpwr_r = atoi(argv[0]);
1014 struct gsm_bts_trx *trx = vty->index;
1015 int upper_limit = 12; /* default 12.21 max power red. */
1016
1017 /* FIXME: check if our BTS type supports more than 12 */
1018 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1019 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1020 maxpwr_r, VTY_NEWLINE);
1021 return CMD_WARNING;
1022 }
1023 if (maxpwr_r & 1) {
1024 vty_out(vty, "%% Power %d dB is not an even value%s",
1025 maxpwr_r, VTY_NEWLINE);
1026 return CMD_WARNING;
1027 }
1028
1029 trx->max_power_red = maxpwr_r;
1030
1031 /* FIXME: make sure we update this using OML */
1032
1033 return CMD_SUCCESS;
1034}
1035
Harald Welte42581822009-08-08 16:12:58 +02001036DEFUN(cfg_trx_rsl_e1,
1037 cfg_trx_rsl_e1_cmd,
1038 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1039 "E1 interface to be used for RSL\n")
1040{
1041 struct gsm_bts_trx *trx = vty->index;
1042
1043 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1044
1045 return CMD_SUCCESS;
1046}
1047
1048DEFUN(cfg_trx_rsl_e1_tei,
1049 cfg_trx_rsl_e1_tei_cmd,
1050 "rsl e1 tei <0-63>",
1051 "Set the TEI to be used for RSL")
1052{
1053 struct gsm_bts_trx *trx = vty->index;
1054
1055 trx->rsl_tei = atoi(argv[0]);
1056
1057 return CMD_SUCCESS;
1058}
1059
1060
Harald Welte5258fc42009-03-28 19:07:53 +00001061/* per TS configuration */
1062DEFUN(cfg_ts,
1063 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001064 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001065 "Select a Timeslot to configure")
1066{
1067 int ts_nr = atoi(argv[0]);
1068 struct gsm_bts_trx *trx = vty->index;
1069 struct gsm_bts_trx_ts *ts;
1070
1071 if (ts_nr >= TRX_NR_TS) {
1072 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1073 TRX_NR_TS, VTY_NEWLINE);
1074 return CMD_WARNING;
1075 }
1076
1077 ts = &trx->ts[ts_nr];
1078
1079 vty->index = ts;
1080 vty->node = TS_NODE;
1081
1082 return CMD_SUCCESS;
1083}
1084
Harald Weltea6fd58e2009-08-07 00:25:23 +02001085DEFUN(cfg_ts_pchan,
1086 cfg_ts_pchan_cmd,
1087 "phys_chan_config PCHAN",
1088 "Physical Channel configuration (TCH/SDCCH/...)")
1089{
1090 struct gsm_bts_trx_ts *ts = vty->index;
1091 int pchanc;
1092
1093 pchanc = gsm_pchan_parse(argv[0]);
1094 if (pchanc < 0)
1095 return CMD_WARNING;
1096
1097 ts->pchan = pchanc;
1098
1099 return CMD_SUCCESS;
1100}
1101
1102DEFUN(cfg_ts_e1_subslot,
1103 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001104 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001105 "E1 sub-slot connected to this on-air timeslot")
1106{
1107 struct gsm_bts_trx_ts *ts = vty->index;
1108
Harald Welte42581822009-08-08 16:12:58 +02001109 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001110
1111 return CMD_SUCCESS;
1112}
Harald Welte5258fc42009-03-28 19:07:53 +00001113
Harald Welte40f82892009-05-23 17:31:39 +00001114/* Subscriber */
1115DEFUN(show_subscr,
1116 show_subscr_cmd,
1117 "show subscriber [IMSI]",
1118 SHOW_STR "Display information about a subscriber\n")
1119{
1120 const char *imsi;
1121 struct gsm_subscriber *subscr;
1122
1123 if (argc >= 1) {
1124 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +02001125 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +00001126 if (!subscr) {
1127 vty_out(vty, "%% unknown subscriber%s",
1128 VTY_NEWLINE);
1129 return CMD_WARNING;
1130 }
1131 subscr_dump_vty(vty, subscr);
1132
1133 return CMD_SUCCESS;
1134 }
1135
1136 /* FIXME: iterate over all subscribers ? */
1137 return CMD_WARNING;
1138
1139 return CMD_SUCCESS;
1140}
1141
Harald Welte76042182009-08-08 16:03:15 +02001142DEFUN(sms_send_pend,
1143 sms_send_pend_cmd,
1144 "sms send pending MIN_ID",
1145 "Send all pending SMS starting from MIN_ID")
1146{
1147 struct gsm_sms *sms;
1148
1149 sms = db_sms_get_unsent(gsmnet, atoi(argv[0]));
1150 if (!sms)
1151 return CMD_WARNING;
1152
1153 if (!sms->receiver) {
1154 sms_free(sms);
1155 return CMD_WARNING;
1156 }
1157
1158 gsm411_send_sms_subscr(sms->receiver, sms);
1159
1160 return CMD_SUCCESS;
1161}
1162
Harald Weltef9daefd2009-08-09 15:13:54 +02001163static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1164{
1165 struct buffer *b = buffer_new(1024);
1166 int i;
1167
1168 if (!b)
1169 return NULL;
1170
1171 for (i = base; i < argc; i++) {
1172 buffer_putstr(b, argv[i]);
1173 buffer_putc(b, ' ');
1174 }
1175 buffer_putc(b, '\0');
1176
1177 return b;
1178}
1179
1180static int _send_sms_buffer(struct gsm_subscriber *receiver,
1181 struct buffer *b)
1182{
1183 struct gsm_sms *sms = sms_alloc();
1184
1185 if (!sms)
1186 return CMD_WARNING;
1187
1188 if (!receiver->lac) {
1189 /* subscriber currently not attached, store in database? */
1190 subscr_put(sms->receiver);
1191 return CMD_WARNING;
1192 }
1193
1194 sms->receiver = receiver;
1195 strncpy(sms->text, buffer_getstr(b), sizeof(sms->text)-1);
1196
1197 /* FIXME: don't use ID 1 static */
1198 sms->sender = subscr_get_by_id(gsmnet, 1);
1199 sms->reply_path_req = 0;
1200 sms->status_rep_req = 0;
1201 sms->ud_hdr_ind = 0;
1202 sms->protocol_id = 0; /* implicit */
1203 sms->data_coding_scheme = 0; /* default 7bit */
1204 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1205 /* Generate user_data */
1206 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1207
1208 gsm411_send_sms_subscr(sms->receiver, sms);
1209
1210 return CMD_SUCCESS;
1211}
1212
Harald Welte76042182009-08-08 16:03:15 +02001213DEFUN(sms_send_ext,
1214 sms_send_ext_cmd,
1215 "sms send extension EXTEN .LINE",
1216 "Send a message to a subscriber identified by EXTEN")
1217{
Harald Weltef9daefd2009-08-09 15:13:54 +02001218 struct gsm_subscriber *receiver;
1219 struct buffer *b;
1220 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001221
Harald Weltef9daefd2009-08-09 15:13:54 +02001222 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1223 if (!receiver)
1224 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001225
Harald Weltef9daefd2009-08-09 15:13:54 +02001226 b = argv_to_buffer(argc, argv, 1);
1227 rc = _send_sms_buffer(receiver, b);
1228 buffer_free(b);
1229
1230 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001231}
1232
1233DEFUN(sms_send_imsi,
1234 sms_send_imsi_cmd,
1235 "sms send imsi IMSI .LINE",
1236 "Send a message to a subscriber identified by IMSI")
1237{
Harald Weltef9daefd2009-08-09 15:13:54 +02001238 struct gsm_subscriber *receiver;
1239 struct buffer *b;
1240 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001241
Harald Weltef9daefd2009-08-09 15:13:54 +02001242 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1243 if (!receiver)
1244 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001245
Harald Weltef9daefd2009-08-09 15:13:54 +02001246 b = argv_to_buffer(argc, argv, 1);
1247 rc = _send_sms_buffer(receiver, b);
1248 buffer_free(b);
1249
1250 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001251}
1252
1253
Harald Welte40f82892009-05-23 17:31:39 +00001254DEFUN(cfg_subscr_name,
1255 cfg_subscr_name_cmd,
1256 "name NAME",
1257 "Set the name of the subscriber")
1258{
1259 const char *name = argv[0];
1260 struct gsm_subscriber *subscr = vty->index;
1261
1262 strncpy(subscr->name, name, sizeof(subscr->name));
1263
1264 db_sync_subscriber(subscr);
1265
1266 return CMD_SUCCESS;
1267}
1268
1269DEFUN(cfg_subscr_extension,
1270 cfg_subscr_extension_cmd,
1271 "extension EXTENSION",
1272 "Set the extension of the subscriber")
1273{
1274 const char *name = argv[0];
1275 struct gsm_subscriber *subscr = vty->index;
1276
1277 strncpy(subscr->extension, name, sizeof(subscr->extension));
1278
1279 db_sync_subscriber(subscr);
1280
1281 return CMD_SUCCESS;
1282}
1283
1284DEFUN(cfg_subscr_authorized,
1285 cfg_subscr_authorized_cmd,
1286 "auth <0-1>",
1287 "Set the authorization status of the subscriber")
1288{
1289 int auth = atoi(argv[0]);
1290 struct gsm_subscriber *subscr = vty->index;
1291
1292 if (auth)
1293 subscr->authorized = 1;
1294 else
1295 subscr->authorized = 0;
1296
1297 db_sync_subscriber(subscr);
1298
1299 return CMD_SUCCESS;
1300}
1301
Harald Welte68628e82009-03-10 12:17:57 +00001302int bsc_vty_init(struct gsm_network *net)
1303{
1304 gsmnet = net;
1305
1306 cmd_init(1);
1307 vty_init();
1308
1309 install_element(VIEW_NODE, &show_net_cmd);
1310 install_element(VIEW_NODE, &show_bts_cmd);
1311 install_element(VIEW_NODE, &show_trx_cmd);
1312 install_element(VIEW_NODE, &show_ts_cmd);
1313 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001314
1315 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001316 install_element(VIEW_NODE, &show_e1line_cmd);
1317 install_element(VIEW_NODE, &show_e1ts_cmd);
1318
Harald Weltef5025b62009-03-28 16:55:11 +00001319 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001320
Harald Welte40f82892009-05-23 17:31:39 +00001321 install_element(VIEW_NODE, &show_subscr_cmd);
1322
Harald Welte76042182009-08-08 16:03:15 +02001323 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001324 install_element(VIEW_NODE, &sms_send_ext_cmd);
1325 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001326
Harald Welte5013b2a2009-08-07 13:29:14 +02001327 install_element(CONFIG_NODE, &cfg_net_cmd);
1328 install_node(&net_node, config_write_net);
1329 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001330 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001331 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1332 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1333 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
1334
1335 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001336 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001337 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001338 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001339 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001340 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1341 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001342 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001343 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001344 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1345 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001346 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
1347
Harald Welte68628e82009-03-10 12:17:57 +00001348
Harald Welte5258fc42009-03-28 19:07:53 +00001349 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001350 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001351 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001352 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001353 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001354 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1355 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001356
Harald Welte5258fc42009-03-28 19:07:53 +00001357 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001358 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001359 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001360 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1361 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001362
Harald Welte40f82892009-05-23 17:31:39 +00001363 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1364 install_node(&subscr_node, dummy_config_write);
1365 install_default(SUBSCR_NODE);
1366 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1367 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1368 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1369
Harald Welte68628e82009-03-10 12:17:57 +00001370 return 0;
1371}