From 9445046b5fff748864545d9de5fad4d053129e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 27 Sep 2016 16:45:37 +0200 Subject: [PATCH] Improve status reporting in the connman wifi driver --- wifi/drivers/connmanctl.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/wifi/drivers/connmanctl.c b/wifi/drivers/connmanctl.c index 9a70845b4a..3396aecdfe 100644 --- a/wifi/drivers/connmanctl.c +++ b/wifi/drivers/connmanctl.c @@ -21,6 +21,8 @@ #include "../../runloop.h" #include "../../lakka.h" +static bool connman_cache[256] = {0}; +static unsigned connman_counter = 0; static struct string_list* lines; static void *connmanctl_init(void) @@ -91,10 +93,38 @@ static void connmanctl_get_ssids(struct string_list* ssids) static bool connmanctl_ssid_is_online(unsigned i) { + char ln[512] = {0}; + char service[128] = {0}; + char command[256] = {0}; const char *line = lines->elems[i].data; - if (!line) - return false; - return line[2] == 'O' || line[2] == 'R'; + FILE *command_file = NULL; + + if (connman_counter == 60) + { + connman_counter = 0; + strlcpy(service, line+25, sizeof(service)); + + strlcat(command, "connmanctl services ", sizeof(command)); + strlcat(command, service, sizeof(command)); + strlcat(command, " | grep 'State = \\(online\\|ready\\)'", sizeof(command)); + + command_file = popen(command, "r"); + + while (fgets (ln, 512, command_file) != NULL) + { + connman_cache[i] = true; + return true; + } + pclose(command_file); + connman_cache[i] = false; + } + else + { + connman_counter++; + return connman_cache[i]; + } + + return false; } static bool connmanctl_connect_ssid(unsigned i, const char* passphrase)