Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 1 | /* HNB-GW interface to quagga VTY */ |
| 2 | |
| 3 | /* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <osmocom/vty/command.h> |
| 22 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 23 | #include <osmocom/iuh/vty.h> |
| 24 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 25 | #include <osmocom/iuh/hnbgw.h> |
| 26 | #include <osmocom/iuh/context_map.h> |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 27 | #include <osmocom/sigtran/protocol/sua.h> |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 28 | |
| 29 | static void *tall_hnb_ctx = NULL; |
| 30 | static struct hnb_gw *g_hnb_gw = NULL; |
| 31 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 32 | static struct cmd_node hnbgw_node = { |
| 33 | HNBGW_NODE, |
| 34 | "%s(config-hnbgw)# ", |
| 35 | 1, |
| 36 | }; |
| 37 | |
| 38 | DEFUN(cfg_hnbgw, cfg_hnbgw_cmd, |
| 39 | "hnbgw", "Configure HNBGW options") |
| 40 | { |
| 41 | vty->node = HNBGW_NODE; |
| 42 | return CMD_SUCCESS; |
| 43 | } |
| 44 | |
| 45 | static struct cmd_node iuh_node = { |
| 46 | IUH_NODE, |
| 47 | "%s(config-hnbgw-iuh)# ", |
| 48 | 1, |
| 49 | }; |
| 50 | |
| 51 | DEFUN(cfg_hnbgw_iuh, cfg_hnbgw_iuh_cmd, |
| 52 | "iuh", "Configure Iuh options") |
| 53 | { |
| 54 | vty->node = IUH_NODE; |
| 55 | return CMD_SUCCESS; |
| 56 | } |
| 57 | |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 58 | static struct cmd_node iucs_node = { |
| 59 | IUCS_NODE, |
| 60 | "%s(config-hnbgw-iucs)# ", |
| 61 | 1, |
| 62 | }; |
| 63 | |
| 64 | DEFUN(cfg_hnbgw_iucs, cfg_hnbgw_iucs_cmd, |
| 65 | "iucs", "Configure IuCS options") |
| 66 | { |
| 67 | vty->node = IUCS_NODE; |
| 68 | return CMD_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | static struct cmd_node iups_node = { |
| 72 | IUPS_NODE, |
| 73 | "%s(config-hnbgw-iups)# ", |
| 74 | 1, |
| 75 | }; |
| 76 | |
| 77 | DEFUN(cfg_hnbgw_iups, cfg_hnbgw_iups_cmd, |
| 78 | "iups", "Configure IuPS options") |
| 79 | { |
| 80 | vty->node = IUPS_NODE; |
| 81 | return CMD_SUCCESS; |
| 82 | } |
| 83 | |
Neels Hofmeyr | c510fc2 | 2016-10-13 16:58:04 +0200 | [diff] [blame] | 84 | int hnbgw_vty_go_parent(struct vty *vty) |
| 85 | { |
| 86 | switch (vty->node) { |
| 87 | case IUH_NODE: |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 88 | case IUCS_NODE: |
| 89 | case IUPS_NODE: |
Neels Hofmeyr | c510fc2 | 2016-10-13 16:58:04 +0200 | [diff] [blame] | 90 | vty->node = HNBGW_NODE; |
| 91 | vty->index = NULL; |
| 92 | break; |
Neels Hofmeyr | c510fc2 | 2016-10-13 16:58:04 +0200 | [diff] [blame] | 93 | case HNBGW_NODE: |
| 94 | vty->node = CONFIG_NODE; |
| 95 | vty->index = NULL; |
| 96 | break; |
| 97 | case CONFIG_NODE: |
| 98 | vty->node = ENABLE_NODE; |
| 99 | vty->index = NULL; |
| 100 | break; |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 101 | default: |
| 102 | osmo_ss7_vty_go_parent(vty); |
| 103 | break; |
Neels Hofmeyr | c510fc2 | 2016-10-13 16:58:04 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | return vty->node; |
| 107 | } |
| 108 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 109 | static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb) |
| 110 | { |
| 111 | struct hnbgw_context_map *map; |
| 112 | |
| 113 | vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info, |
| 114 | hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid, |
| 115 | VTY_NEWLINE); |
| 116 | vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE); |
| 117 | |
| 118 | llist_for_each_entry(map, &hnb->map_list, hnb_list) { |
| 119 | vty_out(vty, " Map %u->%u (RUA->SUA) cnlink=%p state=%u%s", map->rua_ctx_id, map->scu_conn_id, |
| 120 | map->cn_link, map->state, VTY_NEWLINE); |
| 121 | |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue) |
| 126 | { |
| 127 | vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE); |
| 128 | } |
| 129 | |
| 130 | DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB") |
| 131 | { |
| 132 | struct hnb_context *hnb; |
| 133 | |
| 134 | llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) { |
| 135 | vty_dump_hnb_info(vty, hnb); |
| 136 | } |
| 137 | |
| 138 | return CMD_SUCCESS; |
| 139 | } |
| 140 | |
| 141 | DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE") |
| 142 | { |
| 143 | struct ue_context *ue; |
| 144 | |
| 145 | llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) { |
| 146 | vty_dump_ue_info(vty, ue); |
| 147 | } |
| 148 | |
| 149 | return CMD_SUCCESS; |
| 150 | } |
| 151 | |
| 152 | DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info") |
| 153 | { |
| 154 | talloc_report_full(tall_hnb_ctx, stderr); |
| 155 | talloc_report_full(talloc_asn1_ctx, stderr); |
| 156 | |
| 157 | return CMD_SUCCESS; |
| 158 | } |
| 159 | |
Neels Hofmeyr | 39ee926 | 2016-09-26 01:07:19 +0200 | [diff] [blame] | 160 | DEFUN(cfg_hnbgw_iuh_local_ip, cfg_hnbgw_iuh_local_ip_cmd, "local-ip A.B.C.D", |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 161 | "Accept Iuh connections on local interface\n" |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 162 | "Local interface IP address (default: " HNBGW_LOCAL_IP_DEFAULT ")") |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 163 | { |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 164 | talloc_free((void*)g_hnb_gw->config.iuh_local_ip); |
| 165 | g_hnb_gw->config.iuh_local_ip = talloc_strdup(tall_hnb_ctx, argv[0]); |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 166 | return CMD_SUCCESS; |
| 167 | } |
| 168 | |
Neels Hofmeyr | 9153de6 | 2016-10-13 15:11:07 +0200 | [diff] [blame] | 169 | DEFUN(cfg_hnbgw_iuh_local_port, cfg_hnbgw_iuh_local_port_cmd, "local-port <1-65535>", |
| 170 | "Accept Iuh connections on local port\n" |
| 171 | "Local interface port (default: 29169)") |
| 172 | { |
| 173 | g_hnb_gw->config.iuh_local_port = atoi(argv[0]); |
| 174 | return CMD_SUCCESS; |
| 175 | } |
| 176 | |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 177 | DEFUN(cfg_hnbgw_iuh_hnbap_allow_tmsi, cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd, |
| 178 | "hnbap-allow-tmsi (0|1)", |
| 179 | "Allow HNBAP UE Register messages with TMSI or PTMSI identity\n" |
| 180 | "Only accept IMSI identity, reject TMSI or PTMSI\n" |
| 181 | "Accept IMSI, TMSI or PTMSI as UE identity\n") |
| 182 | { |
| 183 | g_hnb_gw->config.hnbap_allow_tmsi = (*argv[0] == '1'); |
| 184 | return CMD_SUCCESS; |
| 185 | } |
| 186 | |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 187 | DEFUN(cfg_hnbgw_iucs_remote_addr, |
| 188 | cfg_hnbgw_iucs_remote_addr_cmd, |
| 189 | "remote-addr NAME", |
| 190 | "SCCP address to send IuCS to (MSC)\n" |
| 191 | "SCCP address book entry name (see 'cs7-instance')\n") |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 192 | { |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 193 | g_hnb_gw->config.iucs_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 194 | return CMD_SUCCESS; |
| 195 | } |
| 196 | |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 197 | DEFUN(cfg_hnbgw_iups_remote_addr, |
| 198 | cfg_hnbgw_iups_remote_addr_cmd, |
| 199 | "remote-addr NAME", |
| 200 | "SCCP address to send IuPS to (SGSN)\n" |
| 201 | "SCCP address book entry name (see 'cs7-instance')\n") |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 202 | { |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 203 | g_hnb_gw->config.iups_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 204 | return CMD_SUCCESS; |
| 205 | } |
| 206 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 207 | static int config_write_hnbgw(struct vty *vty) |
| 208 | { |
| 209 | vty_out(vty, "hnbgw%s", VTY_NEWLINE); |
| 210 | return CMD_SUCCESS; |
| 211 | } |
| 212 | |
| 213 | static int config_write_hnbgw_iuh(struct vty *vty) |
| 214 | { |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 215 | const char *addr; |
Neels Hofmeyr | 9153de6 | 2016-10-13 15:11:07 +0200 | [diff] [blame] | 216 | uint16_t port; |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 217 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 218 | vty_out(vty, " iuh%s", VTY_NEWLINE); |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 219 | |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 220 | addr = g_hnb_gw->config.iuh_local_ip; |
| 221 | if (addr && (strcmp(addr, HNBGW_LOCAL_IP_DEFAULT) != 0)) |
Neels Hofmeyr | 39ee926 | 2016-09-26 01:07:19 +0200 | [diff] [blame] | 222 | vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE); |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 223 | |
Neels Hofmeyr | 9153de6 | 2016-10-13 15:11:07 +0200 | [diff] [blame] | 224 | port = g_hnb_gw->config.iuh_local_port; |
| 225 | if (port && port != IUH_DEFAULT_SCTP_PORT) |
| 226 | vty_out(vty, " local-port %u%s", port, VTY_NEWLINE); |
| 227 | |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 228 | if (g_hnb_gw->config.hnbap_allow_tmsi) |
| 229 | vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE); |
| 230 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 231 | return CMD_SUCCESS; |
| 232 | } |
| 233 | |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 234 | static int config_write_hnbgw_iucs(struct vty *vty) |
| 235 | { |
| 236 | const char *addr; |
| 237 | uint16_t port; |
| 238 | |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 239 | if (!g_hnb_gw->config.iucs_remote_addr_name) |
| 240 | return CMD_SUCCESS; |
| 241 | |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 242 | vty_out(vty, " iucs%s", VTY_NEWLINE); |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 243 | vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iucs_remote_addr_name, |
| 244 | VTY_NEWLINE); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 245 | |
| 246 | return CMD_SUCCESS; |
| 247 | } |
| 248 | |
| 249 | static int config_write_hnbgw_iups(struct vty *vty) |
| 250 | { |
| 251 | const char *addr; |
| 252 | uint16_t port; |
| 253 | |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 254 | if (!g_hnb_gw->config.iups_remote_addr_name) |
| 255 | return CMD_SUCCESS; |
| 256 | |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 257 | vty_out(vty, " iups%s", VTY_NEWLINE); |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 258 | vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iups_remote_addr_name, |
| 259 | VTY_NEWLINE); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 260 | |
| 261 | return CMD_SUCCESS; |
| 262 | } |
| 263 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 264 | void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx) |
| 265 | { |
| 266 | g_hnb_gw = gw; |
| 267 | tall_hnb_ctx = tall_ctx; |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 268 | |
| 269 | install_element(CONFIG_NODE, &cfg_hnbgw_cmd); |
| 270 | install_node(&hnbgw_node, config_write_hnbgw); |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 271 | |
| 272 | install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd); |
| 273 | install_node(&iuh_node, config_write_hnbgw_iuh); |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 274 | |
Neels Hofmeyr | 39ee926 | 2016-09-26 01:07:19 +0200 | [diff] [blame] | 275 | install_element(IUH_NODE, &cfg_hnbgw_iuh_local_ip_cmd); |
Neels Hofmeyr | 9153de6 | 2016-10-13 15:11:07 +0200 | [diff] [blame] | 276 | install_element(IUH_NODE, &cfg_hnbgw_iuh_local_port_cmd); |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 277 | install_element(IUH_NODE, &cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd); |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 278 | |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 279 | install_element(HNBGW_NODE, &cfg_hnbgw_iucs_cmd); |
| 280 | install_node(&iucs_node, config_write_hnbgw_iucs); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 281 | |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 282 | install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_addr_cmd); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 283 | |
| 284 | install_element(HNBGW_NODE, &cfg_hnbgw_iups_cmd); |
| 285 | install_node(&iups_node, config_write_hnbgw_iups); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 286 | |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 287 | install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_addr_cmd); |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 288 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 289 | install_element_ve(&show_hnb_cmd); |
| 290 | install_element_ve(&show_ue_cmd); |
| 291 | install_element_ve(&show_talloc_cmd); |
| 292 | } |