dissolve libcommon,libcommon-cs: clean up vty definitions

From openbsc.git, we still have osmo-msc's VTY definitions spread across
various places. Combine:

- Move the go_parent_cb() and is_config_node() to msc_main.c, drop
  common_vty.c.
- Move all of vty_interface_layer3.c into msc_vty.c.
- Move all of common_cs_vty.c into msc_vty.c.
- Move bsc_vty_init_extra() into msc_vty_init().
- Drop some unused definitions

No functional nor cosmetic changes have been made in the moved code, plain
copy-paste moving (even though the unidiff might look like edits in some
places). I might have adjusted some blank lines though.

Change-Id: Ia818c00ab613a19a34080b160d763b55c19f76b1
This commit is contained in:
Neels Hofmeyr 2018-03-22 14:50:20 +01:00
parent d6a769b51c
commit 7c075a2f74
10 changed files with 1360 additions and 1503 deletions

View File

@ -7,8 +7,6 @@ struct gsm_network;
typedef int (*mncc_recv_cb_t)(struct gsm_network *, struct msgb *);
struct vty;
#define MAX_A5_KEY_LEN (128/8)
struct gsm_encr {
@ -18,7 +16,3 @@ struct gsm_encr {
};
struct gsm_network *gsm_network_init(void *ctx, mncc_recv_cb_t mncc_recv);
int common_cs_vty_init(struct gsm_network *network,
int (* config_write_net )(struct vty *));
struct gsm_network *gsmnet_from_vty(struct vty *v);

View File

@ -25,10 +25,6 @@ enum bsc_vty_node {
HLR_NODE,
};
extern int bsc_vty_is_config_node(struct vty *vty, int node);
struct log_info;
int bsc_vty_init(struct gsm_network *network);
int bsc_vty_init_extra(void);
void msc_vty_init(struct gsm_network *msc_network);

View File

@ -19,5 +19,4 @@ noinst_LIBRARIES = libcommon-cs.a
libcommon_cs_a_SOURCES = \
a_reset.c \
common_cs.c \
common_cs_vty.c
common_cs.c

View File

@ -1,306 +0,0 @@
/* Code used by both libbsc and libmsc (common_cs means "BSC or MSC").
*
* (C) 2016 by sysmocom s.m.f.c. <info@sysmocom.de>
* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* 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
* (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
* GNU Affero General Public License for more details.
*
* 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/>.
*
*/
#include <osmocom/core/utils.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/stats.h>
#include <osmocom/msc/vty.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/gsm_subscriber.h>
struct cmd_node net_node = {
GSMNET_NODE,
"%s(config-net)# ",
1,
};
#define NETWORK_STR "Configure the GSM network\n"
#define CODE_CMD_STR "Code commands\n"
#define NAME_CMD_STR "Name Commands\n"
#define NAME_STR "Name to use\n"
DEFUN(cfg_net,
cfg_net_cmd,
"network", NETWORK_STR)
{
vty->index = gsmnet_from_vty(vty);
vty->node = GSMNET_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_net_ncc,
cfg_net_ncc_cmd,
"network country code <1-999>",
"Set the GSM network country code\n"
"Country commands\n"
CODE_CMD_STR
"Network Country Code to use\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
gsmnet->plmn.mcc = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_mnc,
cfg_net_mnc_cmd,
"mobile network code <0-999>",
"Set the GSM mobile network code\n"
"Network Commands\n"
CODE_CMD_STR
"Mobile Network Code to use\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
uint16_t mnc;
bool mnc_3_digits;
if (osmo_mnc_from_str(argv[0], &mnc, &mnc_3_digits)) {
vty_out(vty, "%% Error decoding MNC: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
gsmnet->plmn.mnc = mnc;
gsmnet->plmn.mnc_3_digits = mnc_3_digits;
return CMD_SUCCESS;
}
DEFUN(cfg_net_name_short,
cfg_net_name_short_cmd,
"short name NAME",
"Set the short GSM network name\n" NAME_CMD_STR NAME_STR)
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
osmo_talloc_replace_string(gsmnet, &gsmnet->name_short, argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_name_long,
cfg_net_name_long_cmd,
"long name NAME",
"Set the long GSM network name\n" NAME_CMD_STR NAME_STR)
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
osmo_talloc_replace_string(gsmnet, &gsmnet->name_long, argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_encryption,
cfg_net_encryption_cmd,
"encryption a5 <0-3> [<0-3>] [<0-3>] [<0-3>]",
"Encryption options\n"
"GSM A5 Air Interface Encryption\n"
"A5/n Algorithm Number\n"
"A5/n Algorithm Number\n"
"A5/n Algorithm Number\n"
"A5/n Algorithm Number\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
unsigned int i;
gsmnet->a5_encryption_mask = 0;
for (i = 0; i < argc; i++)
gsmnet->a5_encryption_mask |= (1 << atoi(argv[i]));
return CMD_SUCCESS;
}
DEFUN(cfg_net_authentication,
cfg_net_authentication_cmd,
"authentication (optional|required)",
"Whether to enforce MS authentication in 2G\n"
"Allow MS to attach via 2G BSC without authentication\n"
"Always do authentication\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
gsmnet->authentication_required = (argv[0][0] == 'r') ? true : false;
return CMD_SUCCESS;
}
DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd,
"rrlp mode (none|ms-based|ms-preferred|ass-preferred)",
"Radio Resource Location Protocol\n"
"Set the Radio Resource Location Protocol Mode\n"
"Don't send RRLP request\n"
"Request MS-based location\n"
"Request any location, prefer MS-based\n"
"Request any location, prefer MS-assisted\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
gsmnet->rrlp.mode = rrlp_mode_parse(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_mm_info, cfg_net_mm_info_cmd,
"mm info (0|1)",
"Mobility Management\n"
"Send MM INFO after LOC UPD ACCEPT\n"
"Disable\n" "Enable\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
gsmnet->send_mm_info = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_timezone,
cfg_net_timezone_cmd,
"timezone <-19-19> (0|15|30|45)",
"Set the Timezone Offset of the network\n"
"Timezone offset (hours)\n"
"Timezone offset (00 minutes)\n"
"Timezone offset (15 minutes)\n"
"Timezone offset (30 minutes)\n"
"Timezone offset (45 minutes)\n"
)
{
struct gsm_network *net = vty->index;
int tzhr = atoi(argv[0]);
int tzmn = atoi(argv[1]);
net->tz.hr = tzhr;
net->tz.mn = tzmn;
net->tz.dst = 0;
net->tz.override = 1;
return CMD_SUCCESS;
}
DEFUN(cfg_net_timezone_dst,
cfg_net_timezone_dst_cmd,
"timezone <-19-19> (0|15|30|45) <0-2>",
"Set the Timezone Offset of the network\n"
"Timezone offset (hours)\n"
"Timezone offset (00 minutes)\n"
"Timezone offset (15 minutes)\n"
"Timezone offset (30 minutes)\n"
"Timezone offset (45 minutes)\n"
"DST offset (hours)\n"
)
{
struct gsm_network *net = vty->index;
int tzhr = atoi(argv[0]);
int tzmn = atoi(argv[1]);
int tzdst = atoi(argv[2]);
net->tz.hr = tzhr;
net->tz.mn = tzmn;
net->tz.dst = tzdst;
net->tz.override = 1;
return CMD_SUCCESS;
}
DEFUN(cfg_net_no_timezone,
cfg_net_no_timezone_cmd,
"no timezone",
NO_STR
"Disable network timezone override, use system tz\n")
{
struct gsm_network *net = vty->index;
net->tz.override = 0;
return CMD_SUCCESS;
}
DEFUN(cfg_net_per_loc_upd, cfg_net_per_loc_upd_cmd,
"periodic location update <6-1530>",
"Periodic Location Updating Interval\n"
"Periodic Location Updating Interval\n"
"Periodic Location Updating Interval\n"
"Periodic Location Updating Interval in Minutes\n")
{
struct gsm_network *net = vty->index;
net->t3212 = atoi(argv[0]) / 6;
return CMD_SUCCESS;
}
DEFUN(cfg_net_no_per_loc_upd, cfg_net_no_per_loc_upd_cmd,
"no periodic location update",
NO_STR
"Periodic Location Updating Interval\n"
"Periodic Location Updating Interval\n"
"Periodic Location Updating Interval\n")
{
struct gsm_network *net = vty->index;
net->t3212 = 0;
return CMD_SUCCESS;
}
static struct gsm_network *vty_global_gsm_network = NULL;
/* initialize VTY elements used in both BSC and MSC */
int common_cs_vty_init(struct gsm_network *network,
int (* config_write_net )(struct vty *))
{
OSMO_ASSERT(vty_global_gsm_network == NULL);
vty_global_gsm_network = network;
osmo_stats_vty_add_cmds();
install_element(CONFIG_NODE, &cfg_net_cmd);
install_node(&net_node, config_write_net);
install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
install_element(GSMNET_NODE, &cfg_net_authentication_cmd);
install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd);
install_element(GSMNET_NODE, &cfg_net_mm_info_cmd);
install_element(GSMNET_NODE, &cfg_net_timezone_cmd);
install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd);
install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd);
install_element(GSMNET_NODE, &cfg_net_per_loc_upd_cmd);
install_element(GSMNET_NODE, &cfg_net_no_per_loc_upd_cmd);
return CMD_SUCCESS;
}
struct gsm_network *gsmnet_from_vty(struct vty *v)
{
/* It can't hurt to force callers to continue to pass the vty instance
* to this function, in case we'd like to retrieve the global
* gsm_network instance from the vty at some point in the future. But
* until then, just return the global pointer, which should have been
* initialized by common_cs_vty_init().
*/
OSMO_ASSERT(vty_global_gsm_network);
return vty_global_gsm_network;
}

View File

@ -21,7 +21,6 @@ noinst_LIBRARIES = \
libcommon_a_SOURCES = \
bsc_version.c \
common_vty.c \
debug.c \
gsm_data.c \
gsup_client.c \

View File

@ -1,82 +0,0 @@
/* OpenBSC VTY common helpers */
/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
* (C) 2009-2010 by Holger Hans Peter Freyther
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* 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
* (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
* GNU Affero General Public License for more details.
*
* 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/>.
*
*/
#include <stdlib.h>
#include <string.h>
#include <osmocom/core/talloc.h>
#include <osmocom/msc/vty.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/debug.h>
#include <osmocom/msc/gsm_subscriber.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/buffer.h>
#include <osmocom/vty/vty.h>
#include <osmocom/sigtran/osmo_ss7.h>
int bsc_vty_go_parent(struct vty *vty)
{
switch (vty->node) {
case GSMNET_NODE:
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
case SMPP_ESME_NODE:
vty->node = SMPP_NODE;
vty->index = NULL;
break;
case SMPP_NODE:
case MSC_NODE:
case MNCC_INT_NODE:
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
case SUBSCR_NODE:
vty->node = ENABLE_NODE;
vty->index = NULL;
break;
default:
osmo_ss7_vty_go_parent(vty);
}
return vty->node;
}
int bsc_vty_is_config_node(struct vty *vty, int node)
{
/* Check if libosmo-sccp declares the node in
* question as config node */
if (osmo_ss7_is_config_node(vty, node))
return 1;
switch (node) {
/* add items that are not config */
case SUBSCR_NODE:
case CONFIG_NODE:
return 0;
default:
return 1;
}
}

View File

@ -44,7 +44,6 @@ libmsc_a_SOURCES = \
silent_call.c \
sms_queue.c \
ussd.c \
vty_interface_layer3.c \
transaction.c \
osmo_msc.c \
ctrl_commands.c \

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -267,13 +267,57 @@ static void db_sync_timer_cb(void *data)
osmo_timer_schedule(&db_sync_timer, DB_SYNC_INTERVAL);
}
extern int bsc_vty_go_parent(struct vty *vty);
static int msc_vty_go_parent(struct vty *vty)
{
switch (vty->node) {
case GSMNET_NODE:
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
case SMPP_ESME_NODE:
vty->node = SMPP_NODE;
vty->index = NULL;
break;
case SMPP_NODE:
case MSC_NODE:
case MNCC_INT_NODE:
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
case SUBSCR_NODE:
vty->node = ENABLE_NODE;
vty->index = NULL;
break;
default:
osmo_ss7_vty_go_parent(vty);
}
return vty->node;
}
static int msc_vty_is_config_node(struct vty *vty, int node)
{
/* Check if libosmo-sccp declares the node in
* question as config node */
if (osmo_ss7_is_config_node(vty, node))
return 1;
switch (node) {
/* add items that are not config */
case SUBSCR_NODE:
case CONFIG_NODE:
return 0;
default:
return 1;
}
}
static struct vty_app_info msc_vty_info = {
.name = "OsmoMSC",
.version = PACKAGE_VERSION,
.go_parent_cb = bsc_vty_go_parent,
.is_config_node = bsc_vty_is_config_node,
.go_parent_cb = msc_vty_go_parent,
.is_config_node = msc_vty_is_config_node,
};
#ifdef BUILD_IU
@ -396,7 +440,6 @@ int main(int argc, char **argv)
logging_vty_add_cmds(&log_info);
osmo_talloc_vty_add_cmds();
msc_vty_init(msc_network);
bsc_vty_init_extra();
#ifdef BUILD_SMPP
if (smpp_openbsc_alloc_init(tall_msc_ctx) < 0)