libbsc: Add ctrl command for MNC, MCC, short-name and long-name

Add the framework for adding more setting commands.
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 404dfe4..1b4720f 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -433,4 +433,7 @@
 extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
 extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
 
+/* control interface handling */
+int bsc_base_ctrl_cmds_install(void);
+
 #endif /* _GSM_DATA_H */
diff --git a/openbsc/src/libbsc/Makefile.am b/openbsc/src/libbsc/Makefile.am
index 42fabab..5330091 100644
--- a/openbsc/src/libbsc/Makefile.am
+++ b/openbsc/src/libbsc/Makefile.am
@@ -22,5 +22,5 @@
 			bsc_api.c bsc_msc.c bsc_vty.c \
 			gsm_04_08_utils.c \
 			bsc_init.c bts_init.c bsc_rf_ctrl.c \
-			arfcn_range_encode.c
+			arfcn_range_encode.c bsc_ctrl_commands.c
 
diff --git a/openbsc/src/libbsc/bsc_ctrl_commands.c b/openbsc/src/libbsc/bsc_ctrl_commands.c
new file mode 100644
index 0000000..db6e632
--- /dev/null
+++ b/openbsc/src/libbsc/bsc_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_base_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;
+}
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
index 1d0e2aa..1442cbc 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
@@ -605,6 +605,9 @@
 {
 	int rc;
 
+	rc = bsc_base_ctrl_cmds_install();
+	if (rc)
+		goto end;
 	rc = ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_rf_state);
 	if (rc)
 		goto end;
diff --git a/openbsc/src/osmo-nitb/bsc_hack.c b/openbsc/src/osmo-nitb/bsc_hack.c
index 96ae0b8..d746bf1 100644
--- a/openbsc/src/osmo-nitb/bsc_hack.c
+++ b/openbsc/src/osmo-nitb/bsc_hack.c
@@ -290,6 +290,11 @@
 		return -1;
 	}
 
+	if (bsc_base_ctrl_cmds_install() != 0) {
+		printf("Failed to initialize the control commands. Exiting.\n");
+		return -1;
+	}
+
 	/* seed the PRNG */
 	srand(time(NULL));