blob: b4c94509702c18a71eaab5c80ccea171678f2ce5 [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>
Harald Welteb54d9502009-11-17 06:00:23 +010036#include <openbsc/silent_call.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020037#include <openbsc/gsm_04_11.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020038#include <osmocom/abis/e1_input.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020039#include <openbsc/abis_nm.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010040#include <osmocom/gsm/gsm_utils.h>
41#include <osmocom/core/utils.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020042#include <openbsc/db.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010043#include <osmocom/core/talloc.h>
Harald Weltea1482332009-11-14 10:08:40 +010044#include <openbsc/signal.h>
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010045#include <openbsc/debug.h>
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +020046#include <openbsc/vty.h>
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080047#include <openbsc/gsm_04_80.h>
Harald Welte94307772017-06-12 01:52:27 +020048#include <openbsc/gsm_04_14.h>
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +080049#include <openbsc/chan_alloc.h>
Holger Hans Peter Freyther81c0e252010-12-25 14:08:00 +010050#include <openbsc/sms_queue.h>
Harald Welteab386e62011-09-01 18:18:43 +020051#include <openbsc/mncc_int.h>
Holger Hans Peter Freyther44853212012-12-25 08:37:36 +010052#include <openbsc/handover.h>
Harald Welte2483f1b2016-06-19 18:06:02 +020053#include <openbsc/vlr.h>
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020054
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +010055#include <osmocom/vty/logging.h>
56
Harald Welte2483f1b2016-06-19 18:06:02 +020057#include <openbsc/osmo_msc.h>
58
Harald Welteb4771a62012-11-11 10:58:51 +010059#include "meas_feed.h"
60
Harald Weltedcccb182010-05-16 20:52:23 +020061extern struct gsm_network *gsmnet_from_vty(struct vty *v);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +020062
Harald Welte2483f1b2016-06-19 18:06:02 +020063static void subscr_dump_full_vty(struct vty *vty, struct vlr_subscr *vsub)
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010064{
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +020065 int reqs;
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +020066 struct llist_head *entry;
Holger Hans Peter Freytherb9708942013-07-27 19:42:35 +020067 char expire_time[200];
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010068
Harald Welte2483f1b2016-06-19 18:06:02 +020069 if (strlen(vsub->name))
70 vty_out(vty, " Name: '%s'%s", vsub->name, VTY_NEWLINE);
71 if (strlen(vsub->msisdn))
72 vty_out(vty, " Extension: %s%s", vsub->msisdn,
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010073 VTY_NEWLINE);
Holger Hans Peter Freyther3d76e442010-12-25 16:40:54 +010074 vty_out(vty, " LAC: %d/0x%x%s",
Harald Welte2483f1b2016-06-19 18:06:02 +020075 vsub->lac, vsub->lac, VTY_NEWLINE);
76 vty_out(vty, " IMSI: %s%s", vsub->imsi, VTY_NEWLINE);
77 if (vsub->tmsi != GSM_RESERVED_TMSI)
78 vty_out(vty, " TMSI: %08X%s", vsub->tmsi,
79 VTY_NEWLINE);
80 if (vsub->tmsi_new != GSM_RESERVED_TMSI)
81 vty_out(vty, " new TMSI: %08X%s", vsub->tmsi_new,
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010082 VTY_NEWLINE);
83
Harald Welte2483f1b2016-06-19 18:06:02 +020084#if 0
85 /* TODO: add this to vlr_subscr? */
86 if (vsub->auth_info.auth_algo != AUTH_ALGO_NONE) {
87 struct gsm_auth_info *i = &vsub->auth_info;
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010088 vty_out(vty, " A3A8 algorithm id: %d%s",
Harald Welte2483f1b2016-06-19 18:06:02 +020089 i->auth_algo, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010090 vty_out(vty, " A3A8 Ki: %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +020091 osmo_hexdump(i->a3a8_ki, i->a3a8_ki_len),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010092 VTY_NEWLINE);
93 }
Harald Welte2483f1b2016-06-19 18:06:02 +020094#endif
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010095
Harald Welte2483f1b2016-06-19 18:06:02 +020096 if (vsub->last_tuple) {
97 struct gsm_auth_tuple *t = vsub->last_tuple;
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +010098 vty_out(vty, " A3A8 last tuple (used %d times):%s",
Harald Welte2483f1b2016-06-19 18:06:02 +020099 t->use_count, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100100 vty_out(vty, " seq # : %d%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200101 t->key_seq, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100102 vty_out(vty, " RAND : %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200103 osmo_hexdump(t->vec.rand, sizeof(t->vec.rand)),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100104 VTY_NEWLINE);
105 vty_out(vty, " SRES : %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200106 osmo_hexdump(t->vec.sres, sizeof(t->vec.sres)),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100107 VTY_NEWLINE);
108 vty_out(vty, " Kc : %s%s",
Harald Welte2483f1b2016-06-19 18:06:02 +0200109 osmo_hexdump(t->vec.kc, sizeof(t->vec.kc)),
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100110 VTY_NEWLINE);
111 }
Holger Hans Peter Freytherb9708942013-07-27 19:42:35 +0200112
113 /* print the expiration time of a subscriber */
114 strftime(expire_time, sizeof(expire_time),
Harald Welte2483f1b2016-06-19 18:06:02 +0200115 "%a, %d %b %Y %T %z", localtime(&vsub->expire_lu));
Holger Hans Peter Freytherb9708942013-07-27 19:42:35 +0200116 expire_time[sizeof(expire_time) - 1] = '\0';
117 vty_out(vty, " Expiration Time: %s%s", expire_time, VTY_NEWLINE);
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +0200118
119 reqs = 0;
Harald Welte2483f1b2016-06-19 18:06:02 +0200120 llist_for_each(entry, &vsub->cs.requests)
Holger Hans Peter Freytherc9dbe3c2015-08-04 13:18:47 +0200121 reqs += 1;
Harald Welte2483f1b2016-06-19 18:06:02 +0200122 vty_out(vty, " Paging: %s paging for %d requests%s",
123 vsub->cs.is_paging ? "is" : "not", reqs, VTY_NEWLINE);
124 vty_out(vty, " Use count: %u%s", vsub->use_count, VTY_NEWLINE);
Holger Hans Peter Freyther424c4f02010-01-06 06:00:40 +0100125}
126
127
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200128/* Subscriber */
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200129DEFUN(show_subscr_cache,
130 show_subscr_cache_cmd,
131 "show subscriber cache",
Harald Weltecfaabbb2012-08-16 23:23:50 +0200132 SHOW_STR "Show information about subscribers\n"
133 "Display contents of subscriber cache\n")
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200134{
Harald Welte2483f1b2016-06-19 18:06:02 +0200135 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
136 struct vlr_subscr *vsub;
137 int count = 0;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200138
Harald Welte2483f1b2016-06-19 18:06:02 +0200139 llist_for_each_entry(vsub, &gsmnet->vlr->subscribers, list) {
140 if (++count > 100) {
141 vty_out(vty, "%% More than %d subscribers in cache,"
142 " stopping here.%s", count-1, VTY_NEWLINE);
143 break;
144 }
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200145 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
Harald Welte2483f1b2016-06-19 18:06:02 +0200146 subscr_dump_full_vty(vty, vsub);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200147 }
148
149 return CMD_SUCCESS;
150}
151
152DEFUN(sms_send_pend,
153 sms_send_pend_cmd,
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100154 "sms send pending",
Neels Hofmeyrd1fdefe2016-04-01 02:17:24 +0200155 "SMS related commands\n" "SMS Sending related commands\n"
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100156 "Send all pending SMS")
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200157{
Harald Weltedcccb182010-05-16 20:52:23 +0200158 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200159 struct gsm_sms *sms;
Harald Welte2483f1b2016-06-19 18:06:02 +0200160 unsigned long long sms_id = 0;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200161
162 while (1) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200163 sms = db_sms_get_next_unsent(gsmnet, sms_id, UINT_MAX);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200164 if (!sms)
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100165 break;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200166
Harald Welte2483f1b2016-06-19 18:06:02 +0200167 if (sms->receiver)
168 gsm411_send_sms_subscr(sms->receiver, sms);
Sylvain Munautff1f19e2009-12-22 13:22:29 +0100169
Harald Welte2483f1b2016-06-19 18:06:02 +0200170 sms_id = sms->id + 1;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200171 }
172
173 return CMD_SUCCESS;
174}
175
Harald Welte2483f1b2016-06-19 18:06:02 +0200176static int _send_sms_str(struct vlr_subscr *receiver,
177 struct vlr_subscr *sender,
178 char *str, uint8_t tp_pid)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200179{
Harald Welte2483f1b2016-06-19 18:06:02 +0200180 struct gsm_network *net = receiver->vlr->user_ctx;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200181 struct gsm_sms *sms;
182
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100183 sms = sms_from_text(receiver, sender, 0, str);
Harald Welte793a1352009-11-05 15:51:17 +0900184 sms->protocol_id = tp_pid;
Nico Golde59502362010-06-29 20:13:06 +0200185
Holger Hans Peter Freyther445e6152010-12-25 15:57:34 +0100186 /* store in database for the queue */
187 if (db_sms_store(sms) != 0) {
Holger Hans Peter Freythereff409492012-11-10 19:46:58 +0100188 LOGP(DLSMS, LOGL_ERROR, "Failed to store SMS in Database\n");
Holger Hans Peter Freyther445e6152010-12-25 15:57:34 +0100189 sms_free(sms);
190 return CMD_WARNING;
Nico Golde59502362010-06-29 20:13:06 +0200191 }
Neels Hofmeyr1e918c32016-05-09 21:48:53 +0200192 LOGP(DLSMS, LOGL_DEBUG, "SMS stored in DB\n");
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200193
Holger Hans Peter Freyther445e6152010-12-25 15:57:34 +0100194 sms_free(sms);
Harald Welte2483f1b2016-06-19 18:06:02 +0200195 sms_queue_trigger(net->sms_queue);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200196 return CMD_SUCCESS;
197}
198
Harald Welte2483f1b2016-06-19 18:06:02 +0200199static struct vlr_subscr *get_vsub_by_argv(struct gsm_network *gsmnet,
200 const char *type,
201 const char *id)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200202{
Harald Welte2483f1b2016-06-19 18:06:02 +0200203 if (!strcmp(type, "extension") || !strcmp(type, "msisdn"))
204 return vlr_subscr_find_by_msisdn(gsmnet->vlr, id);
205 else if (!strcmp(type, "imsi") || !strcmp(type, "id"))
206 return vlr_subscr_find_by_imsi(gsmnet->vlr, id);
Harald Welte98f9c752009-11-14 08:00:53 +0100207 else if (!strcmp(type, "tmsi"))
Harald Welte2483f1b2016-06-19 18:06:02 +0200208 return vlr_subscr_find_by_tmsi(gsmnet->vlr, atoi(id));
Harald Welte98f9c752009-11-14 08:00:53 +0100209
210 return NULL;
211}
212#define SUBSCR_TYPES "(extension|imsi|tmsi|id)"
Harald Welte28326062010-05-14 20:05:17 +0200213#define SUBSCR_HELP "Operations on a Subscriber\n" \
Neels Hofmeyrd1fdefe2016-04-01 02:17:24 +0200214 "Identify subscriber by extension (phone number)\n" \
215 "Identify subscriber by IMSI\n" \
216 "Identify subscriber by TMSI\n" \
217 "Identify subscriber by database ID\n" \
Harald Welte28326062010-05-14 20:05:17 +0200218 "Identifier for the subscriber\n"
Harald Welte98f9c752009-11-14 08:00:53 +0100219
Harald Welteb4a84e12010-05-27 10:44:58 +0200220DEFUN(show_subscr,
221 show_subscr_cmd,
222 "show subscriber " SUBSCR_TYPES " ID",
223 SHOW_STR SUBSCR_HELP)
224{
225 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200226 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0],
227 argv[1]);
Harald Welteb4a84e12010-05-27 10:44:58 +0200228
Harald Welte2483f1b2016-06-19 18:06:02 +0200229 if (!vsub) {
Harald Welteb4a84e12010-05-27 10:44:58 +0200230 vty_out(vty, "%% No subscriber found for %s %s%s",
231 argv[0], argv[1], VTY_NEWLINE);
232 return CMD_WARNING;
233 }
234
Harald Welte2483f1b2016-06-19 18:06:02 +0200235 subscr_dump_full_vty(vty, vsub);
Harald Welteb4a84e12010-05-27 10:44:58 +0200236
Harald Welte2483f1b2016-06-19 18:06:02 +0200237 vlr_subscr_put(vsub);
Harald Welteb4a84e12010-05-27 10:44:58 +0200238
239 return CMD_SUCCESS;
240}
241
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200242DEFUN(subscriber_create,
243 subscriber_create_cmd,
244 "subscriber create imsi ID",
245 "Operations on a Subscriber\n" \
246 "Create new subscriber\n" \
247 "Identify the subscriber by his IMSI\n" \
248 "Identifier for the subscriber\n")
249{
Harald Welte2483f1b2016-06-19 18:06:02 +0200250 vty_out(vty, "%% 'subscriber create' now needs to be done at osmo-hlr%s",
251 VTY_NEWLINE);
252 return CMD_WARNING;
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200253}
254
Nico Goldeb62b1232011-02-22 17:54:47 +0100255DEFUN(subscriber_send_pending_sms,
256 subscriber_send_pending_sms_cmd,
Holger Hans Peter Freyther3217fa22012-07-20 23:55:08 +0200257 "subscriber " SUBSCR_TYPES " ID sms pending-send",
Nico Goldeb62b1232011-02-22 17:54:47 +0100258 SUBSCR_HELP "SMS Operations\n" "Send pending SMS\n")
259{
260 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200261 struct vlr_subscr *vsub;
Nico Goldeb62b1232011-02-22 17:54:47 +0100262 struct gsm_sms *sms;
263
Harald Welte2483f1b2016-06-19 18:06:02 +0200264 vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
265 if (!vsub) {
Holger Hans Peter Freyther9feef482013-07-04 20:34:46 +0200266 vty_out(vty, "%% No subscriber found for %s %s%s",
267 argv[0], argv[1], VTY_NEWLINE);
268 return CMD_WARNING;
269 }
270
Harald Welte2483f1b2016-06-19 18:06:02 +0200271 sms = db_sms_get_unsent_for_subscr(vsub, UINT_MAX);
Nico Goldeb62b1232011-02-22 17:54:47 +0100272 if (sms)
273 gsm411_send_sms_subscr(sms->receiver, sms);
274
Harald Welte2483f1b2016-06-19 18:06:02 +0200275 vlr_subscr_put(vsub);
Nico Goldeb62b1232011-02-22 17:54:47 +0100276
277 return CMD_SUCCESS;
278}
279
Harald Welte98f9c752009-11-14 08:00:53 +0100280DEFUN(subscriber_send_sms,
281 subscriber_send_sms_cmd,
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100282 "subscriber " SUBSCR_TYPES " ID sms sender " SUBSCR_TYPES " SENDER_ID send .LINE",
Holger Hans Peter Freyther63b0e442013-03-03 09:32:08 +0100283 SUBSCR_HELP "SMS Operations\n" SUBSCR_HELP "Send SMS\n" "Actual SMS Text\n")
Harald Welte98f9c752009-11-14 08:00:53 +0100284{
Harald Weltedcccb182010-05-16 20:52:23 +0200285 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200286 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
287 struct vlr_subscr *sender = get_vsub_by_argv(gsmnet, argv[2], argv[3]);
Harald Welte20474ad2010-05-16 19:28:32 +0200288 char *str;
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200289 int rc;
290
Harald Welte2483f1b2016-06-19 18:06:02 +0200291 if (!vsub) {
Harald Welte20f98312009-11-14 10:11:45 +0100292 vty_out(vty, "%% No subscriber found for %s %s%s",
293 argv[0], argv[1], VTY_NEWLINE);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100294 rc = CMD_WARNING;
295 goto err;
Harald Welte20f98312009-11-14 10:11:45 +0100296 }
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100297
298 if (!sender) {
299 vty_out(vty, "%% No sender found for %s %s%s",
300 argv[2], argv[3], VTY_NEWLINE);
301 rc = CMD_WARNING;
302 goto err;
303 }
304
305 str = argv_concat(argv, argc, 4);
Harald Welte2483f1b2016-06-19 18:06:02 +0200306 rc = _send_sms_str(vsub, sender, str, 0);
Harald Welte20474ad2010-05-16 19:28:32 +0200307 talloc_free(str);
Harald Welte793a1352009-11-05 15:51:17 +0900308
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100309err:
310 if (sender)
Harald Welte2483f1b2016-06-19 18:06:02 +0200311 vlr_subscr_put(sender);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100312
Harald Welte2483f1b2016-06-19 18:06:02 +0200313 if (vsub)
314 vlr_subscr_put(vsub);
Harald Welteaf8c7b42009-11-14 10:10:54 +0100315
Harald Welte793a1352009-11-05 15:51:17 +0900316 return rc;
317}
318
Harald Welte98f9c752009-11-14 08:00:53 +0100319DEFUN(subscriber_silent_sms,
320 subscriber_silent_sms_cmd,
Harald Welte1011d5b2014-07-10 20:19:00 +0200321
322 "subscriber " SUBSCR_TYPES " ID silent-sms sender " SUBSCR_TYPES " SENDER_ID send .LINE",
323 SUBSCR_HELP "Silent SMS Operations\n" SUBSCR_HELP "Send SMS\n" "Actual SMS Text\n")
Harald Welte793a1352009-11-05 15:51:17 +0900324{
Harald Weltedcccb182010-05-16 20:52:23 +0200325 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200326 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
327 struct vlr_subscr *sender = get_vsub_by_argv(gsmnet, argv[2], argv[3]);
Harald Welte20474ad2010-05-16 19:28:32 +0200328 char *str;
Harald Welte793a1352009-11-05 15:51:17 +0900329 int rc;
330
Harald Welte2483f1b2016-06-19 18:06:02 +0200331 if (!vsub) {
Harald Welte20f98312009-11-14 10:11:45 +0100332 vty_out(vty, "%% No subscriber found for %s %s%s",
333 argv[0], argv[1], VTY_NEWLINE);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100334 rc = CMD_WARNING;
335 goto err;
Harald Welte20f98312009-11-14 10:11:45 +0100336 }
Harald Welte793a1352009-11-05 15:51:17 +0900337
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100338 if (!sender) {
339 vty_out(vty, "%% No sender found for %s %s%s",
340 argv[2], argv[3], VTY_NEWLINE);
341 rc = CMD_WARNING;
342 goto err;
343 }
344
345 str = argv_concat(argv, argc, 4);
Harald Welte2483f1b2016-06-19 18:06:02 +0200346 rc = _send_sms_str(vsub, sender, str, 64);
Harald Welte20474ad2010-05-16 19:28:32 +0200347 talloc_free(str);
Harald Welte793a1352009-11-05 15:51:17 +0900348
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100349err:
350 if (sender)
Harald Welte2483f1b2016-06-19 18:06:02 +0200351 vlr_subscr_put(sender);
Sylvain Munaut01c13a32012-12-28 00:49:01 +0100352
Harald Welte2483f1b2016-06-19 18:06:02 +0200353 if (vsub)
354 vlr_subscr_put(vsub);
Harald Welteaf8c7b42009-11-14 10:10:54 +0100355
Harald Welte793a1352009-11-05 15:51:17 +0900356 return rc;
357}
358
Harald Welte28326062010-05-14 20:05:17 +0200359#define CHAN_TYPES "(any|tch/f|tch/any|sdcch)"
360#define CHAN_TYPE_HELP \
361 "Any channel\n" \
362 "TCH/F channel\n" \
363 "Any TCH channel\n" \
364 "SDCCH channel\n"
365
Sylvain Munaut50480702010-01-02 14:29:43 +0100366DEFUN(subscriber_silent_call_start,
367 subscriber_silent_call_start_cmd,
Harald Welteb4a84e12010-05-27 10:44:58 +0200368 "subscriber " SUBSCR_TYPES " ID silent-call start (any|tch/f|tch/any|sdcch)",
Harald Welte28326062010-05-14 20:05:17 +0200369 SUBSCR_HELP "Silent call operation\n" "Start silent call\n"
370 CHAN_TYPE_HELP)
Sylvain Munaut50480702010-01-02 14:29:43 +0100371{
Harald Weltedcccb182010-05-16 20:52:23 +0200372 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200373 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
Sylvain Munaut50480702010-01-02 14:29:43 +0100374 int rc, type;
375
Harald Welte2483f1b2016-06-19 18:06:02 +0200376 if (!vsub) {
Sylvain Munaut50480702010-01-02 14:29:43 +0100377 vty_out(vty, "%% No subscriber found for %s %s%s",
378 argv[0], argv[1], VTY_NEWLINE);
379 return CMD_WARNING;
380 }
381
382 if (!strcmp(argv[2], "tch/f"))
383 type = RSL_CHANNEED_TCH_F;
384 else if (!strcmp(argv[2], "tch/any"))
385 type = RSL_CHANNEED_TCH_ForH;
386 else if (!strcmp(argv[2], "sdcch"))
387 type = RSL_CHANNEED_SDCCH;
388 else
389 type = RSL_CHANNEED_ANY; /* Defaults to ANY */
390
Harald Welte2483f1b2016-06-19 18:06:02 +0200391 rc = gsm_silent_call_start(vsub, vty, type);
Sylvain Munaut50480702010-01-02 14:29:43 +0100392 if (rc <= 0) {
393 vty_out(vty, "%% Subscriber not attached%s",
394 VTY_NEWLINE);
Harald Welte2483f1b2016-06-19 18:06:02 +0200395 vlr_subscr_put(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100396 return CMD_WARNING;
397 }
398
Harald Welte2483f1b2016-06-19 18:06:02 +0200399 vlr_subscr_put(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100400
401 return CMD_SUCCESS;
402}
403
404DEFUN(subscriber_silent_call_stop,
405 subscriber_silent_call_stop_cmd,
Harald Welteb4a84e12010-05-27 10:44:58 +0200406 "subscriber " SUBSCR_TYPES " ID silent-call stop",
Harald Welte28326062010-05-14 20:05:17 +0200407 SUBSCR_HELP "Silent call operation\n" "Stop silent call\n"
408 CHAN_TYPE_HELP)
Harald Weltea1482332009-11-14 10:08:40 +0100409{
Harald Weltedcccb182010-05-16 20:52:23 +0200410 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200411 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
Harald Weltea1482332009-11-14 10:08:40 +0100412 int rc;
413
Harald Welte2483f1b2016-06-19 18:06:02 +0200414 if (!vsub) {
Harald Weltea1482332009-11-14 10:08:40 +0100415 vty_out(vty, "%% No subscriber found for %s %s%s",
Harald Welte20f98312009-11-14 10:11:45 +0100416 argv[0], argv[1], VTY_NEWLINE);
Harald Weltea1482332009-11-14 10:08:40 +0100417 return CMD_WARNING;
418 }
419
Harald Welte2483f1b2016-06-19 18:06:02 +0200420 rc = gsm_silent_call_stop(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100421 if (rc < 0) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200422 vlr_subscr_put(vsub);
Sylvain Munaut50480702010-01-02 14:29:43 +0100423 return CMD_WARNING;
Harald Weltea1482332009-11-14 10:08:40 +0100424 }
425
Harald Welte2483f1b2016-06-19 18:06:02 +0200426 vlr_subscr_put(vsub);
Harald Weltea1482332009-11-14 10:08:40 +0100427
428 return CMD_SUCCESS;
429}
430
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800431DEFUN(subscriber_ussd_notify,
432 subscriber_ussd_notify_cmd,
Holger Hans Peter Freythere731e1d2010-07-27 18:27:46 +0800433 "subscriber " SUBSCR_TYPES " ID ussd-notify (0|1|2) .TEXT",
Harald Weltecfaabbb2012-08-16 23:23:50 +0200434 SUBSCR_HELP "Send a USSD notify to the subscriber\n"
Harald Weltecfaabbb2012-08-16 23:23:50 +0200435 "Alerting Level 0\n"
436 "Alerting Level 1\n"
437 "Alerting Level 2\n"
438 "Text of USSD message to send\n")
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800439{
440 char *text;
441 struct gsm_subscriber_connection *conn;
442 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200443 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
Holger Hans Peter Freythere731e1d2010-07-27 18:27:46 +0800444 int level;
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800445
Harald Welte2483f1b2016-06-19 18:06:02 +0200446 if (!vsub) {
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800447 vty_out(vty, "%% No subscriber found for %s %s%s",
448 argv[0], argv[1], VTY_NEWLINE);
449 return CMD_WARNING;
450 }
451
Holger Hans Peter Freythere731e1d2010-07-27 18:27:46 +0800452 level = atoi(argv[2]);
453 text = argv_concat(argv, argc, 3);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800454 if (!text) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200455 vlr_subscr_put(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800456 return CMD_WARNING;
457 }
458
Harald Welte2483f1b2016-06-19 18:06:02 +0200459 conn = connection_for_subscr(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800460 if (!conn) {
461 vty_out(vty, "%% An active connection is required for %s %s%s",
462 argv[0], argv[1], VTY_NEWLINE);
Harald Welte2483f1b2016-06-19 18:06:02 +0200463 vlr_subscr_put(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800464 talloc_free(text);
465 return CMD_WARNING;
466 }
467
Neels Hofmeyr43273c62016-05-10 12:50:31 +0200468 msc_send_ussd_notify(conn, level, text);
469 msc_send_ussd_release_complete(conn);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800470
Harald Welte2483f1b2016-06-19 18:06:02 +0200471 vlr_subscr_put(vsub);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800472 talloc_free(text);
473 return CMD_SUCCESS;
474}
475
Harald Welte94307772017-06-12 01:52:27 +0200476static int loop_by_char(uint8_t ch)
477{
478 switch (ch) {
479 case 'a':
480 return GSM414_LOOP_A;
481 case 'b':
482 return GSM414_LOOP_B;
483 case 'c':
484 return GSM414_LOOP_C;
485 case 'd':
486 return GSM414_LOOP_D;
487 case 'e':
488 return GSM414_LOOP_E;
489 case 'f':
490 return GSM414_LOOP_F;
491 case 'i':
492 return GSM414_LOOP_I;
493 }
494 return -1;
495}
496
497DEFUN(subscriber_mstest_close,
498 subscriber_mstest_close_cmd,
499 "subscriber " SUBSCR_TYPES " ID ms-test close-loop (a|b|c|d|e|f|i)",
500 SUBSCR_HELP "Send a TS 04.14 MS Test Command to subscriber\n"
501 "Close a TCH Loop inside the MS\n"
502 "Loop Type A\n"
503 "Loop Type B\n"
504 "Loop Type C\n"
505 "Loop Type D\n"
506 "Loop Type E\n"
507 "Loop Type F\n"
508 "Loop Type I\n")
509{
510 struct gsm_subscriber_connection *conn;
511 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
512 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
513 const char *loop_str;
514 int loop_mode;
515
516 if (!vsub) {
517 vty_out(vty, "%% No subscriber found for %s %s%s",
518 argv[0], argv[1], VTY_NEWLINE);
519 return CMD_WARNING;
520 }
521
522 loop_str = argv[2];
523 loop_mode = loop_by_char(loop_str[0]);
524
525 conn = connection_for_subscr(vsub);
526 if (!conn) {
527 vty_out(vty, "%% An active connection is required for %s %s%s",
528 argv[0], argv[1], VTY_NEWLINE);
529 vlr_subscr_put(vsub);
530 return CMD_WARNING;
531 }
532
533 gsm0414_tx_close_tch_loop_cmd(conn, loop_mode);
534
535 return CMD_SUCCESS;
536}
537
538DEFUN(subscriber_mstest_open,
539 subscriber_mstest_open_cmd,
540 "subscriber " SUBSCR_TYPES " ID ms-test open-loop",
541 SUBSCR_HELP "Send a TS 04.14 MS Test Command to subscriber\n"
542 "Open a TCH Loop inside the MS\n")
543{
544 struct gsm_subscriber_connection *conn;
545 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
546 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0], argv[1]);
547
548 if (!vsub) {
549 vty_out(vty, "%% No subscriber found for %s %s%s",
550 argv[0], argv[1], VTY_NEWLINE);
551 return CMD_WARNING;
552 }
553
554 conn = connection_for_subscr(vsub);
555 if (!conn) {
556 vty_out(vty, "%% An active connection is required for %s %s%s",
557 argv[0], argv[1], VTY_NEWLINE);
558 vlr_subscr_put(vsub);
559 return CMD_WARNING;
560 }
561
562 gsm0414_tx_open_loop_cmd(conn);
563
564 return CMD_SUCCESS;
565}
566
Keithd32b6d12017-01-18 17:09:33 +0100567DEFUN(ena_subscr_expire,
568 ena_subscr_expire_cmd,
569 "subscriber " SUBSCR_TYPES " ID expire",
570 SUBSCR_HELP "Expire the subscriber Now\n")
571{
Keithd32b6d12017-01-18 17:09:33 +0100572 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte2483f1b2016-06-19 18:06:02 +0200573 struct vlr_subscr *vsub = get_vsub_by_argv(gsmnet, argv[0],
574 argv[1]);
Keithd32b6d12017-01-18 17:09:33 +0100575
Harald Welte2483f1b2016-06-19 18:06:02 +0200576 if (!vsub) {
Keithd32b6d12017-01-18 17:09:33 +0100577 vty_out(vty, "%% No subscriber found for %s %s%s",
578 argv[0], argv[1], VTY_NEWLINE);
579 return CMD_WARNING;
580 }
581
Harald Welte2483f1b2016-06-19 18:06:02 +0200582 if (vsub->lu_complete) {
583 vsub->lu_complete = false;
584 vlr_subscr_put(vsub);
585 vty_out(vty, "%% VLR released subscriber %s%s",
586 vlr_subscr_name(vsub), VTY_NEWLINE);
587 }
Keithd32b6d12017-01-18 17:09:33 +0100588
Harald Welte2483f1b2016-06-19 18:06:02 +0200589 if (vsub->use_count > 1)
590 vty_out(vty, "%% Subscriber %s is still in use,"
591 " should be released soon%s",
592 vlr_subscr_name(vsub), VTY_NEWLINE);
593
594 vlr_subscr_put(vsub);
Keithd32b6d12017-01-18 17:09:33 +0100595 return CMD_SUCCESS;
596}
597
Sylvain Munaute824d9c2010-06-11 00:19:42 +0200598#define A3A8_ALG_TYPES "(none|xor|comp128v1)"
Harald Welte28326062010-05-14 20:05:17 +0200599#define A3A8_ALG_HELP \
600 "Use No A3A8 algorithm\n" \
Sylvain Munaute824d9c2010-06-11 00:19:42 +0200601 "Use XOR algorithm\n" \
Harald Welte28326062010-05-14 20:05:17 +0200602 "Use COMP128v1 algorithm\n"
Sylvain Munaut99792902009-12-27 19:30:46 +0100603
Harald Welteb4a84e12010-05-27 10:44:58 +0200604DEFUN(ena_subscr_a3a8,
605 ena_subscr_a3a8_cmd,
606 "subscriber " SUBSCR_TYPES " ID a3a8 " A3A8_ALG_TYPES " [KI]",
Harald Welted3cf85d2010-05-27 10:48:11 +0200607 SUBSCR_HELP "Set a3a8 parameters for the subscriber\n"
608 A3A8_ALG_HELP "Encryption Key Ki\n")
Sylvain Munaut99792902009-12-27 19:30:46 +0100609{
Harald Welte2483f1b2016-06-19 18:06:02 +0200610 vty_out(vty, "%% 'subscriber a3a8' is no longer supported.%s"
611 "%% This is now up to osmo-hlr.%s",
612 VTY_NEWLINE, VTY_NEWLINE);
613 return CMD_WARNING;
Sylvain Munaut99792902009-12-27 19:30:46 +0100614}
615
Holger Hans Peter Freytherabd0cac2010-12-22 18:12:11 +0100616DEFUN(subscriber_update,
617 subscriber_update_cmd,
618 "subscriber " SUBSCR_TYPES " ID update",
619 SUBSCR_HELP "Update the subscriber data from the dabase.\n")
620{
Harald Welte2483f1b2016-06-19 18:06:02 +0200621 vty_out(vty, "%% 'subscriber update' is no longer supported.%s",
622 VTY_NEWLINE);
623 return CMD_WARNING;
Holger Hans Peter Freytherabd0cac2010-12-22 18:12:11 +0100624}
625
Harald Weltea1482332009-11-14 10:08:40 +0100626static int scall_cbfn(unsigned int subsys, unsigned int signal,
627 void *handler_data, void *signal_data)
628{
629 struct scall_signal_data *sigdata = signal_data;
630 struct vty *vty = sigdata->data;
631
632 switch (signal) {
633 case S_SCALL_SUCCESS:
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200634 vty_out(vty, "%% silent call success%s", VTY_NEWLINE);
Harald Weltea1482332009-11-14 10:08:40 +0100635 break;
636 case S_SCALL_EXPIRED:
637 vty_out(vty, "%% silent call expired paging%s", VTY_NEWLINE);
638 break;
639 }
640 return 0;
641}
642
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200643DEFUN(show_stats,
644 show_stats_cmd,
645 "show statistics",
646 SHOW_STR "Display network statistics\n")
647{
Harald Weltedcccb182010-05-16 20:52:23 +0200648 struct gsm_network *net = gsmnet_from_vty(vty);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200649
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200650 vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200651 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_ATTACH].current,
652 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_NORMAL].current,
653 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_PERIODIC].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200654 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200655 vty_out(vty, "IMSI Detach Indications : %lu%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200656 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_TYPE_DETACH].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200657 VTY_NEWLINE);
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200658 vty_out(vty, "Location Updating Results: %lu completed, %lu failed%s",
659 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_COMPLETED].current,
660 net->msc_ctrs->ctr[MSC_CTR_LOC_UPDATE_FAILED].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200661 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200662 vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, "
663 "%lu completed, %lu failed%s",
Alexander Chemerisa7388d72017-07-08 18:00:36 +0900664 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_ATTEMPTED].current,
665 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_NO_CHANNEL].current,
666 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_TIMEOUT].current,
667 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_COMPLETED].current,
668 net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_FAILED].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200669 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200670 vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200671 net->msc_ctrs->ctr[MSC_CTR_SMS_SUBMITTED].current,
672 net->msc_ctrs->ctr[MSC_CTR_SMS_NO_RECEIVER].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200673 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200674 vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200675 net->msc_ctrs->ctr[MSC_CTR_SMS_DELIVERED].current,
676 net->msc_ctrs->ctr[MSC_CTR_SMS_RP_ERR_MEM].current,
677 net->msc_ctrs->ctr[MSC_CTR_SMS_RP_ERR_OTHER].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200678 VTY_NEWLINE);
Harald Weltea29e43a2010-12-24 16:06:33 +0100679 vty_out(vty, "MO Calls : %lu setup, %lu connect ack%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200680 net->msc_ctrs->ctr[MSC_CTR_CALL_MO_SETUP].current,
681 net->msc_ctrs->ctr[MSC_CTR_CALL_MO_CONNECT_ACK].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200682 VTY_NEWLINE);
Harald Weltea29e43a2010-12-24 16:06:33 +0100683 vty_out(vty, "MT Calls : %lu setup, %lu connect%s",
Alexander Couzensb847a212016-08-02 11:34:11 +0200684 net->msc_ctrs->ctr[MSC_CTR_CALL_MT_SETUP].current,
685 net->msc_ctrs->ctr[MSC_CTR_CALL_MT_CONNECT].current,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200686 VTY_NEWLINE);
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200687 return CMD_SUCCESS;
688}
689
Holger Hans Peter Freyther81c0e252010-12-25 14:08:00 +0100690DEFUN(show_smsqueue,
691 show_smsqueue_cmd,
692 "show sms-queue",
693 SHOW_STR "Display SMSqueue statistics\n")
694{
695 struct gsm_network *net = gsmnet_from_vty(vty);
696
697 sms_queue_stats(net->sms_queue, vty);
698 return CMD_SUCCESS;
699}
700
Holger Hans Peter Freyther7a0e1662010-12-25 14:15:32 +0100701DEFUN(smsqueue_trigger,
702 smsqueue_trigger_cmd,
703 "sms-queue trigger",
704 "SMS Queue\n" "Trigger sending messages\n")
705{
706 struct gsm_network *net = gsmnet_from_vty(vty);
707
708 sms_queue_trigger(net->sms_queue);
709 return CMD_SUCCESS;
710}
Holger Hans Peter Freythere0ec3262010-04-15 11:28:14 +0200711
Holger Hans Peter Freyther3c6f6c22010-12-25 14:25:12 +0100712DEFUN(smsqueue_max,
713 smsqueue_max_cmd,
714 "sms-queue max-pending <1-500>",
Holger Hans Peter Freyther3217fa22012-07-20 23:55:08 +0200715 "SMS Queue\n" "SMS to deliver in parallel\n" "Amount\n")
Holger Hans Peter Freyther3c6f6c22010-12-25 14:25:12 +0100716{
717 struct gsm_network *net = gsmnet_from_vty(vty);
718
719 sms_queue_set_max_pending(net->sms_queue, atoi(argv[0]));
720 return CMD_SUCCESS;
721}
722
Holger Hans Peter Freyther4dcc5e52010-12-25 14:38:30 +0100723DEFUN(smsqueue_clear,
724 smsqueue_clear_cmd,
725 "sms-queue clear",
726 "SMS Queue\n" "Clear the queue of pending SMS\n")
727{
728 struct gsm_network *net = gsmnet_from_vty(vty);
729
730 sms_queue_clear(net->sms_queue);
731 return CMD_SUCCESS;
732}
733
Holger Hans Peter Freyther994dcbb2010-12-25 14:50:50 +0100734DEFUN(smsqueue_fail,
735 smsqueue_fail_cmd,
736 "sms-queue max-failure <1-500>",
Holger Hans Peter Freyther3217fa22012-07-20 23:55:08 +0200737 "SMS Queue\n" "Maximum amount of delivery failures\n" "Amount\n")
Holger Hans Peter Freyther994dcbb2010-12-25 14:50:50 +0100738{
739 struct gsm_network *net = gsmnet_from_vty(vty);
740
741 sms_queue_set_max_failure(net->sms_queue, atoi(argv[0]));
742 return CMD_SUCCESS;
743}
744
Harald Welteab386e62011-09-01 18:18:43 +0200745
746DEFUN(cfg_mncc_int, cfg_mncc_int_cmd,
747 "mncc-int", "Configure internal MNCC handler")
748{
749 vty->node = MNCC_INT_NODE;
750
751 return CMD_SUCCESS;
752}
753
754static struct cmd_node mncc_int_node = {
755 MNCC_INT_NODE,
Harald Welte570ce242012-08-17 13:16:10 +0200756 "%s(config-mncc-int)# ",
Harald Welteab386e62011-09-01 18:18:43 +0200757 1,
758};
759
760static const struct value_string tchf_codec_names[] = {
761 { GSM48_CMODE_SPEECH_V1, "fr" },
762 { GSM48_CMODE_SPEECH_EFR, "efr" },
763 { GSM48_CMODE_SPEECH_AMR, "amr" },
764 { 0, NULL }
765};
766
767static const struct value_string tchh_codec_names[] = {
768 { GSM48_CMODE_SPEECH_V1, "hr" },
769 { GSM48_CMODE_SPEECH_AMR, "amr" },
770 { 0, NULL }
771};
772
773static int config_write_mncc_int(struct vty *vty)
774{
Harald Welteb4771a62012-11-11 10:58:51 +0100775 uint16_t meas_port;
776 char *meas_host;
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100777 const char *meas_scenario;
Harald Welteb4771a62012-11-11 10:58:51 +0100778
779 meas_feed_cfg_get(&meas_host, &meas_port);
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100780 meas_scenario = meas_feed_scenario_get();
Harald Welteb4771a62012-11-11 10:58:51 +0100781
Harald Welteab386e62011-09-01 18:18:43 +0200782 vty_out(vty, "mncc-int%s", VTY_NEWLINE);
783 vty_out(vty, " default-codec tch-f %s%s",
784 get_value_string(tchf_codec_names, mncc_int.def_codec[0]),
785 VTY_NEWLINE);
786 vty_out(vty, " default-codec tch-h %s%s",
787 get_value_string(tchh_codec_names, mncc_int.def_codec[1]),
788 VTY_NEWLINE);
Harald Welteb4771a62012-11-11 10:58:51 +0100789 if (meas_port)
790 vty_out(vty, " meas-feed destination %s %u%s",
791 meas_host, meas_port, VTY_NEWLINE);
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100792 if (strlen(meas_scenario) > 0)
793 vty_out(vty, " meas-feed scenario %s%s",
794 meas_scenario, VTY_NEWLINE);
Harald Welteb4771a62012-11-11 10:58:51 +0100795
Harald Welteab386e62011-09-01 18:18:43 +0200796
797 return CMD_SUCCESS;
798}
799
800DEFUN(mnccint_def_codec_f,
801 mnccint_def_codec_f_cmd,
802 "default-codec tch-f (fr|efr|amr)",
803 "Set default codec\n" "Codec for TCH/F\n"
804 "Full-Rate\n" "Enhanced Full-Rate\n" "Adaptive Multi-Rate\n")
805{
806 mncc_int.def_codec[0] = get_string_value(tchf_codec_names, argv[0]);
807
808 return CMD_SUCCESS;
809}
810
811DEFUN(mnccint_def_codec_h,
812 mnccint_def_codec_h_cmd,
813 "default-codec tch-h (hr|amr)",
814 "Set default codec\n" "Codec for TCH/H\n"
815 "Half-Rate\n" "Adaptive Multi-Rate\n")
816{
817 mncc_int.def_codec[1] = get_string_value(tchh_codec_names, argv[0]);
818
819 return CMD_SUCCESS;
820}
821
Holger Hans Peter Freyther63b0e442013-03-03 09:32:08 +0100822#define OBSOLETE_MSG "Obsolete\n"
Harald Welteb02fc1e2013-02-12 11:15:49 +0100823/* this is just for backwards compatibility as the sms code moved into
824 * libosmocore and old config files no longer parse... */
825DEFUN_DEPRECATED(log_level_sms, log_level_sms_cmd,
826 "logging level sms (everything|debug|info|notice|error|fatal)",
Holger Hans Peter Freyther63b0e442013-03-03 09:32:08 +0100827 ".HIDDEN\n" OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG
828 OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG OBSOLETE_MSG)
Harald Welteb02fc1e2013-02-12 11:15:49 +0100829{
830 vty_out(vty, "%% 'logging level sms' is now called 'logging level "
831 "lsms', please update your config %s", VTY_NEWLINE);
832
833 return CMD_SUCCESS;
834}
835
Holger Hans Peter Freythera07e38d2015-01-31 09:26:20 +0100836#define MEAS_STR "Measurement export related\n"
Harald Welteb4771a62012-11-11 10:58:51 +0100837DEFUN(mnccint_meas_feed, mnccint_meas_feed_cmd,
838 "meas-feed destination ADDR <0-65535>",
Holger Hans Peter Freythera07e38d2015-01-31 09:26:20 +0100839 MEAS_STR "destination\n" "address or hostname\n" "port number\n")
Harald Welteb4771a62012-11-11 10:58:51 +0100840{
841 int rc;
842
843 rc = meas_feed_cfg_set(argv[0], atoi(argv[1]));
844 if (rc < 0)
845 return CMD_WARNING;
846
847 return CMD_SUCCESS;
848}
849
850DEFUN(meas_feed_scenario, meas_feed_scenario_cmd,
851 "meas-feed scenario NAME",
Holger Hans Peter Freythera07e38d2015-01-31 09:26:20 +0100852 MEAS_STR "scenario\n" "Name up to 31 characters included in report\n")
Harald Welteb4771a62012-11-11 10:58:51 +0100853{
854 meas_feed_scenario_set(argv[0]);
855
856 return CMD_SUCCESS;
857}
858
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100859
860DEFUN(logging_fltr_imsi,
861 logging_fltr_imsi_cmd,
862 "logging filter imsi IMSI",
863 LOGGING_STR FILTER_STR
864 "Filter log messages by IMSI\n" "IMSI to be used as filter\n")
865{
Harald Welte2483f1b2016-06-19 18:06:02 +0200866 struct vlr_subscr *vlr_subscr;
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100867 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
868 struct log_target *tgt = osmo_log_vty2tgt(vty);
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100869 const char *imsi = argv[0];
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100870
871 if (!tgt)
872 return CMD_WARNING;
873
Harald Welte2483f1b2016-06-19 18:06:02 +0200874 vlr_subscr = vlr_subscr_find_by_imsi(gsmnet->vlr, imsi);
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100875
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200876 if (!vlr_subscr) {
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100877 vty_out(vty, "%%no subscriber with IMSI(%s)%s",
878 argv[0], VTY_NEWLINE);
879 return CMD_WARNING;
880 }
881
Harald Welte2483f1b2016-06-19 18:06:02 +0200882 log_set_filter_vlr_subscr(tgt, vlr_subscr);
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100883 return CMD_SUCCESS;
884}
Holger Hans Peter Freyther925c57f2015-01-27 10:58:29 +0100885
Harald Welte2483f1b2016-06-19 18:06:02 +0200886static struct cmd_node hlr_node = {
887 HLR_NODE,
888 "%s(config-hlr)# ",
889 1,
890};
891
892DEFUN(cfg_hlr, cfg_hlr_cmd,
893 "hlr", "Configure connection to the HLR")
894{
895 vty->node = HLR_NODE;
896 return CMD_SUCCESS;
897}
898
899DEFUN(cfg_hlr_remote_ip, cfg_hlr_remote_ip_cmd, "remote-ip A.B.C.D",
900 "Remote GSUP address of the HLR\n"
901 "Remote GSUP address (default: " MSC_HLR_REMOTE_IP_DEFAULT ")")
902{
903 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
904 talloc_free((void*)gsmnet->gsup_server_addr_str);
905 gsmnet->gsup_server_addr_str = talloc_strdup(gsmnet, argv[0]);
906 return CMD_SUCCESS;
907}
908
909DEFUN(cfg_hlr_remote_port, cfg_hlr_remote_port_cmd, "remote-port <1-65535>",
910 "Remote GSUP port of the HLR\n"
911 "Remote GSUP port (default: " OSMO_STRINGIFY(MSC_HLR_REMOTE_PORT_DEFAULT) ")")
912{
913 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
914 gsmnet->gsup_server_port = atoi(argv[0]);
915 return CMD_SUCCESS;
916}
917
918static int config_write_hlr(struct vty *vty)
919{
920 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
921
922 vty_out(vty, "hlr%s", VTY_NEWLINE);
923 vty_out(vty, " remote-ip %s%s",
924 gsmnet->gsup_server_addr_str, VTY_NEWLINE);
925 vty_out(vty, " remote-port %u%s",
926 gsmnet->gsup_server_port, VTY_NEWLINE);
927 return CMD_SUCCESS;
928}
929
Harald Weltedcccb182010-05-16 20:52:23 +0200930int bsc_vty_init_extra(void)
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200931{
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200932 osmo_signal_register_handler(SS_SCALL, scall_cbfn, NULL);
Harald Weltea1482332009-11-14 10:08:40 +0100933
Harald Welteb4d5b172010-05-12 16:10:35 +0000934 install_element_ve(&show_subscr_cmd);
935 install_element_ve(&show_subscr_cache_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200936
Harald Welteb4d5b172010-05-12 16:10:35 +0000937 install_element_ve(&sms_send_pend_cmd);
Harald Welte98f9c752009-11-14 08:00:53 +0100938
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200939 install_element_ve(&subscriber_create_cmd);
Harald Welteb4d5b172010-05-12 16:10:35 +0000940 install_element_ve(&subscriber_send_sms_cmd);
941 install_element_ve(&subscriber_silent_sms_cmd);
942 install_element_ve(&subscriber_silent_call_start_cmd);
943 install_element_ve(&subscriber_silent_call_stop_cmd);
Holger Hans Peter Freytherdaf75342010-07-26 20:01:07 +0800944 install_element_ve(&subscriber_ussd_notify_cmd);
Harald Welte94307772017-06-12 01:52:27 +0200945 install_element_ve(&subscriber_mstest_close_cmd);
946 install_element_ve(&subscriber_mstest_open_cmd);
Holger Hans Peter Freytherabd0cac2010-12-22 18:12:11 +0100947 install_element_ve(&subscriber_update_cmd);
Harald Welteb4d5b172010-05-12 16:10:35 +0000948 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freyther81c0e252010-12-25 14:08:00 +0100949 install_element_ve(&show_smsqueue_cmd);
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100950 install_element_ve(&logging_fltr_imsi_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200951
Keithd32b6d12017-01-18 17:09:33 +0100952 install_element(ENABLE_NODE, &ena_subscr_expire_cmd);
Harald Welteb4a84e12010-05-27 10:44:58 +0200953 install_element(ENABLE_NODE, &ena_subscr_a3a8_cmd);
Holger Hans Peter Freyther7a0e1662010-12-25 14:15:32 +0100954 install_element(ENABLE_NODE, &smsqueue_trigger_cmd);
Holger Hans Peter Freyther3c6f6c22010-12-25 14:25:12 +0100955 install_element(ENABLE_NODE, &smsqueue_max_cmd);
Holger Hans Peter Freyther4dcc5e52010-12-25 14:38:30 +0100956 install_element(ENABLE_NODE, &smsqueue_clear_cmd);
Holger Hans Peter Freyther994dcbb2010-12-25 14:50:50 +0100957 install_element(ENABLE_NODE, &smsqueue_fail_cmd);
Nico Goldeb62b1232011-02-22 17:54:47 +0100958 install_element(ENABLE_NODE, &subscriber_send_pending_sms_cmd);
Harald Welteb4771a62012-11-11 10:58:51 +0100959 install_element(ENABLE_NODE, &meas_feed_scenario_cmd);
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200960
Harald Welteab386e62011-09-01 18:18:43 +0200961 install_element(CONFIG_NODE, &cfg_mncc_int_cmd);
962 install_node(&mncc_int_node, config_write_mncc_int);
Jacob Erlbeck36722e12013-10-29 09:30:30 +0100963 vty_install_default(MNCC_INT_NODE);
Harald Welteab386e62011-09-01 18:18:43 +0200964 install_element(MNCC_INT_NODE, &mnccint_def_codec_f_cmd);
965 install_element(MNCC_INT_NODE, &mnccint_def_codec_h_cmd);
Harald Welteb4771a62012-11-11 10:58:51 +0100966 install_element(MNCC_INT_NODE, &mnccint_meas_feed_cmd);
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100967 install_element(MNCC_INT_NODE, &meas_feed_scenario_cmd);
Harald Welteab386e62011-09-01 18:18:43 +0200968
Harald Welteb02fc1e2013-02-12 11:15:49 +0100969 install_element(CFG_LOG_NODE, &log_level_sms_cmd);
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100970 install_element(CFG_LOG_NODE, &logging_fltr_imsi_cmd);
Harald Welteb02fc1e2013-02-12 11:15:49 +0100971
Harald Welte2483f1b2016-06-19 18:06:02 +0200972 install_element(CONFIG_NODE, &cfg_hlr_cmd);
973 install_node(&hlr_node, config_write_hlr);
974 install_element(HLR_NODE, &cfg_hlr_remote_ip_cmd);
975 install_element(HLR_NODE, &cfg_hlr_remote_port_cmd);
Holger Hans Peter Freyther925c57f2015-01-27 10:58:29 +0100976
Holger Hans Peter Freythercfa90d42009-08-10 10:17:50 +0200977 return 0;
978}