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