Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 1 | /* OsmoHLR VTY implementation */ |
| 2 | |
| 3 | /* (C) 2016 sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 4 | * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 5 | * (C) 2018 Harald Welte <laforge@gnumonks.org> |
| 6 | * |
| 7 | * All Rights Reserved |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 8 | * |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 9 | * (C) 2018 Harald Welte <laforge@gnumonks.org> |
| 10 | * |
| 11 | * All Rights Reserved |
| 12 | * |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 13 | * 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 Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 28 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 29 | #include <osmocom/vty/vty.h> |
| 30 | #include <osmocom/vty/command.h> |
| 31 | #include <osmocom/vty/logging.h> |
Harald Welte | 7ee6e55 | 2018-02-14 00:52:05 +0100 | [diff] [blame] | 32 | #include <osmocom/vty/misc.h> |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 33 | #include <osmocom/abis/ipa.h> |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 34 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 35 | #include "hlr.h" |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 36 | #include "hlr_vty.h" |
Neels Hofmeyr | 183e700 | 2017-10-06 02:59:54 +0200 | [diff] [blame] | 37 | #include "hlr_vty_subscr.h" |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 38 | #include "gsup_server.h" |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 39 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 40 | struct cmd_node hlr_node = { |
| 41 | HLR_NODE, |
| 42 | "%s(config-hlr)# ", |
| 43 | 1, |
| 44 | }; |
| 45 | |
| 46 | DEFUN(cfg_hlr, |
| 47 | cfg_hlr_cmd, |
| 48 | "hlr", |
| 49 | "Configure the HLR") |
| 50 | { |
| 51 | vty->node = HLR_NODE; |
| 52 | return CMD_SUCCESS; |
| 53 | } |
| 54 | |
| 55 | struct cmd_node gsup_node = { |
| 56 | GSUP_NODE, |
| 57 | "%s(config-hlr-gsup)# ", |
| 58 | 1, |
| 59 | }; |
| 60 | |
| 61 | DEFUN(cfg_gsup, |
| 62 | cfg_gsup_cmd, |
| 63 | "gsup", |
| 64 | "Configure GSUP options") |
| 65 | { |
| 66 | vty->node = GSUP_NODE; |
| 67 | return CMD_SUCCESS; |
| 68 | } |
| 69 | |
| 70 | static int config_write_hlr(struct vty *vty) |
| 71 | { |
| 72 | vty_out(vty, "hlr%s", VTY_NEWLINE); |
| 73 | return CMD_SUCCESS; |
| 74 | } |
| 75 | |
| 76 | static 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 Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 84 | static 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 | |
| 98 | DEFUN(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 Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 111 | DEFUN(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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 125 | /*********************************************************************** |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 126 | * USSD Entity |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 127 | ***********************************************************************/ |
| 128 | |
| 129 | #include "hlr_ussd.h" |
| 130 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 131 | #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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 134 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 135 | #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 | |
| 143 | DEFUN(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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 149 | if (rt) { |
| 150 | vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE); |
| 151 | return CMD_WARNING; |
| 152 | } |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 153 | ussd_route_prefix_alloc_int(g_hlr, argv[0], iuse); |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 154 | |
| 155 | return CMD_SUCCESS; |
| 156 | } |
| 157 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 158 | DEFUN(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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 161 | { |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 162 | 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 | |
| 177 | DEFUN(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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 182 | if (!rt) { |
| 183 | vty_out(vty, "%% Cannot find route for prefix %s%s", argv[0], VTY_NEWLINE); |
| 184 | return CMD_WARNING; |
| 185 | } |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 186 | ussd_route_del(rt); |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 187 | |
| 188 | return CMD_SUCCESS; |
| 189 | } |
| 190 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 191 | DEFUN(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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 195 | { |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 196 | struct hlr_euse *euse = euse_find(g_hlr, argv[0]); |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 197 | |
| 198 | if (g_hlr->euse_default != euse) { |
| 199 | vty_out(vty, "Switching default route from %s to %s%s", |
Harald Welte | 55d32a1 | 2018-07-30 17:26:35 +0200 | [diff] [blame] | 200 | g_hlr->euse_default ? g_hlr->euse_default->name : "<none>", |
| 201 | euse->name, VTY_NEWLINE); |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 202 | g_hlr->euse_default = euse; |
| 203 | } |
| 204 | |
| 205 | return CMD_SUCCESS; |
| 206 | } |
| 207 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 208 | DEFUN(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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 211 | { |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 212 | g_hlr->euse_default = NULL; |
| 213 | |
| 214 | return CMD_SUCCESS; |
| 215 | } |
| 216 | |
| 217 | struct cmd_node euse_node = { |
| 218 | EUSE_NODE, |
| 219 | "%s(config-hlr-euse)# ", |
| 220 | 1, |
| 221 | }; |
| 222 | |
| 223 | DEFUN(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 | |
| 244 | DEFUN(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 | |
| 262 | static void dump_one_euse(struct vty *vty, struct hlr_euse *euse) |
| 263 | { |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 264 | vty_out(vty, " euse %s%s", euse->name, VTY_NEWLINE); |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static int config_write_euse(struct vty *vty) |
| 268 | { |
| 269 | struct hlr_euse *euse; |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 270 | struct hlr_ussd_route *rt; |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 271 | |
| 272 | llist_for_each_entry(euse, &g_hlr->euse_list, list) |
| 273 | dump_one_euse(vty, euse); |
| 274 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 275 | 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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | /*********************************************************************** |
| 289 | * Common Code |
| 290 | ***********************************************************************/ |
| 291 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 292 | int hlr_vty_go_parent(struct vty *vty) |
| 293 | { |
| 294 | switch (vty->node) { |
| 295 | case GSUP_NODE: |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 296 | case EUSE_NODE: |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 297 | vty->node = HLR_NODE; |
| 298 | vty->index = NULL; |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 299 | vty->index_sub = NULL; |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 300 | 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 Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 315 | int 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 Welte | d5807b8 | 2018-07-29 12:27:41 +0200 | [diff] [blame] | 327 | void hlr_vty_init(const struct log_info *cat) |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 328 | { |
| 329 | logging_vty_add_cmds(cat); |
Harald Welte | 7ee6e55 | 2018-02-14 00:52:05 +0100 | [diff] [blame] | 330 | osmo_talloc_vty_add_cmds(); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 331 | |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 332 | install_element_ve(&show_gsup_conn_cmd); |
| 333 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 334 | install_element(CONFIG_NODE, &cfg_hlr_cmd); |
| 335 | install_node(&hlr_node, config_write_hlr); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 336 | |
| 337 | install_element(HLR_NODE, &cfg_gsup_cmd); |
| 338 | install_node(&gsup_node, config_write_hlr_gsup); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 339 | |
| 340 | install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd); |
Neels Hofmeyr | 183e700 | 2017-10-06 02:59:54 +0200 | [diff] [blame] | 341 | |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 342 | 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 Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame^] | 345 | 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 Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 350 | |
Harald Welte | d5807b8 | 2018-07-29 12:27:41 +0200 | [diff] [blame] | 351 | hlr_vty_subscriber_init(); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 352 | } |