blob: dbf2607d32d7014dceaf0edfb48c51292cade90d [file] [log] [blame]
Harald Welte0df904d2018-12-03 11:00:04 +01001/* (C) 2018-2019 by sysmocom s.f.m.c. GmbH
2 * All Rights Reserved
3 *
4 * Author: Harald Welte, Philipp Maier
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * 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
9 * (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
14 * GNU Affero General Public License for more details.
15 *
16 * 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/>.
18 *
19 */
20
21#include <string.h>
22#include <errno.h>
23#include <osmocom/core/utils.h>
24#include <osmocom/core/msgb.h>
25#include <osmocom/msc/vty.h>
26#include <osmocom/netif/stream.h>
27#include <osmocom/msc/sgs_iface.h>
28#include <osmocom/msc/sgs_server.h>
29#include <osmocom/msc/debug.h>
30#include <osmocom/gsm/tlv.h>
31
32struct cmd_node cfg_sgs_node = {
33 CFG_SGS_NODE,
34 "%s(config-sgs)# ",
35 1
36};
37
38DEFUN(cfg_sgs, cfg_sgs_cmd,
39 "sgs",
40 "Configure the SGs interface\n")
41{
42 vty->index = g_sgs;
43 vty->node = CFG_SGS_NODE;
44
45 return CMD_SUCCESS;
46}
47
48DEFUN(cfg_sgs_local_ip, cfg_sgs_local_ip_cmd,
49 "local-ip A.B.C.D",
50 "Set the Local IP Address of the SGs interface\n"
51 "Local IP Address of the SGs interface\n")
52{
53 struct sgs_state *sgs = vty->index;
54 int rc;
55
56 osmo_strlcpy(sgs->cfg.local_addr, argv[0], sizeof(sgs->cfg.local_addr));
57 osmo_stream_srv_link_set_addr(sgs->srv_link, sgs->cfg.local_addr);
58
Vadim Yanitskiy81635d32019-03-22 02:09:06 +070059 if (vty->type != VTY_FILE) {
60 rc = sgs_server_open(sgs);
61 if (rc < 0)
62 return CMD_WARNING;
63 }
Harald Welte0df904d2018-12-03 11:00:04 +010064
65 return CMD_SUCCESS;
66}
67
68DEFUN(cfg_sgs_local_port, cfg_sgs_local_port_cmd,
69 "local-port <0-65535>",
70 "Set the local SCTP port of the SGs interface\n"
71 "Local SCTP port of the SGs interface\n")
72{
73 struct sgs_state *sgs = vty->index;
74 int rc;
75
76 sgs->cfg.local_port = atoi(argv[0]);
77 osmo_stream_srv_link_set_port(sgs->srv_link, sgs->cfg.local_port);
78
Vadim Yanitskiy81635d32019-03-22 02:09:06 +070079 if (vty->type != VTY_FILE) {
80 rc = sgs_server_open(sgs);
81 if (rc < 0)
82 return CMD_WARNING;
83 }
Harald Welte0df904d2018-12-03 11:00:04 +010084
85 return CMD_SUCCESS;
86}
87
88DEFUN(cfg_sgs_vlr_name, cfg_sgs_vlr_name_cmd,
89 "vlr-name FQDN",
90 "Set the SGs VLR Name as per TS 29.118 9.4.22\n"
91 "Fully-Qualified Domain Name of this VLR\n")
92{
93 struct sgs_state *sgs = vty->index;
94 osmo_strlcpy(sgs->cfg.vlr_name, argv[0], sizeof(sgs->cfg.vlr_name));
95
96 return CMD_SUCCESS;
97}
98
99DEFUN(cfg_sgs_timer, cfg_sgs_timer_cmd,
100 "timer (ts5|ts6-2|ts7|ts11|ts14|ts15) <1-120>",
101 "Configure SGs Timer\n"
102 "Paging procedure guard timer\n"
103 "TMSI reallocation guard timer\n"
104 "Non-EPS alert procedure guard timer\n"
105 "VLR reset guard timer\n"
106 "UE fallback prcoedure timer\n"
107 "MO UE fallback procedure guard timer\n"
108 "Time in seconds\n")
109{
110 struct sgs_state *sgs = vty->index;
111 unsigned int i;
112
113 for (i = 0; i < ARRAY_SIZE(sgs->cfg.timer); i++) {
114 if (!strcasecmp(argv[0], vlr_sgs_state_timer_name(i))) {
115 sgs->cfg.timer[i] = atoi(argv[1]);
116 return CMD_SUCCESS;
117 }
118 }
119
120 return CMD_WARNING;
121}
122
123DEFUN(cfg_sgs_counter, cfg_sgs_counter_cmd,
124 "counter (ns7|ns11) <0-255>",
125 "Configure SGs Counter\n"
126 "Non-EPS alert request retry counter\n"
127 "VLR reset retry counter\n" "Counter value\n")
128{
129 struct sgs_state *sgs = vty->index;
130 unsigned int i = 0;
131
132 for (i = 0; i < ARRAY_SIZE(sgs->cfg.counter); i++) {
133 if (!strcasecmp(argv[0], vlr_sgs_state_counter_name(i))) {
134 sgs->cfg.counter[i] = atoi(argv[1]);
135 return CMD_SUCCESS;
136 }
137 }
138
139 return CMD_WARNING;
140}
141
142DEFUN(show_sgs_conn, show_sgs_conn_cmd,
143 "show sgs-connections", SHOW_STR
144 "Show SGs interface connections / MMEs\n")
145{
146 struct sgs_connection *sgc;
147
148 llist_for_each_entry(sgc, &g_sgs->conn_list, entry) {
149 vty_out(vty, " %s %s%s", sgc->sockname, sgc->mme ? sgc->mme->fqdn : "", VTY_NEWLINE);
150 }
151 return CMD_SUCCESS;
152}
153
154static int config_write_sgs(struct vty *vty)
155{
156 struct sgs_state *sgs = g_sgs;
157 unsigned int i;
158 char str_buf[256];
159
160 vty_out(vty, "sgs%s", VTY_NEWLINE);
Vadim Yanitskiy4d758772019-02-23 16:16:44 +0700161 vty_out(vty, " local-port %u%s", sgs->cfg.local_port, VTY_NEWLINE);
162 vty_out(vty, " local-ip %s%s", sgs->cfg.local_addr, VTY_NEWLINE);
163 vty_out(vty, " vlr-name %s%s", sgs->cfg.vlr_name, VTY_NEWLINE);
Harald Welte0df904d2018-12-03 11:00:04 +0100164
165 for (i = 0; i < ARRAY_SIZE(sgs->cfg.timer); i++) {
166 if (sgs->cfg.timer[i] == sgs_state_timer_defaults[i])
167 continue;
168 osmo_str_tolower_buf(str_buf, sizeof(str_buf), vlr_sgs_state_timer_name(i));
169 vty_out(vty, " timer %s %u%s", str_buf, sgs->cfg.timer[i], VTY_NEWLINE);
170 }
171
172 for (i = 0; i < ARRAY_SIZE(sgs->cfg.counter); i++) {
173 if (sgs->cfg.counter[i] == sgs_state_counter_defaults[i])
174 continue;
175 osmo_str_tolower_buf(str_buf, sizeof(str_buf), vlr_sgs_state_counter_name(i));
176 vty_out(vty, " counter %s %u%s", str_buf, sgs->cfg.counter[i], VTY_NEWLINE);
177 }
178
179 return CMD_SUCCESS;
180}
181
182void sgs_vty_init(void)
183{
184 /* configuration commands / nodes */
185 install_element(CONFIG_NODE, &cfg_sgs_cmd);
186 install_node(&cfg_sgs_node, config_write_sgs);
187 install_element(CFG_SGS_NODE, &cfg_sgs_local_ip_cmd);
188 install_element(CFG_SGS_NODE, &cfg_sgs_local_port_cmd);
189 install_element(CFG_SGS_NODE, &cfg_sgs_timer_cmd);
190 install_element(CFG_SGS_NODE, &cfg_sgs_counter_cmd);
191 install_element(CFG_SGS_NODE, &cfg_sgs_vlr_name_cmd);
192
193 install_element_ve(&show_sgs_conn_cmd);
194}