From 796d140698190c31d2807e2e443f17b92defb46b Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sat, 23 Dec 2017 18:26:18 +0100 Subject: [PATCH] compare essid --- src/include/datastorage.h | 1 + src/include/dawn_iwinfo.h | 2 +- src/main.c | 2 -- src/storage/datastorage.c | 11 +++++++ src/utils/dawn_iwinfo.c | 67 ++++++++++++++++++++++++++++++--------- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 8d1267e..a1f4fca 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -161,6 +161,7 @@ typedef struct ap_s { uint32_t channel_utilization; time_t time; uint32_t station_count; + // essid } ap; // ---------------- Defines ---------------- diff --git a/src/include/dawn_iwinfo.h b/src/include/dawn_iwinfo.h index 4a1c95b..0da0733 100644 --- a/src/include/dawn_iwinfo.h +++ b/src/include/dawn_iwinfo.h @@ -10,6 +10,6 @@ int get_rssi_iwinfo(__uint8_t *client_addr); int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); -int get_essid(const char *ifname, uint8_t *bssid_addr); +int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare); #endif //DAWN_RSSI_H diff --git a/src/main.c b/src/main.c index bc190d1..7fc15e5 100644 --- a/src/main.c +++ b/src/main.c @@ -98,8 +98,6 @@ int main(int argc, char **argv) { gcrypt_init(); gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); - get_essid("wlan0", NULL); - struct time_config_s time_config = uci_get_time_config(); timeout_config = time_config; // TODO: Refactor... diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 1905673..ba75903 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -255,6 +255,17 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat continue; } + // check if same essid!!! + if(compare_essid(bssid_addr, probe_array[k].bssid_addr) != 0) + { + printf("ESSID ARE NOT THE SAME!\n"); + continue; + } else + { + printf("ESSID ARE THE SAME!\n"); + } + + printf("Calculating score to compare!\n"); score_to_compare = eval_probe_metric(probe_array[k]); diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index d94cc83..969631f 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -21,30 +21,67 @@ int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, floa #define IWINFO_ESSID_MAX_SIZE 32 -int get_essid(const char *ifname, uint8_t *bssid_addr) + +int compare_essid(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) { - //struct iwinfo_assoclist_entry *e; const struct iwinfo_ops *iw; - iw = iwinfo_backend(ifname); + char mac_buf[20]; + char mac_buf_to_compare[20]; + sprintf(mac_buf, MACSTR, MAC2STR(bssid_addr)); + sprintf(mac_buf_to_compare, MACSTR, MAC2STR(bssid_addr_to_compare)); - char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; + DIR *dirp; + struct dirent *entry; + dirp = opendir(hostapd_dir_glob); // error handling? + if (!dirp) { + fprintf(stderr, "No hostapd sockets!\n"); + return 0; + } - if (iw->ssid(ifname, buf)) - memset(buf, 0, sizeof(buf)); + char* essid = NULL; + char* essid_to_compare = NULL; - static char buf_bssid[18] = { 0 }; - if (iw->bssid(ifname, buf_bssid)) - snprintf(buf, sizeof(buf), "00:00:00:00:00:00"); + char buf_essid[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; + char buf_essid_to_compare[IWINFO_ESSID_MAX_SIZE+1] = { 0 }; - printf("ESSID is: %s\n", buf); - printf("BSSID is: %s\n", buf_bssid); - - return 0; + while ((entry = readdir(dirp)) != NULL) { + if (entry->d_type == DT_SOCK) { + + iw = iwinfo_backend(entry->d_name); + + static char buf_bssid[18] = { 0 }; + if (iw->bssid(entry->d_name, buf_bssid)) + snprintf(buf_bssid, sizeof(buf_bssid), "00:00:00:00:00:00"); + + if(strcmp(mac_buf, buf_bssid)) + { + + if (iw->ssid(entry->d_type, buf_essid)) + memset(buf_essid, 0, sizeof(buf_essid)); + essid = buf_essid; + } + + if(strcmp(mac_buf_to_compare, buf_bssid)) + { + if (iw->ssid(entry->d_type, buf_essid_to_compare)) + memset(buf_essid_to_compare, 0, sizeof(buf_essid_to_compare)); + essid_to_compare = buf_essid_to_compare; + } + } + } + closedir(dirp); + + printf("Comparing: %s with %s\n", essid, essid_to_compare); + + if(strcmp(essid, essid_to_compare)) + { + return 0; + } + + return -1; } - - int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) { DIR *dirp;