blob: 9ecf8a3fb4876f3f4aa6b3797442ff5e3fff00b0 [file] [log] [blame]
Neels Hofmeyr7685a782017-01-30 23:30:26 +01001/* OsmoHLR VTY implementation */
2
3/* (C) 2016 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
Neels Hofmeyr7685a782017-01-30 23:30:26 +01004 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
Harald Weltefa7ee332018-06-24 13:20:32 +02005 * (C) 2018 Harald Welte <laforge@gnumonks.org>
6 *
7 * All Rights Reserved
Neels Hofmeyr7685a782017-01-30 23:30:26 +01008 *
Harald Welte4956ae12018-06-15 22:04:28 +02009 * (C) 2018 Harald Welte <laforge@gnumonks.org>
10 *
11 * All Rights Reserved
12 *
Neels Hofmeyr7685a782017-01-30 23:30:26 +010013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Affero General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Affero General Public License for more details.
22 *
23 * You should have received a copy of the GNU Affero General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 *
26 */
27
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020028#include <osmocom/core/talloc.h>
Neels Hofmeyr7685a782017-01-30 23:30:26 +010029#include <osmocom/vty/vty.h>
30#include <osmocom/vty/command.h>
31#include <osmocom/vty/logging.h>
Harald Welte7ee6e552018-02-14 00:52:05 +010032#include <osmocom/vty/misc.h>
Harald Weltefa7ee332018-06-24 13:20:32 +020033#include <osmocom/abis/ipa.h>
Neels Hofmeyr7685a782017-01-30 23:30:26 +010034
Harald Weltedab544e2018-07-29 16:14:48 +020035#include "hlr.h"
Neels Hofmeyr7685a782017-01-30 23:30:26 +010036#include "hlr_vty.h"
Neels Hofmeyr183e7002017-10-06 02:59:54 +020037#include "hlr_vty_subscr.h"
Vadim Yanitskiyd157a562018-12-01 00:03:39 +070038#include "hlr_ussd.h"
Harald Weltefa7ee332018-06-24 13:20:32 +020039#include "gsup_server.h"
Neels Hofmeyr7685a782017-01-30 23:30:26 +010040
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020041struct cmd_node hlr_node = {
42 HLR_NODE,
43 "%s(config-hlr)# ",
44 1,
45};
46
47DEFUN(cfg_hlr,
48 cfg_hlr_cmd,
49 "hlr",
50 "Configure the HLR")
51{
52 vty->node = HLR_NODE;
53 return CMD_SUCCESS;
54}
55
56struct cmd_node gsup_node = {
57 GSUP_NODE,
58 "%s(config-hlr-gsup)# ",
59 1,
60};
61
62DEFUN(cfg_gsup,
63 cfg_gsup_cmd,
64 "gsup",
65 "Configure GSUP options")
66{
67 vty->node = GSUP_NODE;
68 return CMD_SUCCESS;
69}
70
71static int config_write_hlr(struct vty *vty)
72{
73 vty_out(vty, "hlr%s", VTY_NEWLINE);
74 return CMD_SUCCESS;
75}
76
77static int config_write_hlr_gsup(struct vty *vty)
78{
79 vty_out(vty, " gsup%s", VTY_NEWLINE);
80 if (g_hlr->gsup_bind_addr)
81 vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
82 return CMD_SUCCESS;
83}
84
Harald Weltefa7ee332018-06-24 13:20:32 +020085static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
86{
87 const struct ipa_server_conn *isc = conn->conn;
88 char *name;
89 int rc;
90
91 rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
92 OSMO_ASSERT(rc);
93
94 vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s",
95 name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind,
96 VTY_NEWLINE);
97}
98
99DEFUN(show_gsup_conn, show_gsup_conn_cmd,
100 "show gsup-connections",
101 SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n")
102{
103 struct osmo_gsup_server *gs = g_hlr->gs;
104 struct osmo_gsup_conn *conn;
105
106 llist_for_each_entry(conn, &gs->clients, list)
107 show_one_conn(vty, conn);
108
109 return CMD_SUCCESS;
110}
111
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200112DEFUN(cfg_hlr_gsup_bind_ip,
113 cfg_hlr_gsup_bind_ip_cmd,
114 "bind ip A.B.C.D",
115 "Listen/Bind related socket option\n"
116 IP_STR
117 "IPv4 Address to bind the GSUP interface to\n")
118{
119 if(g_hlr->gsup_bind_addr)
120 talloc_free(g_hlr->gsup_bind_addr);
121 g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]);
122
123 return CMD_SUCCESS;
124}
125
Harald Welte4956ae12018-06-15 22:04:28 +0200126/***********************************************************************
Harald Weltedab544e2018-07-29 16:14:48 +0200127 * USSD Entity
Harald Welte4956ae12018-06-15 22:04:28 +0200128 ***********************************************************************/
129
130#include "hlr_ussd.h"
131
Harald Weltedab544e2018-07-29 16:14:48 +0200132#define USSD_STR "USSD Configuration\n"
133#define UROUTE_STR "Routing Configuration\n"
134#define PREFIX_STR "Prefix-Matching Route\n" "USSD Prefix\n"
Harald Welte4956ae12018-06-15 22:04:28 +0200135
Vadim Yanitskiya60ad0d2018-12-27 05:39:54 +0700136#define INT_CHOICE "(own-msisdn|own-imsi|get-ran)"
Harald Weltedab544e2018-07-29 16:14:48 +0200137#define INT_STR "Internal USSD Handler\n" \
138 "Respond with subscribers' own MSISDN\n" \
Vadim Yanitskiya60ad0d2018-12-27 05:39:54 +0700139 "Respond with subscribers' own IMSI\n" \
140 "Respond with available RAN types\n"
Harald Weltedab544e2018-07-29 16:14:48 +0200141
142#define EXT_STR "External USSD Handler\n" \
143 "Name of External USSD Handler (IPA CCM ID)\n"
144
145DEFUN(cfg_ussd_route_pfx_int, cfg_ussd_route_pfx_int_cmd,
146 "ussd route prefix PREFIX internal " INT_CHOICE,
147 USSD_STR UROUTE_STR PREFIX_STR INT_STR)
148{
149 const struct hlr_iuse *iuse = iuse_find(argv[1]);
150 struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
Harald Welte4956ae12018-06-15 22:04:28 +0200151 if (rt) {
152 vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
153 return CMD_WARNING;
154 }
Harald Weltedab544e2018-07-29 16:14:48 +0200155 ussd_route_prefix_alloc_int(g_hlr, argv[0], iuse);
Harald Welte4956ae12018-06-15 22:04:28 +0200156
157 return CMD_SUCCESS;
158}
159
Harald Weltedab544e2018-07-29 16:14:48 +0200160DEFUN(cfg_ussd_route_pfx_ext, cfg_ussd_route_pfx_ext_cmd,
161 "ussd route prefix PREFIX external EUSE",
162 USSD_STR UROUTE_STR PREFIX_STR EXT_STR)
Harald Welte4956ae12018-06-15 22:04:28 +0200163{
Harald Weltedab544e2018-07-29 16:14:48 +0200164 struct hlr_euse *euse = euse_find(g_hlr, argv[1]);
165 struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
166 if (rt) {
167 vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
168 return CMD_WARNING;
169 }
170 if (!euse) {
171 vty_out(vty, "%% Cannot find euse '%s'%s", argv[1], VTY_NEWLINE);
172 return CMD_WARNING;
173 }
174 ussd_route_prefix_alloc_ext(g_hlr, argv[0], euse);
175
176 return CMD_SUCCESS;
177}
178
179DEFUN(cfg_ussd_no_route_pfx, cfg_ussd_no_route_pfx_cmd,
180 "no ussd route prefix PREFIX",
181 NO_STR USSD_STR UROUTE_STR PREFIX_STR)
182{
183 struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
Harald Welte4956ae12018-06-15 22:04:28 +0200184 if (!rt) {
185 vty_out(vty, "%% Cannot find route for prefix %s%s", argv[0], VTY_NEWLINE);
186 return CMD_WARNING;
187 }
Harald Weltedab544e2018-07-29 16:14:48 +0200188 ussd_route_del(rt);
Harald Welte4956ae12018-06-15 22:04:28 +0200189
190 return CMD_SUCCESS;
191}
192
Harald Weltedab544e2018-07-29 16:14:48 +0200193DEFUN(cfg_ussd_defaultroute, cfg_ussd_defaultroute_cmd,
194 "ussd default-route external EUSE",
195 USSD_STR "Configure default-route for all USSD to unknown destinations\n"
196 EXT_STR)
Harald Welte4956ae12018-06-15 22:04:28 +0200197{
Vadim Yanitskiyb93c44f2018-08-02 23:37:51 +0700198 struct hlr_euse *euse;
199
200 euse = euse_find(g_hlr, argv[0]);
201 if (!euse) {
202 vty_out(vty, "%% Cannot find EUSE %s%s", argv[0], VTY_NEWLINE);
203 return CMD_WARNING;
204 }
Harald Welte4956ae12018-06-15 22:04:28 +0200205
206 if (g_hlr->euse_default != euse) {
207 vty_out(vty, "Switching default route from %s to %s%s",
Harald Welte55d32a12018-07-30 17:26:35 +0200208 g_hlr->euse_default ? g_hlr->euse_default->name : "<none>",
209 euse->name, VTY_NEWLINE);
Harald Welte4956ae12018-06-15 22:04:28 +0200210 g_hlr->euse_default = euse;
211 }
212
213 return CMD_SUCCESS;
214}
215
Harald Weltedab544e2018-07-29 16:14:48 +0200216DEFUN(cfg_ussd_no_defaultroute, cfg_ussd_no_defaultroute_cmd,
217 "no ussd default-route",
218 NO_STR USSD_STR "Remove the default-route for all USSD to unknown destinations\n")
Harald Welte4956ae12018-06-15 22:04:28 +0200219{
Harald Welte4956ae12018-06-15 22:04:28 +0200220 g_hlr->euse_default = NULL;
221
222 return CMD_SUCCESS;
223}
224
225struct cmd_node euse_node = {
226 EUSE_NODE,
227 "%s(config-hlr-euse)# ",
228 1,
229};
230
231DEFUN(cfg_euse, cfg_euse_cmd,
232 "euse NAME",
233 "Configure a particular External USSD Entity\n"
234 "Alphanumeric name of the External USSD Entity\n")
235{
236 struct hlr_euse *euse;
237 const char *id = argv[0];
238
239 euse = euse_find(g_hlr, id);
240 if (!euse) {
241 euse = euse_alloc(g_hlr, id);
242 if (!euse)
243 return CMD_WARNING;
244 }
245 vty->index = euse;
246 vty->index_sub = &euse->description;
247 vty->node = EUSE_NODE;
248
249 return CMD_SUCCESS;
250}
251
252DEFUN(cfg_no_euse, cfg_no_euse_cmd,
253 "no euse NAME",
254 NO_STR "Remove a particular External USSD Entity\n"
255 "Alphanumeric name of the External USSD Entity\n")
256{
257 struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
258 if (!euse) {
259 vty_out(vty, "%% Cannot remove non-existant EUSE %s%s", argv[0], VTY_NEWLINE);
260 return CMD_WARNING;
261 }
262 if (g_hlr->euse_default == euse) {
263 vty_out(vty, "%% Cannot remove EUSE %s, it is the default route%s", argv[0], VTY_NEWLINE);
264 return CMD_WARNING;
265 }
266 euse_del(euse);
267 return CMD_SUCCESS;
268}
269
270static void dump_one_euse(struct vty *vty, struct hlr_euse *euse)
271{
Harald Welte4956ae12018-06-15 22:04:28 +0200272 vty_out(vty, " euse %s%s", euse->name, VTY_NEWLINE);
Harald Welte4956ae12018-06-15 22:04:28 +0200273}
274
275static int config_write_euse(struct vty *vty)
276{
277 struct hlr_euse *euse;
Harald Weltedab544e2018-07-29 16:14:48 +0200278 struct hlr_ussd_route *rt;
Harald Welte4956ae12018-06-15 22:04:28 +0200279
280 llist_for_each_entry(euse, &g_hlr->euse_list, list)
281 dump_one_euse(vty, euse);
282
Harald Weltedab544e2018-07-29 16:14:48 +0200283 llist_for_each_entry(rt, &g_hlr->ussd_routes, list) {
284 vty_out(vty, " ussd route prefix %s %s %s%s", rt->prefix,
285 rt->is_external ? "external" : "internal",
286 rt->is_external ? rt->u.euse->name : rt->u.iuse->name,
287 VTY_NEWLINE);
288 }
289
290 if (g_hlr->euse_default)
291 vty_out(vty, " ussd default-route external %s%s", g_hlr->euse_default->name, VTY_NEWLINE);
292
Vadim Yanitskiyd157a562018-12-01 00:03:39 +0700293 if (g_hlr->ncss_guard_timeout != NCSS_GUARD_TIMEOUT_DEFAULT)
294 vty_out(vty, " ncss-guard-timeout %i%s",
295 g_hlr->ncss_guard_timeout, VTY_NEWLINE);
296
Harald Welte4956ae12018-06-15 22:04:28 +0200297 return 0;
298}
299
Vadim Yanitskiyd157a562018-12-01 00:03:39 +0700300DEFUN(cfg_ncss_guard_timeout, cfg_ncss_guard_timeout_cmd,
301 "ncss-guard-timeout <0-255>",
302 "Set guard timer for NCSS (call independent SS) session activity\n"
303 "Guard timer value (sec.), or 0 to disable")
304{
305 g_hlr->ncss_guard_timeout = atoi(argv[0]);
306 return CMD_SUCCESS;
307}
308
Harald Welte4956ae12018-06-15 22:04:28 +0200309/***********************************************************************
310 * Common Code
311 ***********************************************************************/
312
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200313int hlr_vty_go_parent(struct vty *vty)
314{
315 switch (vty->node) {
316 case GSUP_NODE:
Harald Welte4956ae12018-06-15 22:04:28 +0200317 case EUSE_NODE:
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200318 vty->node = HLR_NODE;
319 vty->index = NULL;
Harald Welte4956ae12018-06-15 22:04:28 +0200320 vty->index_sub = NULL;
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200321 break;
322 default:
323 case HLR_NODE:
324 vty->node = CONFIG_NODE;
325 vty->index = NULL;
326 break;
327 case CONFIG_NODE:
328 vty->node = ENABLE_NODE;
329 vty->index = NULL;
330 break;
331 }
332
333 return vty->node;
334}
335
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100336int hlr_vty_is_config_node(struct vty *vty, int node)
337{
338 switch (node) {
339 /* add items that are not config */
340 case CONFIG_NODE:
341 return 0;
342
343 default:
344 return 1;
345 }
346}
347
Harald Welted5807b82018-07-29 12:27:41 +0200348void hlr_vty_init(const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100349{
350 logging_vty_add_cmds(cat);
Harald Welte7ee6e552018-02-14 00:52:05 +0100351 osmo_talloc_vty_add_cmds();
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200352
Harald Weltefa7ee332018-06-24 13:20:32 +0200353 install_element_ve(&show_gsup_conn_cmd);
354
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200355 install_element(CONFIG_NODE, &cfg_hlr_cmd);
356 install_node(&hlr_node, config_write_hlr);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200357
358 install_element(HLR_NODE, &cfg_gsup_cmd);
359 install_node(&gsup_node, config_write_hlr_gsup);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200360
361 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr183e7002017-10-06 02:59:54 +0200362
Harald Welte4956ae12018-06-15 22:04:28 +0200363 install_element(HLR_NODE, &cfg_euse_cmd);
364 install_element(HLR_NODE, &cfg_no_euse_cmd);
365 install_node(&euse_node, config_write_euse);
Harald Weltedab544e2018-07-29 16:14:48 +0200366 install_element(HLR_NODE, &cfg_ussd_route_pfx_int_cmd);
367 install_element(HLR_NODE, &cfg_ussd_route_pfx_ext_cmd);
368 install_element(HLR_NODE, &cfg_ussd_no_route_pfx_cmd);
369 install_element(HLR_NODE, &cfg_ussd_defaultroute_cmd);
370 install_element(HLR_NODE, &cfg_ussd_no_defaultroute_cmd);
Vadim Yanitskiyd157a562018-12-01 00:03:39 +0700371 install_element(HLR_NODE, &cfg_ncss_guard_timeout_cmd);
Harald Welte4956ae12018-06-15 22:04:28 +0200372
Harald Welted5807b82018-07-29 12:27:41 +0200373 hlr_vty_subscriber_init();
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100374}