blob: 9532a030998c7f50be5fd60690b020d51fe9ff31 [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"
Harald Weltefa7ee332018-06-24 13:20:32 +020038#include "gsup_server.h"
Neels Hofmeyr7685a782017-01-30 23:30:26 +010039
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020040struct cmd_node hlr_node = {
41 HLR_NODE,
42 "%s(config-hlr)# ",
43 1,
44};
45
46DEFUN(cfg_hlr,
47 cfg_hlr_cmd,
48 "hlr",
49 "Configure the HLR")
50{
51 vty->node = HLR_NODE;
52 return CMD_SUCCESS;
53}
54
55struct cmd_node gsup_node = {
56 GSUP_NODE,
57 "%s(config-hlr-gsup)# ",
58 1,
59};
60
61DEFUN(cfg_gsup,
62 cfg_gsup_cmd,
63 "gsup",
64 "Configure GSUP options")
65{
66 vty->node = GSUP_NODE;
67 return CMD_SUCCESS;
68}
69
70static int config_write_hlr(struct vty *vty)
71{
72 vty_out(vty, "hlr%s", VTY_NEWLINE);
73 return CMD_SUCCESS;
74}
75
76static int config_write_hlr_gsup(struct vty *vty)
77{
78 vty_out(vty, " gsup%s", VTY_NEWLINE);
79 if (g_hlr->gsup_bind_addr)
80 vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
81 return CMD_SUCCESS;
82}
83
Harald Weltefa7ee332018-06-24 13:20:32 +020084static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
85{
86 const struct ipa_server_conn *isc = conn->conn;
87 char *name;
88 int rc;
89
90 rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
91 OSMO_ASSERT(rc);
92
93 vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s",
94 name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind,
95 VTY_NEWLINE);
96}
97
98DEFUN(show_gsup_conn, show_gsup_conn_cmd,
99 "show gsup-connections",
100 SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n")
101{
102 struct osmo_gsup_server *gs = g_hlr->gs;
103 struct osmo_gsup_conn *conn;
104
105 llist_for_each_entry(conn, &gs->clients, list)
106 show_one_conn(vty, conn);
107
108 return CMD_SUCCESS;
109}
110
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200111DEFUN(cfg_hlr_gsup_bind_ip,
112 cfg_hlr_gsup_bind_ip_cmd,
113 "bind ip A.B.C.D",
114 "Listen/Bind related socket option\n"
115 IP_STR
116 "IPv4 Address to bind the GSUP interface to\n")
117{
118 if(g_hlr->gsup_bind_addr)
119 talloc_free(g_hlr->gsup_bind_addr);
120 g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]);
121
122 return CMD_SUCCESS;
123}
124
Harald Welte4956ae12018-06-15 22:04:28 +0200125/***********************************************************************
Harald Weltedab544e2018-07-29 16:14:48 +0200126 * USSD Entity
Harald Welte4956ae12018-06-15 22:04:28 +0200127 ***********************************************************************/
128
129#include "hlr_ussd.h"
130
Harald Weltedab544e2018-07-29 16:14:48 +0200131#define USSD_STR "USSD Configuration\n"
132#define UROUTE_STR "Routing Configuration\n"
133#define PREFIX_STR "Prefix-Matching Route\n" "USSD Prefix\n"
Harald Welte4956ae12018-06-15 22:04:28 +0200134
Harald Weltedab544e2018-07-29 16:14:48 +0200135#define INT_CHOICE "(own-msisdn|own-imsi)"
136#define INT_STR "Internal USSD Handler\n" \
137 "Respond with subscribers' own MSISDN\n" \
138 "Respond with subscribers' own IMSI\n"
139
140#define EXT_STR "External USSD Handler\n" \
141 "Name of External USSD Handler (IPA CCM ID)\n"
142
143DEFUN(cfg_ussd_route_pfx_int, cfg_ussd_route_pfx_int_cmd,
144 "ussd route prefix PREFIX internal " INT_CHOICE,
145 USSD_STR UROUTE_STR PREFIX_STR INT_STR)
146{
147 const struct hlr_iuse *iuse = iuse_find(argv[1]);
148 struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
Harald Welte4956ae12018-06-15 22:04:28 +0200149 if (rt) {
150 vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
151 return CMD_WARNING;
152 }
Harald Weltedab544e2018-07-29 16:14:48 +0200153 ussd_route_prefix_alloc_int(g_hlr, argv[0], iuse);
Harald Welte4956ae12018-06-15 22:04:28 +0200154
155 return CMD_SUCCESS;
156}
157
Harald Weltedab544e2018-07-29 16:14:48 +0200158DEFUN(cfg_ussd_route_pfx_ext, cfg_ussd_route_pfx_ext_cmd,
159 "ussd route prefix PREFIX external EUSE",
160 USSD_STR UROUTE_STR PREFIX_STR EXT_STR)
Harald Welte4956ae12018-06-15 22:04:28 +0200161{
Harald Weltedab544e2018-07-29 16:14:48 +0200162 struct hlr_euse *euse = euse_find(g_hlr, argv[1]);
163 struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
164 if (rt) {
165 vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
166 return CMD_WARNING;
167 }
168 if (!euse) {
169 vty_out(vty, "%% Cannot find euse '%s'%s", argv[1], VTY_NEWLINE);
170 return CMD_WARNING;
171 }
172 ussd_route_prefix_alloc_ext(g_hlr, argv[0], euse);
173
174 return CMD_SUCCESS;
175}
176
177DEFUN(cfg_ussd_no_route_pfx, cfg_ussd_no_route_pfx_cmd,
178 "no ussd route prefix PREFIX",
179 NO_STR USSD_STR UROUTE_STR PREFIX_STR)
180{
181 struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
Harald Welte4956ae12018-06-15 22:04:28 +0200182 if (!rt) {
183 vty_out(vty, "%% Cannot find route for prefix %s%s", argv[0], VTY_NEWLINE);
184 return CMD_WARNING;
185 }
Harald Weltedab544e2018-07-29 16:14:48 +0200186 ussd_route_del(rt);
Harald Welte4956ae12018-06-15 22:04:28 +0200187
188 return CMD_SUCCESS;
189}
190
Harald Weltedab544e2018-07-29 16:14:48 +0200191DEFUN(cfg_ussd_defaultroute, cfg_ussd_defaultroute_cmd,
192 "ussd default-route external EUSE",
193 USSD_STR "Configure default-route for all USSD to unknown destinations\n"
194 EXT_STR)
Harald Welte4956ae12018-06-15 22:04:28 +0200195{
Harald Weltedab544e2018-07-29 16:14:48 +0200196 struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
Harald Welte4956ae12018-06-15 22:04:28 +0200197
198 if (g_hlr->euse_default != euse) {
199 vty_out(vty, "Switching default route from %s to %s%s",
Harald Welte55d32a12018-07-30 17:26:35 +0200200 g_hlr->euse_default ? g_hlr->euse_default->name : "<none>",
201 euse->name, VTY_NEWLINE);
Harald Welte4956ae12018-06-15 22:04:28 +0200202 g_hlr->euse_default = euse;
203 }
204
205 return CMD_SUCCESS;
206}
207
Harald Weltedab544e2018-07-29 16:14:48 +0200208DEFUN(cfg_ussd_no_defaultroute, cfg_ussd_no_defaultroute_cmd,
209 "no ussd default-route",
210 NO_STR USSD_STR "Remove the default-route for all USSD to unknown destinations\n")
Harald Welte4956ae12018-06-15 22:04:28 +0200211{
Harald Welte4956ae12018-06-15 22:04:28 +0200212 g_hlr->euse_default = NULL;
213
214 return CMD_SUCCESS;
215}
216
217struct cmd_node euse_node = {
218 EUSE_NODE,
219 "%s(config-hlr-euse)# ",
220 1,
221};
222
223DEFUN(cfg_euse, cfg_euse_cmd,
224 "euse NAME",
225 "Configure a particular External USSD Entity\n"
226 "Alphanumeric name of the External USSD Entity\n")
227{
228 struct hlr_euse *euse;
229 const char *id = argv[0];
230
231 euse = euse_find(g_hlr, id);
232 if (!euse) {
233 euse = euse_alloc(g_hlr, id);
234 if (!euse)
235 return CMD_WARNING;
236 }
237 vty->index = euse;
238 vty->index_sub = &euse->description;
239 vty->node = EUSE_NODE;
240
241 return CMD_SUCCESS;
242}
243
244DEFUN(cfg_no_euse, cfg_no_euse_cmd,
245 "no euse NAME",
246 NO_STR "Remove a particular External USSD Entity\n"
247 "Alphanumeric name of the External USSD Entity\n")
248{
249 struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
250 if (!euse) {
251 vty_out(vty, "%% Cannot remove non-existant EUSE %s%s", argv[0], VTY_NEWLINE);
252 return CMD_WARNING;
253 }
254 if (g_hlr->euse_default == euse) {
255 vty_out(vty, "%% Cannot remove EUSE %s, it is the default route%s", argv[0], VTY_NEWLINE);
256 return CMD_WARNING;
257 }
258 euse_del(euse);
259 return CMD_SUCCESS;
260}
261
262static void dump_one_euse(struct vty *vty, struct hlr_euse *euse)
263{
Harald Welte4956ae12018-06-15 22:04:28 +0200264 vty_out(vty, " euse %s%s", euse->name, VTY_NEWLINE);
Harald Welte4956ae12018-06-15 22:04:28 +0200265}
266
267static int config_write_euse(struct vty *vty)
268{
269 struct hlr_euse *euse;
Harald Weltedab544e2018-07-29 16:14:48 +0200270 struct hlr_ussd_route *rt;
Harald Welte4956ae12018-06-15 22:04:28 +0200271
272 llist_for_each_entry(euse, &g_hlr->euse_list, list)
273 dump_one_euse(vty, euse);
274
Harald Weltedab544e2018-07-29 16:14:48 +0200275 llist_for_each_entry(rt, &g_hlr->ussd_routes, list) {
276 vty_out(vty, " ussd route prefix %s %s %s%s", rt->prefix,
277 rt->is_external ? "external" : "internal",
278 rt->is_external ? rt->u.euse->name : rt->u.iuse->name,
279 VTY_NEWLINE);
280 }
281
282 if (g_hlr->euse_default)
283 vty_out(vty, " ussd default-route external %s%s", g_hlr->euse_default->name, VTY_NEWLINE);
284
Harald Welte4956ae12018-06-15 22:04:28 +0200285 return 0;
286}
287
288/***********************************************************************
289 * Common Code
290 ***********************************************************************/
291
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200292int hlr_vty_go_parent(struct vty *vty)
293{
294 switch (vty->node) {
295 case GSUP_NODE:
Harald Welte4956ae12018-06-15 22:04:28 +0200296 case EUSE_NODE:
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200297 vty->node = HLR_NODE;
298 vty->index = NULL;
Harald Welte4956ae12018-06-15 22:04:28 +0200299 vty->index_sub = NULL;
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200300 break;
301 default:
302 case HLR_NODE:
303 vty->node = CONFIG_NODE;
304 vty->index = NULL;
305 break;
306 case CONFIG_NODE:
307 vty->node = ENABLE_NODE;
308 vty->index = NULL;
309 break;
310 }
311
312 return vty->node;
313}
314
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100315int hlr_vty_is_config_node(struct vty *vty, int node)
316{
317 switch (node) {
318 /* add items that are not config */
319 case CONFIG_NODE:
320 return 0;
321
322 default:
323 return 1;
324 }
325}
326
Harald Welted5807b82018-07-29 12:27:41 +0200327void hlr_vty_init(const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100328{
329 logging_vty_add_cmds(cat);
Harald Welte7ee6e552018-02-14 00:52:05 +0100330 osmo_talloc_vty_add_cmds();
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200331
Harald Weltefa7ee332018-06-24 13:20:32 +0200332 install_element_ve(&show_gsup_conn_cmd);
333
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200334 install_element(CONFIG_NODE, &cfg_hlr_cmd);
335 install_node(&hlr_node, config_write_hlr);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200336
337 install_element(HLR_NODE, &cfg_gsup_cmd);
338 install_node(&gsup_node, config_write_hlr_gsup);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200339
340 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr183e7002017-10-06 02:59:54 +0200341
Harald Welte4956ae12018-06-15 22:04:28 +0200342 install_element(HLR_NODE, &cfg_euse_cmd);
343 install_element(HLR_NODE, &cfg_no_euse_cmd);
344 install_node(&euse_node, config_write_euse);
Harald Weltedab544e2018-07-29 16:14:48 +0200345 install_element(HLR_NODE, &cfg_ussd_route_pfx_int_cmd);
346 install_element(HLR_NODE, &cfg_ussd_route_pfx_ext_cmd);
347 install_element(HLR_NODE, &cfg_ussd_no_route_pfx_cmd);
348 install_element(HLR_NODE, &cfg_ussd_defaultroute_cmd);
349 install_element(HLR_NODE, &cfg_ussd_no_defaultroute_cmd);
Harald Welte4956ae12018-06-15 22:04:28 +0200350
Harald Welted5807b82018-07-29 12:27:41 +0200351 hlr_vty_subscriber_init();
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100352}