blob: 527d43667820fdfb3db95e56a9155b3a4255f5bd [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 Welte (local)efc92312009-08-14 23:09:25 +0200237 if (bts->chan_desc.t3212)
238 vty_out(vty, " periodic location update %u%s",
239 bts->chan_desc.t3212 * 10, VTY_NEWLINE);
Harald Welte7a8fa412009-08-10 13:48:16 +0200240 vty_out(vty, " channel allocator %s%s",
241 bts->chan_alloc_reverse ? "descending" : "ascending",
242 VTY_NEWLINE);
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200243 if (bts->cell_barred)
244 vty_out(vty, " cell barred 1%s", VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200245 if (is_ipaccess_bts(bts))
Harald Welte5013b2a2009-08-07 13:29:14 +0200246 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200247 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200248 else {
249 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
250 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
251 }
Harald Welte67ce0732009-08-06 19:06:46 +0200252
253 llist_for_each_entry(trx, &bts->trx_list, list)
254 config_write_trx_single(vty, trx);
255}
256
257static int config_write_bts(struct vty *v)
258{
259 struct gsm_bts *bts;
260
261 llist_for_each_entry(bts, &gsmnet->bts_list, list)
262 config_write_bts_single(v, bts);
263
264 return CMD_SUCCESS;
265}
266
Harald Welte5013b2a2009-08-07 13:29:14 +0200267static int config_write_net(struct vty *vty)
268{
269 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200270 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200271 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200272 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
273 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte (local)69de3972009-08-12 14:42:23 +0200274 vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200275
276 return CMD_SUCCESS;
277}
Harald Welte67ce0732009-08-06 19:06:46 +0200278
Harald Welte68628e82009-03-10 12:17:57 +0000279static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
280{
281 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
282 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200283 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200284 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200285 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200286 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000287 vty_out(vty, " NM State: ");
288 net_dump_nmstate(vty, &trx->nm_state);
289 vty_out(vty, " Baseband Transceiver NM State: ");
290 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
291 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
292 e1isl_dump_vty(vty, trx->rsl_link);
293}
294
295DEFUN(show_trx,
296 show_trx_cmd,
297 "show trx [bts_nr] [trx_nr]",
298 SHOW_STR "Display information about a TRX\n")
299{
300 struct gsm_network *net = gsmnet;
301 struct gsm_bts *bts = NULL;
302 struct gsm_bts_trx *trx;
303 int bts_nr, trx_nr;
304
305 if (argc >= 1) {
306 /* use the BTS number that the user has specified */
307 bts_nr = atoi(argv[0]);
308 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000309 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000310 VTY_NEWLINE);
311 return CMD_WARNING;
312 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200313 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000314 }
315 if (argc >= 2) {
316 trx_nr = atoi(argv[1]);
317 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000318 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000319 VTY_NEWLINE);
320 return CMD_WARNING;
321 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200322 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000323 trx_dump_vty(vty, trx);
324 return CMD_SUCCESS;
325 }
326 if (bts) {
327 /* print all TRX in this BTS */
328 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200329 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000330 trx_dump_vty(vty, trx);
331 }
332 return CMD_SUCCESS;
333 }
334
335 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200336 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000337 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200338 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000339 trx_dump_vty(vty, trx);
340 }
341 }
342
343 return CMD_SUCCESS;
344}
345
Harald Welte67ce0732009-08-06 19:06:46 +0200346
Harald Welte68628e82009-03-10 12:17:57 +0000347static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
348{
349 struct in_addr ia;
350
351 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
352 ts->nr, ts->trx->nr, ts->trx->bts->nr,
353 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
354 vty_out(vty, " NM State: ");
355 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000356 if (is_ipaccess_bts(ts->trx->bts)) {
357 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200358 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000359 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200360 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000361 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000362 } else {
363 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
364 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
365 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000366 }
367}
368
369DEFUN(show_ts,
370 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000371 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000372 SHOW_STR "Display information about a TS\n")
373{
374 struct gsm_network *net = gsmnet;
375 struct gsm_bts *bts;
376 struct gsm_bts_trx *trx;
377 struct gsm_bts_trx_ts *ts;
378 int bts_nr, trx_nr, ts_nr;
379
380 if (argc >= 1) {
381 /* use the BTS number that the user has specified */
382 bts_nr = atoi(argv[0]);
383 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000384 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000385 VTY_NEWLINE);
386 return CMD_WARNING;
387 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200388 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000389 }
390 if (argc >= 2) {
391 trx_nr = atoi(argv[1]);
392 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000393 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000394 VTY_NEWLINE);
395 return CMD_WARNING;
396 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200397 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000398 }
399 if (argc >= 3) {
400 ts_nr = atoi(argv[2]);
401 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000402 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000403 VTY_NEWLINE);
404 return CMD_WARNING;
405 }
406 ts = &trx->ts[ts_nr];
407 ts_dump_vty(vty, ts);
408 return CMD_SUCCESS;
409 }
410 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200411 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000412 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200413 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000414 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
415 ts = &trx->ts[ts_nr];
416 ts_dump_vty(vty, ts);
417 }
418 }
419 }
420
421 return CMD_SUCCESS;
422}
423
424static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
425{
Harald Weltefcd24452009-06-20 18:15:19 +0200426 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000427 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000428 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000429 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000430 if (subscr->extension)
431 vty_out(vty, " Extension: %s%s", subscr->extension,
432 VTY_NEWLINE);
433 if (subscr->imsi)
434 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
435 if (subscr->tmsi)
Harald Welte (local)143fd512009-08-14 21:17:44 +0200436 vty_out(vty, " TMSI: %08X", subscr->tmsi, VTY_NEWLINE);
Harald Welte (local)15920de2009-08-14 20:27:16 +0200437 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000438}
439
440static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
441{
442 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
443 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
444 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
445 VTY_NEWLINE);
446 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
447 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
448 lchan->ms_power, VTY_NEWLINE);
449 if (lchan->subscr) {
450 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
451 subscr_dump_vty(vty, lchan->subscr);
452 } else
453 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
454}
455
Harald Welte4bfdfe72009-06-10 23:11:52 +0800456#if 0
457TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000458static void call_dump_vty(struct vty *vty, struct gsm_call *call)
459{
460 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
461 call->type, call->state, call->transaction_id, VTY_NEWLINE);
462
463 if (call->local_lchan) {
464 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
465 lchan_dump_vty(vty, call->local_lchan);
466 } else
467 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
468
469 if (call->remote_lchan) {
470 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
471 lchan_dump_vty(vty, call->remote_lchan);
472 } else
473 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
474
475 if (call->called_subscr) {
476 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
477 subscr_dump_vty(vty, call->called_subscr);
478 } else
479 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
480}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800481#endif
Harald Welte68628e82009-03-10 12:17:57 +0000482
483DEFUN(show_lchan,
484 show_lchan_cmd,
485 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
486 SHOW_STR "Display information about a logical channel\n")
487{
488 struct gsm_network *net = gsmnet;
489 struct gsm_bts *bts;
490 struct gsm_bts_trx *trx;
491 struct gsm_bts_trx_ts *ts;
492 struct gsm_lchan *lchan;
493 int bts_nr, trx_nr, ts_nr, lchan_nr;
494
495 if (argc >= 1) {
496 /* use the BTS number that the user has specified */
497 bts_nr = atoi(argv[0]);
498 if (bts_nr >= net->num_bts) {
499 vty_out(vty, "%% can't find BTS %s%s", argv[0],
500 VTY_NEWLINE);
501 return CMD_WARNING;
502 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200503 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000504 }
505 if (argc >= 2) {
506 trx_nr = atoi(argv[1]);
507 if (trx_nr >= bts->num_trx) {
508 vty_out(vty, "%% can't find TRX %s%s", argv[1],
509 VTY_NEWLINE);
510 return CMD_WARNING;
511 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200512 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000513 }
514 if (argc >= 3) {
515 ts_nr = atoi(argv[2]);
516 if (ts_nr >= TRX_NR_TS) {
517 vty_out(vty, "%% can't find TS %s%s", argv[2],
518 VTY_NEWLINE);
519 return CMD_WARNING;
520 }
521 ts = &trx->ts[ts_nr];
522 }
523 if (argc >= 4) {
524 lchan_nr = atoi(argv[3]);
525 if (lchan_nr >= TS_MAX_LCHAN) {
526 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
527 VTY_NEWLINE);
528 return CMD_WARNING;
529 }
530 lchan = &ts->lchan[lchan_nr];
531 lchan_dump_vty(vty, lchan);
532 return CMD_SUCCESS;
533 }
534 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200535 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000536 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200537 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000538 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
539 ts = &trx->ts[ts_nr];
540 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
541 lchan_nr++) {
542 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000543 if (lchan->type == GSM_LCHAN_NONE)
544 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000545 lchan_dump_vty(vty, lchan);
546 }
547 }
548 }
549 }
550
551 return CMD_SUCCESS;
552}
553
Harald Welte1bc77352009-03-10 19:47:51 +0000554static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
555{
556 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
557}
558
559DEFUN(show_e1drv,
560 show_e1drv_cmd,
561 "show e1_driver",
562 SHOW_STR "Display information about available E1 drivers\n")
563{
564 struct e1inp_driver *drv;
565
566 llist_for_each_entry(drv, &e1inp_driver_list, list)
567 e1drv_dump_vty(vty, drv);
568
569 return CMD_SUCCESS;
570}
571
Harald Welte68628e82009-03-10 12:17:57 +0000572static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
573{
574 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
575 line->num, line->name ? line->name : "",
576 line->driver->name, VTY_NEWLINE);
577}
578
579DEFUN(show_e1line,
580 show_e1line_cmd,
581 "show e1_line [line_nr]",
582 SHOW_STR "Display information about a E1 line\n")
583{
Harald Welte1bc77352009-03-10 19:47:51 +0000584 struct e1inp_line *line;
585
586 if (argc >= 1) {
587 int num = atoi(argv[0]);
588 llist_for_each_entry(line, &e1inp_line_list, list) {
589 if (line->num == num) {
590 e1line_dump_vty(vty, line);
591 return CMD_SUCCESS;
592 }
593 }
594 return CMD_WARNING;
595 }
596
597 llist_for_each_entry(line, &e1inp_line_list, list)
598 e1line_dump_vty(vty, line);
599
600 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000601}
602
603static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
604{
Harald Welte42581822009-08-08 16:12:58 +0200605 if (ts->type == E1INP_TS_TYPE_NONE)
606 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000607 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
608 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
609 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000610}
611
612DEFUN(show_e1ts,
613 show_e1ts_cmd,
614 "show e1_timeslot [line_nr] [ts_nr]",
615 SHOW_STR "Display information about a E1 timeslot\n")
616{
Harald Welte1bc77352009-03-10 19:47:51 +0000617 struct e1inp_line *line;
618 struct e1inp_ts *ts;
619 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000620
Harald Welte1bc77352009-03-10 19:47:51 +0000621 if (argc == 0) {
622 llist_for_each_entry(line, &e1inp_line_list, list) {
623 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
624 ts = &line->ts[ts_nr];
625 e1ts_dump_vty(vty, ts);
626 }
627 }
628 return CMD_SUCCESS;
629 }
630 if (argc >= 1) {
631 int num = atoi(argv[0]);
632 llist_for_each_entry(line, &e1inp_line_list, list) {
633 if (line->num == num)
634 break;
635 }
636 if (!line || line->num != num) {
637 vty_out(vty, "E1 line %s is invalid%s",
638 argv[0], VTY_NEWLINE);
639 return CMD_WARNING;
640 }
641 }
642 if (argc >= 2) {
643 ts_nr = atoi(argv[1]);
644 if (ts_nr > NUM_E1_TS) {
645 vty_out(vty, "E1 timeslot %s is invalid%s",
646 argv[1], VTY_NEWLINE);
647 return CMD_WARNING;
648 }
649 ts = &line->ts[ts_nr];
650 e1ts_dump_vty(vty, ts);
651 return CMD_SUCCESS;
652 } else {
653 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
654 ts = &line->ts[ts_nr];
655 e1ts_dump_vty(vty, ts);
656 }
657 return CMD_SUCCESS;
658 }
659 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000660}
661
Harald Weltebe4b7302009-05-23 16:59:33 +0000662static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000663{
664 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
665 subscr_dump_vty(vty, pag->subscr);
666}
667
Harald Weltebe4b7302009-05-23 16:59:33 +0000668static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000669{
670 struct gsm_paging_request *pag;
671
672 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
673 paging_dump_vty(vty, pag);
674}
675
676DEFUN(show_paging,
677 show_paging_cmd,
678 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000679 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000680{
681 struct gsm_network *net = gsmnet;
682 struct gsm_bts *bts;
683 int bts_nr;
684
685 if (argc >= 1) {
686 /* use the BTS number that the user has specified */
687 bts_nr = atoi(argv[0]);
688 if (bts_nr >= net->num_bts) {
689 vty_out(vty, "%% can't find BTS %s%s", argv[0],
690 VTY_NEWLINE);
691 return CMD_WARNING;
692 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200693 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000694 bts_paging_dump_vty(vty, bts);
695
696 return CMD_SUCCESS;
697 }
698 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200699 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000700 bts_paging_dump_vty(vty, bts);
701 }
702
703 return CMD_SUCCESS;
704}
705
Harald Welte40f82892009-05-23 17:31:39 +0000706/* per-subscriber configuration */
707DEFUN(cfg_subscr,
708 cfg_subscr_cmd,
709 "subscriber IMSI",
710 "Select a Subscriber to configure\n")
711{
712 const char *imsi = argv[0];
713 struct gsm_subscriber *subscr;
714
Harald Welte761e9442009-07-23 19:21:02 +0200715 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000716 if (!subscr) {
717 vty_out(vty, "%% No subscriber for IMSI %s%s",
718 imsi, VTY_NEWLINE);
719 return CMD_WARNING;
720 }
721
722 vty->index = subscr;
723 vty->node = SUBSCR_NODE;
724
725 return CMD_SUCCESS;
726}
727
Harald Welte5013b2a2009-08-07 13:29:14 +0200728DEFUN(cfg_net,
729 cfg_net_cmd,
730 "network",
731 "Configure the GSM network")
732{
733 vty->index = gsmnet;
734 vty->node = GSMNET_NODE;
735
736 return CMD_SUCCESS;
737}
738
739
740DEFUN(cfg_net_ncc,
741 cfg_net_ncc_cmd,
742 "network country code <1-999>",
743 "Set the GSM network country code")
744{
745 gsmnet->country_code = atoi(argv[0]);
746
747 return CMD_SUCCESS;
748}
749
750DEFUN(cfg_net_mnc,
751 cfg_net_mnc_cmd,
752 "mobile network code <1-999>",
753 "Set the GSM mobile network code")
754{
755 gsmnet->network_code = atoi(argv[0]);
756
757 return CMD_SUCCESS;
758}
759
760DEFUN(cfg_net_name_short,
761 cfg_net_name_short_cmd,
762 "short name NAME",
763 "Set the short GSM network name")
764{
765 if (gsmnet->name_short)
766 talloc_free(gsmnet->name_short);
767
768 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
769
770 return CMD_SUCCESS;
771}
772
773DEFUN(cfg_net_name_long,
774 cfg_net_name_long_cmd,
775 "long name NAME",
776 "Set the long GSM network name")
777{
778 if (gsmnet->name_long)
779 talloc_free(gsmnet->name_long);
780
781 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
782
783 return CMD_SUCCESS;
784}
Harald Welte40f82892009-05-23 17:31:39 +0000785
Harald Welte (local)69de3972009-08-12 14:42:23 +0200786DEFUN(cfg_net_auth_policy,
787 cfg_net_auth_policy_cmd,
788 "auth policy (closed|accept-all|token)",
789 "Set the GSM network authentication policy\n")
790{
791 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
792
793 gsmnet->auth_policy = policy;
794
795 return CMD_SUCCESS;
796}
797
Harald Welte5258fc42009-03-28 19:07:53 +0000798/* per-BTS configuration */
799DEFUN(cfg_bts,
800 cfg_bts_cmd,
801 "bts BTS_NR",
802 "Select a BTS to configure\n")
803{
804 int bts_nr = atoi(argv[0]);
805 struct gsm_bts *bts;
806
Harald Weltee441d9c2009-06-21 16:17:15 +0200807 if (bts_nr > gsmnet->num_bts) {
808 vty_out(vty, "%% The next unused BTS number is %u%s",
809 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000810 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200811 } else if (bts_nr == gsmnet->num_bts) {
812 /* allocate a new one */
813 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
814 HARDCODED_TSC, HARDCODED_BSIC);
815 } else
816 bts = gsm_bts_num(gsmnet, bts_nr);
817
818 if (!bts)
819 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000820
821 vty->index = bts;
822 vty->node = BTS_NODE;
823
824 return CMD_SUCCESS;
825}
826
827DEFUN(cfg_bts_type,
828 cfg_bts_type_cmd,
829 "type TYPE",
830 "Set the BTS type\n")
831{
832 struct gsm_bts *bts = vty->index;
833
Harald Weltea6fd58e2009-08-07 00:25:23 +0200834 bts->type = parse_btstype(argv[0]);
835
Harald Welte5258fc42009-03-28 19:07:53 +0000836 return CMD_SUCCESS;
837}
838
Harald Weltefcd24452009-06-20 18:15:19 +0200839DEFUN(cfg_bts_band,
840 cfg_bts_band_cmd,
841 "band BAND",
842 "Set the frequency band of this BTS\n")
843{
844 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200845 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200846
847 if (band < 0) {
848 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
849 band, VTY_NEWLINE);
850 return CMD_WARNING;
851 }
852
853 bts->band = band;
854
855 return CMD_SUCCESS;
856}
857
Harald Welte5258fc42009-03-28 19:07:53 +0000858DEFUN(cfg_bts_lac,
859 cfg_bts_lac_cmd,
860 "location_area_code <0-255>",
861 "Set the Location Area Code (LAC) of this BTS\n")
862{
863 struct gsm_bts *bts = vty->index;
864 int lac = atoi(argv[0]);
865
866 if (lac < 0 || lac > 0xff) {
867 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
868 lac, VTY_NEWLINE);
869 return CMD_WARNING;
870 }
871 bts->location_area_code = lac;
872
873 return CMD_SUCCESS;
874}
875
876DEFUN(cfg_bts_tsc,
877 cfg_bts_tsc_cmd,
878 "training_sequence_code <0-255>",
879 "Set the Training Sequence Code (TSC) of this BTS\n")
880{
881 struct gsm_bts *bts = vty->index;
882 int tsc = atoi(argv[0]);
883
884 if (tsc < 0 || tsc > 0xff) {
885 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
886 tsc, VTY_NEWLINE);
887 return CMD_WARNING;
888 }
889 bts->tsc = tsc;
890
891 return CMD_SUCCESS;
892}
893
Harald Welte78f2f502009-05-23 16:56:52 +0000894DEFUN(cfg_bts_bsic,
895 cfg_bts_bsic_cmd,
896 "base_station_id_code <0-63>",
897 "Set the Base Station Identity Code (BSIC) of this BTS\n")
898{
899 struct gsm_bts *bts = vty->index;
900 int bsic = atoi(argv[0]);
901
902 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200903 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000904 bsic, VTY_NEWLINE);
905 return CMD_WARNING;
906 }
907 bts->bsic = bsic;
908
909 return CMD_SUCCESS;
910}
911
912
Harald Welte4cc34222009-05-01 15:12:31 +0000913DEFUN(cfg_bts_unit_id,
914 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200915 "ip.access unit_id <0-65534> <0-255>",
916 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000917{
918 struct gsm_bts *bts = vty->index;
919 int site_id = atoi(argv[0]);
920 int bts_id = atoi(argv[1]);
921
Harald Welte07dc73d2009-08-07 13:27:09 +0200922 if (!is_ipaccess_bts(bts)) {
923 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
924 return CMD_WARNING;
925 }
926
Harald Welte4cc34222009-05-01 15:12:31 +0000927 bts->ip_access.site_id = site_id;
928 bts->ip_access.bts_id = bts_id;
929
930 return CMD_SUCCESS;
931}
932
Harald Welte42581822009-08-08 16:12:58 +0200933DEFUN(cfg_bts_oml_e1,
934 cfg_bts_oml_e1_cmd,
935 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
936 "E1 interface to be used for OML\n")
937{
938 struct gsm_bts *bts = vty->index;
939
940 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
941
942 return CMD_SUCCESS;
943}
944
945
946DEFUN(cfg_bts_oml_e1_tei,
947 cfg_bts_oml_e1_tei_cmd,
948 "oml e1 tei <0-63>",
949 "Set the TEI to be used for OML")
950{
951 struct gsm_bts *bts = vty->index;
952
953 bts->oml_tei = atoi(argv[0]);
954
955 return CMD_SUCCESS;
956}
957
Harald Welte7a8fa412009-08-10 13:48:16 +0200958DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd,
959 "channel allocator (ascending|descending)",
960 "Should the channel allocator allocate in reverse TRX order?")
961{
962 struct gsm_bts *bts = vty->index;
963
964 if (!strcmp(argv[0], "ascending"))
965 bts->chan_alloc_reverse = 0;
966 else
967 bts->chan_alloc_reverse = 1;
968
969 return CMD_SUCCESS;
970}
971
Harald Welte (local)5dececf2009-08-12 13:28:23 +0200972DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
973 "cell barred (0|1)",
974 "Should this cell be barred from access?")
975{
976 struct gsm_bts *bts = vty->index;
977
978 bts->cell_barred = atoi(argv[0]);
979
980 return CMD_SUCCESS;
981}
982
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200983DEFUN(cfg_bts_ms_max_power, cfg_bts_ms_max_power_cmd,
984 "ms max power <0-40>",
985 "Maximum transmit power of the MS")
986{
987 struct gsm_bts *bts = vty->index;
988
989 bts->ms_max_power = atoi(argv[0]);
990
991 return CMD_SUCCESS;
992}
993
Harald Welte (local)efc92312009-08-14 23:09:25 +0200994DEFUN(cfg_bts_per_loc_upd, cfg_bts_per_loc_upd_cmd,
995 "periodic location update <0-1530>",
996 "Periodic Location Updating Interval in Minutes")
997{
998 struct gsm_bts *bts = vty->index;
999
1000 bts->chan_desc.t3212 = atoi(argv[0]) / 10;
1001
1002 return CMD_SUCCESS;
1003}
1004
Harald Welte7a8fa412009-08-10 13:48:16 +02001005
Harald Welte5258fc42009-03-28 19:07:53 +00001006/* per TRX configuration */
1007DEFUN(cfg_trx,
1008 cfg_trx_cmd,
1009 "trx TRX_NR",
1010 "Select a TRX to configure")
1011{
1012 int trx_nr = atoi(argv[0]);
1013 struct gsm_bts *bts = vty->index;
1014 struct gsm_bts_trx *trx;
1015
Harald Weltee441d9c2009-06-21 16:17:15 +02001016 if (trx_nr > bts->num_trx) {
1017 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
1018 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +00001019 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +02001020 } else if (trx_nr == bts->num_trx) {
1021 /* we need to allocate a new one */
1022 trx = gsm_bts_trx_alloc(bts);
1023 } else
1024 trx = gsm_bts_trx_num(bts, trx_nr);
1025
1026 if (!trx)
1027 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +00001028
1029 vty->index = trx;
1030 vty->node = TRX_NODE;
1031
1032 return CMD_SUCCESS;
1033}
1034
1035DEFUN(cfg_trx_arfcn,
1036 cfg_trx_arfcn_cmd,
1037 "arfcn <1-1024>",
1038 "Set the ARFCN for this TRX\n")
1039{
1040 int arfcn = atoi(argv[0]);
1041 struct gsm_bts_trx *trx = vty->index;
1042
1043 /* FIXME: check if this ARFCN is supported by this TRX */
1044
1045 trx->arfcn = arfcn;
1046
1047 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
1048 /* FIXME: use OML layer to update the ARFCN */
1049 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
1050
1051 return CMD_SUCCESS;
1052}
1053
Harald Weltefcd24452009-06-20 18:15:19 +02001054DEFUN(cfg_trx_max_power_red,
1055 cfg_trx_max_power_red_cmd,
1056 "max_power_red <0-100>",
1057 "Reduction of maximum BS RF Power in dB\n")
1058{
1059 int maxpwr_r = atoi(argv[0]);
1060 struct gsm_bts_trx *trx = vty->index;
1061 int upper_limit = 12; /* default 12.21 max power red. */
1062
1063 /* FIXME: check if our BTS type supports more than 12 */
1064 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1065 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1066 maxpwr_r, VTY_NEWLINE);
1067 return CMD_WARNING;
1068 }
1069 if (maxpwr_r & 1) {
1070 vty_out(vty, "%% Power %d dB is not an even value%s",
1071 maxpwr_r, VTY_NEWLINE);
1072 return CMD_WARNING;
1073 }
1074
1075 trx->max_power_red = maxpwr_r;
1076
1077 /* FIXME: make sure we update this using OML */
1078
1079 return CMD_SUCCESS;
1080}
1081
Harald Welte42581822009-08-08 16:12:58 +02001082DEFUN(cfg_trx_rsl_e1,
1083 cfg_trx_rsl_e1_cmd,
1084 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1085 "E1 interface to be used for RSL\n")
1086{
1087 struct gsm_bts_trx *trx = vty->index;
1088
1089 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1090
1091 return CMD_SUCCESS;
1092}
1093
1094DEFUN(cfg_trx_rsl_e1_tei,
1095 cfg_trx_rsl_e1_tei_cmd,
1096 "rsl e1 tei <0-63>",
1097 "Set the TEI to be used for RSL")
1098{
1099 struct gsm_bts_trx *trx = vty->index;
1100
1101 trx->rsl_tei = atoi(argv[0]);
1102
1103 return CMD_SUCCESS;
1104}
1105
1106
Harald Welte5258fc42009-03-28 19:07:53 +00001107/* per TS configuration */
1108DEFUN(cfg_ts,
1109 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001110 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001111 "Select a Timeslot to configure")
1112{
1113 int ts_nr = atoi(argv[0]);
1114 struct gsm_bts_trx *trx = vty->index;
1115 struct gsm_bts_trx_ts *ts;
1116
1117 if (ts_nr >= TRX_NR_TS) {
1118 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1119 TRX_NR_TS, VTY_NEWLINE);
1120 return CMD_WARNING;
1121 }
1122
1123 ts = &trx->ts[ts_nr];
1124
1125 vty->index = ts;
1126 vty->node = TS_NODE;
1127
1128 return CMD_SUCCESS;
1129}
1130
Harald Weltea6fd58e2009-08-07 00:25:23 +02001131DEFUN(cfg_ts_pchan,
1132 cfg_ts_pchan_cmd,
1133 "phys_chan_config PCHAN",
1134 "Physical Channel configuration (TCH/SDCCH/...)")
1135{
1136 struct gsm_bts_trx_ts *ts = vty->index;
1137 int pchanc;
1138
1139 pchanc = gsm_pchan_parse(argv[0]);
1140 if (pchanc < 0)
1141 return CMD_WARNING;
1142
1143 ts->pchan = pchanc;
1144
1145 return CMD_SUCCESS;
1146}
1147
1148DEFUN(cfg_ts_e1_subslot,
1149 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001150 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001151 "E1 sub-slot connected to this on-air timeslot")
1152{
1153 struct gsm_bts_trx_ts *ts = vty->index;
1154
Harald Welte42581822009-08-08 16:12:58 +02001155 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001156
1157 return CMD_SUCCESS;
1158}
Harald Welte5258fc42009-03-28 19:07:53 +00001159
Harald Welte40f82892009-05-23 17:31:39 +00001160/* Subscriber */
1161DEFUN(show_subscr,
1162 show_subscr_cmd,
1163 "show subscriber [IMSI]",
1164 SHOW_STR "Display information about a subscriber\n")
1165{
1166 const char *imsi;
1167 struct gsm_subscriber *subscr;
1168
1169 if (argc >= 1) {
1170 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +02001171 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +00001172 if (!subscr) {
1173 vty_out(vty, "%% unknown subscriber%s",
1174 VTY_NEWLINE);
1175 return CMD_WARNING;
1176 }
1177 subscr_dump_vty(vty, subscr);
1178
1179 return CMD_SUCCESS;
1180 }
1181
1182 /* FIXME: iterate over all subscribers ? */
1183 return CMD_WARNING;
1184
1185 return CMD_SUCCESS;
1186}
1187
Harald Welte (local)15920de2009-08-14 20:27:16 +02001188DEFUN(show_subscr_cache,
1189 show_subscr_cache_cmd,
1190 "show subscriber cache",
1191 SHOW_STR "Display contents of subscriber cache\n")
1192{
1193 struct gsm_subscriber *subscr;
1194
1195 llist_for_each_entry(subscr, &active_subscribers, entry) {
1196 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
1197 subscr_dump_vty(vty, subscr);
1198 }
1199
1200 return CMD_SUCCESS;
1201}
1202
Harald Welte76042182009-08-08 16:03:15 +02001203DEFUN(sms_send_pend,
1204 sms_send_pend_cmd,
1205 "sms send pending MIN_ID",
1206 "Send all pending SMS starting from MIN_ID")
1207{
1208 struct gsm_sms *sms;
Harald Welte (local)05e67632009-08-14 16:01:20 +02001209 int id = atoi(argv[0]);
Harald Welte76042182009-08-08 16:03:15 +02001210
Harald Welte (local)05e67632009-08-14 16:01:20 +02001211 while (1) {
1212 sms = db_sms_get_unsent(gsmnet, id++);
1213 if (!sms)
1214 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001215
Harald Welte (local)05e67632009-08-14 16:01:20 +02001216 if (!sms->receiver) {
1217 sms_free(sms);
1218 continue;
1219 }
1220
1221 gsm411_send_sms_subscr(sms->receiver, sms);
Harald Welte76042182009-08-08 16:03:15 +02001222 }
1223
Harald Welte76042182009-08-08 16:03:15 +02001224 return CMD_SUCCESS;
1225}
1226
Harald Weltef9daefd2009-08-09 15:13:54 +02001227static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1228{
1229 struct buffer *b = buffer_new(1024);
1230 int i;
1231
1232 if (!b)
1233 return NULL;
1234
1235 for (i = base; i < argc; i++) {
1236 buffer_putstr(b, argv[i]);
1237 buffer_putc(b, ' ');
1238 }
1239 buffer_putc(b, '\0');
1240
1241 return b;
1242}
1243
Harald Welte8c340fe2009-08-13 00:57:31 +02001244int sms_from_text(struct gsm_subscriber *receiver, const char *text)
Harald Weltef9daefd2009-08-09 15:13:54 +02001245{
1246 struct gsm_sms *sms = sms_alloc();
1247
1248 if (!sms)
1249 return CMD_WARNING;
1250
1251 if (!receiver->lac) {
1252 /* subscriber currently not attached, store in database? */
Harald Weltef9daefd2009-08-09 15:13:54 +02001253 return CMD_WARNING;
1254 }
1255
Harald Welte (local)571602f2009-08-13 13:25:32 +02001256 sms->receiver = subscr_get(receiver);
Harald Welte8c340fe2009-08-13 00:57:31 +02001257 strncpy(sms->text, text, sizeof(sms->text)-1);
Harald Weltef9daefd2009-08-09 15:13:54 +02001258
1259 /* FIXME: don't use ID 1 static */
1260 sms->sender = subscr_get_by_id(gsmnet, 1);
1261 sms->reply_path_req = 0;
1262 sms->status_rep_req = 0;
1263 sms->ud_hdr_ind = 0;
1264 sms->protocol_id = 0; /* implicit */
1265 sms->data_coding_scheme = 0; /* default 7bit */
1266 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1267 /* Generate user_data */
1268 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1269
Harald Welte8c340fe2009-08-13 00:57:31 +02001270 return sms;
1271}
1272
1273static int _send_sms_buffer(struct gsm_subscriber *receiver,
1274 struct buffer *b)
1275{
1276 struct gsm_sms *sms;
1277
1278 sms = sms_from_text(receiver, buffer_getstr(b));
1279
Harald Welte (local)571602f2009-08-13 13:25:32 +02001280 gsm411_send_sms_subscr(receiver, sms);
Harald Weltef9daefd2009-08-09 15:13:54 +02001281
1282 return CMD_SUCCESS;
1283}
1284
Harald Welte76042182009-08-08 16:03:15 +02001285DEFUN(sms_send_ext,
1286 sms_send_ext_cmd,
1287 "sms send extension EXTEN .LINE",
1288 "Send a message to a subscriber identified by EXTEN")
1289{
Harald Weltef9daefd2009-08-09 15:13:54 +02001290 struct gsm_subscriber *receiver;
1291 struct buffer *b;
1292 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001293
Harald Weltef9daefd2009-08-09 15:13:54 +02001294 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1295 if (!receiver)
1296 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001297
Harald Weltef9daefd2009-08-09 15:13:54 +02001298 b = argv_to_buffer(argc, argv, 1);
1299 rc = _send_sms_buffer(receiver, b);
1300 buffer_free(b);
1301
1302 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001303}
1304
1305DEFUN(sms_send_imsi,
1306 sms_send_imsi_cmd,
1307 "sms send imsi IMSI .LINE",
1308 "Send a message to a subscriber identified by IMSI")
1309{
Harald Weltef9daefd2009-08-09 15:13:54 +02001310 struct gsm_subscriber *receiver;
1311 struct buffer *b;
1312 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001313
Harald Weltef9daefd2009-08-09 15:13:54 +02001314 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1315 if (!receiver)
1316 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001317
Harald Weltef9daefd2009-08-09 15:13:54 +02001318 b = argv_to_buffer(argc, argv, 1);
1319 rc = _send_sms_buffer(receiver, b);
1320 buffer_free(b);
1321
1322 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001323}
1324
1325
Harald Welte40f82892009-05-23 17:31:39 +00001326DEFUN(cfg_subscr_name,
1327 cfg_subscr_name_cmd,
1328 "name NAME",
1329 "Set the name of the subscriber")
1330{
1331 const char *name = argv[0];
1332 struct gsm_subscriber *subscr = vty->index;
1333
1334 strncpy(subscr->name, name, sizeof(subscr->name));
1335
1336 db_sync_subscriber(subscr);
1337
1338 return CMD_SUCCESS;
1339}
1340
1341DEFUN(cfg_subscr_extension,
1342 cfg_subscr_extension_cmd,
1343 "extension EXTENSION",
1344 "Set the extension of the subscriber")
1345{
1346 const char *name = argv[0];
1347 struct gsm_subscriber *subscr = vty->index;
1348
1349 strncpy(subscr->extension, name, sizeof(subscr->extension));
1350
1351 db_sync_subscriber(subscr);
1352
1353 return CMD_SUCCESS;
1354}
1355
1356DEFUN(cfg_subscr_authorized,
1357 cfg_subscr_authorized_cmd,
1358 "auth <0-1>",
1359 "Set the authorization status of the subscriber")
1360{
1361 int auth = atoi(argv[0]);
1362 struct gsm_subscriber *subscr = vty->index;
1363
1364 if (auth)
1365 subscr->authorized = 1;
1366 else
1367 subscr->authorized = 0;
1368
1369 db_sync_subscriber(subscr);
1370
1371 return CMD_SUCCESS;
1372}
1373
Harald Welte68628e82009-03-10 12:17:57 +00001374int bsc_vty_init(struct gsm_network *net)
1375{
1376 gsmnet = net;
1377
1378 cmd_init(1);
1379 vty_init();
1380
1381 install_element(VIEW_NODE, &show_net_cmd);
1382 install_element(VIEW_NODE, &show_bts_cmd);
1383 install_element(VIEW_NODE, &show_trx_cmd);
1384 install_element(VIEW_NODE, &show_ts_cmd);
1385 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001386
1387 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001388 install_element(VIEW_NODE, &show_e1line_cmd);
1389 install_element(VIEW_NODE, &show_e1ts_cmd);
1390
Harald Weltef5025b62009-03-28 16:55:11 +00001391 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001392
Harald Welte40f82892009-05-23 17:31:39 +00001393 install_element(VIEW_NODE, &show_subscr_cmd);
Harald Welte (local)15920de2009-08-14 20:27:16 +02001394 install_element(VIEW_NODE, &show_subscr_cache_cmd);
Harald Welte40f82892009-05-23 17:31:39 +00001395
Harald Welte76042182009-08-08 16:03:15 +02001396 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001397 install_element(VIEW_NODE, &sms_send_ext_cmd);
1398 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001399
Harald Welte5013b2a2009-08-07 13:29:14 +02001400 install_element(CONFIG_NODE, &cfg_net_cmd);
1401 install_node(&net_node, config_write_net);
1402 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001403 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001404 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1405 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1406 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Harald Welte (local)69de3972009-08-12 14:42:23 +02001407 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001408
1409 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001410 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001411 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001412 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001413 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001414 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1415 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001416 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001417 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001418 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1419 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001420 install_element(BTS_NODE, &cfg_bts_challoc_cmd);
Harald Welte (local)5dececf2009-08-12 13:28:23 +02001421 install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001422 install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
Harald Welte (local)efc92312009-08-14 23:09:25 +02001423 install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
Harald Welte7a8fa412009-08-10 13:48:16 +02001424
Harald Welte68628e82009-03-10 12:17:57 +00001425
Harald Welte5258fc42009-03-28 19:07:53 +00001426 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001427 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001428 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001429 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001430 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001431 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1432 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001433
Harald Welte5258fc42009-03-28 19:07:53 +00001434 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001435 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001436 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001437 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1438 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001439
Harald Welte40f82892009-05-23 17:31:39 +00001440 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1441 install_node(&subscr_node, dummy_config_write);
1442 install_default(SUBSCR_NODE);
1443 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1444 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1445 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1446
Harald Welte68628e82009-03-10 12:17:57 +00001447 return 0;
1448}