blob: 70c5e01a7cc66199389fc7a23304a318c226b382 [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 Welte7a8fa412009-08-10 13:48:16 +0200236 vty_out(vty, " channel allocator %s%s",
237 bts->chan_alloc_reverse ? "descending" : "ascending",
238 VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200239 if (bts->cell_barred)
240 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200241 if (is_ipaccess_bts(bts))
Harald Welte5013b2a2009-08-07 13:29:14 +0200242 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200243 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200244 else {
245 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
246 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
247 }
Harald Welte67ce0732009-08-06 19:06:46 +0200248
249 llist_for_each_entry(trx, &bts->trx_list, list)
250 config_write_trx_single(vty, trx);
251}
252
253static int config_write_bts(struct vty *v)
254{
255 struct gsm_bts *bts;
256
257 llist_for_each_entry(bts, &gsmnet->bts_list, list)
258 config_write_bts_single(v, bts);
259
260 return CMD_SUCCESS;
261}
262
Harald Welte5013b2a2009-08-07 13:29:14 +0200263static int config_write_net(struct vty *vty)
264{
265 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200266 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200267 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200268 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
269 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +0200270 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200271
272 return CMD_SUCCESS;
273}
Harald Welte67ce0732009-08-06 19:06:46 +0200274
Harald Welte68628e82009-03-10 12:17:57 +0000275static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
276{
277 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
278 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200279 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200280 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200281 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200282 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000283 vty_out(vty, " NM State: ");
284 net_dump_nmstate(vty, &trx->nm_state);
285 vty_out(vty, " Baseband Transceiver NM State: ");
286 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
287 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
288 e1isl_dump_vty(vty, trx->rsl_link);
289}
290
291DEFUN(show_trx,
292 show_trx_cmd,
293 "show trx [bts_nr] [trx_nr]",
294 SHOW_STR "Display information about a TRX\n")
295{
296 struct gsm_network *net = gsmnet;
297 struct gsm_bts *bts = NULL;
298 struct gsm_bts_trx *trx;
299 int bts_nr, trx_nr;
300
301 if (argc >= 1) {
302 /* use the BTS number that the user has specified */
303 bts_nr = atoi(argv[0]);
304 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000305 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000306 VTY_NEWLINE);
307 return CMD_WARNING;
308 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200309 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000310 }
311 if (argc >= 2) {
312 trx_nr = atoi(argv[1]);
313 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000314 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000315 VTY_NEWLINE);
316 return CMD_WARNING;
317 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200318 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000319 trx_dump_vty(vty, trx);
320 return CMD_SUCCESS;
321 }
322 if (bts) {
323 /* print all TRX in this BTS */
324 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200325 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000326 trx_dump_vty(vty, trx);
327 }
328 return CMD_SUCCESS;
329 }
330
331 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200332 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000333 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200334 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000335 trx_dump_vty(vty, trx);
336 }
337 }
338
339 return CMD_SUCCESS;
340}
341
Harald Welte67ce0732009-08-06 19:06:46 +0200342
Harald Welte68628e82009-03-10 12:17:57 +0000343static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
344{
345 struct in_addr ia;
346
347 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
348 ts->nr, ts->trx->nr, ts->trx->bts->nr,
349 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
350 vty_out(vty, " NM State: ");
351 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000352 if (is_ipaccess_bts(ts->trx->bts)) {
353 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200354 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000355 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200356 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000357 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000358 } else {
359 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
360 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
361 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000362 }
363}
364
365DEFUN(show_ts,
366 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000367 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000368 SHOW_STR "Display information about a TS\n")
369{
370 struct gsm_network *net = gsmnet;
371 struct gsm_bts *bts;
372 struct gsm_bts_trx *trx;
373 struct gsm_bts_trx_ts *ts;
374 int bts_nr, trx_nr, ts_nr;
375
376 if (argc >= 1) {
377 /* use the BTS number that the user has specified */
378 bts_nr = atoi(argv[0]);
379 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000380 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000381 VTY_NEWLINE);
382 return CMD_WARNING;
383 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200384 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000385 }
386 if (argc >= 2) {
387 trx_nr = atoi(argv[1]);
388 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000389 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000390 VTY_NEWLINE);
391 return CMD_WARNING;
392 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200393 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000394 }
395 if (argc >= 3) {
396 ts_nr = atoi(argv[2]);
397 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000398 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000399 VTY_NEWLINE);
400 return CMD_WARNING;
401 }
402 ts = &trx->ts[ts_nr];
403 ts_dump_vty(vty, ts);
404 return CMD_SUCCESS;
405 }
406 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200407 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000408 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200409 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000410 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
411 ts = &trx->ts[ts_nr];
412 ts_dump_vty(vty, ts);
413 }
414 }
415 }
416
417 return CMD_SUCCESS;
418}
419
420static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
421{
Harald Weltefcd24452009-06-20 18:15:19 +0200422 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000423 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000424 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000425 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000426 if (subscr->extension)
427 vty_out(vty, " Extension: %s%s", subscr->extension,
428 VTY_NEWLINE);
429 if (subscr->imsi)
430 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
431 if (subscr->tmsi)
432 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
433}
434
435static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
436{
437 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
438 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
439 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
440 VTY_NEWLINE);
441 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
442 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
443 lchan->ms_power, VTY_NEWLINE);
444 if (lchan->subscr) {
445 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
446 subscr_dump_vty(vty, lchan->subscr);
447 } else
448 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
449}
450
Harald Welte4bfdfe72009-06-10 23:11:52 +0800451#if 0
452TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000453static void call_dump_vty(struct vty *vty, struct gsm_call *call)
454{
455 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
456 call->type, call->state, call->transaction_id, VTY_NEWLINE);
457
458 if (call->local_lchan) {
459 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
460 lchan_dump_vty(vty, call->local_lchan);
461 } else
462 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
463
464 if (call->remote_lchan) {
465 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
466 lchan_dump_vty(vty, call->remote_lchan);
467 } else
468 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
469
470 if (call->called_subscr) {
471 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
472 subscr_dump_vty(vty, call->called_subscr);
473 } else
474 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
475}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800476#endif
Harald Welte68628e82009-03-10 12:17:57 +0000477
478DEFUN(show_lchan,
479 show_lchan_cmd,
480 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
481 SHOW_STR "Display information about a logical channel\n")
482{
483 struct gsm_network *net = gsmnet;
484 struct gsm_bts *bts;
485 struct gsm_bts_trx *trx;
486 struct gsm_bts_trx_ts *ts;
487 struct gsm_lchan *lchan;
488 int bts_nr, trx_nr, ts_nr, lchan_nr;
489
490 if (argc >= 1) {
491 /* use the BTS number that the user has specified */
492 bts_nr = atoi(argv[0]);
493 if (bts_nr >= net->num_bts) {
494 vty_out(vty, "%% can't find BTS %s%s", argv[0],
495 VTY_NEWLINE);
496 return CMD_WARNING;
497 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200498 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000499 }
500 if (argc >= 2) {
501 trx_nr = atoi(argv[1]);
502 if (trx_nr >= bts->num_trx) {
503 vty_out(vty, "%% can't find TRX %s%s", argv[1],
504 VTY_NEWLINE);
505 return CMD_WARNING;
506 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200507 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000508 }
509 if (argc >= 3) {
510 ts_nr = atoi(argv[2]);
511 if (ts_nr >= TRX_NR_TS) {
512 vty_out(vty, "%% can't find TS %s%s", argv[2],
513 VTY_NEWLINE);
514 return CMD_WARNING;
515 }
516 ts = &trx->ts[ts_nr];
517 }
518 if (argc >= 4) {
519 lchan_nr = atoi(argv[3]);
520 if (lchan_nr >= TS_MAX_LCHAN) {
521 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
522 VTY_NEWLINE);
523 return CMD_WARNING;
524 }
525 lchan = &ts->lchan[lchan_nr];
526 lchan_dump_vty(vty, lchan);
527 return CMD_SUCCESS;
528 }
529 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200530 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000531 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200532 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000533 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
534 ts = &trx->ts[ts_nr];
535 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
536 lchan_nr++) {
537 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000538 if (lchan->type == GSM_LCHAN_NONE)
539 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000540 lchan_dump_vty(vty, lchan);
541 }
542 }
543 }
544 }
545
546 return CMD_SUCCESS;
547}
548
Harald Welte1bc77352009-03-10 19:47:51 +0000549static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
550{
551 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
552}
553
554DEFUN(show_e1drv,
555 show_e1drv_cmd,
556 "show e1_driver",
557 SHOW_STR "Display information about available E1 drivers\n")
558{
559 struct e1inp_driver *drv;
560
561 llist_for_each_entry(drv, &e1inp_driver_list, list)
562 e1drv_dump_vty(vty, drv);
563
564 return CMD_SUCCESS;
565}
566
Harald Welte68628e82009-03-10 12:17:57 +0000567static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
568{
569 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
570 line->num, line->name ? line->name : "",
571 line->driver->name, VTY_NEWLINE);
572}
573
574DEFUN(show_e1line,
575 show_e1line_cmd,
576 "show e1_line [line_nr]",
577 SHOW_STR "Display information about a E1 line\n")
578{
Harald Welte1bc77352009-03-10 19:47:51 +0000579 struct e1inp_line *line;
580
581 if (argc >= 1) {
582 int num = atoi(argv[0]);
583 llist_for_each_entry(line, &e1inp_line_list, list) {
584 if (line->num == num) {
585 e1line_dump_vty(vty, line);
586 return CMD_SUCCESS;
587 }
588 }
589 return CMD_WARNING;
590 }
591
592 llist_for_each_entry(line, &e1inp_line_list, list)
593 e1line_dump_vty(vty, line);
594
595 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000596}
597
598static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
599{
Harald Welte42581822009-08-08 16:12:58 +0200600 if (ts->type == E1INP_TS_TYPE_NONE)
601 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000602 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
603 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
604 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000605}
606
607DEFUN(show_e1ts,
608 show_e1ts_cmd,
609 "show e1_timeslot [line_nr] [ts_nr]",
610 SHOW_STR "Display information about a E1 timeslot\n")
611{
Harald Welte1bc77352009-03-10 19:47:51 +0000612 struct e1inp_line *line;
613 struct e1inp_ts *ts;
614 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000615
Harald Welte1bc77352009-03-10 19:47:51 +0000616 if (argc == 0) {
617 llist_for_each_entry(line, &e1inp_line_list, list) {
618 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
619 ts = &line->ts[ts_nr];
620 e1ts_dump_vty(vty, ts);
621 }
622 }
623 return CMD_SUCCESS;
624 }
625 if (argc >= 1) {
626 int num = atoi(argv[0]);
627 llist_for_each_entry(line, &e1inp_line_list, list) {
628 if (line->num == num)
629 break;
630 }
631 if (!line || line->num != num) {
632 vty_out(vty, "E1 line %s is invalid%s",
633 argv[0], VTY_NEWLINE);
634 return CMD_WARNING;
635 }
636 }
637 if (argc >= 2) {
638 ts_nr = atoi(argv[1]);
639 if (ts_nr > NUM_E1_TS) {
640 vty_out(vty, "E1 timeslot %s is invalid%s",
641 argv[1], VTY_NEWLINE);
642 return CMD_WARNING;
643 }
644 ts = &line->ts[ts_nr];
645 e1ts_dump_vty(vty, ts);
646 return CMD_SUCCESS;
647 } else {
648 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
649 ts = &line->ts[ts_nr];
650 e1ts_dump_vty(vty, ts);
651 }
652 return CMD_SUCCESS;
653 }
654 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000655}
656
Harald Weltebe4b7302009-05-23 16:59:33 +0000657static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000658{
659 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
660 subscr_dump_vty(vty, pag->subscr);
661}
662
Harald Weltebe4b7302009-05-23 16:59:33 +0000663static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000664{
665 struct gsm_paging_request *pag;
666
667 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
668 paging_dump_vty(vty, pag);
669}
670
671DEFUN(show_paging,
672 show_paging_cmd,
673 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000674 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000675{
676 struct gsm_network *net = gsmnet;
677 struct gsm_bts *bts;
678 int bts_nr;
679
680 if (argc >= 1) {
681 /* use the BTS number that the user has specified */
682 bts_nr = atoi(argv[0]);
683 if (bts_nr >= net->num_bts) {
684 vty_out(vty, "%% can't find BTS %s%s", argv[0],
685 VTY_NEWLINE);
686 return CMD_WARNING;
687 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200688 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000689 bts_paging_dump_vty(vty, bts);
690
691 return CMD_SUCCESS;
692 }
693 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200694 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000695 bts_paging_dump_vty(vty, bts);
696 }
697
698 return CMD_SUCCESS;
699}
700
Harald Welte40f82892009-05-23 17:31:39 +0000701/* per-subscriber configuration */
702DEFUN(cfg_subscr,
703 cfg_subscr_cmd,
704 "subscriber IMSI",
705 "Select a Subscriber to configure\n")
706{
707 const char *imsi = argv[0];
708 struct gsm_subscriber *subscr;
709
Harald Welte761e9442009-07-23 19:21:02 +0200710 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000711 if (!subscr) {
712 vty_out(vty, "%% No subscriber for IMSI %s%s",
713 imsi, VTY_NEWLINE);
714 return CMD_WARNING;
715 }
716
717 vty->index = subscr;
718 vty->node = SUBSCR_NODE;
719
720 return CMD_SUCCESS;
721}
722
Harald Welte5013b2a2009-08-07 13:29:14 +0200723DEFUN(cfg_net,
724 cfg_net_cmd,
725 "network",
726 "Configure the GSM network")
727{
728 vty->index = gsmnet;
729 vty->node = GSMNET_NODE;
730
731 return CMD_SUCCESS;
732}
733
734
735DEFUN(cfg_net_ncc,
736 cfg_net_ncc_cmd,
737 "network country code <1-999>",
738 "Set the GSM network country code")
739{
740 gsmnet->country_code = atoi(argv[0]);
741
742 return CMD_SUCCESS;
743}
744
745DEFUN(cfg_net_mnc,
746 cfg_net_mnc_cmd,
747 "mobile network code <1-999>",
748 "Set the GSM mobile network code")
749{
750 gsmnet->network_code = atoi(argv[0]);
751
752 return CMD_SUCCESS;
753}
754
755DEFUN(cfg_net_name_short,
756 cfg_net_name_short_cmd,
757 "short name NAME",
758 "Set the short GSM network name")
759{
760 if (gsmnet->name_short)
761 talloc_free(gsmnet->name_short);
762
763 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
764
765 return CMD_SUCCESS;
766}
767
768DEFUN(cfg_net_name_long,
769 cfg_net_name_long_cmd,
770 "long name NAME",
771 "Set the long GSM network name")
772{
773 if (gsmnet->name_long)
774 talloc_free(gsmnet->name_long);
775
776 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
777
778 return CMD_SUCCESS;
779}
Harald Welte40f82892009-05-23 17:31:39 +0000780
Harald Welte (local)69de3972009-08-12 14:42:23 +0200781DEFUN(cfg_net_auth_policy,
782 cfg_net_auth_policy_cmd,
783 "auth policy (closed|accept-all|token)",
784 "Set the GSM network authentication policy\n")
785{
786 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
787
788 gsmnet->auth_policy = policy;
789
790 return CMD_SUCCESS;
791}
792
Harald Welte5258fc42009-03-28 19:07:53 +0000793/* per-BTS configuration */
794DEFUN(cfg_bts,
795 cfg_bts_cmd,
796 "bts BTS_NR",
797 "Select a BTS to configure\n")
798{
799 int bts_nr = atoi(argv[0]);
800 struct gsm_bts *bts;
801
Harald Weltee441d9c2009-06-21 16:17:15 +0200802 if (bts_nr > gsmnet->num_bts) {
803 vty_out(vty, "%% The next unused BTS number is %u%s",
804 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000805 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200806 } else if (bts_nr == gsmnet->num_bts) {
807 /* allocate a new one */
808 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
809 HARDCODED_TSC, HARDCODED_BSIC);
810 } else
811 bts = gsm_bts_num(gsmnet, bts_nr);
812
813 if (!bts)
814 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000815
816 vty->index = bts;
817 vty->node = BTS_NODE;
818
819 return CMD_SUCCESS;
820}
821
822DEFUN(cfg_bts_type,
823 cfg_bts_type_cmd,
824 "type TYPE",
825 "Set the BTS type\n")
826{
827 struct gsm_bts *bts = vty->index;
828
Harald Weltea6fd58e2009-08-07 00:25:23 +0200829 bts->type = parse_btstype(argv[0]);
830
Harald Welte5258fc42009-03-28 19:07:53 +0000831 return CMD_SUCCESS;
832}
833
Harald Weltefcd24452009-06-20 18:15:19 +0200834DEFUN(cfg_bts_band,
835 cfg_bts_band_cmd,
836 "band BAND",
837 "Set the frequency band of this BTS\n")
838{
839 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200840 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200841
842 if (band < 0) {
843 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
844 band, VTY_NEWLINE);
845 return CMD_WARNING;
846 }
847
848 bts->band = band;
849
850 return CMD_SUCCESS;
851}
852
Harald Welte5258fc42009-03-28 19:07:53 +0000853DEFUN(cfg_bts_lac,
854 cfg_bts_lac_cmd,
855 "location_area_code <0-255>",
856 "Set the Location Area Code (LAC) of this BTS\n")
857{
858 struct gsm_bts *bts = vty->index;
859 int lac = atoi(argv[0]);
860
861 if (lac < 0 || lac > 0xff) {
862 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
863 lac, VTY_NEWLINE);
864 return CMD_WARNING;
865 }
866 bts->location_area_code = lac;
867
868 return CMD_SUCCESS;
869}
870
871DEFUN(cfg_bts_tsc,
872 cfg_bts_tsc_cmd,
873 "training_sequence_code <0-255>",
874 "Set the Training Sequence Code (TSC) of this BTS\n")
875{
876 struct gsm_bts *bts = vty->index;
877 int tsc = atoi(argv[0]);
878
879 if (tsc < 0 || tsc > 0xff) {
880 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
881 tsc, VTY_NEWLINE);
882 return CMD_WARNING;
883 }
884 bts->tsc = tsc;
885
886 return CMD_SUCCESS;
887}
888
Harald Welte78f2f502009-05-23 16:56:52 +0000889DEFUN(cfg_bts_bsic,
890 cfg_bts_bsic_cmd,
891 "base_station_id_code <0-63>",
892 "Set the Base Station Identity Code (BSIC) of this BTS\n")
893{
894 struct gsm_bts *bts = vty->index;
895 int bsic = atoi(argv[0]);
896
897 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200898 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000899 bsic, VTY_NEWLINE);
900 return CMD_WARNING;
901 }
902 bts->bsic = bsic;
903
904 return CMD_SUCCESS;
905}
906
907
Harald Welte4cc34222009-05-01 15:12:31 +0000908DEFUN(cfg_bts_unit_id,
909 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200910 "ip.access unit_id <0-65534> <0-255>",
911 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000912{
913 struct gsm_bts *bts = vty->index;
914 int site_id = atoi(argv[0]);
915 int bts_id = atoi(argv[1]);
916
Harald Welte07dc73d2009-08-07 13:27:09 +0200917 if (!is_ipaccess_bts(bts)) {
918 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
919 return CMD_WARNING;
920 }
921
Harald Welte4cc34222009-05-01 15:12:31 +0000922 bts->ip_access.site_id = site_id;
923 bts->ip_access.bts_id = bts_id;
924
925 return CMD_SUCCESS;
926}
927
Harald Welte42581822009-08-08 16:12:58 +0200928DEFUN(cfg_bts_oml_e1,
929 cfg_bts_oml_e1_cmd,
930 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
931 "E1 interface to be used for OML\n")
932{
933 struct gsm_bts *bts = vty->index;
934
935 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
936
937 return CMD_SUCCESS;
938}
939
940
941DEFUN(cfg_bts_oml_e1_tei,
942 cfg_bts_oml_e1_tei_cmd,
943 "oml e1 tei <0-63>",
944 "Set the TEI to be used for OML")
945{
946 struct gsm_bts *bts = vty->index;
947
948 bts->oml_tei = atoi(argv[0]);
949
950 return CMD_SUCCESS;
951}
952
Harald Welte7a8fa412009-08-10 13:48:16 +0200953DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
954 "channel allocator (ascending|descending)",
955 "Should the channel allocator allocate in reverse TRX order?")
956{
957 struct gsm_bts *bts = vty->index;
958
959 if (!strcmp(argv[0], "ascending"))
960 bts->chan_alloc_reverse = 0;
961 else
962 bts->chan_alloc_reverse = 1;
963
964 return CMD_SUCCESS;
965}
966
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200967DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
968 "cell barred (0|1)",
969 "Should this cell be barred from access?")
970{
971 struct gsm_bts *bts = vty->index;
972
973 bts->cell_barred = atoi(argv[0]);
974
975 return CMD_SUCCESS;
976}
977
Harald Welte7a8fa412009-08-10 13:48:16 +0200978
Harald Welte5258fc42009-03-28 19:07:53 +0000979/* per TRX configuration */
980DEFUN(cfg_trx,
981 cfg_trx_cmd,
982 "trx TRX_NR",
983 "Select a TRX to configure")
984{
985 int trx_nr = atoi(argv[0]);
986 struct gsm_bts *bts = vty->index;
987 struct gsm_bts_trx *trx;
988
Harald Weltee441d9c2009-06-21 16:17:15 +0200989 if (trx_nr > bts->num_trx) {
990 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
991 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000992 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200993 } else if (trx_nr == bts->num_trx) {
994 /* we need to allocate a new one */
995 trx = gsm_bts_trx_alloc(bts);
996 } else
997 trx = gsm_bts_trx_num(bts, trx_nr);
998
999 if (!trx)
1000 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001001
1002 vty->index = trx;
1003 vty->node = TRX_NODE;
1004
1005 return CMD_SUCCESS;
1006}
1007
1008DEFUN(cfg_trx_arfcn,
1009 cfg_trx_arfcn_cmd,
1010 "arfcn <1-1024>",
1011 "Set the ARFCN for this TRX\n")
1012{
1013 int arfcn = atoi(argv[0]);
1014 struct gsm_bts_trx *trx = vty->index;
1015
1016 /* FIXME: check if this ARFCN is supported by this TRX */
1017
1018 trx->arfcn = arfcn;
1019
1020 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1021 /* FIXME: use OML layer to update the ARFCN */
1022 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1023
1024 return CMD_SUCCESS;
1025}
1026
Harald Weltefcd24452009-06-20 18:15:19 +02001027DEFUN(cfg_trx_max_power_red,
1028 cfg_trx_max_power_red_cmd,
1029 "max_power_red <0-100>",
1030 "Reduction of maximum BS RF Power in dB\n")
1031{
1032 int maxpwr_r = atoi(argv[0]);
1033 struct gsm_bts_trx *trx = vty->index;
1034 int upper_limit = 12; /* default 12.21 max power red. */
1035
1036 /* FIXME: check if our BTS type supports more than 12 */
1037 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1038 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1039 maxpwr_r, VTY_NEWLINE);
1040 return CMD_WARNING;
1041 }
1042 if (maxpwr_r & 1) {
1043 vty_out(vty, "%% Power %d dB is not an even value%s",
1044 maxpwr_r, VTY_NEWLINE);
1045 return CMD_WARNING;
1046 }
1047
1048 trx->max_power_red = maxpwr_r;
1049
1050 /* FIXME: make sure we update this using OML */
1051
1052 return CMD_SUCCESS;
1053}
1054
Harald Welte42581822009-08-08 16:12:58 +02001055DEFUN(cfg_trx_rsl_e1,
1056 cfg_trx_rsl_e1_cmd,
1057 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1058 "E1 interface to be used for RSL\n")
1059{
1060 struct gsm_bts_trx *trx = vty->index;
1061
1062 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1063
1064 return CMD_SUCCESS;
1065}
1066
1067DEFUN(cfg_trx_rsl_e1_tei,
1068 cfg_trx_rsl_e1_tei_cmd,
1069 "rsl e1 tei <0-63>",
1070 "Set the TEI to be used for RSL")
1071{
1072 struct gsm_bts_trx *trx = vty->index;
1073
1074 trx->rsl_tei = atoi(argv[0]);
1075
1076 return CMD_SUCCESS;
1077}
1078
1079
Harald Welte5258fc42009-03-28 19:07:53 +00001080/* per TS configuration */
1081DEFUN(cfg_ts,
1082 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001083 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001084 "Select a Timeslot to configure")
1085{
1086 int ts_nr = atoi(argv[0]);
1087 struct gsm_bts_trx *trx = vty->index;
1088 struct gsm_bts_trx_ts *ts;
1089
1090 if (ts_nr >= TRX_NR_TS) {
1091 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1092 TRX_NR_TS, VTY_NEWLINE);
1093 return CMD_WARNING;
1094 }
1095
1096 ts = &trx->ts[ts_nr];
1097
1098 vty->index = ts;
1099 vty->node = TS_NODE;
1100
1101 return CMD_SUCCESS;
1102}
1103
Harald Weltea6fd58e2009-08-07 00:25:23 +02001104DEFUN(cfg_ts_pchan,
1105 cfg_ts_pchan_cmd,
1106 "phys_chan_config PCHAN",
1107 "Physical Channel configuration (TCH/SDCCH/...)")
1108{
1109 struct gsm_bts_trx_ts *ts = vty->index;
1110 int pchanc;
1111
1112 pchanc = gsm_pchan_parse(argv[0]);
1113 if (pchanc < 0)
1114 return CMD_WARNING;
1115
1116 ts->pchan = pchanc;
1117
1118 return CMD_SUCCESS;
1119}
1120
1121DEFUN(cfg_ts_e1_subslot,
1122 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001123 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001124 "E1 sub-slot connected to this on-air timeslot")
1125{
1126 struct gsm_bts_trx_ts *ts = vty->index;
1127
Harald Welte42581822009-08-08 16:12:58 +02001128 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001129
1130 return CMD_SUCCESS;
1131}
Harald Welte5258fc42009-03-28 19:07:53 +00001132
Harald Welte40f82892009-05-23 17:31:39 +00001133/* Subscriber */
1134DEFUN(show_subscr,
1135 show_subscr_cmd,
1136 "show subscriber [IMSI]",
1137 SHOW_STR "Display information about a subscriber\n")
1138{
1139 const char *imsi;
1140 struct gsm_subscriber *subscr;
1141
1142 if (argc >= 1) {
1143 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +02001144 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +00001145 if (!subscr) {
1146 vty_out(vty, "%% unknown subscriber%s",
1147 VTY_NEWLINE);
1148 return CMD_WARNING;
1149 }
1150 subscr_dump_vty(vty, subscr);
1151
1152 return CMD_SUCCESS;
1153 }
1154
1155 /* FIXME: iterate over all subscribers ? */
1156 return CMD_WARNING;
1157
1158 return CMD_SUCCESS;
1159}
1160
Harald Welte76042182009-08-08 16:03:15 +02001161DEFUN(sms_send_pend,
1162 sms_send_pend_cmd,
1163 "sms send pending MIN_ID",
1164 "Send all pending SMS starting from MIN_ID")
1165{
1166 struct gsm_sms *sms;
1167
1168 sms = db_sms_get_unsent(gsmnet, atoi(argv[0]));
1169 if (!sms)
1170 return CMD_WARNING;
1171
1172 if (!sms->receiver) {
1173 sms_free(sms);
1174 return CMD_WARNING;
1175 }
1176
1177 gsm411_send_sms_subscr(sms->receiver, sms);
1178
1179 return CMD_SUCCESS;
1180}
1181
Harald Weltef9daefd2009-08-09 15:13:54 +02001182static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1183{
1184 struct buffer *b = buffer_new(1024);
1185 int i;
1186
1187 if (!b)
1188 return NULL;
1189
1190 for (i = base; i < argc; i++) {
1191 buffer_putstr(b, argv[i]);
1192 buffer_putc(b, ' ');
1193 }
1194 buffer_putc(b, '\0');
1195
1196 return b;
1197}
1198
Harald Welte8c340fe2009-08-13 00:57:31 +02001199int sms_from_text(struct gsm_subscriber *receiver, const char *text)
Harald Weltef9daefd2009-08-09 15:13:54 +02001200{
1201 struct gsm_sms *sms = sms_alloc();
1202
1203 if (!sms)
1204 return CMD_WARNING;
1205
1206 if (!receiver->lac) {
1207 /* subscriber currently not attached, store in database? */
1208 subscr_put(sms->receiver);
1209 return CMD_WARNING;
1210 }
1211
1212 sms->receiver = receiver;
Harald Welte8c340fe2009-08-13 00:57:31 +02001213 strncpy(sms->text, text, sizeof(sms->text)-1);
Harald Weltef9daefd2009-08-09 15:13:54 +02001214
1215 /* FIXME: don't use ID 1 static */
1216 sms->sender = subscr_get_by_id(gsmnet, 1);
1217 sms->reply_path_req = 0;
1218 sms->status_rep_req = 0;
1219 sms->ud_hdr_ind = 0;
1220 sms->protocol_id = 0; /* implicit */
1221 sms->data_coding_scheme = 0; /* default 7bit */
1222 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1223 /* Generate user_data */
1224 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1225
Harald Welte8c340fe2009-08-13 00:57:31 +02001226 return sms;
1227}
1228
1229static int _send_sms_buffer(struct gsm_subscriber *receiver,
1230 struct buffer *b)
1231{
1232 struct gsm_sms *sms;
1233
1234 sms = sms_from_text(receiver, buffer_getstr(b));
1235
Harald Weltef9daefd2009-08-09 15:13:54 +02001236 gsm411_send_sms_subscr(sms->receiver, sms);
1237
1238 return CMD_SUCCESS;
1239}
1240
Harald Welte76042182009-08-08 16:03:15 +02001241DEFUN(sms_send_ext,
1242 sms_send_ext_cmd,
1243 "sms send extension EXTEN .LINE",
1244 "Send a message to a subscriber identified by EXTEN")
1245{
Harald Weltef9daefd2009-08-09 15:13:54 +02001246 struct gsm_subscriber *receiver;
1247 struct buffer *b;
1248 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001249
Harald Weltef9daefd2009-08-09 15:13:54 +02001250 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1251 if (!receiver)
1252 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001253
Harald Weltef9daefd2009-08-09 15:13:54 +02001254 b = argv_to_buffer(argc, argv, 1);
1255 rc = _send_sms_buffer(receiver, b);
1256 buffer_free(b);
1257
1258 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001259}
1260
1261DEFUN(sms_send_imsi,
1262 sms_send_imsi_cmd,
1263 "sms send imsi IMSI .LINE",
1264 "Send a message to a subscriber identified by IMSI")
1265{
Harald Weltef9daefd2009-08-09 15:13:54 +02001266 struct gsm_subscriber *receiver;
1267 struct buffer *b;
1268 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001269
Harald Weltef9daefd2009-08-09 15:13:54 +02001270 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1271 if (!receiver)
1272 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001273
Harald Weltef9daefd2009-08-09 15:13:54 +02001274 b = argv_to_buffer(argc, argv, 1);
1275 rc = _send_sms_buffer(receiver, b);
1276 buffer_free(b);
1277
1278 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001279}
1280
1281
Harald Welte40f82892009-05-23 17:31:39 +00001282DEFUN(cfg_subscr_name,
1283 cfg_subscr_name_cmd,
1284 "name NAME",
1285 "Set the name of the subscriber")
1286{
1287 const char *name = argv[0];
1288 struct gsm_subscriber *subscr = vty->index;
1289
1290 strncpy(subscr->name, name, sizeof(subscr->name));
1291
1292 db_sync_subscriber(subscr);
1293
1294 return CMD_SUCCESS;
1295}
1296
1297DEFUN(cfg_subscr_extension,
1298 cfg_subscr_extension_cmd,
1299 "extension EXTENSION",
1300 "Set the extension of the subscriber")
1301{
1302 const char *name = argv[0];
1303 struct gsm_subscriber *subscr = vty->index;
1304
1305 strncpy(subscr->extension, name, sizeof(subscr->extension));
1306
1307 db_sync_subscriber(subscr);
1308
1309 return CMD_SUCCESS;
1310}
1311
1312DEFUN(cfg_subscr_authorized,
1313 cfg_subscr_authorized_cmd,
1314 "auth <0-1>",
1315 "Set the authorization status of the subscriber")
1316{
1317 int auth = atoi(argv[0]);
1318 struct gsm_subscriber *subscr = vty->index;
1319
1320 if (auth)
1321 subscr->authorized = 1;
1322 else
1323 subscr->authorized = 0;
1324
1325 db_sync_subscriber(subscr);
1326
1327 return CMD_SUCCESS;
1328}
1329
Harald Welte68628e82009-03-10 12:17:57 +00001330int bsc_vty_init(struct gsm_network *net)
1331{
1332 gsmnet = net;
1333
1334 cmd_init(1);
1335 vty_init();
1336
1337 install_element(VIEW_NODE, &show_net_cmd);
1338 install_element(VIEW_NODE, &show_bts_cmd);
1339 install_element(VIEW_NODE, &show_trx_cmd);
1340 install_element(VIEW_NODE, &show_ts_cmd);
1341 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001342
1343 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001344 install_element(VIEW_NODE, &show_e1line_cmd);
1345 install_element(VIEW_NODE, &show_e1ts_cmd);
1346
Harald Weltef5025b62009-03-28 16:55:11 +00001347 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001348
Harald Welte40f82892009-05-23 17:31:39 +00001349 install_element(VIEW_NODE, &show_subscr_cmd);
1350
Harald Welte76042182009-08-08 16:03:15 +02001351 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001352 install_element(VIEW_NODE, &sms_send_ext_cmd);
1353 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001354
Harald Welte5013b2a2009-08-07 13:29:14 +02001355 install_element(CONFIG_NODE, &cfg_net_cmd);
1356 install_node(&net_node, config_write_net);
1357 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001358 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001359 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1360 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1361 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001362 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001363
1364 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001365 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001366 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001367 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001368 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001369 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1370 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001371 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001372 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001373 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1374 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001375 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001376 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001377
Harald Welte68628e82009-03-10 12:17:57 +00001378
Harald Welte5258fc42009-03-28 19:07:53 +00001379 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001380 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001381 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001382 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001383 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001384 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1385 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001386
Harald Welte5258fc42009-03-28 19:07:53 +00001387 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001388 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001389 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001390 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1391 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001392
Harald Welte40f82892009-05-23 17:31:39 +00001393 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1394 install_node(&subscr_node, dummy_config_write);
1395 install_default(SUBSCR_NODE);
1396 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1397 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1398 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1399
Harald Welte68628e82009-03-10 12:17:57 +00001400 return 0;
1401}