aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-23 16:25:16 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-23 16:25:16 +0100
commit49f9e5b6b42cae9f6083e5c69c70af0b29b15b23 (patch)
tree544aefa178f61484e1233ffbf83c02d43db30ec1
parentd883db027bb75cb4299a733d005de6ff6a1f426c (diff)
ctrl: Move the lookup into a separate file in preparation for GPRS
For GPRS the look-up via bts/trx does not make any sense and would introduce bad depdencies for the SGSN. Move the look-up code to a new file and introduce new setup methods.
-rw-r--r--openbsc/include/openbsc/control_cmd.h1
-rw-r--r--openbsc/include/openbsc/control_if.h12
-rw-r--r--openbsc/src/libbsc/Makefile.am3
-rw-r--r--openbsc/src/libbsc/bsc_ctrl_lookup.c179
-rw-r--r--openbsc/src/libctrl/control_if.c153
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_main.c2
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_msc.c3
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c2
-rw-r--r--openbsc/src/osmo-nitb/bsc_hack.c2
9 files changed, 200 insertions, 157 deletions
diff --git a/openbsc/include/openbsc/control_cmd.h b/openbsc/include/openbsc/control_cmd.h
index cd7b7b6d3..725dce061 100644
--- a/openbsc/include/openbsc/control_cmd.h
+++ b/openbsc/include/openbsc/control_cmd.h
@@ -77,7 +77,6 @@ struct ctrl_cmd_map {
int ctrl_cmd_exec(vector vline, struct ctrl_cmd *command, vector node, void *data);
int ctrl_cmd_install(enum ctrl_node_type node, struct ctrl_cmd_element *cmd);
-int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data);
int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd);
int ctrl_cmd_send_to_all(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd);
struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg);
diff --git a/openbsc/include/openbsc/control_if.h b/openbsc/include/openbsc/control_if.h
index 6afc86d76..d103332a9 100644
--- a/openbsc/include/openbsc/control_if.h
+++ b/openbsc/include/openbsc/control_if.h
@@ -5,17 +5,25 @@
#include <openbsc/control_cmd.h>
#include <openbsc/gsm_data.h>
+typedef int (*ctrl_cmd_handler)(struct ctrl_cmd *, void *);
+
struct ctrl_handle {
struct osmo_fd listen_fd;
struct gsm_network *gsmnet;
+ ctrl_cmd_handler handler;
+
/* List of control connections */
struct llist_head ccon_list;
};
+
int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd);
-int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data);
-struct ctrl_handle *controlif_setup(struct gsm_network *gsmnet, uint16_t port);
+struct ctrl_handle *controlif_setup(struct gsm_network *, uint16_t port,
+ ctrl_cmd_handler handler);
+struct ctrl_handle *bsc_controlif_setup(struct gsm_network *gsmnet, uint16_t port);
+
+int bsc_ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data);
#endif /* _CONTROL_IF_H */
diff --git a/openbsc/src/libbsc/Makefile.am b/openbsc/src/libbsc/Makefile.am
index 53300912c..0c22662f1 100644
--- a/openbsc/src/libbsc/Makefile.am
+++ b/openbsc/src/libbsc/Makefile.am
@@ -22,5 +22,6 @@ libbsc_a_SOURCES = abis_nm.c abis_nm_vty.c \
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 bsc_ctrl_commands.c
+ arfcn_range_encode.c bsc_ctrl_commands.c \
+ bsc_ctrl_lookup.c
diff --git a/openbsc/src/libbsc/bsc_ctrl_lookup.c b/openbsc/src/libbsc/bsc_ctrl_lookup.c
new file mode 100644
index 000000000..338fb1154
--- /dev/null
+++ b/openbsc/src/libbsc/bsc_ctrl_lookup.c
@@ -0,0 +1,179 @@
+/* SNMP-like status interface. Look-up of BTS/TRX
+ *
+ * (C) 2010-2011 by Daniel Willmann <daniel@totalueberwachung.de>
+ * (C) 2010-2011 by On-Waves
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <openbsc/control_if.h>
+#include <openbsc/debug.h>
+
+extern vector ctrl_node_vec;
+
+static int get_num(vector vline, int i, long *num)
+{
+ char *token, *tmp;
+
+ if (i >= vector_active(vline))
+ return 0;
+ token = vector_slot(vline, i);
+
+ errno = 0;
+ if (token[0] == '\0')
+ return 0;
+
+ *num = strtol(token, &tmp, 10);
+ if (tmp[0] != '\0' || errno != 0)
+ return 0;
+
+ return 1;
+}
+
+int bsc_ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
+{
+ char *token, *request;
+ long num;
+ int i, j, ret, node;
+
+ struct gsm_network *net = data;
+ struct gsm_bts *bts = NULL;
+ struct gsm_bts_trx *trx = NULL;
+ struct gsm_bts_trx_ts *ts = NULL;
+ vector vline, cmdvec, cmds_vec;
+
+ ret = CTRL_CMD_ERROR;
+ cmd->reply = NULL;
+ node = CTRL_NODE_ROOT;
+ cmd->node = net;
+
+ request = talloc_strdup(tall_bsc_ctx, cmd->variable);
+ if (!request)
+ goto err;
+
+ for (i=0;i<strlen(request);i++) {
+ if (request[i] == '.')
+ request[i] = ' ';
+ }
+
+ vline = cmd_make_strvec(request);
+ talloc_free(request);
+ if (!vline) {
+ cmd->reply = "cmd_make_strvec failed.";
+ goto err;
+ }
+
+ for (i=0;i<vector_active(vline);i++) {
+ token = vector_slot(vline, i);
+ /* TODO: We need to make sure that the following chars are digits
+ * and/or use strtol to check if number conversion was successful
+ * Right now something like net.bts_stats will not work */
+ if (!strcmp(token, "bts")) {
+ if (!net)
+ goto err_missing;
+ i++;
+ if (!get_num(vline, i, &num))
+ goto err_index;
+
+ bts = gsm_bts_num(net, num);
+ if (!bts)
+ goto err_missing;
+ cmd->node = bts;
+ node = CTRL_NODE_BTS;
+ } else if (!strcmp(token, "trx")) {
+ if (!bts)
+ goto err_missing;
+ i++;
+ if (!get_num(vline, i, &num))
+ goto err_index;
+
+ trx = gsm_bts_trx_num(bts, num);
+ if (!trx)
+ goto err_missing;
+ cmd->node = trx;
+ node = CTRL_NODE_TRX;
+ } else if (!strcmp(token, "ts")) {
+ if (!trx)
+ goto err_missing;
+ i++;
+ if (!get_num(vline, i, &num))
+ goto err_index;
+
+ if ((num >= 0) && (num < TRX_NR_TS))
+ ts = &trx->ts[num];
+ if (!ts)
+ goto err_missing;
+ cmd->node = ts;
+ node = CTRL_NODE_TS;
+ } else {
+ /* If we're here the rest must be the command */
+ cmdvec = vector_init(vector_active(vline)-i);
+ for (j=i; j<vector_active(vline); j++) {
+ vector_set(cmdvec, vector_slot(vline, j));
+ }
+
+ /* Get the command vector of the right node */
+ cmds_vec = vector_lookup(ctrl_node_vec, node);
+
+ if (!cmds_vec) {
+ cmd->reply = "Command not found.";
+ vector_free(cmdvec);
+ break;
+ }
+
+ ret = ctrl_cmd_exec(cmdvec, cmd, cmds_vec, data);
+
+ vector_free(cmdvec);
+ break;
+ }
+
+ if (i+1 == vector_active(vline))
+ cmd->reply = "Command not present.";
+ }
+
+ cmd_free_strvec(vline);
+
+err:
+ if (!cmd->reply) {
+ LOGP(DCTRL, LOGL_ERROR, "cmd->reply has not been set.\n");
+ if (ret == CTRL_CMD_ERROR)
+ cmd->reply = "An error has occured.";
+ else
+ cmd->reply = "Command has been handled.";
+ }
+
+ if (ret == CTRL_CMD_ERROR)
+ cmd->type = CTRL_TYPE_ERROR;
+ return ret;
+
+err_missing:
+ cmd_free_strvec(vline);
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "Error while resolving object";
+ return ret;
+err_index:
+ cmd_free_strvec(vline);
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "Error while parsing the index.";
+ return ret;
+}
+
+struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port)
+{
+ return controlif_setup(net, port, bsc_ctrl_cmd_handle);
+}
diff --git a/openbsc/src/libctrl/control_if.c b/openbsc/src/libctrl/control_if.c
index b5db31da2..2727d0dd3 100644
--- a/openbsc/src/libctrl/control_if.c
+++ b/openbsc/src/libctrl/control_if.c
@@ -115,153 +115,6 @@ struct ctrl_cmd *ctrl_cmd_trap(struct ctrl_cmd *cmd)
return trap;
}
-static int get_num(vector vline, int i, long *num)
-{
- char *token, *tmp;
-
- if (i >= vector_active(vline))
- return 0;
- token = vector_slot(vline, i);
-
- errno = 0;
- if (token[0] == '\0')
- return 0;
-
- *num = strtol(token, &tmp, 10);
- if (tmp[0] != '\0' || errno != 0)
- return 0;
-
- return 1;
-}
-
-int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
-{
- char *token, *request;
- long num;
- int i, j, ret, node;
-
- struct gsm_network *net = data;
- struct gsm_bts *bts = NULL;
- struct gsm_bts_trx *trx = NULL;
- struct gsm_bts_trx_ts *ts = NULL;
- vector vline, cmdvec, cmds_vec;
-
- ret = CTRL_CMD_ERROR;
- cmd->reply = NULL;
- node = CTRL_NODE_ROOT;
- cmd->node = net;
-
- request = talloc_strdup(tall_bsc_ctx, cmd->variable);
- if (!request)
- goto err;
-
- for (i=0;i<strlen(request);i++) {
- if (request[i] == '.')
- request[i] = ' ';
- }
-
- vline = cmd_make_strvec(request);
- talloc_free(request);
- if (!vline) {
- cmd->reply = "cmd_make_strvec failed.";
- goto err;
- }
-
- for (i=0;i<vector_active(vline);i++) {
- token = vector_slot(vline, i);
- /* TODO: We need to make sure that the following chars are digits
- * and/or use strtol to check if number conversion was successful
- * Right now something like net.bts_stats will not work */
- if (!strcmp(token, "bts")) {
- if (!net)
- goto err_missing;
- i++;
- if (!get_num(vline, i, &num))
- goto err_index;
-
- bts = gsm_bts_num(net, num);
- if (!bts)
- goto err_missing;
- cmd->node = bts;
- node = CTRL_NODE_BTS;
- } else if (!strcmp(token, "trx")) {
- if (!bts)
- goto err_missing;
- i++;
- if (!get_num(vline, i, &num))
- goto err_index;
-
- trx = gsm_bts_trx_num(bts, num);
- if (!trx)
- goto err_missing;
- cmd->node = trx;
- node = CTRL_NODE_TRX;
- } else if (!strcmp(token, "ts")) {
- if (!trx)
- goto err_missing;
- i++;
- if (!get_num(vline, i, &num))
- goto err_index;
-
- if ((num >= 0) && (num < TRX_NR_TS))
- ts = &trx->ts[num];
- if (!ts)
- goto err_missing;
- cmd->node = ts;
- node = CTRL_NODE_TS;
- } else {
- /* If we're here the rest must be the command */
- cmdvec = vector_init(vector_active(vline)-i);
- for (j=i; j<vector_active(vline); j++) {
- vector_set(cmdvec, vector_slot(vline, j));
- }
-
- /* Get the command vector of the right node */
- cmds_vec = vector_lookup(ctrl_node_vec, node);
-
- if (!cmds_vec) {
- cmd->reply = "Command not found.";
- vector_free(cmdvec);
- break;
- }
-
- ret = ctrl_cmd_exec(cmdvec, cmd, cmds_vec, data);
-
- vector_free(cmdvec);
- break;
- }
-
- if (i+1 == vector_active(vline))
- cmd->reply = "Command not present.";
- }
-
- cmd_free_strvec(vline);
-
-err:
- if (!cmd->reply) {
- LOGP(DCTRL, LOGL_ERROR, "cmd->reply has not been set.\n");
- if (ret == CTRL_CMD_ERROR)
- cmd->reply = "An error has occured.";
- else
- cmd->reply = "Command has been handled.";
- }
-
- if (ret == CTRL_CMD_ERROR)
- cmd->type = CTRL_TYPE_ERROR;
- return ret;
-
-err_missing:
- cmd_free_strvec(vline);
- cmd->type = CTRL_TYPE_ERROR;
- cmd->reply = "Error while resolving object";
- return ret;
-err_index:
- cmd_free_strvec(vline);
- cmd->type = CTRL_TYPE_ERROR;
- cmd->reply = "Error while parsing the index.";
- return ret;
-}
-
static void control_close_conn(struct ctrl_connection *ccon)
{
osmo_wqueue_clear(&ccon->write_queue);
@@ -320,7 +173,7 @@ static int handle_control_read(struct osmo_fd * bfd)
if (cmd) {
cmd->ccon = ccon;
- if (ctrl_cmd_handle(cmd, ctrl->gsmnet) != CTRL_CMD_HANDLED) {
+ if (ctrl->handler(cmd, ctrl->gsmnet) != CTRL_CMD_HANDLED) {
ctrl_cmd_send(queue, cmd);
talloc_free(cmd);
}
@@ -675,7 +528,8 @@ static int verify_counter(struct ctrl_cmd *cmd, const char *value, void *data)
return 0;
}
-struct ctrl_handle *controlif_setup(struct gsm_network *gsmnet, uint16_t port)
+struct ctrl_handle *controlif_setup(struct gsm_network *gsmnet, uint16_t port,
+ ctrl_cmd_handler handler)
{
int ret;
struct ctrl_handle *ctrl;
@@ -687,6 +541,7 @@ struct ctrl_handle *controlif_setup(struct gsm_network *gsmnet, uint16_t port)
INIT_LLIST_HEAD(&ctrl->ccon_list);
ctrl->gsmnet = gsmnet;
+ ctrl->handler = handler;
ctrl_node_vec = vector_init(5);
if (!ctrl_node_vec)
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c
index 84186a6a5..f701089ab 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -212,7 +212,7 @@ int main(int argc, char **argv)
}
bsc_api_init(bsc_gsmnet, osmo_bsc_api());
- bsc_gsmnet->ctrl = controlif_setup(bsc_gsmnet, 4249);
+ bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, 4249);
if (!bsc_gsmnet) {
fprintf(stderr, "Failed to init the control interface. Exiting.\n");
exit(1);
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_msc.c b/openbsc/src/osmo-bsc/osmo_bsc_msc.c
index 5517d3080..603398551 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_msc.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_msc.c
@@ -22,6 +22,7 @@
#include <openbsc/bsc_nat.h>
#include <openbsc/control_cmd.h>
+#include <openbsc/control_if.h>
#include <openbsc/debug.h>
#include <openbsc/gsm_data.h>
#include <openbsc/ipaccess.h>
@@ -217,7 +218,7 @@ static void handle_ctrl(struct osmo_msc_data *msc, struct msgb *msg)
return;
}
- ret = ctrl_cmd_handle(cmd, msc->network);
+ ret = bsc_ctrl_cmd_handle(cmd, msc->network);
if (ret != CTRL_CMD_HANDLED)
ctrl_cmd_send(&msc->msc_con->write_queue, cmd);
talloc_free(cmd);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
index 2836a1956..b9a1eadf4 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
@@ -380,7 +380,7 @@ struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port)
int rc;
- ctrl = controlif_setup(NULL, 4250);
+ ctrl = bsc_controlif_setup(NULL, 4250);
if (!ctrl) {
fprintf(stderr, "Failed to initialize the control interface. Exiting.\n");
return NULL;
diff --git a/openbsc/src/osmo-nitb/bsc_hack.c b/openbsc/src/osmo-nitb/bsc_hack.c
index c78e3ec81..61141fdb0 100644
--- a/openbsc/src/osmo-nitb/bsc_hack.c
+++ b/openbsc/src/osmo-nitb/bsc_hack.c
@@ -284,7 +284,7 @@ int main(int argc, char **argv)
#endif
bsc_api_init(bsc_gsmnet, msc_bsc_api());
- bsc_gsmnet->ctrl = controlif_setup(bsc_gsmnet, 4249);
+ bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, 4249);
if (!bsc_gsmnet->ctrl) {
printf("Failed to initialize control interface. Exiting.\n");
return -1;