blob: 5dee41a992149e5d71417094378dab1b93f79fa1 [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 Hofmeyr4d8eb4c2016-08-18 01:03:44 +020057static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb)
58{
59 struct hnbgw_context_map *map;
60
61 vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info,
62 hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid,
63 VTY_NEWLINE);
64 vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE);
65
66 llist_for_each_entry(map, &hnb->map_list, hnb_list) {
67 vty_out(vty, " Map %u->%u (RUA->SUA) cnlink=%p state=%u%s", map->rua_ctx_id, map->scu_conn_id,
68 map->cn_link, map->state, VTY_NEWLINE);
69
70 }
71}
72
73static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue)
74{
75 vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE);
76}
77
78DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB")
79{
80 struct hnb_context *hnb;
81
82 llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) {
83 vty_dump_hnb_info(vty, hnb);
84 }
85
86 return CMD_SUCCESS;
87}
88
89DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE")
90{
91 struct ue_context *ue;
92
93 llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) {
94 vty_dump_ue_info(vty, ue);
95 }
96
97 return CMD_SUCCESS;
98}
99
100DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info")
101{
102 talloc_report_full(tall_hnb_ctx, stderr);
103 talloc_report_full(talloc_asn1_ctx, stderr);
104
105 return CMD_SUCCESS;
106}
107
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200108DEFUN(cfg_hnbgw_iuh_local_ip, cfg_hnbgw_iuh_local_ip_cmd, "local-ip A.B.C.D",
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200109 "Accept Iuh connections on local interface\n"
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200110 "Local interface IP address (default: " HNBGW_IUH_LOCAL_IP_DEFAULT ")")
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200111{
112 talloc_free((void*)g_hnb_gw->config.iuh_bind_addr);
113 g_hnb_gw->config.iuh_bind_addr = talloc_strdup(tall_hnb_ctx, argv[0]);
114 return CMD_SUCCESS;
115}
116
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200117DEFUN(cfg_hnbgw_iuh_hnbap_allow_tmsi, cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd,
118 "hnbap-allow-tmsi (0|1)",
119 "Allow HNBAP UE Register messages with TMSI or PTMSI identity\n"
120 "Only accept IMSI identity, reject TMSI or PTMSI\n"
121 "Accept IMSI, TMSI or PTMSI as UE identity\n")
122{
123 g_hnb_gw->config.hnbap_allow_tmsi = (*argv[0] == '1');
124 return CMD_SUCCESS;
125}
126
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200127static int config_write_hnbgw(struct vty *vty)
128{
129 vty_out(vty, "hnbgw%s", VTY_NEWLINE);
130 return CMD_SUCCESS;
131}
132
133static int config_write_hnbgw_iuh(struct vty *vty)
134{
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200135 const char *addr;
136
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200137 vty_out(vty, " iuh%s", VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200138
139 addr = g_hnb_gw->config.iuh_bind_addr;
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200140 if (addr && (strcmp(addr, HNBGW_IUH_LOCAL_IP_DEFAULT) != 0))
141 vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200142
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200143 if (g_hnb_gw->config.hnbap_allow_tmsi)
144 vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE);
145
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200146 return CMD_SUCCESS;
147}
148
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200149void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
150{
151 g_hnb_gw = gw;
152 tall_hnb_ctx = tall_ctx;
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200153
154 install_element(CONFIG_NODE, &cfg_hnbgw_cmd);
155 install_node(&hnbgw_node, config_write_hnbgw);
156 vty_install_default(HNBGW_NODE);
157
158 install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
159 install_node(&iuh_node, config_write_hnbgw_iuh);
160 vty_install_default(IUH_NODE);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200161
Neels Hofmeyr39ee9262016-09-26 01:07:19 +0200162 install_element(IUH_NODE, &cfg_hnbgw_iuh_local_ip_cmd);
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200163 install_element(IUH_NODE, &cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200164
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200165 install_element_ve(&show_hnb_cmd);
166 install_element_ve(&show_ue_cmd);
167 install_element_ve(&show_talloc_cmd);
168}