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 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | */ |
| 23 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 24 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 25 | #include <osmocom/vty/vty.h> |
| 26 | #include <osmocom/vty/command.h> |
| 27 | #include <osmocom/vty/logging.h> |
Harald Welte | 7ee6e55 | 2018-02-14 00:52:05 +0100 | [diff] [blame] | 28 | #include <osmocom/vty/misc.h> |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 29 | #include <osmocom/abis/ipa.h> |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 30 | |
| 31 | #include "hlr_vty.h" |
Neels Hofmeyr | 183e700 | 2017-10-06 02:59:54 +0200 | [diff] [blame] | 32 | #include "hlr_vty_subscr.h" |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 33 | #include "gsup_server.h" |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 34 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 35 | static struct hlr *g_hlr = NULL; |
| 36 | |
| 37 | struct cmd_node hlr_node = { |
| 38 | HLR_NODE, |
| 39 | "%s(config-hlr)# ", |
| 40 | 1, |
| 41 | }; |
| 42 | |
| 43 | DEFUN(cfg_hlr, |
| 44 | cfg_hlr_cmd, |
| 45 | "hlr", |
| 46 | "Configure the HLR") |
| 47 | { |
| 48 | vty->node = HLR_NODE; |
| 49 | return CMD_SUCCESS; |
| 50 | } |
| 51 | |
| 52 | struct cmd_node gsup_node = { |
| 53 | GSUP_NODE, |
| 54 | "%s(config-hlr-gsup)# ", |
| 55 | 1, |
| 56 | }; |
| 57 | |
| 58 | DEFUN(cfg_gsup, |
| 59 | cfg_gsup_cmd, |
| 60 | "gsup", |
| 61 | "Configure GSUP options") |
| 62 | { |
| 63 | vty->node = GSUP_NODE; |
| 64 | return CMD_SUCCESS; |
| 65 | } |
| 66 | |
| 67 | static int config_write_hlr(struct vty *vty) |
| 68 | { |
| 69 | vty_out(vty, "hlr%s", VTY_NEWLINE); |
| 70 | return CMD_SUCCESS; |
| 71 | } |
| 72 | |
| 73 | static int config_write_hlr_gsup(struct vty *vty) |
| 74 | { |
| 75 | vty_out(vty, " gsup%s", VTY_NEWLINE); |
| 76 | if (g_hlr->gsup_bind_addr) |
| 77 | vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE); |
| 78 | return CMD_SUCCESS; |
| 79 | } |
| 80 | |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 81 | static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn) |
| 82 | { |
| 83 | const struct ipa_server_conn *isc = conn->conn; |
| 84 | char *name; |
| 85 | int rc; |
| 86 | |
| 87 | rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR); |
| 88 | OSMO_ASSERT(rc); |
| 89 | |
| 90 | vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s", |
| 91 | name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind, |
| 92 | VTY_NEWLINE); |
| 93 | } |
| 94 | |
| 95 | DEFUN(show_gsup_conn, show_gsup_conn_cmd, |
| 96 | "show gsup-connections", |
| 97 | SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n") |
| 98 | { |
| 99 | struct osmo_gsup_server *gs = g_hlr->gs; |
| 100 | struct osmo_gsup_conn *conn; |
| 101 | |
| 102 | llist_for_each_entry(conn, &gs->clients, list) |
| 103 | show_one_conn(vty, conn); |
| 104 | |
| 105 | return CMD_SUCCESS; |
| 106 | } |
| 107 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 108 | DEFUN(cfg_hlr_gsup_bind_ip, |
| 109 | cfg_hlr_gsup_bind_ip_cmd, |
| 110 | "bind ip A.B.C.D", |
| 111 | "Listen/Bind related socket option\n" |
| 112 | IP_STR |
| 113 | "IPv4 Address to bind the GSUP interface to\n") |
| 114 | { |
| 115 | if(g_hlr->gsup_bind_addr) |
| 116 | talloc_free(g_hlr->gsup_bind_addr); |
| 117 | g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]); |
| 118 | |
| 119 | return CMD_SUCCESS; |
| 120 | } |
| 121 | |
| 122 | int hlr_vty_go_parent(struct vty *vty) |
| 123 | { |
| 124 | switch (vty->node) { |
| 125 | case GSUP_NODE: |
| 126 | vty->node = HLR_NODE; |
| 127 | vty->index = NULL; |
| 128 | break; |
| 129 | default: |
| 130 | case HLR_NODE: |
| 131 | vty->node = CONFIG_NODE; |
| 132 | vty->index = NULL; |
| 133 | break; |
| 134 | case CONFIG_NODE: |
| 135 | vty->node = ENABLE_NODE; |
| 136 | vty->index = NULL; |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | return vty->node; |
| 141 | } |
| 142 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 143 | int hlr_vty_is_config_node(struct vty *vty, int node) |
| 144 | { |
| 145 | switch (node) { |
| 146 | /* add items that are not config */ |
| 147 | case CONFIG_NODE: |
| 148 | return 0; |
| 149 | |
| 150 | default: |
| 151 | return 1; |
| 152 | } |
| 153 | } |
| 154 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 155 | void hlr_vty_init(struct hlr *hlr, const struct log_info *cat) |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 156 | { |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 157 | g_hlr = hlr; |
| 158 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 159 | logging_vty_add_cmds(cat); |
Harald Welte | 7ee6e55 | 2018-02-14 00:52:05 +0100 | [diff] [blame] | 160 | osmo_talloc_vty_add_cmds(); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 161 | |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 162 | install_element_ve(&show_gsup_conn_cmd); |
| 163 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 164 | install_element(CONFIG_NODE, &cfg_hlr_cmd); |
| 165 | install_node(&hlr_node, config_write_hlr); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 166 | |
| 167 | install_element(HLR_NODE, &cfg_gsup_cmd); |
| 168 | install_node(&gsup_node, config_write_hlr_gsup); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 169 | |
| 170 | install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd); |
Neels Hofmeyr | 183e700 | 2017-10-06 02:59:54 +0200 | [diff] [blame] | 171 | |
| 172 | hlr_vty_subscriber_init(hlr); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 173 | } |