blob: a458c76b6993ed4a29c42a28e635eebf632c24da [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 Hofmeyr4d8eb4c2016-08-18 01:03:44 +020027
28static void *tall_hnb_ctx = NULL;
29static struct hnb_gw *g_hnb_gw = NULL;
30
Neels Hofmeyr926153b2016-08-18 02:15:56 +020031static struct cmd_node hnbgw_node = {
32 HNBGW_NODE,
33 "%s(config-hnbgw)# ",
34 1,
35};
36
37DEFUN(cfg_hnbgw, cfg_hnbgw_cmd,
38 "hnbgw", "Configure HNBGW options")
39{
40 vty->node = HNBGW_NODE;
41 return CMD_SUCCESS;
42}
43
44static struct cmd_node iuh_node = {
45 IUH_NODE,
46 "%s(config-hnbgw-iuh)# ",
47 1,
48};
49
50DEFUN(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 Hofmeyrc510fc22016-10-13 16:58:04 +020057int hnbgw_vty_go_parent(struct vty *vty)
58{
59 switch (vty->node) {
60 case IUH_NODE:
61 vty->node = HNBGW_NODE;
62 vty->index = NULL;
63 break;
64 default:
65 case HNBGW_NODE:
66 vty->node = CONFIG_NODE;
67 vty->index = NULL;
68 break;
69 case CONFIG_NODE:
70 vty->node = ENABLE_NODE;
71 vty->index = NULL;
72 break;
73 }
74
75 return vty->node;
76}
77
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +020078static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb)
79{
80 struct hnbgw_context_map *map;
81
82 vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info,
83 hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid,
84 VTY_NEWLINE);
85 vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE);
86
87 llist_for_each_entry(map, &hnb->map_list, hnb_list) {
88 vty_out(vty, " Map %u->%u (RUA->SUA) cnlink=%p state=%u%s", map->rua_ctx_id, map->scu_conn_id,
89 map->cn_link, map->state, VTY_NEWLINE);
90
91 }
92}
93
94static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue)
95{
96 vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE);
97}
98
99DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB")
100{
101 struct hnb_context *hnb;
102
103 llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) {
104 vty_dump_hnb_info(vty, hnb);
105 }
106
107 return CMD_SUCCESS;
108}
109
110DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE")
111{
112 struct ue_context *ue;
113
114 llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) {
115 vty_dump_ue_info(vty, ue);
116 }
117
118 return CMD_SUCCESS;
119}
120
121DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info")
122{
123 talloc_report_full(tall_hnb_ctx, stderr);
124 talloc_report_full(talloc_asn1_ctx, stderr);
125
126 return CMD_SUCCESS;
127}
128
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200129DEFUN(cfg_hnbgw_iuh_local_ip, cfg_hnbgw_iuh_local_ip_cmd, "local-ip A.B.C.D",
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200130 "Accept Iuh connections on local interface\n"
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200131 "Local interface IP address (default: " HNBGW_LOCAL_IP_DEFAULT ")")
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200132{
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200133 talloc_free((void*)g_hnb_gw->config.iuh_local_ip);
134 g_hnb_gw->config.iuh_local_ip = talloc_strdup(tall_hnb_ctx, argv[0]);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200135 return CMD_SUCCESS;
136}
137
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200138DEFUN(cfg_hnbgw_iuh_local_port, cfg_hnbgw_iuh_local_port_cmd, "local-port <1-65535>",
139 "Accept Iuh connections on local port\n"
140 "Local interface port (default: 29169)")
141{
142 g_hnb_gw->config.iuh_local_port = atoi(argv[0]);
143 return CMD_SUCCESS;
144}
145
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200146DEFUN(cfg_hnbgw_iuh_hnbap_allow_tmsi, cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd,
147 "hnbap-allow-tmsi (0|1)",
148 "Allow HNBAP UE Register messages with TMSI or PTMSI identity\n"
149 "Only accept IMSI identity, reject TMSI or PTMSI\n"
150 "Accept IMSI, TMSI or PTMSI as UE identity\n")
151{
152 g_hnb_gw->config.hnbap_allow_tmsi = (*argv[0] == '1');
153 return CMD_SUCCESS;
154}
155
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200156static int config_write_hnbgw(struct vty *vty)
157{
158 vty_out(vty, "hnbgw%s", VTY_NEWLINE);
159 return CMD_SUCCESS;
160}
161
162static int config_write_hnbgw_iuh(struct vty *vty)
163{
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200164 const char *addr;
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200165 uint16_t port;
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200166
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200167 vty_out(vty, " iuh%s", VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200168
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200169 addr = g_hnb_gw->config.iuh_local_ip;
170 if (addr && (strcmp(addr, HNBGW_LOCAL_IP_DEFAULT) != 0))
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200171 vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200172
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200173 port = g_hnb_gw->config.iuh_local_port;
174 if (port && port != IUH_DEFAULT_SCTP_PORT)
175 vty_out(vty, " local-port %u%s", port, VTY_NEWLINE);
176
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200177 if (g_hnb_gw->config.hnbap_allow_tmsi)
178 vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE);
179
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200180 return CMD_SUCCESS;
181}
182
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200183void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
184{
185 g_hnb_gw = gw;
186 tall_hnb_ctx = tall_ctx;
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200187
188 install_element(CONFIG_NODE, &cfg_hnbgw_cmd);
189 install_node(&hnbgw_node, config_write_hnbgw);
190 vty_install_default(HNBGW_NODE);
191
192 install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
193 install_node(&iuh_node, config_write_hnbgw_iuh);
194 vty_install_default(IUH_NODE);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200195
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200196 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_ip_cmd);
Neels Hofmeyr9153de62016-10-13 15:11:07 +0200197 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_port_cmd);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200198 install_element(IUH_NODE, &cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200199
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200200 install_element_ve(&show_hnb_cmd);
201 install_element_ve(&show_ue_cmd);
202 install_element_ve(&show_talloc_cmd);
203}