blob: 864597d6c32a4e9bc64f377b505c005b7062e741 [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 Freyther0e7d0712011-04-18 17:15:53 +02003 * (C) 2009-2011 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
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +02009 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020018 *
19 */
20
21#include <stdlib.h>
Holger Hans Peter Freyther73b878a2010-12-25 00:33:40 +010022#include <limits.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020023#include <unistd.h>
Holger Hans Peter Freytherb9708942013-07-27 19:42:35 +020024#include <time.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020025#include <inttypes.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020026
Harald Welte4b037e42010-05-19 19:45:32 +020027#include <osmocom/vty/command.h>
28#include <osmocom/vty/buffer.h>
29#include <osmocom/vty/vty.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020030
31#include <arpa/inet.h>
32
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010033#include <osmocom/core/linuxlist.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020034#include <openbsc/gsm_data.h>
35#include <openbsc/gsm_subscriber.h>
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010036#include <openbsc/bsc_subscriber.h>
Harald Welteb54d9502009-11-17 06:00:23 +010037#include <openbsc/silent_call.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020038#include <openbsc/gsm_04_11.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020039#include <osmocom/abis/e1_input.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020040#include <openbsc/abis_nm.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010041#include <osmocom/gsm/gsm_utils.h>
42#include <osmocom/core/utils.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020043#include <openbsc/db.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010044#include <osmocom/core/talloc.h>
Harald Weltea1482332009-11-14 10:08:40 +010045#include <openbsc/signal.h>
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010046#include <openbsc/debug.h>
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +020047#include <openbsc/vty.h>
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080048#include <openbsc/gsm_04_80.h>
Harald Welte94307772017-06-12 01:52:27 +020049#include <openbsc/gsm_04_14.h>
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080050#include <openbsc/chan_alloc.h>
Holger Hans Peter Freyther81c0e252010-12-25 14:08:00 +010051#include <openbsc/sms_queue.h>
Harald Welteab386e62011-09-01 18:18:43 +020052#include <openbsc/mncc_int.h>
Holger Hans Peter Freyther44853212012-12-25 08:37:36 +010053#include <openbsc/handover.h>
Harald Welte2483f1b2016-06-19 18:06:02 +020054#include <openbsc/vlr.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020055
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +010056#include <osmocom/vty/logging.h>
57
Harald Welte2483f1b2016-06-19 18:06:02 +020058#include <openbsc/osmo_msc.h>
59
Harald Welteb4771a62012-11-11 10:58:51 +010060#include "meas_feed.h"
61
Harald Weltedcccb182010-05-16 20:52:23 +020062extern struct gsm_network *gsmnet_from_vty(struct vty *v);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020063
Harald Welte2483f1b2016-06-19 18:06:02 +020064static void subscr_dump_full_vty(struct vty *vty, struct vlr_subscr *vsub)
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010065{
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +020066 int reqs;
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +020067 struct llist_head *entry;
Holger Hans Peter Freytherb9708942013-07-27 19:42:35 +020068 char expire_time[200];
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010069
Harald Welte2483f1b2016-06-19 18:06:02 +020070 if (strlen(vsub->name))
71 vty_out(vty, " Name: '%s'%s", vsub->name, VTY_NEWLINE);
72 if (strlen(vsub->msisdn))
73 vty_out(vty, " Extension: %s%s", vsub->msisdn,
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010074 VTY_NEWLINE);
Holger Hans Peter Freyther3d76e442010-12-25 16:40:54 +010075 vty_out(vty, " LAC: %d/0x%x%s",
Harald Welte2483f1b2016-06-19 18:06:02 +020076 vsub->lac, vsub->lac, VTY_NEWLINE);
77 vty_out(vty, " IMSI: %s%s", vsub->imsi, VTY_NEWLINE);
78 if (vsub->tmsi != GSM_RESERVED_TMSI)
79 vty_out(vty, " TMSI: %08X%s", vsub->tmsi,
80 VTY_NEWLINE);
81 if (vsub->tmsi_new != GSM_RESERVED_TMSI)
82 vty_out(vty, " new TMSI: %08X%s", vsub->tmsi_new,
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010083 VTY_NEWLINE);
84
Harald Welte2483f1b2016-06-19 18:06:02 +020085#if 0
86 /* TODO: add this to vlr_subscr? */
87 if (vsub->auth_info.auth_algo != AUTH_ALGO_NONE) {
88 struct gsm_auth_info *i = &vsub->auth_info;
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010089 vty_out(vty, " A3A8 algorithm id: %d%s",
Harald Welte2483f1b2016-06-19 18:06:02 +020090 i->auth_algo, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010091 vty_out(vty, " A3A8 Ki: %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +020092 osmo_hexdump(i->a3a8_ki, i->a3a8_ki_len),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010093 VTY_NEWLINE);
94 }
Harald Welte2483f1b2016-06-19 18:06:02 +020095#endif
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010096
Harald Welte2483f1b2016-06-19 18:06:02 +020097 if (vsub->last_tuple) {
98 struct gsm_auth_tuple *t = vsub->last_tuple;
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010099 vty_out(vty, " A3A8 last tuple (used %d times):%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200100 t->use_count, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100101 vty_out(vty, " seq # : %d%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200102 t->key_seq, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100103 vty_out(vty, " RAND : %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200104 osmo_hexdump(t->vec.rand, sizeof(t->vec.rand)),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100105 VTY_NEWLINE);
106 vty_out(vty, " SRES : %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200107 osmo_hexdump(t->vec.sres, sizeof(t->vec.sres)),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100108 VTY_NEWLINE);
109 vty_out(vty, " Kc : %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200110 osmo_hexdump(t->vec.kc, sizeof(t->vec.kc)),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100111 VTY_NEWLINE);
112 }
Holger Hans Peter Freytherb9708942013-07-27 19:42:35 +0200113
114 /* print the expiration time of a subscriber */
115 strftime(expire_time, sizeof(expire_time),
Harald Welte2483f1b2016-06-19 18:06:02 +0200116 "%a, %d %b %Y %T %z", localtime(&vsub->expire_lu));
Holger Hans Peter Freytherb9708942013-07-27 19:42:35 +0200117 expire_time[sizeof(expire_time) - 1] = '\0';
118 vty_out(vty, " Expiration Time: %s%s", expire_time, VTY_NEWLINE);
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +0200119
120 reqs = 0;
Harald Welte2483f1b2016-06-19 18:06:02 +0200121 llist_for_each(entry, &vsub->cs.requests)
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +0200122 reqs += 1;
Harald Welte2483f1b2016-06-19 18:06:02 +0200123 vty_out(vty, " Paging: %s paging for %d requests%s",
124 vsub->cs.is_paging ? "is" : "not", reqs, VTY_NEWLINE);
125 vty_out(vty, " Use count: %u%s", vsub->use_count, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100126}
127
128
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200129/* Subscriber */
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200130DEFUN(show_subscr_cache,
131 show_subscr_cache_cmd,
132 "show subscriber cache",
Harald Weltecfaabbb2012-08-16 23:23:50 +0200133 SHOW_STR "Show information about subscribers\n"
134 "Display contents of subscriber cache\n")
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200135{
Harald Welte2483f1b2016-06-19 18:06:02 +0200136 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
137 struct vlr_subscr *vsub;
138 int count = 0;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200139
Harald Welte2483f1b2016-06-19 18:06:02 +0200140 llist_for_each_entry(vsub, &gsmnet->vlr->subscribers, list) {
141 if (++count > 100) {
142 vty_out(vty, "%% More than %d subscribers in cache,"
143 " stopping here.%s", count-1, VTY_NEWLINE);
144 break;
145 }
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200146 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
Harald Welte2483f1b2016-06-19 18:06:02 +0200147 subscr_dump_full_vty(vty, vsub);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200148 }
149
150 return CMD_SUCCESS;
151}
152
153DEFUN(sms_send_pend,
154 sms_send_pend_cmd,
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100155 "sms send pending",
Neels Hofmeyrd1fdefe2016-04-01 02:17:24 +0200156 "SMS related commands\n" "SMS Sending related commands\n"
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100157 "Send all pending SMS")
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200158{
Harald Weltedcccb182010-05-16 20:52:23 +0200159 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200160 struct gsm_sms *sms;
Harald Welte2483f1b2016-06-19 18:06:02 +0200161 unsigned long long sms_id = 0;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200162
163 while (1) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200164 sms = db_sms_get_next_unsent(gsmnet, sms_id, UINT_MAX);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200165 if (!sms)
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100166 break;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200167
Harald Welte2483f1b2016-06-19 18:06:02 +0200168 if (sms->receiver)
169 gsm411_send_sms_subscr(sms->receiver, sms);
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100170
Harald Welte2483f1b2016-06-19 18:06:02 +0200171 sms_id = sms->id + 1;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200172 }
173
174 return CMD_SUCCESS;
175}
176
Harald Welte2483f1b2016-06-19 18:06:02 +0200177static int _send_sms_str(struct vlr_subscr *receiver,
178 struct vlr_subscr *sender,
179 char *str, uint8_t tp_pid)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200180{
Harald Welte2483f1b2016-06-19 18:06:02 +0200181 struct gsm_network *net = receiver->vlr->user_ctx;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200182 struct gsm_sms *sms;
183
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100184 sms = sms_from_text(receiver, sender, 0, str);
Harald Welte793a1352009-11-05 15:51:17 +0900185 sms->protocol_id = tp_pid;
Nico Golde59502362010-06-29 20:13:06 +0200186
Holger Hans Peter Freyther445e6152010-12-25 15:57:34 +0100187 /* store in database for the queue */
188 if (db_sms_store(sms) != 0) {
Holger Hans Peter Freythereff409492012-11-10 19:46:58 +0100189 LOGP(DLSMS, LOGL_ERROR, "Failed to store SMS in Database\n");
Holger Hans Peter Freyther445e6152010-12-25 15:57:34 +0100190 sms_free(sms);
191 return CMD_WARNING;
Nico Golde59502362010-06-29 20:13:06 +0200192 }
Neels Hofmeyr1e918c32016-05-09 21:48:53 +0200193 LOGP(DLSMS, LOGL_DEBUG, "SMS stored in DB\n");
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200194
Holger Hans Peter Freyther445e6152010-12-25 15:57:34 +0100195 sms_free(sms);
Harald Welte2483f1b2016-06-19 18:06:02 +0200196 sms_queue_trigger(net->sms_queue);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200197 return CMD_SUCCESS;
198}
199
Harald Welte2483f1b2016-06-19 18:06:02 +0200200static struct vlr_subscr *get_vsub_by_argv(struct gsm_network *gsmnet,
201 const char *type,
202 const char *id)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200203{
Harald Welte2483f1b2016-06-19 18:06:02 +0200204 if (!strcmp(type, "extension") || !strcmp(type, "msisdn"))
205 return vlr_subscr_find_by_msisdn(gsmnet->vlr, id);
206 else if (!strcmp(type, "imsi") || !strcmp(type, "id"))
207 return vlr_subscr_find_by_imsi(gsmnet->vlr, id);
Harald Welte98f9c752009-11-14 08:00:53 +0100208 else if (!strcmp(type, "tmsi"))
Harald Welte2483f1b2016-06-19 18:06:02 +0200209 return vlr_subscr_find_by_tmsi(gsmnet->vlr, atoi(id));
Harald Welte98f9c752009-11-14 08:00:53 +0100210
211 return NULL;
212}
213#define SUBSCR_TYPES "(extension|imsi|tmsi|id)"
Harald Welte28326062010-05-14 20:05:17 +0200214#define SUBSCR_HELP "Operations on a Subscriber\n" \
Neels Hofmeyrd1fdefe2016-04-01 02:17:24 +0200215 "Identify subscriber by extension (phone number)\n" \
216 "Identify subscriber by IMSI\n" \
217 "Identify subscriber by TMSI\n" \
218 "Identify subscriber by database ID\n" \
Harald Welte28326062010-05-14 20:05:17 +0200219 "Identifier for the subscriber\n"
Harald Welte98f9c752009-11-14 08:00:53 +0100220
Harald Welteb4a84e12010-05-27 10:44:58 +0200221DEFUN(show_subscr,
222 show_subscr_cmd,
223 "show subscriber " SUBSCR_TYPES " ID",
224 SHOW_STR SUBSCR_HELP)
225{
226 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200227 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0],
228 argv[1]);
Harald Welteb4a84e12010-05-27 10:44:58 +0200229
Harald Welte2483f1b2016-06-19 18:06:02 +0200230 if (!vsub) {
Harald Welteb4a84e12010-05-27 10:44:58 +0200231 vty_out(vty, "%% No subscriber found for %s %s%s",
232 argv[0], argv[1], VTY_NEWLINE);
233 return CMD_WARNING;
234 }
235
Harald Welte2483f1b2016-06-19 18:06:02 +0200236 subscr_dump_full_vty(vty, vsub);
Harald Welteb4a84e12010-05-27 10:44:58 +0200237
Harald Welte2483f1b2016-06-19 18:06:02 +0200238 vlr_subscr_put(vsub);
Harald Welteb4a84e12010-05-27 10:44:58 +0200239
240 return CMD_SUCCESS;
241}
242
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200243DEFUN(subscriber_create,
244 subscriber_create_cmd,
245 "subscriber create imsi ID",
246 "Operations on a Subscriber\n" \
247 "Create new subscriber\n" \
248 "Identify the subscriber by his IMSI\n" \
249 "Identifier for the subscriber\n")
250{
Harald Welte2483f1b2016-06-19 18:06:02 +0200251 vty_out(vty, "%% 'subscriber create' now needs to be done at osmo-hlr%s",
252 VTY_NEWLINE);
253 return CMD_WARNING;
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200254}
255
Nico Goldeb62b1232011-02-22 17:54:47 +0100256DEFUN(subscriber_send_pending_sms,
257 subscriber_send_pending_sms_cmd,
Holger Hans Peter Freyther3217fa22012-07-20 23:55:08 +0200258 "subscriber " SUBSCR_TYPES " ID sms pending-send",
Nico Goldeb62b1232011-02-22 17:54:47 +0100259 SUBSCR_HELP "SMS Operations\n" "Send pending SMS\n")
260{
261 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200262 struct vlr_subscr *vsub;
Nico Goldeb62b1232011-02-22 17:54:47 +0100263 struct gsm_sms *sms;
264
Harald Welte2483f1b2016-06-19 18:06:02 +0200265 vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
266 if (!vsub) {
Holger Hans Peter Freyther9feef482013-07-04 20:34:46 +0200267 vty_out(vty, "%% No subscriber found for %s %s%s",
268 argv[0], argv[1], VTY_NEWLINE);
269 return CMD_WARNING;
270 }
271
Harald Welte2483f1b2016-06-19 18:06:02 +0200272 sms = db_sms_get_unsent_for_subscr(vsub, UINT_MAX);
Nico Goldeb62b1232011-02-22 17:54:47 +0100273 if (sms)
274 gsm411_send_sms_subscr(sms->receiver, sms);
275
Harald Welte2483f1b2016-06-19 18:06:02 +0200276 vlr_subscr_put(vsub);
Nico Goldeb62b1232011-02-22 17:54:47 +0100277
278 return CMD_SUCCESS;
279}
280
Harald Welte98f9c752009-11-14 08:00:53 +0100281DEFUN(subscriber_send_sms,
282 subscriber_send_sms_cmd,
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100283 "subscriber " SUBSCR_TYPES " ID sms sender " SUBSCR_TYPES " SENDER_ID send .LINE",
Holger Hans Peter Freyther63b0e442013-03-03 09:32:08 +0100284 SUBSCR_HELP "SMS Operations\n" SUBSCR_HELP "Send SMS\n" "Actual SMS Text\n")
Harald Welte98f9c752009-11-14 08:00:53 +0100285{
Harald Weltedcccb182010-05-16 20:52:23 +0200286 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200287 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
288 struct vlr_subscr *sender = get_vsub_by_argv(gsmnet, argv[2], argv[3]);
Harald Welte20474ad2010-05-16 19:28:32 +0200289 char *str;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200290 int rc;
291
Harald Welte2483f1b2016-06-19 18:06:02 +0200292 if (!vsub) {
Harald Welte20f98312009-11-14 10:11:45 +0100293 vty_out(vty, "%% No subscriber found for %s %s%s",
294 argv[0], argv[1], VTY_NEWLINE);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100295 rc = CMD_WARNING;
296 goto err;
Harald Welte20f98312009-11-14 10:11:45 +0100297 }
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100298
299 if (!sender) {
300 vty_out(vty, "%% No sender found for %s %s%s",
301 argv[2], argv[3], VTY_NEWLINE);
302 rc = CMD_WARNING;
303 goto err;
304 }
305
306 str = argv_concat(argv, argc, 4);
Harald Welte2483f1b2016-06-19 18:06:02 +0200307 rc = _send_sms_str(vsub, sender, str, 0);
Harald Welte20474ad2010-05-16 19:28:32 +0200308 talloc_free(str);
Harald Welte793a1352009-11-05 15:51:17 +0900309
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100310err:
311 if (sender)
Harald Welte2483f1b2016-06-19 18:06:02 +0200312 vlr_subscr_put(sender);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100313
Harald Welte2483f1b2016-06-19 18:06:02 +0200314 if (vsub)
315 vlr_subscr_put(vsub);
Harald Welteaf8c7b42009-11-14 10:10:54 +0100316
Harald Welte793a1352009-11-05 15:51:17 +0900317 return rc;
318}
319
Harald Welte98f9c752009-11-14 08:00:53 +0100320DEFUN(subscriber_silent_sms,
321 subscriber_silent_sms_cmd,
Harald Welte1011d5b2014-07-10 20:19:00 +0200322
323 "subscriber " SUBSCR_TYPES " ID silent-sms sender " SUBSCR_TYPES " SENDER_ID send .LINE",
324 SUBSCR_HELP "Silent SMS Operations\n" SUBSCR_HELP "Send SMS\n" "Actual SMS Text\n")
Harald Welte793a1352009-11-05 15:51:17 +0900325{
Harald Weltedcccb182010-05-16 20:52:23 +0200326 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200327 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
328 struct vlr_subscr *sender = get_vsub_by_argv(gsmnet, argv[2], argv[3]);
Harald Welte20474ad2010-05-16 19:28:32 +0200329 char *str;
Harald Welte793a1352009-11-05 15:51:17 +0900330 int rc;
331
Harald Welte2483f1b2016-06-19 18:06:02 +0200332 if (!vsub) {
Harald Welte20f98312009-11-14 10:11:45 +0100333 vty_out(vty, "%% No subscriber found for %s %s%s",
334 argv[0], argv[1], VTY_NEWLINE);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100335 rc = CMD_WARNING;
336 goto err;
Harald Welte20f98312009-11-14 10:11:45 +0100337 }
Harald Welte793a1352009-11-05 15:51:17 +0900338
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100339 if (!sender) {
340 vty_out(vty, "%% No sender found for %s %s%s",
341 argv[2], argv[3], VTY_NEWLINE);
342 rc = CMD_WARNING;
343 goto err;
344 }
345
346 str = argv_concat(argv, argc, 4);
Harald Welte2483f1b2016-06-19 18:06:02 +0200347 rc = _send_sms_str(vsub, sender, str, 64);
Harald Welte20474ad2010-05-16 19:28:32 +0200348 talloc_free(str);
Harald Welte793a1352009-11-05 15:51:17 +0900349
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100350err:
351 if (sender)
Harald Welte2483f1b2016-06-19 18:06:02 +0200352 vlr_subscr_put(sender);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100353
Harald Welte2483f1b2016-06-19 18:06:02 +0200354 if (vsub)
355 vlr_subscr_put(vsub);
Harald Welteaf8c7b42009-11-14 10:10:54 +0100356
Harald Welte793a1352009-11-05 15:51:17 +0900357 return rc;
358}
359
Harald Welte28326062010-05-14 20:05:17 +0200360#define CHAN_TYPES "(any|tch/f|tch/any|sdcch)"
361#define CHAN_TYPE_HELP \
362 "Any channel\n" \
363 "TCH/F channel\n" \
364 "Any TCH channel\n" \
365 "SDCCH channel\n"
366
Sylvain Munaut50480702010-01-02 14:29:43 +0100367DEFUN(subscriber_silent_call_start,
368 subscriber_silent_call_start_cmd,
Harald Welteb4a84e12010-05-27 10:44:58 +0200369 "subscriber " SUBSCR_TYPES " ID silent-call start (any|tch/f|tch/any|sdcch)",
Harald Welte28326062010-05-14 20:05:17 +0200370 SUBSCR_HELP "Silent call operation\n" "Start silent call\n"
371 CHAN_TYPE_HELP)
Sylvain Munaut50480702010-01-02 14:29:43 +0100372{
Harald Weltedcccb182010-05-16 20:52:23 +0200373 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200374 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
Sylvain Munaut50480702010-01-02 14:29:43 +0100375 int rc, type;
376
Harald Welte2483f1b2016-06-19 18:06:02 +0200377 if (!vsub) {
Sylvain Munaut50480702010-01-02 14:29:43 +0100378 vty_out(vty, "%% No subscriber found for %s %s%s",
379 argv[0], argv[1], VTY_NEWLINE);
380 return CMD_WARNING;
381 }
382
383 if (!strcmp(argv[2], "tch/f"))
384 type = RSL_CHANNEED_TCH_F;
385 else if (!strcmp(argv[2], "tch/any"))
386 type = RSL_CHANNEED_TCH_ForH;
387 else if (!strcmp(argv[2], "sdcch"))
388 type = RSL_CHANNEED_SDCCH;
389 else
390 type = RSL_CHANNEED_ANY; /* Defaults to ANY */
391
Harald Welte2483f1b2016-06-19 18:06:02 +0200392 rc = gsm_silent_call_start(vsub, vty, type);
Sylvain Munaut50480702010-01-02 14:29:43 +0100393 if (rc <= 0) {
394 vty_out(vty, "%% Subscriber not attached%s",
395 VTY_NEWLINE);
Harald Welte2483f1b2016-06-19 18:06:02 +0200396 vlr_subscr_put(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100397 return CMD_WARNING;
398 }
399
Harald Welte2483f1b2016-06-19 18:06:02 +0200400 vlr_subscr_put(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100401
402 return CMD_SUCCESS;
403}
404
405DEFUN(subscriber_silent_call_stop,
406 subscriber_silent_call_stop_cmd,
Harald Welteb4a84e12010-05-27 10:44:58 +0200407 "subscriber " SUBSCR_TYPES " ID silent-call stop",
Harald Welte28326062010-05-14 20:05:17 +0200408 SUBSCR_HELP "Silent call operation\n" "Stop silent call\n"
409 CHAN_TYPE_HELP)
Harald Weltea1482332009-11-14 10:08:40 +0100410{
Harald Weltedcccb182010-05-16 20:52:23 +0200411 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200412 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
Harald Weltea1482332009-11-14 10:08:40 +0100413 int rc;
414
Harald Welte2483f1b2016-06-19 18:06:02 +0200415 if (!vsub) {
Harald Weltea1482332009-11-14 10:08:40 +0100416 vty_out(vty, "%% No subscriber found for %s %s%s",
Harald Welte20f98312009-11-14 10:11:45 +0100417 argv[0], argv[1], VTY_NEWLINE);
Harald Weltea1482332009-11-14 10:08:40 +0100418 return CMD_WARNING;
419 }
420
Harald Welte2483f1b2016-06-19 18:06:02 +0200421 rc = gsm_silent_call_stop(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100422 if (rc < 0) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200423 vlr_subscr_put(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100424 return CMD_WARNING;
Harald Weltea1482332009-11-14 10:08:40 +0100425 }
426
Harald Welte2483f1b2016-06-19 18:06:02 +0200427 vlr_subscr_put(vsub);
Harald Weltea1482332009-11-14 10:08:40 +0100428
429 return CMD_SUCCESS;
430}
431
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800432DEFUN(subscriber_ussd_notify,
433 subscriber_ussd_notify_cmd,
Holger Hans Peter Freythere731e1d2010-07-27 18:27:46 +0800434 "subscriber " SUBSCR_TYPES " ID ussd-notify (0|1|2) .TEXT",
Harald Weltecfaabbb2012-08-16 23:23:50 +0200435 SUBSCR_HELP "Send a USSD notify to the subscriber\n"
Harald Weltecfaabbb2012-08-16 23:23:50 +0200436 "Alerting Level 0\n"
437 "Alerting Level 1\n"
438 "Alerting Level 2\n"
439 "Text of USSD message to send\n")
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800440{
441 char *text;
442 struct gsm_subscriber_connection *conn;
443 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200444 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
Holger Hans Peter Freythere731e1d2010-07-27 18:27:46 +0800445 int level;
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800446
Harald Welte2483f1b2016-06-19 18:06:02 +0200447 if (!vsub) {
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800448 vty_out(vty, "%% No subscriber found for %s %s%s",
449 argv[0], argv[1], VTY_NEWLINE);
450 return CMD_WARNING;
451 }
452
Holger Hans Peter Freythere731e1d2010-07-27 18:27:46 +0800453 level = atoi(argv[2]);
454 text = argv_concat(argv, argc, 3);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800455 if (!text) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200456 vlr_subscr_put(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800457 return CMD_WARNING;
458 }
459
Harald Welte2483f1b2016-06-19 18:06:02 +0200460 conn = connection_for_subscr(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800461 if (!conn) {
462 vty_out(vty, "%% An active connection is required for %s %s%s",
463 argv[0], argv[1], VTY_NEWLINE);
Harald Welte2483f1b2016-06-19 18:06:02 +0200464 vlr_subscr_put(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800465 talloc_free(text);
466 return CMD_WARNING;
467 }
468
Neels Hofmeyr43273c62016-05-10 12:50:31 +0200469 msc_send_ussd_notify(conn, level, text);
470 msc_send_ussd_release_complete(conn);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800471
Harald Welte2483f1b2016-06-19 18:06:02 +0200472 vlr_subscr_put(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800473 talloc_free(text);
474 return CMD_SUCCESS;
475}
476
Harald Welte94307772017-06-12 01:52:27 +0200477static int loop_by_char(uint8_t ch)
478{
479 switch (ch) {
480 case 'a':
481 return GSM414_LOOP_A;
482 case 'b':
483 return GSM414_LOOP_B;
484 case 'c':
485 return GSM414_LOOP_C;
486 case 'd':
487 return GSM414_LOOP_D;
488 case 'e':
489 return GSM414_LOOP_E;
490 case 'f':
491 return GSM414_LOOP_F;
492 case 'i':
493 return GSM414_LOOP_I;
494 }
495 return -1;
496}
497
498DEFUN(subscriber_mstest_close,
499 subscriber_mstest_close_cmd,
500 "subscriber " SUBSCR_TYPES " ID ms-test close-loop (a|b|c|d|e|f|i)",
501 SUBSCR_HELP "Send a TS 04.14 MS Test Command to subscriber\n"
502 "Close a TCH Loop inside the MS\n"
503 "Loop Type A\n"
504 "Loop Type B\n"
505 "Loop Type C\n"
506 "Loop Type D\n"
507 "Loop Type E\n"
508 "Loop Type F\n"
509 "Loop Type I\n")
510{
511 struct gsm_subscriber_connection *conn;
512 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
513 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
514 const char *loop_str;
515 int loop_mode;
516
517 if (!vsub) {
518 vty_out(vty, "%% No subscriber found for %s %s%s",
519 argv[0], argv[1], VTY_NEWLINE);
520 return CMD_WARNING;
521 }
522
523 loop_str = argv[2];
524 loop_mode = loop_by_char(loop_str[0]);
525
526 conn = connection_for_subscr(vsub);
527 if (!conn) {
528 vty_out(vty, "%% An active connection is required for %s %s%s",
529 argv[0], argv[1], VTY_NEWLINE);
530 vlr_subscr_put(vsub);
531 return CMD_WARNING;
532 }
533
534 gsm0414_tx_close_tch_loop_cmd(conn, loop_mode);
535
536 return CMD_SUCCESS;
537}
538
539DEFUN(subscriber_mstest_open,
540 subscriber_mstest_open_cmd,
541 "subscriber " SUBSCR_TYPES " ID ms-test open-loop",
542 SUBSCR_HELP "Send a TS 04.14 MS Test Command to subscriber\n"
543 "Open a TCH Loop inside the MS\n")
544{
545 struct gsm_subscriber_connection *conn;
546 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
547 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
548
549 if (!vsub) {
550 vty_out(vty, "%% No subscriber found for %s %s%s",
551 argv[0], argv[1], VTY_NEWLINE);
552 return CMD_WARNING;
553 }
554
555 conn = connection_for_subscr(vsub);
556 if (!conn) {
557 vty_out(vty, "%% An active connection is required for %s %s%s",
558 argv[0], argv[1], VTY_NEWLINE);
559 vlr_subscr_put(vsub);
560 return CMD_WARNING;
561 }
562
563 gsm0414_tx_open_loop_cmd(conn);
564
565 return CMD_SUCCESS;
566}
567
Keithd32b6d12017-01-18 17:09:33 +0100568DEFUN(ena_subscr_expire,
569 ena_subscr_expire_cmd,
570 "subscriber " SUBSCR_TYPES " ID expire",
571 SUBSCR_HELP "Expire the subscriber Now\n")
572{
Keithd32b6d12017-01-18 17:09:33 +0100573 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200574 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0],
575 argv[1]);
Keithd32b6d12017-01-18 17:09:33 +0100576
Harald Welte2483f1b2016-06-19 18:06:02 +0200577 if (!vsub) {
Keithd32b6d12017-01-18 17:09:33 +0100578 vty_out(vty, "%% No subscriber found for %s %s%s",
579 argv[0], argv[1], VTY_NEWLINE);
580 return CMD_WARNING;
581 }
582
Harald Welte2483f1b2016-06-19 18:06:02 +0200583 if (vsub->lu_complete) {
584 vsub->lu_complete = false;
585 vlr_subscr_put(vsub);
586 vty_out(vty, "%% VLR released subscriber %s%s",
587 vlr_subscr_name(vsub), VTY_NEWLINE);
588 }
Keithd32b6d12017-01-18 17:09:33 +0100589
Harald Welte2483f1b2016-06-19 18:06:02 +0200590 if (vsub->use_count > 1)
591 vty_out(vty, "%% Subscriber %s is still in use,"
592 " should be released soon%s",
593 vlr_subscr_name(vsub), VTY_NEWLINE);
594
595 vlr_subscr_put(vsub);
Keithd32b6d12017-01-18 17:09:33 +0100596 return CMD_SUCCESS;
597}
598
Sylvain Munaute824d9c2010-06-11 00:19:42 +0200599#define A3A8_ALG_TYPES "(none|xor|comp128v1)"
Harald Welte28326062010-05-14 20:05:17 +0200600#define A3A8_ALG_HELP \
601 "Use No A3A8 algorithm\n" \
Sylvain Munaute824d9c2010-06-11 00:19:42 +0200602 "Use XOR algorithm\n" \
Harald Welte28326062010-05-14 20:05:17 +0200603 "Use COMP128v1 algorithm\n"
Sylvain Munaut99792902009-12-27 19:30:46 +0100604
Harald Welteb4a84e12010-05-27 10:44:58 +0200605DEFUN(ena_subscr_a3a8,
606 ena_subscr_a3a8_cmd,
607 "subscriber " SUBSCR_TYPES " ID a3a8 " A3A8_ALG_TYPES " [KI]",
Harald Welted3cf85d2010-05-27 10:48:11 +0200608 SUBSCR_HELP "Set a3a8 parameters for the subscriber\n"
609 A3A8_ALG_HELP "Encryption Key Ki\n")
Sylvain Munaut99792902009-12-27 19:30:46 +0100610{
Harald Welte2483f1b2016-06-19 18:06:02 +0200611 vty_out(vty, "%% 'subscriber a3a8' is no longer supported.%s"
612 "%% This is now up to osmo-hlr.%s",
613 VTY_NEWLINE, VTY_NEWLINE);
614 return CMD_WARNING;
Sylvain Munaut99792902009-12-27 19:30:46 +0100615}
616
Holger Hans Peter Freytherabd0cac2010-12-22 18:12:11 +0100617DEFUN(subscriber_update,
618 subscriber_update_cmd,
619 "subscriber " SUBSCR_TYPES " ID update",
620 SUBSCR_HELP "Update the subscriber data from the dabase.\n")
621{
Harald Welte2483f1b2016-06-19 18:06:02 +0200622 vty_out(vty, "%% 'subscriber update' is no longer supported.%s",
623 VTY_NEWLINE);
624 return CMD_WARNING;
Holger Hans Peter Freytherabd0cac2010-12-22 18:12:11 +0100625}
626
Harald Weltea1482332009-11-14 10:08:40 +0100627static int scall_cbfn(unsigned int subsys, unsigned int signal,
628 void *handler_data, void *signal_data)
629{
630 struct scall_signal_data *sigdata = signal_data;
631 struct vty *vty = sigdata->data;
632
633 switch (signal) {
634 case S_SCALL_SUCCESS:
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200635 vty_out(vty, "%% silent call success%s", VTY_NEWLINE);
Harald Weltea1482332009-11-14 10:08:40 +0100636 break;
637 case S_SCALL_EXPIRED:
638 vty_out(vty, "%% silent call expired paging%s", VTY_NEWLINE);
639 break;
640 }
641 return 0;
642}
643
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200644DEFUN(show_stats,
645 show_stats_cmd,
646 "show statistics",
647 SHOW_STR "Display network statistics\n")
648{
Harald Weltedcccb182010-05-16 20:52:23 +0200649 struct gsm_network *net = gsmnet_from_vty(vty);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200650
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200651 vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200652 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_ATTACH].current,
653 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_NORMAL].current,
654 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_PERIODIC].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200655 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200656 vty_out(vty, "IMSI Detach Indications : %lu%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200657 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_DETACH].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200658 VTY_NEWLINE);
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200659 vty_out(vty, "Location Updating Results: %lu completed, %lu failed%s",
660 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_COMPLETED].current,
661 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_FAILED].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200662 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200663 vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, "
664 "%lu completed, %lu failed%s",
Alexander Chemerisa7388d72017-07-08 18:00:36 +0900665 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_ATTEMPTED].current,
666 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_NO_CHANNEL].current,
667 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_TIMEOUT].current,
668 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_COMPLETED].current,
669 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_FAILED].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200670 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200671 vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200672 net->msc_ctrs->ctr[MSC_CTR_SMS_SUBMITTED].current,
673 net->msc_ctrs->ctr[MSC_CTR_SMS_NO_RECEIVER].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200674 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200675 vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200676 net->msc_ctrs->ctr[MSC_CTR_SMS_DELIVERED].current,
677 net->msc_ctrs->ctr[MSC_CTR_SMS_RP_ERR_MEM].current,
678 net->msc_ctrs->ctr[MSC_CTR_SMS_RP_ERR_OTHER].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200679 VTY_NEWLINE);
Harald Weltea29e43a2010-12-24 16:06:33 +0100680 vty_out(vty, "MO Calls : %lu setup, %lu connect ack%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200681 net->msc_ctrs->ctr[MSC_CTR_CALL_MO_SETUP].current,
682 net->msc_ctrs->ctr[MSC_CTR_CALL_MO_CONNECT_ACK].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200683 VTY_NEWLINE);
Harald Weltea29e43a2010-12-24 16:06:33 +0100684 vty_out(vty, "MT Calls : %lu setup, %lu connect%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200685 net->msc_ctrs->ctr[MSC_CTR_CALL_MT_SETUP].current,
686 net->msc_ctrs->ctr[MSC_CTR_CALL_MT_CONNECT].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200687 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200688 return CMD_SUCCESS;
689}
690
Holger Hans Peter Freyther81c0e252010-12-25 14:08:00 +0100691DEFUN(show_smsqueue,
692 show_smsqueue_cmd,
693 "show sms-queue",
694 SHOW_STR "Display SMSqueue statistics\n")
695{
696 struct gsm_network *net = gsmnet_from_vty(vty);
697
698 sms_queue_stats(net->sms_queue, vty);
699 return CMD_SUCCESS;
700}
701
Holger Hans Peter Freyther7a0e1662010-12-25 14:15:32 +0100702DEFUN(smsqueue_trigger,
703 smsqueue_trigger_cmd,
704 "sms-queue trigger",
705 "SMS Queue\n" "Trigger sending messages\n")
706{
707 struct gsm_network *net = gsmnet_from_vty(vty);
708
709 sms_queue_trigger(net->sms_queue);
710 return CMD_SUCCESS;
711}
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200712
Holger Hans Peter Freyther3c6f6c22010-12-25 14:25:12 +0100713DEFUN(smsqueue_max,
714 smsqueue_max_cmd,
715 "sms-queue max-pending <1-500>",
Holger Hans Peter Freyther3217fa22012-07-20 23:55:08 +0200716 "SMS Queue\n" "SMS to deliver in parallel\n" "Amount\n")
Holger Hans Peter Freyther3c6f6c22010-12-25 14:25:12 +0100717{
718 struct gsm_network *net = gsmnet_from_vty(vty);
719
720 sms_queue_set_max_pending(net->sms_queue, atoi(argv[0]));
721 return CMD_SUCCESS;
722}
723
Holger Hans Peter Freyther4dcc5e52010-12-25 14:38:30 +0100724DEFUN(smsqueue_clear,
725 smsqueue_clear_cmd,
726 "sms-queue clear",
727 "SMS Queue\n" "Clear the queue of pending SMS\n")
728{
729 struct gsm_network *net = gsmnet_from_vty(vty);
730
731 sms_queue_clear(net->sms_queue);
732 return CMD_SUCCESS;
733}
734
Holger Hans Peter Freyther994dcbb2010-12-25 14:50:50 +0100735DEFUN(smsqueue_fail,
736 smsqueue_fail_cmd,
737 "sms-queue max-failure <1-500>",
Holger Hans Peter Freyther3217fa22012-07-20 23:55:08 +0200738 "SMS Queue\n" "Maximum amount of delivery failures\n" "Amount\n")
Holger Hans Peter Freyther994dcbb2010-12-25 14:50:50 +0100739{
740 struct gsm_network *net = gsmnet_from_vty(vty);
741
742 sms_queue_set_max_failure(net->sms_queue, atoi(argv[0]));
743 return CMD_SUCCESS;
744}
745
Harald Welteab386e62011-09-01 18:18:43 +0200746
747DEFUN(cfg_mncc_int, cfg_mncc_int_cmd,
748 "mncc-int", "Configure internal MNCC handler")
749{
750 vty->node = MNCC_INT_NODE;
751
752 return CMD_SUCCESS;
753}
754
755static struct cmd_node mncc_int_node = {
756 MNCC_INT_NODE,
Harald Welte570ce242012-08-17 13:16:10 +0200757 "%s(config-mncc-int)# ",
Harald Welteab386e62011-09-01 18:18:43 +0200758 1,
759};
760
761static const struct value_string tchf_codec_names[] = {
762 { GSM48_CMODE_SPEECH_V1, "fr" },
763 { GSM48_CMODE_SPEECH_EFR, "efr" },
764 { GSM48_CMODE_SPEECH_AMR, "amr" },
765 { 0, NULL }
766};
767
768static const struct value_string tchh_codec_names[] = {
769 { GSM48_CMODE_SPEECH_V1, "hr" },
770 { GSM48_CMODE_SPEECH_AMR, "amr" },
771 { 0, NULL }
772};
773
774static int config_write_mncc_int(struct vty *vty)
775{
Harald Welteb4771a62012-11-11 10:58:51 +0100776 uint16_t meas_port;
777 char *meas_host;
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100778 const char *meas_scenario;
Harald Welteb4771a62012-11-11 10:58:51 +0100779
780 meas_feed_cfg_get(&meas_host, &meas_port);
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100781 meas_scenario = meas_feed_scenario_get();
Harald Welteb4771a62012-11-11 10:58:51 +0100782
Harald Welteab386e62011-09-01 18:18:43 +0200783 vty_out(vty, "mncc-int%s", VTY_NEWLINE);
784 vty_out(vty, " default-codec tch-f %s%s",
785 get_value_string(tchf_codec_names, mncc_int.def_codec[0]),
786 VTY_NEWLINE);
787 vty_out(vty, " default-codec tch-h %s%s",
788 get_value_string(tchh_codec_names, mncc_int.def_codec[1]),
789 VTY_NEWLINE);
Harald Welteb4771a62012-11-11 10:58:51 +0100790 if (meas_port)
791 vty_out(vty, " meas-feed destination %s %u%s",
792 meas_host, meas_port, VTY_NEWLINE);
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100793 if (strlen(meas_scenario) > 0)
794 vty_out(vty, " meas-feed scenario %s%s",
795 meas_scenario, VTY_NEWLINE);
Harald Welteb4771a62012-11-11 10:58:51 +0100796
Harald Welteab386e62011-09-01 18:18:43 +0200797
798 return CMD_SUCCESS;
799}
800
801DEFUN(mnccint_def_codec_f,
802 mnccint_def_codec_f_cmd,
803 "default-codec tch-f (fr|efr|amr)",
804 "Set default codec\n" "Codec for TCH/F\n"
805 "Full-Rate\n" "Enhanced Full-Rate\n" "Adaptive Multi-Rate\n")
806{
807 mncc_int.def_codec[0] = get_string_value(tchf_codec_names, argv[0]);
808
809 return CMD_SUCCESS;
810}
811
812DEFUN(mnccint_def_codec_h,
813 mnccint_def_codec_h_cmd,
814 "default-codec tch-h (hr|amr)",
815 "Set default codec\n" "Codec for TCH/H\n"
816 "Half-Rate\n" "Adaptive Multi-Rate\n")
817{
818 mncc_int.def_codec[1] = get_string_value(tchh_codec_names, argv[0]);
819
820 return CMD_SUCCESS;
821}
822
Holger Hans Peter Freyther63b0e442013-03-03 09:32:08 +0100823#define OBSOLETE_MSG "Obsolete\n"
Harald Welteb02fc1e2013-02-12 11:15:49 +0100824/* this is just for backwards compatibility as the sms code moved into
825 * libosmocore and old config files no longer parse... */
826DEFUN_DEPRECATED(log_level_sms, log_level_sms_cmd,
827 "logging level sms (everything|debug|info|notice|error|fatal)",
Holger Hans Peter Freyther63b0e442013-03-03 09:32:08 +0100828 ".HIDDEN\n" OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG
829 OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG)
Harald Welteb02fc1e2013-02-12 11:15:49 +0100830{
831 vty_out(vty, "%% 'logging level sms' is now called 'logging level "
832 "lsms', please update your config %s", VTY_NEWLINE);
833
834 return CMD_SUCCESS;
835}
836
Holger Hans Peter Freythera07e38d2015-01-31 09:26:20 +0100837#define MEAS_STR "Measurement export related\n"
Harald Welteb4771a62012-11-11 10:58:51 +0100838DEFUN(mnccint_meas_feed, mnccint_meas_feed_cmd,
839 "meas-feed destination ADDR <0-65535>",
Holger Hans Peter Freythera07e38d2015-01-31 09:26:20 +0100840 MEAS_STR "destination\n" "address or hostname\n" "port number\n")
Harald Welteb4771a62012-11-11 10:58:51 +0100841{
842 int rc;
843
844 rc = meas_feed_cfg_set(argv[0], atoi(argv[1]));
845 if (rc < 0)
846 return CMD_WARNING;
847
848 return CMD_SUCCESS;
849}
850
851DEFUN(meas_feed_scenario, meas_feed_scenario_cmd,
852 "meas-feed scenario NAME",
Holger Hans Peter Freythera07e38d2015-01-31 09:26:20 +0100853 MEAS_STR "scenario\n" "Name up to 31 characters included in report\n")
Harald Welteb4771a62012-11-11 10:58:51 +0100854{
855 meas_feed_scenario_set(argv[0]);
856
857 return CMD_SUCCESS;
858}
859
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100860
861DEFUN(logging_fltr_imsi,
862 logging_fltr_imsi_cmd,
863 "logging filter imsi IMSI",
864 LOGGING_STR FILTER_STR
865 "Filter log messages by IMSI\n" "IMSI to be used as filter\n")
866{
Harald Welte2483f1b2016-06-19 18:06:02 +0200867 struct vlr_subscr *vlr_subscr;
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100868 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
869 struct log_target *tgt = osmo_log_vty2tgt(vty);
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100870 const char *imsi = argv[0];
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100871
872 if (!tgt)
873 return CMD_WARNING;
874
Harald Welte2483f1b2016-06-19 18:06:02 +0200875 vlr_subscr = vlr_subscr_find_by_imsi(gsmnet->vlr, imsi);
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100876
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200877 if (!vlr_subscr) {
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100878 vty_out(vty, "%%no subscriber with IMSI(%s)%s",
879 argv[0], VTY_NEWLINE);
880 return CMD_WARNING;
881 }
882
Harald Welte2483f1b2016-06-19 18:06:02 +0200883 log_set_filter_vlr_subscr(tgt, vlr_subscr);
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100884 return CMD_SUCCESS;
885}
Holger Hans Peter Freyther925c57f2015-01-27 10:58:29 +0100886
Harald Welte2483f1b2016-06-19 18:06:02 +0200887static struct cmd_node hlr_node = {
888 HLR_NODE,
889 "%s(config-hlr)# ",
890 1,
891};
892
893DEFUN(cfg_hlr, cfg_hlr_cmd,
894 "hlr", "Configure connection to the HLR")
895{
896 vty->node = HLR_NODE;
897 return CMD_SUCCESS;
898}
899
900DEFUN(cfg_hlr_remote_ip, cfg_hlr_remote_ip_cmd, "remote-ip A.B.C.D",
901 "Remote GSUP address of the HLR\n"
902 "Remote GSUP address (default: " MSC_HLR_REMOTE_IP_DEFAULT ")")
903{
904 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
905 talloc_free((void*)gsmnet->gsup_server_addr_str);
906 gsmnet->gsup_server_addr_str = talloc_strdup(gsmnet, argv[0]);
907 return CMD_SUCCESS;
908}
909
910DEFUN(cfg_hlr_remote_port, cfg_hlr_remote_port_cmd, "remote-port <1-65535>",
911 "Remote GSUP port of the HLR\n"
912 "Remote GSUP port (default: " OSMO_STRINGIFY(MSC_HLR_REMOTE_PORT_DEFAULT) ")")
913{
914 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
915 gsmnet->gsup_server_port = atoi(argv[0]);
916 return CMD_SUCCESS;
917}
918
919static int config_write_hlr(struct vty *vty)
920{
921 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
922
923 vty_out(vty, "hlr%s", VTY_NEWLINE);
924 vty_out(vty, " remote-ip %s%s",
925 gsmnet->gsup_server_addr_str, VTY_NEWLINE);
926 vty_out(vty, " remote-port %u%s",
927 gsmnet->gsup_server_port, VTY_NEWLINE);
928 return CMD_SUCCESS;
929}
930
Harald Weltedcccb182010-05-16 20:52:23 +0200931int bsc_vty_init_extra(void)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200932{
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200933 osmo_signal_register_handler(SS_SCALL, scall_cbfn, NULL);
Harald Weltea1482332009-11-14 10:08:40 +0100934
Harald Welteb4d5b172010-05-12 16:10:35 +0000935 install_element_ve(&show_subscr_cmd);
936 install_element_ve(&show_subscr_cache_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200937
Harald Welteb4d5b172010-05-12 16:10:35 +0000938 install_element_ve(&sms_send_pend_cmd);
Harald Welte98f9c752009-11-14 08:00:53 +0100939
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200940 install_element_ve(&subscriber_create_cmd);
Harald Welteb4d5b172010-05-12 16:10:35 +0000941 install_element_ve(&subscriber_send_sms_cmd);
942 install_element_ve(&subscriber_silent_sms_cmd);
943 install_element_ve(&subscriber_silent_call_start_cmd);
944 install_element_ve(&subscriber_silent_call_stop_cmd);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800945 install_element_ve(&subscriber_ussd_notify_cmd);
Harald Welte94307772017-06-12 01:52:27 +0200946 install_element_ve(&subscriber_mstest_close_cmd);
947 install_element_ve(&subscriber_mstest_open_cmd);
Holger Hans Peter Freytherabd0cac2010-12-22 18:12:11 +0100948 install_element_ve(&subscriber_update_cmd);
Harald Welteb4d5b172010-05-12 16:10:35 +0000949 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freyther81c0e252010-12-25 14:08:00 +0100950 install_element_ve(&show_smsqueue_cmd);
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100951 install_element_ve(&logging_fltr_imsi_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200952
Keithd32b6d12017-01-18 17:09:33 +0100953 install_element(ENABLE_NODE, &ena_subscr_expire_cmd);
Harald Welteb4a84e12010-05-27 10:44:58 +0200954 install_element(ENABLE_NODE, &ena_subscr_a3a8_cmd);
Holger Hans Peter Freyther7a0e1662010-12-25 14:15:32 +0100955 install_element(ENABLE_NODE, &smsqueue_trigger_cmd);
Holger Hans Peter Freyther3c6f6c22010-12-25 14:25:12 +0100956 install_element(ENABLE_NODE, &smsqueue_max_cmd);
Holger Hans Peter Freyther4dcc5e52010-12-25 14:38:30 +0100957 install_element(ENABLE_NODE, &smsqueue_clear_cmd);
Holger Hans Peter Freyther994dcbb2010-12-25 14:50:50 +0100958 install_element(ENABLE_NODE, &smsqueue_fail_cmd);
Nico Goldeb62b1232011-02-22 17:54:47 +0100959 install_element(ENABLE_NODE, &subscriber_send_pending_sms_cmd);
Harald Welteb4771a62012-11-11 10:58:51 +0100960 install_element(ENABLE_NODE, &meas_feed_scenario_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200961
Harald Welteab386e62011-09-01 18:18:43 +0200962 install_element(CONFIG_NODE, &cfg_mncc_int_cmd);
963 install_node(&mncc_int_node, config_write_mncc_int);
Jacob Erlbeck36722e12013-10-29 09:30:30 +0100964 vty_install_default(MNCC_INT_NODE);
Harald Welteab386e62011-09-01 18:18:43 +0200965 install_element(MNCC_INT_NODE, &mnccint_def_codec_f_cmd);
966 install_element(MNCC_INT_NODE, &mnccint_def_codec_h_cmd);
Harald Welteb4771a62012-11-11 10:58:51 +0100967 install_element(MNCC_INT_NODE, &mnccint_meas_feed_cmd);
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100968 install_element(MNCC_INT_NODE, &meas_feed_scenario_cmd);
Harald Welteab386e62011-09-01 18:18:43 +0200969
Harald Welteb02fc1e2013-02-12 11:15:49 +0100970 install_element(CFG_LOG_NODE, &log_level_sms_cmd);
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100971 install_element(CFG_LOG_NODE, &logging_fltr_imsi_cmd);
Harald Welteb02fc1e2013-02-12 11:15:49 +0100972
Harald Welte2483f1b2016-06-19 18:06:02 +0200973 install_element(CONFIG_NODE, &cfg_hlr_cmd);
974 install_node(&hlr_node, config_write_hlr);
975 install_element(HLR_NODE, &cfg_hlr_remote_ip_cmd);
976 install_element(HLR_NODE, &cfg_hlr_remote_port_cmd);
Holger Hans Peter Freyther925c57f2015-01-27 10:58:29 +0100977
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200978 return 0;
979}