mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
reformat code
This commit is contained in:
parent
a2b7faee97
commit
377d0815e9
13 changed files with 116 additions and 124 deletions
|
|
@ -8,46 +8,46 @@ ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-unknow
|
||||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||||
|
|
||||||
SET(SOURCES
|
SET(SOURCES
|
||||||
main.c
|
main.c
|
||||||
|
|
||||||
storage/datastorage.c
|
storage/datastorage.c
|
||||||
include/datastorage.h
|
include/datastorage.h
|
||||||
|
|
||||||
network/networksocket.c
|
network/networksocket.c
|
||||||
include/networksocket.h
|
include/networksocket.h
|
||||||
|
|
||||||
network/broadcastsocket.c
|
network/broadcastsocket.c
|
||||||
include/broadcastsocket.h
|
include/broadcastsocket.h
|
||||||
|
|
||||||
network/multicastsocket.c
|
network/multicastsocket.c
|
||||||
include/multicastsocket.h
|
include/multicastsocket.h
|
||||||
|
|
||||||
utils/ubus.c
|
utils/ubus.c
|
||||||
include/ubus.h
|
include/ubus.h
|
||||||
|
|
||||||
include/utils.h
|
include/utils.h
|
||||||
|
|
||||||
utils/runopts.c
|
utils/runopts.c
|
||||||
include/runopts.h
|
include/runopts.h
|
||||||
|
|
||||||
utils/dawn_uci.c
|
utils/dawn_uci.c
|
||||||
include/dawn_uci.h
|
include/dawn_uci.h
|
||||||
|
|
||||||
crypto/crypto.c
|
crypto/crypto.c
|
||||||
include/crypto.h
|
include/crypto.h
|
||||||
|
|
||||||
crypto/base64.c
|
crypto/base64.c
|
||||||
include/base64.h
|
include/base64.h
|
||||||
|
|
||||||
utils/utils.c include/rssi.h utils/rssi.c)
|
utils/utils.c include/rssi.h utils/rssi.c)
|
||||||
|
|
||||||
SET(LIBS
|
SET(LIBS
|
||||||
ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto)
|
ubox ubus json-c blobmsg_json config uci gcrypt ssl crypto)
|
||||||
|
|
||||||
ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h)
|
ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h)
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(dawn ${LIBS})
|
TARGET_LINK_LIBRARIES(dawn ${LIBS})
|
||||||
|
|
||||||
INSTALL(TARGETS dawn
|
INSTALL(TARGETS dawn
|
||||||
RUNTIME DESTINATION /usr/bin/
|
RUNTIME DESTINATION /usr/bin/
|
||||||
)
|
)
|
||||||
|
|
@ -59,7 +59,7 @@ void gcrypt_set_key_and_iv(char *key, char *iv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// free out buffer after using!
|
// free out buffer after using!
|
||||||
char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int* out_length) {
|
char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length) {
|
||||||
if (0U != (msg_length & 0xfU))
|
if (0U != (msg_length & 0xfU))
|
||||||
msg_length += 0x10U - (msg_length & 0xfU);
|
msg_length += 0x10U - (msg_length & 0xfU);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ void gcrypt_init();
|
||||||
void gcrypt_set_key_and_iv(char *key, char *iv);
|
void gcrypt_set_key_and_iv(char *key, char *iv);
|
||||||
|
|
||||||
//char *gcrypt_encrypt_msg(char *msg, size_t msg_length);
|
//char *gcrypt_encrypt_msg(char *msg, size_t msg_length);
|
||||||
char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int* out_length);
|
char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length);
|
||||||
|
|
||||||
|
|
||||||
char *gcrypt_decrypt_msg(char *msg, size_t msg_length);
|
char *gcrypt_decrypt_msg(char *msg, size_t msg_length);
|
||||||
|
|
@ -31,8 +31,11 @@ void build_decoding_table();
|
||||||
void base64_cleanup();
|
void base64_cleanup();
|
||||||
|
|
||||||
int Base64decode_len(const char *bufcoded);
|
int Base64decode_len(const char *bufcoded);
|
||||||
|
|
||||||
int Base64encode_len(int len);
|
int Base64encode_len(int len);
|
||||||
|
|
||||||
int Base64encode(char *encoded, const char *string, int len);
|
int Base64encode(char *encoded, const char *string, int len);
|
||||||
|
|
||||||
int Base64decode(char *bufplain, const char *bufcoded);
|
int Base64decode(char *bufplain, const char *bufcoded);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,11 @@ struct ap_s ap_array[ARRAY_AP_LEN];
|
||||||
pthread_mutex_t ap_array_mutex;
|
pthread_mutex_t ap_array_mutex;
|
||||||
|
|
||||||
ap insert_to_ap_array(ap entry);
|
ap insert_to_ap_array(ap entry);
|
||||||
|
|
||||||
void print_ap_array();
|
void print_ap_array();
|
||||||
|
|
||||||
void *remove_ap_array_thread(void *arg);
|
void *remove_ap_array_thread(void *arg);
|
||||||
|
|
||||||
ap ap_array_get_ap(uint8_t bssid_addr[]);
|
ap ap_array_get_ap(uint8_t bssid_addr[]);
|
||||||
|
|
||||||
// Array
|
// Array
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int get_rssi_from_iwinfo(__uint8_t* client_addr);
|
int get_rssi_from_iwinfo(__uint8_t *client_addr);
|
||||||
|
|
||||||
#endif //DAWN_RSSI_H
|
#endif //DAWN_RSSI_H
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@
|
||||||
#define STR2MAC(a) &(a)[0], &(a)[1], &(a)[2], &(a)[3], &(a)[4], &(a)[5]
|
#define STR2MAC(a) &(a)[0], &(a)[1], &(a)[2], &(a)[3], &(a)[4], &(a)[5]
|
||||||
|
|
||||||
int hex_to_bin(char ch);
|
int hex_to_bin(char ch);
|
||||||
|
|
||||||
int hwaddr_aton(const char *txt, uint8_t *addr);
|
int hwaddr_aton(const char *txt, uint8_t *addr);
|
||||||
int convert_mac(char* in, char* out);
|
|
||||||
|
int convert_mac(char *in, char *out);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
17
src/main.c
17
src/main.c
|
|
@ -22,6 +22,7 @@
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
|
@ -42,8 +43,7 @@ pthread_t tid_get_client;
|
||||||
pthread_t tid_kick_clients;
|
pthread_t tid_kick_clients;
|
||||||
pthread_t tid_ap;
|
pthread_t tid_ap;
|
||||||
|
|
||||||
void daemon_shutdown()
|
void daemon_shutdown() {
|
||||||
{
|
|
||||||
// kill threads
|
// kill threads
|
||||||
printf("Cancelling Threads!\n");
|
printf("Cancelling Threads!\n");
|
||||||
pthread_cancel(tid_probe);
|
pthread_cancel(tid_probe);
|
||||||
|
|
@ -62,11 +62,9 @@ void daemon_shutdown()
|
||||||
//printf("Free Counter: %d\n", free_counter);
|
//printf("Free Counter: %d\n", free_counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal_handler(int sig)
|
void signal_handler(int sig) {
|
||||||
{
|
|
||||||
printf("SOME SIGNAL RECEIVED!\n");
|
printf("SOME SIGNAL RECEIVED!\n");
|
||||||
switch(sig)
|
switch (sig) {
|
||||||
{
|
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
//syslog(LOG_WARNING, "Received SIGHUP signal.");
|
//syslog(LOG_WARNING, "Received SIGHUP signal.");
|
||||||
break;
|
break;
|
||||||
|
|
@ -82,6 +80,7 @@ void signal_handler(int sig)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static void mtrace_init(void)
|
static void mtrace_init(void)
|
||||||
{
|
{
|
||||||
|
|
@ -211,9 +210,9 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1);
|
init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1);
|
||||||
|
|
||||||
pthread_create(&tid_probe, NULL, &remove_array_thread, (void*)&time_config.remove_probe);
|
pthread_create(&tid_probe, NULL, &remove_array_thread, (void *) &time_config.remove_probe);
|
||||||
pthread_create(&tid_client, NULL, &remove_client_array_thread, (void*)&time_config.remove_client);
|
pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client);
|
||||||
pthread_create(&tid_get_client, NULL, &update_clients_thread, (void*)&time_config.update_client);
|
pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client);
|
||||||
//pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL);
|
//pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL);
|
||||||
//pthread_create(&tid_ap, NULL, &remove_ap_array_thread, NULL);
|
//pthread_create(&tid_ap, NULL, &remove_ap_array_thread, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ void *receive_msg_enc(void *args) {
|
||||||
}
|
}
|
||||||
//recv_string[recv_string_len] = '\0';
|
//recv_string[recv_string_len] = '\0';
|
||||||
|
|
||||||
char* base64_dec_str = malloc(Base64decode_len(recv_string));
|
char *base64_dec_str = malloc(Base64decode_len(recv_string));
|
||||||
int base64_dec_length = Base64decode(base64_dec_str, recv_string);
|
int base64_dec_length = Base64decode(base64_dec_str, recv_string);
|
||||||
|
|
||||||
char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length);
|
char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length);
|
||||||
|
|
@ -214,7 +214,7 @@ int send_string_enc(char *msg) {
|
||||||
int length_enc;
|
int length_enc;
|
||||||
char *enc = gcrypt_encrypt_msg(msg, msglen + 1, &length_enc);
|
char *enc = gcrypt_encrypt_msg(msg, msglen + 1, &length_enc);
|
||||||
|
|
||||||
char* base64_enc_str = malloc(Base64encode_len(length_enc));
|
char *base64_enc_str = malloc(Base64encode_len(length_enc));
|
||||||
size_t base64_enc_length = Base64encode(base64_enc_str, enc, length_enc);
|
size_t base64_enc_length = Base64encode(base64_enc_str, enc, length_enc);
|
||||||
|
|
||||||
if (sendto(sock,
|
if (sendto(sock,
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ int eval_probe_metric(struct probe_entry_s probe_entry) {
|
||||||
ap ap_entry = ap_array_get_ap(probe_entry.bssid_addr);
|
ap ap_entry = ap_array_get_ap(probe_entry.bssid_addr);
|
||||||
|
|
||||||
// check if ap entry is available
|
// check if ap entry is available
|
||||||
if(mac_is_equal(ap_entry.bssid_addr, probe_entry.bssid_addr)) {
|
if (mac_is_equal(ap_entry.bssid_addr, probe_entry.bssid_addr)) {
|
||||||
score += probe_entry.ht_support ? dawn_metric.ht_support : 0;
|
score += probe_entry.ht_support ? dawn_metric.ht_support : 0;
|
||||||
score += !probe_entry.ht_support && !ap_entry.ht ? dawn_metric.no_ht_support : 0;
|
score += !probe_entry.ht_support && !ap_entry.ht ? dawn_metric.no_ht_support : 0;
|
||||||
score += probe_entry.vht_support ? dawn_metric.vht_support : 0;
|
score += probe_entry.vht_support ? dawn_metric.vht_support : 0;
|
||||||
|
|
@ -67,8 +67,7 @@ int eval_probe_metric(struct probe_entry_s probe_entry) {
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[])
|
int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[]) {
|
||||||
{
|
|
||||||
int own_score = -1;
|
int own_score = -1;
|
||||||
|
|
||||||
// find first client entry in probe array
|
// find first client entry in probe array
|
||||||
|
|
@ -95,8 +94,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// no entry for own ap
|
// no entry for own ap
|
||||||
if(own_score == -1)
|
if (own_score == -1) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +104,8 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!mac_is_equal(bssid_addr, probe_array[k].bssid_addr) &&
|
if (!mac_is_equal(bssid_addr, probe_array[k].bssid_addr) &&
|
||||||
own_score < eval_probe_metric(probe_array[k])) // that's wrong! find client_entry OR write things in probe array struct!
|
own_score <
|
||||||
|
eval_probe_metric(probe_array[k])) // that's wrong! find client_entry OR write things in probe array struct!
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -139,11 +138,9 @@ void kick_clients(uint8_t bssid[], uint32_t id) {
|
||||||
|
|
||||||
// update rssi
|
// update rssi
|
||||||
int rssi = get_rssi_from_iwinfo(client_array[j].client_addr);
|
int rssi = get_rssi_from_iwinfo(client_array[j].client_addr);
|
||||||
if(rssi != INT_MIN)
|
if (rssi != INT_MIN) {
|
||||||
{
|
|
||||||
pthread_mutex_unlock(&probe_array_mutex);
|
pthread_mutex_unlock(&probe_array_mutex);
|
||||||
if(!probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi))
|
if (!probe_array_update_rssi(client_array[j].bssid_addr, client_array[j].client_addr, rssi)) {
|
||||||
{
|
|
||||||
printf("Failed to update RSSI!\n");
|
printf("Failed to update RSSI!\n");
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&probe_array_mutex);
|
pthread_mutex_lock(&probe_array_mutex);
|
||||||
|
|
@ -156,13 +153,13 @@ void kick_clients(uint8_t bssid[], uint32_t id) {
|
||||||
print_client_entry(client_array[j]);
|
print_client_entry(client_array[j]);
|
||||||
del_client_interface(id, client_array[j].client_addr, 5, 1, 60000);
|
del_client_interface(id, client_array[j].client_addr, 5, 1, 60000);
|
||||||
|
|
||||||
// no entry in probe array for own bssid
|
// no entry in probe array for own bssid
|
||||||
} else if (kick_client(client_array[j]) == -1) {
|
} else if (kick_client(client_array[j]) == -1) {
|
||||||
printf("No Information about client. Force reconnect:\n");
|
printf("No Information about client. Force reconnect:\n");
|
||||||
print_client_entry(client_array[j]);
|
print_client_entry(client_array[j]);
|
||||||
del_client_interface(id, client_array[j].client_addr, 0, 0, 0);
|
del_client_interface(id, client_array[j].client_addr, 0, 0, 0);
|
||||||
|
|
||||||
// ap is best
|
// ap is best
|
||||||
} else {
|
} else {
|
||||||
printf("AP is best. Client will stay:\n");
|
printf("AP is best. Client will stay:\n");
|
||||||
print_client_entry(client_array[j]);
|
print_client_entry(client_array[j]);
|
||||||
|
|
@ -173,8 +170,7 @@ void kick_clients(uint8_t bssid[], uint32_t id) {
|
||||||
pthread_mutex_unlock(&client_array_mutex);
|
pthread_mutex_unlock(&client_array_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_connected(uint8_t bssid_addr[], uint8_t client_addr[])
|
int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
int found_in_array = 0;
|
int found_in_array = 0;
|
||||||
|
|
||||||
|
|
@ -184,9 +180,8 @@ int is_connected(uint8_t bssid_addr[], uint8_t client_addr[])
|
||||||
|
|
||||||
for (i = 0; i <= client_entry_last; i++) {
|
for (i = 0; i <= client_entry_last; i++) {
|
||||||
|
|
||||||
if ( mac_is_equal(bssid_addr, client_array[i].bssid_addr) &&
|
if (mac_is_equal(bssid_addr, client_array[i].bssid_addr) &&
|
||||||
mac_is_equal(client_addr, client_array[i].client_addr))
|
mac_is_equal(client_addr, client_array[i].client_addr)) {
|
||||||
{
|
|
||||||
found_in_array = 1;
|
found_in_array = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -450,12 +445,11 @@ ap ap_array_get_ap(uint8_t bssid_addr[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&ap_array_mutex);
|
pthread_mutex_lock(&ap_array_mutex);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i <= ap_entry_last; i++) {
|
for (i = 0; i <= ap_entry_last; i++) {
|
||||||
if (mac_is_equal(bssid_addr, ap_array[i].bssid_addr) || mac_is_greater(ap_array[i].bssid_addr, bssid_addr )) {
|
if (mac_is_equal(bssid_addr, ap_array[i].bssid_addr) || mac_is_greater(ap_array[i].bssid_addr, bssid_addr)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -474,7 +468,7 @@ void ap_array_insert(ap entry) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i <= ap_entry_last; i++) {
|
for (i = 0; i <= ap_entry_last; i++) {
|
||||||
if (!mac_is_greater(entry.bssid_addr, ap_array[i].bssid_addr)) {
|
if (!mac_is_greater(entry.bssid_addr, ap_array[i].bssid_addr)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -528,7 +522,7 @@ void remove_old_client_entries(time_t current_time, long long int threshold) {
|
||||||
void remove_old_probe_entries(time_t current_time, long long int threshold) {
|
void remove_old_probe_entries(time_t current_time, long long int threshold) {
|
||||||
for (int i = 0; i < probe_entry_last; i++) {
|
for (int i = 0; i < probe_entry_last; i++) {
|
||||||
if (probe_array[i].time < current_time - threshold) {
|
if (probe_array[i].time < current_time - threshold) {
|
||||||
if(!is_connected(probe_array[i].bssid_addr, probe_array[i].client_addr))
|
if (!is_connected(probe_array[i].bssid_addr, probe_array[i].client_addr))
|
||||||
probe_array_delete(probe_array[i]);
|
probe_array_delete(probe_array[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -543,8 +537,8 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *remove_array_thread(void *arg) {
|
void *remove_array_thread(void *arg) {
|
||||||
printf("Removing thread with time: %lu\n", *(long int*)arg);
|
printf("Removing thread with time: %lu\n", *(long int *) arg);
|
||||||
time_t time_treshold = *(time_t*)arg;
|
time_t time_treshold = *(time_t *) arg;
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep(time_treshold);
|
sleep(time_treshold);
|
||||||
pthread_mutex_lock(&probe_array_mutex);
|
pthread_mutex_lock(&probe_array_mutex);
|
||||||
|
|
@ -556,7 +550,7 @@ void *remove_array_thread(void *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *remove_client_array_thread(void *arg) {
|
void *remove_client_array_thread(void *arg) {
|
||||||
time_t time_treshold_client = *(time_t*)arg;
|
time_t time_treshold_client = *(time_t *) arg;
|
||||||
printf("Removing client thread with time: %lu\n", time_treshold_client);
|
printf("Removing client thread with time: %lu\n", time_treshold_client);
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep(time_treshold_client);
|
sleep(time_treshold_client);
|
||||||
|
|
@ -569,7 +563,7 @@ void *remove_client_array_thread(void *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *remove_ap_array_thread(void *arg) {
|
void *remove_ap_array_thread(void *arg) {
|
||||||
time_t time_treshold_ap = *(time_t*)arg;
|
time_t time_treshold_ap = *(time_t *) arg;
|
||||||
printf("Removing ap thread with time: %lu\n", time_treshold_ap);
|
printf("Removing ap thread with time: %lu\n", time_treshold_ap);
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep(time_treshold_ap);
|
sleep(time_treshold_ap);
|
||||||
|
|
|
||||||
|
|
@ -20,40 +20,39 @@ dawn.metric.freq
|
||||||
option remove_probe '120'
|
option remove_probe '120'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct time_config_s uci_get_time_config()
|
struct time_config_s uci_get_time_config() {
|
||||||
{
|
|
||||||
struct time_config_s ret;
|
struct time_config_s ret;
|
||||||
|
|
||||||
struct uci_context *c;
|
struct uci_context *c;
|
||||||
struct uci_ptr ptr;
|
struct uci_ptr ptr;
|
||||||
|
|
||||||
c = uci_alloc_context ();
|
c = uci_alloc_context();
|
||||||
|
|
||||||
printf("Loading TImes!");
|
printf("Loading TImes!");
|
||||||
|
|
||||||
|
|
||||||
char tmp_update_client[] = "dawn.times.update_client";
|
char tmp_update_client[] = "dawn.times.update_client";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_update_client, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_update_client, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.update_client = atoi(ptr.o->v.string);
|
ret.update_client = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_remove_client[] = "dawn.times.remove_client";
|
char tmp_remove_client[] = "dawn.times.remove_client";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_remove_client, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_remove_client, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.remove_client = atoi(ptr.o->v.string);
|
ret.remove_client = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_remove_probe[] = "dawn.times.remove_probe";
|
char tmp_remove_probe[] = "dawn.times.remove_probe";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_remove_probe, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_remove_probe, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.remove_probe = atoi(ptr.o->v.string);
|
ret.remove_probe = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
printf("Times: %lu, %lu, %lu\n", ret.update_client, ret.remove_client, ret.remove_probe);
|
printf("Times: %lu, %lu, %lu\n", ret.update_client, ret.remove_client, ret.remove_probe);
|
||||||
|
|
@ -63,95 +62,94 @@ struct time_config_s uci_get_time_config()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct probe_metric_s uci_get_dawn_metric()
|
struct probe_metric_s uci_get_dawn_metric() {
|
||||||
{
|
|
||||||
struct probe_metric_s ret;
|
struct probe_metric_s ret;
|
||||||
|
|
||||||
struct uci_context *c;
|
struct uci_context *c;
|
||||||
struct uci_ptr ptr;
|
struct uci_ptr ptr;
|
||||||
|
|
||||||
c = uci_alloc_context ();
|
c = uci_alloc_context();
|
||||||
|
|
||||||
char tmp_ht_support[] = "dawn.metric.ht_support";
|
char tmp_ht_support[] = "dawn.metric.ht_support";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_ht_support, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_ht_support, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.ht_support = atoi(ptr.o->v.string);
|
ret.ht_support = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_vht_support[] = "dawn.metric.vht_support";
|
char tmp_vht_support[] = "dawn.metric.vht_support";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_vht_support, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_vht_support, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.vht_support = atoi(ptr.o->v.string);
|
ret.vht_support = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_no_ht_support[] = "dawn.metric.no_ht_support";
|
char tmp_no_ht_support[] = "dawn.metric.no_ht_support";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_no_ht_support, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_no_ht_support, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.no_ht_support = atoi(ptr.o->v.string);
|
ret.no_ht_support = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_no_vht_support[] = "dawn.metric.no_vht_support";
|
char tmp_no_vht_support[] = "dawn.metric.no_vht_support";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_no_vht_support, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_no_vht_support, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.no_vht_support = atoi(ptr.o->v.string);
|
ret.no_vht_support = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_rssi[] = "dawn.metric.rssi";
|
char tmp_rssi[] = "dawn.metric.rssi";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_rssi, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_rssi, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.rssi = atoi(ptr.o->v.string);
|
ret.rssi = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_freq[] = "dawn.metric.freq";
|
char tmp_freq[] = "dawn.metric.freq";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_freq, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_freq, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.freq = atoi(ptr.o->v.string);
|
ret.freq = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_util[] = "dawn.metric.chan_util";
|
char tmp_util[] = "dawn.metric.chan_util";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_util, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_util, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.chan_util = atoi(ptr.o->v.string);
|
ret.chan_util = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_min_rssi[] = "dawn.metric.min_rssi";
|
char tmp_min_rssi[] = "dawn.metric.min_rssi";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_min_rssi, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_min_rssi, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.min_rssi = atoi(ptr.o->v.string);
|
ret.min_rssi = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
char tmp_max_chan_util[] = "dawn.metric.max_chan_util";
|
char tmp_max_chan_util[] = "dawn.metric.max_chan_util";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_max_chan_util, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.max_chan_util = atoi(ptr.o->v.string);
|
ret.max_chan_util = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
|
|
||||||
printf("Try to load min_probe_count\n");
|
printf("Try to load min_probe_count\n");
|
||||||
char tmp_min_probe_count[] = "dawn.metric.min_probe_count";
|
char tmp_min_probe_count[] = "dawn.metric.min_probe_count";
|
||||||
if (uci_lookup_ptr (c, &ptr, tmp_min_probe_count, 1) != UCI_OK) {
|
if (uci_lookup_ptr(c, &ptr, tmp_min_probe_count, 1) != UCI_OK) {
|
||||||
uci_perror(c, "uci_get_daw_metric Error");
|
uci_perror(c, "uci_get_daw_metric Error");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(ptr.o->type == UCI_TYPE_STRING)
|
if (ptr.o->type == UCI_TYPE_STRING)
|
||||||
ret.min_probe_count = atoi(ptr.o->v.string);
|
ret.min_probe_count = atoi(ptr.o->v.string);
|
||||||
|
|
||||||
printf("Loaded metric: %d\n", ret.min_probe_count);
|
printf("Loaded metric: %d\n", ret.min_probe_count);
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
#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 call_iwinfo(char* client_addr);
|
int call_iwinfo(char *client_addr);
|
||||||
int parse_rssi(char* iwinfo_string);
|
|
||||||
|
|
||||||
int get_rssi_from_iwinfo(__uint8_t* client_addr)
|
int parse_rssi(char *iwinfo_string);
|
||||||
{
|
|
||||||
|
int get_rssi_from_iwinfo(__uint8_t *client_addr) {
|
||||||
char mac_buf[20];
|
char mac_buf[20];
|
||||||
sprintf(mac_buf, "%x:%x:%x:%x:%x:%x", MAC2STR(client_addr));
|
sprintf(mac_buf, "%x:%x:%x:%x:%x:%x", MAC2STR(client_addr));
|
||||||
char mac_buf_conv[20];
|
char mac_buf_conv[20];
|
||||||
|
|
@ -20,8 +20,7 @@ int get_rssi_from_iwinfo(__uint8_t* client_addr)
|
||||||
return call_iwinfo(mac_buf_conv);
|
return call_iwinfo(mac_buf_conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int call_iwinfo(char* client_addr)
|
int call_iwinfo(char *client_addr) {
|
||||||
{
|
|
||||||
// TODO: REFACTOR THIS! USE NET LINK... LOOK AT IWINFO
|
// TODO: REFACTOR THIS! USE NET LINK... LOOK AT IWINFO
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
@ -30,7 +29,7 @@ int call_iwinfo(char* client_addr)
|
||||||
int rssi = INT_MIN;
|
int rssi = INT_MIN;
|
||||||
int command_length = 68;
|
int command_length = 68;
|
||||||
char iwinfo_command[command_length];
|
char iwinfo_command[command_length];
|
||||||
char* first_command = "(iwinfo wlan0 assoc && iwinfo wlan1 assoc) | grep ";
|
char *first_command = "(iwinfo wlan0 assoc && iwinfo wlan1 assoc) | grep ";
|
||||||
size_t length_first_command = strlen(first_command);
|
size_t length_first_command = strlen(first_command);
|
||||||
memcpy(iwinfo_command, first_command, length_first_command);
|
memcpy(iwinfo_command, first_command, length_first_command);
|
||||||
memcpy(iwinfo_command + length_first_command, client_addr, strlen(client_addr));
|
memcpy(iwinfo_command + length_first_command, client_addr, strlen(client_addr));
|
||||||
|
|
@ -39,12 +38,12 @@ int call_iwinfo(char* client_addr)
|
||||||
|
|
||||||
fp = popen(iwinfo_command, "r");
|
fp = popen(iwinfo_command, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf("Failed to run command\n" );
|
printf("Failed to run command\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the output a line at a time - output it. */
|
/* Read the output a line at a time - output it. */
|
||||||
while (fgets(path, sizeof(path)-1, fp) != NULL) {
|
while (fgets(path, sizeof(path) - 1, fp) != NULL) {
|
||||||
rssi = parse_rssi(path);
|
rssi = parse_rssi(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,15 +53,13 @@ int call_iwinfo(char* client_addr)
|
||||||
return rssi;
|
return rssi;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_rssi(char* iwinfo_string)
|
int parse_rssi(char *iwinfo_string) {
|
||||||
{
|
|
||||||
char cut_1[] = " ";
|
char cut_1[] = " ";
|
||||||
char cut_2[] = "dBm";
|
char cut_2[] = "dBm";
|
||||||
char *p_1 = strstr(iwinfo_string, cut_1);
|
char *p_1 = strstr(iwinfo_string, cut_1);
|
||||||
char *p_2 = strstr(iwinfo_string, cut_2);
|
char *p_2 = strstr(iwinfo_string, cut_2);
|
||||||
int rssi = INT_MIN;
|
int rssi = INT_MIN;
|
||||||
if(p_1 != NULL && p_2 != NULL)
|
if (p_1 != NULL && p_2 != NULL) {
|
||||||
{
|
|
||||||
int length = (int) (p_2 - p_1);
|
int length = (int) (p_2 - p_1);
|
||||||
char dest[length + 1];
|
char dest[length + 1];
|
||||||
memcpy(dest, p_1, (int) (p_2 - p_1));
|
memcpy(dest, p_1, (int) (p_2 - p_1));
|
||||||
|
|
|
||||||
|
|
@ -283,18 +283,16 @@ static int handle_probe_req(struct blob_attr *msg) {
|
||||||
static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
struct ubus_request_data *req, const char *method,
|
struct ubus_request_data *req, const char *method,
|
||||||
struct blob_attr *msg) {
|
struct blob_attr *msg) {
|
||||||
printf("METHOD new: %s\n",method);
|
printf("METHOD new: %s\n", method);
|
||||||
|
|
||||||
|
|
||||||
// TODO: Only handle probe request and NOT assoc, ...
|
// TODO: Only handle probe request and NOT assoc, ...
|
||||||
|
|
||||||
if (strncmp(method, "probe", 5) == 0) {
|
if (strncmp(method, "probe", 5) == 0) {
|
||||||
return handle_probe_req(msg);
|
return handle_probe_req(msg);
|
||||||
}
|
} else if (strncmp(method, "auth", 4) == 0) {
|
||||||
else if (strncmp(method, "auth", 4) == 0) {
|
|
||||||
return handle_auth_req(msg);
|
return handle_auth_req(msg);
|
||||||
}
|
} else if (strncmp(method, "assoc", 5) == 0) {
|
||||||
else if (strncmp(method, "assoc", 5) == 0) {
|
|
||||||
return handle_assoc_req(msg);
|
return handle_assoc_req(msg);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -515,7 +513,7 @@ static int ubus_get_clients() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *update_clients_thread(void *arg) {
|
void *update_clients_thread(void *arg) {
|
||||||
time_t time_update_client = *(time_t*)arg;
|
time_t time_update_client = *(time_t *) arg;
|
||||||
printf("Update client thread with time: %lu\n", time_update_client);
|
printf("Update client thread with time: %lu\n", time_update_client);
|
||||||
|
|
||||||
const char *ubus_socket = NULL;
|
const char *ubus_socket = NULL;
|
||||||
|
|
@ -611,8 +609,7 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr *
|
||||||
printf("UMDNS:\n%s", str);
|
printf("UMDNS:\n%s", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ubus_call_umdns()
|
int ubus_call_umdns() {
|
||||||
{
|
|
||||||
u_int32_t id;
|
u_int32_t id;
|
||||||
if (ubus_lookup_id(ctx, "umdns", &id)) {
|
if (ubus_lookup_id(ctx, "umdns", &id)) {
|
||||||
fprintf(stderr, "Failed to look up test object for %s\n", "umdns");
|
fprintf(stderr, "Failed to look up test object for %s\n", "umdns");
|
||||||
|
|
@ -624,8 +621,7 @@ int ubus_call_umdns()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ubus_send_probe_via_network(struct probe_entry_s probe_entry)
|
int ubus_send_probe_via_network(struct probe_entry_s probe_entry) {
|
||||||
{
|
|
||||||
printf("Try to send new probe!!!\n");
|
printf("Try to send new probe!!!\n");
|
||||||
|
|
||||||
static struct blob_buf b;
|
static struct blob_buf b;
|
||||||
|
|
|
||||||
|
|
@ -25,19 +25,19 @@ int hwaddr_aton(const char *txt, uint8_t *addr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int convert_mac(char* in, char* out) {
|
int convert_mac(char *in, char *out) {
|
||||||
int i,j = 0;
|
int i, j = 0;
|
||||||
|
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
if(in[j+1] != ':' && in[j+1] != '\0') {
|
if (in[j + 1] != ':' && in[j + 1] != '\0') {
|
||||||
out[3 * i] = toupper(in[j]);
|
out[3 * i] = toupper(in[j]);
|
||||||
out[(3 * i) + 1] = toupper(in[j + 1]);
|
out[(3 * i) + 1] = toupper(in[j + 1]);
|
||||||
out[(3 * i) + 2] = in[j + 2];
|
out[(3 * i) + 2] = in[j + 2];
|
||||||
j+= 3;
|
j += 3;
|
||||||
} else {
|
} else {
|
||||||
out[3 * i] = '0';
|
out[3 * i] = '0';
|
||||||
out[(3 * i) + 1] = toupper(in[j]);
|
out[(3 * i) + 1] = toupper(in[j]);
|
||||||
out[(3 * i) + 2] = toupper(in[j+1]);
|
out[(3 * i) + 2] = toupper(in[j + 1]);
|
||||||
j += 2;
|
j += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue