aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2013-01-09 17:03:27 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2013-04-22 09:09:31 +0200
commit853b93caaee70ec1259749dca50a1e69484a7df2 (patch)
tree4aa1cbc76e4ccb528260fdfd746d713804f21c14
parent3e3c305c8a755f956cb0c5cfea2926b561306041 (diff)
nitb: Add ctrl command for MNC, MCC, short-name and long-name
Add the framework for adding more setting commands.
-rw-r--r--openbsc/src/osmo-nitb/Makefile.am2
-rw-r--r--openbsc/src/osmo-nitb/bsc_hack.c7
-rw-r--r--openbsc/src/osmo-nitb/ctrl_commands.c75
3 files changed, 83 insertions, 1 deletions
diff --git a/openbsc/src/osmo-nitb/Makefile.am b/openbsc/src/osmo-nitb/Makefile.am
index dc692323d..93e1d7ac1 100644
--- a/openbsc/src/osmo-nitb/Makefile.am
+++ b/openbsc/src/osmo-nitb/Makefile.am
@@ -7,7 +7,7 @@ AM_LDFLAGS = $(COVERAGE_LDFLAGS)
bin_PROGRAMS = osmo-nitb
-osmo_nitb_SOURCES = bsc_hack.c
+osmo_nitb_SOURCES = bsc_hack.c ctrl_commands.c
osmo_nitb_LDADD = \
$(top_builddir)/src/libbsc/libbsc.a \
$(top_builddir)/src/libmsc/libmsc.a \
diff --git a/openbsc/src/osmo-nitb/bsc_hack.c b/openbsc/src/osmo-nitb/bsc_hack.c
index 172fb8269..063d384e6 100644
--- a/openbsc/src/osmo-nitb/bsc_hack.c
+++ b/openbsc/src/osmo-nitb/bsc_hack.c
@@ -67,6 +67,8 @@ static int use_db_counter = 1;
static struct osmo_timer_list db_sync_timer;
+extern int bsc_ctrl_cmds_install(void);
+
static void create_pcap_file(char *file)
{
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
@@ -290,6 +292,11 @@ int main(int argc, char **argv)
return -1;
}
+ if (bsc_ctrl_cmds_install() != 0) {
+ printf("Failed to initialize the control commands. Exiting.\n");
+ return -1;
+ }
+
/* seed the PRNG */
srand(time(NULL));
diff --git a/openbsc/src/osmo-nitb/ctrl_commands.c b/openbsc/src/osmo-nitb/ctrl_commands.c
new file mode 100644
index 000000000..3cc434834
--- /dev/null
+++ b/openbsc/src/osmo-nitb/ctrl_commands.c
@@ -0,0 +1,75 @@
+/*
+ * (C) 2013 by Holger Hans Peter Freyther
+ * (C) 2013 by sysmocom s.f.m.c. GmbH
+ *
+ * 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 <openbsc/control_cmd.h>
+#include <openbsc/gsm_data.h>
+
+#define CTRL_CMD_VTY_STRING(cmdname, cmdstr, dtype, element) \
+ CTRL_HELPER_GET_STRING(cmdname, dtype, element) \
+ CTRL_HELPER_SET_STRING(cmdname, dtype, element) \
+static struct ctrl_cmd_element cmd_##cmdname = { \
+ .name = cmdstr, \
+ .param = NULL, \
+ .get = get_##cmdname, \
+ .set = set_##cmdname, \
+ .verify = verify_vty_description_string, \
+}
+
+/**
+ * Check that there are no newlines or comments or other things
+ * that could make the VTY configuration unparsable.
+ */
+static int verify_vty_description_string(struct ctrl_cmd *cmd,
+ const char *value, void *data)
+{
+ int i;
+ const size_t len = strlen(value);
+
+ for (i = 0; i < len; ++i) {
+ switch(value[i]) {
+ case '#':
+ case '\n':
+ case '\r':
+ cmd->reply = "String includes illegal character";
+ return -1;
+ default:
+ break;
+ }
+ }
+
+ return 0;
+}
+
+CTRL_CMD_DEFINE_RANGE(net_mnc, "mnc", struct gsm_network, network_code, 0, 999);
+CTRL_CMD_DEFINE_RANGE(net_mcc, "mcc", struct gsm_network, country_code, 1, 999);
+CTRL_CMD_VTY_STRING(net_short_name, "short-name", struct gsm_network, name_short);
+CTRL_CMD_VTY_STRING(net_long_name, "long-name", struct gsm_network, name_long);
+
+int bsc_ctrl_cmds_install(void)
+{
+ int rc = 0;
+ rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mnc);
+ rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc);
+ rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_short_name);
+ rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_long_name);
+
+ return rc;
+}