blob: 04431f0e39de780e83c3d99551272966ed8a3c8e [file] [log] [blame]
Harald Welte799e0c92010-04-30 21:49:24 +02001/*
2 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
3 * (C) 2010 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Harald Welte799e0c92010-04-30 21:49:24 +02009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Harald Welte799e0c92010-04-30 21:49:24 +020015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte799e0c92010-04-30 21:49:24 +020018 *
19 */
20
Harald Welte799e0c92010-04-30 21:49:24 +020021#include <sys/socket.h>
22#include <netinet/in.h>
23#include <arpa/inet.h>
24
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010025#include <osmocom/core/talloc.h>
Harald Welte799e0c92010-04-30 21:49:24 +020026
Harald Welteea34a4e2012-06-16 14:59:56 +080027#include <osmocom/gprs/gprs_ns.h>
28
Harald Welte799e0c92010-04-30 21:49:24 +020029#include <openbsc/debug.h>
Harald Welteb77c6972010-05-01 11:28:43 +020030#include <openbsc/gb_proxy.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020031#include <openbsc/vty.h>
Harald Welte799e0c92010-04-30 21:49:24 +020032
Harald Welte4b037e42010-05-19 19:45:32 +020033#include <osmocom/vty/command.h>
34#include <osmocom/vty/vty.h>
Harald Welte799e0c92010-04-30 21:49:24 +020035
Harald Welte799e0c92010-04-30 21:49:24 +020036static struct gbproxy_config *g_cfg = NULL;
37
38/*
39 * vty code for mgcp below
40 */
Harald Welteb77c6972010-05-01 11:28:43 +020041static struct cmd_node gbproxy_node = {
Harald Welte799e0c92010-04-30 21:49:24 +020042 GBPROXY_NODE,
Harald Welte570ce242012-08-17 13:16:10 +020043 "%s(config-gbproxy)# ",
Harald Welte799e0c92010-04-30 21:49:24 +020044 1,
45};
46
47static int config_write_gbproxy(struct vty *vty)
48{
Harald Welte799e0c92010-04-30 21:49:24 +020049 vty_out(vty, "gbproxy%s", VTY_NEWLINE);
50
Harald Welteff3bde82010-05-19 15:09:09 +020051 vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
Harald Welte799e0c92010-04-30 21:49:24 +020052 VTY_NEWLINE);
Harald Welte799e0c92010-04-30 21:49:24 +020053
Jacob Erlbeck67a44452014-05-19 10:14:58 +020054 if (g_cfg->core_mcc > 0)
55 vty_out(vty, " core-mobile-country-code %d%s",
56 g_cfg->core_mcc, VTY_NEWLINE);
57 if (g_cfg->core_mnc > 0)
58 vty_out(vty, " core-mobile-network-code %d%s",
59 g_cfg->core_mnc, VTY_NEWLINE);
60
Harald Welte799e0c92010-04-30 21:49:24 +020061 return CMD_SUCCESS;
62}
63
Harald Welte799e0c92010-04-30 21:49:24 +020064DEFUN(cfg_gbproxy,
65 cfg_gbproxy_cmd,
66 "gbproxy",
67 "Configure the Gb proxy")
68{
69 vty->node = GBPROXY_NODE;
70 return CMD_SUCCESS;
71}
72
Harald Welte799e0c92010-04-30 21:49:24 +020073DEFUN(cfg_nsip_sgsn_nsei,
74 cfg_nsip_sgsn_nsei_cmd,
Harald Welteff3bde82010-05-19 15:09:09 +020075 "sgsn nsei <0-65534>",
Holger Hans Peter Freyther2eb6e2c2011-11-05 15:14:59 +010076 "SGSN information\n"
77 "NSEI to be used in the connection with the SGSN\n"
78 "The NSEI\n")
Harald Welte799e0c92010-04-30 21:49:24 +020079{
80 unsigned int port = atoi(argv[0]);
81
82 g_cfg->nsip_sgsn_nsei = port;
83 return CMD_SUCCESS;
84}
85
Jacob Erlbeck67a44452014-05-19 10:14:58 +020086#define GBPROXY_CORE_MNC_STR "Use this network code for the core network\n"
87
88DEFUN(cfg_gbproxy_core_mnc,
89 cfg_gbproxy_core_mnc_cmd,
90 "core-mobile-network-code <1-999>",
91 GBPROXY_CORE_MNC_STR "NCC value\n")
92{
93 g_cfg->core_mnc = atoi(argv[0]);
94 return CMD_SUCCESS;
95}
96
97DEFUN(cfg_gbproxy_no_core_mnc,
98 cfg_gbproxy_no_core_mnc_cmd,
99 "no core-mobile-network-code",
100 NO_STR GBPROXY_CORE_MNC_STR)
101{
102 g_cfg->core_mnc = 0;
103 return CMD_SUCCESS;
104}
105
106#define GBPROXY_CORE_MCC_STR "Use this country code for the core network\n"
107
108DEFUN(cfg_gbproxy_core_mcc,
109 cfg_gbproxy_core_mcc_cmd,
110 "core-mobile-country-code <1-999>",
111 GBPROXY_CORE_MCC_STR "MCC value\n")
112{
113 g_cfg->core_mcc = atoi(argv[0]);
114 return CMD_SUCCESS;
115}
116
117DEFUN(cfg_gbproxy_no_core_mcc,
118 cfg_gbproxy_no_core_mcc_cmd,
119 "no core-mobile-country-code",
120 NO_STR GBPROXY_CORE_MCC_STR)
121{
122 g_cfg->core_mcc = 0;
123 return CMD_SUCCESS;
124}
125
126
Harald Welte799e0c92010-04-30 21:49:24 +0200127int gbproxy_vty_init(void)
128{
Harald Welte995a2d32010-05-12 16:50:52 +0000129 install_element_ve(&show_gbproxy_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200130
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200131 install_element(ENABLE_NODE, &delete_gb_bvci_cmd);
132 install_element(ENABLE_NODE, &delete_gb_nsei_cmd);
Holger Hans Peter Freyther90267a92013-10-23 11:24:17 +0200133
Harald Welte799e0c92010-04-30 21:49:24 +0200134 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
135 install_node(&gbproxy_node, config_write_gbproxy);
Jacob Erlbeck36722e12013-10-29 09:30:30 +0100136 vty_install_default(GBPROXY_NODE);
Harald Welte799e0c92010-04-30 21:49:24 +0200137 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
Jacob Erlbeck67a44452014-05-19 10:14:58 +0200138 install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd);
139 install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd);
140 install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd);
141 install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200142
143 return 0;
144}
145
146int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
147{
148 int rc;
149
150 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200151 rc = vty_read_config_file(config_file, NULL);
Harald Welte799e0c92010-04-30 21:49:24 +0200152 if (rc < 0) {
153 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
154 return rc;
155 }
156
157 return 0;
158}
159