diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-06-10 22:26:35 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2018-09-16 10:45:01 +0000 |
commit | 19795c5ab22b6502f543a44b30224ad57befafa4 (patch) | |
tree | fdaed4eff953681c8a28e70e0e9766cd8d619baa /src | |
parent | a8041edb5be3ae82bef97106b783ea4ec15e2a21 (diff) |
lc15: rewrite and refactor code to print hwversion description
Also print a newline at the end of print_hwversion().
In the process of rewrite, fix several warnings in the few lines of this functions:
osmo-bts/src/osmo-bts-litecell15/main.c: In function ‘print_hwversion’:
osmo-bts/src/osmo-bts-litecell15/main.c:162:12: warning: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Wrestrict]
snprintf(model_name, sizeof(model_name), "%s Rev %c",
^~~~~~~~~~
model_name, (char)rev);
~~~~~~~~~~
osmo-bts/src/osmo-bts-litecell15/main.c:168:12: warning: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Wrestrict]
snprintf(model_name, sizeof(model_name), "%s (%05X)",
^~~~~~~~~~
model_name, model);
~~~~~~~~~~
osmo-bts/src/osmo-bts-litecell15/main.c:162:47: warning: ‘ Rev ’ directive output may be truncated writing 5 bytes into a region of size between 1 and 64 [-Wformat-truncation=]
snprintf(model_name, sizeof(model_name), "%s Rev %c",
^~~~~
osmo-bts/src/osmo-bts-litecell15/main.c:162:3: note: ‘snprintf’ output between 7 and 70 bytes into a destination of size 64
snprintf(model_name, sizeof(model_name), "%s Rev %c",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
model_name, (char)rev);
~~~~~~~~~~~~~~~~~~~~~~
osmo-bts/src/osmo-bts-litecell15/main.c:168:47: warning: ‘ (’ directive output may be truncated writing 2 bytes into a region of size between 1 and 64 [-Wformat-truncation=]
snprintf(model_name, sizeof(model_name), "%s (%05X)",
^~
osmo-bts/src/osmo-bts-litecell15/main.c:168:44: note: using the range [0, 4294967295] for directive argument
snprintf(model_name, sizeof(model_name), "%s (%05X)",
^~~~~~~~~~~
osmo-bts/src/osmo-bts-litecell15/main.c:168:3: note: ‘snprintf’ output between 9 and 75 bytes into a destination of size 64
snprintf(model_name, sizeof(model_name), "%s (%05X)",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
model_name, model);
~~~~~~~~~~~~~~~~~~
Change-Id: I079b056a04fe77d2f7f361ff5899232cb70b5a93
Diffstat (limited to 'src')
-rw-r--r-- | src/osmo-bts-litecell15/main.c | 21 | ||||
-rw-r--r-- | src/osmo-bts-litecell15/misc/lc15bts_bid.c | 22 | ||||
-rw-r--r-- | src/osmo-bts-litecell15/misc/lc15bts_bid.h | 1 | ||||
-rw-r--r-- | src/osmo-bts-litecell15/misc/lc15bts_mgr_nl.c | 17 |
4 files changed, 26 insertions, 35 deletions
diff --git a/src/osmo-bts-litecell15/main.c b/src/osmo-bts-litecell15/main.c index 030c3efd..de175e34 100644 --- a/src/osmo-bts-litecell15/main.c +++ b/src/osmo-bts-litecell15/main.c @@ -151,25 +151,8 @@ void bts_model_print_help() static void print_hwversion() { - int rev; - int model; - static char model_name[64] = {0, }; - - snprintf(model_name, sizeof(model_name), "NuRAN Litecell 1.5 BTS"); - - rev = lc15bts_rev_get(); - if (rev >= 0) { - snprintf(model_name, sizeof(model_name), "%s Rev %c", - model_name, (char)rev); - } - - model = lc15bts_model_get(); - if (model >= 0) { - snprintf(model_name, sizeof(model_name), "%s (%05X)", - model_name, model); - } - - printf(model_name); + printf(get_hwversion_desc()); + printf("\n"); } int bts_model_handle_options(int argc, char **argv) diff --git a/src/osmo-bts-litecell15/misc/lc15bts_bid.c b/src/osmo-bts-litecell15/misc/lc15bts_bid.c index 7f278bff..9284b62e 100644 --- a/src/osmo-bts-litecell15/misc/lc15bts_bid.c +++ b/src/osmo-bts-litecell15/misc/lc15bts_bid.c @@ -138,3 +138,25 @@ int lc15bts_option_get(enum lc15bts_option_type type) return option; } + +const char* get_hwversion_desc() +{ + int rev; + int model; + size_t len; + static char model_name[64] = {0, }; + len = snprintf(model_name, sizeof(model_name), "NuRAN Litecell 1.5 BTS"); + + rev = lc15bts_rev_get(); + if (rev >= 0) { + len += snprintf(model_name + len, sizeof(model_name) - len, + " Rev %c", (char)rev); + } + + model = lc15bts_model_get(); + if (model >= 0) { + snprintf(model_name + len, sizeof(model_name) - len, + "%s (%05X)", model_name, model); + } + return model_name; +} diff --git a/src/osmo-bts-litecell15/misc/lc15bts_bid.h b/src/osmo-bts-litecell15/misc/lc15bts_bid.h index b320e117..a71fdd7e 100644 --- a/src/osmo-bts-litecell15/misc/lc15bts_bid.h +++ b/src/osmo-bts-litecell15/misc/lc15bts_bid.h @@ -47,5 +47,6 @@ enum lc15bts_gsm_band { int lc15bts_rev_get(void); int lc15bts_model_get(void); int lc15bts_option_get(enum lc15bts_option_type type); +const char* get_hwversion_desc(); #endif diff --git a/src/osmo-bts-litecell15/misc/lc15bts_mgr_nl.c b/src/osmo-bts-litecell15/misc/lc15bts_mgr_nl.c index 549c1793..3a617dd7 100644 --- a/src/osmo-bts-litecell15/misc/lc15bts_mgr_nl.c +++ b/src/osmo-bts-litecell15/misc/lc15bts_mgr_nl.c @@ -104,8 +104,6 @@ static void respond_to(struct sockaddr_in *src, struct osmo_fd *fd, if (!fetched_info) { int fd_eth; int serno; - int model; - int rev; /* fetch the MAC */ fd_eth = open(ETH0_ADDR_SYSFS, O_RDONLY); @@ -119,20 +117,7 @@ static void respond_to(struct sockaddr_in *src, struct osmo_fd *fd, lc15bts_par_get_int(tall_mgr_ctx, LC15BTS_PAR_SERNR, &serno); snprintf(ser_str, sizeof(ser_str), "%d", serno); - /* fetch the model and trx number */ - snprintf(model_name, sizeof(model_name), "Litecell 1.5 BTS"); - - rev = lc15bts_rev_get(); - if (rev >= 0) { - snprintf(model_name, sizeof(model_name), "%s Rev %c", - model_name, rev); - } - - model = lc15bts_model_get(); - if (model >= 0) { - snprintf(model_name, sizeof(model_name), "%s (%05X)", - model_name, model); - } + strncpy(model_name, get_hwversion_desc(), sizeof(model_name)-1); fetched_info = 1; } |