blob: 8fc26e2dddd835aa6875b9a211579ef437174e6f [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001/* 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 Welte684b9752009-08-09 15:13:54 +020026#include <vty/buffer.h>
Harald Welte59b04682009-06-10 05:40:52 +080027#include <vty/vty.h>
28
29#include <arpa/inet.h>
30
31#include <openbsc/linuxlist.h>
32#include <openbsc/gsm_data.h>
33#include <openbsc/gsm_subscriber.h>
Holger Hans Peter Freyther735cd9e2009-08-10 07:54:02 +020034#include <openbsc/gsm_04_11.h>
Harald Welte59b04682009-06-10 05:40:52 +080035#include <openbsc/e1_input.h>
36#include <openbsc/abis_nm.h>
Harald Welte684b9752009-08-09 15:13:54 +020037#include <openbsc/gsm_utils.h>
Harald Welte59b04682009-06-10 05:40:52 +080038#include <openbsc/db.h>
Harald Weltee87eb462009-08-07 13:29:14 +020039#include <openbsc/talloc.h>
Harald Welte59b04682009-06-10 05:40:52 +080040
41static struct gsm_network *gsmnet;
42
Harald Weltee87eb462009-08-07 13:29:14 +020043struct cmd_node net_node = {
44 GSMNET_NODE,
45 "%s(network)#",
46 1,
47};
48
Harald Welte59b04682009-06-10 05:40:52 +080049struct 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
67struct cmd_node subscr_node = {
68 SUBSCR_NODE,
69 "%s(subscriber)#",
70 1,
71};
72
73static 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{
80 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);
83}
84
85static void net_dump_vty(struct vty *vty, struct gsm_network *net)
86{
87 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);
90 vty_out(vty, " Long network name: '%s'%s",
91 net->name_long, VTY_NEWLINE);
92 vty_out(vty, " Short network name: '%s'%s",
93 net->name_short, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +020094 vty_out(vty, " Authentication policy: %s%s",
95 gsm_auth_policy_name(net->auth_policy), VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +080096}
97
98DEFUN(show_net, show_net_cmd, "show network",
99 SHOW_STR "Display information about a GSM NETWORK\n")
100{
101 struct gsm_network *net = gsmnet;
102 net_dump_vty(vty, net);
103
104 return CMD_SUCCESS;
105}
106
107static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
108{
109 struct e1inp_line *line;
110
111 if (!e1l) {
112 vty_out(vty, " None%s", VTY_NEWLINE);
113 return;
114 }
115
116 line = e1l->ts->line;
117
118 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
119 line->num, line->driver->name, e1l->ts->num,
120 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
121 vty_out(vty, " E1 TEI %u, SAPI %u%s",
122 e1l->tei, e1l->sapi, VTY_NEWLINE);
123}
124
125static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
126{
Harald Welte91afe4c2009-06-20 18:15:19 +0200127 vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, "
128 "BSIC %u, TSC %u and %u TRX%s",
129 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
130 bts->location_area_code, bts->bsic, bts->tsc,
131 bts->num_trx, VTY_NEWLINE);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200132 if (bts->cell_barred)
133 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800134 if (is_ipaccess_bts(bts))
135 vty_out(vty, " Unit ID: %u/%u/0%s",
136 bts->ip_access.site_id, bts->ip_access.bts_id,
137 VTY_NEWLINE);
138 vty_out(vty, " NM State: ");
139 net_dump_nmstate(vty, &bts->nm_state);
140 vty_out(vty, " Site Mgr NM State: ");
141 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
142 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
143 bts->paging.available_slots, VTY_NEWLINE);
144 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
145 e1isl_dump_vty(vty, bts->oml_link);
146 /* FIXME: oml_link, chan_desc */
147}
148
149DEFUN(show_bts, show_bts_cmd, "show bts [number]",
150 SHOW_STR "Display information about a BTS\n"
151 "BTS number")
152{
153 struct gsm_network *net = gsmnet;
154 int bts_nr;
155
156 if (argc != 0) {
157 /* use the BTS number that the user has specified */
158 bts_nr = atoi(argv[0]);
159 if (bts_nr > net->num_bts) {
160 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
161 VTY_NEWLINE);
162 return CMD_WARNING;
163 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200164 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte59b04682009-06-10 05:40:52 +0800165 return CMD_SUCCESS;
166 }
167 /* print all BTS's */
168 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee712a5f2009-06-21 16:17:15 +0200169 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte59b04682009-06-10 05:40:52 +0800170
171 return CMD_SUCCESS;
172}
173
Harald Welte62868882009-08-08 16:12:58 +0200174/* utility functions */
175static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
176 const char *ts, const char *ss)
177{
178 e1_link->e1_nr = atoi(line);
179 e1_link->e1_ts = atoi(ts);
180 if (!strcmp(ss, "full"))
181 e1_link->e1_ts_ss = 255;
182 else
183 e1_link->e1_ts_ss = atoi(ss);
184}
185
186static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
187 const char *prefix)
188{
189 if (!e1_link->e1_ts)
190 return;
191
192 if (e1_link->e1_ts_ss == 255)
193 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
194 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
195 else
196 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
197 prefix, e1_link->e1_nr, e1_link->e1_ts,
198 e1_link->e1_ts_ss, VTY_NEWLINE);
199}
200
201
Harald Welte97ceef92009-08-06 19:06:46 +0200202static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
203{
Harald Welte62868882009-08-08 16:12:58 +0200204 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
205 if (ts->pchan != GSM_PCHAN_NONE)
206 vty_out(vty, " phys_chan_config %s%s",
207 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
208 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte97ceef92009-08-06 19:06:46 +0200209}
210
211static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
212{
213 int i;
214
Harald Weltee87eb462009-08-07 13:29:14 +0200215 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
216 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
217 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200218 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
219 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte97ceef92009-08-06 19:06:46 +0200220
221 for (i = 0; i < TRX_NR_TS; i++)
222 config_write_ts_single(vty, &trx->ts[i]);
223}
224
225static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
226{
227 struct gsm_bts_trx *trx;
228
Harald Weltee87eb462009-08-07 13:29:14 +0200229 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
230 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
231 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
232 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte97ceef92009-08-06 19:06:46 +0200233 VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200234 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
235 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Welte (local)cbd46102009-08-13 10:14:26 +0200236 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Welte3e774612009-08-10 13:48:16 +0200237 vty_out(vty, " channel allocator %s%s",
238 bts->chan_alloc_reverse ? "descending" : "ascending",
239 VTY_NEWLINE);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200240 if (bts->cell_barred)
241 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte3ffe1b32009-08-07 00:25:23 +0200242 if (is_ipaccess_bts(bts))
Harald Weltee87eb462009-08-07 13:29:14 +0200243 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Welte3ffe1b32009-08-07 00:25:23 +0200244 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200245 else {
246 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
247 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
248 }
Harald Welte97ceef92009-08-06 19:06:46 +0200249
250 llist_for_each_entry(trx, &bts->trx_list, list)
251 config_write_trx_single(vty, trx);
252}
253
254static int config_write_bts(struct vty *v)
255{
256 struct gsm_bts *bts;
257
258 llist_for_each_entry(bts, &gsmnet->bts_list, list)
259 config_write_bts_single(v, bts);
260
261 return CMD_SUCCESS;
262}
263
Harald Weltee87eb462009-08-07 13:29:14 +0200264static int config_write_net(struct vty *vty)
265{
266 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200267 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200268 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200269 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
270 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200271 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200272
273 return CMD_SUCCESS;
274}
Harald Welte97ceef92009-08-06 19:06:46 +0200275
Harald Welte59b04682009-06-10 05:40:52 +0800276static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
277{
278 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
279 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Welte91afe4c2009-06-20 18:15:19 +0200280 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte62868882009-08-08 16:12:58 +0200281 "resulting BS power: %d dBm%s",
Harald Welte91afe4c2009-06-20 18:15:19 +0200282 trx->nominal_power, trx->max_power_red,
Harald Welte62868882009-08-08 16:12:58 +0200283 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800284 vty_out(vty, " NM State: ");
285 net_dump_nmstate(vty, &trx->nm_state);
286 vty_out(vty, " Baseband Transceiver NM State: ");
287 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
288 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
289 e1isl_dump_vty(vty, trx->rsl_link);
290}
291
292DEFUN(show_trx,
293 show_trx_cmd,
294 "show trx [bts_nr] [trx_nr]",
295 SHOW_STR "Display information about a TRX\n")
296{
297 struct gsm_network *net = gsmnet;
298 struct gsm_bts *bts = NULL;
299 struct gsm_bts_trx *trx;
300 int bts_nr, trx_nr;
301
302 if (argc >= 1) {
303 /* use the BTS number that the user has specified */
304 bts_nr = atoi(argv[0]);
305 if (bts_nr >= net->num_bts) {
306 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
307 VTY_NEWLINE);
308 return CMD_WARNING;
309 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200310 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800311 }
312 if (argc >= 2) {
313 trx_nr = atoi(argv[1]);
314 if (trx_nr >= bts->num_trx) {
315 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
316 VTY_NEWLINE);
317 return CMD_WARNING;
318 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200319 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800320 trx_dump_vty(vty, trx);
321 return CMD_SUCCESS;
322 }
323 if (bts) {
324 /* print all TRX in this BTS */
325 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200326 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800327 trx_dump_vty(vty, trx);
328 }
329 return CMD_SUCCESS;
330 }
331
332 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200333 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800334 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200335 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800336 trx_dump_vty(vty, trx);
337 }
338 }
339
340 return CMD_SUCCESS;
341}
342
Harald Welte97ceef92009-08-06 19:06:46 +0200343
Harald Welte59b04682009-06-10 05:40:52 +0800344static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
345{
346 struct in_addr ia;
347
348 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
349 ts->nr, ts->trx->nr, ts->trx->bts->nr,
350 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
351 vty_out(vty, " NM State: ");
352 net_dump_nmstate(vty, &ts->nm_state);
353 if (is_ipaccess_bts(ts->trx->bts)) {
354 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte8cdeaad2009-07-12 09:50:35 +0200355 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte59b04682009-06-10 05:40:52 +0800356 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte8cdeaad2009-07-12 09:50:35 +0200357 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte59b04682009-06-10 05:40:52 +0800358 VTY_NEWLINE);
359 } else {
360 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
361 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
362 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
363 }
364}
365
366DEFUN(show_ts,
367 show_ts_cmd,
368 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
369 SHOW_STR "Display information about a TS\n")
370{
371 struct gsm_network *net = gsmnet;
372 struct gsm_bts *bts;
373 struct gsm_bts_trx *trx;
374 struct gsm_bts_trx_ts *ts;
375 int bts_nr, trx_nr, ts_nr;
376
377 if (argc >= 1) {
378 /* use the BTS number that the user has specified */
379 bts_nr = atoi(argv[0]);
380 if (bts_nr >= net->num_bts) {
381 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
382 VTY_NEWLINE);
383 return CMD_WARNING;
384 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200385 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800386 }
387 if (argc >= 2) {
388 trx_nr = atoi(argv[1]);
389 if (trx_nr >= bts->num_trx) {
390 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
391 VTY_NEWLINE);
392 return CMD_WARNING;
393 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200394 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800395 }
396 if (argc >= 3) {
397 ts_nr = atoi(argv[2]);
398 if (ts_nr >= TRX_NR_TS) {
399 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
400 VTY_NEWLINE);
401 return CMD_WARNING;
402 }
403 ts = &trx->ts[ts_nr];
404 ts_dump_vty(vty, ts);
405 return CMD_SUCCESS;
406 }
407 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200408 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800409 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200410 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800411 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
412 ts = &trx->ts[ts_nr];
413 ts_dump_vty(vty, ts);
414 }
415 }
416 }
417
418 return CMD_SUCCESS;
419}
420
421static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
422{
Harald Welte91afe4c2009-06-20 18:15:19 +0200423 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte59b04682009-06-10 05:40:52 +0800424 subscr->authorized, VTY_NEWLINE);
425 if (subscr->name)
426 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
427 if (subscr->extension)
428 vty_out(vty, " Extension: %s%s", subscr->extension,
429 VTY_NEWLINE);
430 if (subscr->imsi)
431 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
432 if (subscr->tmsi)
433 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +0200434 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800435}
436
437static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
438{
439 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
440 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
441 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
442 VTY_NEWLINE);
443 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
444 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
445 lchan->ms_power, VTY_NEWLINE);
446 if (lchan->subscr) {
447 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
448 subscr_dump_vty(vty, lchan->subscr);
449 } else
450 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
451}
452
Harald Welte03740842009-06-10 23:11:52 +0800453#if 0
454TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte59b04682009-06-10 05:40:52 +0800455static void call_dump_vty(struct vty *vty, struct gsm_call *call)
456{
457 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
458 call->type, call->state, call->transaction_id, VTY_NEWLINE);
459
460 if (call->local_lchan) {
461 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
462 lchan_dump_vty(vty, call->local_lchan);
463 } else
464 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
465
466 if (call->remote_lchan) {
467 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
468 lchan_dump_vty(vty, call->remote_lchan);
469 } else
470 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
471
472 if (call->called_subscr) {
473 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
474 subscr_dump_vty(vty, call->called_subscr);
475 } else
476 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
477}
Harald Welte03740842009-06-10 23:11:52 +0800478#endif
Harald Welte59b04682009-06-10 05:40:52 +0800479
480DEFUN(show_lchan,
481 show_lchan_cmd,
482 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
483 SHOW_STR "Display information about a logical channel\n")
484{
485 struct gsm_network *net = gsmnet;
486 struct gsm_bts *bts;
487 struct gsm_bts_trx *trx;
488 struct gsm_bts_trx_ts *ts;
489 struct gsm_lchan *lchan;
490 int bts_nr, trx_nr, ts_nr, lchan_nr;
491
492 if (argc >= 1) {
493 /* use the BTS number that the user has specified */
494 bts_nr = atoi(argv[0]);
495 if (bts_nr >= net->num_bts) {
496 vty_out(vty, "%% can't find BTS %s%s", argv[0],
497 VTY_NEWLINE);
498 return CMD_WARNING;
499 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200500 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800501 }
502 if (argc >= 2) {
503 trx_nr = atoi(argv[1]);
504 if (trx_nr >= bts->num_trx) {
505 vty_out(vty, "%% can't find TRX %s%s", argv[1],
506 VTY_NEWLINE);
507 return CMD_WARNING;
508 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200509 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800510 }
511 if (argc >= 3) {
512 ts_nr = atoi(argv[2]);
513 if (ts_nr >= TRX_NR_TS) {
514 vty_out(vty, "%% can't find TS %s%s", argv[2],
515 VTY_NEWLINE);
516 return CMD_WARNING;
517 }
518 ts = &trx->ts[ts_nr];
519 }
520 if (argc >= 4) {
521 lchan_nr = atoi(argv[3]);
522 if (lchan_nr >= TS_MAX_LCHAN) {
523 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
524 VTY_NEWLINE);
525 return CMD_WARNING;
526 }
527 lchan = &ts->lchan[lchan_nr];
528 lchan_dump_vty(vty, lchan);
529 return CMD_SUCCESS;
530 }
531 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200532 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800533 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200534 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800535 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
536 ts = &trx->ts[ts_nr];
537 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
538 lchan_nr++) {
539 lchan = &ts->lchan[lchan_nr];
540 if (lchan->type == GSM_LCHAN_NONE)
541 continue;
542 lchan_dump_vty(vty, lchan);
543 }
544 }
545 }
546 }
547
548 return CMD_SUCCESS;
549}
550
551static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
552{
553 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
554}
555
556DEFUN(show_e1drv,
557 show_e1drv_cmd,
558 "show e1_driver",
559 SHOW_STR "Display information about available E1 drivers\n")
560{
561 struct e1inp_driver *drv;
562
563 llist_for_each_entry(drv, &e1inp_driver_list, list)
564 e1drv_dump_vty(vty, drv);
565
566 return CMD_SUCCESS;
567}
568
569static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
570{
571 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
572 line->num, line->name ? line->name : "",
573 line->driver->name, VTY_NEWLINE);
574}
575
576DEFUN(show_e1line,
577 show_e1line_cmd,
578 "show e1_line [line_nr]",
579 SHOW_STR "Display information about a E1 line\n")
580{
581 struct e1inp_line *line;
582
583 if (argc >= 1) {
584 int num = atoi(argv[0]);
585 llist_for_each_entry(line, &e1inp_line_list, list) {
586 if (line->num == num) {
587 e1line_dump_vty(vty, line);
588 return CMD_SUCCESS;
589 }
590 }
591 return CMD_WARNING;
592 }
593
594 llist_for_each_entry(line, &e1inp_line_list, list)
595 e1line_dump_vty(vty, line);
596
597 return CMD_SUCCESS;
598}
599
600static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
601{
Harald Welte62868882009-08-08 16:12:58 +0200602 if (ts->type == E1INP_TS_TYPE_NONE)
603 return;
Harald Welte59b04682009-06-10 05:40:52 +0800604 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
605 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
606 VTY_NEWLINE);
607}
608
609DEFUN(show_e1ts,
610 show_e1ts_cmd,
611 "show e1_timeslot [line_nr] [ts_nr]",
612 SHOW_STR "Display information about a E1 timeslot\n")
613{
614 struct e1inp_line *line;
615 struct e1inp_ts *ts;
616 int ts_nr;
617
618 if (argc == 0) {
619 llist_for_each_entry(line, &e1inp_line_list, list) {
620 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
621 ts = &line->ts[ts_nr];
622 e1ts_dump_vty(vty, ts);
623 }
624 }
625 return CMD_SUCCESS;
626 }
627 if (argc >= 1) {
628 int num = atoi(argv[0]);
629 llist_for_each_entry(line, &e1inp_line_list, list) {
630 if (line->num == num)
631 break;
632 }
633 if (!line || line->num != num) {
634 vty_out(vty, "E1 line %s is invalid%s",
635 argv[0], VTY_NEWLINE);
636 return CMD_WARNING;
637 }
638 }
639 if (argc >= 2) {
640 ts_nr = atoi(argv[1]);
641 if (ts_nr > NUM_E1_TS) {
642 vty_out(vty, "E1 timeslot %s is invalid%s",
643 argv[1], VTY_NEWLINE);
644 return CMD_WARNING;
645 }
646 ts = &line->ts[ts_nr];
647 e1ts_dump_vty(vty, ts);
648 return CMD_SUCCESS;
649 } else {
650 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
651 ts = &line->ts[ts_nr];
652 e1ts_dump_vty(vty, ts);
653 }
654 return CMD_SUCCESS;
655 }
656 return CMD_SUCCESS;
657}
658
659static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
660{
661 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
662 subscr_dump_vty(vty, pag->subscr);
663}
664
665static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
666{
667 struct gsm_paging_request *pag;
668
669 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
670 paging_dump_vty(vty, pag);
671}
672
673DEFUN(show_paging,
674 show_paging_cmd,
675 "show paging [bts_nr]",
676 SHOW_STR "Display information about paging reuqests of a BTS\n")
677{
678 struct gsm_network *net = gsmnet;
679 struct gsm_bts *bts;
680 int bts_nr;
681
682 if (argc >= 1) {
683 /* use the BTS number that the user has specified */
684 bts_nr = atoi(argv[0]);
685 if (bts_nr >= net->num_bts) {
686 vty_out(vty, "%% can't find BTS %s%s", argv[0],
687 VTY_NEWLINE);
688 return CMD_WARNING;
689 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200690 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800691 bts_paging_dump_vty(vty, bts);
692
693 return CMD_SUCCESS;
694 }
695 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200696 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800697 bts_paging_dump_vty(vty, bts);
698 }
699
700 return CMD_SUCCESS;
701}
702
703/* per-subscriber configuration */
704DEFUN(cfg_subscr,
705 cfg_subscr_cmd,
706 "subscriber IMSI",
707 "Select a Subscriber to configure\n")
708{
709 const char *imsi = argv[0];
710 struct gsm_subscriber *subscr;
711
Harald Welteaae7a522009-07-23 19:21:02 +0200712 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte59b04682009-06-10 05:40:52 +0800713 if (!subscr) {
714 vty_out(vty, "%% No subscriber for IMSI %s%s",
715 imsi, VTY_NEWLINE);
716 return CMD_WARNING;
717 }
718
719 vty->index = subscr;
720 vty->node = SUBSCR_NODE;
721
722 return CMD_SUCCESS;
723}
724
Harald Weltee87eb462009-08-07 13:29:14 +0200725DEFUN(cfg_net,
726 cfg_net_cmd,
727 "network",
728 "Configure the GSM network")
729{
730 vty->index = gsmnet;
731 vty->node = GSMNET_NODE;
732
733 return CMD_SUCCESS;
734}
735
736
737DEFUN(cfg_net_ncc,
738 cfg_net_ncc_cmd,
739 "network country code <1-999>",
740 "Set the GSM network country code")
741{
742 gsmnet->country_code = atoi(argv[0]);
743
744 return CMD_SUCCESS;
745}
746
747DEFUN(cfg_net_mnc,
748 cfg_net_mnc_cmd,
749 "mobile network code <1-999>",
750 "Set the GSM mobile network code")
751{
752 gsmnet->network_code = atoi(argv[0]);
753
754 return CMD_SUCCESS;
755}
756
757DEFUN(cfg_net_name_short,
758 cfg_net_name_short_cmd,
759 "short name NAME",
760 "Set the short GSM network name")
761{
762 if (gsmnet->name_short)
763 talloc_free(gsmnet->name_short);
764
765 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
766
767 return CMD_SUCCESS;
768}
769
770DEFUN(cfg_net_name_long,
771 cfg_net_name_long_cmd,
772 "long name NAME",
773 "Set the long GSM network name")
774{
775 if (gsmnet->name_long)
776 talloc_free(gsmnet->name_long);
777
778 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
779
780 return CMD_SUCCESS;
781}
Harald Welte59b04682009-06-10 05:40:52 +0800782
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200783DEFUN(cfg_net_auth_policy,
784 cfg_net_auth_policy_cmd,
785 "auth policy (closed|accept-all|token)",
786 "Set the GSM network authentication policy\n")
787{
788 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
789
790 gsmnet->auth_policy = policy;
791
792 return CMD_SUCCESS;
793}
794
Harald Welte59b04682009-06-10 05:40:52 +0800795/* per-BTS configuration */
796DEFUN(cfg_bts,
797 cfg_bts_cmd,
798 "bts BTS_NR",
799 "Select a BTS to configure\n")
800{
801 int bts_nr = atoi(argv[0]);
802 struct gsm_bts *bts;
803
Harald Weltee712a5f2009-06-21 16:17:15 +0200804 if (bts_nr > gsmnet->num_bts) {
805 vty_out(vty, "%% The next unused BTS number is %u%s",
806 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800807 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +0200808 } else if (bts_nr == gsmnet->num_bts) {
809 /* allocate a new one */
810 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
811 HARDCODED_TSC, HARDCODED_BSIC);
812 } else
813 bts = gsm_bts_num(gsmnet, bts_nr);
814
815 if (!bts)
816 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +0800817
818 vty->index = bts;
819 vty->node = BTS_NODE;
820
821 return CMD_SUCCESS;
822}
823
824DEFUN(cfg_bts_type,
825 cfg_bts_type_cmd,
826 "type TYPE",
827 "Set the BTS type\n")
828{
829 struct gsm_bts *bts = vty->index;
830
Harald Welte3ffe1b32009-08-07 00:25:23 +0200831 bts->type = parse_btstype(argv[0]);
832
Harald Welte59b04682009-06-10 05:40:52 +0800833 return CMD_SUCCESS;
834}
835
Harald Welte91afe4c2009-06-20 18:15:19 +0200836DEFUN(cfg_bts_band,
837 cfg_bts_band_cmd,
838 "band BAND",
839 "Set the frequency band of this BTS\n")
840{
841 struct gsm_bts *bts = vty->index;
Harald Welte62868882009-08-08 16:12:58 +0200842 int band = gsm_band_parse(argv[0]);
Harald Welte91afe4c2009-06-20 18:15:19 +0200843
844 if (band < 0) {
845 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
846 band, VTY_NEWLINE);
847 return CMD_WARNING;
848 }
849
850 bts->band = band;
851
852 return CMD_SUCCESS;
853}
854
Harald Welte59b04682009-06-10 05:40:52 +0800855DEFUN(cfg_bts_lac,
856 cfg_bts_lac_cmd,
857 "location_area_code <0-255>",
858 "Set the Location Area Code (LAC) of this BTS\n")
859{
860 struct gsm_bts *bts = vty->index;
861 int lac = atoi(argv[0]);
862
863 if (lac < 0 || lac > 0xff) {
864 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
865 lac, VTY_NEWLINE);
866 return CMD_WARNING;
867 }
868 bts->location_area_code = lac;
869
870 return CMD_SUCCESS;
871}
872
873DEFUN(cfg_bts_tsc,
874 cfg_bts_tsc_cmd,
875 "training_sequence_code <0-255>",
876 "Set the Training Sequence Code (TSC) of this BTS\n")
877{
878 struct gsm_bts *bts = vty->index;
879 int tsc = atoi(argv[0]);
880
881 if (tsc < 0 || tsc > 0xff) {
882 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
883 tsc, VTY_NEWLINE);
884 return CMD_WARNING;
885 }
886 bts->tsc = tsc;
887
888 return CMD_SUCCESS;
889}
890
891DEFUN(cfg_bts_bsic,
892 cfg_bts_bsic_cmd,
893 "base_station_id_code <0-63>",
894 "Set the Base Station Identity Code (BSIC) of this BTS\n")
895{
896 struct gsm_bts *bts = vty->index;
897 int bsic = atoi(argv[0]);
898
899 if (bsic < 0 || bsic > 0x3f) {
Harald Welte62868882009-08-08 16:12:58 +0200900 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte59b04682009-06-10 05:40:52 +0800901 bsic, VTY_NEWLINE);
902 return CMD_WARNING;
903 }
904 bts->bsic = bsic;
905
906 return CMD_SUCCESS;
907}
908
909
910DEFUN(cfg_bts_unit_id,
911 cfg_bts_unit_id_cmd,
Harald Weltef515aa02009-08-07 13:27:09 +0200912 "ip.access unit_id <0-65534> <0-255>",
913 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte59b04682009-06-10 05:40:52 +0800914{
915 struct gsm_bts *bts = vty->index;
916 int site_id = atoi(argv[0]);
917 int bts_id = atoi(argv[1]);
918
Harald Weltef515aa02009-08-07 13:27:09 +0200919 if (!is_ipaccess_bts(bts)) {
920 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
921 return CMD_WARNING;
922 }
923
Harald Welte59b04682009-06-10 05:40:52 +0800924 bts->ip_access.site_id = site_id;
925 bts->ip_access.bts_id = bts_id;
926
927 return CMD_SUCCESS;
928}
929
Harald Welte62868882009-08-08 16:12:58 +0200930DEFUN(cfg_bts_oml_e1,
931 cfg_bts_oml_e1_cmd,
932 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
933 "E1 interface to be used for OML\n")
934{
935 struct gsm_bts *bts = vty->index;
936
937 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
938
939 return CMD_SUCCESS;
940}
941
942
943DEFUN(cfg_bts_oml_e1_tei,
944 cfg_bts_oml_e1_tei_cmd,
945 "oml e1 tei <0-63>",
946 "Set the TEI to be used for OML")
947{
948 struct gsm_bts *bts = vty->index;
949
950 bts->oml_tei = atoi(argv[0]);
951
952 return CMD_SUCCESS;
953}
954
Harald Welte3e774612009-08-10 13:48:16 +0200955DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
956 "channel allocator (ascending|descending)",
957 "Should the channel allocator allocate in reverse TRX order?")
958{
959 struct gsm_bts *bts = vty->index;
960
961 if (!strcmp(argv[0], "ascending"))
962 bts->chan_alloc_reverse = 0;
963 else
964 bts->chan_alloc_reverse = 1;
965
966 return CMD_SUCCESS;
967}
968
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200969DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
970 "cell barred (0|1)",
971 "Should this cell be barred from access?")
972{
973 struct gsm_bts *bts = vty->index;
974
975 bts->cell_barred = atoi(argv[0]);
976
977 return CMD_SUCCESS;
978}
979
Harald Welte (local)cbd46102009-08-13 10:14:26 +0200980DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
981 "ms max power <0-40>",
982 "Maximum transmit power of the MS")
983{
984 struct gsm_bts *bts = vty->index;
985
986 bts->ms_max_power = atoi(argv[0]);
987
988 return CMD_SUCCESS;
989}
990
Harald Welte3e774612009-08-10 13:48:16 +0200991
Harald Welte59b04682009-06-10 05:40:52 +0800992/* per TRX configuration */
993DEFUN(cfg_trx,
994 cfg_trx_cmd,
995 "trx TRX_NR",
996 "Select a TRX to configure")
997{
998 int trx_nr = atoi(argv[0]);
999 struct gsm_bts *bts = vty->index;
1000 struct gsm_bts_trx *trx;
1001
Harald Weltee712a5f2009-06-21 16:17:15 +02001002 if (trx_nr > bts->num_trx) {
1003 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1004 bts->num_trx, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001005 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001006 } else if (trx_nr == bts->num_trx) {
1007 /* we need to allocate a new one */
1008 trx = gsm_bts_trx_alloc(bts);
1009 } else
1010 trx = gsm_bts_trx_num(bts, trx_nr);
1011
1012 if (!trx)
1013 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001014
1015 vty->index = trx;
1016 vty->node = TRX_NODE;
1017
1018 return CMD_SUCCESS;
1019}
1020
1021DEFUN(cfg_trx_arfcn,
1022 cfg_trx_arfcn_cmd,
1023 "arfcn <1-1024>",
1024 "Set the ARFCN for this TRX\n")
1025{
1026 int arfcn = atoi(argv[0]);
1027 struct gsm_bts_trx *trx = vty->index;
1028
1029 /* FIXME: check if this ARFCN is supported by this TRX */
1030
1031 trx->arfcn = arfcn;
1032
1033 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1034 /* FIXME: use OML layer to update the ARFCN */
1035 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1036
1037 return CMD_SUCCESS;
1038}
1039
Harald Welte91afe4c2009-06-20 18:15:19 +02001040DEFUN(cfg_trx_max_power_red,
1041 cfg_trx_max_power_red_cmd,
1042 "max_power_red <0-100>",
1043 "Reduction of maximum BS RF Power in dB\n")
1044{
1045 int maxpwr_r = atoi(argv[0]);
1046 struct gsm_bts_trx *trx = vty->index;
1047 int upper_limit = 12; /* default 12.21 max power red. */
1048
1049 /* FIXME: check if our BTS type supports more than 12 */
1050 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1051 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1052 maxpwr_r, VTY_NEWLINE);
1053 return CMD_WARNING;
1054 }
1055 if (maxpwr_r & 1) {
1056 vty_out(vty, "%% Power %d dB is not an even value%s",
1057 maxpwr_r, VTY_NEWLINE);
1058 return CMD_WARNING;
1059 }
1060
1061 trx->max_power_red = maxpwr_r;
1062
1063 /* FIXME: make sure we update this using OML */
1064
1065 return CMD_SUCCESS;
1066}
1067
Harald Welte62868882009-08-08 16:12:58 +02001068DEFUN(cfg_trx_rsl_e1,
1069 cfg_trx_rsl_e1_cmd,
1070 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1071 "E1 interface to be used for RSL\n")
1072{
1073 struct gsm_bts_trx *trx = vty->index;
1074
1075 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1076
1077 return CMD_SUCCESS;
1078}
1079
1080DEFUN(cfg_trx_rsl_e1_tei,
1081 cfg_trx_rsl_e1_tei_cmd,
1082 "rsl e1 tei <0-63>",
1083 "Set the TEI to be used for RSL")
1084{
1085 struct gsm_bts_trx *trx = vty->index;
1086
1087 trx->rsl_tei = atoi(argv[0]);
1088
1089 return CMD_SUCCESS;
1090}
1091
1092
Harald Welte59b04682009-06-10 05:40:52 +08001093/* per TS configuration */
1094DEFUN(cfg_ts,
1095 cfg_ts_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001096 "timeslot <0-7>",
Harald Welte59b04682009-06-10 05:40:52 +08001097 "Select a Timeslot to configure")
1098{
1099 int ts_nr = atoi(argv[0]);
1100 struct gsm_bts_trx *trx = vty->index;
1101 struct gsm_bts_trx_ts *ts;
1102
1103 if (ts_nr >= TRX_NR_TS) {
1104 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1105 TRX_NR_TS, VTY_NEWLINE);
1106 return CMD_WARNING;
1107 }
1108
1109 ts = &trx->ts[ts_nr];
1110
1111 vty->index = ts;
1112 vty->node = TS_NODE;
1113
1114 return CMD_SUCCESS;
1115}
1116
Harald Welte3ffe1b32009-08-07 00:25:23 +02001117DEFUN(cfg_ts_pchan,
1118 cfg_ts_pchan_cmd,
1119 "phys_chan_config PCHAN",
1120 "Physical Channel configuration (TCH/SDCCH/...)")
1121{
1122 struct gsm_bts_trx_ts *ts = vty->index;
1123 int pchanc;
1124
1125 pchanc = gsm_pchan_parse(argv[0]);
1126 if (pchanc < 0)
1127 return CMD_WARNING;
1128
1129 ts->pchan = pchanc;
1130
1131 return CMD_SUCCESS;
1132}
1133
1134DEFUN(cfg_ts_e1_subslot,
1135 cfg_ts_e1_subslot_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001136 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Welte3ffe1b32009-08-07 00:25:23 +02001137 "E1 sub-slot connected to this on-air timeslot")
1138{
1139 struct gsm_bts_trx_ts *ts = vty->index;
1140
Harald Welte62868882009-08-08 16:12:58 +02001141 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001142
1143 return CMD_SUCCESS;
1144}
Harald Welte59b04682009-06-10 05:40:52 +08001145
1146/* Subscriber */
1147DEFUN(show_subscr,
1148 show_subscr_cmd,
1149 "show subscriber [IMSI]",
1150 SHOW_STR "Display information about a subscriber\n")
1151{
1152 const char *imsi;
1153 struct gsm_subscriber *subscr;
1154
1155 if (argc >= 1) {
1156 imsi = argv[0];
Harald Welteaae7a522009-07-23 19:21:02 +02001157 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte59b04682009-06-10 05:40:52 +08001158 if (!subscr) {
1159 vty_out(vty, "%% unknown subscriber%s",
1160 VTY_NEWLINE);
1161 return CMD_WARNING;
1162 }
1163 subscr_dump_vty(vty, subscr);
1164
1165 return CMD_SUCCESS;
1166 }
1167
1168 /* FIXME: iterate over all subscribers ? */
1169 return CMD_WARNING;
1170
1171 return CMD_SUCCESS;
1172}
1173
Harald Welte (local)02d5efa2009-08-14 20:27:16 +02001174DEFUN(show_subscr_cache,
1175 show_subscr_cache_cmd,
1176 "show subscriber cache",
1177 SHOW_STR "Display contents of subscriber cache\n")
1178{
1179 struct gsm_subscriber *subscr;
1180
1181 llist_for_each_entry(subscr, &active_subscribers, entry) {
1182 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
1183 subscr_dump_vty(vty, subscr);
1184 }
1185
1186 return CMD_SUCCESS;
1187}
1188
Harald Welte68b7df22009-08-08 16:03:15 +02001189DEFUN(sms_send_pend,
1190 sms_send_pend_cmd,
1191 "sms send pending MIN_ID",
1192 "Send all pending SMS starting from MIN_ID")
1193{
1194 struct gsm_sms *sms;
Harald Welte (local)5be45322009-08-14 16:01:20 +02001195 int id = atoi(argv[0]);
Harald Welte68b7df22009-08-08 16:03:15 +02001196
Harald Welte (local)5be45322009-08-14 16:01:20 +02001197 while (1) {
1198 sms = db_sms_get_unsent(gsmnet, id++);
1199 if (!sms)
1200 return CMD_WARNING;
Harald Welte68b7df22009-08-08 16:03:15 +02001201
Harald Welte (local)5be45322009-08-14 16:01:20 +02001202 if (!sms->receiver) {
1203 sms_free(sms);
1204 continue;
1205 }
1206
1207 gsm411_send_sms_subscr(sms->receiver, sms);
Harald Welte68b7df22009-08-08 16:03:15 +02001208 }
1209
Harald Welte68b7df22009-08-08 16:03:15 +02001210 return CMD_SUCCESS;
1211}
1212
Harald Welte684b9752009-08-09 15:13:54 +02001213static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1214{
1215 struct buffer *b = buffer_new(1024);
1216 int i;
1217
1218 if (!b)
1219 return NULL;
1220
1221 for (i = base; i < argc; i++) {
1222 buffer_putstr(b, argv[i]);
1223 buffer_putc(b, ' ');
1224 }
1225 buffer_putc(b, '\0');
1226
1227 return b;
1228}
1229
Harald Welte948bba82009-08-13 00:57:31 +02001230int sms_from_text(struct gsm_subscriber *receiver, const char *text)
Harald Welte684b9752009-08-09 15:13:54 +02001231{
1232 struct gsm_sms *sms = sms_alloc();
1233
1234 if (!sms)
1235 return CMD_WARNING;
1236
1237 if (!receiver->lac) {
1238 /* subscriber currently not attached, store in database? */
Harald Welte684b9752009-08-09 15:13:54 +02001239 return CMD_WARNING;
1240 }
1241
Harald Welte (local)ddf83b22009-08-13 13:25:32 +02001242 sms->receiver = subscr_get(receiver);
Harald Welte948bba82009-08-13 00:57:31 +02001243 strncpy(sms->text, text, sizeof(sms->text)-1);
Harald Welte684b9752009-08-09 15:13:54 +02001244
1245 /* FIXME: don't use ID 1 static */
1246 sms->sender = subscr_get_by_id(gsmnet, 1);
1247 sms->reply_path_req = 0;
1248 sms->status_rep_req = 0;
1249 sms->ud_hdr_ind = 0;
1250 sms->protocol_id = 0; /* implicit */
1251 sms->data_coding_scheme = 0; /* default 7bit */
1252 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1253 /* Generate user_data */
1254 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1255
Harald Welte948bba82009-08-13 00:57:31 +02001256 return sms;
1257}
1258
1259static int _send_sms_buffer(struct gsm_subscriber *receiver,
1260 struct buffer *b)
1261{
1262 struct gsm_sms *sms;
1263
1264 sms = sms_from_text(receiver, buffer_getstr(b));
1265
Harald Welte (local)ddf83b22009-08-13 13:25:32 +02001266 gsm411_send_sms_subscr(receiver, sms);
Harald Welte684b9752009-08-09 15:13:54 +02001267
1268 return CMD_SUCCESS;
1269}
1270
Harald Welte68b7df22009-08-08 16:03:15 +02001271DEFUN(sms_send_ext,
1272 sms_send_ext_cmd,
1273 "sms send extension EXTEN .LINE",
1274 "Send a message to a subscriber identified by EXTEN")
1275{
Harald Welte684b9752009-08-09 15:13:54 +02001276 struct gsm_subscriber *receiver;
1277 struct buffer *b;
1278 int rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001279
Harald Welte684b9752009-08-09 15:13:54 +02001280 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1281 if (!receiver)
1282 return CMD_WARNING;
Harald Welte68b7df22009-08-08 16:03:15 +02001283
Harald Welte684b9752009-08-09 15:13:54 +02001284 b = argv_to_buffer(argc, argv, 1);
1285 rc = _send_sms_buffer(receiver, b);
1286 buffer_free(b);
1287
1288 return rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001289}
1290
1291DEFUN(sms_send_imsi,
1292 sms_send_imsi_cmd,
1293 "sms send imsi IMSI .LINE",
1294 "Send a message to a subscriber identified by IMSI")
1295{
Harald Welte684b9752009-08-09 15:13:54 +02001296 struct gsm_subscriber *receiver;
1297 struct buffer *b;
1298 int rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001299
Harald Welte684b9752009-08-09 15:13:54 +02001300 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1301 if (!receiver)
1302 return CMD_WARNING;
Harald Welte68b7df22009-08-08 16:03:15 +02001303
Harald Welte684b9752009-08-09 15:13:54 +02001304 b = argv_to_buffer(argc, argv, 1);
1305 rc = _send_sms_buffer(receiver, b);
1306 buffer_free(b);
1307
1308 return rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001309}
1310
1311
Harald Welte59b04682009-06-10 05:40:52 +08001312DEFUN(cfg_subscr_name,
1313 cfg_subscr_name_cmd,
1314 "name NAME",
1315 "Set the name of the subscriber")
1316{
1317 const char *name = argv[0];
1318 struct gsm_subscriber *subscr = vty->index;
1319
1320 strncpy(subscr->name, name, sizeof(subscr->name));
1321
1322 db_sync_subscriber(subscr);
1323
1324 return CMD_SUCCESS;
1325}
1326
1327DEFUN(cfg_subscr_extension,
1328 cfg_subscr_extension_cmd,
1329 "extension EXTENSION",
1330 "Set the extension of the subscriber")
1331{
1332 const char *name = argv[0];
1333 struct gsm_subscriber *subscr = vty->index;
1334
1335 strncpy(subscr->extension, name, sizeof(subscr->extension));
1336
1337 db_sync_subscriber(subscr);
1338
1339 return CMD_SUCCESS;
1340}
1341
1342DEFUN(cfg_subscr_authorized,
1343 cfg_subscr_authorized_cmd,
1344 "auth <0-1>",
1345 "Set the authorization status of the subscriber")
1346{
1347 int auth = atoi(argv[0]);
1348 struct gsm_subscriber *subscr = vty->index;
1349
1350 if (auth)
1351 subscr->authorized = 1;
1352 else
1353 subscr->authorized = 0;
1354
1355 db_sync_subscriber(subscr);
1356
1357 return CMD_SUCCESS;
1358}
1359
1360int bsc_vty_init(struct gsm_network *net)
1361{
1362 gsmnet = net;
1363
1364 cmd_init(1);
1365 vty_init();
1366
1367 install_element(VIEW_NODE, &show_net_cmd);
1368 install_element(VIEW_NODE, &show_bts_cmd);
1369 install_element(VIEW_NODE, &show_trx_cmd);
1370 install_element(VIEW_NODE, &show_ts_cmd);
1371 install_element(VIEW_NODE, &show_lchan_cmd);
1372
1373 install_element(VIEW_NODE, &show_e1drv_cmd);
1374 install_element(VIEW_NODE, &show_e1line_cmd);
1375 install_element(VIEW_NODE, &show_e1ts_cmd);
1376
1377 install_element(VIEW_NODE, &show_paging_cmd);
1378
1379 install_element(VIEW_NODE, &show_subscr_cmd);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +02001380 install_element(VIEW_NODE, &show_subscr_cache_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001381
Harald Welte68b7df22009-08-08 16:03:15 +02001382 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte68b7df22009-08-08 16:03:15 +02001383 install_element(VIEW_NODE, &sms_send_ext_cmd);
1384 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte68b7df22009-08-08 16:03:15 +02001385
Harald Weltee87eb462009-08-07 13:29:14 +02001386 install_element(CONFIG_NODE, &cfg_net_cmd);
1387 install_node(&net_node, config_write_net);
1388 install_default(GSMNET_NODE);
Harald Welte62868882009-08-08 16:12:58 +02001389 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001390 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1391 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1392 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001393 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001394
1395 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte97ceef92009-08-06 19:06:46 +02001396 install_node(&bts_node, config_write_bts);
Harald Welte59b04682009-06-10 05:40:52 +08001397 install_default(BTS_NODE);
1398 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Welte91afe4c2009-06-20 18:15:19 +02001399 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001400 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1401 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001402 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001403 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001404 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1405 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001406 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001407 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001408 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001409
Harald Welte59b04682009-06-10 05:40:52 +08001410
1411 install_element(BTS_NODE, &cfg_trx_cmd);
1412 install_node(&trx_node, dummy_config_write);
1413 install_default(TRX_NODE);
1414 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte7f597bc2009-06-20 22:36:12 +02001415 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001416 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1417 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001418
1419 install_element(TRX_NODE, &cfg_ts_cmd);
1420 install_node(&ts_node, dummy_config_write);
1421 install_default(TS_NODE);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001422 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1423 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001424
1425 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1426 install_node(&subscr_node, dummy_config_write);
1427 install_default(SUBSCR_NODE);
1428 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1429 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1430 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1431
1432 return 0;
1433}