fix ubus_invoke, fix iwinfo

This commit is contained in:
Polynomialdivision 2018-07-25 19:16:16 +02:00
parent 7dd5d0f6ef
commit 0407da37e8
3 changed files with 60 additions and 21 deletions

View file

@ -39,14 +39,14 @@ config metric
option low_rssi_val '-80'
option chan_util_val '140'
option max_chan_util_val '170'
option min_probe_count '2'
option min_probe_count '0'
option bandwith_threshold '6'
option use_station_count '1'
option max_station_diff '1'
option eval_probe_req '1'
option eval_auth_req '1' # no real reasoncode...
option eval_assoc_req '1' # just deny assocs...
option kicking '1'
option eval_probe_req '0'
option eval_auth_req '0' # no real reasoncode...
option eval_assoc_req '0' # just deny assocs...
option kicking '0'
option deny_auth_reason '1' # unspecified
option deny_assoc_reason '17' # assoc rejected can't handle new station
option use_driver_recog '1'

View file

@ -276,21 +276,49 @@ int get_ssid(const char *ifname, char* ssid) {
int get_channel_utilization(const char *ifname, uint64_t *last_channel_time, uint64_t *last_channel_time_busy) {
int len;
const struct iwinfo_ops *iw;
struct iwinfo_survey_entry survey_entry;
char buf[IWINFO_BUFSIZE];
struct iwinfo_survey_entry *e;
int ret = 0;
iw = iwinfo_backend(ifname);
if (iw->survey(ifname, &survey_entry))
int freq;
if (iw->frequency(ifname, &freq))
{
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;
if (iw->survey(ifname, buf, &len))
{
printf("Survey not possible!\n\n");
return 0;
}
else if (len <= 0)
{
printf("No survey results\n\n");
return 0;
}
for (int i = 0, x = 1; i < len; i += sizeof(struct iwinfo_survey_entry), x++)
{
e = (struct iwinfo_survey_entry *) &buf[i];
if(e->mhz == freq)
{
uint64_t dividend = e->busy_time - *last_channel_time_busy;
uint64_t divisor = e->active_time - *last_channel_time;
*last_channel_time = e->active_time;
*last_channel_time_busy = e->busy_time;
if(divisor)
ret = (int)(dividend * 255 / divisor);
break;
}
}
if(divisor)
ret = (int)(dividend * 255 / divisor);
iwinfo_finish();
return ret;
}

View file

@ -32,6 +32,8 @@ static struct blob_buf data_buf;
static struct blob_buf b_probe;
static struct blob_buf b_domain;
static struct blob_buf b_notify;
static struct blob_buf b_clients;
static struct blob_buf b_umdns;
void update_clients(struct uloop_timeout *t);
@ -700,7 +702,6 @@ static int add_subscriber(char *name) {
struct hostapd_sock_entry *hostapd_entry;
uint32_t id = 0;
sprintf(subscribe_name, "hostapd.%s", name);
if (ubus_lookup_id(ctx, subscribe_name, &id)) {
@ -708,6 +709,9 @@ static int add_subscriber(char *name) {
return -1;
}
printf("Subscribing to: %s\n", subscribe_name);
printf("Subscriber ID: %d\n", id);
if(hostapd_array_check_id(id))
{
// entry already existing
@ -728,7 +732,6 @@ static int add_subscriber(char *name) {
hostapd_entry->ht = (uint8_t) support_ht(name);
hostapd_entry->vht = (uint8_t) support_vht(name);
ret = ubus_register_subscriber(ctx, &hostapd_entry->subscriber);
ret = ubus_subscribe( ctx, &hostapd_entry->subscriber, id);
@ -772,20 +775,22 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
return -1;
} else {
printf("Connected to ubus\n");
}
}
ubus_add_uloop(ctx);
// set dawn metric
dawn_metric = uci_get_dawn_metric();
uloop_timeout_add(&hostapd_timer);
//uloop_timeout_add(&hostapd_timer);
// remove probe
uloop_add_data_cbs();
// get clients
printf("SETTING UP CLIENT TIMER:\n");
uloop_timeout_add(&client_timer);
printf("FINISHED ADDING CLIENT TIMER!\n");
uloop_timeout_add(&channel_utilization_timer);
@ -798,6 +803,8 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
if (network_config.network_option == 2)
run_server(network_config.tcp_port);
subscribe_to_hostapd_interfaces(hostapd_dir_glob);
//subscribe_to_hostapd_interfaces(hostapd_dir_glob);
uloop_run();
@ -961,6 +968,8 @@ int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) {
static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_attr *msg) {
printf("GOT CALLBACK!\n");
if (!msg)
return;
@ -995,9 +1004,10 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
}
static int ubus_get_clients() {
int timeout = 1;
for (int i = 0; i <= hostapd_sock_last; i++) {
int timeout = 1;
ubus_invoke(ctx, hostapd_sock_arr[i]->id, "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000);
blob_buf_init(&b_clients, 0);
ubus_invoke(ctx, hostapd_sock_arr[i]->id, "get_clients", b_clients.head, ubus_get_clients_cb, NULL, timeout * 1000);
}
return 0;
}
@ -1106,8 +1116,9 @@ int ubus_call_umdns() {
}
int timeout = 1;
ubus_invoke(ctx, id, "update", NULL, NULL, NULL, timeout * 1000);
ubus_invoke(ctx, id, "browse", NULL, ubus_umdns_cb, NULL, timeout * 1000);
blob_buf_init(&b_umdns, 0);
ubus_invoke(ctx, id, "update", b_umdns.head, NULL, NULL, timeout * 1000);
ubus_invoke(ctx, id, "browse", b_umdns.head, ubus_umdns_cb, NULL, timeout * 1000);
return 0;
}