blob: 4933bb4e936ff25bc91e3c66794daff1336b6dbb [file] [log] [blame]
Harald Welte68628e82009-03-10 12:17:57 +00001/* OpenBSC interface to quagga VTY */
2/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <stdlib.h>
22#include <unistd.h>
23#include <sys/types.h>
24
25#include <vty/command.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020026#include <vty/buffer.h>
Harald Welte68628e82009-03-10 12:17:57 +000027#include <vty/vty.h>
28
29#include <arpa/inet.h>
30
Harald Welte1bc77352009-03-10 19:47:51 +000031#include <openbsc/linuxlist.h>
Harald Welte68628e82009-03-10 12:17:57 +000032#include <openbsc/gsm_data.h>
33#include <openbsc/gsm_subscriber.h>
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +020034#include <openbsc/gsm_04_11.h>
Harald Welte68628e82009-03-10 12:17:57 +000035#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000036#include <openbsc/abis_nm.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020037#include <openbsc/gsm_utils.h>
Harald Welte40f82892009-05-23 17:31:39 +000038#include <openbsc/db.h>
Harald Welte5013b2a2009-08-07 13:29:14 +020039#include <openbsc/talloc.h>
Harald Welte68628e82009-03-10 12:17:57 +000040
41static struct gsm_network *gsmnet;
42
Harald Welte5013b2a2009-08-07 13:29:14 +020043struct cmd_node net_node = {
44 GSMNET_NODE,
45 "%s(network)#",
46 1,
47};
48
Harald Welte68628e82009-03-10 12:17:57 +000049struct cmd_node bts_node = {
50 BTS_NODE,
51 "%s(bts)#",
52 1,
53};
54
55struct cmd_node trx_node = {
56 TRX_NODE,
57 "%s(trx)#",
58 1,
59};
60
61struct cmd_node ts_node = {
62 TS_NODE,
63 "%s(ts)#",
64 1,
65};
66
Harald Welte40f82892009-05-23 17:31:39 +000067struct cmd_node subscr_node = {
68 SUBSCR_NODE,
69 "%s(subscriber)#",
70 1,
71};
72
Harald Welte68628e82009-03-10 12:17:57 +000073static int dummy_config_write(struct vty *v)
74{
75 return CMD_SUCCESS;
76}
77
78static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
79{
Harald Welte1bc77352009-03-10 19:47:51 +000080 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
81 nm_opstate_name(nms->operational), nms->administrative,
82 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000083}
84
85static void net_dump_vty(struct vty *vty, struct gsm_network *net)
86{
Harald Welteef235b52009-03-10 12:34:02 +000087 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
88 "and has %u BTS%s", net->country_code, net->network_code,
89 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000090 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000091 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000092 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000093 net->name_short, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +020094 vty_out(vty, " Authentication policy: %s%s",
95 gsm_auth_policy_name(net->auth_policy), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000096}
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{
Harald Welteedb37782009-05-01 14:59:07 +0000109 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,
Harald Welte1bc77352009-03-10 19:47:51 +0000120 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000121 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000122 e1l->tei, e1l->sapi, VTY_NEWLINE);
123}
124
125static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
126{
Harald Weltefcd24452009-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)5dececf2009-08-12 13:28:23 +0200132 if (bts->cell_barred)
133 vty_out(vty, " CELL IS BARRED%s", VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000134 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);
Harald Welte68628e82009-03-10 12:17:57 +0000138 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) {
Harald Welte1bc77352009-03-10 19:47:51 +0000160 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000161 VTY_NEWLINE);
162 return CMD_WARNING;
163 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200164 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000165 return CMD_SUCCESS;
166 }
167 /* print all BTS's */
168 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200169 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000170
171 return CMD_SUCCESS;
172}
173
Harald Welte42581822009-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 Welte67ce0732009-08-06 19:06:46 +0200202static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
203{
Harald Welte42581822009-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 Welte67ce0732009-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 Welte5013b2a2009-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 Welte42581822009-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 Welte67ce0732009-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 Welte5013b2a2009-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 Welte67ce0732009-08-06 19:06:46 +0200233 VTY_NEWLINE);
Harald Welte5013b2a2009-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)0e451d02009-08-13 10:14:26 +0200236 vty_out(vty, " ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
Harald Welte7a8fa412009-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)5dececf2009-08-12 13:28:23 +0200240 if (bts->cell_barred)
241 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200242 if (is_ipaccess_bts(bts))
Harald Welte5013b2a2009-08-07 13:29:14 +0200243 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200244 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte42581822009-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 Welte67ce0732009-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 Welte5013b2a2009-08-07 13:29:14 +0200264static int config_write_net(struct vty *vty)
265{
266 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200267 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200268 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-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)69de3972009-08-12 14:42:23 +0200271 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200272
273 return CMD_SUCCESS;
274}
Harald Welte67ce0732009-08-06 19:06:46 +0200275
Harald Welte68628e82009-03-10 12:17:57 +0000276static 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 Weltefcd24452009-06-20 18:15:19 +0200280 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200281 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200282 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200283 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000284 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) {
Harald Welte1bc77352009-03-10 19:47:51 +0000306 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000307 VTY_NEWLINE);
308 return CMD_WARNING;
309 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200310 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000311 }
312 if (argc >= 2) {
313 trx_nr = atoi(argv[1]);
314 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000315 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000316 VTY_NEWLINE);
317 return CMD_WARNING;
318 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200319 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000320 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 Weltee441d9c2009-06-21 16:17:15 +0200326 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000327 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 Weltee441d9c2009-06-21 16:17:15 +0200333 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000334 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200335 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000336 trx_dump_vty(vty, trx);
337 }
338 }
339
340 return CMD_SUCCESS;
341}
342
Harald Welte67ce0732009-08-06 19:06:46 +0200343
Harald Welte68628e82009-03-10 12:17:57 +0000344static 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);
Harald Welte68628e82009-03-10 12:17:57 +0000353 if (is_ipaccess_bts(ts->trx->bts)) {
354 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200355 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000356 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200357 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000358 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000359 } 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);
Harald Welte68628e82009-03-10 12:17:57 +0000363 }
364}
365
366DEFUN(show_ts,
367 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000368 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000369 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) {
Harald Welte1bc77352009-03-10 19:47:51 +0000381 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000382 VTY_NEWLINE);
383 return CMD_WARNING;
384 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200385 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000386 }
387 if (argc >= 2) {
388 trx_nr = atoi(argv[1]);
389 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000390 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000391 VTY_NEWLINE);
392 return CMD_WARNING;
393 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200394 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000395 }
396 if (argc >= 3) {
397 ts_nr = atoi(argv[2]);
398 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000399 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000400 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 Weltee441d9c2009-06-21 16:17:15 +0200408 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000409 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200410 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000411 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 Weltefcd24452009-06-20 18:15:19 +0200423 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000424 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000425 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000426 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000427 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);
434}
435
436static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
437{
438 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
439 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
440 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
441 VTY_NEWLINE);
442 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
443 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
444 lchan->ms_power, VTY_NEWLINE);
445 if (lchan->subscr) {
446 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
447 subscr_dump_vty(vty, lchan->subscr);
448 } else
449 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
450}
451
Harald Welte4bfdfe72009-06-10 23:11:52 +0800452#if 0
453TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000454static void call_dump_vty(struct vty *vty, struct gsm_call *call)
455{
456 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
457 call->type, call->state, call->transaction_id, VTY_NEWLINE);
458
459 if (call->local_lchan) {
460 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
461 lchan_dump_vty(vty, call->local_lchan);
462 } else
463 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
464
465 if (call->remote_lchan) {
466 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
467 lchan_dump_vty(vty, call->remote_lchan);
468 } else
469 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
470
471 if (call->called_subscr) {
472 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
473 subscr_dump_vty(vty, call->called_subscr);
474 } else
475 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
476}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800477#endif
Harald Welte68628e82009-03-10 12:17:57 +0000478
479DEFUN(show_lchan,
480 show_lchan_cmd,
481 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
482 SHOW_STR "Display information about a logical channel\n")
483{
484 struct gsm_network *net = gsmnet;
485 struct gsm_bts *bts;
486 struct gsm_bts_trx *trx;
487 struct gsm_bts_trx_ts *ts;
488 struct gsm_lchan *lchan;
489 int bts_nr, trx_nr, ts_nr, lchan_nr;
490
491 if (argc >= 1) {
492 /* use the BTS number that the user has specified */
493 bts_nr = atoi(argv[0]);
494 if (bts_nr >= net->num_bts) {
495 vty_out(vty, "%% can't find BTS %s%s", argv[0],
496 VTY_NEWLINE);
497 return CMD_WARNING;
498 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200499 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000500 }
501 if (argc >= 2) {
502 trx_nr = atoi(argv[1]);
503 if (trx_nr >= bts->num_trx) {
504 vty_out(vty, "%% can't find TRX %s%s", argv[1],
505 VTY_NEWLINE);
506 return CMD_WARNING;
507 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200508 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000509 }
510 if (argc >= 3) {
511 ts_nr = atoi(argv[2]);
512 if (ts_nr >= TRX_NR_TS) {
513 vty_out(vty, "%% can't find TS %s%s", argv[2],
514 VTY_NEWLINE);
515 return CMD_WARNING;
516 }
517 ts = &trx->ts[ts_nr];
518 }
519 if (argc >= 4) {
520 lchan_nr = atoi(argv[3]);
521 if (lchan_nr >= TS_MAX_LCHAN) {
522 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
523 VTY_NEWLINE);
524 return CMD_WARNING;
525 }
526 lchan = &ts->lchan[lchan_nr];
527 lchan_dump_vty(vty, lchan);
528 return CMD_SUCCESS;
529 }
530 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200531 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000532 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200533 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000534 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
535 ts = &trx->ts[ts_nr];
536 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
537 lchan_nr++) {
538 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000539 if (lchan->type == GSM_LCHAN_NONE)
540 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000541 lchan_dump_vty(vty, lchan);
542 }
543 }
544 }
545 }
546
547 return CMD_SUCCESS;
548}
549
Harald Welte1bc77352009-03-10 19:47:51 +0000550static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
551{
552 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
553}
554
555DEFUN(show_e1drv,
556 show_e1drv_cmd,
557 "show e1_driver",
558 SHOW_STR "Display information about available E1 drivers\n")
559{
560 struct e1inp_driver *drv;
561
562 llist_for_each_entry(drv, &e1inp_driver_list, list)
563 e1drv_dump_vty(vty, drv);
564
565 return CMD_SUCCESS;
566}
567
Harald Welte68628e82009-03-10 12:17:57 +0000568static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
569{
570 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
571 line->num, line->name ? line->name : "",
572 line->driver->name, VTY_NEWLINE);
573}
574
575DEFUN(show_e1line,
576 show_e1line_cmd,
577 "show e1_line [line_nr]",
578 SHOW_STR "Display information about a E1 line\n")
579{
Harald Welte1bc77352009-03-10 19:47:51 +0000580 struct e1inp_line *line;
581
582 if (argc >= 1) {
583 int num = atoi(argv[0]);
584 llist_for_each_entry(line, &e1inp_line_list, list) {
585 if (line->num == num) {
586 e1line_dump_vty(vty, line);
587 return CMD_SUCCESS;
588 }
589 }
590 return CMD_WARNING;
591 }
592
593 llist_for_each_entry(line, &e1inp_line_list, list)
594 e1line_dump_vty(vty, line);
595
596 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000597}
598
599static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
600{
Harald Welte42581822009-08-08 16:12:58 +0200601 if (ts->type == E1INP_TS_TYPE_NONE)
602 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000603 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
604 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
605 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000606}
607
608DEFUN(show_e1ts,
609 show_e1ts_cmd,
610 "show e1_timeslot [line_nr] [ts_nr]",
611 SHOW_STR "Display information about a E1 timeslot\n")
612{
Harald Welte1bc77352009-03-10 19:47:51 +0000613 struct e1inp_line *line;
614 struct e1inp_ts *ts;
615 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000616
Harald Welte1bc77352009-03-10 19:47:51 +0000617 if (argc == 0) {
618 llist_for_each_entry(line, &e1inp_line_list, list) {
619 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
620 ts = &line->ts[ts_nr];
621 e1ts_dump_vty(vty, ts);
622 }
623 }
624 return CMD_SUCCESS;
625 }
626 if (argc >= 1) {
627 int num = atoi(argv[0]);
628 llist_for_each_entry(line, &e1inp_line_list, list) {
629 if (line->num == num)
630 break;
631 }
632 if (!line || line->num != num) {
633 vty_out(vty, "E1 line %s is invalid%s",
634 argv[0], VTY_NEWLINE);
635 return CMD_WARNING;
636 }
637 }
638 if (argc >= 2) {
639 ts_nr = atoi(argv[1]);
640 if (ts_nr > NUM_E1_TS) {
641 vty_out(vty, "E1 timeslot %s is invalid%s",
642 argv[1], VTY_NEWLINE);
643 return CMD_WARNING;
644 }
645 ts = &line->ts[ts_nr];
646 e1ts_dump_vty(vty, ts);
647 return CMD_SUCCESS;
648 } else {
649 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
650 ts = &line->ts[ts_nr];
651 e1ts_dump_vty(vty, ts);
652 }
653 return CMD_SUCCESS;
654 }
655 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000656}
657
Harald Weltebe4b7302009-05-23 16:59:33 +0000658static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000659{
660 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
661 subscr_dump_vty(vty, pag->subscr);
662}
663
Harald Weltebe4b7302009-05-23 16:59:33 +0000664static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000665{
666 struct gsm_paging_request *pag;
667
668 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
669 paging_dump_vty(vty, pag);
670}
671
672DEFUN(show_paging,
673 show_paging_cmd,
674 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000675 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000676{
677 struct gsm_network *net = gsmnet;
678 struct gsm_bts *bts;
679 int bts_nr;
680
681 if (argc >= 1) {
682 /* use the BTS number that the user has specified */
683 bts_nr = atoi(argv[0]);
684 if (bts_nr >= net->num_bts) {
685 vty_out(vty, "%% can't find BTS %s%s", argv[0],
686 VTY_NEWLINE);
687 return CMD_WARNING;
688 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200689 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000690 bts_paging_dump_vty(vty, bts);
691
692 return CMD_SUCCESS;
693 }
694 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200695 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000696 bts_paging_dump_vty(vty, bts);
697 }
698
699 return CMD_SUCCESS;
700}
701
Harald Welte40f82892009-05-23 17:31:39 +0000702/* per-subscriber configuration */
703DEFUN(cfg_subscr,
704 cfg_subscr_cmd,
705 "subscriber IMSI",
706 "Select a Subscriber to configure\n")
707{
708 const char *imsi = argv[0];
709 struct gsm_subscriber *subscr;
710
Harald Welte761e9442009-07-23 19:21:02 +0200711 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000712 if (!subscr) {
713 vty_out(vty, "%% No subscriber for IMSI %s%s",
714 imsi, VTY_NEWLINE);
715 return CMD_WARNING;
716 }
717
718 vty->index = subscr;
719 vty->node = SUBSCR_NODE;
720
721 return CMD_SUCCESS;
722}
723
Harald Welte5013b2a2009-08-07 13:29:14 +0200724DEFUN(cfg_net,
725 cfg_net_cmd,
726 "network",
727 "Configure the GSM network")
728{
729 vty->index = gsmnet;
730 vty->node = GSMNET_NODE;
731
732 return CMD_SUCCESS;
733}
734
735
736DEFUN(cfg_net_ncc,
737 cfg_net_ncc_cmd,
738 "network country code <1-999>",
739 "Set the GSM network country code")
740{
741 gsmnet->country_code = atoi(argv[0]);
742
743 return CMD_SUCCESS;
744}
745
746DEFUN(cfg_net_mnc,
747 cfg_net_mnc_cmd,
748 "mobile network code <1-999>",
749 "Set the GSM mobile network code")
750{
751 gsmnet->network_code = atoi(argv[0]);
752
753 return CMD_SUCCESS;
754}
755
756DEFUN(cfg_net_name_short,
757 cfg_net_name_short_cmd,
758 "short name NAME",
759 "Set the short GSM network name")
760{
761 if (gsmnet->name_short)
762 talloc_free(gsmnet->name_short);
763
764 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
765
766 return CMD_SUCCESS;
767}
768
769DEFUN(cfg_net_name_long,
770 cfg_net_name_long_cmd,
771 "long name NAME",
772 "Set the long GSM network name")
773{
774 if (gsmnet->name_long)
775 talloc_free(gsmnet->name_long);
776
777 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
778
779 return CMD_SUCCESS;
780}
Harald Welte40f82892009-05-23 17:31:39 +0000781
Harald Welte (local)69de3972009-08-12 14:42:23 +0200782DEFUN(cfg_net_auth_policy,
783 cfg_net_auth_policy_cmd,
784 "auth policy (closed|accept-all|token)",
785 "Set the GSM network authentication policy\n")
786{
787 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
788
789 gsmnet->auth_policy = policy;
790
791 return CMD_SUCCESS;
792}
793
Harald Welte5258fc42009-03-28 19:07:53 +0000794/* per-BTS configuration */
795DEFUN(cfg_bts,
796 cfg_bts_cmd,
797 "bts BTS_NR",
798 "Select a BTS to configure\n")
799{
800 int bts_nr = atoi(argv[0]);
801 struct gsm_bts *bts;
802
Harald Weltee441d9c2009-06-21 16:17:15 +0200803 if (bts_nr > gsmnet->num_bts) {
804 vty_out(vty, "%% The next unused BTS number is %u%s",
805 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000806 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200807 } else if (bts_nr == gsmnet->num_bts) {
808 /* allocate a new one */
809 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
810 HARDCODED_TSC, HARDCODED_BSIC);
811 } else
812 bts = gsm_bts_num(gsmnet, bts_nr);
813
814 if (!bts)
815 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000816
817 vty->index = bts;
818 vty->node = BTS_NODE;
819
820 return CMD_SUCCESS;
821}
822
823DEFUN(cfg_bts_type,
824 cfg_bts_type_cmd,
825 "type TYPE",
826 "Set the BTS type\n")
827{
828 struct gsm_bts *bts = vty->index;
829
Harald Weltea6fd58e2009-08-07 00:25:23 +0200830 bts->type = parse_btstype(argv[0]);
831
Harald Welte5258fc42009-03-28 19:07:53 +0000832 return CMD_SUCCESS;
833}
834
Harald Weltefcd24452009-06-20 18:15:19 +0200835DEFUN(cfg_bts_band,
836 cfg_bts_band_cmd,
837 "band BAND",
838 "Set the frequency band of this BTS\n")
839{
840 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200841 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200842
843 if (band < 0) {
844 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
845 band, VTY_NEWLINE);
846 return CMD_WARNING;
847 }
848
849 bts->band = band;
850
851 return CMD_SUCCESS;
852}
853
Harald Welte5258fc42009-03-28 19:07:53 +0000854DEFUN(cfg_bts_lac,
855 cfg_bts_lac_cmd,
856 "location_area_code <0-255>",
857 "Set the Location Area Code (LAC) of this BTS\n")
858{
859 struct gsm_bts *bts = vty->index;
860 int lac = atoi(argv[0]);
861
862 if (lac < 0 || lac > 0xff) {
863 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
864 lac, VTY_NEWLINE);
865 return CMD_WARNING;
866 }
867 bts->location_area_code = lac;
868
869 return CMD_SUCCESS;
870}
871
872DEFUN(cfg_bts_tsc,
873 cfg_bts_tsc_cmd,
874 "training_sequence_code <0-255>",
875 "Set the Training Sequence Code (TSC) of this BTS\n")
876{
877 struct gsm_bts *bts = vty->index;
878 int tsc = atoi(argv[0]);
879
880 if (tsc < 0 || tsc > 0xff) {
881 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
882 tsc, VTY_NEWLINE);
883 return CMD_WARNING;
884 }
885 bts->tsc = tsc;
886
887 return CMD_SUCCESS;
888}
889
Harald Welte78f2f502009-05-23 16:56:52 +0000890DEFUN(cfg_bts_bsic,
891 cfg_bts_bsic_cmd,
892 "base_station_id_code <0-63>",
893 "Set the Base Station Identity Code (BSIC) of this BTS\n")
894{
895 struct gsm_bts *bts = vty->index;
896 int bsic = atoi(argv[0]);
897
898 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200899 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000900 bsic, VTY_NEWLINE);
901 return CMD_WARNING;
902 }
903 bts->bsic = bsic;
904
905 return CMD_SUCCESS;
906}
907
908
Harald Welte4cc34222009-05-01 15:12:31 +0000909DEFUN(cfg_bts_unit_id,
910 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200911 "ip.access unit_id <0-65534> <0-255>",
912 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000913{
914 struct gsm_bts *bts = vty->index;
915 int site_id = atoi(argv[0]);
916 int bts_id = atoi(argv[1]);
917
Harald Welte07dc73d2009-08-07 13:27:09 +0200918 if (!is_ipaccess_bts(bts)) {
919 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
920 return CMD_WARNING;
921 }
922
Harald Welte4cc34222009-05-01 15:12:31 +0000923 bts->ip_access.site_id = site_id;
924 bts->ip_access.bts_id = bts_id;
925
926 return CMD_SUCCESS;
927}
928
Harald Welte42581822009-08-08 16:12:58 +0200929DEFUN(cfg_bts_oml_e1,
930 cfg_bts_oml_e1_cmd,
931 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
932 "E1 interface to be used for OML\n")
933{
934 struct gsm_bts *bts = vty->index;
935
936 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
937
938 return CMD_SUCCESS;
939}
940
941
942DEFUN(cfg_bts_oml_e1_tei,
943 cfg_bts_oml_e1_tei_cmd,
944 "oml e1 tei <0-63>",
945 "Set the TEI to be used for OML")
946{
947 struct gsm_bts *bts = vty->index;
948
949 bts->oml_tei = atoi(argv[0]);
950
951 return CMD_SUCCESS;
952}
953
Harald Welte7a8fa412009-08-10 13:48:16 +0200954DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
955 "channel allocator (ascending|descending)",
956 "Should the channel allocator allocate in reverse TRX order?")
957{
958 struct gsm_bts *bts = vty->index;
959
960 if (!strcmp(argv[0], "ascending"))
961 bts->chan_alloc_reverse = 0;
962 else
963 bts->chan_alloc_reverse = 1;
964
965 return CMD_SUCCESS;
966}
967
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200968DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
969 "cell barred (0|1)",
970 "Should this cell be barred from access?")
971{
972 struct gsm_bts *bts = vty->index;
973
974 bts->cell_barred = atoi(argv[0]);
975
976 return CMD_SUCCESS;
977}
978
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200979DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
980 "ms max power <0-40>",
981 "Maximum transmit power of the MS")
982{
983 struct gsm_bts *bts = vty->index;
984
985 bts->ms_max_power = atoi(argv[0]);
986
987 return CMD_SUCCESS;
988}
989
Harald Welte7a8fa412009-08-10 13:48:16 +0200990
Harald Welte5258fc42009-03-28 19:07:53 +0000991/* per TRX configuration */
992DEFUN(cfg_trx,
993 cfg_trx_cmd,
994 "trx TRX_NR",
995 "Select a TRX to configure")
996{
997 int trx_nr = atoi(argv[0]);
998 struct gsm_bts *bts = vty->index;
999 struct gsm_bts_trx *trx;
1000
Harald Weltee441d9c2009-06-21 16:17:15 +02001001 if (trx_nr > bts->num_trx) {
1002 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1003 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +00001004 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +02001005 } else if (trx_nr == bts->num_trx) {
1006 /* we need to allocate a new one */
1007 trx = gsm_bts_trx_alloc(bts);
1008 } else
1009 trx = gsm_bts_trx_num(bts, trx_nr);
1010
1011 if (!trx)
1012 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001013
1014 vty->index = trx;
1015 vty->node = TRX_NODE;
1016
1017 return CMD_SUCCESS;
1018}
1019
1020DEFUN(cfg_trx_arfcn,
1021 cfg_trx_arfcn_cmd,
1022 "arfcn <1-1024>",
1023 "Set the ARFCN for this TRX\n")
1024{
1025 int arfcn = atoi(argv[0]);
1026 struct gsm_bts_trx *trx = vty->index;
1027
1028 /* FIXME: check if this ARFCN is supported by this TRX */
1029
1030 trx->arfcn = arfcn;
1031
1032 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1033 /* FIXME: use OML layer to update the ARFCN */
1034 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1035
1036 return CMD_SUCCESS;
1037}
1038
Harald Weltefcd24452009-06-20 18:15:19 +02001039DEFUN(cfg_trx_max_power_red,
1040 cfg_trx_max_power_red_cmd,
1041 "max_power_red <0-100>",
1042 "Reduction of maximum BS RF Power in dB\n")
1043{
1044 int maxpwr_r = atoi(argv[0]);
1045 struct gsm_bts_trx *trx = vty->index;
1046 int upper_limit = 12; /* default 12.21 max power red. */
1047
1048 /* FIXME: check if our BTS type supports more than 12 */
1049 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1050 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1051 maxpwr_r, VTY_NEWLINE);
1052 return CMD_WARNING;
1053 }
1054 if (maxpwr_r & 1) {
1055 vty_out(vty, "%% Power %d dB is not an even value%s",
1056 maxpwr_r, VTY_NEWLINE);
1057 return CMD_WARNING;
1058 }
1059
1060 trx->max_power_red = maxpwr_r;
1061
1062 /* FIXME: make sure we update this using OML */
1063
1064 return CMD_SUCCESS;
1065}
1066
Harald Welte42581822009-08-08 16:12:58 +02001067DEFUN(cfg_trx_rsl_e1,
1068 cfg_trx_rsl_e1_cmd,
1069 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1070 "E1 interface to be used for RSL\n")
1071{
1072 struct gsm_bts_trx *trx = vty->index;
1073
1074 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1075
1076 return CMD_SUCCESS;
1077}
1078
1079DEFUN(cfg_trx_rsl_e1_tei,
1080 cfg_trx_rsl_e1_tei_cmd,
1081 "rsl e1 tei <0-63>",
1082 "Set the TEI to be used for RSL")
1083{
1084 struct gsm_bts_trx *trx = vty->index;
1085
1086 trx->rsl_tei = atoi(argv[0]);
1087
1088 return CMD_SUCCESS;
1089}
1090
1091
Harald Welte5258fc42009-03-28 19:07:53 +00001092/* per TS configuration */
1093DEFUN(cfg_ts,
1094 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001095 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001096 "Select a Timeslot to configure")
1097{
1098 int ts_nr = atoi(argv[0]);
1099 struct gsm_bts_trx *trx = vty->index;
1100 struct gsm_bts_trx_ts *ts;
1101
1102 if (ts_nr >= TRX_NR_TS) {
1103 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1104 TRX_NR_TS, VTY_NEWLINE);
1105 return CMD_WARNING;
1106 }
1107
1108 ts = &trx->ts[ts_nr];
1109
1110 vty->index = ts;
1111 vty->node = TS_NODE;
1112
1113 return CMD_SUCCESS;
1114}
1115
Harald Weltea6fd58e2009-08-07 00:25:23 +02001116DEFUN(cfg_ts_pchan,
1117 cfg_ts_pchan_cmd,
1118 "phys_chan_config PCHAN",
1119 "Physical Channel configuration (TCH/SDCCH/...)")
1120{
1121 struct gsm_bts_trx_ts *ts = vty->index;
1122 int pchanc;
1123
1124 pchanc = gsm_pchan_parse(argv[0]);
1125 if (pchanc < 0)
1126 return CMD_WARNING;
1127
1128 ts->pchan = pchanc;
1129
1130 return CMD_SUCCESS;
1131}
1132
1133DEFUN(cfg_ts_e1_subslot,
1134 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001135 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001136 "E1 sub-slot connected to this on-air timeslot")
1137{
1138 struct gsm_bts_trx_ts *ts = vty->index;
1139
Harald Welte42581822009-08-08 16:12:58 +02001140 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001141
1142 return CMD_SUCCESS;
1143}
Harald Welte5258fc42009-03-28 19:07:53 +00001144
Harald Welte40f82892009-05-23 17:31:39 +00001145/* Subscriber */
1146DEFUN(show_subscr,
1147 show_subscr_cmd,
1148 "show subscriber [IMSI]",
1149 SHOW_STR "Display information about a subscriber\n")
1150{
1151 const char *imsi;
1152 struct gsm_subscriber *subscr;
1153
1154 if (argc >= 1) {
1155 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +02001156 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +00001157 if (!subscr) {
1158 vty_out(vty, "%% unknown subscriber%s",
1159 VTY_NEWLINE);
1160 return CMD_WARNING;
1161 }
1162 subscr_dump_vty(vty, subscr);
1163
1164 return CMD_SUCCESS;
1165 }
1166
1167 /* FIXME: iterate over all subscribers ? */
1168 return CMD_WARNING;
1169
1170 return CMD_SUCCESS;
1171}
1172
Harald Welte76042182009-08-08 16:03:15 +02001173DEFUN(sms_send_pend,
1174 sms_send_pend_cmd,
1175 "sms send pending MIN_ID",
1176 "Send all pending SMS starting from MIN_ID")
1177{
1178 struct gsm_sms *sms;
1179
1180 sms = db_sms_get_unsent(gsmnet, atoi(argv[0]));
1181 if (!sms)
1182 return CMD_WARNING;
1183
1184 if (!sms->receiver) {
1185 sms_free(sms);
1186 return CMD_WARNING;
1187 }
1188
1189 gsm411_send_sms_subscr(sms->receiver, sms);
1190
1191 return CMD_SUCCESS;
1192}
1193
Harald Weltef9daefd2009-08-09 15:13:54 +02001194static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1195{
1196 struct buffer *b = buffer_new(1024);
1197 int i;
1198
1199 if (!b)
1200 return NULL;
1201
1202 for (i = base; i < argc; i++) {
1203 buffer_putstr(b, argv[i]);
1204 buffer_putc(b, ' ');
1205 }
1206 buffer_putc(b, '\0');
1207
1208 return b;
1209}
1210
Harald Welte8c340fe2009-08-13 00:57:31 +02001211int sms_from_text(struct gsm_subscriber *receiver, const char *text)
Harald Weltef9daefd2009-08-09 15:13:54 +02001212{
1213 struct gsm_sms *sms = sms_alloc();
1214
1215 if (!sms)
1216 return CMD_WARNING;
1217
1218 if (!receiver->lac) {
1219 /* subscriber currently not attached, store in database? */
Harald Weltef9daefd2009-08-09 15:13:54 +02001220 return CMD_WARNING;
1221 }
1222
Harald Welte (local)571602f2009-08-13 13:25:32 +02001223 sms->receiver = subscr_get(receiver);
Harald Welte8c340fe2009-08-13 00:57:31 +02001224 strncpy(sms->text, text, sizeof(sms->text)-1);
Harald Weltef9daefd2009-08-09 15:13:54 +02001225
1226 /* FIXME: don't use ID 1 static */
1227 sms->sender = subscr_get_by_id(gsmnet, 1);
1228 sms->reply_path_req = 0;
1229 sms->status_rep_req = 0;
1230 sms->ud_hdr_ind = 0;
1231 sms->protocol_id = 0; /* implicit */
1232 sms->data_coding_scheme = 0; /* default 7bit */
1233 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1234 /* Generate user_data */
1235 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1236
Harald Welte8c340fe2009-08-13 00:57:31 +02001237 return sms;
1238}
1239
1240static int _send_sms_buffer(struct gsm_subscriber *receiver,
1241 struct buffer *b)
1242{
1243 struct gsm_sms *sms;
1244
1245 sms = sms_from_text(receiver, buffer_getstr(b));
1246
Harald Welte (local)571602f2009-08-13 13:25:32 +02001247 gsm411_send_sms_subscr(receiver, sms);
Harald Weltef9daefd2009-08-09 15:13:54 +02001248
1249 return CMD_SUCCESS;
1250}
1251
Harald Welte76042182009-08-08 16:03:15 +02001252DEFUN(sms_send_ext,
1253 sms_send_ext_cmd,
1254 "sms send extension EXTEN .LINE",
1255 "Send a message to a subscriber identified by EXTEN")
1256{
Harald Weltef9daefd2009-08-09 15:13:54 +02001257 struct gsm_subscriber *receiver;
1258 struct buffer *b;
1259 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001260
Harald Weltef9daefd2009-08-09 15:13:54 +02001261 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1262 if (!receiver)
1263 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001264
Harald Weltef9daefd2009-08-09 15:13:54 +02001265 b = argv_to_buffer(argc, argv, 1);
1266 rc = _send_sms_buffer(receiver, b);
1267 buffer_free(b);
1268
1269 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001270}
1271
1272DEFUN(sms_send_imsi,
1273 sms_send_imsi_cmd,
1274 "sms send imsi IMSI .LINE",
1275 "Send a message to a subscriber identified by IMSI")
1276{
Harald Weltef9daefd2009-08-09 15:13:54 +02001277 struct gsm_subscriber *receiver;
1278 struct buffer *b;
1279 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001280
Harald Weltef9daefd2009-08-09 15:13:54 +02001281 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1282 if (!receiver)
1283 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001284
Harald Weltef9daefd2009-08-09 15:13:54 +02001285 b = argv_to_buffer(argc, argv, 1);
1286 rc = _send_sms_buffer(receiver, b);
1287 buffer_free(b);
1288
1289 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001290}
1291
1292
Harald Welte40f82892009-05-23 17:31:39 +00001293DEFUN(cfg_subscr_name,
1294 cfg_subscr_name_cmd,
1295 "name NAME",
1296 "Set the name of the subscriber")
1297{
1298 const char *name = argv[0];
1299 struct gsm_subscriber *subscr = vty->index;
1300
1301 strncpy(subscr->name, name, sizeof(subscr->name));
1302
1303 db_sync_subscriber(subscr);
1304
1305 return CMD_SUCCESS;
1306}
1307
1308DEFUN(cfg_subscr_extension,
1309 cfg_subscr_extension_cmd,
1310 "extension EXTENSION",
1311 "Set the extension of the subscriber")
1312{
1313 const char *name = argv[0];
1314 struct gsm_subscriber *subscr = vty->index;
1315
1316 strncpy(subscr->extension, name, sizeof(subscr->extension));
1317
1318 db_sync_subscriber(subscr);
1319
1320 return CMD_SUCCESS;
1321}
1322
1323DEFUN(cfg_subscr_authorized,
1324 cfg_subscr_authorized_cmd,
1325 "auth <0-1>",
1326 "Set the authorization status of the subscriber")
1327{
1328 int auth = atoi(argv[0]);
1329 struct gsm_subscriber *subscr = vty->index;
1330
1331 if (auth)
1332 subscr->authorized = 1;
1333 else
1334 subscr->authorized = 0;
1335
1336 db_sync_subscriber(subscr);
1337
1338 return CMD_SUCCESS;
1339}
1340
Harald Welte68628e82009-03-10 12:17:57 +00001341int bsc_vty_init(struct gsm_network *net)
1342{
1343 gsmnet = net;
1344
1345 cmd_init(1);
1346 vty_init();
1347
1348 install_element(VIEW_NODE, &show_net_cmd);
1349 install_element(VIEW_NODE, &show_bts_cmd);
1350 install_element(VIEW_NODE, &show_trx_cmd);
1351 install_element(VIEW_NODE, &show_ts_cmd);
1352 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001353
1354 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001355 install_element(VIEW_NODE, &show_e1line_cmd);
1356 install_element(VIEW_NODE, &show_e1ts_cmd);
1357
Harald Weltef5025b62009-03-28 16:55:11 +00001358 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001359
Harald Welte40f82892009-05-23 17:31:39 +00001360 install_element(VIEW_NODE, &show_subscr_cmd);
1361
Harald Welte76042182009-08-08 16:03:15 +02001362 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001363 install_element(VIEW_NODE, &sms_send_ext_cmd);
1364 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001365
Harald Welte5013b2a2009-08-07 13:29:14 +02001366 install_element(CONFIG_NODE, &cfg_net_cmd);
1367 install_node(&net_node, config_write_net);
1368 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001369 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001370 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1371 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1372 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001373 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001374
1375 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001376 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001377 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001378 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001379 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001380 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1381 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001382 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001383 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001384 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1385 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001386 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001387 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001388 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001389
Harald Welte68628e82009-03-10 12:17:57 +00001390
Harald Welte5258fc42009-03-28 19:07:53 +00001391 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001392 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001393 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001394 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001395 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001396 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1397 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001398
Harald Welte5258fc42009-03-28 19:07:53 +00001399 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001400 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001401 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001402 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1403 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001404
Harald Welte40f82892009-05-23 17:31:39 +00001405 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1406 install_node(&subscr_node, dummy_config_write);
1407 install_default(SUBSCR_NODE);
1408 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1409 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1410 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1411
Harald Welte68628e82009-03-10 12:17:57 +00001412 return 0;
1413}