blob: b2d191a4dc90c8beaf9448ebdd5e8c5b0f1e45ee [file] [log] [blame]
Harald Welte1a62db22022-05-17 12:06:58 +02001/* SMSC interface to VTY */
2/* (C) 2016-2018 by sysmocom s.m.f.c. GmbH <info@sysmocom.de>
3 * 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 Welte1a62db22022-05-17 12:06:58 +0200101/***********************************************************************
102 * View / Enable Node
103 ***********************************************************************/
104
105DEFUN(show_smsqueue,
106 show_smsqueue_cmd,
107 "show sms-queue",
108 SHOW_STR "Display SMSqueue statistics\n")
109{
110 sms_queue_stats(gsmnet->sms_queue, vty);
111 return CMD_SUCCESS;
112}
113
114DEFUN(smsqueue_trigger,
115 smsqueue_trigger_cmd,
116 "sms-queue trigger",
117 "SMS Queue\n" "Trigger sending messages\n")
118{
119 sms_queue_trigger(gsmnet->sms_queue);
120 return CMD_SUCCESS;
121}
122
123DEFUN(smsqueue_max,
124 smsqueue_max_cmd,
125 "sms-queue max-pending <1-500>",
126 "SMS Queue\n" "SMS to deliver in parallel\n" "Amount\n")
127{
128 int max_pending = atoi(argv[0]);
129 vty_out(vty, "%% SMSqueue old max: %d new: %d%s",
130 smqcfg->max_pending, max_pending, VTY_NEWLINE);
131 smqcfg->max_pending = max_pending;
132 return CMD_SUCCESS;
133}
134
135DEFUN(smsqueue_clear,
136 smsqueue_clear_cmd,
137 "sms-queue clear",
138 "SMS Queue\n" "Clear the queue of pending SMS\n")
139{
140 sms_queue_clear(gsmnet->sms_queue);
141 return CMD_SUCCESS;
142}
143
144DEFUN(smsqueue_fail,
145 smsqueue_fail_cmd,
146 "sms-queue max-failure <1-500>",
147 "SMS Queue\n" "Maximum amount of delivery failures\n" "Amount\n")
148{
149 int max_fail = atoi(argv[0]);
150 vty_out(vty, "%% SMSqueue max failure old: %d new: %d%s",
151 smqcfg->max_fail, max_fail, VTY_NEWLINE);
152 smqcfg->max_fail = max_fail;
153 return CMD_SUCCESS;
154}
155
156static int config_write_smsc(struct vty *vty)
157{
158 vty_out(vty, "smsc%s", VTY_NEWLINE);
159
160 if (smqcfg->db_file_path && strcmp(smqcfg->db_file_path, SMS_DEFAULT_DB_FILE_PATH))
161 vty_out(vty, " database %s%s", smqcfg->db_file_path, VTY_NEWLINE);
162
163 vty_out(vty, " queue max-pending %u%s", smqcfg->max_pending, VTY_NEWLINE);
164 vty_out(vty, " queue max-failure %u%s", smqcfg->max_fail, VTY_NEWLINE);
165
Harald Welte53e2e5f2022-05-17 14:39:51 +0200166 vty_out(vty, " database delete-delivered %u%s", smqcfg->delete_delivered, VTY_NEWLINE);
167 vty_out(vty, " database delete-expired %u%s", smqcfg->delete_expired, VTY_NEWLINE);
168
Harald Welte1a62db22022-05-17 12:06:58 +0200169 return 0;
170}
171
172void smsc_vty_init(struct gsm_network *msc_network)
173{
174 OSMO_ASSERT(gsmnet == NULL);
175 gsmnet = msc_network;
176 smqcfg = msc_network->sms_queue_cfg;
177
178 /* config node */
179 install_element(CONFIG_NODE, &cfg_smsc_cmd);
180 install_node(&smsc_node, config_write_smsc);
181 install_element(SMSC_NODE, &cfg_sms_database_cmd);
182 install_element(SMSC_NODE, &cfg_sms_queue_max_cmd);
183 install_element(SMSC_NODE, &cfg_sms_queue_fail_cmd);
Harald Welte53e2e5f2022-05-17 14:39:51 +0200184 install_element(SMSC_NODE, &cfg_sms_db_del_delivered_cmd);
185 install_element(SMSC_NODE, &cfg_sms_db_del_expired_cmd);
Harald Welte1a62db22022-05-17 12:06:58 +0200186
187 /* enable node */
188 install_element(ENABLE_NODE, &smsqueue_trigger_cmd);
189 install_element(ENABLE_NODE, &smsqueue_max_cmd);
190 install_element(ENABLE_NODE, &smsqueue_clear_cmd);
191 install_element(ENABLE_NODE, &smsqueue_fail_cmd);
192
193 /* view / enable node */
194 install_element_ve(&show_smsqueue_cmd);
195}