blob: 59871dac36952c1d406b424df8d7aff3bf845e61 [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;
93 default:
94 case HNBGW_NODE:
95 vty->node = CONFIG_NODE;
96 vty->index = NULL;
97 break;
98 case CONFIG_NODE:
99 vty->node = ENABLE_NODE;
100 vty->index = NULL;
101 break;
102 }
103
104 return vty->node;
105}
106
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200107static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb)
108{
109 struct hnbgw_context_map *map;
110
111 vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info,
112 hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid,
113 VTY_NEWLINE);
114 vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE);
115
116 llist_for_each_entry(map, &hnb->map_list, hnb_list) {
117 vty_out(vty, " Map %u->%u (RUA->SUA) cnlink=%p state=%u%s", map->rua_ctx_id, map->scu_conn_id,
118 map->cn_link, map->state, VTY_NEWLINE);
119
120 }
121}
122
123static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue)
124{
125 vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE);
126}
127
128DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB")
129{
130 struct hnb_context *hnb;
131
132 llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) {
133 vty_dump_hnb_info(vty, hnb);
134 }
135
136 return CMD_SUCCESS;
137}
138
139DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE")
140{
141 struct ue_context *ue;
142
143 llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) {
144 vty_dump_ue_info(vty, ue);
145 }
146
147 return CMD_SUCCESS;
148}
149
150DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info")
151{
152 talloc_report_full(tall_hnb_ctx, stderr);
153 talloc_report_full(talloc_asn1_ctx, stderr);
154
155 return CMD_SUCCESS;
156}
157
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200158DEFUN(cfg_hnbgw_iuh_local_ip, cfg_hnbgw_iuh_local_ip_cmd, "local-ip A.B.C.D",
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200159 "Accept Iuh connections on local interface\n"
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200160 "Local interface IP address (default: " HNBGW_LOCAL_IP_DEFAULT ")")
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200161{
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200162 talloc_free((void*)g_hnb_gw->config.iuh_local_ip);
163 g_hnb_gw->config.iuh_local_ip = talloc_strdup(tall_hnb_ctx, argv[0]);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200164 return CMD_SUCCESS;
165}
166
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200167DEFUN(cfg_hnbgw_iuh_local_port, cfg_hnbgw_iuh_local_port_cmd, "local-port <1-65535>",
168 "Accept Iuh connections on local port\n"
169 "Local interface port (default: 29169)")
170{
171 g_hnb_gw->config.iuh_local_port = atoi(argv[0]);
172 return CMD_SUCCESS;
173}
174
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200175DEFUN(cfg_hnbgw_iuh_hnbap_allow_tmsi, cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd,
176 "hnbap-allow-tmsi (0|1)",
177 "Allow HNBAP UE Register messages with TMSI or PTMSI identity\n"
178 "Only accept IMSI identity, reject TMSI or PTMSI\n"
179 "Accept IMSI, TMSI or PTMSI as UE identity\n")
180{
181 g_hnb_gw->config.hnbap_allow_tmsi = (*argv[0] == '1');
182 return CMD_SUCCESS;
183}
184
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200185DEFUN(cfg_hnbgw_iucs_remote_ip, cfg_hnbgw_iucs_remote_ip_cmd, "remote-ip A.B.C.D",
186 "Address to establish IuCS core network link to\n"
187 "Remote IuCS IP address (default: " HNBGW_IUCS_REMOTE_IP_DEFAULT ")")
188{
189 talloc_free((void*)g_hnb_gw->config.iucs_remote_ip);
190 g_hnb_gw->config.iucs_remote_ip = talloc_strdup(tall_hnb_ctx, argv[0]);
191 return CMD_SUCCESS;
192}
193
194DEFUN(cfg_hnbgw_iucs_remote_port, cfg_hnbgw_iucs_remote_port_cmd, "remote-port <1-65535>",
195 "Remote port to establish IuCS core network link to\n"
196 "Remote IuCS port (default: 14001)")
197{
198 g_hnb_gw->config.iucs_remote_port = atoi(argv[0]);
199 return CMD_SUCCESS;
200}
201
202DEFUN(cfg_hnbgw_iups_remote_ip, cfg_hnbgw_iups_remote_ip_cmd, "remote-ip A.B.C.D",
203 "Address to establish IuPS core network link to\n"
204 "Remote IuPS IP address (default: " HNBGW_IUPS_REMOTE_IP_DEFAULT ")")
205{
206 talloc_free((void*)g_hnb_gw->config.iups_remote_ip);
207 g_hnb_gw->config.iups_remote_ip = talloc_strdup(tall_hnb_ctx, argv[0]);
208 return CMD_SUCCESS;
209}
210
211DEFUN(cfg_hnbgw_iups_remote_port, cfg_hnbgw_iups_remote_port_cmd, "remote-port <1-65535>",
212 "Remote port to establish IuPS core network link to\n"
213 "Remote IuPS port (default: 14001)")
214{
215 g_hnb_gw->config.iups_remote_port = atoi(argv[0]);
216 return CMD_SUCCESS;
217}
218
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200219static int config_write_hnbgw(struct vty *vty)
220{
221 vty_out(vty, "hnbgw%s", VTY_NEWLINE);
222 return CMD_SUCCESS;
223}
224
225static int config_write_hnbgw_iuh(struct vty *vty)
226{
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200227 const char *addr;
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200228 uint16_t port;
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200229
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200230 vty_out(vty, " iuh%s", VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200231
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200232 addr = g_hnb_gw->config.iuh_local_ip;
233 if (addr && (strcmp(addr, HNBGW_LOCAL_IP_DEFAULT) != 0))
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200234 vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200235
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200236 port = g_hnb_gw->config.iuh_local_port;
237 if (port && port != IUH_DEFAULT_SCTP_PORT)
238 vty_out(vty, " local-port %u%s", port, VTY_NEWLINE);
239
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200240 if (g_hnb_gw->config.hnbap_allow_tmsi)
241 vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE);
242
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200243 return CMD_SUCCESS;
244}
245
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200246static int config_write_hnbgw_iucs(struct vty *vty)
247{
248 const char *addr;
249 uint16_t port;
250
251 vty_out(vty, " iucs%s", VTY_NEWLINE);
252
253 addr = g_hnb_gw->config.iucs_remote_ip;
254 if (addr && (strcmp(addr, HNBGW_IUCS_REMOTE_IP_DEFAULT) != 0))
255 vty_out(vty, " remote-ip %s%s", addr, VTY_NEWLINE);
256
257 port = g_hnb_gw->config.iucs_remote_port;
258 if (port && port != SUA_PORT)
259 vty_out(vty, " remote-port %u%s", port, VTY_NEWLINE);
260
261 return CMD_SUCCESS;
262}
263
264static int config_write_hnbgw_iups(struct vty *vty)
265{
266 const char *addr;
267 uint16_t port;
268
269 vty_out(vty, " iups%s", VTY_NEWLINE);
270
271 addr = g_hnb_gw->config.iups_remote_ip;
272 if (addr && (strcmp(addr, HNBGW_IUPS_REMOTE_IP_DEFAULT) != 0))
273 vty_out(vty, " remote-ip %s%s", addr, VTY_NEWLINE);
274
275 port = g_hnb_gw->config.iups_remote_port;
276 if (port && port != SUA_PORT)
277 vty_out(vty, " remote-port %u%s", port, VTY_NEWLINE);
278
279 return CMD_SUCCESS;
280}
281
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200282void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
283{
284 g_hnb_gw = gw;
285 tall_hnb_ctx = tall_ctx;
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200286
287 install_element(CONFIG_NODE, &cfg_hnbgw_cmd);
288 install_node(&hnbgw_node, config_write_hnbgw);
289 vty_install_default(HNBGW_NODE);
290
291 install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
292 install_node(&iuh_node, config_write_hnbgw_iuh);
293 vty_install_default(IUH_NODE);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200294
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200295 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_ip_cmd);
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200296 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_port_cmd);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200297 install_element(IUH_NODE, &cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200298
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200299 install_element(HNBGW_NODE, &cfg_hnbgw_iucs_cmd);
300 install_node(&iucs_node, config_write_hnbgw_iucs);
301 vty_install_default(IUCS_NODE);
302
303 install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_ip_cmd);
304 install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_port_cmd);
305
306 install_element(HNBGW_NODE, &cfg_hnbgw_iups_cmd);
307 install_node(&iups_node, config_write_hnbgw_iups);
308 vty_install_default(IUPS_NODE);
309
310 install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_ip_cmd);
311 install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_port_cmd);
312
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200313 install_element_ve(&show_hnb_cmd);
314 install_element_ve(&show_ue_cmd);
315 install_element_ve(&show_talloc_cmd);
316}