2010-04-30 19:49:24 +00:00
|
|
|
/*
|
|
|
|
* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* (C) 2010 by On-Waves
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-04-30 19:49:24 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2010-04-30 19:49:24 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-04-30 19:49:24 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2014-05-23 18:48:07 +00:00
|
|
|
#include <string.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2012-06-16 06:59:56 +00:00
|
|
|
#include <osmocom/gprs/gprs_ns.h>
|
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
#include <openbsc/debug.h>
|
2010-05-01 09:28:43 +00:00
|
|
|
#include <openbsc/gb_proxy.h>
|
2010-05-14 16:59:17 +00:00
|
|
|
#include <openbsc/vty.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2010-05-19 17:45:32 +00:00
|
|
|
#include <osmocom/vty/command.h>
|
|
|
|
#include <osmocom/vty/vty.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
|
|
|
static struct gbproxy_config *g_cfg = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vty code for mgcp below
|
|
|
|
*/
|
2010-05-01 09:28:43 +00:00
|
|
|
static struct cmd_node gbproxy_node = {
|
2010-04-30 19:49:24 +00:00
|
|
|
GBPROXY_NODE,
|
2012-08-17 11:16:10 +00:00
|
|
|
"%s(config-gbproxy)# ",
|
2010-04-30 19:49:24 +00:00
|
|
|
1,
|
|
|
|
};
|
|
|
|
|
2014-05-28 08:59:10 +00:00
|
|
|
static const struct value_string patch_modes[] = {
|
|
|
|
{GBPROX_PATCH_DEFAULT, "default"},
|
|
|
|
{GBPROX_PATCH_BSSGP, "bssgp"},
|
|
|
|
{GBPROX_PATCH_LLC_ATTACH_REQ, "llc-attach-req"},
|
|
|
|
{GBPROX_PATCH_LLC_ATTACH, "llc-attach"},
|
|
|
|
{GBPROX_PATCH_LLC_GMM, "llc-gmm"},
|
2014-05-23 18:48:07 +00:00
|
|
|
{GBPROX_PATCH_LLC_GSM, "llc-gsm"},
|
2014-05-28 08:59:10 +00:00
|
|
|
{GBPROX_PATCH_LLC, "llc"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
static int config_write_gbproxy(struct vty *vty)
|
|
|
|
{
|
|
|
|
vty_out(vty, "gbproxy%s", VTY_NEWLINE);
|
|
|
|
|
2010-05-19 13:09:09 +00:00
|
|
|
vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
|
2010-04-30 19:49:24 +00:00
|
|
|
VTY_NEWLINE);
|
|
|
|
|
2014-05-19 08:14:58 +00:00
|
|
|
if (g_cfg->core_mcc > 0)
|
|
|
|
vty_out(vty, " core-mobile-country-code %d%s",
|
|
|
|
g_cfg->core_mcc, VTY_NEWLINE);
|
|
|
|
if (g_cfg->core_mnc > 0)
|
|
|
|
vty_out(vty, " core-mobile-network-code %d%s",
|
|
|
|
g_cfg->core_mnc, VTY_NEWLINE);
|
2014-05-23 18:48:07 +00:00
|
|
|
if (g_cfg->core_apn != NULL) {
|
|
|
|
if (g_cfg->core_apn_size > 0) {
|
|
|
|
char str[500] = {0};
|
|
|
|
vty_out(vty, " core-access-point-name %s%s",
|
|
|
|
gbprox_apn_to_str(str, g_cfg->core_apn,
|
|
|
|
g_cfg->core_apn_size),
|
|
|
|
VTY_NEWLINE);
|
|
|
|
} else {
|
|
|
|
vty_out(vty, " core-access-point-name%s",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 08:14:58 +00:00
|
|
|
|
2014-05-28 08:59:10 +00:00
|
|
|
if (g_cfg->patch_mode != GBPROX_PATCH_DEFAULT)
|
|
|
|
vty_out(vty, " patch-mode %s%s",
|
|
|
|
get_value_string(patch_modes, g_cfg->patch_mode),
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy,
|
|
|
|
cfg_gbproxy_cmd,
|
|
|
|
"gbproxy",
|
|
|
|
"Configure the Gb proxy")
|
|
|
|
{
|
|
|
|
vty->node = GBPROXY_NODE;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_nsip_sgsn_nsei,
|
|
|
|
cfg_nsip_sgsn_nsei_cmd,
|
2010-05-19 13:09:09 +00:00
|
|
|
"sgsn nsei <0-65534>",
|
2011-11-05 14:14:59 +00:00
|
|
|
"SGSN information\n"
|
|
|
|
"NSEI to be used in the connection with the SGSN\n"
|
|
|
|
"The NSEI\n")
|
2010-04-30 19:49:24 +00:00
|
|
|
{
|
|
|
|
unsigned int port = atoi(argv[0]);
|
|
|
|
|
|
|
|
g_cfg->nsip_sgsn_nsei = port;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-05-19 08:14:58 +00:00
|
|
|
#define GBPROXY_CORE_MNC_STR "Use this network code for the core network\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_core_mnc,
|
|
|
|
cfg_gbproxy_core_mnc_cmd,
|
|
|
|
"core-mobile-network-code <1-999>",
|
|
|
|
GBPROXY_CORE_MNC_STR "NCC value\n")
|
|
|
|
{
|
|
|
|
g_cfg->core_mnc = atoi(argv[0]);
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_core_mnc,
|
|
|
|
cfg_gbproxy_no_core_mnc_cmd,
|
|
|
|
"no core-mobile-network-code",
|
|
|
|
NO_STR GBPROXY_CORE_MNC_STR)
|
|
|
|
{
|
|
|
|
g_cfg->core_mnc = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GBPROXY_CORE_MCC_STR "Use this country code for the core network\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_core_mcc,
|
|
|
|
cfg_gbproxy_core_mcc_cmd,
|
|
|
|
"core-mobile-country-code <1-999>",
|
|
|
|
GBPROXY_CORE_MCC_STR "MCC value\n")
|
|
|
|
{
|
|
|
|
g_cfg->core_mcc = atoi(argv[0]);
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_core_mcc,
|
|
|
|
cfg_gbproxy_no_core_mcc_cmd,
|
|
|
|
"no core-mobile-country-code",
|
|
|
|
NO_STR GBPROXY_CORE_MCC_STR)
|
|
|
|
{
|
|
|
|
g_cfg->core_mcc = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-05-23 18:48:07 +00:00
|
|
|
#define GBPROXY_CORE_APN_STR "Use this access point name (APN) for the backbone\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_core_apn_remove,
|
|
|
|
cfg_gbproxy_core_apn_remove_cmd,
|
|
|
|
"core-access-point-name",
|
|
|
|
GBPROXY_CORE_APN_STR)
|
|
|
|
{
|
|
|
|
talloc_free(g_cfg->core_apn);
|
|
|
|
/* TODO: replace NULL */
|
|
|
|
g_cfg->core_apn = talloc_zero_size(NULL, 2);
|
|
|
|
g_cfg->core_apn_size = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_core_apn,
|
|
|
|
cfg_gbproxy_core_apn_cmd,
|
|
|
|
"core-access-point-name APN",
|
|
|
|
GBPROXY_CORE_APN_STR "Replacement APN\n")
|
|
|
|
{
|
|
|
|
int apn_len = strlen(argv[0]) + 1;
|
|
|
|
|
|
|
|
if (apn_len > 100) {
|
|
|
|
vty_out(vty, "APN string too long (max 99 chars)%s",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: replace NULL */
|
|
|
|
g_cfg->core_apn = talloc_realloc_size(NULL, g_cfg->core_apn, apn_len);
|
|
|
|
g_cfg->core_apn_size = gbprox_str_to_apn(g_cfg->core_apn, argv[0], apn_len);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_core_apn,
|
|
|
|
cfg_gbproxy_no_core_apn_cmd,
|
|
|
|
"no core-access-point-name",
|
|
|
|
NO_STR GBPROXY_CORE_APN_STR)
|
|
|
|
{
|
|
|
|
talloc_free(g_cfg->core_apn);
|
|
|
|
g_cfg->core_apn = NULL;
|
|
|
|
g_cfg->core_apn_size = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-05-28 08:59:10 +00:00
|
|
|
DEFUN(cfg_gbproxy_patch_mode,
|
|
|
|
cfg_gbproxy_patch_mode_cmd,
|
2014-05-23 18:48:07 +00:00
|
|
|
"patch-mode (default|bssgp|llc-attach-req|llc-attach|llc-gmm|llc-gsm|llc)",
|
2014-05-28 08:59:10 +00:00
|
|
|
"Set patch mode\n"
|
2014-05-23 18:48:07 +00:00
|
|
|
"Use build-in default (best effort, try to patch everything)\n"
|
2014-05-28 08:59:10 +00:00
|
|
|
"Only patch BSSGP headers\n"
|
|
|
|
"Patch BSSGP headers and LLC Attach Request messages\n"
|
|
|
|
"Patch BSSGP headers and LLC Attach Request/Accept messages\n"
|
2014-05-23 18:48:07 +00:00
|
|
|
"Patch BSSGP headers and LLC GMM messages\n"
|
|
|
|
"Patch BSSGP headers, LLC GMM, and LLC GSM messages\n"
|
|
|
|
"Patch BSSGP headers and all supported LLC messages\n"
|
2014-05-28 08:59:10 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int val = get_string_value(patch_modes, argv[0]);
|
|
|
|
OSMO_ASSERT(val >= 0);
|
|
|
|
g_cfg->patch_mode = val;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-19 08:14:58 +00:00
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
int gbproxy_vty_init(void)
|
|
|
|
{
|
2010-05-12 16:50:52 +00:00
|
|
|
install_element_ve(&show_gbproxy_cmd);
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2013-10-24 10:48:23 +00:00
|
|
|
install_element(ENABLE_NODE, &delete_gb_bvci_cmd);
|
|
|
|
install_element(ENABLE_NODE, &delete_gb_nsei_cmd);
|
2013-10-23 09:24:17 +00:00
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
|
|
|
|
install_node(&gbproxy_node, config_write_gbproxy);
|
2013-10-29 08:30:30 +00:00
|
|
|
vty_install_default(GBPROXY_NODE);
|
2010-04-30 19:49:24 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
|
2014-05-19 08:14:58 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd);
|
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd);
|
2014-05-23 18:48:07 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_remove_cmd);
|
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_cmd);
|
2014-05-19 08:14:58 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd);
|
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd);
|
2014-05-23 18:48:07 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_apn_cmd);
|
2014-05-28 08:59:10 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_patch_mode_cmd);
|
2010-04-30 19:49:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
g_cfg = cfg;
|
2010-05-16 18:52:23 +00:00
|
|
|
rc = vty_read_config_file(config_file, NULL);
|
2010-04-30 19:49:24 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|