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