blob: 1673c0cdc0497bcb6dd375347f1488aac6c7d1b1 [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 Hofmeyr4d8eb4c2016-08-18 01:03:44 +020025#include "hnbgw.h"
26#include "context_map.h"
27
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 Hofmeyrf495b232016-08-18 02:18:00 +0200108DEFUN(cfg_hnbgw_iuh_bind, cfg_hnbgw_iuh_bind_cmd, "bind A.B.C.D",
109 "Accept Iuh connections on local interface\n"
110 "Local interface IP address (default: " HNBGW_IUH_BIND_ADDR_DEFAULT ")")
111{
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 Hofmeyr926153b2016-08-18 02:15:56 +0200117static int config_write_hnbgw(struct vty *vty)
118{
119 vty_out(vty, "hnbgw%s", VTY_NEWLINE);
120 return CMD_SUCCESS;
121}
122
123static int config_write_hnbgw_iuh(struct vty *vty)
124{
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200125 const char *addr;
126
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200127 vty_out(vty, " iuh%s", VTY_NEWLINE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200128
129 addr = g_hnb_gw->config.iuh_bind_addr;
130 if (addr && (strcmp(addr, HNBGW_IUH_BIND_ADDR_DEFAULT) != 0))
131 vty_out(vty, " bind %s%s", addr, VTY_NEWLINE);
132
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200133 return CMD_SUCCESS;
134}
135
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200136void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
137{
138 g_hnb_gw = gw;
139 tall_hnb_ctx = tall_ctx;
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200140
141 install_element(CONFIG_NODE, &cfg_hnbgw_cmd);
142 install_node(&hnbgw_node, config_write_hnbgw);
143 vty_install_default(HNBGW_NODE);
144
145 install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
146 install_node(&iuh_node, config_write_hnbgw_iuh);
147 vty_install_default(IUH_NODE);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200148 install_element(IUH_NODE, &cfg_hnbgw_iuh_bind_cmd);
Neels Hofmeyr926153b2016-08-18 02:15:56 +0200149
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200150 install_element_ve(&show_hnb_cmd);
151 install_element_ve(&show_ue_cmd);
152 install_element_ve(&show_talloc_cmd);
153}