From 0dc0e951aff3f6ecc62c45c5be735daebe291c8f Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Tue, 29 May 2018 18:52:58 +0200 Subject: [PATCH] add channel util --- src/include/dawn_iwinfo.h | 2 +- src/utils/dawn_iwinfo.c | 31 ++++++++++++++++++------------- src/utils/ubus.c | 5 ++++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/include/dawn_iwinfo.h b/src/include/dawn_iwinfo.h index 9c3bfeb..8878223 100644 --- a/src/include/dawn_iwinfo.h +++ b/src/include/dawn_iwinfo.h @@ -59,6 +59,6 @@ int get_bssid(const char *ifname, uint8_t *bssid_addr); int get_ssid(const char *ifname, char *ssid); -int get_channel_utilization(const char *ifname); +int get_channel_utilization(const char *ifname, uint64_t *last_channel_time, uint64_t *last_channel_time_busy); #endif //DAWN_RSSI_H diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index a5d57c5..f6040f3 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -21,9 +21,6 @@ int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, floa #define IWINFO_ESSID_MAX_SIZE 32 -uint64_t last_channel_time = 0; -uint64_t last_channel_time_busy = 0; - int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) { const struct iwinfo_ops *iw; @@ -278,19 +275,27 @@ int get_ssid(const char *ifname, char* ssid) { return 0; } -int get_channel_utilization(const char *ifname) { +int get_channel_utilization(const char *ifname, uint64_t *last_channel_time, uint64_t *last_channel_time_busy) { + printf("GETTING UTILKIATUION FOR : %s\n", ifname); + const struct iwinfo_ops *iw; struct iwinfo_survey_entry survey_entry; iw = iwinfo_backend(ifname); if (iw->survey(ifname, &survey_entry)) - { - uint64_t dividend = survey_entry.channel_time_busy - last_channel_time_busy; - uint64_t divisor = survey_entry.channel_time - last_channel_time; - last_channel_time = survey_entry.channel_time; - last_channel_time_busy = survey_entry.channel_time_busy; - printf("GOT SURVEY INFO!\n"); - return (dividend * 255 / divisor); - } - return 0; + return 0; + + uint64_t dividend = survey_entry.channel_time_busy - *last_channel_time_busy; + uint64_t divisor = survey_entry.channel_time - *last_channel_time; + *last_channel_time = survey_entry.channel_time; + *last_channel_time_busy = survey_entry.channel_time_busy; + printf("dvidend: %llu\n", dividend); + printf("divisior: %llu\n", divisor); + + printf("last_channel_time: %llu\n", *last_channel_time); + printf("last_channel_time_busy: %llu\n", *last_channel_time_busy); + + printf("GOT SURVEY INFO!\n"); + return (int)(dividend * 255 / divisor); + iwinfo_finish(); } \ No newline at end of file diff --git a/src/utils/ubus.c b/src/utils/ubus.c index fd66740..8be945d 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -58,6 +58,8 @@ struct hostapd_sock_entry{ char ssid[SSID_MAX_LEN]; uint8_t ht; uint8_t vht; + uint64_t last_channel_time; + uint64_t last_channel_time_busy; struct ubus_subscriber subscriber; }; @@ -977,7 +979,8 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_ blobmsg_add_u8(&b_domain, "ht_supported", entry->ht); blobmsg_add_u8(&b_domain, "vht_supported", entry->vht); - int channel_util = get_channel_utilization(entry->iface_name); + int channel_util = get_channel_utilization(entry->iface_name, &entry->last_channel_time, &entry->last_channel_time_busy); + blobmsg_add_u32(&b_domain, "channel_utilization", channel_util); printf("CHANNEL UTILIZATION!!!: %d\n", channel_util); char* collision_string = blobmsg_format_json(b_domain.head, 1);