osmo-bsc: Put the control commands in osmo_bsc_ctrl.c
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c
index 8afd6cc..0f70ceb 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -175,261 +175,6 @@
}
}
-void osmo_bsc_send_trap(struct ctrl_cmd *cmd, struct bsc_msc_connection *msc_con)
-{
- struct ctrl_cmd *trap;
- struct ctrl_handle *ctrl;
- struct osmo_msc_data *msc_data;
-
- msc_data = (struct osmo_msc_data *) msc_con->write_queue.bfd.data;
- ctrl = msc_data->network->ctrl;
-
- trap = ctrl_cmd_trap(cmd);
- if (!trap) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to create trap.\n");
- return;
- }
-
- ctrl_cmd_send_to_all(ctrl, trap);
- ctrl_cmd_send(&msc_con->write_queue, trap);
-
- talloc_free(trap);
-}
-
-struct location {
- struct llist_head list;
- unsigned long age;
- int valid;
- double lat;
- double lon;
- double height;
-};
-
-static int location_equal(struct location *a, struct location *b)
-{
- return ((a->age == b->age) && (a->valid == b->valid) && (a->lat == b->lat) &&
- (a->lon == b->lon) && (a->height == b->height));
-}
-
-static LLIST_HEAD(locations);
-
-static void cleanup_locations()
-{
- struct location *myloc, *tmp;
- int invalpos = 0, i = 0;
-
- LOGP(DCTRL, LOGL_DEBUG, "Checking position list.\n");
- llist_for_each_entry_safe(myloc, tmp, &locations, list) {
- i++;
- if (i > 3) {
- LOGP(DCTRL, LOGL_DEBUG, "Deleting old position.\n");
- llist_del(&myloc->list);
- talloc_free(myloc);
- } else if (!myloc->valid) { /* Only capture the newest of subsequent invalid positions */
- invalpos++;
- if (invalpos > 1) {
- LOGP(DCTRL, LOGL_DEBUG, "Deleting subsequent invalid position.\n");
- invalpos--;
- i--;
- llist_del(&myloc->list);
- talloc_free(myloc);
- }
- } else {
- invalpos = 0;
- }
- }
- LOGP(DCTRL, LOGL_DEBUG, "Found %i positions.\n", i);
-}
-
-CTRL_CMD_DEFINE(net_loc, "location");
-static int get_net_loc(struct ctrl_cmd *cmd, void *data)
-{
- struct location *myloc;
-
- if (llist_empty(&locations)) {
- cmd->reply = talloc_asprintf(cmd, "0,0,0,0,0");
- return CTRL_CMD_REPLY;
- } else {
- myloc = llist_entry(locations.next, struct location, list);
- }
-
- cmd->reply = talloc_asprintf(cmd, "%lu,%i,%f,%f,%f", myloc->age, myloc->valid, myloc->lat, myloc->lon, myloc->height);
- if (!cmd->reply) {
- cmd->reply = "OOM";
- return CTRL_CMD_ERROR;
- }
-
- return CTRL_CMD_REPLY;
-}
-
-static int set_net_loc(struct ctrl_cmd *cmd, void *data)
-{
- char *saveptr, *lat, *lon, *height, *age, *valid, *tmp;
- struct osmo_msc_data *msc;
- struct location *myloc, *lastloc;
- int ret;
- struct gsm_network *gsmnet = (struct gsm_network *)data;
-
- tmp = talloc_strdup(cmd, cmd->value);
- if (!tmp)
- goto oom;
-
- myloc = talloc_zero(tall_bsc_ctx, struct location);
- if (!myloc) {
- talloc_free(tmp);
- goto oom;
- }
- INIT_LLIST_HEAD(&myloc->list);
-
-
- age = strtok_r(tmp, ",", &saveptr);
- valid = strtok_r(NULL, ",", &saveptr);
- lat = strtok_r(NULL, ",", &saveptr);
- lon = strtok_r(NULL, ",", &saveptr);
- height = strtok_r(NULL, "\0", &saveptr);
-
- myloc->age = atol(age);
- myloc->valid = atoi(valid);
- myloc->lat = atof(lat);
- myloc->lon = atof(lon);
- myloc->height = atof(height);
- talloc_free(tmp);
-
- lastloc = llist_entry(locations.next, struct location, list);
-
- /* Add location to the end of the list */
- llist_add(&myloc->list, &locations);
-
- ret = get_net_loc(cmd, data);
-
- if (!location_equal(myloc, lastloc))
- llist_for_each_entry(msc, &gsmnet->bsc_data->mscs, entry)
- osmo_bsc_send_trap(cmd, msc->msc_con);
-
- cleanup_locations();
-
- return ret;
-
-oom:
- cmd->reply = "OOM";
- return CTRL_CMD_ERROR;
-}
-
-static int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data)
-{
- char *saveptr, *latstr, *lonstr, *heightstr, *agestr, *validstr, *tmp;
- unsigned long age;
- int valid;
- double lat, lon, height;
-
- tmp = talloc_strdup(cmd, value);
- if (!tmp)
- return 1;
-
- agestr = strtok_r(tmp, ",", &saveptr);
- validstr = strtok_r(NULL, ",", &saveptr);
- latstr = strtok_r(NULL, ",", &saveptr);
- lonstr = strtok_r(NULL, ",", &saveptr);
- heightstr = strtok_r(NULL, "\0", &saveptr);
-
- if ((agestr == NULL) || (validstr == NULL) || (latstr == NULL) ||
- (lonstr == NULL) || (heightstr == NULL))
- return 1;
-
- age = atol(agestr);
- valid = atoi(validstr);
- lat = atof(latstr);
- lon = atof(lonstr);
- height = atof(heightstr);
- talloc_free(tmp);
-
- if (((age == 0) && (valid !=0)) || (lat < -90) || (lat > 90) ||
- (lon < -180) || (lon > 180) || (valid < 0) || (valid > 2))
- return 1;
-
- return 0;
-}
-
-CTRL_CMD_DEFINE(trx_rf_lock, "rf_locked");
-static int get_trx_rf_lock(struct ctrl_cmd *cmd, void *data)
-{
- struct gsm_bts_trx *trx = cmd->node;
- if (!trx) {
- cmd->reply = "trx not found.";
- return CTRL_CMD_ERROR;
- }
-
- cmd->reply = talloc_asprintf(cmd, "%u", trx->mo.nm_state.administrative == NM_STATE_LOCKED ? 1 : 0);
- return CTRL_CMD_REPLY;
-}
-
-static int set_trx_rf_lock(struct ctrl_cmd *cmd, void *data)
-{
- int locked = atoi(cmd->value);
- struct gsm_bts_trx *trx = cmd->node;
- if (!trx) {
- cmd->reply = "trx not found.";
- return CTRL_CMD_ERROR;
- }
-
- gsm_trx_lock_rf(trx, locked);
-
- return get_trx_rf_lock(cmd, data);
-}
-
-static int verify_trx_rf_lock(struct ctrl_cmd *cmd, const char *value, void *data)
-{
- int locked = atoi(cmd->value);
-
- if ((locked != 0) && (locked != 1))
- return 1;
-
- return 0;
-}
-
-CTRL_CMD_DEFINE(net_rf_lock, "rf_locked");
-static int get_net_rf_lock(struct ctrl_cmd *cmd, void *data)
-{
- cmd->reply = "get only works for the individual trx properties.";
- return CTRL_CMD_ERROR;
-}
-
-static int set_net_rf_lock(struct ctrl_cmd *cmd, void *data)
-{
- int locked = atoi(cmd->value);
- struct gsm_network *net = cmd->node;
- struct gsm_bts *bts;
- if (!net) {
- cmd->reply = "net not found.";
- return CTRL_CMD_ERROR;
- }
-
- llist_for_each_entry(bts, &net->bts_list, list) {
- struct gsm_bts_trx *trx;
- llist_for_each_entry(trx, &bts->trx_list, list) {
- gsm_trx_lock_rf(trx, locked);
- }
- }
-
- cmd->reply = talloc_asprintf(cmd, "%u", locked);
- if (!cmd->reply) {
- cmd->reply = "OOM.";
- return CTRL_CMD_ERROR;
- }
-
- return CTRL_CMD_REPLY;
-}
-
-static int verify_net_rf_lock(struct ctrl_cmd *cmd, const char *value, void *data)
-{
- int locked = atoi(cmd->value);
-
- if ((locked != 0) && (locked != 1))
- return 1;
-
- return 0;
-}
-
int main(int argc, char **argv)
{
struct osmo_msc_data *msc;
@@ -469,9 +214,7 @@
bsc_gsmnet->ctrl = controlif_setup(bsc_gsmnet, 4249);
- ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_loc);
- ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_rf_lock);
- ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_rf_lock);
+ bsc_ctrl_cmds_install();
data = bsc_gsmnet->bsc_data;
if (rf_ctrl)