blob: d50c4a5e78ddd5903a42728eba7f2e4fb4cd76da [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
Harald Welteda86fe52017-11-21 08:14:37 +010021#include <string.h>
22
Neels Hofmeyr140f38c2017-12-20 23:48:02 +010023#include <osmocom/core/socket.h>
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +020024#include <osmocom/vty/command.h>
25
Neels Hofmeyr926153b2016-08-18 02:15:56 +020026#include <osmocom/iuh/vty.h>
27
Neels Hofmeyrdf63de22016-08-18 13:13:55 +020028#include <osmocom/iuh/hnbgw.h>
29#include <osmocom/iuh/context_map.h>
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020030#include <osmocom/sigtran/protocol/sua.h>
Neels Hofmeyr140f38c2017-12-20 23:48:02 +010031#include <osmocom/sigtran/sccp_helpers.h>
32#include <osmocom/netif/stream.h>
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +020033
34static void *tall_hnb_ctx = NULL;
35static struct hnb_gw *g_hnb_gw = NULL;
36
Neels Hofmeyr926153b2016-08-18 02:15:56 +020037static struct cmd_node hnbgw_node = {
38 HNBGW_NODE,
39 "%s(config-hnbgw)# ",
40 1,
41};
42
43DEFUN(cfg_hnbgw, cfg_hnbgw_cmd,
44 "hnbgw", "Configure HNBGW options")
45{
46 vty->node = HNBGW_NODE;
47 return CMD_SUCCESS;
48}
49
50static struct cmd_node iuh_node = {
51 IUH_NODE,
52 "%s(config-hnbgw-iuh)# ",
53 1,
54};
55
56DEFUN(cfg_hnbgw_iuh, cfg_hnbgw_iuh_cmd,
57 "iuh", "Configure Iuh options")
58{
59 vty->node = IUH_NODE;
60 return CMD_SUCCESS;
61}
62
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020063static struct cmd_node iucs_node = {
64 IUCS_NODE,
65 "%s(config-hnbgw-iucs)# ",
66 1,
67};
68
69DEFUN(cfg_hnbgw_iucs, cfg_hnbgw_iucs_cmd,
70 "iucs", "Configure IuCS options")
71{
72 vty->node = IUCS_NODE;
73 return CMD_SUCCESS;
74}
75
76static struct cmd_node iups_node = {
77 IUPS_NODE,
78 "%s(config-hnbgw-iups)# ",
79 1,
80};
81
82DEFUN(cfg_hnbgw_iups, cfg_hnbgw_iups_cmd,
83 "iups", "Configure IuPS options")
84{
85 vty->node = IUPS_NODE;
86 return CMD_SUCCESS;
87}
88
Neels Hofmeyrc510fc22016-10-13 16:58:04 +020089int hnbgw_vty_go_parent(struct vty *vty)
90{
91 switch (vty->node) {
92 case IUH_NODE:
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020093 case IUCS_NODE:
94 case IUPS_NODE:
Neels Hofmeyrc510fc22016-10-13 16:58:04 +020095 vty->node = HNBGW_NODE;
96 vty->index = NULL;
97 break;
Neels Hofmeyrc510fc22016-10-13 16:58:04 +020098 case HNBGW_NODE:
99 vty->node = CONFIG_NODE;
100 vty->index = NULL;
101 break;
102 case CONFIG_NODE:
103 vty->node = ENABLE_NODE;
104 vty->index = NULL;
105 break;
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200106 default:
107 osmo_ss7_vty_go_parent(vty);
108 break;
Neels Hofmeyrc510fc22016-10-13 16:58:04 +0200109 }
110
111 return vty->node;
112}
113
Neels Hofmeyr140f38c2017-12-20 23:48:02 +0100114DEFUN(show_cnlink, show_cnlink_cmd, "show cnlink",
115 SHOW_STR "Display information on core network link\n")
116{
117 struct osmo_ss7_route *rt;
118 struct osmo_ss7_instance *ss7 = osmo_sccp_get_ss7(g_hnb_gw->sccp.client);
119 int i;
120#define GUARD(STR) \
121 STR ? STR : "", \
122 STR ? ":" : ""
123
124 vty_out(vty, "IuCS: %s <->",
125 osmo_sccp_user_name(g_hnb_gw->sccp.cnlink->sccp_user));
126 vty_out(vty, " %s%s%s%s",
127 GUARD(g_hnb_gw->config.iucs_remote_addr_name),
128 osmo_sccp_inst_addr_name(g_hnb_gw->sccp.client, &g_hnb_gw->sccp.iucs_remote_addr),
129 VTY_NEWLINE);
130
131 rt = osmo_ss7_route_lookup(ss7, g_hnb_gw->sccp.iucs_remote_addr.pc);
132 vty_out(vty, " SS7 route: %s%s", osmo_ss7_route_name(rt, true), VTY_NEWLINE);
133
134 vty_out(vty, "IuPS: %s <->",
135 osmo_sccp_user_name(g_hnb_gw->sccp.cnlink->sccp_user));
136 vty_out(vty, " %s%s%s%s",
137 GUARD(g_hnb_gw->config.iups_remote_addr_name),
138 osmo_sccp_inst_addr_name(g_hnb_gw->sccp.client, &g_hnb_gw->sccp.iups_remote_addr),
139 VTY_NEWLINE);
140
141 rt = osmo_ss7_route_lookup(ss7, g_hnb_gw->sccp.iups_remote_addr.pc);
142 vty_out(vty, " SS7 route: %s%s", osmo_ss7_route_name(rt, true), VTY_NEWLINE);
143
144#undef GUARD
145 return CMD_SUCCESS;
146}
147
148static void vty_out_ofd_addr(struct vty *vty, struct osmo_fd *ofd)
149{
150 char *name;
151 if (!ofd || ofd->fd < 0
152 || !(name = osmo_sock_get_name(vty, ofd->fd))) {
153 vty_out(vty, "(no addr)");
154 return;
155 }
156 vty_out(vty, name);
157 talloc_free(name);
158}
159
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200160static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb)
161{
162 struct hnbgw_context_map *map;
163
Neels Hofmeyr140f38c2017-12-20 23:48:02 +0100164 vty_out(vty, "HNB ");
165 vty_out_ofd_addr(vty, hnb->conn? osmo_stream_srv_get_ofd(hnb->conn) : NULL);
166 vty_out(vty, " \"%s\"%s", hnb->identity_info, VTY_NEWLINE);
167 vty_out(vty, " MCC %u MNC %u LAC %u RAC %u SAC %u CID %u SCCP-stream:HNBAP=%u,RUA=%u%s",
168 hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid,
169 hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE);
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200170
171 llist_for_each_entry(map, &hnb->map_list, hnb_list) {
Neels Hofmeyr140f38c2017-12-20 23:48:02 +0100172 vty_out(vty, " %s %u->%u (RUA->SUA) state=%u%s",
173 map->is_ps ? "IuPS" : "IuCS",
174 map->rua_ctx_id, map->scu_conn_id,
175 map->state, VTY_NEWLINE);
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200176 }
177}
178
179static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue)
180{
181 vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE);
182}
183
184DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB")
185{
186 struct hnb_context *hnb;
187
Neels Hofmeyr140f38c2017-12-20 23:48:02 +0100188 if (llist_empty(&g_hnb_gw->hnb_list)) {
189 vty_out(vty, "No HNB connected%s", VTY_NEWLINE);
190 return CMD_SUCCESS;
191 }
192
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200193 llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) {
194 vty_dump_hnb_info(vty, hnb);
195 }
196
197 return CMD_SUCCESS;
198}
199
200DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE")
201{
202 struct ue_context *ue;
203
204 llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) {
205 vty_dump_ue_info(vty, ue);
206 }
207
208 return CMD_SUCCESS;
209}
210
211DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info")
212{
213 talloc_report_full(tall_hnb_ctx, stderr);
214 talloc_report_full(talloc_asn1_ctx, stderr);
215
216 return CMD_SUCCESS;
217}
218
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200219DEFUN(cfg_hnbgw_iuh_local_ip, cfg_hnbgw_iuh_local_ip_cmd, "local-ip A.B.C.D",
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200220 "Accept Iuh connections on local interface\n"
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200221 "Local interface IP address (default: " HNBGW_LOCAL_IP_DEFAULT ")")
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200222{
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200223 talloc_free((void*)g_hnb_gw->config.iuh_local_ip);
224 g_hnb_gw->config.iuh_local_ip = talloc_strdup(tall_hnb_ctx, argv[0]);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200225 return CMD_SUCCESS;
226}
227
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200228DEFUN(cfg_hnbgw_iuh_local_port, cfg_hnbgw_iuh_local_port_cmd, "local-port <1-65535>",
229 "Accept Iuh connections on local port\n"
230 "Local interface port (default: 29169)")
231{
232 g_hnb_gw->config.iuh_local_port = atoi(argv[0]);
233 return CMD_SUCCESS;
234}
235
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200236DEFUN(cfg_hnbgw_iuh_hnbap_allow_tmsi, cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd,
237 "hnbap-allow-tmsi (0|1)",
238 "Allow HNBAP UE Register messages with TMSI or PTMSI identity\n"
239 "Only accept IMSI identity, reject TMSI or PTMSI\n"
240 "Accept IMSI, TMSI or PTMSI as UE identity\n")
241{
242 g_hnb_gw->config.hnbap_allow_tmsi = (*argv[0] == '1');
243 return CMD_SUCCESS;
244}
245
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200246DEFUN(cfg_hnbgw_iucs_remote_addr,
247 cfg_hnbgw_iucs_remote_addr_cmd,
248 "remote-addr NAME",
249 "SCCP address to send IuCS to (MSC)\n"
250 "SCCP address book entry name (see 'cs7-instance')\n")
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200251{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200252 g_hnb_gw->config.iucs_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200253 return CMD_SUCCESS;
254}
255
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200256DEFUN(cfg_hnbgw_iups_remote_addr,
257 cfg_hnbgw_iups_remote_addr_cmd,
258 "remote-addr NAME",
259 "SCCP address to send IuPS to (SGSN)\n"
260 "SCCP address book entry name (see 'cs7-instance')\n")
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200261{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200262 g_hnb_gw->config.iups_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200263 return CMD_SUCCESS;
264}
265
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200266static int config_write_hnbgw(struct vty *vty)
267{
268 vty_out(vty, "hnbgw%s", VTY_NEWLINE);
269 return CMD_SUCCESS;
270}
271
272static int config_write_hnbgw_iuh(struct vty *vty)
273{
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200274 const char *addr;
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200275 uint16_t port;
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200276
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200277 vty_out(vty, " iuh%s", VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200278
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200279 addr = g_hnb_gw->config.iuh_local_ip;
280 if (addr && (strcmp(addr, HNBGW_LOCAL_IP_DEFAULT) != 0))
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200281 vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200282
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200283 port = g_hnb_gw->config.iuh_local_port;
284 if (port && port != IUH_DEFAULT_SCTP_PORT)
285 vty_out(vty, " local-port %u%s", port, VTY_NEWLINE);
286
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200287 if (g_hnb_gw->config.hnbap_allow_tmsi)
288 vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE);
289
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200290 return CMD_SUCCESS;
291}
292
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200293static int config_write_hnbgw_iucs(struct vty *vty)
294{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200295 if (!g_hnb_gw->config.iucs_remote_addr_name)
296 return CMD_SUCCESS;
297
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200298 vty_out(vty, " iucs%s", VTY_NEWLINE);
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200299 vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iucs_remote_addr_name,
300 VTY_NEWLINE);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200301
302 return CMD_SUCCESS;
303}
304
305static int config_write_hnbgw_iups(struct vty *vty)
306{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200307 if (!g_hnb_gw->config.iups_remote_addr_name)
308 return CMD_SUCCESS;
309
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200310 vty_out(vty, " iups%s", VTY_NEWLINE);
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200311 vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iups_remote_addr_name,
312 VTY_NEWLINE);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200313
314 return CMD_SUCCESS;
315}
316
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200317void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
318{
319 g_hnb_gw = gw;
320 tall_hnb_ctx = tall_ctx;
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200321
322 install_element(CONFIG_NODE, &cfg_hnbgw_cmd);
323 install_node(&hnbgw_node, config_write_hnbgw);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200324
325 install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
326 install_node(&iuh_node, config_write_hnbgw_iuh);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200327
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200328 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_ip_cmd);
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200329 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_port_cmd);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200330 install_element(IUH_NODE, &cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200331
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200332 install_element(HNBGW_NODE, &cfg_hnbgw_iucs_cmd);
333 install_node(&iucs_node, config_write_hnbgw_iucs);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200334
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200335 install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_addr_cmd);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200336
337 install_element(HNBGW_NODE, &cfg_hnbgw_iups_cmd);
338 install_node(&iups_node, config_write_hnbgw_iups);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200339
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200340 install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_addr_cmd);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200341
Neels Hofmeyr140f38c2017-12-20 23:48:02 +0100342 install_element_ve(&show_cnlink_cmd);
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200343 install_element_ve(&show_hnb_cmd);
344 install_element_ve(&show_ue_cmd);
345 install_element_ve(&show_talloc_cmd);
346}