blob: c10829dbf19479a0e75d74394956fd2a7dccb9c2 [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>
4 * All Rights Reserved
5 *
6 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020023#include <osmocom/core/talloc.h>
Neels Hofmeyr7685a782017-01-30 23:30:26 +010024#include <osmocom/vty/vty.h>
25#include <osmocom/vty/command.h>
26#include <osmocom/vty/logging.h>
Harald Welte7ee6e552018-02-14 00:52:05 +010027#include <osmocom/vty/misc.h>
Neels Hofmeyr7685a782017-01-30 23:30:26 +010028
29#include "hlr_vty.h"
Neels Hofmeyr183e7002017-10-06 02:59:54 +020030#include "hlr_vty_subscr.h"
Neels Hofmeyr7685a782017-01-30 23:30:26 +010031
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020032static struct hlr *g_hlr = NULL;
33
34struct cmd_node hlr_node = {
35 HLR_NODE,
36 "%s(config-hlr)# ",
37 1,
38};
39
40DEFUN(cfg_hlr,
41 cfg_hlr_cmd,
42 "hlr",
43 "Configure the HLR")
44{
45 vty->node = HLR_NODE;
46 return CMD_SUCCESS;
47}
48
49struct cmd_node gsup_node = {
50 GSUP_NODE,
51 "%s(config-hlr-gsup)# ",
52 1,
53};
54
55DEFUN(cfg_gsup,
56 cfg_gsup_cmd,
57 "gsup",
58 "Configure GSUP options")
59{
60 vty->node = GSUP_NODE;
61 return CMD_SUCCESS;
62}
63
64static int config_write_hlr(struct vty *vty)
65{
66 vty_out(vty, "hlr%s", VTY_NEWLINE);
67 return CMD_SUCCESS;
68}
69
70static int config_write_hlr_gsup(struct vty *vty)
71{
72 vty_out(vty, " gsup%s", VTY_NEWLINE);
73 if (g_hlr->gsup_bind_addr)
74 vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
75 return CMD_SUCCESS;
76}
77
78DEFUN(cfg_hlr_gsup_bind_ip,
79 cfg_hlr_gsup_bind_ip_cmd,
80 "bind ip A.B.C.D",
81 "Listen/Bind related socket option\n"
82 IP_STR
83 "IPv4 Address to bind the GSUP interface to\n")
84{
85 if(g_hlr->gsup_bind_addr)
86 talloc_free(g_hlr->gsup_bind_addr);
87 g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]);
88
89 return CMD_SUCCESS;
90}
91
92int hlr_vty_go_parent(struct vty *vty)
93{
94 switch (vty->node) {
95 case GSUP_NODE:
96 vty->node = HLR_NODE;
97 vty->index = NULL;
98 break;
99 default:
100 case HLR_NODE:
101 vty->node = CONFIG_NODE;
102 vty->index = NULL;
103 break;
104 case CONFIG_NODE:
105 vty->node = ENABLE_NODE;
106 vty->index = NULL;
107 break;
108 }
109
110 return vty->node;
111}
112
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100113int hlr_vty_is_config_node(struct vty *vty, int node)
114{
115 switch (node) {
116 /* add items that are not config */
117 case CONFIG_NODE:
118 return 0;
119
120 default:
121 return 1;
122 }
123}
124
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200125void hlr_vty_init(struct hlr *hlr, const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100126{
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200127 g_hlr = hlr;
128
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100129 logging_vty_add_cmds(cat);
Harald Welte7ee6e552018-02-14 00:52:05 +0100130 osmo_talloc_vty_add_cmds();
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200131
132 install_element(CONFIG_NODE, &cfg_hlr_cmd);
133 install_node(&hlr_node, config_write_hlr);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200134
135 install_element(HLR_NODE, &cfg_gsup_cmd);
136 install_node(&gsup_node, config_write_hlr_gsup);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200137
138 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr183e7002017-10-06 02:59:54 +0200139
140 hlr_vty_subscriber_init(hlr);
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100141}