mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
Refactor of datastorage.c to allow scalability testing
This commit is contained in:
parent
92561cbe9d
commit
353405359f
9 changed files with 473 additions and 311 deletions
|
@ -13,6 +13,9 @@ SET(SOURCES
|
||||||
storage/datastorage.c
|
storage/datastorage.c
|
||||||
include/datastorage.h
|
include/datastorage.h
|
||||||
|
|
||||||
|
storage/uface.c
|
||||||
|
include/uface.h
|
||||||
|
|
||||||
network/networksocket.c
|
network/networksocket.c
|
||||||
include/networksocket.h
|
include/networksocket.h
|
||||||
|
|
||||||
|
@ -43,12 +46,27 @@ SET(SOURCES
|
||||||
utils/ieee80211_utils.c
|
utils/ieee80211_utils.c
|
||||||
include/ieee80211_utils.h)
|
include/ieee80211_utils.h)
|
||||||
|
|
||||||
|
SET(SOURCES_TEST_STORAGE
|
||||||
|
test/storage_test.c
|
||||||
|
|
||||||
|
include/uface.h
|
||||||
|
|
||||||
|
include/utils.h
|
||||||
|
utils/utils.c
|
||||||
|
|
||||||
|
storage/datastorage.c
|
||||||
|
include/datastorage.h
|
||||||
|
|
||||||
|
utils/ieee80211_utils.c
|
||||||
|
include/ieee80211_utils.h)
|
||||||
|
|
||||||
SET(LIBS
|
SET(LIBS
|
||||||
ubox ubus json-c blobmsg_json uci gcrypt iwinfo)
|
ubox ubus json-c blobmsg_json uci gcrypt iwinfo)
|
||||||
|
|
||||||
ADD_EXECUTABLE(dawn ${SOURCES})
|
ADD_EXECUTABLE(dawn ${SOURCES})
|
||||||
|
ADD_EXECUTABLE(test_storage ${SOURCES_TEST_STORAGE})
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(dawn ${LIBS})
|
TARGET_LINK_LIBRARIES(dawn ${LIBS})
|
||||||
|
|
||||||
INSTALL(TARGETS dawn
|
INSTALL(TARGETS dawn
|
||||||
RUNTIME DESTINATION /usr/sbin/)
|
RUNTIME DESTINATION /usr/sbin/)
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libubox/blobmsg_json.h>
|
|
||||||
|
|
||||||
#ifndef ETH_ALEN
|
#ifndef ETH_ALEN
|
||||||
#define ETH_ALEN 6
|
#define ETH_ALEN 6
|
||||||
|
@ -101,6 +100,7 @@ struct time_config_s timeout_config;
|
||||||
|
|
||||||
// ---------------- Global variables ----------------
|
// ---------------- Global variables ----------------
|
||||||
struct probe_metric_s dawn_metric;
|
struct probe_metric_s dawn_metric;
|
||||||
|
extern int probe_entry_last;
|
||||||
|
|
||||||
|
|
||||||
/* Probe, Auth, Assoc */
|
/* Probe, Auth, Assoc */
|
||||||
|
@ -155,6 +155,8 @@ auth_entry insert_to_denied_req_array(auth_entry entry, int inc_counter);
|
||||||
// ---------------- Global variables ----------------
|
// ---------------- Global variables ----------------
|
||||||
struct probe_entry_s probe_array[PROBE_ARRAY_LEN];
|
struct probe_entry_s probe_array[PROBE_ARRAY_LEN];
|
||||||
pthread_mutex_t probe_array_mutex;
|
pthread_mutex_t probe_array_mutex;
|
||||||
|
extern int denied_req_last;
|
||||||
|
auth_entry denied_req_array_delete(auth_entry entry);
|
||||||
|
|
||||||
// ---------------- Functions ----------------
|
// ---------------- Functions ----------------
|
||||||
probe_entry insert_to_array(probe_entry entry, int inc_counter, int save_80211k, int is_beacon);
|
probe_entry insert_to_array(probe_entry entry, int inc_counter, int save_80211k, int is_beacon);
|
||||||
|
@ -175,7 +177,6 @@ void uloop_add_data_cbs();
|
||||||
|
|
||||||
/* AP, Client */
|
/* AP, Client */
|
||||||
|
|
||||||
// blobmsg_alloc_string_buffer(&b, "signature", 1024);
|
|
||||||
#define SIGNATURE_LEN 1024
|
#define SIGNATURE_LEN 1024
|
||||||
|
|
||||||
// ---------------- Structs ----------------
|
// ---------------- Structs ----------------
|
||||||
|
@ -229,6 +230,8 @@ struct client_s client_array[ARRAY_CLIENT_LEN];
|
||||||
pthread_mutex_t client_array_mutex;
|
pthread_mutex_t client_array_mutex;
|
||||||
struct ap_s ap_array[ARRAY_AP_LEN];
|
struct ap_s ap_array[ARRAY_AP_LEN];
|
||||||
pthread_mutex_t ap_array_mutex;
|
pthread_mutex_t ap_array_mutex;
|
||||||
|
extern int ap_entry_last;
|
||||||
|
extern int client_entry_last;
|
||||||
|
|
||||||
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
|
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
|
||||||
|
|
||||||
|
@ -258,18 +261,12 @@ void print_ap_array();
|
||||||
|
|
||||||
ap ap_array_get_ap(uint8_t bssid_addr[]);
|
ap ap_array_get_ap(uint8_t bssid_addr[]);
|
||||||
|
|
||||||
int build_hearing_map_sort_client(struct blob_buf *b);
|
|
||||||
|
|
||||||
int build_network_overview(struct blob_buf *b);
|
|
||||||
|
|
||||||
int probe_array_set_all_probe_count(uint8_t client_addr[], uint32_t probe_count);
|
int probe_array_set_all_probe_count(uint8_t client_addr[], uint32_t probe_count);
|
||||||
|
|
||||||
int ap_get_collision_count(int col_domain);
|
int ap_get_collision_count(int col_domain);
|
||||||
|
|
||||||
void send_beacon_reports(uint8_t bssid[], int id);
|
void send_beacon_reports(uint8_t bssid[], int id);
|
||||||
|
|
||||||
int ap_get_nr(struct blob_buf *b, uint8_t own_bssid_addr[]);
|
|
||||||
|
|
||||||
/* Utils */
|
/* Utils */
|
||||||
|
|
||||||
// ---------------- Defines -------------------
|
// ---------------- Defines -------------------
|
||||||
|
@ -281,4 +278,14 @@ char *sort_string;
|
||||||
// ---------------- Functions -------------------
|
// ---------------- Functions -------------------
|
||||||
int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], char* neighbor_report, int automatic_kick);
|
int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], char* neighbor_report, int automatic_kick);
|
||||||
|
|
||||||
#endif
|
int is_connected_somehwere(uint8_t client_addr[]);
|
||||||
|
|
||||||
|
void remove_old_probe_entries(time_t current_time, long long int threshold);
|
||||||
|
|
||||||
|
void remove_old_client_entries(time_t current_time, long long int threshold);
|
||||||
|
|
||||||
|
void remove_old_ap_entries(time_t current_time, long long int threshold);
|
||||||
|
|
||||||
|
int eval_probe_metric(struct probe_entry_s probe_entry);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <libubox/blobmsg_json.h>
|
#include <libubox/blobmsg_json.h>
|
||||||
#include <libubox/uloop.h>
|
#include <libubox/uloop.h>
|
||||||
|
|
||||||
|
|
||||||
#include "datastorage.h"
|
#include "datastorage.h"
|
||||||
|
|
||||||
// 802.11 Status codes
|
// 802.11 Status codes
|
||||||
|
@ -166,4 +167,10 @@ int uci_send_via_network();
|
||||||
|
|
||||||
void ubus_send_beacon_report(uint8_t client[], int id);
|
void ubus_send_beacon_report(uint8_t client[], int id);
|
||||||
|
|
||||||
|
int build_hearing_map_sort_client(struct blob_buf *b);
|
||||||
|
|
||||||
|
int build_network_overview(struct blob_buf *b);
|
||||||
|
|
||||||
|
int ap_get_nr(struct blob_buf *b, uint8_t own_bssid_addr[]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
8
src/include/uface.h
Normal file
8
src/include/uface.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
void send_beacon_report(uint8_t client[], int id);
|
||||||
|
int send_probe_via_network(struct probe_entry_s probe_entry);
|
||||||
|
|
||||||
|
int send_set_probe(uint8_t client_addr[]);
|
||||||
|
void wnm_disassoc_imminent(uint32_t id, const uint8_t *client_addr, char* dest_ap, uint32_t duration);
|
||||||
|
void add_client_update_timer(time_t time);
|
||||||
|
void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include "datastorage.h"
|
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <libubox/uloop.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "ubus.h"
|
|
||||||
#include "dawn_iwinfo.h"
|
#include "dawn_iwinfo.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "ieee80211_utils.h"
|
#include "ieee80211_utils.h"
|
||||||
|
|
||||||
|
#include "datastorage.h"
|
||||||
|
#include "uface.h"
|
||||||
|
|
||||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||||
|
|
||||||
int go_next_help(char sort_order[], int i, probe_entry entry,
|
int go_next_help(char sort_order[], int i, probe_entry entry,
|
||||||
|
@ -16,32 +16,22 @@ int go_next_help(char sort_order[], int i, probe_entry entry,
|
||||||
int go_next(char sort_order[], int i, probe_entry entry,
|
int go_next(char sort_order[], int i, probe_entry entry,
|
||||||
probe_entry next_entry);
|
probe_entry next_entry);
|
||||||
|
|
||||||
void remove_old_probe_entries(time_t current_time, long long int threshold);
|
|
||||||
|
|
||||||
int client_array_go_next(char sort_order[], int i, client entry,
|
int client_array_go_next(char sort_order[], int i, client entry,
|
||||||
client next_entry);
|
client next_entry);
|
||||||
|
|
||||||
int client_array_go_next_help(char sort_order[], int i, client entry,
|
int client_array_go_next_help(char sort_order[], int i, client entry,
|
||||||
client next_entry);
|
client next_entry);
|
||||||
|
|
||||||
void remove_old_client_entries(time_t current_time, long long int threshold);
|
|
||||||
|
|
||||||
int eval_probe_metric(struct probe_entry_s probe_entry);
|
|
||||||
|
|
||||||
int kick_client(struct client_s client_entry, char* neighbor_report);
|
int kick_client(struct client_s client_entry, char* neighbor_report);
|
||||||
|
|
||||||
void ap_array_insert(ap entry);
|
void ap_array_insert(ap entry);
|
||||||
|
|
||||||
ap ap_array_delete(ap entry);
|
ap ap_array_delete(ap entry);
|
||||||
|
|
||||||
void remove_old_ap_entries(time_t current_time, long long int threshold);
|
|
||||||
|
|
||||||
void print_ap_entry(ap entry);
|
void print_ap_entry(ap entry);
|
||||||
|
|
||||||
int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]);
|
int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]);
|
||||||
|
|
||||||
int is_connected_somehwere(uint8_t client_addr[]);
|
|
||||||
|
|
||||||
int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr,
|
int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr,
|
||||||
int automatic_kick);
|
int automatic_kick);
|
||||||
|
|
||||||
|
@ -49,8 +39,6 @@ int compare_ssid(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare);
|
||||||
|
|
||||||
void denied_req_array_insert(auth_entry entry);
|
void denied_req_array_insert(auth_entry entry);
|
||||||
|
|
||||||
auth_entry denied_req_array_delete(auth_entry entry);
|
|
||||||
|
|
||||||
int denied_req_array_go_next(char sort_order[], int i, auth_entry entry,
|
int denied_req_array_go_next(char sort_order[], int i, auth_entry entry,
|
||||||
auth_entry next_entry);
|
auth_entry next_entry);
|
||||||
|
|
||||||
|
@ -63,30 +51,6 @@ int ap_entry_last = -1;
|
||||||
int mac_list_entry_last = -1;
|
int mac_list_entry_last = -1;
|
||||||
int denied_req_last = -1;
|
int denied_req_last = -1;
|
||||||
|
|
||||||
void remove_probe_array_cb(struct uloop_timeout *t);
|
|
||||||
|
|
||||||
struct uloop_timeout probe_timeout = {
|
|
||||||
.cb = remove_probe_array_cb
|
|
||||||
};
|
|
||||||
|
|
||||||
void remove_client_array_cb(struct uloop_timeout *t);
|
|
||||||
|
|
||||||
struct uloop_timeout client_timeout = {
|
|
||||||
.cb = remove_client_array_cb
|
|
||||||
};
|
|
||||||
|
|
||||||
void remove_ap_array_cb(struct uloop_timeout *t);
|
|
||||||
|
|
||||||
struct uloop_timeout ap_timeout = {
|
|
||||||
.cb = remove_ap_array_cb
|
|
||||||
};
|
|
||||||
|
|
||||||
void denied_req_array_cb(struct uloop_timeout *t);
|
|
||||||
|
|
||||||
struct uloop_timeout denied_req_timeout = {
|
|
||||||
.cb = denied_req_array_cb
|
|
||||||
};
|
|
||||||
|
|
||||||
void send_beacon_reports(uint8_t bssid[], int id) {
|
void send_beacon_reports(uint8_t bssid[], int id) {
|
||||||
pthread_mutex_lock(&client_array_mutex);
|
pthread_mutex_lock(&client_array_mutex);
|
||||||
|
|
||||||
|
@ -104,171 +68,10 @@ void send_beacon_reports(uint8_t bssid[], int id) {
|
||||||
if (!mac_is_equal(client_array[j].bssid_addr, bssid)) {
|
if (!mac_is_equal(client_array[j].bssid_addr, bssid)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ubus_send_beacon_report(client_array[j].client_addr, id);
|
send_beacon_report(client_array[j].client_addr, id);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&client_array_mutex);
|
pthread_mutex_unlock(&client_array_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int build_hearing_map_sort_client(struct blob_buf *b) {
|
|
||||||
print_probe_array();
|
|
||||||
pthread_mutex_lock(&probe_array_mutex);
|
|
||||||
|
|
||||||
void *client_list, *ap_list, *ssid_list;
|
|
||||||
char ap_mac_buf[20];
|
|
||||||
char client_mac_buf[20];
|
|
||||||
|
|
||||||
blob_buf_init(b, 0);
|
|
||||||
int m;
|
|
||||||
for (m = 0; m <= ap_entry_last; m++) {
|
|
||||||
if (m > 0) {
|
|
||||||
if (strcmp((char *) ap_array[m].ssid, (char *) ap_array[m - 1].ssid) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ssid_list = blobmsg_open_table(b, (char *) ap_array[m].ssid);
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i <= probe_entry_last; i++) {
|
|
||||||
/*if(!mac_is_equal(ap_array[m].bssid_addr, probe_array[i].bssid_addr))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
ap ap_entry_i = ap_array_get_ap(probe_array[i].bssid_addr);
|
|
||||||
|
|
||||||
if (!mac_is_equal(ap_entry_i.bssid_addr, probe_array[i].bssid_addr)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp((char *) ap_entry_i.ssid, (char *) ap_array[m].ssid) != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int k;
|
|
||||||
sprintf(client_mac_buf, MACSTR, MAC2STR(probe_array[i].client_addr));
|
|
||||||
client_list = blobmsg_open_table(b, client_mac_buf);
|
|
||||||
for (k = i; k <= probe_entry_last; k++) {
|
|
||||||
ap ap_entry = ap_array_get_ap(probe_array[k].bssid_addr);
|
|
||||||
|
|
||||||
if (!mac_is_equal(ap_entry.bssid_addr, probe_array[k].bssid_addr)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp((char *) ap_entry.ssid, (char *) ap_array[m].ssid) != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) {
|
|
||||||
i = k - 1;
|
|
||||||
break;
|
|
||||||
} else if (k == probe_entry_last) {
|
|
||||||
i = k;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(ap_mac_buf, MACSTR, MAC2STR(probe_array[k].bssid_addr));
|
|
||||||
ap_list = blobmsg_open_table(b, ap_mac_buf);
|
|
||||||
blobmsg_add_u32(b, "signal", probe_array[k].signal);
|
|
||||||
blobmsg_add_u32(b, "rcpi", probe_array[k].rcpi);
|
|
||||||
blobmsg_add_u32(b, "rsni", probe_array[k].rsni);
|
|
||||||
blobmsg_add_u32(b, "freq", probe_array[k].freq);
|
|
||||||
blobmsg_add_u8(b, "ht_capabilities", probe_array[k].ht_capabilities);
|
|
||||||
blobmsg_add_u8(b, "vht_capabilities", probe_array[k].vht_capabilities);
|
|
||||||
|
|
||||||
|
|
||||||
// check if ap entry is available
|
|
||||||
blobmsg_add_u32(b, "channel_utilization", ap_entry.channel_utilization);
|
|
||||||
blobmsg_add_u32(b, "num_sta", ap_entry.station_count);
|
|
||||||
blobmsg_add_u8(b, "ht_support", ap_entry.ht_support);
|
|
||||||
blobmsg_add_u8(b, "vht_support", ap_entry.vht_support);
|
|
||||||
|
|
||||||
blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k]));
|
|
||||||
blobmsg_close_table(b, ap_list);
|
|
||||||
}
|
|
||||||
blobmsg_close_table(b, client_list);
|
|
||||||
}
|
|
||||||
blobmsg_close_table(b, ssid_list);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&probe_array_mutex);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int build_network_overview(struct blob_buf *b) {
|
|
||||||
void *client_list, *ap_list, *ssid_list;
|
|
||||||
char ap_mac_buf[20];
|
|
||||||
char client_mac_buf[20];
|
|
||||||
|
|
||||||
blob_buf_init(b, 0);
|
|
||||||
int m;
|
|
||||||
for (m = 0; m <= ap_entry_last; m++) {
|
|
||||||
if (m > 0) {
|
|
||||||
if (strcmp((char *) ap_array[m].ssid, (char *) ap_array[m - 1].ssid) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ssid_list = blobmsg_open_table(b, (char *) ap_array[m].ssid);
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i <= client_entry_last; i++) {
|
|
||||||
ap ap_entry_i = ap_array_get_ap(client_array[i].bssid_addr);
|
|
||||||
|
|
||||||
if (strcmp((char *) ap_entry_i.ssid, (char *) ap_array[m].ssid) != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int k;
|
|
||||||
sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr));
|
|
||||||
ap_list = blobmsg_open_table(b, ap_mac_buf);
|
|
||||||
|
|
||||||
blobmsg_add_u32(b, "freq", ap_entry_i.freq);
|
|
||||||
blobmsg_add_u32(b, "channel_utilization", ap_entry_i.channel_utilization);
|
|
||||||
blobmsg_add_u32(b, "num_sta", ap_entry_i.station_count);
|
|
||||||
blobmsg_add_u8(b, "ht_support", ap_entry_i.ht_support);
|
|
||||||
blobmsg_add_u8(b, "vht_support", ap_entry_i.vht_support);
|
|
||||||
|
|
||||||
char *nr;
|
|
||||||
nr = blobmsg_alloc_string_buffer(b, "neighbor_report", NEIGHBOR_REPORT_LEN);
|
|
||||||
sprintf(nr, "%s", ap_entry_i.neighbor_report);
|
|
||||||
blobmsg_add_string_buffer(b);
|
|
||||||
|
|
||||||
for (k = i; k <= client_entry_last; k++) {
|
|
||||||
if (!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) {
|
|
||||||
i = k - 1;
|
|
||||||
break;
|
|
||||||
} else if (k == client_entry_last) {
|
|
||||||
i = k;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr));
|
|
||||||
client_list = blobmsg_open_table(b, client_mac_buf);
|
|
||||||
if(strlen(client_array[k].signature) != 0)
|
|
||||||
{
|
|
||||||
char *s;
|
|
||||||
s = blobmsg_alloc_string_buffer(b, "signature", 1024);
|
|
||||||
sprintf(s, "%s", client_array[k].signature);
|
|
||||||
blobmsg_add_string_buffer(b);
|
|
||||||
}
|
|
||||||
blobmsg_add_u8(b, "ht", client_array[k].ht);
|
|
||||||
blobmsg_add_u8(b, "vht", client_array[k].vht);
|
|
||||||
blobmsg_add_u32(b, "collision_count", ap_get_collision_count(ap_array[m].collision_domain));
|
|
||||||
|
|
||||||
int n;
|
|
||||||
for(n = 0; n <= probe_entry_last; n++)
|
|
||||||
{
|
|
||||||
if (mac_is_equal(client_array[k].client_addr, probe_array[n].client_addr) &&
|
|
||||||
mac_is_equal(client_array[k].bssid_addr, probe_array[n].bssid_addr)) {
|
|
||||||
blobmsg_add_u32(b, "signal", probe_array[n].signal);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blobmsg_close_table(b, client_list);
|
|
||||||
}
|
|
||||||
blobmsg_close_table(b, ap_list);
|
|
||||||
}
|
|
||||||
blobmsg_close_table(b, ssid_list);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int eval_probe_metric(struct probe_entry_s probe_entry) {
|
int eval_probe_metric(struct probe_entry_s probe_entry) {
|
||||||
|
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
@ -780,7 +583,7 @@ int probe_array_update_rssi(uint8_t bssid_addr[], uint8_t client_addr[], uint32_
|
||||||
updated = 1;
|
updated = 1;
|
||||||
if(send_network)
|
if(send_network)
|
||||||
{
|
{
|
||||||
ubus_send_probe_via_network(probe_array[i]);
|
send_probe_via_network(probe_array[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//TODO: break?!
|
//TODO: break?!
|
||||||
|
@ -809,7 +612,7 @@ int probe_array_update_rcpi_rsni(uint8_t bssid_addr[], uint8_t client_addr[], ui
|
||||||
updated = 1;
|
updated = 1;
|
||||||
if(send_network)
|
if(send_network)
|
||||||
{
|
{
|
||||||
ubus_send_probe_via_network(probe_array[i]);
|
send_probe_via_network(probe_array[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//TODO: break?!
|
//TODO: break?!
|
||||||
|
@ -895,36 +698,6 @@ ap insert_to_ap_array(ap entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ap_get_nr(struct blob_buf *b_local, uint8_t own_bssid_addr[]) {
|
|
||||||
|
|
||||||
pthread_mutex_lock(&ap_array_mutex);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
void* nbs = blobmsg_open_array(b_local, "list");
|
|
||||||
|
|
||||||
for (i = 0; i <= ap_entry_last; i++) {
|
|
||||||
if (mac_is_equal(own_bssid_addr, ap_array[i].bssid_addr)) {
|
|
||||||
continue; //TODO: Skip own entry?!
|
|
||||||
}
|
|
||||||
|
|
||||||
void* nr_entry = blobmsg_open_array(b_local, NULL);
|
|
||||||
|
|
||||||
char mac_buf[20];
|
|
||||||
sprintf(mac_buf, MACSTRLOWER, MAC2STR(ap_array[i].bssid_addr));
|
|
||||||
blobmsg_add_string(b_local, NULL, mac_buf);
|
|
||||||
|
|
||||||
blobmsg_add_string(b_local, NULL, (char *) ap_array[i].ssid);
|
|
||||||
blobmsg_add_string(b_local, NULL, ap_array[i].neighbor_report);
|
|
||||||
blobmsg_close_array(b_local, nr_entry);
|
|
||||||
|
|
||||||
}
|
|
||||||
blobmsg_close_array(b_local, nbs);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&ap_array_mutex);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ap_get_collision_count(int col_domain) {
|
int ap_get_collision_count(int col_domain) {
|
||||||
|
|
||||||
int ret_sta_count = 0;
|
int ret_sta_count = 0;
|
||||||
|
@ -1046,71 +819,6 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uloop_add_data_cbs() {
|
|
||||||
uloop_timeout_add(&probe_timeout);
|
|
||||||
uloop_timeout_add(&client_timeout);
|
|
||||||
uloop_timeout_add(&ap_timeout);
|
|
||||||
|
|
||||||
if (dawn_metric.use_driver_recog) {
|
|
||||||
uloop_timeout_add(&denied_req_timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove_probe_array_cb(struct uloop_timeout *t) {
|
|
||||||
pthread_mutex_lock(&probe_array_mutex);
|
|
||||||
printf("[Thread] : Removing old probe entries!\n");
|
|
||||||
remove_old_probe_entries(time(0), timeout_config.remove_probe);
|
|
||||||
printf("[Thread] : Removing old entries finished!\n");
|
|
||||||
pthread_mutex_unlock(&probe_array_mutex);
|
|
||||||
uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove_client_array_cb(struct uloop_timeout *t) {
|
|
||||||
pthread_mutex_lock(&client_array_mutex);
|
|
||||||
printf("[Thread] : Removing old client entries!\n");
|
|
||||||
remove_old_client_entries(time(0), timeout_config.update_client);
|
|
||||||
pthread_mutex_unlock(&client_array_mutex);
|
|
||||||
uloop_timeout_set(&client_timeout, timeout_config.update_client * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove_ap_array_cb(struct uloop_timeout *t) {
|
|
||||||
pthread_mutex_lock(&ap_array_mutex);
|
|
||||||
printf("[ULOOP] : Removing old ap entries!\n");
|
|
||||||
remove_old_ap_entries(time(0), timeout_config.remove_ap);
|
|
||||||
pthread_mutex_unlock(&ap_array_mutex);
|
|
||||||
uloop_timeout_set(&ap_timeout, timeout_config.remove_ap * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void denied_req_array_cb(struct uloop_timeout *t) {
|
|
||||||
pthread_mutex_lock(&denied_array_mutex);
|
|
||||||
printf("[ULOOP] : Processing denied authentication!\n");
|
|
||||||
|
|
||||||
time_t current_time = time(0);
|
|
||||||
|
|
||||||
for (int i = 0; i <= denied_req_last; i++) {
|
|
||||||
// check counter
|
|
||||||
|
|
||||||
//check timer
|
|
||||||
if (denied_req_array[i].time < current_time - timeout_config.denied_req_threshold) {
|
|
||||||
|
|
||||||
// client is not connected for a given time threshold!
|
|
||||||
if (!is_connected_somehwere(denied_req_array[i].client_addr)) {
|
|
||||||
printf("Client has probably a bad driver!\n");
|
|
||||||
|
|
||||||
// problem that somehow station will land into this list
|
|
||||||
// maybe delete again?
|
|
||||||
if (insert_to_maclist(denied_req_array[i].client_addr) == 0) {
|
|
||||||
send_add_mac(denied_req_array[i].client_addr);
|
|
||||||
write_mac_to_file("/tmp/dawn_mac_list", denied_req_array[i].client_addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
denied_req_array_delete(denied_req_array[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&denied_array_mutex);
|
|
||||||
uloop_timeout_set(&denied_req_timeout, timeout_config.denied_req_threshold * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void insert_client_to_array(client entry) {
|
void insert_client_to_array(client entry) {
|
||||||
pthread_mutex_lock(&client_array_mutex);
|
pthread_mutex_lock(&client_array_mutex);
|
||||||
entry.time = time(0);
|
entry.time = time(0);
|
||||||
|
|
124
src/storage/uface.c
Normal file
124
src/storage/uface.c
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
#include <libubox/uloop.h>
|
||||||
|
#include "datastorage.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "ubus.h"
|
||||||
|
#include "uface.h"
|
||||||
|
|
||||||
|
void send_beacon_report(uint8_t client[], int id)
|
||||||
|
{
|
||||||
|
ubus_send_beacon_report(client, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_set_probe(uint8_t client_addr[])
|
||||||
|
{
|
||||||
|
return send_set_probe(client_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wnm_disassoc_imminent(uint32_t id, const uint8_t *client_addr, char* dest_ap, uint32_t duration)
|
||||||
|
{
|
||||||
|
wnm_disassoc_imminent(id, client_addr, dest_ap, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_client_update_timer(time_t time)
|
||||||
|
{
|
||||||
|
add_client_update_timer(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time)
|
||||||
|
{
|
||||||
|
del_client_interface(id, client_addr, reason, deauth, ban_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_probe_via_network(struct probe_entry_s probe_entry)
|
||||||
|
{
|
||||||
|
return ubus_send_probe_via_network(probe_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_probe_array_cb(struct uloop_timeout *t);
|
||||||
|
|
||||||
|
struct uloop_timeout probe_timeout = {
|
||||||
|
.cb = remove_probe_array_cb
|
||||||
|
};
|
||||||
|
|
||||||
|
void remove_client_array_cb(struct uloop_timeout *t);
|
||||||
|
|
||||||
|
struct uloop_timeout client_timeout = {
|
||||||
|
.cb = remove_client_array_cb
|
||||||
|
};
|
||||||
|
|
||||||
|
void remove_ap_array_cb(struct uloop_timeout *t);
|
||||||
|
|
||||||
|
struct uloop_timeout ap_timeout = {
|
||||||
|
.cb = remove_ap_array_cb
|
||||||
|
};
|
||||||
|
|
||||||
|
void denied_req_array_cb(struct uloop_timeout *t);
|
||||||
|
|
||||||
|
struct uloop_timeout denied_req_timeout = {
|
||||||
|
.cb = denied_req_array_cb
|
||||||
|
};
|
||||||
|
|
||||||
|
void uloop_add_data_cbs() {
|
||||||
|
uloop_timeout_add(&probe_timeout);
|
||||||
|
uloop_timeout_add(&client_timeout);
|
||||||
|
uloop_timeout_add(&ap_timeout);
|
||||||
|
|
||||||
|
if (dawn_metric.use_driver_recog) {
|
||||||
|
uloop_timeout_add(&denied_req_timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_probe_array_cb(struct uloop_timeout *t) {
|
||||||
|
pthread_mutex_lock(&probe_array_mutex);
|
||||||
|
printf("[Thread] : Removing old probe entries!\n");
|
||||||
|
remove_old_probe_entries(time(0), timeout_config.remove_probe);
|
||||||
|
printf("[Thread] : Removing old entries finished!\n");
|
||||||
|
pthread_mutex_unlock(&probe_array_mutex);
|
||||||
|
uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_client_array_cb(struct uloop_timeout *t) {
|
||||||
|
pthread_mutex_lock(&client_array_mutex);
|
||||||
|
printf("[Thread] : Removing old client entries!\n");
|
||||||
|
remove_old_client_entries(time(0), timeout_config.update_client);
|
||||||
|
pthread_mutex_unlock(&client_array_mutex);
|
||||||
|
uloop_timeout_set(&client_timeout, timeout_config.update_client * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_ap_array_cb(struct uloop_timeout *t) {
|
||||||
|
pthread_mutex_lock(&ap_array_mutex);
|
||||||
|
printf("[ULOOP] : Removing old ap entries!\n");
|
||||||
|
remove_old_ap_entries(time(0), timeout_config.remove_ap);
|
||||||
|
pthread_mutex_unlock(&ap_array_mutex);
|
||||||
|
uloop_timeout_set(&ap_timeout, timeout_config.remove_ap * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void denied_req_array_cb(struct uloop_timeout *t) {
|
||||||
|
pthread_mutex_lock(&denied_array_mutex);
|
||||||
|
printf("[ULOOP] : Processing denied authentication!\n");
|
||||||
|
|
||||||
|
time_t current_time = time(0);
|
||||||
|
|
||||||
|
for (int i = 0; i <= denied_req_last; i++) {
|
||||||
|
// check counter
|
||||||
|
|
||||||
|
//check timer
|
||||||
|
if (denied_req_array[i].time < current_time - timeout_config.denied_req_threshold) {
|
||||||
|
|
||||||
|
// client is not connected for a given time threshold!
|
||||||
|
if (!is_connected_somehwere(denied_req_array[i].client_addr)) {
|
||||||
|
printf("Client has probably a bad driver!\n");
|
||||||
|
|
||||||
|
// problem that somehow station will land into this list
|
||||||
|
// maybe delete again?
|
||||||
|
if (insert_to_maclist(denied_req_array[i].client_addr) == 0) {
|
||||||
|
send_add_mac(denied_req_array[i].client_addr);
|
||||||
|
write_mac_to_file("/tmp/dawn_mac_list", denied_req_array[i].client_addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
denied_req_array_delete(denied_req_array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&denied_array_mutex);
|
||||||
|
uloop_timeout_set(&denied_req_timeout, timeout_config.denied_req_threshold * 1000);
|
||||||
|
}
|
93
src/test/storage_test.c
Normal file
93
src/test/storage_test.c
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "dawn_iwinfo.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "ieee80211_utils.h"
|
||||||
|
|
||||||
|
#include "datastorage.h"
|
||||||
|
#include "uface.h"
|
||||||
|
|
||||||
|
void ap_array_insert(ap entry);
|
||||||
|
|
||||||
|
ap ap_array_delete(ap entry);
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
ap ap0;
|
||||||
|
union __attribute__((__packed__)){
|
||||||
|
struct {
|
||||||
|
uint8_t the_mac[6];
|
||||||
|
uint8_t packing[2];
|
||||||
|
}mac;
|
||||||
|
uint64_t u64;
|
||||||
|
} mac_mangler;
|
||||||
|
|
||||||
|
|
||||||
|
print_ap_array();
|
||||||
|
for (int m = 0; m < 1000; m++)
|
||||||
|
{
|
||||||
|
mac_mangler.u64 = m;
|
||||||
|
memcpy(ap0.bssid_addr, mac_mangler.mac.the_mac, sizeof(ap0.bssid_addr));
|
||||||
|
ap_array_insert(ap0);
|
||||||
|
}
|
||||||
|
print_ap_array();
|
||||||
|
for (int m = 0; m < 1000; m++)
|
||||||
|
{
|
||||||
|
mac_mangler.u64 = m;
|
||||||
|
memcpy(ap0.bssid_addr, mac_mangler.mac.the_mac, sizeof(ap0.bssid_addr));
|
||||||
|
ap_array_delete(ap0);
|
||||||
|
}
|
||||||
|
print_ap_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_beacon_report(uint8_t client[], int id)
|
||||||
|
{
|
||||||
|
printf("send_beacon_report() was called...\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_set_probe(uint8_t client_addr[])
|
||||||
|
{
|
||||||
|
printf("send_set_probe() was called...\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wnm_disassoc_imminent(uint32_t id, const uint8_t *client_addr, char* dest_ap, uint32_t duration)
|
||||||
|
{
|
||||||
|
printf("wnm_disassoc_imminent() was called...\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_client_update_timer(time_t time)
|
||||||
|
{
|
||||||
|
printf("add_client_update_timer() was called...\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time)
|
||||||
|
{
|
||||||
|
printf("del_client_interface() was called...\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_probe_via_network(struct probe_entry_s probe_entry)
|
||||||
|
{
|
||||||
|
printf("send_probe_via_network() was called...\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_rssi_iwinfo(uint8_t *client_addr)
|
||||||
|
{
|
||||||
|
printf("get_rssi_iwinfo() was called...\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_expected_throughput_iwinfo(uint8_t *client_addr)
|
||||||
|
{
|
||||||
|
printf("get_expected_throughput_iwinfo() was called...\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_bandwidth_iwinfo(uint8_t *client_addr, float *rx_rate, float *tx_rate)
|
||||||
|
{
|
||||||
|
printf("get_bandwidth_iwinfo() was called...\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
194
src/utils/ubus.c
194
src/utils/ubus.c
|
@ -1,3 +1,6 @@
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <libubox/blobmsg_json.h>
|
#include <libubox/blobmsg_json.h>
|
||||||
|
@ -22,6 +25,7 @@
|
||||||
#include "dawn_iwinfo.h"
|
#include "dawn_iwinfo.h"
|
||||||
#include "datastorage.h"
|
#include "datastorage.h"
|
||||||
#include "tcpsocket.h"
|
#include "tcpsocket.h"
|
||||||
|
#include "ieee80211_utils.h"
|
||||||
|
|
||||||
static struct ubus_context *ctx = NULL;
|
static struct ubus_context *ctx = NULL;
|
||||||
|
|
||||||
|
@ -1990,3 +1994,193 @@ int handle_uci_config(struct blob_attr *msg) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int build_hearing_map_sort_client(struct blob_buf *b) {
|
||||||
|
print_probe_array();
|
||||||
|
pthread_mutex_lock(&probe_array_mutex);
|
||||||
|
|
||||||
|
void *client_list, *ap_list, *ssid_list;
|
||||||
|
char ap_mac_buf[20];
|
||||||
|
char client_mac_buf[20];
|
||||||
|
|
||||||
|
blob_buf_init(b, 0);
|
||||||
|
int m;
|
||||||
|
for (m = 0; m <= ap_entry_last; m++) {
|
||||||
|
if (m > 0) {
|
||||||
|
if (strcmp((char *) ap_array[m].ssid, (char *) ap_array[m - 1].ssid) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ssid_list = blobmsg_open_table(b, (char *) ap_array[m].ssid);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= probe_entry_last; i++) {
|
||||||
|
/*if(!mac_is_equal(ap_array[m].bssid_addr, probe_array[i].bssid_addr))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
ap ap_entry_i = ap_array_get_ap(probe_array[i].bssid_addr);
|
||||||
|
|
||||||
|
if (!mac_is_equal(ap_entry_i.bssid_addr, probe_array[i].bssid_addr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp((char *) ap_entry_i.ssid, (char *) ap_array[m].ssid) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int k;
|
||||||
|
sprintf(client_mac_buf, MACSTR, MAC2STR(probe_array[i].client_addr));
|
||||||
|
client_list = blobmsg_open_table(b, client_mac_buf);
|
||||||
|
for (k = i; k <= probe_entry_last; k++) {
|
||||||
|
ap ap_entry = ap_array_get_ap(probe_array[k].bssid_addr);
|
||||||
|
|
||||||
|
if (!mac_is_equal(ap_entry.bssid_addr, probe_array[k].bssid_addr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp((char *) ap_entry.ssid, (char *) ap_array[m].ssid) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) {
|
||||||
|
i = k - 1;
|
||||||
|
break;
|
||||||
|
} else if (k == probe_entry_last) {
|
||||||
|
i = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(ap_mac_buf, MACSTR, MAC2STR(probe_array[k].bssid_addr));
|
||||||
|
ap_list = blobmsg_open_table(b, ap_mac_buf);
|
||||||
|
blobmsg_add_u32(b, "signal", probe_array[k].signal);
|
||||||
|
blobmsg_add_u32(b, "rcpi", probe_array[k].rcpi);
|
||||||
|
blobmsg_add_u32(b, "rsni", probe_array[k].rsni);
|
||||||
|
blobmsg_add_u32(b, "freq", probe_array[k].freq);
|
||||||
|
blobmsg_add_u8(b, "ht_capabilities", probe_array[k].ht_capabilities);
|
||||||
|
blobmsg_add_u8(b, "vht_capabilities", probe_array[k].vht_capabilities);
|
||||||
|
|
||||||
|
|
||||||
|
// check if ap entry is available
|
||||||
|
blobmsg_add_u32(b, "channel_utilization", ap_entry.channel_utilization);
|
||||||
|
blobmsg_add_u32(b, "num_sta", ap_entry.station_count);
|
||||||
|
blobmsg_add_u8(b, "ht_support", ap_entry.ht_support);
|
||||||
|
blobmsg_add_u8(b, "vht_support", ap_entry.vht_support);
|
||||||
|
|
||||||
|
blobmsg_add_u32(b, "score", eval_probe_metric(probe_array[k]));
|
||||||
|
blobmsg_close_table(b, ap_list);
|
||||||
|
}
|
||||||
|
blobmsg_close_table(b, client_list);
|
||||||
|
}
|
||||||
|
blobmsg_close_table(b, ssid_list);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&probe_array_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int build_network_overview(struct blob_buf *b) {
|
||||||
|
void *client_list, *ap_list, *ssid_list;
|
||||||
|
char ap_mac_buf[20];
|
||||||
|
char client_mac_buf[20];
|
||||||
|
|
||||||
|
blob_buf_init(b, 0);
|
||||||
|
int m;
|
||||||
|
for (m = 0; m <= ap_entry_last; m++) {
|
||||||
|
if (m > 0) {
|
||||||
|
if (strcmp((char *) ap_array[m].ssid, (char *) ap_array[m - 1].ssid) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ssid_list = blobmsg_open_table(b, (char *) ap_array[m].ssid);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= client_entry_last; i++) {
|
||||||
|
ap ap_entry_i = ap_array_get_ap(client_array[i].bssid_addr);
|
||||||
|
|
||||||
|
if (strcmp((char *) ap_entry_i.ssid, (char *) ap_array[m].ssid) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int k;
|
||||||
|
sprintf(ap_mac_buf, MACSTR, MAC2STR(client_array[i].bssid_addr));
|
||||||
|
ap_list = blobmsg_open_table(b, ap_mac_buf);
|
||||||
|
|
||||||
|
blobmsg_add_u32(b, "freq", ap_entry_i.freq);
|
||||||
|
blobmsg_add_u32(b, "channel_utilization", ap_entry_i.channel_utilization);
|
||||||
|
blobmsg_add_u32(b, "num_sta", ap_entry_i.station_count);
|
||||||
|
blobmsg_add_u8(b, "ht_support", ap_entry_i.ht_support);
|
||||||
|
blobmsg_add_u8(b, "vht_support", ap_entry_i.vht_support);
|
||||||
|
|
||||||
|
char *nr;
|
||||||
|
nr = blobmsg_alloc_string_buffer(b, "neighbor_report", NEIGHBOR_REPORT_LEN);
|
||||||
|
sprintf(nr, "%s", ap_entry_i.neighbor_report);
|
||||||
|
blobmsg_add_string_buffer(b);
|
||||||
|
|
||||||
|
for (k = i; k <= client_entry_last; k++) {
|
||||||
|
if (!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) {
|
||||||
|
i = k - 1;
|
||||||
|
break;
|
||||||
|
} else if (k == client_entry_last) {
|
||||||
|
i = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(client_mac_buf, MACSTR, MAC2STR(client_array[k].client_addr));
|
||||||
|
client_list = blobmsg_open_table(b, client_mac_buf);
|
||||||
|
if(strlen(client_array[k].signature) != 0)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
s = blobmsg_alloc_string_buffer(b, "signature", 1024);
|
||||||
|
sprintf(s, "%s", client_array[k].signature);
|
||||||
|
blobmsg_add_string_buffer(b);
|
||||||
|
}
|
||||||
|
blobmsg_add_u8(b, "ht", client_array[k].ht);
|
||||||
|
blobmsg_add_u8(b, "vht", client_array[k].vht);
|
||||||
|
blobmsg_add_u32(b, "collision_count", ap_get_collision_count(ap_array[m].collision_domain));
|
||||||
|
|
||||||
|
int n;
|
||||||
|
for(n = 0; n <= probe_entry_last; n++)
|
||||||
|
{
|
||||||
|
if (mac_is_equal(client_array[k].client_addr, probe_array[n].client_addr) &&
|
||||||
|
mac_is_equal(client_array[k].bssid_addr, probe_array[n].bssid_addr)) {
|
||||||
|
blobmsg_add_u32(b, "signal", probe_array[n].signal);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
blobmsg_close_table(b, client_list);
|
||||||
|
}
|
||||||
|
blobmsg_close_table(b, ap_list);
|
||||||
|
}
|
||||||
|
blobmsg_close_table(b, ssid_list);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ap_get_nr(struct blob_buf *b_local, uint8_t own_bssid_addr[]) {
|
||||||
|
|
||||||
|
pthread_mutex_lock(&ap_array_mutex);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
void* nbs = blobmsg_open_array(b_local, "list");
|
||||||
|
|
||||||
|
for (i = 0; i <= ap_entry_last; i++) {
|
||||||
|
if (mac_is_equal(own_bssid_addr, ap_array[i].bssid_addr)) {
|
||||||
|
continue; //TODO: Skip own entry?!
|
||||||
|
}
|
||||||
|
|
||||||
|
void* nr_entry = blobmsg_open_array(b_local, NULL);
|
||||||
|
|
||||||
|
char mac_buf[20];
|
||||||
|
sprintf(mac_buf, MACSTRLOWER, MAC2STR(ap_array[i].bssid_addr));
|
||||||
|
blobmsg_add_string(b_local, NULL, mac_buf);
|
||||||
|
|
||||||
|
blobmsg_add_string(b_local, NULL, (char *) ap_array[i].ssid);
|
||||||
|
blobmsg_add_string(b_local, NULL, ap_array[i].neighbor_report);
|
||||||
|
blobmsg_close_array(b_local, nr_entry);
|
||||||
|
|
||||||
|
}
|
||||||
|
blobmsg_close_array(b_local, nbs);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&ap_array_mutex);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "datastorage.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "ubus.h"
|
|
||||||
|
|
||||||
int string_is_greater(uint8_t *str, uint8_t *str_2) {
|
int string_is_greater(uint8_t *str, uint8_t *str_2) {
|
||||||
|
|
||||||
|
@ -82,4 +85,4 @@ void write_mac_to_file(char *path, uint8_t addr[]) {
|
||||||
int rcpi_to_rssi(int rcpi)
|
int rcpi_to_rssi(int rcpi)
|
||||||
{
|
{
|
||||||
return rcpi / 2 - 110;
|
return rcpi / 2 - 110;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue