blob: ae2797519d86e56ad6d2515707019c711cee9e17 [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 +020035struct cmd_node hlr_node = {
36 HLR_NODE,
37 "%s(config-hlr)# ",
38 1,
39};
40
41DEFUN(cfg_hlr,
42 cfg_hlr_cmd,
43 "hlr",
44 "Configure the HLR")
45{
46 vty->node = HLR_NODE;
47 return CMD_SUCCESS;
48}
49
50struct cmd_node gsup_node = {
51 GSUP_NODE,
52 "%s(config-hlr-gsup)# ",
53 1,
54};
55
56DEFUN(cfg_gsup,
57 cfg_gsup_cmd,
58 "gsup",
59 "Configure GSUP options")
60{
61 vty->node = GSUP_NODE;
62 return CMD_SUCCESS;
63}
64
65static int config_write_hlr(struct vty *vty)
66{
67 vty_out(vty, "hlr%s", VTY_NEWLINE);
68 return CMD_SUCCESS;
69}
70
71static int config_write_hlr_gsup(struct vty *vty)
72{
73 vty_out(vty, " gsup%s", VTY_NEWLINE);
74 if (g_hlr->gsup_bind_addr)
75 vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
76 return CMD_SUCCESS;
77}
78
Harald Weltefa7ee332018-06-24 13:20:32 +020079static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
80{
81 const struct ipa_server_conn *isc = conn->conn;
82 char *name;
83 int rc;
84
85 rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
86 OSMO_ASSERT(rc);
87
88 vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s",
89 name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind,
90 VTY_NEWLINE);
91}
92
93DEFUN(show_gsup_conn, show_gsup_conn_cmd,
94 "show gsup-connections",
95 SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n")
96{
97 struct osmo_gsup_server *gs = g_hlr->gs;
98 struct osmo_gsup_conn *conn;
99
100 llist_for_each_entry(conn, &gs->clients, list)
101 show_one_conn(vty, conn);
102
103 return CMD_SUCCESS;
104}
105
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200106DEFUN(cfg_hlr_gsup_bind_ip,
107 cfg_hlr_gsup_bind_ip_cmd,
108 "bind ip A.B.C.D",
109 "Listen/Bind related socket option\n"
110 IP_STR
111 "IPv4 Address to bind the GSUP interface to\n")
112{
113 if(g_hlr->gsup_bind_addr)
114 talloc_free(g_hlr->gsup_bind_addr);
115 g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]);
116
117 return CMD_SUCCESS;
118}
119
120int hlr_vty_go_parent(struct vty *vty)
121{
122 switch (vty->node) {
123 case GSUP_NODE:
124 vty->node = HLR_NODE;
125 vty->index = NULL;
126 break;
127 default:
128 case HLR_NODE:
129 vty->node = CONFIG_NODE;
130 vty->index = NULL;
131 break;
132 case CONFIG_NODE:
133 vty->node = ENABLE_NODE;
134 vty->index = NULL;
135 break;
136 }
137
138 return vty->node;
139}
140
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100141int hlr_vty_is_config_node(struct vty *vty, int node)
142{
143 switch (node) {
144 /* add items that are not config */
145 case CONFIG_NODE:
146 return 0;
147
148 default:
149 return 1;
150 }
151}
152
Harald Welted5807b82018-07-29 12:27:41 +0200153void hlr_vty_init(const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100154{
155 logging_vty_add_cmds(cat);
Harald Welte7ee6e552018-02-14 00:52:05 +0100156 osmo_talloc_vty_add_cmds();
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200157
Harald Weltefa7ee332018-06-24 13:20:32 +0200158 install_element_ve(&show_gsup_conn_cmd);
159
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200160 install_element(CONFIG_NODE, &cfg_hlr_cmd);
161 install_node(&hlr_node, config_write_hlr);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200162
163 install_element(HLR_NODE, &cfg_gsup_cmd);
164 install_node(&gsup_node, config_write_hlr_gsup);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200165
166 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr183e7002017-10-06 02:59:54 +0200167
Harald Welted5807b82018-07-29 12:27:41 +0200168 hlr_vty_subscriber_init();
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100169}