diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d44daf..7ec9273 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,13 +47,20 @@ install(TARGETS ffffm ARCHIVE DESTINATION lib/static) if(RESPONDD) - add_library(ffffm-respondd SHARED ffffm-respondd.c) # FIXME make this a module - target_link_libraries(ffffm-respondd ffffm) - target_link_libraries(ffffm-respondd ffffm ${JSON_LIBRARIES}) - target_include_directories(ffffm-respondd PUBLIC ${JSON_INCLUDE_DIRS}) -# install(FILES $ - install(FILES libffffm-respondd.so - RENAME ffffm.so + add_library(respondd-nexthop SHARED respondd-nexthop.c) # FIXME make this a module + target_link_libraries(respondd-nexthop ffffm ${JSON_LIBRARIES}) + target_include_directories(respondd-nexthop PUBLIC ${JSON_INCLUDE_DIRS}) +# install(FILES $ + install(FILES librespondd-nexthop.so + RENAME nexthop.so + DESTINATION lib/gluon/respondd/) + + add_library(respondd-wireless SHARED respondd-wireless.c) # FIXME make this a module + target_link_libraries(respondd-wireless ffffm ${JSON_LIBRARIES}) + target_include_directories(respondd-wireless PUBLIC ${JSON_INCLUDE_DIRS}) +# install(FILES $ + install(FILES librespondd-wireless.so + RENAME wireless.so DESTINATION lib/gluon/respondd/) endif() @@ -83,15 +90,15 @@ if(INSTALL_TESTS) RUNTIME DESTINATION bin) endif() -if(RESPONDD) - add_executable(ffffm-respondd-test ffffm-respondd-test.c) - target_link_libraries(ffffm-respondd-test ffffm-respondd) - add_test(NAME ffffm-respondd-test COMMAND ffffm-respondd-test) - if(INSTALL_TESTS) - install(TARGETS ffffm-respondd-test - RUNTIME DESTINATION bin) - endif() -endif() +#if(RESPONDD) +# add_executable(ffffm-respondd-test ffffm-respondd-test.c) +# target_link_libraries(ffffm-respondd-test ffffm-respondd) +# add_test(NAME ffffm-respondd-test COMMAND ffffm-respondd-test) +# if(INSTALL_TESTS) +# install(TARGETS ffffm-respondd-test +# RUNTIME DESTINATION bin) +# endif() +#endif() if(LUA) add_test(NAME ffffm-lua-test COMMAND ffffm-lua-test) diff --git a/ffffm-lua.c b/ffffm-lua.c index d6d44bf..f34c3f1 100644 --- a/ffffm-lua.c +++ b/ffffm-lua.c @@ -27,14 +27,14 @@ static int get_wifi_info(lua_State *L) { lua_newtable(L); - if (i->channel_24) { - lua_pushstring(L, "channel_24"); - lua_pushinteger(L, i->channel_24); + if (i->c24) { + lua_pushstring(L, "chan2"); + lua_pushinteger(L, i->c24); lua_settable(L,-3); } - if (i->channel_50) { - lua_pushstring(L, "channel_50"); - lua_pushinteger(L, i->channel_50); + if (i->c50) { + lua_pushstring(L, "chan5"); + lua_pushinteger(L, i->c50); lua_settable(L, -3); } diff --git a/ffffm-respondd.c b/ffffm-respondd.c deleted file mode 100644 index 704d876..0000000 --- a/ffffm-respondd.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - Copyright (c) 2016, Thomas Weißschuh - Copyright (c) 2016, Matthias Schiffer - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include - -#include - -#include "ffffm.h" - -static struct json_object *get_nexthop(void) { - struct json_object *ret; - char *nexthop_s; - - nexthop_s = ffffm_get_nexthop(); - if (!nexthop_s) - return NULL; - - ret = json_object_new_string(nexthop_s); - free(nexthop_s); - return ret; -} - -static struct json_object *get_wifi_info(void) { - struct ffffm_wifi_info *i = ffffm_get_wifi_info(); - if (!i) - goto end; - - struct json_object *ret = json_object_new_object(); - if (!ret) - goto end; - - if (i->channel_24 != FFFFM_INVALID_CHANNEL) { - struct json_object *w24_c = json_object_new_int64(i->channel_24); - if (!w24_c) - goto end; - json_object_object_add(ret, "channel_24", w24_c); - } - if (i->channel_50 != FFFFM_INVALID_CHANNEL) { - struct json_object *w50_c = json_object_new_int64(i->channel_50); - if (!w50_c) - goto end; - json_object_object_add(ret, "channel_50", w50_c); - } -end: - ffffm_free_wifi_info(i); - return ret; - -} - -static struct json_object *get_airtime(void) { - double airtime = ffffm_get_airtime(); - if (FFFFM_INVALID_AIRTIME == airtime) - return NULL; - - return json_object_new_double(airtime); -} - -static struct json_object *respondd_provider_statistics(void) { - struct json_object *ret = json_object_new_object(); - - if (!ret) - return NULL; - - struct json_object *nexthop, *wifi_info, *airtime; - - nexthop = get_nexthop(); - if (nexthop) - json_object_object_add(ret, "nexthop", nexthop); - - wifi_info = get_wifi_info(); - if (wifi_info) - json_object_object_add(ret, "wifi_info", wifi_info); - - airtime = get_airtime(); - if (airtime) - json_object_object_add(ret, "airtime", airtime); - - return ret; -} - - -const struct respondd_provider_info respondd_providers[] = { - {"statistics", respondd_provider_statistics}, - {0}, -}; diff --git a/ffffm-test.c b/ffffm-test.c index 6eaf19e..f11cc31 100644 --- a/ffffm-test.c +++ b/ffffm-test.c @@ -4,5 +4,5 @@ int main() { struct ffffm_wifi_info *i = ffffm_get_wifi_info(); - printf("24: %u, 50: %u\n", i->channel_24, i->channel_50); + printf("24: %u, 50: %u\n", i->c24, i->c50); } diff --git a/ffffm.h b/ffffm.h index 87df856..394b023 100644 --- a/ffffm.h +++ b/ffffm.h @@ -4,11 +4,12 @@ extern const unsigned int FFFFM_INVALID_CHANNEL; extern const double FFFFM_INVALID_AIRTIME; struct ffffm_wifi_info { - unsigned char channel_24; - unsigned char channel_50; + unsigned char c24; + unsigned char c50; + unsigned char t24; + unsigned char t50; }; char *ffffm_get_nexthop(void); struct ffffm_wifi_info *ffffm_get_wifi_info(void); -void ffffm_free_wifi_info(struct ffffm_wifi_info *i); double ffffm_get_airtime(void); diff --git a/respondd-nexthop.c b/respondd-nexthop.c new file mode 100644 index 0000000..affb53d --- /dev/null +++ b/respondd-nexthop.c @@ -0,0 +1,38 @@ +#include + +#include + +#include "ffffm.h" + +static struct json_object *get_nexthop(void) { + struct json_object *ret; + char *nexthop_s; + + nexthop_s = ffffm_get_nexthop(); + if (!nexthop_s) + return NULL; + + ret = json_object_new_string(nexthop_s); + free(nexthop_s); + return ret; +} + +static struct json_object *respondd_provider_statistics(void) { + struct json_object *ret = json_object_new_object(); + + if (!ret) + return NULL; + + struct json_object *nexthop; + + nexthop = get_nexthop(); + if (nexthop) + json_object_object_add(ret, "nexthop", nexthop); + + return ret; +} + +const struct respondd_provider_info respondd_providers[] = { + {"statistics", respondd_provider_statistics}, + {0}, +}; diff --git a/respondd-wireless.c b/respondd-wireless.c new file mode 100644 index 0000000..6b59f5d --- /dev/null +++ b/respondd-wireless.c @@ -0,0 +1,77 @@ +#include + +#include + +#include + +#include "ffffm.h" + +static struct json_object *get_airtime(void) { + double airtime = ffffm_get_airtime(); + if (FFFFM_INVALID_AIRTIME == airtime) + return NULL; + + return json_object_new_double(airtime); +} + +static struct json_object *respondd_provider_statistics(void) { + struct json_object *ret = json_object_new_object(); + + if (!ret) + return NULL; + + struct json_object *airtime; + + airtime = get_airtime(); + if (airtime) + json_object_object_add(ret, "airtime2", airtime); + + return ret; +} + +static struct json_object *respondd_provider_nodeinfo(void) { + struct ffffm_wifi_info *i = ffffm_get_wifi_info(); + if (!i) + goto end; + + struct json_object *ret = json_object_new_object(); + struct json_object *v; + if (!ret) + goto end; + + if (i->c24) { + v = json_object_new_int64(i->c24); + if (!v) + goto end; + json_object_object_add(ret, "chan2", v); + } + if (i->c50) { + v = json_object_new_int64(i->c50); + if (!v) + goto end; + json_object_object_add(ret, "chan5", v); + } + if (i->t24) { + v = json_object_new_int64(i->t24); + if (!v) + goto end; + json_object_object_add(ret, "txpower2", v); + } + if (i->t50) { + v = json_object_new_int64(i->t50); + if (!v) + goto end; + json_object_object_add(ret, "txpower5", v); + } +end: + free(i); + return ret; + +} + + +const struct respondd_provider_info respondd_providers[] = { + {"statistics", respondd_provider_statistics}, + {"nodeinfo", respondd_provider_nodeinfo}, + {0}, +}; diff --git a/wifi_info.c b/wifi_info.c index 507cc3c..84891d8 100644 --- a/wifi_info.c +++ b/wifi_info.c @@ -43,6 +43,10 @@ static inline unsigned char parse_channel(const char *s) { return (unsigned char)(result % UCHAR_MAX); } +static inline unsigned char parse_txpower(const char *s) { + return parse_channel(s); +} + struct ffffm_wifi_info *ffffm_get_wifi_info(void) { struct uci_context *ctx = uci_alloc_context(); ctx->flags &= ~UCI_FLAG_STRICT; @@ -57,9 +61,13 @@ struct ffffm_wifi_info *ffffm_get_wifi_info(void) { const char *c24 = lookup_option_value(ctx, p, wifi_24_dev, "channel"); const char *c50 = lookup_option_value(ctx, p, wifi_50_dev, "channel"); + const char *t24 = lookup_option_value(ctx, p, wifi_24_dev, "txpower"); + const char *t50 = lookup_option_value(ctx, p, wifi_50_dev, "txpower"); - ret->channel_24 = parse_channel(c24); - ret->channel_50 = parse_channel(c50); + ret->c24 = parse_channel(c24); + ret->c50 = parse_channel(c50); + ret->t24 = parse_txpower(t24); + ret->t50 = parse_txpower(t50); end: if (ctx) uci_free_context(ctx); @@ -70,7 +78,3 @@ struct ffffm_wifi_info *ffffm_get_wifi_info(void) { ret = NULL; goto end; } - -void ffffm_free_wifi_info(struct ffffm_wifi_info *i) { - free(i); -}