diff options
author | arehbein <arehbein@sysmocom.de> | 2023-01-16 01:31:32 +0100 |
---|---|---|
committer | arehbein <arehbein@sysmocom.de> | 2023-02-01 23:19:55 +0000 |
commit | 97ed3c8d971f3c231a1303efe61b3f98116f1e2f (patch) | |
tree | 6af7002c23769d1de26001142f6a399024f4579f /src | |
parent | 2e83847865fe9fddda50591a76fd04a7aa542782 (diff) |
bsc_ctrl_commands: Add GET for bts neighbor-list (local bts numbers)
Related: SYS#6287
Change-Id: I79aeffd93089086f57c66787fe20b439a4d8b6b4
Diffstat (limited to 'src')
-rw-r--r-- | src/osmo-bsc/neighbor_ident_ctrl.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/osmo-bsc/neighbor_ident_ctrl.c b/src/osmo-bsc/neighbor_ident_ctrl.c index 8e5e04875..a9d7b5dc5 100644 --- a/src/osmo-bsc/neighbor_ident_ctrl.c +++ b/src/osmo-bsc/neighbor_ident_ctrl.c @@ -21,6 +21,7 @@ */ #include <errno.h> +#include <inttypes.h> #include <time.h> #include <osmocom/ctrl/control_cmd.h> @@ -94,6 +95,44 @@ static int verify_neighbor_bts_add(struct ctrl_cmd *cmd, const char *value, void return verify_neighbor_bts(cmd, value, _data); } +static int get_neighbor_bts_list(struct ctrl_cmd *cmd, void *data) +{ + /* Max. 256 BTS neighbors (as of now, any bts can be its own neighbor per cfg) comma-separated -> + * max. 255 commas * + trailing '\0': 256 + * 10 of those numbers (0...9) are 1-digit numbers: + 10 = 266 + * 90 of those numbers are 2-digit numbers (10...99): + 90 = 356 + * 255 - 100 + 1 = 156 are 3-digit numbers (100...255): + 156 = 512 bytes + * Double BTS num entries are not possible (check exists and is being tested against in python tests). */ + char log_buf[512]; + struct osmo_strbuf reply = { .buf = log_buf, + .len = sizeof(log_buf), + .pos = log_buf + }; + struct gsm_bts *neighbor_bts, *bts = (struct gsm_bts *)cmd->node; + if (!bts) { + cmd->reply = "BTS not found"; + return CTRL_CMD_ERROR; + } + struct neighbor *n; + llist_for_each_entry(n, &bts->neighbors, entry) + if (resolve_local_neighbor(&neighbor_bts, bts, n) == 0) + OSMO_STRBUF_PRINTF(reply, "%" PRIu8 ",", neighbor_bts->nr); + if (reply.buf == reply.pos) + cmd->reply = ""; + else { /* Get rid of trailing comma */ + reply.pos[-1] = '\0'; + if (!(cmd->reply = talloc_strdup(cmd, reply.buf))) + goto oom; + } + return CTRL_CMD_REPLY; + +oom: + cmd->reply = "OOM"; + return CTRL_CMD_ERROR; +} + +CTRL_CMD_DEFINE_RO(neighbor_bts_list, "neighbor-bts list"); + static int set_neighbor_bts_add(struct ctrl_cmd *cmd, void *data) { struct gsm_bts *bts = cmd->node; @@ -705,6 +744,7 @@ int neighbor_ident_ctrl_init(void) rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_lac_ci_del); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_add); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_del); + rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_bts_list); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_ps_add); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_ps_del); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_clear); |