mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
utils: cleanup
- Simplify linked list search - code was unnecessarily complex for no benefit - Refactored parse / kick logic to simplify functions [cleanup commit message] Signed-off-by: Nick Hainke <vincent@systemli.org>
This commit is contained in:
parent
5d7f99dded
commit
0eca0fae0b
5 changed files with 105 additions and 259 deletions
|
|
@ -231,9 +231,7 @@ int handle_deauth_req(struct blob_attr* msg) {
|
|||
|
||||
pthread_mutex_lock(&client_array_mutex);
|
||||
|
||||
client* client_entry = client_array_get_client(notify_req.client_addr);
|
||||
if (client_entry != NULL)
|
||||
client_array_delete(client_entry, false);
|
||||
client_array_delete_bc(notify_req.bssid_addr, notify_req.client_addr);
|
||||
|
||||
pthread_mutex_unlock(&client_array_mutex);
|
||||
|
||||
|
|
@ -309,7 +307,7 @@ int handle_network_msg(char* msg) {
|
|||
}
|
||||
}
|
||||
else if (strncmp(method, "clients", 5) == 0) {
|
||||
parse_to_clients(data_buf.head, 0, 0);
|
||||
parse_to_clients(data_buf.head);
|
||||
}
|
||||
else if (strncmp(method, "deauth", 5) == 0) {
|
||||
dawnlog_debug("METHOD DEAUTH\n");
|
||||
|
|
@ -437,11 +435,12 @@ dump_client(struct blob_attr** tb, struct dawn_mac client_addr, const char* bssi
|
|||
}
|
||||
|
||||
pthread_mutex_lock(&client_array_mutex);
|
||||
// If entry was akraedy in list it won't be added, so free memorY
|
||||
if (client_entry != insert_client_to_array(client_entry, time(0)))
|
||||
// If entry was already in list we get back the old entry, which needs to be freed
|
||||
client* prev_entry = client_array_update_entry(client_entry, time(0));
|
||||
if (prev_entry)
|
||||
{
|
||||
dawn_free(client_entry);
|
||||
client_entry = NULL;
|
||||
dawn_free(prev_entry);
|
||||
prev_entry = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&client_array_mutex);
|
||||
|
|
@ -464,19 +463,13 @@ dump_client_table(struct blob_attr* head, int len, const char* bssid_addr, uint3
|
|||
blobmsg_parse(client_policy, __CLIENT_MAX, tb, blobmsg_data(attr), blobmsg_len(attr));
|
||||
//char* str = blobmsg_format_json_indent(attr, true, -1);
|
||||
|
||||
int tmp_int_mac[ETH_ALEN];
|
||||
struct dawn_mac tmp_mac;
|
||||
sscanf((char*)hdr->name, MACSTR, STR2MAC(tmp_int_mac));
|
||||
for (int i = 0; i < ETH_ALEN; ++i)
|
||||
tmp_mac.u8[i] = (uint8_t)tmp_int_mac[i];
|
||||
|
||||
dump_client(tb, tmp_mac, bssid_addr, freq, ht_supported, vht_supported);
|
||||
dump_client(tb, str2mac((char*)hdr->name), bssid_addr, freq, ht_supported, vht_supported);
|
||||
station_count++;
|
||||
}
|
||||
return station_count;
|
||||
}
|
||||
|
||||
int parse_to_clients(struct blob_attr* msg, int do_kick, uint32_t id) {
|
||||
int parse_to_clients(struct blob_attr* msg) {
|
||||
struct blob_attr* tb[__CLIENT_TABLE_MAX];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
|
@ -495,11 +488,14 @@ int parse_to_clients(struct blob_attr* msg, int do_kick, uint32_t id) {
|
|||
|
||||
blobmsg_parse(client_table_policy, __CLIENT_TABLE_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
// Get clients
|
||||
if (tb[CLIENT_TABLE] && tb[CLIENT_TABLE_BSSID] && tb[CLIENT_TABLE_FREQ]) {
|
||||
int num_stations = 0;
|
||||
num_stations = dump_client_table(blobmsg_data(tb[CLIENT_TABLE]), blobmsg_data_len(tb[CLIENT_TABLE]),
|
||||
blobmsg_data(tb[CLIENT_TABLE_BSSID]), blobmsg_get_u32(tb[CLIENT_TABLE_FREQ]),
|
||||
blobmsg_get_u8(tb[CLIENT_TABLE_HT]), blobmsg_get_u8(tb[CLIENT_TABLE_VHT]));
|
||||
|
||||
// Get AP
|
||||
ap *ap_entry = dawn_malloc(sizeof(struct ap_s));
|
||||
hwaddr_aton(blobmsg_data(tb[CLIENT_TABLE_BSSID]), ap_entry->bssid_addr.u8);
|
||||
ap_entry->freq = blobmsg_get_u32(tb[CLIENT_TABLE_FREQ]);
|
||||
|
|
@ -579,11 +575,6 @@ int parse_to_clients(struct blob_attr* msg, int do_kick, uint32_t id) {
|
|||
}
|
||||
|
||||
insert_to_ap_array(ap_entry, time(0));
|
||||
|
||||
if (do_kick && dawn_metric.kicking) {
|
||||
update_iw_info(ap_entry->bssid_addr);
|
||||
kick_clients(ap_entry->bssid_addr, id);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,6 +218,8 @@ static probe_entry* parse_to_beacon_rep(struct blob_attr *msg);
|
|||
|
||||
void ubus_set_nr();
|
||||
|
||||
|
||||
/*** CODE START ***/
|
||||
void add_client_update_timer(time_t time) {
|
||||
uloop_timeout_set(&client_timer, time);
|
||||
}
|
||||
|
|
@ -699,7 +701,7 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
|||
uloop_add_data_cbs();
|
||||
|
||||
// get clients
|
||||
uloop_timeout_add(&client_timer); // callback = update_clients
|
||||
uloop_timeout_add(&client_timer); // callback = update_client_nr
|
||||
|
||||
uloop_timeout_add(&channel_utilization_timer); // callback = update_channel_utilization
|
||||
|
||||
|
|
@ -800,8 +802,8 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
|
|||
blobmsg_add_string(&b, "hostname", entry->hostname);
|
||||
|
||||
send_blob_attr_via_network(b.head, "clients");
|
||||
// TODO: Have we just bit-packed data to send to something locally to unpack it again? Performance / scalability?
|
||||
parse_to_clients(b.head, 1, req->peer);
|
||||
|
||||
parse_to_clients(b.head);
|
||||
|
||||
print_client_array();
|
||||
print_ap_array();
|
||||
|
|
@ -811,6 +813,13 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
|
|||
|
||||
blob_buf_free(&b);
|
||||
dawn_unregmem(&b);
|
||||
|
||||
if (dawn_metric.kicking) {
|
||||
//FIXME: Should we do this? Does it mix up STA and AP RSSI values, and does that matter?
|
||||
update_iw_info(entry->bssid_addr);
|
||||
|
||||
kick_clients(entry->bssid_addr, req->peer);
|
||||
}
|
||||
}
|
||||
|
||||
static int ubus_get_clients() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue