blob: f30907f4baebb10b54a934c58ef1becc275b4026 [file] [log] [blame]
Harald Welte1a62db22022-05-17 12:06:58 +02001/* SMSC interface to VTY */
Vadim Yanitskiy999a5932023-05-18 17:22:26 +07002/* (C) 2016-2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
Harald Welte1a62db22022-05-17 12:06:58 +02003 * Based on OpenBSC interface to quagga VTY (libmsc/vty_interface_layer3.c)
4 * (C) 2009-2022 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2009-2011 by Holger Hans Peter Freyther
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include "config.h"
24
25#include <osmocom/vty/command.h>
26#include <osmocom/vty/logging.h>
27#include <osmocom/vty/misc.h>
28
29#include <osmocom/msc/vty.h>
30#include <osmocom/msc/gsm_data.h>
31#include <osmocom/msc/sms_queue.h>
32
33
34static struct gsm_network *gsmnet;
35static struct sms_queue_config *smqcfg;
36
37/***********************************************************************
38 * SMSC Config Node
39 ***********************************************************************/
40
41static struct cmd_node smsc_node = {
42 SMSC_NODE,
43 "%s(config-smsc)# ",
44 1,
45};
46
47DEFUN(cfg_smsc, cfg_smsc_cmd,
48 "smsc", "Configure SMSC options")
49{
50 vty->node = SMSC_NODE;
51 return CMD_SUCCESS;
52}
53
54DEFUN(cfg_sms_database, cfg_sms_database_cmd,
55 "database PATH",
56 "Set the path to the MSC-SMS database file\n"
57 "Relative or absolute file system path to the database file (default is '" SMS_DEFAULT_DB_FILE_PATH "')\n")
58{
59 osmo_talloc_replace_string(smqcfg, &smqcfg->db_file_path, argv[0]);
60 return CMD_SUCCESS;
61}
62
63DEFUN(cfg_sms_queue_max, cfg_sms_queue_max_cmd,
64 "queue max-pending <1-500>",
65 "SMS Queue\n" "SMS to deliver in parallel\n" "Amount\n")
66{
67 smqcfg->max_pending = atoi(argv[0]);
68 return CMD_SUCCESS;
69}
70
71DEFUN(cfg_sms_queue_fail, cfg_sms_queue_fail_cmd,
72 "queue max-failure <1-500>",
73 "SMS Queue\n" "Maximum number of delivery failures before giving up\n" "Amount\n")
74{
75 smqcfg->max_fail = atoi(argv[0]);
76 return CMD_SUCCESS;
77}
78
Harald Welte53e2e5f2022-05-17 14:39:51 +020079#define DB_STR "SMS Database Configuration\n"
80
81DEFUN(cfg_sms_db_del_delivered, cfg_sms_db_del_delivered_cmd,
82 "database delete-delivered (0|1)",
83 DB_STR "Configure if delivered SMS are deleted from DB\n"
84 "Do not delete SMS after delivery\n"
85 "Delete SMS after delivery\n")
86{
87 smqcfg->delete_delivered = atoi(argv[0]);
88 return CMD_SUCCESS;
89}
90
91DEFUN(cfg_sms_db_del_expired, cfg_sms_db_del_expired_cmd,
92 "database delete-expired (0|1)",
93 DB_STR "Configure if expired SMS are deleted from DB\n"
94 "Do not delete SMS after expiration of validity period\n"
95 "Delete SMS after expiration of validity period\n")
96{
97 smqcfg->delete_expired = atoi(argv[0]);
98 return CMD_SUCCESS;
99}
100
Harald Welte2765a182022-05-17 18:56:55 +0200101DEFUN(cfg_sms_def_val_per, cfg_sms_def_val_per_cmd,
Harald Weltea3c639f2022-05-17 19:01:43 +0200102 "validity-period (minimum|default) <1-5256000>",
Harald Welte2765a182022-05-17 18:56:55 +0200103 "Configure validity period for SMS\n"
Harald Weltea3c639f2022-05-17 19:01:43 +0200104 "Minimum SMS validity period in minutes\n"
Harald Welte2765a182022-05-17 18:56:55 +0200105 "Default SMS validity period in minutes\n"
Harald Weltea3c639f2022-05-17 19:01:43 +0200106 "Validity period in minutes\n")
Harald Welte2765a182022-05-17 18:56:55 +0200107{
Harald Weltea3c639f2022-05-17 19:01:43 +0200108 if (!strcmp(argv[0], "minimum"))
109 smqcfg->minimum_validity_mins = atoi(argv[1]);
110 else
111 smqcfg->default_validity_mins = atoi(argv[1]);
Harald Welte2765a182022-05-17 18:56:55 +0200112 return CMD_SUCCESS;
113}
114
115
Harald Welte1a62db22022-05-17 12:06:58 +0200116/***********************************************************************
117 * View / Enable Node
118 ***********************************************************************/
119
120DEFUN(show_smsqueue,
121 show_smsqueue_cmd,
122 "show sms-queue",
123 SHOW_STR "Display SMSqueue statistics\n")
124{
125 sms_queue_stats(gsmnet->sms_queue, vty);
126 return CMD_SUCCESS;
127}
128
129DEFUN(smsqueue_trigger,
130 smsqueue_trigger_cmd,
131 "sms-queue trigger",
132 "SMS Queue\n" "Trigger sending messages\n")
133{
134 sms_queue_trigger(gsmnet->sms_queue);
135 return CMD_SUCCESS;
136}
137
138DEFUN(smsqueue_max,
139 smsqueue_max_cmd,
140 "sms-queue max-pending <1-500>",
141 "SMS Queue\n" "SMS to deliver in parallel\n" "Amount\n")
142{
143 int max_pending = atoi(argv[0]);
144 vty_out(vty, "%% SMSqueue old max: %d new: %d%s",
145 smqcfg->max_pending, max_pending, VTY_NEWLINE);
146 smqcfg->max_pending = max_pending;
147 return CMD_SUCCESS;
148}
149
150DEFUN(smsqueue_clear,
151 smsqueue_clear_cmd,
152 "sms-queue clear",
153 "SMS Queue\n" "Clear the queue of pending SMS\n")
154{
155 sms_queue_clear(gsmnet->sms_queue);
156 return CMD_SUCCESS;
157}
158
159DEFUN(smsqueue_fail,
160 smsqueue_fail_cmd,
161 "sms-queue max-failure <1-500>",
162 "SMS Queue\n" "Maximum amount of delivery failures\n" "Amount\n")
163{
164 int max_fail = atoi(argv[0]);
165 vty_out(vty, "%% SMSqueue max failure old: %d new: %d%s",
166 smqcfg->max_fail, max_fail, VTY_NEWLINE);
167 smqcfg->max_fail = max_fail;
168 return CMD_SUCCESS;
169}
170
171static int config_write_smsc(struct vty *vty)
172{
173 vty_out(vty, "smsc%s", VTY_NEWLINE);
174
175 if (smqcfg->db_file_path && strcmp(smqcfg->db_file_path, SMS_DEFAULT_DB_FILE_PATH))
176 vty_out(vty, " database %s%s", smqcfg->db_file_path, VTY_NEWLINE);
177
178 vty_out(vty, " queue max-pending %u%s", smqcfg->max_pending, VTY_NEWLINE);
179 vty_out(vty, " queue max-failure %u%s", smqcfg->max_fail, VTY_NEWLINE);
180
Harald Welte53e2e5f2022-05-17 14:39:51 +0200181 vty_out(vty, " database delete-delivered %u%s", smqcfg->delete_delivered, VTY_NEWLINE);
182 vty_out(vty, " database delete-expired %u%s", smqcfg->delete_expired, VTY_NEWLINE);
183
Harald Weltea3c639f2022-05-17 19:01:43 +0200184 vty_out(vty, " validity-period minimum %u%s", smqcfg->minimum_validity_mins, VTY_NEWLINE);
Harald Welte2765a182022-05-17 18:56:55 +0200185 vty_out(vty, " validity-period default %u%s", smqcfg->default_validity_mins, VTY_NEWLINE);
186
Harald Welte1a62db22022-05-17 12:06:58 +0200187 return 0;
188}
189
190void smsc_vty_init(struct gsm_network *msc_network)
191{
192 OSMO_ASSERT(gsmnet == NULL);
193 gsmnet = msc_network;
194 smqcfg = msc_network->sms_queue_cfg;
195
196 /* config node */
197 install_element(CONFIG_NODE, &cfg_smsc_cmd);
198 install_node(&smsc_node, config_write_smsc);
199 install_element(SMSC_NODE, &cfg_sms_database_cmd);
200 install_element(SMSC_NODE, &cfg_sms_queue_max_cmd);
201 install_element(SMSC_NODE, &cfg_sms_queue_fail_cmd);
Harald Welte53e2e5f2022-05-17 14:39:51 +0200202 install_element(SMSC_NODE, &cfg_sms_db_del_delivered_cmd);
203 install_element(SMSC_NODE, &cfg_sms_db_del_expired_cmd);
Harald Welte2765a182022-05-17 18:56:55 +0200204 install_element(SMSC_NODE, &cfg_sms_def_val_per_cmd);
Harald Welte1a62db22022-05-17 12:06:58 +0200205
206 /* enable node */
207 install_element(ENABLE_NODE, &smsqueue_trigger_cmd);
208 install_element(ENABLE_NODE, &smsqueue_max_cmd);
209 install_element(ENABLE_NODE, &smsqueue_clear_cmd);
210 install_element(ENABLE_NODE, &smsqueue_fail_cmd);
211
212 /* view / enable node */
213 install_element_ve(&show_smsqueue_cmd);
214}