blob: e1349e790fcf496559245494285e4aad13f314ee [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
35#include "hlr_vty.h"
Neels Hofmeyr183e7002017-10-06 02:59:54 +020036#include "hlr_vty_subscr.h"
Harald Weltefa7ee332018-06-24 13:20:32 +020037#include "gsup_server.h"
Neels Hofmeyr7685a782017-01-30 23:30:26 +010038
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020039struct cmd_node hlr_node = {
40 HLR_NODE,
41 "%s(config-hlr)# ",
42 1,
43};
44
45DEFUN(cfg_hlr,
46 cfg_hlr_cmd,
47 "hlr",
48 "Configure the HLR")
49{
50 vty->node = HLR_NODE;
51 return CMD_SUCCESS;
52}
53
54struct cmd_node gsup_node = {
55 GSUP_NODE,
56 "%s(config-hlr-gsup)# ",
57 1,
58};
59
60DEFUN(cfg_gsup,
61 cfg_gsup_cmd,
62 "gsup",
63 "Configure GSUP options")
64{
65 vty->node = GSUP_NODE;
66 return CMD_SUCCESS;
67}
68
69static int config_write_hlr(struct vty *vty)
70{
71 vty_out(vty, "hlr%s", VTY_NEWLINE);
72 return CMD_SUCCESS;
73}
74
75static int config_write_hlr_gsup(struct vty *vty)
76{
77 vty_out(vty, " gsup%s", VTY_NEWLINE);
78 if (g_hlr->gsup_bind_addr)
79 vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
80 return CMD_SUCCESS;
81}
82
Harald Weltefa7ee332018-06-24 13:20:32 +020083static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
84{
85 const struct ipa_server_conn *isc = conn->conn;
86 char *name;
87 int rc;
88
89 rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
90 OSMO_ASSERT(rc);
91
92 vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s",
93 name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind,
94 VTY_NEWLINE);
95}
96
97DEFUN(show_gsup_conn, show_gsup_conn_cmd,
98 "show gsup-connections",
99 SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n")
100{
101 struct osmo_gsup_server *gs = g_hlr->gs;
102 struct osmo_gsup_conn *conn;
103
104 llist_for_each_entry(conn, &gs->clients, list)
105 show_one_conn(vty, conn);
106
107 return CMD_SUCCESS;
108}
109
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200110DEFUN(cfg_hlr_gsup_bind_ip,
111 cfg_hlr_gsup_bind_ip_cmd,
112 "bind ip A.B.C.D",
113 "Listen/Bind related socket option\n"
114 IP_STR
115 "IPv4 Address to bind the GSUP interface to\n")
116{
117 if(g_hlr->gsup_bind_addr)
118 talloc_free(g_hlr->gsup_bind_addr);
119 g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]);
120
121 return CMD_SUCCESS;
122}
123
Harald Welte4956ae12018-06-15 22:04:28 +0200124/***********************************************************************
125 * External USSD Entity
126 ***********************************************************************/
127
128#include "hlr_ussd.h"
129
130DEFUN(cfg_euse_route_pfx, cfg_euse_route_pfx_cmd,
131 "route prefix PREFIX",
132 "")
133{
134 struct hlr_euse *euse = vty->index;
135 struct hlr_euse_route *rt = euse_route_find(euse, argv[0]);
136
137 if (rt) {
138 vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
139 return CMD_WARNING;
140 }
141 euse_route_prefix_alloc(euse, argv[0]);
142
143 return CMD_SUCCESS;
144}
145
146DEFUN(cfg_euse_no_route_pfx, cfg_euse_no_route_pfx_cmd,
147 "no route prefix PREFIX",
148 NO_STR "")
149{
150 struct hlr_euse *euse = vty->index;
151 struct hlr_euse_route *rt = euse_route_find(euse, argv[0]);
152 if (!rt) {
153 vty_out(vty, "%% Cannot find route for prefix %s%s", argv[0], VTY_NEWLINE);
154 return CMD_WARNING;
155 }
156 euse_route_del(rt);
157
158 return CMD_SUCCESS;
159}
160
161DEFUN(cfg_euse_defaultroute, cfg_euse_defaultroute_cmd,
162 "default-route",
163 "Set this EUSE as default-route for all USSD to unknown destinations\n")
164{
165 struct hlr_euse *euse = vty->index;
166
167 if (g_hlr->euse_default != euse) {
168 vty_out(vty, "Switching default route from %s to %s%s",
169 g_hlr->euse_default->name, euse->name, VTY_NEWLINE);
170 g_hlr->euse_default = euse;
171 }
172
173 return CMD_SUCCESS;
174}
175
176DEFUN(cfg_euse_no_defaultroute, cfg_euse_no_defaultroute_cmd,
177 "no default-route",
178 NO_STR "Remove this EUSE as default-route for all USSD to unknown destinations\n")
179{
180 struct hlr_euse *euse = vty->index;
181
182 if (g_hlr->euse_default != euse) {
183 vty_out(vty, "%% Current EUSE is no default route, cannot delete it%s", VTY_NEWLINE);
184 return CMD_WARNING;
185 }
186 g_hlr->euse_default = NULL;
187
188 return CMD_SUCCESS;
189}
190
191struct cmd_node euse_node = {
192 EUSE_NODE,
193 "%s(config-hlr-euse)# ",
194 1,
195};
196
197DEFUN(cfg_euse, cfg_euse_cmd,
198 "euse NAME",
199 "Configure a particular External USSD Entity\n"
200 "Alphanumeric name of the External USSD Entity\n")
201{
202 struct hlr_euse *euse;
203 const char *id = argv[0];
204
205 euse = euse_find(g_hlr, id);
206 if (!euse) {
207 euse = euse_alloc(g_hlr, id);
208 if (!euse)
209 return CMD_WARNING;
210 }
211 vty->index = euse;
212 vty->index_sub = &euse->description;
213 vty->node = EUSE_NODE;
214
215 return CMD_SUCCESS;
216}
217
218DEFUN(cfg_no_euse, cfg_no_euse_cmd,
219 "no euse NAME",
220 NO_STR "Remove a particular External USSD Entity\n"
221 "Alphanumeric name of the External USSD Entity\n")
222{
223 struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
224 if (!euse) {
225 vty_out(vty, "%% Cannot remove non-existant EUSE %s%s", argv[0], VTY_NEWLINE);
226 return CMD_WARNING;
227 }
228 if (g_hlr->euse_default == euse) {
229 vty_out(vty, "%% Cannot remove EUSE %s, it is the default route%s", argv[0], VTY_NEWLINE);
230 return CMD_WARNING;
231 }
232 euse_del(euse);
233 return CMD_SUCCESS;
234}
235
236static void dump_one_euse(struct vty *vty, struct hlr_euse *euse)
237{
238 struct hlr_euse_route *er;
239
240 vty_out(vty, " euse %s%s", euse->name, VTY_NEWLINE);
241
242 llist_for_each_entry(er, &euse->routes, list)
243 vty_out(vty, " route prefix %s%s", er->prefix, VTY_NEWLINE);
244
245 if (g_hlr->euse_default == euse)
246 vty_out(vty, " default-route%s", VTY_NEWLINE);
247}
248
249static int config_write_euse(struct vty *vty)
250{
251 struct hlr_euse *euse;
252
253 llist_for_each_entry(euse, &g_hlr->euse_list, list)
254 dump_one_euse(vty, euse);
255
256 return 0;
257}
258
259/***********************************************************************
260 * Common Code
261 ***********************************************************************/
262
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200263int hlr_vty_go_parent(struct vty *vty)
264{
265 switch (vty->node) {
266 case GSUP_NODE:
Harald Welte4956ae12018-06-15 22:04:28 +0200267 case EUSE_NODE:
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200268 vty->node = HLR_NODE;
269 vty->index = NULL;
Harald Welte4956ae12018-06-15 22:04:28 +0200270 vty->index_sub = NULL;
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200271 break;
272 default:
273 case HLR_NODE:
274 vty->node = CONFIG_NODE;
275 vty->index = NULL;
276 break;
277 case CONFIG_NODE:
278 vty->node = ENABLE_NODE;
279 vty->index = NULL;
280 break;
281 }
282
283 return vty->node;
284}
285
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100286int hlr_vty_is_config_node(struct vty *vty, int node)
287{
288 switch (node) {
289 /* add items that are not config */
290 case CONFIG_NODE:
291 return 0;
292
293 default:
294 return 1;
295 }
296}
297
Harald Welted5807b82018-07-29 12:27:41 +0200298void hlr_vty_init(const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100299{
300 logging_vty_add_cmds(cat);
Harald Welte7ee6e552018-02-14 00:52:05 +0100301 osmo_talloc_vty_add_cmds();
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200302
Harald Weltefa7ee332018-06-24 13:20:32 +0200303 install_element_ve(&show_gsup_conn_cmd);
304
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200305 install_element(CONFIG_NODE, &cfg_hlr_cmd);
306 install_node(&hlr_node, config_write_hlr);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200307
308 install_element(HLR_NODE, &cfg_gsup_cmd);
309 install_node(&gsup_node, config_write_hlr_gsup);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200310
311 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr183e7002017-10-06 02:59:54 +0200312
Harald Welte4956ae12018-06-15 22:04:28 +0200313 install_element(HLR_NODE, &cfg_euse_cmd);
314 install_element(HLR_NODE, &cfg_no_euse_cmd);
315 install_node(&euse_node, config_write_euse);
316 install_element(EUSE_NODE, &cfg_euse_route_pfx_cmd);
317 install_element(EUSE_NODE, &cfg_euse_no_route_pfx_cmd);
318 install_element(EUSE_NODE, &cfg_euse_defaultroute_cmd);
319 install_element(EUSE_NODE, &cfg_euse_no_defaultroute_cmd);
320
Harald Welted5807b82018-07-29 12:27:41 +0200321 hlr_vty_subscriber_init();
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100322}