blob: 3d169707f298cf371dd98499fbeb5e8eb3be0688 [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 Hofmeyr4d8eb4c2016-08-18 01:03:44 +020023#include <osmocom/vty/command.h>
24
Neels Hofmeyr926153b2016-08-18 02:15:56 +020025#include <osmocom/iuh/vty.h>
26
Neels Hofmeyrdf63de22016-08-18 13:13:55 +020027#include <osmocom/iuh/hnbgw.h>
28#include <osmocom/iuh/context_map.h>
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020029#include <osmocom/sigtran/protocol/sua.h>
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +020030
31static void *tall_hnb_ctx = NULL;
32static struct hnb_gw *g_hnb_gw = NULL;
33
Neels Hofmeyr926153b2016-08-18 02:15:56 +020034static struct cmd_node hnbgw_node = {
35 HNBGW_NODE,
36 "%s(config-hnbgw)# ",
37 1,
38};
39
40DEFUN(cfg_hnbgw, cfg_hnbgw_cmd,
41 "hnbgw", "Configure HNBGW options")
42{
43 vty->node = HNBGW_NODE;
44 return CMD_SUCCESS;
45}
46
47static struct cmd_node iuh_node = {
48 IUH_NODE,
49 "%s(config-hnbgw-iuh)# ",
50 1,
51};
52
53DEFUN(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 Hofmeyr5ee050c2016-10-13 15:12:18 +020060static struct cmd_node iucs_node = {
61 IUCS_NODE,
62 "%s(config-hnbgw-iucs)# ",
63 1,
64};
65
66DEFUN(cfg_hnbgw_iucs, cfg_hnbgw_iucs_cmd,
67 "iucs", "Configure IuCS options")
68{
69 vty->node = IUCS_NODE;
70 return CMD_SUCCESS;
71}
72
73static struct cmd_node iups_node = {
74 IUPS_NODE,
75 "%s(config-hnbgw-iups)# ",
76 1,
77};
78
79DEFUN(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 Hofmeyrc510fc22016-10-13 16:58:04 +020086int hnbgw_vty_go_parent(struct vty *vty)
87{
88 switch (vty->node) {
89 case IUH_NODE:
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020090 case IUCS_NODE:
91 case IUPS_NODE:
Neels Hofmeyrc510fc22016-10-13 16:58:04 +020092 vty->node = HNBGW_NODE;
93 vty->index = NULL;
94 break;
Neels Hofmeyrc510fc22016-10-13 16:58:04 +020095 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 Hofmeyrecbdc5c2017-07-31 13:13:24 +0200103 default:
104 osmo_ss7_vty_go_parent(vty);
105 break;
Neels Hofmeyrc510fc22016-10-13 16:58:04 +0200106 }
107
108 return vty->node;
109}
110
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200111static 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
127static 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
132DEFUN(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
143DEFUN(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
154DEFUN(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 Hofmeyr39ee9262016-09-26 01:07:19 +0200162DEFUN(cfg_hnbgw_iuh_local_ip, cfg_hnbgw_iuh_local_ip_cmd, "local-ip A.B.C.D",
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200163 "Accept Iuh connections on local interface\n"
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200164 "Local interface IP address (default: " HNBGW_LOCAL_IP_DEFAULT ")")
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200165{
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200166 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 Hofmeyrf495b232016-08-18 02:18:00 +0200168 return CMD_SUCCESS;
169}
170
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200171DEFUN(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 Hofmeyr12181a92016-04-25 15:05:32 +0200179DEFUN(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 Hofmeyrecbdc5c2017-07-31 13:13:24 +0200189DEFUN(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 Hofmeyr5ee050c2016-10-13 15:12:18 +0200194{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200195 g_hnb_gw->config.iucs_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200196 return CMD_SUCCESS;
197}
198
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200199DEFUN(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 Hofmeyr5ee050c2016-10-13 15:12:18 +0200204{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200205 g_hnb_gw->config.iups_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200206 return CMD_SUCCESS;
207}
208
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200209static int config_write_hnbgw(struct vty *vty)
210{
211 vty_out(vty, "hnbgw%s", VTY_NEWLINE);
212 return CMD_SUCCESS;
213}
214
215static int config_write_hnbgw_iuh(struct vty *vty)
216{
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200217 const char *addr;
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200218 uint16_t port;
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200219
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200220 vty_out(vty, " iuh%s", VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200221
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200222 addr = g_hnb_gw->config.iuh_local_ip;
223 if (addr && (strcmp(addr, HNBGW_LOCAL_IP_DEFAULT) != 0))
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200224 vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200225
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200226 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 Hofmeyr12181a92016-04-25 15:05:32 +0200230 if (g_hnb_gw->config.hnbap_allow_tmsi)
231 vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE);
232
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200233 return CMD_SUCCESS;
234}
235
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200236static int config_write_hnbgw_iucs(struct vty *vty)
237{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200238 if (!g_hnb_gw->config.iucs_remote_addr_name)
239 return CMD_SUCCESS;
240
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200241 vty_out(vty, " iucs%s", VTY_NEWLINE);
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200242 vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iucs_remote_addr_name,
243 VTY_NEWLINE);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200244
245 return CMD_SUCCESS;
246}
247
248static int config_write_hnbgw_iups(struct vty *vty)
249{
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200250 if (!g_hnb_gw->config.iups_remote_addr_name)
251 return CMD_SUCCESS;
252
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200253 vty_out(vty, " iups%s", VTY_NEWLINE);
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200254 vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iups_remote_addr_name,
255 VTY_NEWLINE);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200256
257 return CMD_SUCCESS;
258}
259
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200260void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
261{
262 g_hnb_gw = gw;
263 tall_hnb_ctx = tall_ctx;
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200264
265 install_element(CONFIG_NODE, &cfg_hnbgw_cmd);
266 install_node(&hnbgw_node, config_write_hnbgw);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200267
268 install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
269 install_node(&iuh_node, config_write_hnbgw_iuh);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200270
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200271 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_ip_cmd);
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200272 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_port_cmd);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200273 install_element(IUH_NODE, &cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200274
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200275 install_element(HNBGW_NODE, &cfg_hnbgw_iucs_cmd);
276 install_node(&iucs_node, config_write_hnbgw_iucs);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200277
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200278 install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_addr_cmd);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200279
280 install_element(HNBGW_NODE, &cfg_hnbgw_iups_cmd);
281 install_node(&iups_node, config_write_hnbgw_iups);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200282
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200283 install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_addr_cmd);
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +0200284
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200285 install_element_ve(&show_hnb_cmd);
286 install_element_ve(&show_ue_cmd);
287 install_element_ve(&show_talloc_cmd);
288}