blob: c23c1c2bf782860d8e3b30fd1483072b117a6290 [file] [log] [blame]
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02001/* OpenBSC interface to quagga VTY */
2/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freythere33966c2009-10-27 12:47:06 +01003 * (C) 2009 by Holger Hans Peter Freyther
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02004 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <stdlib.h>
23#include <unistd.h>
24#include <sys/types.h>
25
Harald Welte4b037e42010-05-19 19:45:32 +020026#include <osmocom/vty/command.h>
27#include <osmocom/vty/buffer.h>
28#include <osmocom/vty/vty.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020029
30#include <arpa/inet.h>
31
Harald Weltedfe6c7d2010-02-20 16:24:02 +010032#include <osmocore/linuxlist.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020033#include <openbsc/gsm_data.h>
34#include <openbsc/gsm_subscriber.h>
Harald Welteb54d9502009-11-17 06:00:23 +010035#include <openbsc/silent_call.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020036#include <openbsc/gsm_04_11.h>
37#include <openbsc/e1_input.h>
38#include <openbsc/abis_nm.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010039#include <osmocore/gsm_utils.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020040#include <openbsc/db.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010041#include <osmocore/talloc.h>
Harald Weltea1482332009-11-14 10:08:40 +010042#include <openbsc/signal.h>
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010043#include <openbsc/debug.h>
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +020044#include <openbsc/vty.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020045
Harald Weltedcccb182010-05-16 20:52:23 +020046extern struct gsm_network *gsmnet_from_vty(struct vty *v);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020047
48struct cmd_node subscr_node = {
49 SUBSCR_NODE,
50 "%s(subscriber)#",
51 1,
52};
53
Harald Welte62ab20c2010-05-14 18:59:17 +020054/* Down vty node level. */
55DEFUN(subscr_node_exit,
56 subscr_node_exit_cmd, "exit", "Exit current mode and down to previous mode\n")
57{
58 switch (vty->node) {
59 case SUBSCR_NODE:
60 vty->node = VIEW_NODE;
61 subscr_put(vty->index);
62 vty->index = NULL;
63 break;
64 }
65 return CMD_SUCCESS;
66}
67
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020068static int dummy_config_write(struct vty *v)
69{
70 return CMD_SUCCESS;
71}
72
Sylvain Munaut99792902009-12-27 19:30:46 +010073static int hexparse(const char *str, u_int8_t *b, int max_len)
74
75{
76 int i, l, v;
77
78 l = strlen(str);
79 if ((l&1) || ((l>>1) > max_len))
80 return -1;
81
82 memset(b, 0x00, max_len);
83
84 for (i=0; i<l; i++) {
85 char c = str[i];
86 if (c >= '0' && c <= '9')
87 v = c - '0';
88 else if (c >= 'a' && c <= 'f')
89 v = 10 + (c - 'a');
90 else if (c >= 'A' && c <= 'F')
91 v = 10 + (c - 'a');
92 else
93 return -1;
94 b[i>>1] |= v << (i&1 ? 0 : 4);
95 }
96
97 return i>>1;
98}
99
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200100/* per-subscriber configuration */
101DEFUN(cfg_subscr,
102 cfg_subscr_cmd,
103 "subscriber IMSI",
104 "Select a Subscriber to configure\n")
105{
Harald Weltedcccb182010-05-16 20:52:23 +0200106 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200107 const char *imsi = argv[0];
108 struct gsm_subscriber *subscr;
109
110 subscr = subscr_get_by_imsi(gsmnet, imsi);
111 if (!subscr) {
112 vty_out(vty, "%% No subscriber for IMSI %s%s",
113 imsi, VTY_NEWLINE);
114 return CMD_WARNING;
115 }
116
Holger Hans Peter Freythere33966c2009-10-27 12:47:06 +0100117 /* vty_go_parent should put this subscriber */
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200118 vty->index = subscr;
119 vty->node = SUBSCR_NODE;
120
121 return CMD_SUCCESS;
122}
123
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100124static void subscr_dump_full_vty(struct vty *vty, struct gsm_subscriber *subscr)
125{
126 int rc;
127 struct gsm_auth_info ainfo;
128 struct gsm_auth_tuple atuple;
129
130 vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
131 subscr->authorized, VTY_NEWLINE);
132 if (subscr->name)
133 vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
134 if (subscr->extension)
135 vty_out(vty, " Extension: %s%s", subscr->extension,
136 VTY_NEWLINE);
137 if (subscr->imsi)
138 vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
139 if (subscr->tmsi != GSM_RESERVED_TMSI)
140 vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
141 VTY_NEWLINE);
142
143 rc = get_authinfo_by_subscr(&ainfo, subscr);
144 if (!rc) {
145 vty_out(vty, " A3A8 algorithm id: %d%s",
146 ainfo.auth_algo, VTY_NEWLINE);
147 vty_out(vty, " A3A8 Ki: %s%s",
148 hexdump(ainfo.a3a8_ki, ainfo.a3a8_ki_len),
149 VTY_NEWLINE);
150 }
151
152 rc = get_authtuple_by_subscr(&atuple, subscr);
153 if (!rc) {
154 vty_out(vty, " A3A8 last tuple (used %d times):%s",
155 atuple.use_count, VTY_NEWLINE);
156 vty_out(vty, " seq # : %d%s",
157 atuple.key_seq, VTY_NEWLINE);
158 vty_out(vty, " RAND : %s%s",
159 hexdump(atuple.rand, sizeof(atuple.rand)),
160 VTY_NEWLINE);
161 vty_out(vty, " SRES : %s%s",
162 hexdump(atuple.sres, sizeof(atuple.sres)),
163 VTY_NEWLINE);
164 vty_out(vty, " Kc : %s%s",
165 hexdump(atuple.kc, sizeof(atuple.kc)),
166 VTY_NEWLINE);
167 }
168
169 vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
170}
171
172
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200173/* Subscriber */
174DEFUN(show_subscr,
175 show_subscr_cmd,
176 "show subscriber [IMSI]",
177 SHOW_STR "Display information about a subscriber\n")
178{
Harald Weltedcccb182010-05-16 20:52:23 +0200179 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200180 const char *imsi;
181 struct gsm_subscriber *subscr;
182
183 if (argc >= 1) {
184 imsi = argv[0];
185 subscr = subscr_get_by_imsi(gsmnet, imsi);
186 if (!subscr) {
187 vty_out(vty, "%% unknown subscriber%s",
188 VTY_NEWLINE);
189 return CMD_WARNING;
190 }
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100191 subscr_dump_full_vty(vty, subscr);
Holger Hans Peter Freythere33966c2009-10-27 12:47:06 +0100192 subscr_put(subscr);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200193
194 return CMD_SUCCESS;
195 }
196
197 /* FIXME: iterate over all subscribers ? */
198 return CMD_WARNING;
199
200 return CMD_SUCCESS;
201}
202
203DEFUN(show_subscr_cache,
204 show_subscr_cache_cmd,
205 "show subscriber cache",
206 SHOW_STR "Display contents of subscriber cache\n")
207{
208 struct gsm_subscriber *subscr;
209
210 llist_for_each_entry(subscr, &active_subscribers, entry) {
211 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100212 subscr_dump_full_vty(vty, subscr);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200213 }
214
215 return CMD_SUCCESS;
216}
217
218DEFUN(sms_send_pend,
219 sms_send_pend_cmd,
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100220 "sms send pending",
221 "Send all pending SMS")
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200222{
Harald Weltedcccb182010-05-16 20:52:23 +0200223 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200224 struct gsm_sms *sms;
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100225 int id = 0;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200226
227 while (1) {
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100228 sms = db_sms_get_unsent_by_subscr(gsmnet, id);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200229 if (!sms)
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100230 break;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200231
232 gsm411_send_sms_subscr(sms->receiver, sms);
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100233
234 id = sms->receiver->id + 1;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200235 }
236
237 return CMD_SUCCESS;
238}
239
240struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver, const char *text)
241{
242 struct gsm_sms *sms = sms_alloc();
243
244 if (!sms)
245 return NULL;
246
247 if (!receiver->lac) {
248 /* subscriber currently not attached, store in database? */
249 return NULL;
250 }
251
252 sms->receiver = subscr_get(receiver);
253 strncpy(sms->text, text, sizeof(sms->text)-1);
254
255 /* FIXME: don't use ID 1 static */
Harald Weltedcccb182010-05-16 20:52:23 +0200256 sms->sender = subscr_get_by_id(receiver->net, 1);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200257 sms->reply_path_req = 0;
258 sms->status_rep_req = 0;
259 sms->ud_hdr_ind = 0;
260 sms->protocol_id = 0; /* implicit */
261 sms->data_coding_scheme = 0; /* default 7bit */
262 strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1);
263 /* Generate user_data */
264 sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text);
265
266 return sms;
267}
268
Harald Welte20474ad2010-05-16 19:28:32 +0200269static int _send_sms_str(struct gsm_subscriber *receiver, char *str,
270 u_int8_t tp_pid)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200271{
272 struct gsm_sms *sms;
273
Harald Welte20474ad2010-05-16 19:28:32 +0200274 sms = sms_from_text(receiver, str);
Harald Welte793a1352009-11-05 15:51:17 +0900275 sms->protocol_id = tp_pid;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200276 gsm411_send_sms_subscr(receiver, sms);
277
278 return CMD_SUCCESS;
279}
280
Harald Weltedcccb182010-05-16 20:52:23 +0200281static struct gsm_subscriber *get_subscr_by_argv(struct gsm_network *gsmnet,
282 const char *type,
Harald Welte98f9c752009-11-14 08:00:53 +0100283 const char *id)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200284{
Harald Welte98f9c752009-11-14 08:00:53 +0100285 if (!strcmp(type, "extension"))
286 return subscr_get_by_extension(gsmnet, id);
287 else if (!strcmp(type, "imsi"))
288 return subscr_get_by_imsi(gsmnet, id);
289 else if (!strcmp(type, "tmsi"))
290 return subscr_get_by_tmsi(gsmnet, atoi(id));
291 else if (!strcmp(type, "id"))
292 return subscr_get_by_id(gsmnet, atoi(id));
293
294 return NULL;
295}
296#define SUBSCR_TYPES "(extension|imsi|tmsi|id)"
Harald Welte28326062010-05-14 20:05:17 +0200297#define SUBSCR_HELP "Operations on a Subscriber\n" \
298 "Identify subscriber by his extension (phone number)\n" \
299 "Identify subscriber by his IMSI\n" \
300 "Identify subscriber by his TMSI\n" \
301 "Identify subscriber by his database ID\n" \
302 "Identifier for the subscriber\n"
Harald Welte98f9c752009-11-14 08:00:53 +0100303
304DEFUN(subscriber_send_sms,
305 subscriber_send_sms_cmd,
306 "subscriber " SUBSCR_TYPES " EXTEN sms send .LINE",
Harald Welte28326062010-05-14 20:05:17 +0200307 SUBSCR_HELP "SMS Operations\n" "Send SMS\n" "Actual SMS Text")
Harald Welte98f9c752009-11-14 08:00:53 +0100308{
Harald Weltedcccb182010-05-16 20:52:23 +0200309 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
310 struct gsm_subscriber *subscr = get_subscr_by_argv(gsmnet, argv[0], argv[1]);
Harald Welte20474ad2010-05-16 19:28:32 +0200311 char *str;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200312 int rc;
313
Harald Welte20f98312009-11-14 10:11:45 +0100314 if (!subscr) {
315 vty_out(vty, "%% No subscriber found for %s %s%s",
316 argv[0], argv[1], VTY_NEWLINE);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200317 return CMD_WARNING;
Harald Welte20f98312009-11-14 10:11:45 +0100318 }
Harald Welte20474ad2010-05-16 19:28:32 +0200319 str = argv_concat(argv, argc, 2);
320 rc = _send_sms_str(subscr, str, 0);
321 talloc_free(str);
Harald Welte793a1352009-11-05 15:51:17 +0900322
Harald Welteaf8c7b42009-11-14 10:10:54 +0100323 subscr_put(subscr);
324
Harald Welte793a1352009-11-05 15:51:17 +0900325 return rc;
326}
327
Harald Welte98f9c752009-11-14 08:00:53 +0100328DEFUN(subscriber_silent_sms,
329 subscriber_silent_sms_cmd,
Harald Welte28326062010-05-14 20:05:17 +0200330 "subscriber " SUBSCR_TYPES " EXTEN silent-sms send .LINE",
331 SUBSCR_HELP
332 "Silent SMS Operation\n" "Send Silent SMS\n" "Actual SMS text\n")
Harald Welte793a1352009-11-05 15:51:17 +0900333{
Harald Weltedcccb182010-05-16 20:52:23 +0200334 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
335 struct gsm_subscriber *subscr = get_subscr_by_argv(gsmnet, argv[0], argv[1]);
Harald Welte20474ad2010-05-16 19:28:32 +0200336 char *str;
Harald Welte793a1352009-11-05 15:51:17 +0900337 int rc;
338
Harald Welte20f98312009-11-14 10:11:45 +0100339 if (!subscr) {
340 vty_out(vty, "%% No subscriber found for %s %s%s",
341 argv[0], argv[1], VTY_NEWLINE);
Harald Welte793a1352009-11-05 15:51:17 +0900342 return CMD_WARNING;
Harald Welte20f98312009-11-14 10:11:45 +0100343 }
Harald Welte793a1352009-11-05 15:51:17 +0900344
Harald Welte20474ad2010-05-16 19:28:32 +0200345 str = argv_concat(argv, argc, 2);
346 rc = _send_sms_str(subscr, str, 0);
347 talloc_free(str);
Harald Welte793a1352009-11-05 15:51:17 +0900348
Harald Welteaf8c7b42009-11-14 10:10:54 +0100349 subscr_put(subscr);
350
Harald Welte793a1352009-11-05 15:51:17 +0900351 return rc;
352}
353
Harald Welte28326062010-05-14 20:05:17 +0200354#define CHAN_TYPES "(any|tch/f|tch/any|sdcch)"
355#define CHAN_TYPE_HELP \
356 "Any channel\n" \
357 "TCH/F channel\n" \
358 "Any TCH channel\n" \
359 "SDCCH channel\n"
360
Sylvain Munaut50480702010-01-02 14:29:43 +0100361DEFUN(subscriber_silent_call_start,
362 subscriber_silent_call_start_cmd,
Harald Welte28326062010-05-14 20:05:17 +0200363 "subscriber " SUBSCR_TYPES " EXTEN silent-call start (any|tch/f|tch/any|sdcch)",
364 SUBSCR_HELP "Silent call operation\n" "Start silent call\n"
365 CHAN_TYPE_HELP)
Sylvain Munaut50480702010-01-02 14:29:43 +0100366{
Harald Weltedcccb182010-05-16 20:52:23 +0200367 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
368 struct gsm_subscriber *subscr = get_subscr_by_argv(gsmnet, argv[0], argv[1]);
Sylvain Munaut50480702010-01-02 14:29:43 +0100369 int rc, type;
370
371 if (!subscr) {
372 vty_out(vty, "%% No subscriber found for %s %s%s",
373 argv[0], argv[1], VTY_NEWLINE);
374 return CMD_WARNING;
375 }
376
377 if (!strcmp(argv[2], "tch/f"))
378 type = RSL_CHANNEED_TCH_F;
379 else if (!strcmp(argv[2], "tch/any"))
380 type = RSL_CHANNEED_TCH_ForH;
381 else if (!strcmp(argv[2], "sdcch"))
382 type = RSL_CHANNEED_SDCCH;
383 else
384 type = RSL_CHANNEED_ANY; /* Defaults to ANY */
385
386 rc = gsm_silent_call_start(subscr, vty, type);
387 if (rc <= 0) {
388 vty_out(vty, "%% Subscriber not attached%s",
389 VTY_NEWLINE);
390 subscr_put(subscr);
391 return CMD_WARNING;
392 }
393
394 subscr_put(subscr);
395
396 return CMD_SUCCESS;
397}
398
399DEFUN(subscriber_silent_call_stop,
400 subscriber_silent_call_stop_cmd,
Harald Welte28326062010-05-14 20:05:17 +0200401 "subscriber " SUBSCR_TYPES " EXTEN silent-call stop",
402 SUBSCR_HELP "Silent call operation\n" "Stop silent call\n"
403 CHAN_TYPE_HELP)
Harald Weltea1482332009-11-14 10:08:40 +0100404{
Harald Weltedcccb182010-05-16 20:52:23 +0200405 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
406 struct gsm_subscriber *subscr = get_subscr_by_argv(gsmnet, argv[0], argv[1]);
Harald Weltea1482332009-11-14 10:08:40 +0100407 int rc;
408
409 if (!subscr) {
410 vty_out(vty, "%% No subscriber found for %s %s%s",
Harald Welte20f98312009-11-14 10:11:45 +0100411 argv[0], argv[1], VTY_NEWLINE);
Harald Weltea1482332009-11-14 10:08:40 +0100412 return CMD_WARNING;
413 }
414
Sylvain Munaut50480702010-01-02 14:29:43 +0100415 rc = gsm_silent_call_stop(subscr);
416 if (rc < 0) {
417 subscr_put(subscr);
418 return CMD_WARNING;
Harald Weltea1482332009-11-14 10:08:40 +0100419 }
420
421 subscr_put(subscr);
422
423 return CMD_SUCCESS;
424}
425
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200426DEFUN(cfg_subscr_name,
427 cfg_subscr_name_cmd,
428 "name NAME",
429 "Set the name of the subscriber")
430{
431 const char *name = argv[0];
432 struct gsm_subscriber *subscr = vty->index;
433
434 strncpy(subscr->name, name, sizeof(subscr->name));
435
436 db_sync_subscriber(subscr);
437
438 return CMD_SUCCESS;
439}
440
441DEFUN(cfg_subscr_extension,
442 cfg_subscr_extension_cmd,
443 "extension EXTENSION",
444 "Set the extension of the subscriber")
445{
446 const char *name = argv[0];
447 struct gsm_subscriber *subscr = vty->index;
448
449 strncpy(subscr->extension, name, sizeof(subscr->extension));
450
451 db_sync_subscriber(subscr);
452
453 return CMD_SUCCESS;
454}
455
456DEFUN(cfg_subscr_authorized,
457 cfg_subscr_authorized_cmd,
Harald Welte28326062010-05-14 20:05:17 +0200458 "auth (0|1)",
459 "Set the authorization status of the subscriber\n"
460 "Not authorized\n" "Authorized\n")
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200461{
462 int auth = atoi(argv[0]);
463 struct gsm_subscriber *subscr = vty->index;
464
465 if (auth)
466 subscr->authorized = 1;
467 else
468 subscr->authorized = 0;
469
470 db_sync_subscriber(subscr);
471
472 return CMD_SUCCESS;
473}
474
Sylvain Munaut99792902009-12-27 19:30:46 +0100475#define A3A8_ALG_TYPES "(none|comp128v1)"
Harald Welte28326062010-05-14 20:05:17 +0200476#define A3A8_ALG_HELP \
477 "Use No A3A8 algorithm\n" \
478 "Use COMP128v1 algorithm\n"
Sylvain Munaut99792902009-12-27 19:30:46 +0100479
480DEFUN(cfg_subscr_a3a8,
481 cfg_subscr_a3a8_cmd,
482 "a3a8 " A3A8_ALG_TYPES " [KI]",
Harald Welte28326062010-05-14 20:05:17 +0200483 "Set a3a8 parameters for the subscriber\n" A3A8_ALG_HELP
484 "Encryption Key Ki\n")
Sylvain Munaut99792902009-12-27 19:30:46 +0100485{
486 struct gsm_subscriber *subscr = vty->index;
487 const char *alg_str = argv[0];
488 const char *ki_str = argv[1];
489 struct gsm_auth_info ainfo;
490 int rc;
491
492 if (!strcasecmp(alg_str, "none")) {
493 /* Just erase */
494 rc = set_authinfo_for_subscr(NULL, subscr);
495 } else if (!strcasecmp(alg_str, "comp128v1")) {
496 /* Parse hex string Ki */
497 rc = hexparse(ki_str, ainfo.a3a8_ki, sizeof(ainfo.a3a8_ki));
498 if (rc != 16)
499 return CMD_WARNING;
500
501 /* Set the infos */
502 ainfo.auth_algo = AUTH_ALGO_COMP128v1;
503 ainfo.a3a8_ki_len = rc;
504 rc = set_authinfo_for_subscr(&ainfo, subscr);
505 } else {
506 /* Unknown method */
507 return CMD_WARNING;
508 }
509
510 return rc ? CMD_WARNING : CMD_SUCCESS;
511}
512
Harald Weltea1482332009-11-14 10:08:40 +0100513static int scall_cbfn(unsigned int subsys, unsigned int signal,
514 void *handler_data, void *signal_data)
515{
516 struct scall_signal_data *sigdata = signal_data;
517 struct vty *vty = sigdata->data;
518
519 switch (signal) {
520 case S_SCALL_SUCCESS:
521 vty_out(vty, "%% silent call on ARFCN %u timeslot %u%s",
522 sigdata->lchan->ts->trx->arfcn, sigdata->lchan->ts->nr,
523 VTY_NEWLINE);
524 break;
525 case S_SCALL_EXPIRED:
526 vty_out(vty, "%% silent call expired paging%s", VTY_NEWLINE);
527 break;
528 }
529 return 0;
530}
531
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200532DEFUN(show_stats,
533 show_stats_cmd,
534 "show statistics",
535 SHOW_STR "Display network statistics\n")
536{
Harald Weltedcccb182010-05-16 20:52:23 +0200537 struct gsm_network *net = gsmnet_from_vty(vty);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200538
539 openbsc_vty_print_statistics(vty, net);
540 vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s",
541 counter_get(net->stats.loc_upd_type.attach),
542 counter_get(net->stats.loc_upd_type.normal),
543 counter_get(net->stats.loc_upd_type.periodic), VTY_NEWLINE);
544 vty_out(vty, "IMSI Detach Indications : %lu%s",
545 counter_get(net->stats.loc_upd_type.detach), VTY_NEWLINE);
546 vty_out(vty, "Location Update Response: %lu accept, %lu reject%s",
547 counter_get(net->stats.loc_upd_resp.accept),
548 counter_get(net->stats.loc_upd_resp.reject), VTY_NEWLINE);
549 vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, "
550 "%lu completed, %lu failed%s",
551 counter_get(net->stats.handover.attempted),
552 counter_get(net->stats.handover.no_channel),
553 counter_get(net->stats.handover.timeout),
554 counter_get(net->stats.handover.completed),
555 counter_get(net->stats.handover.failed), VTY_NEWLINE);
556 vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s",
557 counter_get(net->stats.sms.submitted),
558 counter_get(net->stats.sms.no_receiver), VTY_NEWLINE);
559 vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s",
560 counter_get(net->stats.sms.delivered),
561 counter_get(net->stats.sms.rp_err_mem),
562 counter_get(net->stats.sms.rp_err_other), VTY_NEWLINE);
563 return CMD_SUCCESS;
564}
565
566
Harald Weltedcccb182010-05-16 20:52:23 +0200567int bsc_vty_init_extra(void)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200568{
Harald Weltea1482332009-11-14 10:08:40 +0100569 register_signal_handler(SS_SCALL, scall_cbfn, NULL);
570
Harald Welteb4d5b172010-05-12 16:10:35 +0000571 install_element_ve(&show_subscr_cmd);
572 install_element_ve(&show_subscr_cache_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200573
Harald Welteb4d5b172010-05-12 16:10:35 +0000574 install_element_ve(&sms_send_pend_cmd);
Harald Welte98f9c752009-11-14 08:00:53 +0100575
Harald Welteb4d5b172010-05-12 16:10:35 +0000576 install_element_ve(&subscriber_send_sms_cmd);
577 install_element_ve(&subscriber_silent_sms_cmd);
578 install_element_ve(&subscriber_silent_call_start_cmd);
579 install_element_ve(&subscriber_silent_call_stop_cmd);
580 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200581
582 install_element(CONFIG_NODE, &cfg_subscr_cmd);
583 install_node(&subscr_node, dummy_config_write);
584
585 install_default(SUBSCR_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200586 install_element(SUBSCR_NODE, &subscr_node_exit_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200587 install_element(SUBSCR_NODE, &cfg_subscr_name_cmd);
588 install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd);
589 install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd);
Sylvain Munaut99792902009-12-27 19:30:46 +0100590 install_element(SUBSCR_NODE, &cfg_subscr_a3a8_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200591
592 return 0;
593}