blob: 5c359b7ddefba5f34eb3733fc1a4e67d4a9303d2 [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",
Harald Welte55d32a12018-07-30 17:26:35 +0200169 g_hlr->euse_default ? g_hlr->euse_default->name : "<none>",
170 euse->name, VTY_NEWLINE);
Harald Welte4956ae12018-06-15 22:04:28 +0200171 g_hlr->euse_default = euse;
172 }
173
174 return CMD_SUCCESS;
175}
176
177DEFUN(cfg_euse_no_defaultroute, cfg_euse_no_defaultroute_cmd,
178 "no default-route",
179 NO_STR "Remove this EUSE as default-route for all USSD to unknown destinations\n")
180{
181 struct hlr_euse *euse = vty->index;
182
183 if (g_hlr->euse_default != euse) {
184 vty_out(vty, "%% Current EUSE is no default route, cannot delete it%s", VTY_NEWLINE);
185 return CMD_WARNING;
186 }
187 g_hlr->euse_default = NULL;
188
189 return CMD_SUCCESS;
190}
191
192struct cmd_node euse_node = {
193 EUSE_NODE,
194 "%s(config-hlr-euse)# ",
195 1,
196};
197
198DEFUN(cfg_euse, cfg_euse_cmd,
199 "euse NAME",
200 "Configure a particular External USSD Entity\n"
201 "Alphanumeric name of the External USSD Entity\n")
202{
203 struct hlr_euse *euse;
204 const char *id = argv[0];
205
206 euse = euse_find(g_hlr, id);
207 if (!euse) {
208 euse = euse_alloc(g_hlr, id);
209 if (!euse)
210 return CMD_WARNING;
211 }
212 vty->index = euse;
213 vty->index_sub = &euse->description;
214 vty->node = EUSE_NODE;
215
216 return CMD_SUCCESS;
217}
218
219DEFUN(cfg_no_euse, cfg_no_euse_cmd,
220 "no euse NAME",
221 NO_STR "Remove a particular External USSD Entity\n"
222 "Alphanumeric name of the External USSD Entity\n")
223{
224 struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
225 if (!euse) {
226 vty_out(vty, "%% Cannot remove non-existant EUSE %s%s", argv[0], VTY_NEWLINE);
227 return CMD_WARNING;
228 }
229 if (g_hlr->euse_default == euse) {
230 vty_out(vty, "%% Cannot remove EUSE %s, it is the default route%s", argv[0], VTY_NEWLINE);
231 return CMD_WARNING;
232 }
233 euse_del(euse);
234 return CMD_SUCCESS;
235}
236
237static void dump_one_euse(struct vty *vty, struct hlr_euse *euse)
238{
239 struct hlr_euse_route *er;
240
241 vty_out(vty, " euse %s%s", euse->name, VTY_NEWLINE);
242
243 llist_for_each_entry(er, &euse->routes, list)
244 vty_out(vty, " route prefix %s%s", er->prefix, VTY_NEWLINE);
245
246 if (g_hlr->euse_default == euse)
247 vty_out(vty, " default-route%s", VTY_NEWLINE);
248}
249
250static int config_write_euse(struct vty *vty)
251{
252 struct hlr_euse *euse;
253
254 llist_for_each_entry(euse, &g_hlr->euse_list, list)
255 dump_one_euse(vty, euse);
256
257 return 0;
258}
259
260/***********************************************************************
261 * Common Code
262 ***********************************************************************/
263
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200264int hlr_vty_go_parent(struct vty *vty)
265{
266 switch (vty->node) {
267 case GSUP_NODE:
Harald Welte4956ae12018-06-15 22:04:28 +0200268 case EUSE_NODE:
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200269 vty->node = HLR_NODE;
270 vty->index = NULL;
Harald Welte4956ae12018-06-15 22:04:28 +0200271 vty->index_sub = NULL;
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200272 break;
273 default:
274 case HLR_NODE:
275 vty->node = CONFIG_NODE;
276 vty->index = NULL;
277 break;
278 case CONFIG_NODE:
279 vty->node = ENABLE_NODE;
280 vty->index = NULL;
281 break;
282 }
283
284 return vty->node;
285}
286
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100287int hlr_vty_is_config_node(struct vty *vty, int node)
288{
289 switch (node) {
290 /* add items that are not config */
291 case CONFIG_NODE:
292 return 0;
293
294 default:
295 return 1;
296 }
297}
298
Harald Welted5807b82018-07-29 12:27:41 +0200299void hlr_vty_init(const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100300{
301 logging_vty_add_cmds(cat);
Harald Welte7ee6e552018-02-14 00:52:05 +0100302 osmo_talloc_vty_add_cmds();
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200303
Harald Weltefa7ee332018-06-24 13:20:32 +0200304 install_element_ve(&show_gsup_conn_cmd);
305
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200306 install_element(CONFIG_NODE, &cfg_hlr_cmd);
307 install_node(&hlr_node, config_write_hlr);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200308
309 install_element(HLR_NODE, &cfg_gsup_cmd);
310 install_node(&gsup_node, config_write_hlr_gsup);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200311
312 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr183e7002017-10-06 02:59:54 +0200313
Harald Welte4956ae12018-06-15 22:04:28 +0200314 install_element(HLR_NODE, &cfg_euse_cmd);
315 install_element(HLR_NODE, &cfg_no_euse_cmd);
316 install_node(&euse_node, config_write_euse);
317 install_element(EUSE_NODE, &cfg_euse_route_pfx_cmd);
318 install_element(EUSE_NODE, &cfg_euse_no_route_pfx_cmd);
319 install_element(EUSE_NODE, &cfg_euse_defaultroute_cmd);
320 install_element(EUSE_NODE, &cfg_euse_no_defaultroute_cmd);
321
Harald Welted5807b82018-07-29 12:27:41 +0200322 hlr_vty_subscriber_init();
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100323}