From fc83a36cbd00ea06ec7053b5fbe628556cc3d9c1 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Tue, 19 Jul 2011 12:12:10 +0200 Subject: libctrl: Use inttypes.h macros to make uint64_t printfs portable. --- openbsc/src/libctrl/control_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openbsc/src/libctrl/control_if.c b/openbsc/src/libctrl/control_if.c index 0e625cd79..91c69e094 100644 --- a/openbsc/src/libctrl/control_if.c +++ b/openbsc/src/libctrl/control_if.c @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -365,7 +366,7 @@ static char *get_all_rate_ctr_in_group(const struct rate_ctr_group *ctrg, int in return NULL; for (i=0;idesc->num_ctr;i++) { - counters = talloc_asprintf_append(counters, "\n%s.%u.%s %lu", + counters = talloc_asprintf_append(counters, "\n%s.%u.%s %"PRIu64, ctrg->desc->group_name_prefix, ctrg->idx, ctrg->desc->ctr_desc[i].name, get_rate_ctr_value(&ctrg->ctr[i], intv)); -- cgit v1.2.3 From 1c33d4c00d780fccede8216a22c702c399c67f21 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Tue, 19 Jul 2011 12:14:34 +0200 Subject: libcommon: Add DCTRL logging destination for libctrl related messages --- openbsc/include/openbsc/debug.h | 1 + openbsc/src/libcommon/debug.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/openbsc/include/openbsc/debug.h b/openbsc/include/openbsc/debug.h index ff4aec1d5..d78252a93 100644 --- a/openbsc/include/openbsc/debug.h +++ b/openbsc/include/openbsc/debug.h @@ -35,6 +35,7 @@ enum { DLLC, DSNDCP, DNAT, + DCTRL, Debug_LastEntry, }; diff --git a/openbsc/src/libcommon/debug.c b/openbsc/src/libcommon/debug.c index 1372150c8..479390c10 100644 --- a/openbsc/src/libcommon/debug.c +++ b/openbsc/src/libcommon/debug.c @@ -175,6 +175,11 @@ static const struct log_info_cat default_categories[] = { .description = "GSM 08.08 NAT/Multipkexer", .enabled = 1, .loglevel = LOGL_NOTICE, }, + [DCTRL] = { + .name = "DCTRL", + .description = "Control interface", + .enabled = 1, .loglevel = LOGL_NOTICE, + }, }; enum log_filter { -- cgit v1.2.3 From 44fb151c12e53672002670eea9d6475f27f6b22c Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Sat, 16 Jul 2011 21:05:43 +0200 Subject: osmo-bsc: Compare char * with NULL instead of 0 --- openbsc/src/osmo-bsc/osmo_bsc_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c index 2a4ed1aa7..3a2306c94 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_main.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c @@ -233,7 +233,8 @@ int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data) lonstr = strtok_r(NULL, ",", &saveptr); heightstr = strtok_r(NULL, "\0", &saveptr); - if ((agestr == 0) || (latstr == 0) || (lonstr == 0) || (heightstr == 0)) + if ((agestr == NULL) || (latstr == NULL) || + (lonstr == NULL) || (heightstr == NULL)) ret = 1; age = atol(agestr); -- cgit v1.2.3 From 6d718c054ad2bce52548bcac1def61085a15391c Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Sat, 16 Jul 2011 21:50:13 +0200 Subject: osmo-bsc: Improve return handling in verify_net_loc --- openbsc/src/osmo-bsc/osmo_bsc_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c index 3a2306c94..1b914688e 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_main.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c @@ -220,7 +220,6 @@ oom: int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data) { char *saveptr, *latstr, *lonstr, *heightstr, *agestr, *tmp; - int ret = 0; unsigned long age; double lat, lon, height; @@ -235,7 +234,7 @@ int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data) if ((agestr == NULL) || (latstr == NULL) || (lonstr == NULL) || (heightstr == NULL)) - ret = 1; + return 1; age = atol(agestr); lat = atof(latstr); @@ -246,7 +245,7 @@ int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data) if ((age == 0) || (lat < -90) || (lat > 90) || (lon < -180) || (lon > 180)) return 1; - return ret; + return 0; } CTRL_CMD_DEFINE(trx_rf_lock, "rf_locked"); -- cgit v1.2.3 From fa2218cbc90345fc2f4c9505cbfe48e8095a8b20 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Fri, 24 Jun 2011 04:16:03 +0200 Subject: osmo-bsc: Add valid field to location command --- openbsc/src/osmo-bsc/osmo_bsc_main.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c index 1b914688e..4ae37a1a9 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_main.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c @@ -171,10 +171,11 @@ static void signal_handler(int signal) } struct location { + unsigned long age; + int valid; double lat; double lon; double height; - unsigned long age; }; static struct location myloc; @@ -182,7 +183,7 @@ static struct location myloc; CTRL_CMD_DEFINE(net_loc, "location"); int get_net_loc(struct ctrl_cmd *cmd, void *data) { - cmd->reply = talloc_asprintf(cmd, "%lu,%f,%f,%f", myloc.age, myloc.lat, myloc.lon, myloc.height); + 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; @@ -193,7 +194,7 @@ int get_net_loc(struct ctrl_cmd *cmd, void *data) int set_net_loc(struct ctrl_cmd *cmd, void *data) { - char *saveptr, *lat, *lon, *height, *age, *tmp; + char *saveptr, *lat, *lon, *height, *age, *valid, *tmp; tmp = talloc_strdup(cmd, cmd->value); if (!tmp) @@ -201,11 +202,13 @@ int set_net_loc(struct ctrl_cmd *cmd, void *data) 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); @@ -219,8 +222,9 @@ oom: int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data) { - char *saveptr, *latstr, *lonstr, *heightstr, *agestr, *tmp; + char *saveptr, *latstr, *lonstr, *heightstr, *agestr, *validstr, *tmp; unsigned long age; + int valid; double lat, lon, height; tmp = talloc_strdup(cmd, value); @@ -228,21 +232,24 @@ int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data) 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) || (latstr == NULL) || + 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) || (lat < -90) || (lat > 90) || (lon < -180) || (lon > 180)) + if ((age == 0) || (lat < -90) || (lat > 90) || (lon < -180) || + (lon > 180) || (valid < 0) || (valid > 2)) return 1; return 0; -- cgit v1.2.3 From 3118191f59c066ec47e5e34c5ce28677b4351399 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Thu, 30 Jun 2011 11:03:07 +0200 Subject: osmo_bsc: Track the last three locations. --- openbsc/src/osmo-bsc/osmo_bsc_main.c | 54 +++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c index 4ae37a1a9..69622bbe8 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_main.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -171,6 +172,7 @@ static void signal_handler(int signal) } struct location { + struct llist_head list; unsigned long age; int valid; double lat; @@ -178,12 +180,38 @@ struct location { double height; }; -static struct location myloc; +static LLIST_HEAD(locations); + +void cleanup_locations() +{ + struct location *myloc, *tmp; + int 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); + } + } + LOGP(DCTRL, LOGL_DEBUG, "Found %i positions.\n", i); +} CTRL_CMD_DEFINE(net_loc, "location"); int get_net_loc(struct ctrl_cmd *cmd, void *data) { - cmd->reply = talloc_asprintf(cmd, "%lu,%i,%f,%f,%f", myloc.age, myloc.valid, myloc.lat, myloc.lon, myloc.height); + 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; @@ -195,11 +223,19 @@ int get_net_loc(struct ctrl_cmd *cmd, void *data) int set_net_loc(struct ctrl_cmd *cmd, void *data) { char *saveptr, *lat, *lon, *height, *age, *valid, *tmp; + struct location *myloc; 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); @@ -207,13 +243,17 @@ int set_net_loc(struct ctrl_cmd *cmd, void *data) 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); + myloc->age = atol(age); + myloc->valid = atoi(valid); + myloc->lat = atof(lat); + myloc->lon = atof(lon); + myloc->height = atof(height); talloc_free(tmp); + /* Add location to the end of the list */ + llist_add(&myloc->list, &locations); + cleanup_locations(); + return get_net_loc(cmd, data); oom: cmd->reply = "OOM"; -- cgit v1.2.3 From 8d9876e1ba158a569d543b08d122016f19e76108 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Thu, 14 Jul 2011 12:12:01 +0200 Subject: osmo-bsc: Only keep the newest of subsequent invalid positions --- openbsc/src/osmo-bsc/osmo_bsc_main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c index 69622bbe8..7d376ef0e 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_main.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c @@ -185,7 +185,7 @@ static LLIST_HEAD(locations); void cleanup_locations() { struct location *myloc, *tmp; - int i = 0; + int invalpos = 0, i = 0; LOGP(DCTRL, LOGL_DEBUG, "Checking position list.\n"); llist_for_each_entry_safe(myloc, tmp, &locations, list) { @@ -194,6 +194,17 @@ void cleanup_locations() 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); -- cgit v1.2.3