blob: 2c0c5583a6afd7a891edbe48e7d6bd7d76cf143c [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 Welte (local)b6ea7f72009-08-14 23:09:25 +0200237 if (bts->chan_desc.t3212)
238 vty_out(vty, " periodic location update %u%s",
239 bts->chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte3e774612009-08-10 13:48:16 +0200240 vty_out(vty, " channel allocator %s%s",
241 bts->chan_alloc_reverse ? "descending" : "ascending",
242 VTY_NEWLINE);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200243 if (bts->cell_barred)
244 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Welte3ffe1b32009-08-07 00:25:23 +0200245 if (is_ipaccess_bts(bts))
Harald Weltee87eb462009-08-07 13:29:14 +0200246 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Welte3ffe1b32009-08-07 00:25:23 +0200247 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200248 else {
249 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
250 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
251 }
Harald Welte97ceef92009-08-06 19:06:46 +0200252
253 llist_for_each_entry(trx, &bts->trx_list, list)
254 config_write_trx_single(vty, trx);
255}
256
257static int config_write_bts(struct vty *v)
258{
259 struct gsm_bts *bts;
260
261 llist_for_each_entry(bts, &gsmnet->bts_list, list)
262 config_write_bts_single(v, bts);
263
264 return CMD_SUCCESS;
265}
266
Harald Weltee87eb462009-08-07 13:29:14 +0200267static int config_write_net(struct vty *vty)
268{
269 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200270 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200271 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte62868882009-08-08 16:12:58 +0200272 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
273 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200274 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Weltee87eb462009-08-07 13:29:14 +0200275
276 return CMD_SUCCESS;
277}
Harald Welte97ceef92009-08-06 19:06:46 +0200278
Harald Welte59b04682009-06-10 05:40:52 +0800279static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
280{
281 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
282 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Welte91afe4c2009-06-20 18:15:19 +0200283 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte62868882009-08-08 16:12:58 +0200284 "resulting BS power: %d dBm%s",
Harald Welte91afe4c2009-06-20 18:15:19 +0200285 trx->nominal_power, trx->max_power_red,
Harald Welte62868882009-08-08 16:12:58 +0200286 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800287 vty_out(vty, " NM State: ");
288 net_dump_nmstate(vty, &trx->nm_state);
289 vty_out(vty, " Baseband Transceiver NM State: ");
290 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
291 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
292 e1isl_dump_vty(vty, trx->rsl_link);
293}
294
295DEFUN(show_trx,
296 show_trx_cmd,
297 "show trx [bts_nr] [trx_nr]",
298 SHOW_STR "Display information about a TRX\n")
299{
300 struct gsm_network *net = gsmnet;
301 struct gsm_bts *bts = NULL;
302 struct gsm_bts_trx *trx;
303 int bts_nr, trx_nr;
304
305 if (argc >= 1) {
306 /* use the BTS number that the user has specified */
307 bts_nr = atoi(argv[0]);
308 if (bts_nr >= net->num_bts) {
309 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
310 VTY_NEWLINE);
311 return CMD_WARNING;
312 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200313 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800314 }
315 if (argc >= 2) {
316 trx_nr = atoi(argv[1]);
317 if (trx_nr >= bts->num_trx) {
318 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
319 VTY_NEWLINE);
320 return CMD_WARNING;
321 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200322 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800323 trx_dump_vty(vty, trx);
324 return CMD_SUCCESS;
325 }
326 if (bts) {
327 /* print all TRX in this BTS */
328 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200329 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800330 trx_dump_vty(vty, trx);
331 }
332 return CMD_SUCCESS;
333 }
334
335 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200336 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800337 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200338 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800339 trx_dump_vty(vty, trx);
340 }
341 }
342
343 return CMD_SUCCESS;
344}
345
Harald Welte97ceef92009-08-06 19:06:46 +0200346
Harald Welte59b04682009-06-10 05:40:52 +0800347static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
348{
349 struct in_addr ia;
350
351 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
352 ts->nr, ts->trx->nr, ts->trx->bts->nr,
353 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
354 vty_out(vty, " NM State: ");
355 net_dump_nmstate(vty, &ts->nm_state);
356 if (is_ipaccess_bts(ts->trx->bts)) {
357 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte8cdeaad2009-07-12 09:50:35 +0200358 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte59b04682009-06-10 05:40:52 +0800359 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte8cdeaad2009-07-12 09:50:35 +0200360 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte59b04682009-06-10 05:40:52 +0800361 VTY_NEWLINE);
362 } else {
363 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
364 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
365 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
366 }
367}
368
369DEFUN(show_ts,
370 show_ts_cmd,
371 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
372 SHOW_STR "Display information about a TS\n")
373{
374 struct gsm_network *net = gsmnet;
375 struct gsm_bts *bts;
376 struct gsm_bts_trx *trx;
377 struct gsm_bts_trx_ts *ts;
378 int bts_nr, trx_nr, ts_nr;
379
380 if (argc >= 1) {
381 /* use the BTS number that the user has specified */
382 bts_nr = atoi(argv[0]);
383 if (bts_nr >= net->num_bts) {
384 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
385 VTY_NEWLINE);
386 return CMD_WARNING;
387 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200388 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800389 }
390 if (argc >= 2) {
391 trx_nr = atoi(argv[1]);
392 if (trx_nr >= bts->num_trx) {
393 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
394 VTY_NEWLINE);
395 return CMD_WARNING;
396 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200397 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800398 }
399 if (argc >= 3) {
400 ts_nr = atoi(argv[2]);
401 if (ts_nr >= TRX_NR_TS) {
402 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
403 VTY_NEWLINE);
404 return CMD_WARNING;
405 }
406 ts = &trx->ts[ts_nr];
407 ts_dump_vty(vty, ts);
408 return CMD_SUCCESS;
409 }
410 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200411 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800412 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200413 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800414 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
415 ts = &trx->ts[ts_nr];
416 ts_dump_vty(vty, ts);
417 }
418 }
419 }
420
421 return CMD_SUCCESS;
422}
423
424static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
425{
Harald Welte91afe4c2009-06-20 18:15:19 +0200426 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte59b04682009-06-10 05:40:52 +0800427 subscr->authorized, VTY_NEWLINE);
428 if (subscr->name)
429 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
430 if (subscr->extension)
431 vty_out(vty, " Extension: %s%s", subscr->extension,
432 VTY_NEWLINE);
433 if (subscr->imsi)
434 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
435 if (subscr->tmsi)
Harald Welte270c06c2009-08-15 03:24:51 +0200436 vty_out(vty, " TMSI: %08X%s", atoi(subscr->tmsi),
437 VTY_NEWLINE);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +0200438 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800439}
440
441static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
442{
443 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
444 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
445 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
446 VTY_NEWLINE);
447 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
448 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
449 lchan->ms_power, VTY_NEWLINE);
450 if (lchan->subscr) {
451 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
452 subscr_dump_vty(vty, lchan->subscr);
453 } else
454 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
455}
456
Harald Welte03740842009-06-10 23:11:52 +0800457#if 0
458TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte59b04682009-06-10 05:40:52 +0800459static void call_dump_vty(struct vty *vty, struct gsm_call *call)
460{
461 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
462 call->type, call->state, call->transaction_id, VTY_NEWLINE);
463
464 if (call->local_lchan) {
465 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
466 lchan_dump_vty(vty, call->local_lchan);
467 } else
468 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
469
470 if (call->remote_lchan) {
471 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
472 lchan_dump_vty(vty, call->remote_lchan);
473 } else
474 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
475
476 if (call->called_subscr) {
477 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
478 subscr_dump_vty(vty, call->called_subscr);
479 } else
480 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
481}
Harald Welte03740842009-06-10 23:11:52 +0800482#endif
Harald Welte59b04682009-06-10 05:40:52 +0800483
484DEFUN(show_lchan,
485 show_lchan_cmd,
486 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
487 SHOW_STR "Display information about a logical channel\n")
488{
489 struct gsm_network *net = gsmnet;
490 struct gsm_bts *bts;
491 struct gsm_bts_trx *trx;
492 struct gsm_bts_trx_ts *ts;
493 struct gsm_lchan *lchan;
494 int bts_nr, trx_nr, ts_nr, lchan_nr;
495
496 if (argc >= 1) {
497 /* use the BTS number that the user has specified */
498 bts_nr = atoi(argv[0]);
499 if (bts_nr >= net->num_bts) {
500 vty_out(vty, "%% can't find BTS %s%s", argv[0],
501 VTY_NEWLINE);
502 return CMD_WARNING;
503 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200504 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800505 }
506 if (argc >= 2) {
507 trx_nr = atoi(argv[1]);
508 if (trx_nr >= bts->num_trx) {
509 vty_out(vty, "%% can't find TRX %s%s", argv[1],
510 VTY_NEWLINE);
511 return CMD_WARNING;
512 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200513 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800514 }
515 if (argc >= 3) {
516 ts_nr = atoi(argv[2]);
517 if (ts_nr >= TRX_NR_TS) {
518 vty_out(vty, "%% can't find TS %s%s", argv[2],
519 VTY_NEWLINE);
520 return CMD_WARNING;
521 }
522 ts = &trx->ts[ts_nr];
523 }
524 if (argc >= 4) {
525 lchan_nr = atoi(argv[3]);
526 if (lchan_nr >= TS_MAX_LCHAN) {
527 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
528 VTY_NEWLINE);
529 return CMD_WARNING;
530 }
531 lchan = &ts->lchan[lchan_nr];
532 lchan_dump_vty(vty, lchan);
533 return CMD_SUCCESS;
534 }
535 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200536 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800537 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200538 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800539 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
540 ts = &trx->ts[ts_nr];
541 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
542 lchan_nr++) {
543 lchan = &ts->lchan[lchan_nr];
544 if (lchan->type == GSM_LCHAN_NONE)
545 continue;
546 lchan_dump_vty(vty, lchan);
547 }
548 }
549 }
550 }
551
552 return CMD_SUCCESS;
553}
554
555static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
556{
557 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
558}
559
560DEFUN(show_e1drv,
561 show_e1drv_cmd,
562 "show e1_driver",
563 SHOW_STR "Display information about available E1 drivers\n")
564{
565 struct e1inp_driver *drv;
566
567 llist_for_each_entry(drv, &e1inp_driver_list, list)
568 e1drv_dump_vty(vty, drv);
569
570 return CMD_SUCCESS;
571}
572
573static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
574{
575 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
576 line->num, line->name ? line->name : "",
577 line->driver->name, VTY_NEWLINE);
578}
579
580DEFUN(show_e1line,
581 show_e1line_cmd,
582 "show e1_line [line_nr]",
583 SHOW_STR "Display information about a E1 line\n")
584{
585 struct e1inp_line *line;
586
587 if (argc >= 1) {
588 int num = atoi(argv[0]);
589 llist_for_each_entry(line, &e1inp_line_list, list) {
590 if (line->num == num) {
591 e1line_dump_vty(vty, line);
592 return CMD_SUCCESS;
593 }
594 }
595 return CMD_WARNING;
596 }
597
598 llist_for_each_entry(line, &e1inp_line_list, list)
599 e1line_dump_vty(vty, line);
600
601 return CMD_SUCCESS;
602}
603
604static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
605{
Harald Welte62868882009-08-08 16:12:58 +0200606 if (ts->type == E1INP_TS_TYPE_NONE)
607 return;
Harald Welte59b04682009-06-10 05:40:52 +0800608 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
609 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
610 VTY_NEWLINE);
611}
612
613DEFUN(show_e1ts,
614 show_e1ts_cmd,
615 "show e1_timeslot [line_nr] [ts_nr]",
616 SHOW_STR "Display information about a E1 timeslot\n")
617{
618 struct e1inp_line *line;
619 struct e1inp_ts *ts;
620 int ts_nr;
621
622 if (argc == 0) {
623 llist_for_each_entry(line, &e1inp_line_list, list) {
624 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
625 ts = &line->ts[ts_nr];
626 e1ts_dump_vty(vty, ts);
627 }
628 }
629 return CMD_SUCCESS;
630 }
631 if (argc >= 1) {
632 int num = atoi(argv[0]);
633 llist_for_each_entry(line, &e1inp_line_list, list) {
634 if (line->num == num)
635 break;
636 }
637 if (!line || line->num != num) {
638 vty_out(vty, "E1 line %s is invalid%s",
639 argv[0], VTY_NEWLINE);
640 return CMD_WARNING;
641 }
642 }
643 if (argc >= 2) {
644 ts_nr = atoi(argv[1]);
645 if (ts_nr > NUM_E1_TS) {
646 vty_out(vty, "E1 timeslot %s is invalid%s",
647 argv[1], VTY_NEWLINE);
648 return CMD_WARNING;
649 }
650 ts = &line->ts[ts_nr];
651 e1ts_dump_vty(vty, ts);
652 return CMD_SUCCESS;
653 } else {
654 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
655 ts = &line->ts[ts_nr];
656 e1ts_dump_vty(vty, ts);
657 }
658 return CMD_SUCCESS;
659 }
660 return CMD_SUCCESS;
661}
662
663static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
664{
665 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
666 subscr_dump_vty(vty, pag->subscr);
667}
668
669static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
670{
671 struct gsm_paging_request *pag;
672
673 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
674 paging_dump_vty(vty, pag);
675}
676
677DEFUN(show_paging,
678 show_paging_cmd,
679 "show paging [bts_nr]",
680 SHOW_STR "Display information about paging reuqests of a BTS\n")
681{
682 struct gsm_network *net = gsmnet;
683 struct gsm_bts *bts;
684 int bts_nr;
685
686 if (argc >= 1) {
687 /* use the BTS number that the user has specified */
688 bts_nr = atoi(argv[0]);
689 if (bts_nr >= net->num_bts) {
690 vty_out(vty, "%% can't find BTS %s%s", argv[0],
691 VTY_NEWLINE);
692 return CMD_WARNING;
693 }
Harald Weltee712a5f2009-06-21 16:17:15 +0200694 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800695 bts_paging_dump_vty(vty, bts);
696
697 return CMD_SUCCESS;
698 }
699 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200700 bts = gsm_bts_num(net, bts_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800701 bts_paging_dump_vty(vty, bts);
702 }
703
704 return CMD_SUCCESS;
705}
706
707/* per-subscriber configuration */
708DEFUN(cfg_subscr,
709 cfg_subscr_cmd,
710 "subscriber IMSI",
711 "Select a Subscriber to configure\n")
712{
713 const char *imsi = argv[0];
714 struct gsm_subscriber *subscr;
715
Harald Welteaae7a522009-07-23 19:21:02 +0200716 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte59b04682009-06-10 05:40:52 +0800717 if (!subscr) {
718 vty_out(vty, "%% No subscriber for IMSI %s%s",
719 imsi, VTY_NEWLINE);
720 return CMD_WARNING;
721 }
722
723 vty->index = subscr;
724 vty->node = SUBSCR_NODE;
725
726 return CMD_SUCCESS;
727}
728
Harald Weltee87eb462009-08-07 13:29:14 +0200729DEFUN(cfg_net,
730 cfg_net_cmd,
731 "network",
732 "Configure the GSM network")
733{
734 vty->index = gsmnet;
735 vty->node = GSMNET_NODE;
736
737 return CMD_SUCCESS;
738}
739
740
741DEFUN(cfg_net_ncc,
742 cfg_net_ncc_cmd,
743 "network country code <1-999>",
744 "Set the GSM network country code")
745{
746 gsmnet->country_code = atoi(argv[0]);
747
748 return CMD_SUCCESS;
749}
750
751DEFUN(cfg_net_mnc,
752 cfg_net_mnc_cmd,
753 "mobile network code <1-999>",
754 "Set the GSM mobile network code")
755{
756 gsmnet->network_code = atoi(argv[0]);
757
758 return CMD_SUCCESS;
759}
760
761DEFUN(cfg_net_name_short,
762 cfg_net_name_short_cmd,
763 "short name NAME",
764 "Set the short GSM network name")
765{
766 if (gsmnet->name_short)
767 talloc_free(gsmnet->name_short);
768
769 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
770
771 return CMD_SUCCESS;
772}
773
774DEFUN(cfg_net_name_long,
775 cfg_net_name_long_cmd,
776 "long name NAME",
777 "Set the long GSM network name")
778{
779 if (gsmnet->name_long)
780 talloc_free(gsmnet->name_long);
781
782 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
783
784 return CMD_SUCCESS;
785}
Harald Welte59b04682009-06-10 05:40:52 +0800786
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200787DEFUN(cfg_net_auth_policy,
788 cfg_net_auth_policy_cmd,
789 "auth policy (closed|accept-all|token)",
790 "Set the GSM network authentication policy\n")
791{
792 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
793
794 gsmnet->auth_policy = policy;
795
796 return CMD_SUCCESS;
797}
798
Harald Welte59b04682009-06-10 05:40:52 +0800799/* per-BTS configuration */
800DEFUN(cfg_bts,
801 cfg_bts_cmd,
802 "bts BTS_NR",
803 "Select a BTS to configure\n")
804{
805 int bts_nr = atoi(argv[0]);
806 struct gsm_bts *bts;
807
Harald Weltee712a5f2009-06-21 16:17:15 +0200808 if (bts_nr > gsmnet->num_bts) {
809 vty_out(vty, "%% The next unused BTS number is %u%s",
810 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +0800811 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +0200812 } else if (bts_nr == gsmnet->num_bts) {
813 /* allocate a new one */
814 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
815 HARDCODED_TSC, HARDCODED_BSIC);
816 } else
817 bts = gsm_bts_num(gsmnet, bts_nr);
818
819 if (!bts)
820 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +0800821
822 vty->index = bts;
823 vty->node = BTS_NODE;
824
825 return CMD_SUCCESS;
826}
827
828DEFUN(cfg_bts_type,
829 cfg_bts_type_cmd,
830 "type TYPE",
831 "Set the BTS type\n")
832{
833 struct gsm_bts *bts = vty->index;
834
Harald Welte3ffe1b32009-08-07 00:25:23 +0200835 bts->type = parse_btstype(argv[0]);
836
Harald Welte59b04682009-06-10 05:40:52 +0800837 return CMD_SUCCESS;
838}
839
Harald Welte91afe4c2009-06-20 18:15:19 +0200840DEFUN(cfg_bts_band,
841 cfg_bts_band_cmd,
842 "band BAND",
843 "Set the frequency band of this BTS\n")
844{
845 struct gsm_bts *bts = vty->index;
Harald Welte62868882009-08-08 16:12:58 +0200846 int band = gsm_band_parse(argv[0]);
Harald Welte91afe4c2009-06-20 18:15:19 +0200847
848 if (band < 0) {
849 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
850 band, VTY_NEWLINE);
851 return CMD_WARNING;
852 }
853
854 bts->band = band;
855
856 return CMD_SUCCESS;
857}
858
Harald Welte59b04682009-06-10 05:40:52 +0800859DEFUN(cfg_bts_lac,
860 cfg_bts_lac_cmd,
861 "location_area_code <0-255>",
862 "Set the Location Area Code (LAC) of this BTS\n")
863{
864 struct gsm_bts *bts = vty->index;
865 int lac = atoi(argv[0]);
866
867 if (lac < 0 || lac > 0xff) {
868 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
869 lac, VTY_NEWLINE);
870 return CMD_WARNING;
871 }
872 bts->location_area_code = lac;
873
874 return CMD_SUCCESS;
875}
876
877DEFUN(cfg_bts_tsc,
878 cfg_bts_tsc_cmd,
879 "training_sequence_code <0-255>",
880 "Set the Training Sequence Code (TSC) of this BTS\n")
881{
882 struct gsm_bts *bts = vty->index;
883 int tsc = atoi(argv[0]);
884
885 if (tsc < 0 || tsc > 0xff) {
886 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
887 tsc, VTY_NEWLINE);
888 return CMD_WARNING;
889 }
890 bts->tsc = tsc;
891
892 return CMD_SUCCESS;
893}
894
895DEFUN(cfg_bts_bsic,
896 cfg_bts_bsic_cmd,
897 "base_station_id_code <0-63>",
898 "Set the Base Station Identity Code (BSIC) of this BTS\n")
899{
900 struct gsm_bts *bts = vty->index;
901 int bsic = atoi(argv[0]);
902
903 if (bsic < 0 || bsic > 0x3f) {
Harald Welte62868882009-08-08 16:12:58 +0200904 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte59b04682009-06-10 05:40:52 +0800905 bsic, VTY_NEWLINE);
906 return CMD_WARNING;
907 }
908 bts->bsic = bsic;
909
910 return CMD_SUCCESS;
911}
912
913
914DEFUN(cfg_bts_unit_id,
915 cfg_bts_unit_id_cmd,
Harald Weltef515aa02009-08-07 13:27:09 +0200916 "ip.access unit_id <0-65534> <0-255>",
917 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte59b04682009-06-10 05:40:52 +0800918{
919 struct gsm_bts *bts = vty->index;
920 int site_id = atoi(argv[0]);
921 int bts_id = atoi(argv[1]);
922
Harald Weltef515aa02009-08-07 13:27:09 +0200923 if (!is_ipaccess_bts(bts)) {
924 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
925 return CMD_WARNING;
926 }
927
Harald Welte59b04682009-06-10 05:40:52 +0800928 bts->ip_access.site_id = site_id;
929 bts->ip_access.bts_id = bts_id;
930
931 return CMD_SUCCESS;
932}
933
Harald Welte62868882009-08-08 16:12:58 +0200934DEFUN(cfg_bts_oml_e1,
935 cfg_bts_oml_e1_cmd,
936 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
937 "E1 interface to be used for OML\n")
938{
939 struct gsm_bts *bts = vty->index;
940
941 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
942
943 return CMD_SUCCESS;
944}
945
946
947DEFUN(cfg_bts_oml_e1_tei,
948 cfg_bts_oml_e1_tei_cmd,
949 "oml e1 tei <0-63>",
950 "Set the TEI to be used for OML")
951{
952 struct gsm_bts *bts = vty->index;
953
954 bts->oml_tei = atoi(argv[0]);
955
956 return CMD_SUCCESS;
957}
958
Harald Welte3e774612009-08-10 13:48:16 +0200959DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
960 "channel allocator (ascending|descending)",
961 "Should the channel allocator allocate in reverse TRX order?")
962{
963 struct gsm_bts *bts = vty->index;
964
965 if (!strcmp(argv[0], "ascending"))
966 bts->chan_alloc_reverse = 0;
967 else
968 bts->chan_alloc_reverse = 1;
969
970 return CMD_SUCCESS;
971}
972
Harald Welte (local)e19be3f2009-08-12 13:28:23 +0200973DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
974 "cell barred (0|1)",
975 "Should this cell be barred from access?")
976{
977 struct gsm_bts *bts = vty->index;
978
979 bts->cell_barred = atoi(argv[0]);
980
981 return CMD_SUCCESS;
982}
983
Harald Welte (local)cbd46102009-08-13 10:14:26 +0200984DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
985 "ms max power <0-40>",
986 "Maximum transmit power of the MS")
987{
988 struct gsm_bts *bts = vty->index;
989
990 bts->ms_max_power = atoi(argv[0]);
991
992 return CMD_SUCCESS;
993}
994
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +0200995DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
996 "periodic location update <0-1530>",
997 "Periodic Location Updating Interval in Minutes")
998{
999 struct gsm_bts *bts = vty->index;
1000
1001 bts->chan_desc.t3212 = atoi(argv[0]) / 10;
1002
1003 return CMD_SUCCESS;
1004}
1005
Harald Welte3e774612009-08-10 13:48:16 +02001006
Harald Welte59b04682009-06-10 05:40:52 +08001007/* per TRX configuration */
1008DEFUN(cfg_trx,
1009 cfg_trx_cmd,
1010 "trx TRX_NR",
1011 "Select a TRX to configure")
1012{
1013 int trx_nr = atoi(argv[0]);
1014 struct gsm_bts *bts = vty->index;
1015 struct gsm_bts_trx *trx;
1016
Harald Weltee712a5f2009-06-21 16:17:15 +02001017 if (trx_nr > bts->num_trx) {
1018 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1019 bts->num_trx, VTY_NEWLINE);
Harald Welte59b04682009-06-10 05:40:52 +08001020 return CMD_WARNING;
Harald Weltee712a5f2009-06-21 16:17:15 +02001021 } else if (trx_nr == bts->num_trx) {
1022 /* we need to allocate a new one */
1023 trx = gsm_bts_trx_alloc(bts);
1024 } else
1025 trx = gsm_bts_trx_num(bts, trx_nr);
1026
1027 if (!trx)
1028 return CMD_WARNING;
Harald Welte59b04682009-06-10 05:40:52 +08001029
1030 vty->index = trx;
1031 vty->node = TRX_NODE;
1032
1033 return CMD_SUCCESS;
1034}
1035
1036DEFUN(cfg_trx_arfcn,
1037 cfg_trx_arfcn_cmd,
1038 "arfcn <1-1024>",
1039 "Set the ARFCN for this TRX\n")
1040{
1041 int arfcn = atoi(argv[0]);
1042 struct gsm_bts_trx *trx = vty->index;
1043
1044 /* FIXME: check if this ARFCN is supported by this TRX */
1045
1046 trx->arfcn = arfcn;
1047
1048 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1049 /* FIXME: use OML layer to update the ARFCN */
1050 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1051
1052 return CMD_SUCCESS;
1053}
1054
Harald Welte91afe4c2009-06-20 18:15:19 +02001055DEFUN(cfg_trx_max_power_red,
1056 cfg_trx_max_power_red_cmd,
1057 "max_power_red <0-100>",
1058 "Reduction of maximum BS RF Power in dB\n")
1059{
1060 int maxpwr_r = atoi(argv[0]);
1061 struct gsm_bts_trx *trx = vty->index;
1062 int upper_limit = 12; /* default 12.21 max power red. */
1063
1064 /* FIXME: check if our BTS type supports more than 12 */
1065 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1066 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1067 maxpwr_r, VTY_NEWLINE);
1068 return CMD_WARNING;
1069 }
1070 if (maxpwr_r & 1) {
1071 vty_out(vty, "%% Power %d dB is not an even value%s",
1072 maxpwr_r, VTY_NEWLINE);
1073 return CMD_WARNING;
1074 }
1075
1076 trx->max_power_red = maxpwr_r;
1077
1078 /* FIXME: make sure we update this using OML */
1079
1080 return CMD_SUCCESS;
1081}
1082
Harald Welte62868882009-08-08 16:12:58 +02001083DEFUN(cfg_trx_rsl_e1,
1084 cfg_trx_rsl_e1_cmd,
1085 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1086 "E1 interface to be used for RSL\n")
1087{
1088 struct gsm_bts_trx *trx = vty->index;
1089
1090 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1091
1092 return CMD_SUCCESS;
1093}
1094
1095DEFUN(cfg_trx_rsl_e1_tei,
1096 cfg_trx_rsl_e1_tei_cmd,
1097 "rsl e1 tei <0-63>",
1098 "Set the TEI to be used for RSL")
1099{
1100 struct gsm_bts_trx *trx = vty->index;
1101
1102 trx->rsl_tei = atoi(argv[0]);
1103
1104 return CMD_SUCCESS;
1105}
1106
1107
Harald Welte59b04682009-06-10 05:40:52 +08001108/* per TS configuration */
1109DEFUN(cfg_ts,
1110 cfg_ts_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001111 "timeslot <0-7>",
Harald Welte59b04682009-06-10 05:40:52 +08001112 "Select a Timeslot to configure")
1113{
1114 int ts_nr = atoi(argv[0]);
1115 struct gsm_bts_trx *trx = vty->index;
1116 struct gsm_bts_trx_ts *ts;
1117
1118 if (ts_nr >= TRX_NR_TS) {
1119 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1120 TRX_NR_TS, VTY_NEWLINE);
1121 return CMD_WARNING;
1122 }
1123
1124 ts = &trx->ts[ts_nr];
1125
1126 vty->index = ts;
1127 vty->node = TS_NODE;
1128
1129 return CMD_SUCCESS;
1130}
1131
Harald Welte3ffe1b32009-08-07 00:25:23 +02001132DEFUN(cfg_ts_pchan,
1133 cfg_ts_pchan_cmd,
1134 "phys_chan_config PCHAN",
1135 "Physical Channel configuration (TCH/SDCCH/...)")
1136{
1137 struct gsm_bts_trx_ts *ts = vty->index;
1138 int pchanc;
1139
1140 pchanc = gsm_pchan_parse(argv[0]);
1141 if (pchanc < 0)
1142 return CMD_WARNING;
1143
1144 ts->pchan = pchanc;
1145
1146 return CMD_SUCCESS;
1147}
1148
1149DEFUN(cfg_ts_e1_subslot,
1150 cfg_ts_e1_subslot_cmd,
Harald Welte62868882009-08-08 16:12:58 +02001151 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Welte3ffe1b32009-08-07 00:25:23 +02001152 "E1 sub-slot connected to this on-air timeslot")
1153{
1154 struct gsm_bts_trx_ts *ts = vty->index;
1155
Harald Welte62868882009-08-08 16:12:58 +02001156 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001157
1158 return CMD_SUCCESS;
1159}
Harald Welte59b04682009-06-10 05:40:52 +08001160
1161/* Subscriber */
1162DEFUN(show_subscr,
1163 show_subscr_cmd,
1164 "show subscriber [IMSI]",
1165 SHOW_STR "Display information about a subscriber\n")
1166{
1167 const char *imsi;
1168 struct gsm_subscriber *subscr;
1169
1170 if (argc >= 1) {
1171 imsi = argv[0];
Harald Welteaae7a522009-07-23 19:21:02 +02001172 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte59b04682009-06-10 05:40:52 +08001173 if (!subscr) {
1174 vty_out(vty, "%% unknown subscriber%s",
1175 VTY_NEWLINE);
1176 return CMD_WARNING;
1177 }
1178 subscr_dump_vty(vty, subscr);
1179
1180 return CMD_SUCCESS;
1181 }
1182
1183 /* FIXME: iterate over all subscribers ? */
1184 return CMD_WARNING;
1185
1186 return CMD_SUCCESS;
1187}
1188
Harald Welte (local)02d5efa2009-08-14 20:27:16 +02001189DEFUN(show_subscr_cache,
1190 show_subscr_cache_cmd,
1191 "show subscriber cache",
1192 SHOW_STR "Display contents of subscriber cache\n")
1193{
1194 struct gsm_subscriber *subscr;
1195
1196 llist_for_each_entry(subscr, &active_subscribers, entry) {
1197 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
1198 subscr_dump_vty(vty, subscr);
1199 }
1200
1201 return CMD_SUCCESS;
1202}
1203
Harald Welte68b7df22009-08-08 16:03:15 +02001204DEFUN(sms_send_pend,
1205 sms_send_pend_cmd,
1206 "sms send pending MIN_ID",
1207 "Send all pending SMS starting from MIN_ID")
1208{
1209 struct gsm_sms *sms;
Harald Welte (local)5be45322009-08-14 16:01:20 +02001210 int id = atoi(argv[0]);
Harald Welte68b7df22009-08-08 16:03:15 +02001211
Harald Welte (local)5be45322009-08-14 16:01:20 +02001212 while (1) {
1213 sms = db_sms_get_unsent(gsmnet, id++);
1214 if (!sms)
1215 return CMD_WARNING;
Harald Welte68b7df22009-08-08 16:03:15 +02001216
Harald Welte (local)5be45322009-08-14 16:01:20 +02001217 if (!sms->receiver) {
1218 sms_free(sms);
1219 continue;
1220 }
1221
1222 gsm411_send_sms_subscr(sms->receiver, sms);
Harald Welte68b7df22009-08-08 16:03:15 +02001223 }
1224
Harald Welte68b7df22009-08-08 16:03:15 +02001225 return CMD_SUCCESS;
1226}
1227
Harald Welte684b9752009-08-09 15:13:54 +02001228static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1229{
1230 struct buffer *b = buffer_new(1024);
1231 int i;
1232
1233 if (!b)
1234 return NULL;
1235
1236 for (i = base; i < argc; i++) {
1237 buffer_putstr(b, argv[i]);
1238 buffer_putc(b, ' ');
1239 }
1240 buffer_putc(b, '\0');
1241
1242 return b;
1243}
1244
Harald Welte948bba82009-08-13 00:57:31 +02001245int sms_from_text(struct gsm_subscriber *receiver, const char *text)
Harald Welte684b9752009-08-09 15:13:54 +02001246{
1247 struct gsm_sms *sms = sms_alloc();
1248
1249 if (!sms)
1250 return CMD_WARNING;
1251
1252 if (!receiver->lac) {
1253 /* subscriber currently not attached, store in database? */
Harald Welte684b9752009-08-09 15:13:54 +02001254 return CMD_WARNING;
1255 }
1256
Harald Welte (local)ddf83b22009-08-13 13:25:32 +02001257 sms->receiver = subscr_get(receiver);
Harald Welte948bba82009-08-13 00:57:31 +02001258 strncpy(sms->text, text, sizeof(sms->text)-1);
Harald Welte684b9752009-08-09 15:13:54 +02001259
1260 /* FIXME: don't use ID 1 static */
1261 sms->sender = subscr_get_by_id(gsmnet, 1);
1262 sms->reply_path_req = 0;
1263 sms->status_rep_req = 0;
1264 sms->ud_hdr_ind = 0;
1265 sms->protocol_id = 0; /* implicit */
1266 sms->data_coding_scheme = 0; /* default 7bit */
1267 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1268 /* Generate user_data */
1269 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1270
Harald Welte948bba82009-08-13 00:57:31 +02001271 return sms;
1272}
1273
1274static int _send_sms_buffer(struct gsm_subscriber *receiver,
1275 struct buffer *b)
1276{
1277 struct gsm_sms *sms;
1278
1279 sms = sms_from_text(receiver, buffer_getstr(b));
1280
Harald Welte (local)ddf83b22009-08-13 13:25:32 +02001281 gsm411_send_sms_subscr(receiver, sms);
Harald Welte684b9752009-08-09 15:13:54 +02001282
1283 return CMD_SUCCESS;
1284}
1285
Harald Welte68b7df22009-08-08 16:03:15 +02001286DEFUN(sms_send_ext,
1287 sms_send_ext_cmd,
1288 "sms send extension EXTEN .LINE",
1289 "Send a message to a subscriber identified by EXTEN")
1290{
Harald Welte684b9752009-08-09 15:13:54 +02001291 struct gsm_subscriber *receiver;
1292 struct buffer *b;
1293 int rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001294
Harald Welte684b9752009-08-09 15:13:54 +02001295 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1296 if (!receiver)
1297 return CMD_WARNING;
Harald Welte68b7df22009-08-08 16:03:15 +02001298
Harald Welte684b9752009-08-09 15:13:54 +02001299 b = argv_to_buffer(argc, argv, 1);
1300 rc = _send_sms_buffer(receiver, b);
1301 buffer_free(b);
1302
1303 return rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001304}
1305
1306DEFUN(sms_send_imsi,
1307 sms_send_imsi_cmd,
1308 "sms send imsi IMSI .LINE",
1309 "Send a message to a subscriber identified by IMSI")
1310{
Harald Welte684b9752009-08-09 15:13:54 +02001311 struct gsm_subscriber *receiver;
1312 struct buffer *b;
1313 int rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001314
Harald Welte684b9752009-08-09 15:13:54 +02001315 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1316 if (!receiver)
1317 return CMD_WARNING;
Harald Welte68b7df22009-08-08 16:03:15 +02001318
Harald Welte684b9752009-08-09 15:13:54 +02001319 b = argv_to_buffer(argc, argv, 1);
1320 rc = _send_sms_buffer(receiver, b);
1321 buffer_free(b);
1322
1323 return rc;
Harald Welte68b7df22009-08-08 16:03:15 +02001324}
1325
1326
Harald Welte59b04682009-06-10 05:40:52 +08001327DEFUN(cfg_subscr_name,
1328 cfg_subscr_name_cmd,
1329 "name NAME",
1330 "Set the name of the subscriber")
1331{
1332 const char *name = argv[0];
1333 struct gsm_subscriber *subscr = vty->index;
1334
1335 strncpy(subscr->name, name, sizeof(subscr->name));
1336
1337 db_sync_subscriber(subscr);
1338
1339 return CMD_SUCCESS;
1340}
1341
1342DEFUN(cfg_subscr_extension,
1343 cfg_subscr_extension_cmd,
1344 "extension EXTENSION",
1345 "Set the extension of the subscriber")
1346{
1347 const char *name = argv[0];
1348 struct gsm_subscriber *subscr = vty->index;
1349
1350 strncpy(subscr->extension, name, sizeof(subscr->extension));
1351
1352 db_sync_subscriber(subscr);
1353
1354 return CMD_SUCCESS;
1355}
1356
1357DEFUN(cfg_subscr_authorized,
1358 cfg_subscr_authorized_cmd,
1359 "auth <0-1>",
1360 "Set the authorization status of the subscriber")
1361{
1362 int auth = atoi(argv[0]);
1363 struct gsm_subscriber *subscr = vty->index;
1364
1365 if (auth)
1366 subscr->authorized = 1;
1367 else
1368 subscr->authorized = 0;
1369
1370 db_sync_subscriber(subscr);
1371
1372 return CMD_SUCCESS;
1373}
1374
1375int bsc_vty_init(struct gsm_network *net)
1376{
1377 gsmnet = net;
1378
1379 cmd_init(1);
1380 vty_init();
1381
1382 install_element(VIEW_NODE, &show_net_cmd);
1383 install_element(VIEW_NODE, &show_bts_cmd);
1384 install_element(VIEW_NODE, &show_trx_cmd);
1385 install_element(VIEW_NODE, &show_ts_cmd);
1386 install_element(VIEW_NODE, &show_lchan_cmd);
1387
1388 install_element(VIEW_NODE, &show_e1drv_cmd);
1389 install_element(VIEW_NODE, &show_e1line_cmd);
1390 install_element(VIEW_NODE, &show_e1ts_cmd);
1391
1392 install_element(VIEW_NODE, &show_paging_cmd);
1393
1394 install_element(VIEW_NODE, &show_subscr_cmd);
Harald Welte (local)02d5efa2009-08-14 20:27:16 +02001395 install_element(VIEW_NODE, &show_subscr_cache_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001396
Harald Welte68b7df22009-08-08 16:03:15 +02001397 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte68b7df22009-08-08 16:03:15 +02001398 install_element(VIEW_NODE, &sms_send_ext_cmd);
1399 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte68b7df22009-08-08 16:03:15 +02001400
Harald Weltee87eb462009-08-07 13:29:14 +02001401 install_element(CONFIG_NODE, &cfg_net_cmd);
1402 install_node(&net_node, config_write_net);
1403 install_default(GSMNET_NODE);
Harald Welte62868882009-08-08 16:12:58 +02001404 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001405 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1406 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1407 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)a59a27e2009-08-12 14:42:23 +02001408 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Weltee87eb462009-08-07 13:29:14 +02001409
1410 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte97ceef92009-08-06 19:06:46 +02001411 install_node(&bts_node, config_write_bts);
Harald Welte59b04682009-06-10 05:40:52 +08001412 install_default(BTS_NODE);
1413 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Welte91afe4c2009-06-20 18:15:19 +02001414 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001415 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1416 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001417 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001418 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001419 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1420 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001421 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)e19be3f2009-08-12 13:28:23 +02001422 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001423 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)b6ea7f72009-08-14 23:09:25 +02001424 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte3e774612009-08-10 13:48:16 +02001425
Harald Welte59b04682009-06-10 05:40:52 +08001426
1427 install_element(BTS_NODE, &cfg_trx_cmd);
1428 install_node(&trx_node, dummy_config_write);
1429 install_default(TRX_NODE);
1430 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte7f597bc2009-06-20 22:36:12 +02001431 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte62868882009-08-08 16:12:58 +02001432 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1433 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001434
1435 install_element(TRX_NODE, &cfg_ts_cmd);
1436 install_node(&ts_node, dummy_config_write);
1437 install_default(TS_NODE);
Harald Welte3ffe1b32009-08-07 00:25:23 +02001438 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1439 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte59b04682009-06-10 05:40:52 +08001440
1441 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1442 install_node(&subscr_node, dummy_config_write);
1443 install_default(SUBSCR_NODE);
1444 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1445 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1446 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1447
1448 return 0;
1449}