blob: 946117e689d0a2bbe765a60eb9d9b7f2e23ec33b [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>
27
28#include "hlr_vty.h"
29
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +020030static struct hlr *g_hlr = NULL;
31
32struct cmd_node hlr_node = {
33 HLR_NODE,
34 "%s(config-hlr)# ",
35 1,
36};
37
38DEFUN(cfg_hlr,
39 cfg_hlr_cmd,
40 "hlr",
41 "Configure the HLR")
42{
43 vty->node = HLR_NODE;
44 return CMD_SUCCESS;
45}
46
47struct cmd_node gsup_node = {
48 GSUP_NODE,
49 "%s(config-hlr-gsup)# ",
50 1,
51};
52
53DEFUN(cfg_gsup,
54 cfg_gsup_cmd,
55 "gsup",
56 "Configure GSUP options")
57{
58 vty->node = GSUP_NODE;
59 return CMD_SUCCESS;
60}
61
62static int config_write_hlr(struct vty *vty)
63{
64 vty_out(vty, "hlr%s", VTY_NEWLINE);
65 return CMD_SUCCESS;
66}
67
68static int config_write_hlr_gsup(struct vty *vty)
69{
70 vty_out(vty, " gsup%s", VTY_NEWLINE);
71 if (g_hlr->gsup_bind_addr)
72 vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
73 return CMD_SUCCESS;
74}
75
76DEFUN(cfg_hlr_gsup_bind_ip,
77 cfg_hlr_gsup_bind_ip_cmd,
78 "bind ip A.B.C.D",
79 "Listen/Bind related socket option\n"
80 IP_STR
81 "IPv4 Address to bind the GSUP interface to\n")
82{
83 if(g_hlr->gsup_bind_addr)
84 talloc_free(g_hlr->gsup_bind_addr);
85 g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]);
86
87 return CMD_SUCCESS;
88}
89
90int hlr_vty_go_parent(struct vty *vty)
91{
92 switch (vty->node) {
93 case GSUP_NODE:
94 vty->node = HLR_NODE;
95 vty->index = NULL;
96 break;
97 default:
98 case HLR_NODE:
99 vty->node = CONFIG_NODE;
100 vty->index = NULL;
101 break;
102 case CONFIG_NODE:
103 vty->node = ENABLE_NODE;
104 vty->index = NULL;
105 break;
106 }
107
108 return vty->node;
109}
110
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100111int hlr_vty_is_config_node(struct vty *vty, int node)
112{
113 switch (node) {
114 /* add items that are not config */
115 case CONFIG_NODE:
116 return 0;
117
118 default:
119 return 1;
120 }
121}
122
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200123void hlr_vty_init(struct hlr *hlr, const struct log_info *cat)
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100124{
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200125 g_hlr = hlr;
126
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100127 logging_vty_add_cmds(cat);
Pau Espin Pedrolce9bc402017-05-31 13:19:22 +0200128
129 install_element(CONFIG_NODE, &cfg_hlr_cmd);
130 install_node(&hlr_node, config_write_hlr);
131 install_default(HLR_NODE);
132
133 install_element(HLR_NODE, &cfg_gsup_cmd);
134 install_node(&gsup_node, config_write_hlr_gsup);
135 install_default(GSUP_NODE);
136
137 install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100138}