blob: ecc2f5c076a5d5a1024e1b50e65c789e77566a19 [file] [log] [blame]
Neels Hofmeyr7685a782017-01-30 23:30:26 +01001/* OsmoHLR VTY implementation */
2
3/* (C) 2016 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
Neels Hofmeyr7685a782017-01-30 23:30:26 +01004 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
Harald Weltefa7ee332018-06-24 13:20:32 +02005 * (C) 2018 Harald Welte <laforge@gnumonks.org>
6 *
7 * All Rights Reserved
Neels Hofmeyr7685a782017-01-30 23:30:26 +01008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020024#include <osmocom/core/talloc.h>
Neels Hofmeyr7685a782017-01-30 23:30:26 +010025#include <osmocom/vty/vty.h>
26#include <osmocom/vty/command.h>
27#include <osmocom/vty/logging.h>
Harald Welte7ee6e552018-02-14 00:52:05 +010028#include <osmocom/vty/misc.h>
Harald Weltefa7ee332018-06-24 13:20:32 +020029#include <osmocom/abis/ipa.h>
Neels Hofmeyr7685a782017-01-30 23:30:26 +010030
31#include "hlr_vty.h"
Neels Hofmeyr183e7002017-10-06 02:59:54 +020032#include "hlr_vty_subscr.h"
Harald Weltefa7ee332018-06-24 13:20:32 +020033#include "gsup_server.h"
Neels Hofmeyr7685a782017-01-30 23:30:26 +010034
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020035static struct hlr *g_hlr = NULL;
36
37struct cmd_node hlr_node = {
38 HLR_NODE,
39 "%s(config-hlr)# ",
40 1,
41};
42
43DEFUN(cfg_hlr,
44 cfg_hlr_cmd,
45 "hlr",
46 "Configure the HLR")
47{
48 vty->node = HLR_NODE;
49 return CMD_SUCCESS;
50}
51
52struct cmd_node gsup_node = {
53 GSUP_NODE,
54 "%s(config-hlr-gsup)# ",
55 1,
56};
57
58DEFUN(cfg_gsup,
59 cfg_gsup_cmd,
60 "gsup",
61 "Configure GSUP options")
62{
63 vty->node = GSUP_NODE;
64 return CMD_SUCCESS;
65}
66
67static int config_write_hlr(struct vty *vty)
68{
69 vty_out(vty, "hlr%s", VTY_NEWLINE);
70 return CMD_SUCCESS;
71}
72
73static int config_write_hlr_gsup(struct vty *vty)
74{
75 vty_out(vty, " gsup%s", VTY_NEWLINE);
76 if (g_hlr->gsup_bind_addr)
77 vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
78 return CMD_SUCCESS;
79}
80
Harald Weltefa7ee332018-06-24 13:20:32 +020081static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
82{
83 const struct ipa_server_conn *isc = conn->conn;
84 char *name;
85 int rc;
86
87 rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
88 OSMO_ASSERT(rc);
89
90 vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s",
91 name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind,
92 VTY_NEWLINE);
93}
94
95DEFUN(show_gsup_conn, show_gsup_conn_cmd,
96 "show gsup-connections",
97 SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n")
98{
99 struct osmo_gsup_server *gs = g_hlr->gs;
100 struct osmo_gsup_conn *conn;
101
102 llist_for_each_entry(conn, &gs->clients, list)
103 show_one_conn(vty, conn);
104
105 return CMD_SUCCESS;
106}
107
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200108DEFUN(cfg_hlr_gsup_bind_ip,
109 cfg_hlr_gsup_bind_ip_cmd,
110 "bind ip A.B.C.D",
111 "Listen/Bind related socket option\n"
112 IP_STR
113 "IPv4 Address to bind the GSUP interface to\n")
114{
115 if(g_hlr->gsup_bind_addr)
116 talloc_free(g_hlr->gsup_bind_addr);
117 g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]);
118
119 return CMD_SUCCESS;
120}
121
122int hlr_vty_go_parent(struct vty *vty)
123{
124 switch (vty->node) {
125 case GSUP_NODE:
126 vty->node = HLR_NODE;
127 vty->index = NULL;
128 break;
129 default:
130 case HLR_NODE:
131 vty->node = CONFIG_NODE;
132 vty->index = NULL;
133 break;
134 case CONFIG_NODE:
135 vty->node = ENABLE_NODE;
136 vty->index = NULL;
137 break;
138 }
139
140 return vty->node;
141}
142
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100143int hlr_vty_is_config_node(struct vty *vty, int node)
144{
145 switch (node) {
146 /* add items that are not config */
147 case CONFIG_NODE:
148 return 0;
149
150 default:
151 return 1;
152 }
153}
154
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200155void hlr_vty_init(struct hlr *hlr, const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100156{
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200157 g_hlr = hlr;
158
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100159 logging_vty_add_cmds(cat);
Harald Welte7ee6e552018-02-14 00:52:05 +0100160 osmo_talloc_vty_add_cmds();
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200161
Harald Weltefa7ee332018-06-24 13:20:32 +0200162 install_element_ve(&show_gsup_conn_cmd);
163
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200164 install_element(CONFIG_NODE, &cfg_hlr_cmd);
165 install_node(&hlr_node, config_write_hlr);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200166
167 install_element(HLR_NODE, &cfg_gsup_cmd);
168 install_node(&gsup_node, config_write_hlr_gsup);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200169
170 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr183e7002017-10-06 02:59:54 +0200171
172 hlr_vty_subscriber_init(hlr);
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100173}