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 | struct cmd_node hlr_node = { |
| 36 | HLR_NODE, |
| 37 | "%s(config-hlr)# ", |
| 38 | 1, |
| 39 | }; |
| 40 | |
| 41 | DEFUN(cfg_hlr, |
| 42 | cfg_hlr_cmd, |
| 43 | "hlr", |
| 44 | "Configure the HLR") |
| 45 | { |
| 46 | vty->node = HLR_NODE; |
| 47 | return CMD_SUCCESS; |
| 48 | } |
| 49 | |
| 50 | struct cmd_node gsup_node = { |
| 51 | GSUP_NODE, |
| 52 | "%s(config-hlr-gsup)# ", |
| 53 | 1, |
| 54 | }; |
| 55 | |
| 56 | DEFUN(cfg_gsup, |
| 57 | cfg_gsup_cmd, |
| 58 | "gsup", |
| 59 | "Configure GSUP options") |
| 60 | { |
| 61 | vty->node = GSUP_NODE; |
| 62 | return CMD_SUCCESS; |
| 63 | } |
| 64 | |
| 65 | static int config_write_hlr(struct vty *vty) |
| 66 | { |
| 67 | vty_out(vty, "hlr%s", VTY_NEWLINE); |
| 68 | return CMD_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | static int config_write_hlr_gsup(struct vty *vty) |
| 72 | { |
| 73 | vty_out(vty, " gsup%s", VTY_NEWLINE); |
| 74 | if (g_hlr->gsup_bind_addr) |
| 75 | vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE); |
| 76 | return CMD_SUCCESS; |
| 77 | } |
| 78 | |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 79 | static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn) |
| 80 | { |
| 81 | const struct ipa_server_conn *isc = conn->conn; |
| 82 | char *name; |
| 83 | int rc; |
| 84 | |
| 85 | rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR); |
| 86 | OSMO_ASSERT(rc); |
| 87 | |
| 88 | vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s", |
| 89 | name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind, |
| 90 | VTY_NEWLINE); |
| 91 | } |
| 92 | |
| 93 | DEFUN(show_gsup_conn, show_gsup_conn_cmd, |
| 94 | "show gsup-connections", |
| 95 | SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n") |
| 96 | { |
| 97 | struct osmo_gsup_server *gs = g_hlr->gs; |
| 98 | struct osmo_gsup_conn *conn; |
| 99 | |
| 100 | llist_for_each_entry(conn, &gs->clients, list) |
| 101 | show_one_conn(vty, conn); |
| 102 | |
| 103 | return CMD_SUCCESS; |
| 104 | } |
| 105 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 106 | DEFUN(cfg_hlr_gsup_bind_ip, |
| 107 | cfg_hlr_gsup_bind_ip_cmd, |
| 108 | "bind ip A.B.C.D", |
| 109 | "Listen/Bind related socket option\n" |
| 110 | IP_STR |
| 111 | "IPv4 Address to bind the GSUP interface to\n") |
| 112 | { |
| 113 | if(g_hlr->gsup_bind_addr) |
| 114 | talloc_free(g_hlr->gsup_bind_addr); |
| 115 | g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]); |
| 116 | |
| 117 | return CMD_SUCCESS; |
| 118 | } |
| 119 | |
| 120 | int hlr_vty_go_parent(struct vty *vty) |
| 121 | { |
| 122 | switch (vty->node) { |
| 123 | case GSUP_NODE: |
| 124 | vty->node = HLR_NODE; |
| 125 | vty->index = NULL; |
| 126 | break; |
| 127 | default: |
| 128 | case HLR_NODE: |
| 129 | vty->node = CONFIG_NODE; |
| 130 | vty->index = NULL; |
| 131 | break; |
| 132 | case CONFIG_NODE: |
| 133 | vty->node = ENABLE_NODE; |
| 134 | vty->index = NULL; |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | return vty->node; |
| 139 | } |
| 140 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 141 | int hlr_vty_is_config_node(struct vty *vty, int node) |
| 142 | { |
| 143 | switch (node) { |
| 144 | /* add items that are not config */ |
| 145 | case CONFIG_NODE: |
| 146 | return 0; |
| 147 | |
| 148 | default: |
| 149 | return 1; |
| 150 | } |
| 151 | } |
| 152 | |
Harald Welte | d5807b8 | 2018-07-29 12:27:41 +0200 | [diff] [blame^] | 153 | void hlr_vty_init(const struct log_info *cat) |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 154 | { |
| 155 | logging_vty_add_cmds(cat); |
Harald Welte | 7ee6e55 | 2018-02-14 00:52:05 +0100 | [diff] [blame] | 156 | osmo_talloc_vty_add_cmds(); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 157 | |
Harald Welte | fa7ee33 | 2018-06-24 13:20:32 +0200 | [diff] [blame] | 158 | install_element_ve(&show_gsup_conn_cmd); |
| 159 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 160 | install_element(CONFIG_NODE, &cfg_hlr_cmd); |
| 161 | install_node(&hlr_node, config_write_hlr); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 162 | |
| 163 | install_element(HLR_NODE, &cfg_gsup_cmd); |
| 164 | install_node(&gsup_node, config_write_hlr_gsup); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 165 | |
| 166 | install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd); |
Neels Hofmeyr | 183e700 | 2017-10-06 02:59:54 +0200 | [diff] [blame] | 167 | |
Harald Welte | d5807b8 | 2018-07-29 12:27:41 +0200 | [diff] [blame^] | 168 | hlr_vty_subscriber_init(); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 169 | } |