mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
Merge branch 'feature/refactor_config_handling' into feature/add_ubus_methods
This commit is contained in:
commit
a78891d0df
21 changed files with 579 additions and 481 deletions
129
src/utils/dawn_iwinfo.c
Normal file
129
src/utils/dawn_iwinfo.c
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
#include "dawn_iwinfo.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <iwinfo.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "ubus.h"
|
||||
|
||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||
|
||||
int call_iwinfo(char *client_addr);
|
||||
|
||||
int parse_rssi(char *iwinfo_string);
|
||||
|
||||
int get_rssi(const char *ifname, uint8_t *client_addr);
|
||||
|
||||
int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate);
|
||||
|
||||
#define IWINFO_BUFSIZE 24 * 1024
|
||||
|
||||
int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) {
|
||||
|
||||
DIR *dirp;
|
||||
struct dirent *entry;
|
||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "No hostapd sockets!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sucess = 0;
|
||||
|
||||
while ((entry = readdir(dirp)) != NULL) {
|
||||
if (entry->d_type == DT_SOCK) {
|
||||
if (get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) {
|
||||
sucess = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
return sucess;
|
||||
}
|
||||
|
||||
int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate) {
|
||||
|
||||
int i, len;
|
||||
char buf[IWINFO_BUFSIZE];
|
||||
struct iwinfo_assoclist_entry *e;
|
||||
const struct iwinfo_ops *iw;
|
||||
|
||||
iw = iwinfo_backend(ifname);
|
||||
|
||||
if (iw->assoclist(ifname, buf, &len)) {
|
||||
printf("No information available\n");
|
||||
return 0;
|
||||
} else if (len <= 0) {
|
||||
printf("No station connected\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) {
|
||||
e = (struct iwinfo_assoclist_entry *) &buf[i];
|
||||
|
||||
if (mac_is_equal(client_addr, e->mac)) {
|
||||
//struct iwinfo_assoclist_entry * rx_rate = e->rx_rate;
|
||||
//struct iwinfo_assoclist_entry * tx_rate = e->tx_rate;
|
||||
*rx_rate = e->rx_rate.rate / 1000;
|
||||
*tx_rate = e->tx_rate.rate / 1000;
|
||||
return 1;
|
||||
}
|
||||
// return e->signal;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_rssi_iwinfo(__uint8_t *client_addr) {
|
||||
|
||||
DIR *dirp;
|
||||
struct dirent *entry;
|
||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "No hostapd sockets!\n");
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
int rssi = INT_MIN;
|
||||
|
||||
while ((entry = readdir(dirp)) != NULL) {
|
||||
if (entry->d_type == DT_SOCK) {
|
||||
rssi = get_rssi(entry->d_name, client_addr);
|
||||
if (rssi != INT_MIN)
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
return rssi;
|
||||
}
|
||||
|
||||
int get_rssi(const char *ifname, uint8_t *client_addr) {
|
||||
|
||||
int i, len;
|
||||
char buf[IWINFO_BUFSIZE];
|
||||
struct iwinfo_assoclist_entry *e;
|
||||
const struct iwinfo_ops *iw;
|
||||
|
||||
iw = iwinfo_backend(ifname);
|
||||
|
||||
if (iw->assoclist(ifname, buf, &len)) {
|
||||
printf("No information available\n");
|
||||
return INT_MIN;
|
||||
} else if (len <= 0) {
|
||||
printf("No station connected\n");
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) {
|
||||
e = (struct iwinfo_assoclist_entry *) &buf[i];
|
||||
|
||||
if (mac_is_equal(client_addr, e->mac))
|
||||
return e->signal;
|
||||
}
|
||||
|
||||
return INT_MIN;
|
||||
}
|
||||
|
|
@ -4,76 +4,38 @@
|
|||
|
||||
#include "dawn_uci.h"
|
||||
|
||||
/*
|
||||
|
||||
dawn.metric.ht_support
|
||||
dawn.metric.vht_support'
|
||||
dawn.metric.rssi
|
||||
dawn.metric.freq
|
||||
static struct uci_context *uci_ctx;
|
||||
static struct uci_package *uci_pkg;
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
config settings times
|
||||
option update_client '50'
|
||||
option remove_client '120'
|
||||
option remove_probe '120'
|
||||
*/
|
||||
// why is this not included in uci lib...?!
|
||||
// fund here: https://github.com/br101/pingcheck/blob/master/uci.c
|
||||
static int uci_lookup_option_int(struct uci_context *uci, struct uci_section *s,
|
||||
const char *name)
|
||||
{
|
||||
const char* str = uci_lookup_option_string(uci, s, name);
|
||||
return str == NULL ? -1 : atoi(str);
|
||||
}
|
||||
|
||||
struct time_config_s uci_get_time_config() {
|
||||
struct time_config_s ret;
|
||||
|
||||
struct uci_context *c;
|
||||
struct uci_ptr ptr;
|
||||
printf("Loading Times!");
|
||||
|
||||
c = uci_alloc_context();
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
printf("Loading TImes!");
|
||||
|
||||
|
||||
char tmp_update_client[] = "dawn.times.update_client";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_update_client, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
if (strcmp(s->type, "times") == 0)
|
||||
{
|
||||
ret.update_client = uci_lookup_option_int(uci_ctx, s, "update_client");
|
||||
ret.remove_client = uci_lookup_option_int(uci_ctx, s, "remove_client");
|
||||
ret.remove_probe = uci_lookup_option_int(uci_ctx, s, "remove_probe");
|
||||
ret.update_hostapd = uci_lookup_option_int(uci_ctx, s, "update_hostapd");
|
||||
ret.remove_ap = uci_lookup_option_int(uci_ctx, s, "remove_ap");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.update_client = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_remove_client[] = "dawn.times.remove_client";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_remove_client, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.remove_client = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_remove_probe[] = "dawn.times.remove_probe";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_remove_probe, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.remove_probe = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_update_hostapd[] = "dawn.times.update_hostapd";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_update_hostapd, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.update_hostapd = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_remove_ap[] = "dawn.times.remove_ap";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_remove_ap, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.remove_ap = atoi(ptr.o->v.string);
|
||||
|
||||
printf("Times: %lu, %lu, %lu %lu\n", ret.update_client, ret.remove_client, ret.remove_probe, ret.update_hostapd);
|
||||
|
||||
uci_free_context(c);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -81,96 +43,116 @@ struct time_config_s uci_get_time_config() {
|
|||
struct probe_metric_s uci_get_dawn_metric() {
|
||||
struct probe_metric_s ret;
|
||||
|
||||
struct uci_context *c;
|
||||
struct uci_ptr ptr;
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
c = uci_alloc_context();
|
||||
|
||||
char tmp_ht_support[] = "dawn.metric.ht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_ht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
if (strcmp(s->type, "metric") == 0)
|
||||
{
|
||||
ret.ht_support = uci_lookup_option_int(uci_ctx, s, "ht_support");
|
||||
ret.vht_support = uci_lookup_option_int(uci_ctx, s, "vht_support");
|
||||
ret.no_ht_support = uci_lookup_option_int(uci_ctx, s, "no_ht_support");
|
||||
ret.no_vht_support = uci_lookup_option_int(uci_ctx, s, "no_vht_support");
|
||||
ret.rssi = uci_lookup_option_int(uci_ctx, s, "rssi");
|
||||
ret.freq = uci_lookup_option_int(uci_ctx, s, "freq");
|
||||
ret.rssi_val = uci_lookup_option_int(uci_ctx, s, "rssi_val");
|
||||
ret.chan_util = uci_lookup_option_int(uci_ctx, s, "chan_util");
|
||||
ret.max_chan_util = uci_lookup_option_int(uci_ctx, s, "max_chan_util");
|
||||
ret.chan_util_val = uci_lookup_option_int(uci_ctx, s, "chan_util_val");
|
||||
ret.max_chan_util_val = uci_lookup_option_int(uci_ctx, s, "max_chan_util_val");
|
||||
ret.min_probe_count = uci_lookup_option_int(uci_ctx, s, "min_probe_count");
|
||||
ret.low_rssi = uci_lookup_option_int(uci_ctx, s, "low_rssi");
|
||||
ret.low_rssi_val = uci_lookup_option_int(uci_ctx, s, "low_rssi_val");
|
||||
ret.bandwith_threshold = uci_lookup_option_int(uci_ctx, s, "bandwith_threshold");
|
||||
ret.use_station_count = uci_lookup_option_int(uci_ctx, s, "use_station_count");
|
||||
ret.eval_probe_req = uci_lookup_option_int(uci_ctx, s, "eval_probe_req");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.ht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_vht_support[] = "dawn.metric.vht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_vht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.vht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_no_ht_support[] = "dawn.metric.no_ht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_no_ht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.no_ht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_no_vht_support[] = "dawn.metric.no_vht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_no_vht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.no_vht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_rssi[] = "dawn.metric.rssi";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_rssi, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.rssi = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_freq[] = "dawn.metric.freq";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_freq, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.freq = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_util[] = "dawn.metric.chan_util";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_util, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.chan_util = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_min_rssi[] = "dawn.metric.min_rssi";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_min_rssi, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.min_rssi = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_max_chan_util[] = "dawn.metric.max_chan_util";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.max_chan_util = atoi(ptr.o->v.string);
|
||||
|
||||
|
||||
printf("Try to load min_probe_count\n");
|
||||
char tmp_min_probe_count[] = "dawn.metric.min_probe_count";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_min_probe_count, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.min_probe_count = atoi(ptr.o->v.string);
|
||||
|
||||
printf("Loaded metric: %d\n", ret.min_probe_count);
|
||||
|
||||
uci_free_context(c);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct network_config_s uci_get_dawn_network() {
|
||||
struct network_config_s ret;
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "network") == 0)
|
||||
{
|
||||
printf("Fronund network entry!\n");
|
||||
ret.broadcast_ip = uci_lookup_option_string(uci_ctx, s, "broadcast_ip");
|
||||
printf("BROADCAST: %s\n", ret.broadcast_ip);
|
||||
ret.broadcast_port = uci_lookup_option_int(uci_ctx, s, "broadcast_port");
|
||||
ret.bool_multicast = uci_lookup_option_int(uci_ctx, s, "multicast");
|
||||
printf("multicast: %s\n", ret.broadcast_ip);
|
||||
ret.shared_key = uci_lookup_option_string(uci_ctx, s, "shared_key");
|
||||
ret.iv = uci_lookup_option_string(uci_ctx, s, "iv");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
const char* uci_get_dawn_hostapd_dir() {
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "hostapd") == 0) {
|
||||
return uci_lookup_option_string(uci_ctx, s, "hostapd_dir");
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* uci_get_dawn_sort_order() {
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "ordering") == 0)
|
||||
{
|
||||
return uci_lookup_option_string(uci_ctx, s, "sort_order");
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int uci_init()
|
||||
{
|
||||
struct uci_context *ctx = uci_ctx;
|
||||
|
||||
if (!ctx) {
|
||||
ctx = uci_alloc_context();
|
||||
uci_ctx = ctx;
|
||||
|
||||
ctx->flags &= ~UCI_FLAG_STRICT;
|
||||
} else {
|
||||
// shouldn't happen?
|
||||
uci_pkg = uci_lookup_package(ctx, "dawn");
|
||||
if (uci_pkg)
|
||||
uci_unload(ctx, uci_pkg);
|
||||
}
|
||||
|
||||
if (uci_load(ctx, "dawn", &uci_pkg))
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int uci_clear()
|
||||
{
|
||||
if(uci_pkg != NULL)
|
||||
{
|
||||
uci_unload(uci_ctx, uci_pkg);
|
||||
}
|
||||
if(uci_ctx != NULL)
|
||||
{
|
||||
uci_free_context(uci_ctx);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
#include "rssi.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <iwinfo.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "ubus.h"
|
||||
|
||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||
|
||||
int call_iwinfo(char *client_addr);
|
||||
|
||||
int parse_rssi(char *iwinfo_string);
|
||||
|
||||
int get_rssi(const char *ifname, uint8_t *client_addr);
|
||||
|
||||
#define IWINFO_BUFSIZE 24 * 1024
|
||||
|
||||
int get_rssi_iwinfo(__uint8_t *client_addr) {
|
||||
|
||||
DIR *dirp;
|
||||
struct dirent *entry;
|
||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "No hostapd sockets!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rssi = INT_MIN;
|
||||
|
||||
while ((entry = readdir(dirp)) != NULL) {
|
||||
if (entry->d_type == DT_SOCK) {
|
||||
rssi = get_rssi(entry->d_name, client_addr);
|
||||
if(rssi != INT_MIN)
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
return rssi;
|
||||
}
|
||||
|
||||
int get_rssi(const char *ifname, uint8_t *client_addr){
|
||||
|
||||
int i, len;
|
||||
char buf[IWINFO_BUFSIZE];
|
||||
struct iwinfo_assoclist_entry *e;
|
||||
const struct iwinfo_ops *iw;
|
||||
|
||||
iw = iwinfo_backend(ifname);
|
||||
|
||||
if (iw->assoclist(ifname, buf, &len))
|
||||
{
|
||||
printf("No information available\n");
|
||||
return INT_MIN;
|
||||
}
|
||||
else if (len <= 0)
|
||||
{
|
||||
printf("No station connected\n");
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
|
||||
{
|
||||
e = (struct iwinfo_assoclist_entry *) &buf[i];
|
||||
|
||||
if(mac_is_equal(client_addr, e->mac))
|
||||
return e->signal;
|
||||
}
|
||||
|
||||
return INT_MIN;
|
||||
}
|
||||
100
src/utils/ubus.c
100
src/utils/ubus.c
|
|
@ -24,13 +24,12 @@ static struct blob_buf b;
|
|||
|
||||
void update_clients(struct uloop_timeout *t);
|
||||
|
||||
struct uloop_timeout hostapd_timer = {
|
||||
.cb = update_hostapd_sockets
|
||||
};
|
||||
|
||||
struct uloop_timeout client_timer = {
|
||||
.cb = update_clients
|
||||
};
|
||||
struct uloop_timeout hostapd_timer = {
|
||||
.cb = update_hostapd_sockets
|
||||
};
|
||||
|
||||
#define MAX_HOSTAPD_SOCKETS 10
|
||||
uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS];
|
||||
|
|
@ -81,6 +80,7 @@ enum {
|
|||
CLIENT_TABLE_HT,
|
||||
CLIENT_TABLE_VHT,
|
||||
CLIENT_TABLE_CHAN_UTIL,
|
||||
CLIENT_TABLE_NUM_STA,
|
||||
__CLIENT_TABLE_MAX,
|
||||
};
|
||||
|
||||
|
|
@ -91,6 +91,7 @@ static const struct blobmsg_policy client_table_policy[__CLIENT_TABLE_MAX] = {
|
|||
[CLIENT_TABLE_HT] = {.name = "ht_supported", .type = BLOBMSG_TYPE_INT8},
|
||||
[CLIENT_TABLE_VHT] = {.name = "vht_supported", .type = BLOBMSG_TYPE_INT8},
|
||||
[CLIENT_TABLE_CHAN_UTIL] = {.name = "channel_utilization", .type = BLOBMSG_TYPE_INT32},
|
||||
[CLIENT_TABLE_NUM_STA] = {.name = "num_sta", .type = BLOBMSG_TYPE_INT32},
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -132,7 +133,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
static int add_subscriber(char *name);
|
||||
|
||||
static int subscribe_to_hostapd_interfaces(char *hostapd_dir);
|
||||
static int subscribe_to_hostapd_interfaces(const char *hostapd_dir);
|
||||
|
||||
static int ubus_get_clients();
|
||||
|
||||
|
|
@ -142,16 +143,19 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
struct blob_attr *msg);
|
||||
|
||||
int hostapd_array_check_id(uint32_t id);
|
||||
|
||||
void hostapd_array_insert(uint32_t id);
|
||||
|
||||
void hostapd_array_delete(uint32_t id);
|
||||
static void ubus_add_oject();
|
||||
|
||||
int hostapd_array_check_id(uint32_t id)
|
||||
{
|
||||
for(int i = 0; i <= hostapd_sock_last; i++)
|
||||
{
|
||||
if(hostapd_sock_arr[i] == id)
|
||||
{
|
||||
void add_client_update_timer(time_t time) {
|
||||
uloop_timeout_set(&client_timer, time);
|
||||
}
|
||||
|
||||
int hostapd_array_check_id(uint32_t id) {
|
||||
for (int i = 0; i <= hostapd_sock_last; i++) {
|
||||
if (hostapd_sock_arr[i] == id) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -159,21 +163,18 @@ int hostapd_array_check_id(uint32_t id)
|
|||
}
|
||||
|
||||
|
||||
void hostapd_array_insert(uint32_t id)
|
||||
{
|
||||
if(hostapd_sock_last < MAX_HOSTAPD_SOCKETS) {
|
||||
void hostapd_array_insert(uint32_t id) {
|
||||
if (hostapd_sock_last < MAX_HOSTAPD_SOCKETS) {
|
||||
hostapd_sock_last++;
|
||||
hostapd_sock_arr[hostapd_sock_last] = id;
|
||||
}
|
||||
|
||||
for(int i = 0; i <= hostapd_sock_last; i++)
|
||||
{
|
||||
printf("%d: %d\n",i,hostapd_sock_arr[i]);
|
||||
for (int i = 0; i <= hostapd_sock_last; i++) {
|
||||
printf("%d: %d\n", i, hostapd_sock_arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void hostapd_array_delete(uint32_t id)
|
||||
{
|
||||
void hostapd_array_delete(uint32_t id) {
|
||||
int i = 0;
|
||||
int found_in_array = 0;
|
||||
|
||||
|
|
@ -181,9 +182,8 @@ void hostapd_array_delete(uint32_t id)
|
|||
return;
|
||||
}
|
||||
|
||||
for(i = 0; i <= hostapd_sock_last; i++)
|
||||
{
|
||||
if(hostapd_sock_arr[i] == id) {
|
||||
for (i = 0; i <= hostapd_sock_last; i++) {
|
||||
if (hostapd_sock_arr[i] == id) {
|
||||
found_in_array = 1;
|
||||
break;
|
||||
}
|
||||
|
|
@ -217,8 +217,7 @@ static int decide_function(probe_entry *prob_req) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(better_ap_available(prob_req->bssid_addr, prob_req->client_addr))
|
||||
{
|
||||
if (better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -309,8 +308,7 @@ static int handle_auth_req(struct blob_attr *msg) {
|
|||
print_probe_entry(tmp);
|
||||
|
||||
// block if entry was not already found in probe database
|
||||
if(!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr)))
|
||||
{
|
||||
if (!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr))) {
|
||||
printf("DENY AUTH!\n");
|
||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||
}
|
||||
|
|
@ -337,7 +335,7 @@ static int handle_probe_req(struct blob_attr *msg) {
|
|||
parse_to_probe_req(msg, &prob_req);
|
||||
//insert_to_list(prob_req, 1);
|
||||
//probe_entry tmp_probe =
|
||||
insert_to_array(prob_req, 1);
|
||||
probe_entry tmp_prob_req = insert_to_array(prob_req, 1);
|
||||
|
||||
|
||||
// send probe via network
|
||||
|
|
@ -348,12 +346,17 @@ static int handle_probe_req(struct blob_attr *msg) {
|
|||
printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str);
|
||||
|
||||
//print_probe_array();
|
||||
/*
|
||||
|
||||
// deny access
|
||||
if (!decide_function(&tmp_probe)) {
|
||||
|
||||
if (!dawn_metric.eval_probe_req) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!decide_function(&tmp_prob_req)) {
|
||||
//printf("MAC WILL BE DECLINED!!!\n");
|
||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||
}*/
|
||||
}
|
||||
//printf("MAC WILL BE ACCEPDTED!!!\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -384,8 +387,7 @@ static int add_subscriber(char *name) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(hostapd_array_check_id(id))
|
||||
{
|
||||
if (hostapd_array_check_id(id)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -396,12 +398,11 @@ static int add_subscriber(char *name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int subscribe_to_hostapd_interfaces(char *hostapd_dir) {
|
||||
static int subscribe_to_hostapd_interfaces(const char *hostapd_dir) {
|
||||
DIR *dirp;
|
||||
struct dirent *entry;
|
||||
|
||||
if(ctx == NULL)
|
||||
{
|
||||
if (ctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -421,10 +422,9 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int subscribe_to_hostapd(char *hostapd_dir) {
|
||||
static int subscribe_to_hostapd(const char *hostapd_dir) {
|
||||
|
||||
if(ctx == NULL)
|
||||
{
|
||||
if (ctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -439,14 +439,14 @@ static int subscribe_to_hostapd(char *hostapd_dir) {
|
|||
hostapd_event.remove_cb = hostapd_handle_remove;
|
||||
hostapd_event.cb = hostapd_notify;
|
||||
|
||||
//subscribe_to_hostapd_interfaces(hostapd_dir);
|
||||
subscribe_to_hostapd_interfaces(hostapd_dir);
|
||||
|
||||
|
||||
// free(hostapd_dir); // free string
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) {
|
||||
int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
||||
uloop_init();
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
|
|
@ -578,6 +578,13 @@ int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) {
|
|||
ap_entry.ht = blobmsg_get_u8(tb[CLIENT_TABLE_HT]);
|
||||
ap_entry.vht = blobmsg_get_u8(tb[CLIENT_TABLE_VHT]);
|
||||
ap_entry.channel_utilization = blobmsg_get_u32(tb[CLIENT_TABLE_CHAN_UTIL]);
|
||||
|
||||
if (tb[CLIENT_TABLE_NUM_STA]) {
|
||||
ap_entry.station_count = blobmsg_get_u32(tb[CLIENT_TABLE_NUM_STA]);
|
||||
} else {
|
||||
ap_entry.station_count = 0;
|
||||
}
|
||||
|
||||
insert_to_ap_array(ap_entry);
|
||||
|
||||
if (do_kick) {
|
||||
|
|
@ -592,17 +599,17 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
|
|||
if (!msg)
|
||||
return;
|
||||
|
||||
parse_to_clients(msg, 1, req->peer);
|
||||
|
||||
char *str = blobmsg_format_json(msg, true);
|
||||
send_string_enc(str);
|
||||
|
||||
parse_to_clients(msg, 1, req->peer);
|
||||
|
||||
print_client_array();
|
||||
print_ap_array();
|
||||
}
|
||||
|
||||
static int ubus_get_clients() {
|
||||
for(int i = 0; i <= hostapd_sock_last; i++)
|
||||
{
|
||||
for (int i = 0; i <= hostapd_sock_last; i++) {
|
||||
int timeout = 1;
|
||||
ubus_invoke(ctx_clients, hostapd_sock_arr[i], "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000);
|
||||
}
|
||||
|
|
@ -611,10 +618,12 @@ static int ubus_get_clients() {
|
|||
|
||||
void update_clients(struct uloop_timeout *t) {
|
||||
ubus_get_clients();
|
||||
// maybe to much?! don't set timer again...
|
||||
uloop_timeout_set(&client_timer, timeout_config.update_client * 1000);
|
||||
}
|
||||
|
||||
void update_hostapd_sockets(struct uloop_timeout *t) {
|
||||
printf("Updating hostapd sockets!\n");
|
||||
subscribe_to_hostapd_interfaces(hostapd_dir_glob);
|
||||
uloop_timeout_set(&hostapd_timer, timeout_config.update_hostapd * 1000);
|
||||
}
|
||||
|
|
@ -635,8 +644,7 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint
|
|||
blobmsg_add_u8(&b, "deauth", deauth);
|
||||
blobmsg_add_u32(&b, "ban_time", ban_time);
|
||||
|
||||
for(int i = 0; i <= hostapd_sock_last; i++)
|
||||
{
|
||||
for (int i = 0; i <= hostapd_sock_last; i++) {
|
||||
int timeout = 1;
|
||||
ubus_invoke(ctx_clients, hostapd_sock_arr[i], "del_client", b.head, NULL, NULL, timeout * 1000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue