aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-08-05 14:08:58 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-09-11 16:20:37 +0200
commita5352a017412bde12461bbb48f731c4683673af3 (patch)
tree509c3c24fe0da10aa186cddcf5e7a0bd43b726af
parent47b5b3eeb2e8e9081e809e860dc5c201c9a0bb1b (diff)
osmo-bsc: Change variable name to better reflect current/last location
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_ctrl.c91
1 files changed, 43 insertions, 48 deletions
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
index 6bab46111..d6a569177 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
@@ -53,47 +53,32 @@ void osmo_bsc_send_trap(struct ctrl_cmd *cmd, struct bsc_msc_connection *msc_con
talloc_free(trap);
}
-#define LOC_FIX_INVALID 0
-#define LOC_FIX_2D 1
-#define LOC_FIX_3D 2
-
static const struct value_string valid_names[] = {
- { LOC_FIX_INVALID, "invalid" },
- { LOC_FIX_2D, "fix2d" },
- { LOC_FIX_3D, "fix3d" },
+ { BTS_LOC_FIX_INVALID, "invalid" },
+ { BTS_LOC_FIX_2D, "fix2d" },
+ { BTS_LOC_FIX_3D, "fix3d" },
{ 0, NULL }
};
-struct location {
- struct llist_head list;
- time_t tstamp;
- int valid;
- double lat;
- double lon;
- double height;
-};
-
-static int location_equal(struct location *a, struct location *b)
+static int location_equal(struct bts_location *a, struct bts_location *b)
{
return ((a->tstamp == b->tstamp) && (a->valid == b->valid) && (a->lat == b->lat) &&
(a->lon == b->lon) && (a->height == b->height));
}
-static LLIST_HEAD(locations);
-
-static void cleanup_locations()
+static void cleanup_locations(struct llist_head *locations)
{
- struct location *myloc, *tmp;
+ struct bts_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) {
+ 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 == LOC_FIX_INVALID) {
+ } else if (myloc->valid == BTS_LOC_FIX_INVALID) {
/* Only capture the newest of subsequent invalid positions */
invalpos++;
if (invalpos > 1) {
@@ -110,20 +95,25 @@ static void cleanup_locations()
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)
+CTRL_CMD_DEFINE(bts_loc, "location");
+static int get_bts_loc(struct ctrl_cmd *cmd, void *data)
{
- struct location *myloc;
+ struct bts_location *curloc;
+ struct gsm_bts *bts = (struct gsm_bts *) cmd->node;
+ if (!bts) {
+ cmd->reply = "bts not found.";
+ return CTRL_CMD_ERROR;
+ }
- if (llist_empty(&locations)) {
+ if (llist_empty(&bts->loc_list)) {
cmd->reply = talloc_asprintf(cmd, "0,invalid,0,0,0");
return CTRL_CMD_REPLY;
} else {
- myloc = llist_entry(locations.next, struct location, list);
+ curloc = llist_entry(bts->loc_list.next, struct bts_location, list);
}
- cmd->reply = talloc_asprintf(cmd, "%lu,%s,%f,%f,%f", myloc->tstamp,
- get_value_string(valid_names, myloc->valid), myloc->lat, myloc->lon, myloc->height);
+ cmd->reply = talloc_asprintf(cmd, "%lu,%s,%f,%f,%f", curloc->tstamp,
+ get_value_string(valid_names, curloc->valid), curloc->lat, curloc->lon, curloc->height);
if (!cmd->reply) {
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
@@ -132,24 +122,29 @@ static int get_net_loc(struct ctrl_cmd *cmd, void *data)
return CTRL_CMD_REPLY;
}
-static int set_net_loc(struct ctrl_cmd *cmd, void *data)
+static int set_bts_loc(struct ctrl_cmd *cmd, void *data)
{
char *saveptr, *lat, *lon, *height, *tstamp, *valid, *tmp;
struct osmo_msc_data *msc;
- struct location *myloc, *lastloc;
+ struct bts_location *curloc, *lastloc;
int ret;
struct gsm_network *gsmnet = (struct gsm_network *)data;
+ struct gsm_bts *bts = (struct gsm_bts *) cmd->node;
+ if (!bts) {
+ cmd->reply = "bts not found.";
+ return CTRL_CMD_ERROR;
+ }
tmp = talloc_strdup(cmd, cmd->value);
if (!tmp)
goto oom;
- myloc = talloc_zero(tall_bsc_ctx, struct location);
- if (!myloc) {
+ curloc = talloc_zero(tall_bsc_ctx, struct bts_location);
+ if (!curloc) {
talloc_free(tmp);
goto oom;
}
- INIT_LLIST_HEAD(&myloc->list);
+ INIT_LLIST_HEAD(&curloc->list);
tstamp = strtok_r(tmp, ",", &saveptr);
@@ -158,25 +153,25 @@ static int set_net_loc(struct ctrl_cmd *cmd, void *data)
lon = strtok_r(NULL, ",", &saveptr);
height = strtok_r(NULL, "\0", &saveptr);
- myloc->tstamp = atol(tstamp);
- myloc->valid = get_string_value(valid_names, valid);
- myloc->lat = atof(lat);
- myloc->lon = atof(lon);
- myloc->height = atof(height);
+ curloc->tstamp = atol(tstamp);
+ curloc->valid = get_string_value(valid_names, valid);
+ curloc->lat = atof(lat);
+ curloc->lon = atof(lon);
+ curloc->height = atof(height);
talloc_free(tmp);
- lastloc = llist_entry(locations.next, struct location, list);
+ lastloc = llist_entry(bts->loc_list.next, struct bts_location, list);
/* Add location to the end of the list */
- llist_add(&myloc->list, &locations);
+ llist_add(&curloc->list, &bts->loc_list);
- ret = get_net_loc(cmd, data);
+ ret = get_bts_loc(cmd, data);
- if (!location_equal(myloc, lastloc))
+ if (!location_equal(curloc, lastloc))
llist_for_each_entry(msc, &gsmnet->bsc_data->mscs, entry)
osmo_bsc_send_trap(cmd, msc->msc_con);
- cleanup_locations();
+ cleanup_locations(&bts->loc_list);
return ret;
@@ -185,7 +180,7 @@ oom:
return CTRL_CMD_ERROR;
}
-static int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data)
+static int verify_bts_loc(struct ctrl_cmd *cmd, const char *value, void *data)
{
char *saveptr, *latstr, *lonstr, *heightstr, *tstampstr, *validstr, *tmp;
time_t tstamp;
@@ -213,7 +208,7 @@ static int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data)
height = atof(heightstr);
talloc_free(tmp);
- if (((tstamp == 0) && (valid != LOC_FIX_INVALID)) || (lat < -90) || (lat > 90) ||
+ if (((tstamp == 0) && (valid != BTS_LOC_FIX_INVALID)) || (lat < -90) || (lat > 90) ||
(lon < -180) || (lon > 180) || (valid < 0)) {
goto err;
}
@@ -308,7 +303,7 @@ int bsc_ctrl_cmds_install()
{
int rc;
- rc = ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_loc);
+ rc = ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_loc);
if (rc)
goto end;
rc = ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_rf_lock);