blob: ddea5780cf3035925f196540593ad408d5dae403 [file] [log] [blame]
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +02001/* 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 Hofmeyr926153b2016-08-18 02:15:56 +020023#include <osmocom/iuh/vty.h>
24
Neels Hofmeyrdf63de22016-08-18 13:13:55 +020025#include <osmocom/iuh/hnbgw.h>
26#include <osmocom/iuh/context_map.h>
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020027#include <osmocom/sigtran/protocol/sua.h>
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +020028
29static void *tall_hnb_ctx = NULL;
30static struct hnb_gw *g_hnb_gw = NULL;
31
Neels Hofmeyr926153b2016-08-18 02:15:56 +020032static struct cmd_node hnbgw_node = {
33 HNBGW_NODE,
34 "%s(config-hnbgw)# ",
35 1,
36};
37
38DEFUN(cfg_hnbgw, cfg_hnbgw_cmd,
39 "hnbgw", "Configure HNBGW options")
40{
41 vty->node = HNBGW_NODE;
42 return CMD_SUCCESS;
43}
44
45static struct cmd_node iuh_node = {
46 IUH_NODE,
47 "%s(config-hnbgw-iuh)# ",
48 1,
49};
50
51DEFUN(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 Hofmeyr5ee050c2016-10-13 15:12:18 +020058static struct cmd_node iucs_node = {
59 IUCS_NODE,
60 "%s(config-hnbgw-iucs)# ",
61 1,
62};
63
64DEFUN(cfg_hnbgw_iucs, cfg_hnbgw_iucs_cmd,
65 "iucs", "Configure IuCS options")
66{
67 vty->node = IUCS_NODE;
68 return CMD_SUCCESS;
69}
70
71static struct cmd_node iups_node = {
72 IUPS_NODE,
73 "%s(config-hnbgw-iups)# ",
74 1,
75};
76
77DEFUN(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 Hofmeyrc510fc22016-10-13 16:58:04 +020084int hnbgw_vty_go_parent(struct vty *vty)
85{
86 switch (vty->node) {
87 case IUH_NODE:
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020088 case IUCS_NODE:
89 case IUPS_NODE:
Neels Hofmeyrc510fc22016-10-13 16:58:04 +020090 vty->node = HNBGW_NODE;
91 vty->index = NULL;
92 break;
Neels Hofmeyrc510fc22016-10-13 16:58:04 +020093 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 Hofmeyrecbdc5c2017-07-31 13:13:24 +0200101 default:
102 osmo_ss7_vty_go_parent(vty);
103 break;
Neels Hofmeyrc510fc22016-10-13 16:58:04 +0200104 }
105
106 return vty->node;
107}
108
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200109static 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
125static 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
130DEFUN(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
141DEFUN(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
152DEFUN(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 Hofmeyr39ee9262016-09-26 01:07:19 +0200160DEFUN(cfg_hnbgw_iuh_local_ip, cfg_hnbgw_iuh_local_ip_cmd, "local-ip A.B.C.D",
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200161 "Accept Iuh connections on local interface\n"
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200162 "Local interface IP address (default: " HNBGW_LOCAL_IP_DEFAULT ")")
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200163{
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200164 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 Hofmeyrf495b232016-08-18 02:18:00 +0200166 return CMD_SUCCESS;
167}
168
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200169DEFUN(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 Hofmeyr12181a92016-04-25 15:05:32 +0200177DEFUN(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 Hofmeyrecbdc5c2017-07-31 13:13:24 +0200187DEFUN(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 Hofmeyr5ee050c2016-10-13 15:12:18 +0200192{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200193 g_hnb_gw->config.iucs_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200194 return CMD_SUCCESS;
195}
196
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200197DEFUN(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 Hofmeyr5ee050c2016-10-13 15:12:18 +0200202{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200203 g_hnb_gw->config.iups_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200204 return CMD_SUCCESS;
205}
206
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200207static int config_write_hnbgw(struct vty *vty)
208{
209 vty_out(vty, "hnbgw%s", VTY_NEWLINE);
210 return CMD_SUCCESS;
211}
212
213static int config_write_hnbgw_iuh(struct vty *vty)
214{
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200215 const char *addr;
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200216 uint16_t port;
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200217
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200218 vty_out(vty, " iuh%s", VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200219
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200220 addr = g_hnb_gw->config.iuh_local_ip;
221 if (addr && (strcmp(addr, HNBGW_LOCAL_IP_DEFAULT) != 0))
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200222 vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200223
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200224 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 Hofmeyr12181a92016-04-25 15:05:32 +0200228 if (g_hnb_gw->config.hnbap_allow_tmsi)
229 vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE);
230
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200231 return CMD_SUCCESS;
232}
233
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200234static int config_write_hnbgw_iucs(struct vty *vty)
235{
236 const char *addr;
237 uint16_t port;
238
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200239 if (!g_hnb_gw->config.iucs_remote_addr_name)
240 return CMD_SUCCESS;
241
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200242 vty_out(vty, " iucs%s", VTY_NEWLINE);
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200243 vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iucs_remote_addr_name,
244 VTY_NEWLINE);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200245
246 return CMD_SUCCESS;
247}
248
249static int config_write_hnbgw_iups(struct vty *vty)
250{
251 const char *addr;
252 uint16_t port;
253
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200254 if (!g_hnb_gw->config.iups_remote_addr_name)
255 return CMD_SUCCESS;
256
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200257 vty_out(vty, " iups%s", VTY_NEWLINE);
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200258 vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iups_remote_addr_name,
259 VTY_NEWLINE);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200260
261 return CMD_SUCCESS;
262}
263
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200264void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
265{
266 g_hnb_gw = gw;
267 tall_hnb_ctx = tall_ctx;
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200268
269 install_element(CONFIG_NODE, &cfg_hnbgw_cmd);
270 install_node(&hnbgw_node, config_write_hnbgw);
271 vty_install_default(HNBGW_NODE);
272
273 install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
274 install_node(&iuh_node, config_write_hnbgw_iuh);
275 vty_install_default(IUH_NODE);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200276
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200277 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_ip_cmd);
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200278 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_port_cmd);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200279 install_element(IUH_NODE, &cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200280
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200281 install_element(HNBGW_NODE, &cfg_hnbgw_iucs_cmd);
282 install_node(&iucs_node, config_write_hnbgw_iucs);
283 vty_install_default(IUCS_NODE);
284
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200285 install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_addr_cmd);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200286
287 install_element(HNBGW_NODE, &cfg_hnbgw_iups_cmd);
288 install_node(&iups_node, config_write_hnbgw_iups);
289 vty_install_default(IUPS_NODE);
290
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200291 install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_addr_cmd);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200292
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200293 install_element_ve(&show_hnb_cmd);
294 install_element_ve(&show_ue_cmd);
295 install_element_ve(&show_talloc_cmd);
296}