blob: 1fe65df66248388e1b77eb10b9690d2a70e8b3c6 [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);
94}
95
96DEFUN(show_net, show_net_cmd, "show network",
97 SHOW_STR "Display information about a GSM NETWORK\n")
98{
99 struct gsm_network *net = gsmnet;
100 net_dump_vty(vty, net);
101
102 return CMD_SUCCESS;
103}
104
105static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
106{
Harald Welteedb37782009-05-01 14:59:07 +0000107 struct e1inp_line *line;
108
109 if (!e1l) {
110 vty_out(vty, " None%s", VTY_NEWLINE);
111 return;
112 }
113
114 line = e1l->ts->line;
115
116 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
117 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000118 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000119 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000120 e1l->tei, e1l->sapi, VTY_NEWLINE);
121}
122
123static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
124{
Harald Weltefcd24452009-06-20 18:15:19 +0200125 vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, "
126 "BSIC %u, TSC %u and %u TRX%s",
127 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
128 bts->location_area_code, bts->bsic, bts->tsc,
129 bts->num_trx, VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000130 if (is_ipaccess_bts(bts))
131 vty_out(vty, " Unit ID: %u/%u/0%s",
132 bts->ip_access.site_id, bts->ip_access.bts_id,
133 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000134 vty_out(vty, " NM State: ");
135 net_dump_nmstate(vty, &bts->nm_state);
136 vty_out(vty, " Site Mgr NM State: ");
137 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
138 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
139 bts->paging.available_slots, VTY_NEWLINE);
140 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
141 e1isl_dump_vty(vty, bts->oml_link);
142 /* FIXME: oml_link, chan_desc */
143}
144
145DEFUN(show_bts, show_bts_cmd, "show bts [number]",
146 SHOW_STR "Display information about a BTS\n"
147 "BTS number")
148{
149 struct gsm_network *net = gsmnet;
150 int bts_nr;
151
152 if (argc != 0) {
153 /* use the BTS number that the user has specified */
154 bts_nr = atoi(argv[0]);
155 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000156 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000157 VTY_NEWLINE);
158 return CMD_WARNING;
159 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200160 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000161 return CMD_SUCCESS;
162 }
163 /* print all BTS's */
164 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200165 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000166
167 return CMD_SUCCESS;
168}
169
Harald Welte42581822009-08-08 16:12:58 +0200170/* utility functions */
171static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
172 const char *ts, const char *ss)
173{
174 e1_link->e1_nr = atoi(line);
175 e1_link->e1_ts = atoi(ts);
176 if (!strcmp(ss, "full"))
177 e1_link->e1_ts_ss = 255;
178 else
179 e1_link->e1_ts_ss = atoi(ss);
180}
181
182static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link,
183 const char *prefix)
184{
185 if (!e1_link->e1_ts)
186 return;
187
188 if (e1_link->e1_ts_ss == 255)
189 vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s",
190 prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE);
191 else
192 vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s",
193 prefix, e1_link->e1_nr, e1_link->e1_ts,
194 e1_link->e1_ts_ss, VTY_NEWLINE);
195}
196
197
Harald Welte67ce0732009-08-06 19:06:46 +0200198static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
199{
Harald Welte42581822009-08-08 16:12:58 +0200200 vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
201 if (ts->pchan != GSM_PCHAN_NONE)
202 vty_out(vty, " phys_chan_config %s%s",
203 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
204 config_write_e1_link(vty, &ts->e1_link, " ");
Harald Welte67ce0732009-08-06 19:06:46 +0200205}
206
207static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
208{
209 int i;
210
Harald Welte5013b2a2009-08-07 13:29:14 +0200211 vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE);
212 vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE);
213 vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200214 config_write_e1_link(vty, &trx->rsl_e1_link, " rsl ");
215 vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200216
217 for (i = 0; i < TRX_NR_TS; i++)
218 config_write_ts_single(vty, &trx->ts[i]);
219}
220
221static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
222{
223 struct gsm_bts_trx *trx;
224
Harald Welte5013b2a2009-08-07 13:29:14 +0200225 vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE);
226 vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE);
227 vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
228 vty_out(vty, " location_area_code %u%s", bts->location_area_code,
Harald Welte67ce0732009-08-06 19:06:46 +0200229 VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200230 vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
231 vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200232 if (is_ipaccess_bts(bts))
Harald Welte5013b2a2009-08-07 13:29:14 +0200233 vty_out(vty, " ip.access unit_id %u %u%s",
Harald Weltea6fd58e2009-08-07 00:25:23 +0200234 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200235 else {
236 config_write_e1_link(vty, &bts->oml_e1_link, " oml ");
237 vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
238 }
Harald Welte67ce0732009-08-06 19:06:46 +0200239
240 llist_for_each_entry(trx, &bts->trx_list, list)
241 config_write_trx_single(vty, trx);
242}
243
244static int config_write_bts(struct vty *v)
245{
246 struct gsm_bts *bts;
247
248 llist_for_each_entry(bts, &gsmnet->bts_list, list)
249 config_write_bts_single(v, bts);
250
251 return CMD_SUCCESS;
252}
253
Harald Welte5013b2a2009-08-07 13:29:14 +0200254static int config_write_net(struct vty *vty)
255{
256 vty_out(vty, "network%s", VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200257 vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200258 vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
Harald Welte42581822009-08-08 16:12:58 +0200259 vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
260 vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
Harald Welte5013b2a2009-08-07 13:29:14 +0200261
262 return CMD_SUCCESS;
263}
Harald Welte67ce0732009-08-06 19:06:46 +0200264
Harald Welte68628e82009-03-10 12:17:57 +0000265static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
266{
267 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
268 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200269 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
Harald Welte42581822009-08-08 16:12:58 +0200270 "resulting BS power: %d dBm%s",
Harald Weltefcd24452009-06-20 18:15:19 +0200271 trx->nominal_power, trx->max_power_red,
Harald Welte42581822009-08-08 16:12:58 +0200272 trx->nominal_power - trx->max_power_red, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000273 vty_out(vty, " NM State: ");
274 net_dump_nmstate(vty, &trx->nm_state);
275 vty_out(vty, " Baseband Transceiver NM State: ");
276 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
277 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
278 e1isl_dump_vty(vty, trx->rsl_link);
279}
280
281DEFUN(show_trx,
282 show_trx_cmd,
283 "show trx [bts_nr] [trx_nr]",
284 SHOW_STR "Display information about a TRX\n")
285{
286 struct gsm_network *net = gsmnet;
287 struct gsm_bts *bts = NULL;
288 struct gsm_bts_trx *trx;
289 int bts_nr, trx_nr;
290
291 if (argc >= 1) {
292 /* use the BTS number that the user has specified */
293 bts_nr = atoi(argv[0]);
294 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000295 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000296 VTY_NEWLINE);
297 return CMD_WARNING;
298 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200299 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000300 }
301 if (argc >= 2) {
302 trx_nr = atoi(argv[1]);
303 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000304 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000305 VTY_NEWLINE);
306 return CMD_WARNING;
307 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200308 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000309 trx_dump_vty(vty, trx);
310 return CMD_SUCCESS;
311 }
312 if (bts) {
313 /* print all TRX in this BTS */
314 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200315 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000316 trx_dump_vty(vty, trx);
317 }
318 return CMD_SUCCESS;
319 }
320
321 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200322 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000323 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200324 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000325 trx_dump_vty(vty, trx);
326 }
327 }
328
329 return CMD_SUCCESS;
330}
331
Harald Welte67ce0732009-08-06 19:06:46 +0200332
Harald Welte68628e82009-03-10 12:17:57 +0000333static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
334{
335 struct in_addr ia;
336
337 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
338 ts->nr, ts->trx->nr, ts->trx->bts->nr,
339 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
340 vty_out(vty, " NM State: ");
341 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000342 if (is_ipaccess_bts(ts->trx->bts)) {
343 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200344 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000345 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200346 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000347 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000348 } else {
349 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
350 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
351 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000352 }
353}
354
355DEFUN(show_ts,
356 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000357 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000358 SHOW_STR "Display information about a TS\n")
359{
360 struct gsm_network *net = gsmnet;
361 struct gsm_bts *bts;
362 struct gsm_bts_trx *trx;
363 struct gsm_bts_trx_ts *ts;
364 int bts_nr, trx_nr, ts_nr;
365
366 if (argc >= 1) {
367 /* use the BTS number that the user has specified */
368 bts_nr = atoi(argv[0]);
369 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000370 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000371 VTY_NEWLINE);
372 return CMD_WARNING;
373 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200374 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000375 }
376 if (argc >= 2) {
377 trx_nr = atoi(argv[1]);
378 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000379 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000380 VTY_NEWLINE);
381 return CMD_WARNING;
382 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200383 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000384 }
385 if (argc >= 3) {
386 ts_nr = atoi(argv[2]);
387 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000388 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000389 VTY_NEWLINE);
390 return CMD_WARNING;
391 }
392 ts = &trx->ts[ts_nr];
393 ts_dump_vty(vty, ts);
394 return CMD_SUCCESS;
395 }
396 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200397 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000398 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200399 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000400 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
401 ts = &trx->ts[ts_nr];
402 ts_dump_vty(vty, ts);
403 }
404 }
405 }
406
407 return CMD_SUCCESS;
408}
409
410static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
411{
Harald Weltefcd24452009-06-20 18:15:19 +0200412 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000413 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000414 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000415 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000416 if (subscr->extension)
417 vty_out(vty, " Extension: %s%s", subscr->extension,
418 VTY_NEWLINE);
419 if (subscr->imsi)
420 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
421 if (subscr->tmsi)
422 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
423}
424
425static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
426{
427 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
428 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
429 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
430 VTY_NEWLINE);
431 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
432 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
433 lchan->ms_power, VTY_NEWLINE);
434 if (lchan->subscr) {
435 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
436 subscr_dump_vty(vty, lchan->subscr);
437 } else
438 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
439}
440
Harald Welte4bfdfe72009-06-10 23:11:52 +0800441#if 0
442TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000443static void call_dump_vty(struct vty *vty, struct gsm_call *call)
444{
445 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
446 call->type, call->state, call->transaction_id, VTY_NEWLINE);
447
448 if (call->local_lchan) {
449 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
450 lchan_dump_vty(vty, call->local_lchan);
451 } else
452 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
453
454 if (call->remote_lchan) {
455 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
456 lchan_dump_vty(vty, call->remote_lchan);
457 } else
458 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
459
460 if (call->called_subscr) {
461 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
462 subscr_dump_vty(vty, call->called_subscr);
463 } else
464 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
465}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800466#endif
Harald Welte68628e82009-03-10 12:17:57 +0000467
468DEFUN(show_lchan,
469 show_lchan_cmd,
470 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
471 SHOW_STR "Display information about a logical channel\n")
472{
473 struct gsm_network *net = gsmnet;
474 struct gsm_bts *bts;
475 struct gsm_bts_trx *trx;
476 struct gsm_bts_trx_ts *ts;
477 struct gsm_lchan *lchan;
478 int bts_nr, trx_nr, ts_nr, lchan_nr;
479
480 if (argc >= 1) {
481 /* use the BTS number that the user has specified */
482 bts_nr = atoi(argv[0]);
483 if (bts_nr >= net->num_bts) {
484 vty_out(vty, "%% can't find BTS %s%s", argv[0],
485 VTY_NEWLINE);
486 return CMD_WARNING;
487 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200488 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000489 }
490 if (argc >= 2) {
491 trx_nr = atoi(argv[1]);
492 if (trx_nr >= bts->num_trx) {
493 vty_out(vty, "%% can't find TRX %s%s", argv[1],
494 VTY_NEWLINE);
495 return CMD_WARNING;
496 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200497 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000498 }
499 if (argc >= 3) {
500 ts_nr = atoi(argv[2]);
501 if (ts_nr >= TRX_NR_TS) {
502 vty_out(vty, "%% can't find TS %s%s", argv[2],
503 VTY_NEWLINE);
504 return CMD_WARNING;
505 }
506 ts = &trx->ts[ts_nr];
507 }
508 if (argc >= 4) {
509 lchan_nr = atoi(argv[3]);
510 if (lchan_nr >= TS_MAX_LCHAN) {
511 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
512 VTY_NEWLINE);
513 return CMD_WARNING;
514 }
515 lchan = &ts->lchan[lchan_nr];
516 lchan_dump_vty(vty, lchan);
517 return CMD_SUCCESS;
518 }
519 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200520 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000521 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200522 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000523 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
524 ts = &trx->ts[ts_nr];
525 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
526 lchan_nr++) {
527 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000528 if (lchan->type == GSM_LCHAN_NONE)
529 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000530 lchan_dump_vty(vty, lchan);
531 }
532 }
533 }
534 }
535
536 return CMD_SUCCESS;
537}
538
Harald Welte1bc77352009-03-10 19:47:51 +0000539static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
540{
541 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
542}
543
544DEFUN(show_e1drv,
545 show_e1drv_cmd,
546 "show e1_driver",
547 SHOW_STR "Display information about available E1 drivers\n")
548{
549 struct e1inp_driver *drv;
550
551 llist_for_each_entry(drv, &e1inp_driver_list, list)
552 e1drv_dump_vty(vty, drv);
553
554 return CMD_SUCCESS;
555}
556
Harald Welte68628e82009-03-10 12:17:57 +0000557static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
558{
559 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
560 line->num, line->name ? line->name : "",
561 line->driver->name, VTY_NEWLINE);
562}
563
564DEFUN(show_e1line,
565 show_e1line_cmd,
566 "show e1_line [line_nr]",
567 SHOW_STR "Display information about a E1 line\n")
568{
Harald Welte1bc77352009-03-10 19:47:51 +0000569 struct e1inp_line *line;
570
571 if (argc >= 1) {
572 int num = atoi(argv[0]);
573 llist_for_each_entry(line, &e1inp_line_list, list) {
574 if (line->num == num) {
575 e1line_dump_vty(vty, line);
576 return CMD_SUCCESS;
577 }
578 }
579 return CMD_WARNING;
580 }
581
582 llist_for_each_entry(line, &e1inp_line_list, list)
583 e1line_dump_vty(vty, line);
584
585 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000586}
587
588static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
589{
Harald Welte42581822009-08-08 16:12:58 +0200590 if (ts->type == E1INP_TS_TYPE_NONE)
591 return;
Harald Welte1bc77352009-03-10 19:47:51 +0000592 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
593 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
594 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000595}
596
597DEFUN(show_e1ts,
598 show_e1ts_cmd,
599 "show e1_timeslot [line_nr] [ts_nr]",
600 SHOW_STR "Display information about a E1 timeslot\n")
601{
Harald Welte1bc77352009-03-10 19:47:51 +0000602 struct e1inp_line *line;
603 struct e1inp_ts *ts;
604 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000605
Harald Welte1bc77352009-03-10 19:47:51 +0000606 if (argc == 0) {
607 llist_for_each_entry(line, &e1inp_line_list, list) {
608 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
609 ts = &line->ts[ts_nr];
610 e1ts_dump_vty(vty, ts);
611 }
612 }
613 return CMD_SUCCESS;
614 }
615 if (argc >= 1) {
616 int num = atoi(argv[0]);
617 llist_for_each_entry(line, &e1inp_line_list, list) {
618 if (line->num == num)
619 break;
620 }
621 if (!line || line->num != num) {
622 vty_out(vty, "E1 line %s is invalid%s",
623 argv[0], VTY_NEWLINE);
624 return CMD_WARNING;
625 }
626 }
627 if (argc >= 2) {
628 ts_nr = atoi(argv[1]);
629 if (ts_nr > NUM_E1_TS) {
630 vty_out(vty, "E1 timeslot %s is invalid%s",
631 argv[1], VTY_NEWLINE);
632 return CMD_WARNING;
633 }
634 ts = &line->ts[ts_nr];
635 e1ts_dump_vty(vty, ts);
636 return CMD_SUCCESS;
637 } else {
638 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
639 ts = &line->ts[ts_nr];
640 e1ts_dump_vty(vty, ts);
641 }
642 return CMD_SUCCESS;
643 }
644 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000645}
646
Harald Weltebe4b7302009-05-23 16:59:33 +0000647static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000648{
649 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
650 subscr_dump_vty(vty, pag->subscr);
651}
652
Harald Weltebe4b7302009-05-23 16:59:33 +0000653static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000654{
655 struct gsm_paging_request *pag;
656
657 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
658 paging_dump_vty(vty, pag);
659}
660
661DEFUN(show_paging,
662 show_paging_cmd,
663 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000664 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000665{
666 struct gsm_network *net = gsmnet;
667 struct gsm_bts *bts;
668 int bts_nr;
669
670 if (argc >= 1) {
671 /* use the BTS number that the user has specified */
672 bts_nr = atoi(argv[0]);
673 if (bts_nr >= net->num_bts) {
674 vty_out(vty, "%% can't find BTS %s%s", argv[0],
675 VTY_NEWLINE);
676 return CMD_WARNING;
677 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200678 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000679 bts_paging_dump_vty(vty, bts);
680
681 return CMD_SUCCESS;
682 }
683 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200684 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000685 bts_paging_dump_vty(vty, bts);
686 }
687
688 return CMD_SUCCESS;
689}
690
Harald Welte40f82892009-05-23 17:31:39 +0000691/* per-subscriber configuration */
692DEFUN(cfg_subscr,
693 cfg_subscr_cmd,
694 "subscriber IMSI",
695 "Select a Subscriber to configure\n")
696{
697 const char *imsi = argv[0];
698 struct gsm_subscriber *subscr;
699
Harald Welte761e9442009-07-23 19:21:02 +0200700 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000701 if (!subscr) {
702 vty_out(vty, "%% No subscriber for IMSI %s%s",
703 imsi, VTY_NEWLINE);
704 return CMD_WARNING;
705 }
706
707 vty->index = subscr;
708 vty->node = SUBSCR_NODE;
709
710 return CMD_SUCCESS;
711}
712
Harald Welte5013b2a2009-08-07 13:29:14 +0200713DEFUN(cfg_net,
714 cfg_net_cmd,
715 "network",
716 "Configure the GSM network")
717{
718 vty->index = gsmnet;
719 vty->node = GSMNET_NODE;
720
721 return CMD_SUCCESS;
722}
723
724
725DEFUN(cfg_net_ncc,
726 cfg_net_ncc_cmd,
727 "network country code <1-999>",
728 "Set the GSM network country code")
729{
730 gsmnet->country_code = atoi(argv[0]);
731
732 return CMD_SUCCESS;
733}
734
735DEFUN(cfg_net_mnc,
736 cfg_net_mnc_cmd,
737 "mobile network code <1-999>",
738 "Set the GSM mobile network code")
739{
740 gsmnet->network_code = atoi(argv[0]);
741
742 return CMD_SUCCESS;
743}
744
745DEFUN(cfg_net_name_short,
746 cfg_net_name_short_cmd,
747 "short name NAME",
748 "Set the short GSM network name")
749{
750 if (gsmnet->name_short)
751 talloc_free(gsmnet->name_short);
752
753 gsmnet->name_short = talloc_strdup(gsmnet, argv[0]);
754
755 return CMD_SUCCESS;
756}
757
758DEFUN(cfg_net_name_long,
759 cfg_net_name_long_cmd,
760 "long name NAME",
761 "Set the long GSM network name")
762{
763 if (gsmnet->name_long)
764 talloc_free(gsmnet->name_long);
765
766 gsmnet->name_long = talloc_strdup(gsmnet, argv[0]);
767
768 return CMD_SUCCESS;
769}
Harald Welte40f82892009-05-23 17:31:39 +0000770
Harald Welte5258fc42009-03-28 19:07:53 +0000771/* per-BTS configuration */
772DEFUN(cfg_bts,
773 cfg_bts_cmd,
774 "bts BTS_NR",
775 "Select a BTS to configure\n")
776{
777 int bts_nr = atoi(argv[0]);
778 struct gsm_bts *bts;
779
Harald Weltee441d9c2009-06-21 16:17:15 +0200780 if (bts_nr > gsmnet->num_bts) {
781 vty_out(vty, "%% The next unused BTS number is %u%s",
782 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000783 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200784 } else if (bts_nr == gsmnet->num_bts) {
785 /* allocate a new one */
786 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
787 HARDCODED_TSC, HARDCODED_BSIC);
788 } else
789 bts = gsm_bts_num(gsmnet, bts_nr);
790
791 if (!bts)
792 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000793
794 vty->index = bts;
795 vty->node = BTS_NODE;
796
797 return CMD_SUCCESS;
798}
799
800DEFUN(cfg_bts_type,
801 cfg_bts_type_cmd,
802 "type TYPE",
803 "Set the BTS type\n")
804{
805 struct gsm_bts *bts = vty->index;
806
Harald Weltea6fd58e2009-08-07 00:25:23 +0200807 bts->type = parse_btstype(argv[0]);
808
Harald Welte5258fc42009-03-28 19:07:53 +0000809 return CMD_SUCCESS;
810}
811
Harald Weltefcd24452009-06-20 18:15:19 +0200812DEFUN(cfg_bts_band,
813 cfg_bts_band_cmd,
814 "band BAND",
815 "Set the frequency band of this BTS\n")
816{
817 struct gsm_bts *bts = vty->index;
Harald Welte42581822009-08-08 16:12:58 +0200818 int band = gsm_band_parse(argv[0]);
Harald Weltefcd24452009-06-20 18:15:19 +0200819
820 if (band < 0) {
821 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
822 band, VTY_NEWLINE);
823 return CMD_WARNING;
824 }
825
826 bts->band = band;
827
828 return CMD_SUCCESS;
829}
830
Harald Welte5258fc42009-03-28 19:07:53 +0000831DEFUN(cfg_bts_lac,
832 cfg_bts_lac_cmd,
833 "location_area_code <0-255>",
834 "Set the Location Area Code (LAC) of this BTS\n")
835{
836 struct gsm_bts *bts = vty->index;
837 int lac = atoi(argv[0]);
838
839 if (lac < 0 || lac > 0xff) {
840 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
841 lac, VTY_NEWLINE);
842 return CMD_WARNING;
843 }
844 bts->location_area_code = lac;
845
846 return CMD_SUCCESS;
847}
848
849DEFUN(cfg_bts_tsc,
850 cfg_bts_tsc_cmd,
851 "training_sequence_code <0-255>",
852 "Set the Training Sequence Code (TSC) of this BTS\n")
853{
854 struct gsm_bts *bts = vty->index;
855 int tsc = atoi(argv[0]);
856
857 if (tsc < 0 || tsc > 0xff) {
858 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
859 tsc, VTY_NEWLINE);
860 return CMD_WARNING;
861 }
862 bts->tsc = tsc;
863
864 return CMD_SUCCESS;
865}
866
Harald Welte78f2f502009-05-23 16:56:52 +0000867DEFUN(cfg_bts_bsic,
868 cfg_bts_bsic_cmd,
869 "base_station_id_code <0-63>",
870 "Set the Base Station Identity Code (BSIC) of this BTS\n")
871{
872 struct gsm_bts *bts = vty->index;
873 int bsic = atoi(argv[0]);
874
875 if (bsic < 0 || bsic > 0x3f) {
Harald Welte42581822009-08-08 16:12:58 +0200876 vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s",
Harald Welte78f2f502009-05-23 16:56:52 +0000877 bsic, VTY_NEWLINE);
878 return CMD_WARNING;
879 }
880 bts->bsic = bsic;
881
882 return CMD_SUCCESS;
883}
884
885
Harald Welte4cc34222009-05-01 15:12:31 +0000886DEFUN(cfg_bts_unit_id,
887 cfg_bts_unit_id_cmd,
Harald Welte07dc73d2009-08-07 13:27:09 +0200888 "ip.access unit_id <0-65534> <0-255>",
889 "Set the ip.access BTS Unit ID of this BTS\n")
Harald Welte4cc34222009-05-01 15:12:31 +0000890{
891 struct gsm_bts *bts = vty->index;
892 int site_id = atoi(argv[0]);
893 int bts_id = atoi(argv[1]);
894
895 if (site_id < 0 || site_id > 65534) {
896 vty_out(vty, "%% Site ID %d is not in the valid range%s",
897 site_id, VTY_NEWLINE);
898 return CMD_WARNING;
899 }
900 if (site_id < 0 || site_id > 255) {
901 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
902 bts_id, VTY_NEWLINE);
903 return CMD_WARNING;
904 }
Harald Welte07dc73d2009-08-07 13:27:09 +0200905
906 if (!is_ipaccess_bts(bts)) {
907 vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE);
908 return CMD_WARNING;
909 }
910
Harald Welte4cc34222009-05-01 15:12:31 +0000911 bts->ip_access.site_id = site_id;
912 bts->ip_access.bts_id = bts_id;
913
914 return CMD_SUCCESS;
915}
916
Harald Welte42581822009-08-08 16:12:58 +0200917DEFUN(cfg_bts_oml_e1,
918 cfg_bts_oml_e1_cmd,
919 "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
920 "E1 interface to be used for OML\n")
921{
922 struct gsm_bts *bts = vty->index;
923
924 parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]);
925
926 return CMD_SUCCESS;
927}
928
929
930DEFUN(cfg_bts_oml_e1_tei,
931 cfg_bts_oml_e1_tei_cmd,
932 "oml e1 tei <0-63>",
933 "Set the TEI to be used for OML")
934{
935 struct gsm_bts *bts = vty->index;
936
937 bts->oml_tei = atoi(argv[0]);
938
939 return CMD_SUCCESS;
940}
941
Harald Welte5258fc42009-03-28 19:07:53 +0000942/* per TRX configuration */
943DEFUN(cfg_trx,
944 cfg_trx_cmd,
945 "trx TRX_NR",
946 "Select a TRX to configure")
947{
948 int trx_nr = atoi(argv[0]);
949 struct gsm_bts *bts = vty->index;
950 struct gsm_bts_trx *trx;
951
Harald Weltee441d9c2009-06-21 16:17:15 +0200952 if (trx_nr > bts->num_trx) {
953 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
954 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000955 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200956 } else if (trx_nr == bts->num_trx) {
957 /* we need to allocate a new one */
958 trx = gsm_bts_trx_alloc(bts);
959 } else
960 trx = gsm_bts_trx_num(bts, trx_nr);
961
962 if (!trx)
963 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000964
965 vty->index = trx;
966 vty->node = TRX_NODE;
967
968 return CMD_SUCCESS;
969}
970
971DEFUN(cfg_trx_arfcn,
972 cfg_trx_arfcn_cmd,
973 "arfcn <1-1024>",
974 "Set the ARFCN for this TRX\n")
975{
976 int arfcn = atoi(argv[0]);
977 struct gsm_bts_trx *trx = vty->index;
978
979 /* FIXME: check if this ARFCN is supported by this TRX */
980
981 trx->arfcn = arfcn;
982
983 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
984 /* FIXME: use OML layer to update the ARFCN */
985 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
986
987 return CMD_SUCCESS;
988}
989
Harald Weltefcd24452009-06-20 18:15:19 +0200990DEFUN(cfg_trx_max_power_red,
991 cfg_trx_max_power_red_cmd,
992 "max_power_red <0-100>",
993 "Reduction of maximum BS RF Power in dB\n")
994{
995 int maxpwr_r = atoi(argv[0]);
996 struct gsm_bts_trx *trx = vty->index;
997 int upper_limit = 12; /* default 12.21 max power red. */
998
999 /* FIXME: check if our BTS type supports more than 12 */
1000 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
1001 vty_out(vty, "%% Power %d dB is not in the valid range%s",
1002 maxpwr_r, VTY_NEWLINE);
1003 return CMD_WARNING;
1004 }
1005 if (maxpwr_r & 1) {
1006 vty_out(vty, "%% Power %d dB is not an even value%s",
1007 maxpwr_r, VTY_NEWLINE);
1008 return CMD_WARNING;
1009 }
1010
1011 trx->max_power_red = maxpwr_r;
1012
1013 /* FIXME: make sure we update this using OML */
1014
1015 return CMD_SUCCESS;
1016}
1017
Harald Welte42581822009-08-08 16:12:58 +02001018DEFUN(cfg_trx_rsl_e1,
1019 cfg_trx_rsl_e1_cmd,
1020 "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
1021 "E1 interface to be used for RSL\n")
1022{
1023 struct gsm_bts_trx *trx = vty->index;
1024
1025 parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]);
1026
1027 return CMD_SUCCESS;
1028}
1029
1030DEFUN(cfg_trx_rsl_e1_tei,
1031 cfg_trx_rsl_e1_tei_cmd,
1032 "rsl e1 tei <0-63>",
1033 "Set the TEI to be used for RSL")
1034{
1035 struct gsm_bts_trx *trx = vty->index;
1036
1037 trx->rsl_tei = atoi(argv[0]);
1038
1039 return CMD_SUCCESS;
1040}
1041
1042
Harald Welte5258fc42009-03-28 19:07:53 +00001043/* per TS configuration */
1044DEFUN(cfg_ts,
1045 cfg_ts_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001046 "timeslot <0-7>",
Harald Welte5258fc42009-03-28 19:07:53 +00001047 "Select a Timeslot to configure")
1048{
1049 int ts_nr = atoi(argv[0]);
1050 struct gsm_bts_trx *trx = vty->index;
1051 struct gsm_bts_trx_ts *ts;
1052
1053 if (ts_nr >= TRX_NR_TS) {
1054 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
1055 TRX_NR_TS, VTY_NEWLINE);
1056 return CMD_WARNING;
1057 }
1058
1059 ts = &trx->ts[ts_nr];
1060
1061 vty->index = ts;
1062 vty->node = TS_NODE;
1063
1064 return CMD_SUCCESS;
1065}
1066
Harald Weltea6fd58e2009-08-07 00:25:23 +02001067DEFUN(cfg_ts_pchan,
1068 cfg_ts_pchan_cmd,
1069 "phys_chan_config PCHAN",
1070 "Physical Channel configuration (TCH/SDCCH/...)")
1071{
1072 struct gsm_bts_trx_ts *ts = vty->index;
1073 int pchanc;
1074
1075 pchanc = gsm_pchan_parse(argv[0]);
1076 if (pchanc < 0)
1077 return CMD_WARNING;
1078
1079 ts->pchan = pchanc;
1080
1081 return CMD_SUCCESS;
1082}
1083
1084DEFUN(cfg_ts_e1_subslot,
1085 cfg_ts_e1_subslot_cmd,
Harald Welte42581822009-08-08 16:12:58 +02001086 "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)",
Harald Weltea6fd58e2009-08-07 00:25:23 +02001087 "E1 sub-slot connected to this on-air timeslot")
1088{
1089 struct gsm_bts_trx_ts *ts = vty->index;
1090
Harald Welte42581822009-08-08 16:12:58 +02001091 parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001092
1093 return CMD_SUCCESS;
1094}
Harald Welte5258fc42009-03-28 19:07:53 +00001095
Harald Welte40f82892009-05-23 17:31:39 +00001096/* Subscriber */
1097DEFUN(show_subscr,
1098 show_subscr_cmd,
1099 "show subscriber [IMSI]",
1100 SHOW_STR "Display information about a subscriber\n")
1101{
1102 const char *imsi;
1103 struct gsm_subscriber *subscr;
1104
1105 if (argc >= 1) {
1106 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +02001107 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +00001108 if (!subscr) {
1109 vty_out(vty, "%% unknown subscriber%s",
1110 VTY_NEWLINE);
1111 return CMD_WARNING;
1112 }
1113 subscr_dump_vty(vty, subscr);
1114
1115 return CMD_SUCCESS;
1116 }
1117
1118 /* FIXME: iterate over all subscribers ? */
1119 return CMD_WARNING;
1120
1121 return CMD_SUCCESS;
1122}
1123
Harald Welte76042182009-08-08 16:03:15 +02001124DEFUN(sms_send_pend,
1125 sms_send_pend_cmd,
1126 "sms send pending MIN_ID",
1127 "Send all pending SMS starting from MIN_ID")
1128{
1129 struct gsm_sms *sms;
1130
1131 sms = db_sms_get_unsent(gsmnet, atoi(argv[0]));
1132 if (!sms)
1133 return CMD_WARNING;
1134
1135 if (!sms->receiver) {
1136 sms_free(sms);
1137 return CMD_WARNING;
1138 }
1139
1140 gsm411_send_sms_subscr(sms->receiver, sms);
1141
1142 return CMD_SUCCESS;
1143}
1144
Harald Weltef9daefd2009-08-09 15:13:54 +02001145static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
1146{
1147 struct buffer *b = buffer_new(1024);
1148 int i;
1149
1150 if (!b)
1151 return NULL;
1152
1153 for (i = base; i < argc; i++) {
1154 buffer_putstr(b, argv[i]);
1155 buffer_putc(b, ' ');
1156 }
1157 buffer_putc(b, '\0');
1158
1159 return b;
1160}
1161
1162static int _send_sms_buffer(struct gsm_subscriber *receiver,
1163 struct buffer *b)
1164{
1165 struct gsm_sms *sms = sms_alloc();
1166
1167 if (!sms)
1168 return CMD_WARNING;
1169
1170 if (!receiver->lac) {
1171 /* subscriber currently not attached, store in database? */
1172 subscr_put(sms->receiver);
1173 return CMD_WARNING;
1174 }
1175
1176 sms->receiver = receiver;
1177 strncpy(sms->text, buffer_getstr(b), sizeof(sms->text)-1);
1178
1179 /* FIXME: don't use ID 1 static */
1180 sms->sender = subscr_get_by_id(gsmnet, 1);
1181 sms->reply_path_req = 0;
1182 sms->status_rep_req = 0;
1183 sms->ud_hdr_ind = 0;
1184 sms->protocol_id = 0; /* implicit */
1185 sms->data_coding_scheme = 0; /* default 7bit */
1186 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1187 /* Generate user_data */
1188 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1189
1190 gsm411_send_sms_subscr(sms->receiver, sms);
1191
1192 return CMD_SUCCESS;
1193}
1194
Harald Welte76042182009-08-08 16:03:15 +02001195DEFUN(sms_send_ext,
1196 sms_send_ext_cmd,
1197 "sms send extension EXTEN .LINE",
1198 "Send a message to a subscriber identified by EXTEN")
1199{
Harald Weltef9daefd2009-08-09 15:13:54 +02001200 struct gsm_subscriber *receiver;
1201 struct buffer *b;
1202 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001203
Harald Weltef9daefd2009-08-09 15:13:54 +02001204 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1205 if (!receiver)
1206 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001207
Harald Weltef9daefd2009-08-09 15:13:54 +02001208 b = argv_to_buffer(argc, argv, 1);
1209 rc = _send_sms_buffer(receiver, b);
1210 buffer_free(b);
1211
1212 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001213}
1214
1215DEFUN(sms_send_imsi,
1216 sms_send_imsi_cmd,
1217 "sms send imsi IMSI .LINE",
1218 "Send a message to a subscriber identified by IMSI")
1219{
Harald Weltef9daefd2009-08-09 15:13:54 +02001220 struct gsm_subscriber *receiver;
1221 struct buffer *b;
1222 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001223
Harald Weltef9daefd2009-08-09 15:13:54 +02001224 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1225 if (!receiver)
1226 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001227
Harald Weltef9daefd2009-08-09 15:13:54 +02001228 b = argv_to_buffer(argc, argv, 1);
1229 rc = _send_sms_buffer(receiver, b);
1230 buffer_free(b);
1231
1232 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001233}
1234
1235
Harald Welte40f82892009-05-23 17:31:39 +00001236DEFUN(cfg_subscr_name,
1237 cfg_subscr_name_cmd,
1238 "name NAME",
1239 "Set the name of the subscriber")
1240{
1241 const char *name = argv[0];
1242 struct gsm_subscriber *subscr = vty->index;
1243
1244 strncpy(subscr->name, name, sizeof(subscr->name));
1245
1246 db_sync_subscriber(subscr);
1247
1248 return CMD_SUCCESS;
1249}
1250
1251DEFUN(cfg_subscr_extension,
1252 cfg_subscr_extension_cmd,
1253 "extension EXTENSION",
1254 "Set the extension of the subscriber")
1255{
1256 const char *name = argv[0];
1257 struct gsm_subscriber *subscr = vty->index;
1258
1259 strncpy(subscr->extension, name, sizeof(subscr->extension));
1260
1261 db_sync_subscriber(subscr);
1262
1263 return CMD_SUCCESS;
1264}
1265
1266DEFUN(cfg_subscr_authorized,
1267 cfg_subscr_authorized_cmd,
1268 "auth <0-1>",
1269 "Set the authorization status of the subscriber")
1270{
1271 int auth = atoi(argv[0]);
1272 struct gsm_subscriber *subscr = vty->index;
1273
1274 if (auth)
1275 subscr->authorized = 1;
1276 else
1277 subscr->authorized = 0;
1278
1279 db_sync_subscriber(subscr);
1280
1281 return CMD_SUCCESS;
1282}
1283
Harald Welte68628e82009-03-10 12:17:57 +00001284int bsc_vty_init(struct gsm_network *net)
1285{
1286 gsmnet = net;
1287
1288 cmd_init(1);
1289 vty_init();
1290
1291 install_element(VIEW_NODE, &show_net_cmd);
1292 install_element(VIEW_NODE, &show_bts_cmd);
1293 install_element(VIEW_NODE, &show_trx_cmd);
1294 install_element(VIEW_NODE, &show_ts_cmd);
1295 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001296
1297 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001298 install_element(VIEW_NODE, &show_e1line_cmd);
1299 install_element(VIEW_NODE, &show_e1ts_cmd);
1300
Harald Weltef5025b62009-03-28 16:55:11 +00001301 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001302
Harald Welte40f82892009-05-23 17:31:39 +00001303 install_element(VIEW_NODE, &show_subscr_cmd);
1304
Harald Welte76042182009-08-08 16:03:15 +02001305 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001306 install_element(VIEW_NODE, &sms_send_ext_cmd);
1307 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001308
Harald Welte5013b2a2009-08-07 13:29:14 +02001309 install_element(CONFIG_NODE, &cfg_net_cmd);
1310 install_node(&net_node, config_write_net);
1311 install_default(GSMNET_NODE);
Harald Welte42581822009-08-08 16:12:58 +02001312 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
Harald Welte5013b2a2009-08-07 13:29:14 +02001313 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
1314 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
1315 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
1316
1317 install_element(GSMNET_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001318 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001319 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001320 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001321 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001322 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1323 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001324 install_element(BTS_NODE, &cfg_bts_bsic_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001325 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001326 install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
1327 install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001328
Harald Welte5258fc42009-03-28 19:07:53 +00001329 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001330 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001331 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001332 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001333 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte42581822009-08-08 16:12:58 +02001334 install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd);
1335 install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001336
Harald Welte5258fc42009-03-28 19:07:53 +00001337 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001338 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001339 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001340 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1341 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001342
Harald Welte40f82892009-05-23 17:31:39 +00001343 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1344 install_node(&subscr_node, dummy_config_write);
1345 install_default(SUBSCR_NODE);
1346 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1347 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1348 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1349
Harald Welte68628e82009-03-10 12:17:57 +00001350 return 0;
1351}