blob: cdb81c60f064db2581c1ef6b224dc11b0c9f0f42 [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
79/***********************************************************************
80 * View / Enable Node
81 ***********************************************************************/
82
83DEFUN(show_smsqueue,
84 show_smsqueue_cmd,
85 "show sms-queue",
86 SHOW_STR "Display SMSqueue statistics\n")
87{
88 sms_queue_stats(gsmnet->sms_queue, vty);
89 return CMD_SUCCESS;
90}
91
92DEFUN(smsqueue_trigger,
93 smsqueue_trigger_cmd,
94 "sms-queue trigger",
95 "SMS Queue\n" "Trigger sending messages\n")
96{
97 sms_queue_trigger(gsmnet->sms_queue);
98 return CMD_SUCCESS;
99}
100
101DEFUN(smsqueue_max,
102 smsqueue_max_cmd,
103 "sms-queue max-pending <1-500>",
104 "SMS Queue\n" "SMS to deliver in parallel\n" "Amount\n")
105{
106 int max_pending = atoi(argv[0]);
107 vty_out(vty, "%% SMSqueue old max: %d new: %d%s",
108 smqcfg->max_pending, max_pending, VTY_NEWLINE);
109 smqcfg->max_pending = max_pending;
110 return CMD_SUCCESS;
111}
112
113DEFUN(smsqueue_clear,
114 smsqueue_clear_cmd,
115 "sms-queue clear",
116 "SMS Queue\n" "Clear the queue of pending SMS\n")
117{
118 sms_queue_clear(gsmnet->sms_queue);
119 return CMD_SUCCESS;
120}
121
122DEFUN(smsqueue_fail,
123 smsqueue_fail_cmd,
124 "sms-queue max-failure <1-500>",
125 "SMS Queue\n" "Maximum amount of delivery failures\n" "Amount\n")
126{
127 int max_fail = atoi(argv[0]);
128 vty_out(vty, "%% SMSqueue max failure old: %d new: %d%s",
129 smqcfg->max_fail, max_fail, VTY_NEWLINE);
130 smqcfg->max_fail = max_fail;
131 return CMD_SUCCESS;
132}
133
134static int config_write_smsc(struct vty *vty)
135{
136 vty_out(vty, "smsc%s", VTY_NEWLINE);
137
138 if (smqcfg->db_file_path && strcmp(smqcfg->db_file_path, SMS_DEFAULT_DB_FILE_PATH))
139 vty_out(vty, " database %s%s", smqcfg->db_file_path, VTY_NEWLINE);
140
141 vty_out(vty, " queue max-pending %u%s", smqcfg->max_pending, VTY_NEWLINE);
142 vty_out(vty, " queue max-failure %u%s", smqcfg->max_fail, VTY_NEWLINE);
143
144 return 0;
145}
146
147void smsc_vty_init(struct gsm_network *msc_network)
148{
149 OSMO_ASSERT(gsmnet == NULL);
150 gsmnet = msc_network;
151 smqcfg = msc_network->sms_queue_cfg;
152
153 /* config node */
154 install_element(CONFIG_NODE, &cfg_smsc_cmd);
155 install_node(&smsc_node, config_write_smsc);
156 install_element(SMSC_NODE, &cfg_sms_database_cmd);
157 install_element(SMSC_NODE, &cfg_sms_queue_max_cmd);
158 install_element(SMSC_NODE, &cfg_sms_queue_fail_cmd);
159
160 /* enable node */
161 install_element(ENABLE_NODE, &smsqueue_trigger_cmd);
162 install_element(ENABLE_NODE, &smsqueue_max_cmd);
163 install_element(ENABLE_NODE, &smsqueue_clear_cmd);
164 install_element(ENABLE_NODE, &smsqueue_fail_cmd);
165
166 /* view / enable node */
167 install_element_ve(&show_smsqueue_cmd);
168}