blob: 6d1ec96d12e194099c4d3e8a7b730b2a24a1c6ba [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>
34#include <openbsc/e1_input.h>
Harald Welte1bc77352009-03-10 19:47:51 +000035#include <openbsc/abis_nm.h>
Harald Weltef9daefd2009-08-09 15:13:54 +020036#include <openbsc/gsm_utils.h>
Harald Welte40f82892009-05-23 17:31:39 +000037#include <openbsc/db.h>
Harald Welte68628e82009-03-10 12:17:57 +000038
39static struct gsm_network *gsmnet;
40
41struct cmd_node bts_node = {
42 BTS_NODE,
43 "%s(bts)#",
44 1,
45};
46
47struct cmd_node trx_node = {
48 TRX_NODE,
49 "%s(trx)#",
50 1,
51};
52
53struct cmd_node ts_node = {
54 TS_NODE,
55 "%s(ts)#",
56 1,
57};
58
Harald Welte40f82892009-05-23 17:31:39 +000059struct cmd_node subscr_node = {
60 SUBSCR_NODE,
61 "%s(subscriber)#",
62 1,
63};
64
Harald Welte68628e82009-03-10 12:17:57 +000065static int dummy_config_write(struct vty *v)
66{
67 return CMD_SUCCESS;
68}
69
70static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms)
71{
Harald Welte1bc77352009-03-10 19:47:51 +000072 vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s",
73 nm_opstate_name(nms->operational), nms->administrative,
74 nm_avail_name(nms->availability), VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +000075}
76
77static void net_dump_vty(struct vty *vty, struct gsm_network *net)
78{
Harald Welteef235b52009-03-10 12:34:02 +000079 vty_out(vty, "BSC is on Country Code %u, Network Code %u "
80 "and has %u BTS%s", net->country_code, net->network_code,
81 net->num_bts, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000082 vty_out(vty, " Long network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000083 net->name_long, VTY_NEWLINE);
Harald Welte1bc77352009-03-10 19:47:51 +000084 vty_out(vty, " Short network name: '%s'%s",
Harald Welte68628e82009-03-10 12:17:57 +000085 net->name_short, VTY_NEWLINE);
86}
87
88DEFUN(show_net, show_net_cmd, "show network",
89 SHOW_STR "Display information about a GSM NETWORK\n")
90{
91 struct gsm_network *net = gsmnet;
92 net_dump_vty(vty, net);
93
94 return CMD_SUCCESS;
95}
96
97static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l)
98{
Harald Welteedb37782009-05-01 14:59:07 +000099 struct e1inp_line *line;
100
101 if (!e1l) {
102 vty_out(vty, " None%s", VTY_NEWLINE);
103 return;
104 }
105
106 line = e1l->ts->line;
107
108 vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s",
109 line->num, line->driver->name, e1l->ts->num,
Harald Welte1bc77352009-03-10 19:47:51 +0000110 e1inp_signtype_name(e1l->type), VTY_NEWLINE);
Harald Welteedb37782009-05-01 14:59:07 +0000111 vty_out(vty, " E1 TEI %u, SAPI %u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000112 e1l->tei, e1l->sapi, VTY_NEWLINE);
113}
114
115static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
116{
Harald Weltefcd24452009-06-20 18:15:19 +0200117 vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, "
118 "BSIC %u, TSC %u and %u TRX%s",
119 bts->nr, btstype2str(bts->type), gsm_band_name(bts->band),
120 bts->location_area_code, bts->bsic, bts->tsc,
121 bts->num_trx, VTY_NEWLINE);
Harald Welte4cc34222009-05-01 15:12:31 +0000122 if (is_ipaccess_bts(bts))
123 vty_out(vty, " Unit ID: %u/%u/0%s",
124 bts->ip_access.site_id, bts->ip_access.bts_id,
125 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000126 vty_out(vty, " NM State: ");
127 net_dump_nmstate(vty, &bts->nm_state);
128 vty_out(vty, " Site Mgr NM State: ");
129 net_dump_nmstate(vty, &bts->site_mgr.nm_state);
130 vty_out(vty, " Paging: FIXME pending requests, %u free slots%s",
131 bts->paging.available_slots, VTY_NEWLINE);
132 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
133 e1isl_dump_vty(vty, bts->oml_link);
134 /* FIXME: oml_link, chan_desc */
135}
136
137DEFUN(show_bts, show_bts_cmd, "show bts [number]",
138 SHOW_STR "Display information about a BTS\n"
139 "BTS number")
140{
141 struct gsm_network *net = gsmnet;
142 int bts_nr;
143
144 if (argc != 0) {
145 /* use the BTS number that the user has specified */
146 bts_nr = atoi(argv[0]);
147 if (bts_nr > net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000148 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000149 VTY_NEWLINE);
150 return CMD_WARNING;
151 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200152 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000153 return CMD_SUCCESS;
154 }
155 /* print all BTS's */
156 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
Harald Weltee441d9c2009-06-21 16:17:15 +0200157 bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
Harald Welte68628e82009-03-10 12:17:57 +0000158
159 return CMD_SUCCESS;
160}
161
Harald Welte67ce0732009-08-06 19:06:46 +0200162static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
163{
164 vty_out(vty, "\t\tts %u%s", ts->nr, VTY_NEWLINE);
165 vty_out(vty, "\t\t\tphys_chan_config %s%s", gsm_pchan_name(ts->pchan),
166 VTY_NEWLINE);
167 vty_out(vty, "\t\t\te1_subslot %u %u %u%s", ts->e1_link.e1_nr,
168 ts->e1_link.e1_ts, ts->e1_link.e1_ts_ss, VTY_NEWLINE);
169}
170
171static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx)
172{
173 int i;
174
175 vty_out(vty, "\ttrx %u%s", trx->nr, VTY_NEWLINE);
176 vty_out(vty, "\t\tarfcn %u%s", trx->arfcn, VTY_NEWLINE);
177 vty_out(vty, "\t\tmax_power_red %u%s", trx->max_power_red, VTY_NEWLINE);
178
179 for (i = 0; i < TRX_NR_TS; i++)
180 config_write_ts_single(vty, &trx->ts[i]);
181}
182
183static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
184{
185 struct gsm_bts_trx *trx;
186
187 vty_out(vty, "bts %u%s", bts->nr, VTY_NEWLINE);
188 vty_out(vty, "\ttype %s%s", btstype2str(bts->type), VTY_NEWLINE);
189 vty_out(vty, "\tband %s%s", gsm_band_name(bts->band), VTY_NEWLINE);
190 vty_out(vty, "\tlocation_area_code %u%s", bts->location_area_code,
191 VTY_NEWLINE);
192 vty_out(vty, "\ttraining_sequence_code %u%s", bts->tsc, VTY_NEWLINE);
193 vty_out(vty, "\tbase_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
Harald Weltea6fd58e2009-08-07 00:25:23 +0200194 if (is_ipaccess_bts(bts))
195 vty_out(vty, "\tunit_id %u %u%s",
196 bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
Harald Welte67ce0732009-08-06 19:06:46 +0200197
198 llist_for_each_entry(trx, &bts->trx_list, list)
199 config_write_trx_single(vty, trx);
200}
201
202static int config_write_bts(struct vty *v)
203{
204 struct gsm_bts *bts;
205
206 llist_for_each_entry(bts, &gsmnet->bts_list, list)
207 config_write_bts_single(v, bts);
208
209 return CMD_SUCCESS;
210}
211
212
Harald Welte68628e82009-03-10 12:17:57 +0000213static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx)
214{
215 vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s",
216 trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE);
Harald Weltefcd24452009-06-20 18:15:19 +0200217 vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, "
218 "resulting BS power: %d dBm\n",
219 trx->nominal_power, trx->max_power_red,
220 trx->nominal_power - trx->max_power_red);
Harald Welte68628e82009-03-10 12:17:57 +0000221 vty_out(vty, " NM State: ");
222 net_dump_nmstate(vty, &trx->nm_state);
223 vty_out(vty, " Baseband Transceiver NM State: ");
224 net_dump_nmstate(vty, &trx->bb_transc.nm_state);
225 vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE);
226 e1isl_dump_vty(vty, trx->rsl_link);
227}
228
229DEFUN(show_trx,
230 show_trx_cmd,
231 "show trx [bts_nr] [trx_nr]",
232 SHOW_STR "Display information about a TRX\n")
233{
234 struct gsm_network *net = gsmnet;
235 struct gsm_bts *bts = NULL;
236 struct gsm_bts_trx *trx;
237 int bts_nr, trx_nr;
238
239 if (argc >= 1) {
240 /* use the BTS number that the user has specified */
241 bts_nr = atoi(argv[0]);
242 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000243 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000244 VTY_NEWLINE);
245 return CMD_WARNING;
246 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200247 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000248 }
249 if (argc >= 2) {
250 trx_nr = atoi(argv[1]);
251 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000252 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000253 VTY_NEWLINE);
254 return CMD_WARNING;
255 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200256 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000257 trx_dump_vty(vty, trx);
258 return CMD_SUCCESS;
259 }
260 if (bts) {
261 /* print all TRX in this BTS */
262 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200263 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000264 trx_dump_vty(vty, trx);
265 }
266 return CMD_SUCCESS;
267 }
268
269 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200270 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000271 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200272 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000273 trx_dump_vty(vty, trx);
274 }
275 }
276
277 return CMD_SUCCESS;
278}
279
Harald Welte67ce0732009-08-06 19:06:46 +0200280
Harald Welte68628e82009-03-10 12:17:57 +0000281static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
282{
283 struct in_addr ia;
284
285 vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s",
286 ts->nr, ts->trx->nr, ts->trx->bts->nr,
287 gsm_pchan_name(ts->pchan), VTY_NEWLINE);
288 vty_out(vty, " NM State: ");
289 net_dump_nmstate(vty, &ts->nm_state);
Harald Welte68628e82009-03-10 12:17:57 +0000290 if (is_ipaccess_bts(ts->trx->bts)) {
291 ia.s_addr = ts->abis_ip.bound_ip;
Harald Welte20855542009-07-12 09:50:35 +0200292 vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
Harald Welte68628e82009-03-10 12:17:57 +0000293 inet_ntoa(ia), ts->abis_ip.bound_port,
Harald Welte20855542009-07-12 09:50:35 +0200294 ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id,
Harald Welte68628e82009-03-10 12:17:57 +0000295 VTY_NEWLINE);
Harald Welteef235b52009-03-10 12:34:02 +0000296 } else {
297 vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
298 ts->e1_link.e1_nr, ts->e1_link.e1_ts,
299 ts->e1_link.e1_ts_ss, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000300 }
301}
302
303DEFUN(show_ts,
304 show_ts_cmd,
Harald Welte1bc77352009-03-10 19:47:51 +0000305 "show timeslot [bts_nr] [trx_nr] [ts_nr]",
Harald Welte68628e82009-03-10 12:17:57 +0000306 SHOW_STR "Display information about a TS\n")
307{
308 struct gsm_network *net = gsmnet;
309 struct gsm_bts *bts;
310 struct gsm_bts_trx *trx;
311 struct gsm_bts_trx_ts *ts;
312 int bts_nr, trx_nr, ts_nr;
313
314 if (argc >= 1) {
315 /* use the BTS number that the user has specified */
316 bts_nr = atoi(argv[0]);
317 if (bts_nr >= net->num_bts) {
Harald Welte1bc77352009-03-10 19:47:51 +0000318 vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
Harald Welte68628e82009-03-10 12:17:57 +0000319 VTY_NEWLINE);
320 return CMD_WARNING;
321 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200322 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000323 }
324 if (argc >= 2) {
325 trx_nr = atoi(argv[1]);
326 if (trx_nr >= bts->num_trx) {
Harald Welte1bc77352009-03-10 19:47:51 +0000327 vty_out(vty, "%% can't find TRX '%s'%s", argv[1],
Harald Welte68628e82009-03-10 12:17:57 +0000328 VTY_NEWLINE);
329 return CMD_WARNING;
330 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200331 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000332 }
333 if (argc >= 3) {
334 ts_nr = atoi(argv[2]);
335 if (ts_nr >= TRX_NR_TS) {
Harald Welte1bc77352009-03-10 19:47:51 +0000336 vty_out(vty, "%% can't find TS '%s'%s", argv[2],
Harald Welte68628e82009-03-10 12:17:57 +0000337 VTY_NEWLINE);
338 return CMD_WARNING;
339 }
340 ts = &trx->ts[ts_nr];
341 ts_dump_vty(vty, ts);
342 return CMD_SUCCESS;
343 }
344 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200345 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000346 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200347 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000348 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
349 ts = &trx->ts[ts_nr];
350 ts_dump_vty(vty, ts);
351 }
352 }
353 }
354
355 return CMD_SUCCESS;
356}
357
358static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
359{
Harald Weltefcd24452009-06-20 18:15:19 +0200360 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
Harald Welte40f82892009-05-23 17:31:39 +0000361 subscr->authorized, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000362 if (subscr->name)
Harald Welte1bc77352009-03-10 19:47:51 +0000363 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000364 if (subscr->extension)
365 vty_out(vty, " Extension: %s%s", subscr->extension,
366 VTY_NEWLINE);
367 if (subscr->imsi)
368 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
369 if (subscr->tmsi)
370 vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE);
371}
372
373static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan)
374{
375 vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s",
376 lchan->nr, lchan->ts->nr, lchan->ts->trx->nr,
377 lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type),
378 VTY_NEWLINE);
379 vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE);
380 vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power,
381 lchan->ms_power, VTY_NEWLINE);
382 if (lchan->subscr) {
383 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
384 subscr_dump_vty(vty, lchan->subscr);
385 } else
386 vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
387}
388
Harald Welte4bfdfe72009-06-10 23:11:52 +0800389#if 0
390TODO: callref and remote callref of call must be resolved to get gsm_trans object
Harald Welte68628e82009-03-10 12:17:57 +0000391static void call_dump_vty(struct vty *vty, struct gsm_call *call)
392{
393 vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s",
394 call->type, call->state, call->transaction_id, VTY_NEWLINE);
395
396 if (call->local_lchan) {
397 vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE);
398 lchan_dump_vty(vty, call->local_lchan);
399 } else
400 vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE);
401
402 if (call->remote_lchan) {
403 vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE);
404 lchan_dump_vty(vty, call->remote_lchan);
405 } else
406 vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE);
407
408 if (call->called_subscr) {
409 vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE);
410 subscr_dump_vty(vty, call->called_subscr);
411 } else
412 vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE);
413}
Harald Welte4bfdfe72009-06-10 23:11:52 +0800414#endif
Harald Welte68628e82009-03-10 12:17:57 +0000415
416DEFUN(show_lchan,
417 show_lchan_cmd,
418 "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]",
419 SHOW_STR "Display information about a logical channel\n")
420{
421 struct gsm_network *net = gsmnet;
422 struct gsm_bts *bts;
423 struct gsm_bts_trx *trx;
424 struct gsm_bts_trx_ts *ts;
425 struct gsm_lchan *lchan;
426 int bts_nr, trx_nr, ts_nr, lchan_nr;
427
428 if (argc >= 1) {
429 /* use the BTS number that the user has specified */
430 bts_nr = atoi(argv[0]);
431 if (bts_nr >= net->num_bts) {
432 vty_out(vty, "%% can't find BTS %s%s", argv[0],
433 VTY_NEWLINE);
434 return CMD_WARNING;
435 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200436 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000437 }
438 if (argc >= 2) {
439 trx_nr = atoi(argv[1]);
440 if (trx_nr >= bts->num_trx) {
441 vty_out(vty, "%% can't find TRX %s%s", argv[1],
442 VTY_NEWLINE);
443 return CMD_WARNING;
444 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200445 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000446 }
447 if (argc >= 3) {
448 ts_nr = atoi(argv[2]);
449 if (ts_nr >= TRX_NR_TS) {
450 vty_out(vty, "%% can't find TS %s%s", argv[2],
451 VTY_NEWLINE);
452 return CMD_WARNING;
453 }
454 ts = &trx->ts[ts_nr];
455 }
456 if (argc >= 4) {
457 lchan_nr = atoi(argv[3]);
458 if (lchan_nr >= TS_MAX_LCHAN) {
459 vty_out(vty, "%% can't find LCHAN %s%s", argv[3],
460 VTY_NEWLINE);
461 return CMD_WARNING;
462 }
463 lchan = &ts->lchan[lchan_nr];
464 lchan_dump_vty(vty, lchan);
465 return CMD_SUCCESS;
466 }
467 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200468 bts = gsm_bts_num(net, bts_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000469 for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200470 trx = gsm_bts_trx_num(bts, trx_nr);
Harald Welte68628e82009-03-10 12:17:57 +0000471 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
472 ts = &trx->ts[ts_nr];
473 for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN;
474 lchan_nr++) {
475 lchan = &ts->lchan[lchan_nr];
Harald Welteef235b52009-03-10 12:34:02 +0000476 if (lchan->type == GSM_LCHAN_NONE)
477 continue;
Harald Welte68628e82009-03-10 12:17:57 +0000478 lchan_dump_vty(vty, lchan);
479 }
480 }
481 }
482 }
483
484 return CMD_SUCCESS;
485}
486
Harald Welte1bc77352009-03-10 19:47:51 +0000487static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
488{
489 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
490}
491
492DEFUN(show_e1drv,
493 show_e1drv_cmd,
494 "show e1_driver",
495 SHOW_STR "Display information about available E1 drivers\n")
496{
497 struct e1inp_driver *drv;
498
499 llist_for_each_entry(drv, &e1inp_driver_list, list)
500 e1drv_dump_vty(vty, drv);
501
502 return CMD_SUCCESS;
503}
504
Harald Welte68628e82009-03-10 12:17:57 +0000505static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
506{
507 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
508 line->num, line->name ? line->name : "",
509 line->driver->name, VTY_NEWLINE);
510}
511
512DEFUN(show_e1line,
513 show_e1line_cmd,
514 "show e1_line [line_nr]",
515 SHOW_STR "Display information about a E1 line\n")
516{
Harald Welte1bc77352009-03-10 19:47:51 +0000517 struct e1inp_line *line;
518
519 if (argc >= 1) {
520 int num = atoi(argv[0]);
521 llist_for_each_entry(line, &e1inp_line_list, list) {
522 if (line->num == num) {
523 e1line_dump_vty(vty, line);
524 return CMD_SUCCESS;
525 }
526 }
527 return CMD_WARNING;
528 }
529
530 llist_for_each_entry(line, &e1inp_line_list, list)
531 e1line_dump_vty(vty, line);
532
533 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000534}
535
536static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
537{
Harald Welte1bc77352009-03-10 19:47:51 +0000538 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
539 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
540 VTY_NEWLINE);
Harald Welte68628e82009-03-10 12:17:57 +0000541}
542
543DEFUN(show_e1ts,
544 show_e1ts_cmd,
545 "show e1_timeslot [line_nr] [ts_nr]",
546 SHOW_STR "Display information about a E1 timeslot\n")
547{
Harald Welte1bc77352009-03-10 19:47:51 +0000548 struct e1inp_line *line;
549 struct e1inp_ts *ts;
550 int ts_nr;
Harald Welte68628e82009-03-10 12:17:57 +0000551
Harald Welte1bc77352009-03-10 19:47:51 +0000552 if (argc == 0) {
553 llist_for_each_entry(line, &e1inp_line_list, list) {
554 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
555 ts = &line->ts[ts_nr];
556 e1ts_dump_vty(vty, ts);
557 }
558 }
559 return CMD_SUCCESS;
560 }
561 if (argc >= 1) {
562 int num = atoi(argv[0]);
563 llist_for_each_entry(line, &e1inp_line_list, list) {
564 if (line->num == num)
565 break;
566 }
567 if (!line || line->num != num) {
568 vty_out(vty, "E1 line %s is invalid%s",
569 argv[0], VTY_NEWLINE);
570 return CMD_WARNING;
571 }
572 }
573 if (argc >= 2) {
574 ts_nr = atoi(argv[1]);
575 if (ts_nr > NUM_E1_TS) {
576 vty_out(vty, "E1 timeslot %s is invalid%s",
577 argv[1], VTY_NEWLINE);
578 return CMD_WARNING;
579 }
580 ts = &line->ts[ts_nr];
581 e1ts_dump_vty(vty, ts);
582 return CMD_SUCCESS;
583 } else {
584 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
585 ts = &line->ts[ts_nr];
586 e1ts_dump_vty(vty, ts);
587 }
588 return CMD_SUCCESS;
589 }
590 return CMD_SUCCESS;
Harald Welte68628e82009-03-10 12:17:57 +0000591}
592
Harald Weltebe4b7302009-05-23 16:59:33 +0000593static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
Harald Weltef5025b62009-03-28 16:55:11 +0000594{
595 vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
596 subscr_dump_vty(vty, pag->subscr);
597}
598
Harald Weltebe4b7302009-05-23 16:59:33 +0000599static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts)
Harald Weltef5025b62009-03-28 16:55:11 +0000600{
601 struct gsm_paging_request *pag;
602
603 llist_for_each_entry(pag, &bts->paging.pending_requests, entry)
604 paging_dump_vty(vty, pag);
605}
606
607DEFUN(show_paging,
608 show_paging_cmd,
609 "show paging [bts_nr]",
Harald Weltebe4b7302009-05-23 16:59:33 +0000610 SHOW_STR "Display information about paging reuqests of a BTS\n")
Harald Weltef5025b62009-03-28 16:55:11 +0000611{
612 struct gsm_network *net = gsmnet;
613 struct gsm_bts *bts;
614 int bts_nr;
615
616 if (argc >= 1) {
617 /* use the BTS number that the user has specified */
618 bts_nr = atoi(argv[0]);
619 if (bts_nr >= net->num_bts) {
620 vty_out(vty, "%% can't find BTS %s%s", argv[0],
621 VTY_NEWLINE);
622 return CMD_WARNING;
623 }
Harald Weltee441d9c2009-06-21 16:17:15 +0200624 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000625 bts_paging_dump_vty(vty, bts);
626
627 return CMD_SUCCESS;
628 }
629 for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200630 bts = gsm_bts_num(net, bts_nr);
Harald Weltef5025b62009-03-28 16:55:11 +0000631 bts_paging_dump_vty(vty, bts);
632 }
633
634 return CMD_SUCCESS;
635}
636
Harald Welte40f82892009-05-23 17:31:39 +0000637/* per-subscriber configuration */
638DEFUN(cfg_subscr,
639 cfg_subscr_cmd,
640 "subscriber IMSI",
641 "Select a Subscriber to configure\n")
642{
643 const char *imsi = argv[0];
644 struct gsm_subscriber *subscr;
645
Harald Welte761e9442009-07-23 19:21:02 +0200646 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000647 if (!subscr) {
648 vty_out(vty, "%% No subscriber for IMSI %s%s",
649 imsi, VTY_NEWLINE);
650 return CMD_WARNING;
651 }
652
653 vty->index = subscr;
654 vty->node = SUBSCR_NODE;
655
656 return CMD_SUCCESS;
657}
658
659
Harald Welte5258fc42009-03-28 19:07:53 +0000660/* per-BTS configuration */
661DEFUN(cfg_bts,
662 cfg_bts_cmd,
663 "bts BTS_NR",
664 "Select a BTS to configure\n")
665{
666 int bts_nr = atoi(argv[0]);
667 struct gsm_bts *bts;
668
Harald Weltee441d9c2009-06-21 16:17:15 +0200669 if (bts_nr > gsmnet->num_bts) {
670 vty_out(vty, "%% The next unused BTS number is %u%s",
671 gsmnet->num_bts, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000672 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200673 } else if (bts_nr == gsmnet->num_bts) {
674 /* allocate a new one */
675 bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN,
676 HARDCODED_TSC, HARDCODED_BSIC);
677 } else
678 bts = gsm_bts_num(gsmnet, bts_nr);
679
680 if (!bts)
681 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000682
683 vty->index = bts;
684 vty->node = BTS_NODE;
685
686 return CMD_SUCCESS;
687}
688
689DEFUN(cfg_bts_type,
690 cfg_bts_type_cmd,
691 "type TYPE",
692 "Set the BTS type\n")
693{
694 struct gsm_bts *bts = vty->index;
695
Harald Weltea6fd58e2009-08-07 00:25:23 +0200696 bts->type = parse_btstype(argv[0]);
697
Harald Welte5258fc42009-03-28 19:07:53 +0000698 return CMD_SUCCESS;
699}
700
Harald Weltefcd24452009-06-20 18:15:19 +0200701DEFUN(cfg_bts_band,
702 cfg_bts_band_cmd,
703 "band BAND",
704 "Set the frequency band of this BTS\n")
705{
706 struct gsm_bts *bts = vty->index;
707 int band = gsm_band_parse(atoi(argv[0]));
708
709 if (band < 0) {
710 vty_out(vty, "%% BAND %d is not a valid GSM band%s",
711 band, VTY_NEWLINE);
712 return CMD_WARNING;
713 }
714
715 bts->band = band;
716
717 return CMD_SUCCESS;
718}
719
Harald Welte5258fc42009-03-28 19:07:53 +0000720DEFUN(cfg_bts_lac,
721 cfg_bts_lac_cmd,
722 "location_area_code <0-255>",
723 "Set the Location Area Code (LAC) of this BTS\n")
724{
725 struct gsm_bts *bts = vty->index;
726 int lac = atoi(argv[0]);
727
728 if (lac < 0 || lac > 0xff) {
729 vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s",
730 lac, VTY_NEWLINE);
731 return CMD_WARNING;
732 }
733 bts->location_area_code = lac;
734
735 return CMD_SUCCESS;
736}
737
738DEFUN(cfg_bts_tsc,
739 cfg_bts_tsc_cmd,
740 "training_sequence_code <0-255>",
741 "Set the Training Sequence Code (TSC) of this BTS\n")
742{
743 struct gsm_bts *bts = vty->index;
744 int tsc = atoi(argv[0]);
745
746 if (tsc < 0 || tsc > 0xff) {
747 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
748 tsc, VTY_NEWLINE);
749 return CMD_WARNING;
750 }
751 bts->tsc = tsc;
752
753 return CMD_SUCCESS;
754}
755
Harald Welte78f2f502009-05-23 16:56:52 +0000756DEFUN(cfg_bts_bsic,
757 cfg_bts_bsic_cmd,
758 "base_station_id_code <0-63>",
759 "Set the Base Station Identity Code (BSIC) of this BTS\n")
760{
761 struct gsm_bts *bts = vty->index;
762 int bsic = atoi(argv[0]);
763
764 if (bsic < 0 || bsic > 0x3f) {
765 vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s",
766 bsic, VTY_NEWLINE);
767 return CMD_WARNING;
768 }
769 bts->bsic = bsic;
770
771 return CMD_SUCCESS;
772}
773
774
Harald Welte4cc34222009-05-01 15:12:31 +0000775DEFUN(cfg_bts_unit_id,
776 cfg_bts_unit_id_cmd,
777 "unit_id <0-65534> <0-255>",
778 "Set the BTS Unit ID of this BTS\n")
779{
780 struct gsm_bts *bts = vty->index;
781 int site_id = atoi(argv[0]);
782 int bts_id = atoi(argv[1]);
783
784 if (site_id < 0 || site_id > 65534) {
785 vty_out(vty, "%% Site ID %d is not in the valid range%s",
786 site_id, VTY_NEWLINE);
787 return CMD_WARNING;
788 }
789 if (site_id < 0 || site_id > 255) {
790 vty_out(vty, "%% BTS ID %d is not in the valid range%s",
791 bts_id, VTY_NEWLINE);
792 return CMD_WARNING;
793 }
794 bts->ip_access.site_id = site_id;
795 bts->ip_access.bts_id = bts_id;
796
797 return CMD_SUCCESS;
798}
799
Harald Welte5258fc42009-03-28 19:07:53 +0000800/* per TRX configuration */
801DEFUN(cfg_trx,
802 cfg_trx_cmd,
803 "trx TRX_NR",
804 "Select a TRX to configure")
805{
806 int trx_nr = atoi(argv[0]);
807 struct gsm_bts *bts = vty->index;
808 struct gsm_bts_trx *trx;
809
Harald Weltee441d9c2009-06-21 16:17:15 +0200810 if (trx_nr > bts->num_trx) {
811 vty_out(vty, "%% The next unused TRX number in this BTS is %u%s",
812 bts->num_trx, VTY_NEWLINE);
Harald Welte5258fc42009-03-28 19:07:53 +0000813 return CMD_WARNING;
Harald Weltee441d9c2009-06-21 16:17:15 +0200814 } else if (trx_nr == bts->num_trx) {
815 /* we need to allocate a new one */
816 trx = gsm_bts_trx_alloc(bts);
817 } else
818 trx = gsm_bts_trx_num(bts, trx_nr);
819
820 if (!trx)
821 return CMD_WARNING;
Harald Welte5258fc42009-03-28 19:07:53 +0000822
823 vty->index = trx;
824 vty->node = TRX_NODE;
825
826 return CMD_SUCCESS;
827}
828
829DEFUN(cfg_trx_arfcn,
830 cfg_trx_arfcn_cmd,
831 "arfcn <1-1024>",
832 "Set the ARFCN for this TRX\n")
833{
834 int arfcn = atoi(argv[0]);
835 struct gsm_bts_trx *trx = vty->index;
836
837 /* FIXME: check if this ARFCN is supported by this TRX */
838
839 trx->arfcn = arfcn;
840
841 /* FIXME: patch ARFCN into SYSTEM INFORMATION */
842 /* FIXME: use OML layer to update the ARFCN */
843 /* FIXME: use RSL layer to update SYSTEM INFORMATION */
844
845 return CMD_SUCCESS;
846}
847
Harald Weltefcd24452009-06-20 18:15:19 +0200848DEFUN(cfg_trx_max_power_red,
849 cfg_trx_max_power_red_cmd,
850 "max_power_red <0-100>",
851 "Reduction of maximum BS RF Power in dB\n")
852{
853 int maxpwr_r = atoi(argv[0]);
854 struct gsm_bts_trx *trx = vty->index;
855 int upper_limit = 12; /* default 12.21 max power red. */
856
857 /* FIXME: check if our BTS type supports more than 12 */
858 if (maxpwr_r < 0 || maxpwr_r > upper_limit) {
859 vty_out(vty, "%% Power %d dB is not in the valid range%s",
860 maxpwr_r, VTY_NEWLINE);
861 return CMD_WARNING;
862 }
863 if (maxpwr_r & 1) {
864 vty_out(vty, "%% Power %d dB is not an even value%s",
865 maxpwr_r, VTY_NEWLINE);
866 return CMD_WARNING;
867 }
868
869 trx->max_power_red = maxpwr_r;
870
871 /* FIXME: make sure we update this using OML */
872
873 return CMD_SUCCESS;
874}
875
Harald Welte5258fc42009-03-28 19:07:53 +0000876/* per TS configuration */
877DEFUN(cfg_ts,
878 cfg_ts_cmd,
879 "timeslot TS_NR",
880 "Select a Timeslot to configure")
881{
882 int ts_nr = atoi(argv[0]);
883 struct gsm_bts_trx *trx = vty->index;
884 struct gsm_bts_trx_ts *ts;
885
886 if (ts_nr >= TRX_NR_TS) {
887 vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s",
888 TRX_NR_TS, VTY_NEWLINE);
889 return CMD_WARNING;
890 }
891
892 ts = &trx->ts[ts_nr];
893
894 vty->index = ts;
895 vty->node = TS_NODE;
896
897 return CMD_SUCCESS;
898}
899
Harald Weltea6fd58e2009-08-07 00:25:23 +0200900DEFUN(cfg_ts_pchan,
901 cfg_ts_pchan_cmd,
902 "phys_chan_config PCHAN",
903 "Physical Channel configuration (TCH/SDCCH/...)")
904{
905 struct gsm_bts_trx_ts *ts = vty->index;
906 int pchanc;
907
908 pchanc = gsm_pchan_parse(argv[0]);
909 if (pchanc < 0)
910 return CMD_WARNING;
911
912 ts->pchan = pchanc;
913
914 return CMD_SUCCESS;
915}
916
917DEFUN(cfg_ts_e1_subslot,
918 cfg_ts_e1_subslot_cmd,
919 "e1_subslot E1_IF <1-31> <0-4>",
920 "E1 sub-slot connected to this on-air timeslot")
921{
922 struct gsm_bts_trx_ts *ts = vty->index;
923
924 ts->e1_link.e1_nr = atoi(argv[0]);
925 ts->e1_link.e1_ts = atoi(argv[1]);
926 ts->e1_link.e1_ts_ss = atoi(argv[2]);
927
928 return CMD_SUCCESS;
929}
Harald Welte5258fc42009-03-28 19:07:53 +0000930
Harald Welte40f82892009-05-23 17:31:39 +0000931/* Subscriber */
932DEFUN(show_subscr,
933 show_subscr_cmd,
934 "show subscriber [IMSI]",
935 SHOW_STR "Display information about a subscriber\n")
936{
937 const char *imsi;
938 struct gsm_subscriber *subscr;
939
940 if (argc >= 1) {
941 imsi = argv[0];
Harald Welte761e9442009-07-23 19:21:02 +0200942 subscr = subscr_get_by_imsi(gsmnet, imsi);
Harald Welte40f82892009-05-23 17:31:39 +0000943 if (!subscr) {
944 vty_out(vty, "%% unknown subscriber%s",
945 VTY_NEWLINE);
946 return CMD_WARNING;
947 }
948 subscr_dump_vty(vty, subscr);
949
950 return CMD_SUCCESS;
951 }
952
953 /* FIXME: iterate over all subscribers ? */
954 return CMD_WARNING;
955
956 return CMD_SUCCESS;
957}
958
Harald Welte76042182009-08-08 16:03:15 +0200959DEFUN(sms_send_pend,
960 sms_send_pend_cmd,
961 "sms send pending MIN_ID",
962 "Send all pending SMS starting from MIN_ID")
963{
964 struct gsm_sms *sms;
965
966 sms = db_sms_get_unsent(gsmnet, atoi(argv[0]));
967 if (!sms)
968 return CMD_WARNING;
969
970 if (!sms->receiver) {
971 sms_free(sms);
972 return CMD_WARNING;
973 }
974
975 gsm411_send_sms_subscr(sms->receiver, sms);
976
977 return CMD_SUCCESS;
978}
979
Harald Weltef9daefd2009-08-09 15:13:54 +0200980static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
981{
982 struct buffer *b = buffer_new(1024);
983 int i;
984
985 if (!b)
986 return NULL;
987
988 for (i = base; i < argc; i++) {
989 buffer_putstr(b, argv[i]);
990 buffer_putc(b, ' ');
991 }
992 buffer_putc(b, '\0');
993
994 return b;
995}
996
997static int _send_sms_buffer(struct gsm_subscriber *receiver,
998 struct buffer *b)
999{
1000 struct gsm_sms *sms = sms_alloc();
1001
1002 if (!sms)
1003 return CMD_WARNING;
1004
1005 if (!receiver->lac) {
1006 /* subscriber currently not attached, store in database? */
1007 subscr_put(sms->receiver);
1008 return CMD_WARNING;
1009 }
1010
1011 sms->receiver = receiver;
1012 strncpy(sms->text, buffer_getstr(b), sizeof(sms->text)-1);
1013
1014 /* FIXME: don't use ID 1 static */
1015 sms->sender = subscr_get_by_id(gsmnet, 1);
1016 sms->reply_path_req = 0;
1017 sms->status_rep_req = 0;
1018 sms->ud_hdr_ind = 0;
1019 sms->protocol_id = 0; /* implicit */
1020 sms->data_coding_scheme = 0; /* default 7bit */
1021 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
1022 /* Generate user_data */
1023 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
1024
1025 gsm411_send_sms_subscr(sms->receiver, sms);
1026
1027 return CMD_SUCCESS;
1028}
1029
Harald Welte76042182009-08-08 16:03:15 +02001030DEFUN(sms_send_ext,
1031 sms_send_ext_cmd,
1032 "sms send extension EXTEN .LINE",
1033 "Send a message to a subscriber identified by EXTEN")
1034{
Harald Weltef9daefd2009-08-09 15:13:54 +02001035 struct gsm_subscriber *receiver;
1036 struct buffer *b;
1037 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001038
Harald Weltef9daefd2009-08-09 15:13:54 +02001039 receiver = subscr_get_by_extension(gsmnet, argv[0]);
1040 if (!receiver)
1041 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001042
Harald Weltef9daefd2009-08-09 15:13:54 +02001043 b = argv_to_buffer(argc, argv, 1);
1044 rc = _send_sms_buffer(receiver, b);
1045 buffer_free(b);
1046
1047 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001048}
1049
1050DEFUN(sms_send_imsi,
1051 sms_send_imsi_cmd,
1052 "sms send imsi IMSI .LINE",
1053 "Send a message to a subscriber identified by IMSI")
1054{
Harald Weltef9daefd2009-08-09 15:13:54 +02001055 struct gsm_subscriber *receiver;
1056 struct buffer *b;
1057 int rc;
Harald Welte76042182009-08-08 16:03:15 +02001058
Harald Weltef9daefd2009-08-09 15:13:54 +02001059 receiver = subscr_get_by_imsi(gsmnet, argv[0]);
1060 if (!receiver)
1061 return CMD_WARNING;
Harald Welte76042182009-08-08 16:03:15 +02001062
Harald Weltef9daefd2009-08-09 15:13:54 +02001063 b = argv_to_buffer(argc, argv, 1);
1064 rc = _send_sms_buffer(receiver, b);
1065 buffer_free(b);
1066
1067 return rc;
Harald Welte76042182009-08-08 16:03:15 +02001068}
1069
1070
Harald Welte40f82892009-05-23 17:31:39 +00001071DEFUN(cfg_subscr_name,
1072 cfg_subscr_name_cmd,
1073 "name NAME",
1074 "Set the name of the subscriber")
1075{
1076 const char *name = argv[0];
1077 struct gsm_subscriber *subscr = vty->index;
1078
1079 strncpy(subscr->name, name, sizeof(subscr->name));
1080
1081 db_sync_subscriber(subscr);
1082
1083 return CMD_SUCCESS;
1084}
1085
1086DEFUN(cfg_subscr_extension,
1087 cfg_subscr_extension_cmd,
1088 "extension EXTENSION",
1089 "Set the extension of the subscriber")
1090{
1091 const char *name = argv[0];
1092 struct gsm_subscriber *subscr = vty->index;
1093
1094 strncpy(subscr->extension, name, sizeof(subscr->extension));
1095
1096 db_sync_subscriber(subscr);
1097
1098 return CMD_SUCCESS;
1099}
1100
1101DEFUN(cfg_subscr_authorized,
1102 cfg_subscr_authorized_cmd,
1103 "auth <0-1>",
1104 "Set the authorization status of the subscriber")
1105{
1106 int auth = atoi(argv[0]);
1107 struct gsm_subscriber *subscr = vty->index;
1108
1109 if (auth)
1110 subscr->authorized = 1;
1111 else
1112 subscr->authorized = 0;
1113
1114 db_sync_subscriber(subscr);
1115
1116 return CMD_SUCCESS;
1117}
1118
Harald Welte68628e82009-03-10 12:17:57 +00001119int bsc_vty_init(struct gsm_network *net)
1120{
1121 gsmnet = net;
1122
1123 cmd_init(1);
1124 vty_init();
1125
1126 install_element(VIEW_NODE, &show_net_cmd);
1127 install_element(VIEW_NODE, &show_bts_cmd);
1128 install_element(VIEW_NODE, &show_trx_cmd);
1129 install_element(VIEW_NODE, &show_ts_cmd);
1130 install_element(VIEW_NODE, &show_lchan_cmd);
Harald Welte1bc77352009-03-10 19:47:51 +00001131
1132 install_element(VIEW_NODE, &show_e1drv_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001133 install_element(VIEW_NODE, &show_e1line_cmd);
1134 install_element(VIEW_NODE, &show_e1ts_cmd);
1135
Harald Weltef5025b62009-03-28 16:55:11 +00001136 install_element(VIEW_NODE, &show_paging_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001137
Harald Welte40f82892009-05-23 17:31:39 +00001138 install_element(VIEW_NODE, &show_subscr_cmd);
1139
Harald Welte76042182009-08-08 16:03:15 +02001140 install_element(VIEW_NODE, &sms_send_pend_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001141 install_element(VIEW_NODE, &sms_send_ext_cmd);
1142 install_element(VIEW_NODE, &sms_send_imsi_cmd);
Harald Welte76042182009-08-08 16:03:15 +02001143
Harald Welte5258fc42009-03-28 19:07:53 +00001144 install_element(CONFIG_NODE, &cfg_bts_cmd);
Harald Welte67ce0732009-08-06 19:06:46 +02001145 install_node(&bts_node, config_write_bts);
Harald Welte68628e82009-03-10 12:17:57 +00001146 install_default(BTS_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001147 install_element(BTS_NODE, &cfg_bts_type_cmd);
Harald Weltefcd24452009-06-20 18:15:19 +02001148 install_element(BTS_NODE, &cfg_bts_band_cmd);
Harald Welte5258fc42009-03-28 19:07:53 +00001149 install_element(BTS_NODE, &cfg_bts_lac_cmd);
1150 install_element(BTS_NODE, &cfg_bts_tsc_cmd);
Harald Welte4cc34222009-05-01 15:12:31 +00001151 install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001152
Harald Welte5258fc42009-03-28 19:07:53 +00001153 install_element(BTS_NODE, &cfg_trx_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001154 install_node(&trx_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001155 install_default(TRX_NODE);
Harald Welte5258fc42009-03-28 19:07:53 +00001156 install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
Harald Welte879dc972009-06-20 22:36:12 +02001157 install_element(TRX_NODE, &cfg_trx_max_power_red_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001158
Harald Welte5258fc42009-03-28 19:07:53 +00001159 install_element(TRX_NODE, &cfg_ts_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001160 install_node(&ts_node, dummy_config_write);
Harald Welte68628e82009-03-10 12:17:57 +00001161 install_default(TS_NODE);
Harald Weltea6fd58e2009-08-07 00:25:23 +02001162 install_element(TS_NODE, &cfg_ts_pchan_cmd);
1163 install_element(TS_NODE, &cfg_ts_e1_subslot_cmd);
Harald Welte68628e82009-03-10 12:17:57 +00001164
Harald Welte40f82892009-05-23 17:31:39 +00001165 install_element(CONFIG_NODE, &cfg_subscr_cmd);
1166 install_node(&subscr_node, dummy_config_write);
1167 install_default(SUBSCR_NODE);
1168 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
1169 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
1170 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
1171
Harald Welte68628e82009-03-10 12:17:57 +00001172 return 0;
1173}