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 | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 27 | |
| 28 | static void *tall_hnb_ctx = NULL; |
| 29 | static struct hnb_gw *g_hnb_gw = NULL; |
| 30 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 31 | static struct cmd_node hnbgw_node = { |
| 32 | HNBGW_NODE, |
| 33 | "%s(config-hnbgw)# ", |
| 34 | 1, |
| 35 | }; |
| 36 | |
| 37 | DEFUN(cfg_hnbgw, cfg_hnbgw_cmd, |
| 38 | "hnbgw", "Configure HNBGW options") |
| 39 | { |
| 40 | vty->node = HNBGW_NODE; |
| 41 | return CMD_SUCCESS; |
| 42 | } |
| 43 | |
| 44 | static struct cmd_node iuh_node = { |
| 45 | IUH_NODE, |
| 46 | "%s(config-hnbgw-iuh)# ", |
| 47 | 1, |
| 48 | }; |
| 49 | |
| 50 | DEFUN(cfg_hnbgw_iuh, cfg_hnbgw_iuh_cmd, |
| 51 | "iuh", "Configure Iuh options") |
| 52 | { |
| 53 | vty->node = IUH_NODE; |
| 54 | return CMD_SUCCESS; |
| 55 | } |
| 56 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 57 | static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb) |
| 58 | { |
| 59 | struct hnbgw_context_map *map; |
| 60 | |
| 61 | vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info, |
| 62 | hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid, |
| 63 | VTY_NEWLINE); |
| 64 | vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE); |
| 65 | |
| 66 | llist_for_each_entry(map, &hnb->map_list, hnb_list) { |
| 67 | vty_out(vty, " Map %u->%u (RUA->SUA) cnlink=%p state=%u%s", map->rua_ctx_id, map->scu_conn_id, |
| 68 | map->cn_link, map->state, VTY_NEWLINE); |
| 69 | |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue) |
| 74 | { |
| 75 | vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE); |
| 76 | } |
| 77 | |
| 78 | DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB") |
| 79 | { |
| 80 | struct hnb_context *hnb; |
| 81 | |
| 82 | llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) { |
| 83 | vty_dump_hnb_info(vty, hnb); |
| 84 | } |
| 85 | |
| 86 | return CMD_SUCCESS; |
| 87 | } |
| 88 | |
| 89 | DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE") |
| 90 | { |
| 91 | struct ue_context *ue; |
| 92 | |
| 93 | llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) { |
| 94 | vty_dump_ue_info(vty, ue); |
| 95 | } |
| 96 | |
| 97 | return CMD_SUCCESS; |
| 98 | } |
| 99 | |
| 100 | DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info") |
| 101 | { |
| 102 | talloc_report_full(tall_hnb_ctx, stderr); |
| 103 | talloc_report_full(talloc_asn1_ctx, stderr); |
| 104 | |
| 105 | return CMD_SUCCESS; |
| 106 | } |
| 107 | |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 108 | DEFUN(cfg_hnbgw_iuh_bind, cfg_hnbgw_iuh_bind_cmd, "bind A.B.C.D", |
| 109 | "Accept Iuh connections on local interface\n" |
| 110 | "Local interface IP address (default: " HNBGW_IUH_BIND_ADDR_DEFAULT ")") |
| 111 | { |
| 112 | talloc_free((void*)g_hnb_gw->config.iuh_bind_addr); |
| 113 | g_hnb_gw->config.iuh_bind_addr = talloc_strdup(tall_hnb_ctx, argv[0]); |
| 114 | return CMD_SUCCESS; |
| 115 | } |
| 116 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 117 | static int config_write_hnbgw(struct vty *vty) |
| 118 | { |
| 119 | vty_out(vty, "hnbgw%s", VTY_NEWLINE); |
| 120 | return CMD_SUCCESS; |
| 121 | } |
| 122 | |
| 123 | static int config_write_hnbgw_iuh(struct vty *vty) |
| 124 | { |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 125 | const char *addr; |
| 126 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 127 | vty_out(vty, " iuh%s", VTY_NEWLINE); |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 128 | |
| 129 | addr = g_hnb_gw->config.iuh_bind_addr; |
| 130 | if (addr && (strcmp(addr, HNBGW_IUH_BIND_ADDR_DEFAULT) != 0)) |
| 131 | vty_out(vty, " bind %s%s", addr, VTY_NEWLINE); |
| 132 | |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 133 | return CMD_SUCCESS; |
| 134 | } |
| 135 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 136 | void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx) |
| 137 | { |
| 138 | g_hnb_gw = gw; |
| 139 | tall_hnb_ctx = tall_ctx; |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 140 | |
| 141 | install_element(CONFIG_NODE, &cfg_hnbgw_cmd); |
| 142 | install_node(&hnbgw_node, config_write_hnbgw); |
| 143 | vty_install_default(HNBGW_NODE); |
| 144 | |
| 145 | install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd); |
| 146 | install_node(&iuh_node, config_write_hnbgw_iuh); |
| 147 | vty_install_default(IUH_NODE); |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 148 | install_element(IUH_NODE, &cfg_hnbgw_iuh_bind_cmd); |
Neels Hofmeyr | 926153b | 2016-08-18 02:15:56 +0200 | [diff] [blame] | 149 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 150 | install_element_ve(&show_hnb_cmd); |
| 151 | install_element_ve(&show_ue_cmd); |
| 152 | install_element_ve(&show_talloc_cmd); |
| 153 | } |