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
2352474a36
commit
b6cc6470af
10 changed files with 116 additions and 175 deletions
|
@ -89,10 +89,12 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
int Base64encode_len(int len);
|
||||
int Base64encode(char * coded_dst, const char *plain_src,int len_plain_src);
|
||||
|
||||
int Base64decode_len(const char * coded_src);
|
||||
int Base64decode(char * plain_dst, const char *coded_src);
|
||||
int Base64encode(char *coded_dst, const char *plain_src, int len_plain_src);
|
||||
|
||||
int Base64decode_len(const char *coded_src);
|
||||
|
||||
int Base64decode(char *plain_dst, const char *coded_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ uint8_t mac_list[MAC_LIST_LENGTH][ETH_ALEN];
|
|||
|
||||
// ---------------- Functions ----------
|
||||
void insert_macs_from_file();
|
||||
|
||||
int insert_to_maclist(uint8_t mac[]);
|
||||
|
||||
|
||||
|
@ -67,13 +68,13 @@ struct time_config_s {
|
|||
};
|
||||
|
||||
struct network_config_s {
|
||||
const char* broadcast_ip;
|
||||
const char *broadcast_ip;
|
||||
int broadcast_port;
|
||||
int tcp_port;
|
||||
int network_option;
|
||||
const char* multicast;
|
||||
const char* shared_key;
|
||||
const char* iv;
|
||||
const char *multicast;
|
||||
const char *shared_key;
|
||||
const char *iv;
|
||||
int bool_multicast;
|
||||
};
|
||||
|
||||
|
@ -226,7 +227,7 @@ int probe_array_set_all_probe_count(uint8_t client_addr[], uint32_t probe_count)
|
|||
#define TIME_THRESHOLD 120 // every minute
|
||||
|
||||
// ---------------- Global variables ----------------
|
||||
char* sort_string;
|
||||
char *sort_string;
|
||||
|
||||
// ---------------- Functions -------------------
|
||||
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
|
||||
|
|
|
@ -7,9 +7,9 @@ struct time_config_s uci_get_time_config();
|
|||
|
||||
struct network_config_s uci_get_dawn_network();
|
||||
|
||||
const char* uci_get_dawn_hostapd_dir();
|
||||
const char *uci_get_dawn_hostapd_dir();
|
||||
|
||||
const char* uci_get_dawn_sort_order();
|
||||
const char *uci_get_dawn_sort_order();
|
||||
|
||||
int uci_init();
|
||||
|
||||
|
|
|
@ -4,21 +4,26 @@
|
|||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
|
||||
struct network_con_s
|
||||
{
|
||||
struct network_con_s {
|
||||
int sockfd;
|
||||
struct sockaddr_in sock_addr;
|
||||
};
|
||||
|
||||
void *run_tcp_socket(void *arg);
|
||||
int add_tcp_conncection(char* ipv4, int port);
|
||||
|
||||
int add_tcp_conncection(char *ipv4, int port);
|
||||
|
||||
int run_server(int port);
|
||||
|
||||
void print_tcp_array();
|
||||
|
||||
pthread_mutex_t tcp_array_mutex;
|
||||
|
||||
int insert_to_tcp_array(struct network_con_s entry);
|
||||
|
||||
int tcp_array_contains_address(struct sockaddr_in entry);
|
||||
void send_tcp(char* msg);
|
||||
|
||||
void send_tcp(char *msg);
|
||||
|
||||
#define ARRAY_NETWORK_LEN 50
|
||||
struct network_con_s network_array[ARRAY_NETWORK_LEN];
|
||||
|
|
12
src/main.c
12
src/main.c
|
@ -28,6 +28,7 @@ struct sigaction signal_action;
|
|||
|
||||
pthread_t tid_tcp_server;
|
||||
pthread_t tid_connections;
|
||||
|
||||
void daemon_shutdown() {
|
||||
// kill threads
|
||||
close_socket();
|
||||
|
@ -60,8 +61,7 @@ void signal_handler(int sig) {
|
|||
}
|
||||
}
|
||||
|
||||
int init_mutex()
|
||||
{
|
||||
int init_mutex() {
|
||||
if (pthread_mutex_init(&list_mutex, NULL) != 0) {
|
||||
printf("\n mutex init failed\n");
|
||||
return 1;
|
||||
|
@ -89,8 +89,7 @@ int init_mutex()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int run_tcp_server()
|
||||
{
|
||||
int run_tcp_server() {
|
||||
//run_server(1027);
|
||||
//pthread_create(&tid_tcp_server, NULL, &run_tcp_socket, NULL);
|
||||
//start_umdns_update();
|
||||
|
@ -124,12 +123,11 @@ int main(int argc, char **argv) {
|
|||
timeout_config = time_config; // TODO: Refactor...
|
||||
|
||||
hostapd_dir_glob = uci_get_dawn_hostapd_dir();
|
||||
sort_string = (char*) uci_get_dawn_sort_order();
|
||||
sort_string = (char *) uci_get_dawn_sort_order();
|
||||
|
||||
init_mutex();
|
||||
|
||||
switch(net_config.network_option)
|
||||
{
|
||||
switch (net_config.network_option) {
|
||||
case 0:
|
||||
init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, 0);
|
||||
break;
|
||||
|
|
|
@ -30,9 +30,9 @@ struct client {
|
|||
int ctr;
|
||||
};
|
||||
|
||||
static void client_close(struct ustream *s)
|
||||
{
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
static void client_close(struct ustream *s) {
|
||||
struct client *cl = container_of(s,
|
||||
struct client, s.stream);
|
||||
|
||||
fprintf(stderr, "Connection closed\n");
|
||||
ustream_free(s);
|
||||
|
@ -40,14 +40,13 @@ static void client_close(struct ustream *s)
|
|||
free(cl);
|
||||
}
|
||||
|
||||
static void client_notify_write(struct ustream *s, int bytes)
|
||||
{
|
||||
static void client_notify_write(struct ustream *s, int bytes) {
|
||||
return;
|
||||
}
|
||||
|
||||
static void client_notify_state(struct ustream *s)
|
||||
{
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
static void client_notify_state(struct ustream *s) {
|
||||
struct client *cl = container_of(s,
|
||||
struct client, s.stream);
|
||||
|
||||
if (!s->eof)
|
||||
return;
|
||||
|
@ -58,8 +57,7 @@ static void client_notify_state(struct ustream *s)
|
|||
|
||||
}
|
||||
|
||||
static void client_read_cb(struct ustream *s, int bytes)
|
||||
{
|
||||
static void client_read_cb(struct ustream *s, int bytes) {
|
||||
char *str;
|
||||
int len;
|
||||
|
||||
|
@ -72,7 +70,7 @@ static void client_read_cb(struct ustream *s, int bytes)
|
|||
handle_network_msg(str);
|
||||
ustream_consume(s, len);
|
||||
|
||||
} while(1);
|
||||
} while (1);
|
||||
|
||||
if (s->w.data_bytes > 256 && !ustream_read_blocked(s)) {
|
||||
fprintf(stderr, "Block read, bytes: %d\n", s->w.data_bytes);
|
||||
|
@ -80,8 +78,7 @@ static void client_read_cb(struct ustream *s, int bytes)
|
|||
}
|
||||
}
|
||||
|
||||
static void server_cb(struct uloop_fd *fd, unsigned int events)
|
||||
{
|
||||
static void server_cb(struct uloop_fd *fd, unsigned int events) {
|
||||
struct client *cl;
|
||||
unsigned int sl = sizeof(struct sockaddr_in);
|
||||
int sfd;
|
||||
|
@ -105,8 +102,7 @@ static void server_cb(struct uloop_fd *fd, unsigned int events)
|
|||
fprintf(stderr, "New connection\n");
|
||||
}
|
||||
|
||||
int run_server(int port)
|
||||
{
|
||||
int run_server(int port) {
|
||||
char port_str[12];
|
||||
sprintf(port_str, "%d", port);
|
||||
|
||||
|
@ -122,7 +118,7 @@ int run_server(int port)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int add_tcp_conncection(char* ipv4, int port){
|
||||
int add_tcp_conncection(char *ipv4, int port) {
|
||||
int sockfd;
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
|
@ -136,7 +132,7 @@ int add_tcp_conncection(char* ipv4, int port){
|
|||
|
||||
print_tcp_array();
|
||||
|
||||
if(tcp_array_contains_address(serv_addr)) {
|
||||
if (tcp_array_contains_address(serv_addr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -164,18 +160,15 @@ int insert_to_tcp_array(struct network_con_s entry) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void print_tcp_entry(struct network_con_s entry)
|
||||
{
|
||||
void print_tcp_entry(struct network_con_s entry) {
|
||||
printf("Conenctin to Port: %d\n", entry.sock_addr.sin_port);
|
||||
}
|
||||
|
||||
void send_tcp(char* msg)
|
||||
{
|
||||
void send_tcp(char *msg) {
|
||||
printf("SENDING TCP!\n");
|
||||
pthread_mutex_lock(&tcp_array_mutex);
|
||||
for (int i = 0; i <= tcp_entry_last; i++) {
|
||||
if(send(network_array[i].sockfd, msg, strlen(msg), 0) < 0)
|
||||
{
|
||||
if (send(network_array[i].sockfd, msg, strlen(msg), 0) < 0) {
|
||||
close(network_array->sockfd);
|
||||
printf("Removing bad TCP connection!\n");
|
||||
for (int j = i; j < tcp_entry_last; j++) {
|
||||
|
@ -191,8 +184,7 @@ void send_tcp(char* msg)
|
|||
}
|
||||
|
||||
|
||||
void print_tcp_array()
|
||||
{
|
||||
void print_tcp_array() {
|
||||
printf("--------Connections------\n");
|
||||
for (int i = 0; i <= tcp_entry_last; i++) {
|
||||
print_tcp_entry(network_array[i]);
|
||||
|
|
|
@ -19,11 +19,10 @@ int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, floa
|
|||
|
||||
#define IWINFO_BUFSIZE 24 * 1024
|
||||
|
||||
#define IWINFO_ESSID_MAX_SIZE 32
|
||||
#define IWINFO_ESSID_MAX_SIZE 32
|
||||
|
||||
|
||||
int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare)
|
||||
{
|
||||
int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare) {
|
||||
const struct iwinfo_ops *iw;
|
||||
|
||||
char mac_buf[20];
|
||||
|
@ -39,31 +38,29 @@ int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare
|
|||
return 0;
|
||||
}
|
||||
|
||||
char* essid = NULL;
|
||||
char* essid_to_compare = NULL;
|
||||
char *essid = NULL;
|
||||
char *essid_to_compare = NULL;
|
||||
|
||||
char buf_essid[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
|
||||
char buf_essid_to_compare[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
|
||||
char buf_essid[IWINFO_ESSID_MAX_SIZE + 1] = {0};
|
||||
char buf_essid_to_compare[IWINFO_ESSID_MAX_SIZE + 1] = {0};
|
||||
|
||||
while ((entry = readdir(dirp)) != NULL && (essid == NULL || essid_to_compare == NULL)) {
|
||||
if (entry->d_type == DT_SOCK) {
|
||||
|
||||
iw = iwinfo_backend(entry->d_name);
|
||||
|
||||
static char buf_bssid[18] = { 0 };
|
||||
static char buf_bssid[18] = {0};
|
||||
if (iw->bssid(entry->d_name, buf_bssid))
|
||||
snprintf(buf_bssid, sizeof(buf_bssid), "00:00:00:00:00:00");
|
||||
|
||||
if(strcmp(mac_buf, buf_bssid) == 0)
|
||||
{
|
||||
if (strcmp(mac_buf, buf_bssid) == 0) {
|
||||
|
||||
if (iw->ssid(entry->d_name, buf_essid))
|
||||
memset(buf_essid, 0, sizeof(buf_essid));
|
||||
essid = buf_essid;
|
||||
}
|
||||
|
||||
if(strcmp(mac_buf_to_compare, buf_bssid) == 0)
|
||||
{
|
||||
if (strcmp(mac_buf_to_compare, buf_bssid) == 0) {
|
||||
if (iw->ssid(entry->d_name, buf_essid_to_compare))
|
||||
memset(buf_essid_to_compare, 0, sizeof(buf_essid_to_compare));
|
||||
essid_to_compare = buf_essid_to_compare;
|
||||
|
@ -74,13 +71,11 @@ int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare
|
|||
|
||||
printf("Comparing: %s with %s\n", essid, essid_to_compare);
|
||||
|
||||
if(essid == NULL || essid_to_compare == NULL)
|
||||
{
|
||||
if (essid == NULL || essid_to_compare == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(strcmp(essid, essid_to_compare) == 0)
|
||||
{
|
||||
if (strcmp(essid, essid_to_compare) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,8 @@ static struct uci_package *uci_pkg;
|
|||
// 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);
|
||||
const char *name) {
|
||||
const char *str = uci_lookup_option_string(uci, s, name);
|
||||
return str == NULL ? -1 : atoi(str);
|
||||
}
|
||||
|
||||
|
@ -23,11 +22,11 @@ struct time_config_s uci_get_time_config() {
|
|||
printf("Loading Times!");
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "times") == 0)
|
||||
{
|
||||
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");
|
||||
|
@ -45,11 +44,11 @@ struct probe_metric_s uci_get_dawn_metric() {
|
|||
struct probe_metric_s ret;
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "metric") == 0)
|
||||
{
|
||||
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");
|
||||
|
@ -83,11 +82,11 @@ struct network_config_s uci_get_dawn_network() {
|
|||
struct network_config_s ret;
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "network") == 0)
|
||||
{
|
||||
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);
|
||||
|
@ -104,7 +103,8 @@ struct network_config_s uci_get_dawn_network() {
|
|||
|
||||
return ret;
|
||||
}
|
||||
const char* uci_get_dawn_hostapd_dir() {
|
||||
|
||||
const char *uci_get_dawn_hostapd_dir() {
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
|
@ -117,21 +117,20 @@ const char* uci_get_dawn_hostapd_dir() {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const char* uci_get_dawn_sort_order() {
|
||||
const char *uci_get_dawn_sort_order() {
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "ordering") == 0)
|
||||
{
|
||||
if (strcmp(s->type, "ordering") == 0) {
|
||||
return uci_lookup_option_string(uci_ctx, s, "sort_order");
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int uci_init()
|
||||
{
|
||||
int uci_init() {
|
||||
struct uci_context *ctx = uci_ctx;
|
||||
|
||||
if (!ctx) {
|
||||
|
@ -152,14 +151,11 @@ int uci_init()
|
|||
return 1;
|
||||
}
|
||||
|
||||
int uci_clear()
|
||||
{
|
||||
if(uci_pkg != NULL)
|
||||
{
|
||||
int uci_clear() {
|
||||
if (uci_pkg != NULL) {
|
||||
uci_unload(uci_ctx, uci_pkg);
|
||||
}
|
||||
if(uci_ctx != NULL)
|
||||
{
|
||||
if (uci_ctx != NULL) {
|
||||
uci_free_context(uci_ctx);
|
||||
}
|
||||
return 1;
|
||||
|
|
114
src/utils/ubus.c
114
src/utils/ubus.c
|
@ -290,18 +290,15 @@ static int decide_function(probe_entry *prob_req, int req_type) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(req_type == REQ_TYPE_PROBE && !dawn_metric.eval_probe_req)
|
||||
{
|
||||
if (req_type == REQ_TYPE_PROBE && !dawn_metric.eval_probe_req) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(req_type == REQ_TYPE_AUTH && !dawn_metric.eval_auth_req)
|
||||
{
|
||||
if (req_type == REQ_TYPE_AUTH && !dawn_metric.eval_auth_req) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(req_type == REQ_TYPE_AUTH && !dawn_metric.eval_assoc_req)
|
||||
{
|
||||
if (req_type == REQ_TYPE_AUTH && !dawn_metric.eval_assoc_req) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -457,8 +454,7 @@ static int handle_probe_req(struct blob_attr *msg) {
|
|||
probe_entry prob_req;
|
||||
probe_entry tmp_prob_req;
|
||||
|
||||
if(parse_to_probe_req(msg, &prob_req) == 0)
|
||||
{
|
||||
if (parse_to_probe_req(msg, &prob_req) == 0) {
|
||||
tmp_prob_req = insert_to_array(prob_req, 1);
|
||||
send_blob_attr_via_network(msg, "probe");
|
||||
}
|
||||
|
@ -475,8 +471,8 @@ static int handle_deauth_req(struct blob_attr *msg) {
|
|||
parse_to_hostapd_notify(msg, ¬ify_req);
|
||||
|
||||
client client_entry;
|
||||
memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN );
|
||||
memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN );
|
||||
memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN);
|
||||
memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN);
|
||||
|
||||
pthread_mutex_lock(&client_array_mutex);
|
||||
client_array_delete(client_entry);
|
||||
|
@ -493,16 +489,15 @@ static int handle_set_probe(struct blob_attr *msg) {
|
|||
parse_to_hostapd_notify(msg, ¬ify_req);
|
||||
|
||||
client client_entry;
|
||||
memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN );
|
||||
memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN );
|
||||
memcpy(client_entry.bssid_addr, notify_req.bssid_addr, sizeof(uint8_t) * ETH_ALEN);
|
||||
memcpy(client_entry.client_addr, notify_req.client_addr, sizeof(uint8_t) * ETH_ALEN);
|
||||
|
||||
probe_array_set_all_probe_count(client_entry.client_addr, dawn_metric.min_probe_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_network_msg(char* msg)
|
||||
{
|
||||
int handle_network_msg(char *msg) {
|
||||
//printf("HANDLING NETWORK MSG: %s\n", msg);
|
||||
struct blob_attr *tb[__NETWORK_MAX];
|
||||
char *method;
|
||||
|
@ -513,8 +508,7 @@ int handle_network_msg(char* msg)
|
|||
|
||||
blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(network_buf.head), blob_len(network_buf.head));
|
||||
|
||||
if(!tb[NETWORK_METHOD] ||!tb[NETWORK_DATA] )
|
||||
{
|
||||
if (!tb[NETWORK_METHOD] || !tb[NETWORK_DATA]) {
|
||||
return -1;
|
||||
}
|
||||
//method = blobmsg_get_string(tb[NETWORK_METHOD]);
|
||||
|
@ -528,35 +522,27 @@ int handle_network_msg(char* msg)
|
|||
|
||||
|
||||
//printf("DO STRINGCOMPARE: %s : %s!\n", method, data);
|
||||
if(!data_buf.head)
|
||||
{
|
||||
if (!data_buf.head) {
|
||||
//printf("NULL?!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(blob_len(data_buf.head) <= 0)
|
||||
{
|
||||
if (blob_len(data_buf.head) <= 0) {
|
||||
//printf("NULL?!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(strlen(method) < 5)
|
||||
{
|
||||
if (strlen(method) < 5) {
|
||||
//printf("STRING IS LESS THAN 5!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strncmp(method, "probe", 5) == 0) {
|
||||
//printf("METHOD PROBE\n");
|
||||
probe_entry entry;
|
||||
if(parse_to_probe_req(data_buf.head, &entry) == 0)
|
||||
{
|
||||
if (parse_to_probe_req(data_buf.head, &entry) == 0) {
|
||||
insert_to_array(entry, 0);
|
||||
//print_probe_array();
|
||||
}
|
||||
} else if (strncmp(method, "clients", 5) == 0) {
|
||||
//printf("METHOD CLIENTS\n");
|
||||
//printf("PARSING CLIENTS NETWORK MSG!\n");
|
||||
parse_to_clients(data_buf.head, 0, 0);
|
||||
} else if (strncmp(method, "deauth", 5) == 0) {
|
||||
printf("METHOD DEAUTH\n");
|
||||
|
@ -565,31 +551,12 @@ int handle_network_msg(char* msg)
|
|||
printf("HANDLING SET PROBE!\n");
|
||||
handle_set_probe(data_buf.head);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
hostapd_notify_entry entry;
|
||||
parse_to_hostapd_notify(data_buf.head, &entry);
|
||||
|
||||
client client_entry;
|
||||
memcpy(client_entry.bssid_addr, client_entry.bssid_addr, sizeof(uint8_t) * ETH_ALEN );
|
||||
memcpy(client_entry.client_addr, client_entry.client_addr, sizeof(uint8_t) * ETH_ALEN );
|
||||
|
||||
pthread_mutex_lock(&client_array_mutex);
|
||||
client_array_delete(client_entry);
|
||||
pthread_mutex_unlock(&client_array_mutex);*/
|
||||
//}
|
||||
//free(method);
|
||||
//free(data);
|
||||
//printf("HANDLING FINISHED NETWORK MSG!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int send_blob_attr_via_network(struct blob_attr *msg, char* method)
|
||||
{
|
||||
if(!msg)
|
||||
{
|
||||
int send_blob_attr_via_network(struct blob_attr *msg, char *method) {
|
||||
if (!msg) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -617,11 +584,8 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
str = blobmsg_format_json(msg, true);
|
||||
printf("METHOD new: %s : %s\n", method, str);
|
||||
|
||||
//TODO CHECK IF FREE IS CORREECT!
|
||||
free(str);
|
||||
|
||||
// TODO: Only handle probe request and NOT assoc, ...
|
||||
|
||||
if (strncmp(method, "probe", 5) == 0) {
|
||||
return handle_probe_req(msg);
|
||||
} else if (strncmp(method, "auth", 4) == 0) {
|
||||
|
@ -700,8 +664,6 @@ static int subscribe_to_hostapd(const char *hostapd_dir) {
|
|||
|
||||
subscribe_to_hostapd_interfaces(hostapd_dir);
|
||||
|
||||
|
||||
// free(hostapd_dir); // free string
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -741,7 +703,7 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
|||
|
||||
start_umdns_update();
|
||||
|
||||
if(network_config.network_option == 2)
|
||||
if (network_config.network_option == 2)
|
||||
run_server(network_config.tcp_port);
|
||||
|
||||
uloop_run();
|
||||
|
@ -829,18 +791,15 @@ dump_client_table(struct blob_attr *head, int len, const char *bssid_addr, uint3
|
|||
int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) {
|
||||
struct blob_attr *tb[__CLIENT_TABLE_MAX];
|
||||
|
||||
if(!msg)
|
||||
{
|
||||
if (!msg) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!blob_data(msg))
|
||||
{
|
||||
if (!blob_data(msg)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(blob_len(msg) <= 0)
|
||||
{
|
||||
if (blob_len(msg) <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -857,7 +816,7 @@ 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]);
|
||||
strcpy((char*)ap_entry.ssid, blobmsg_get_string(tb[CLIENT_TABLE_SSID]));
|
||||
strcpy((char *) ap_entry.ssid, blobmsg_get_string(tb[CLIENT_TABLE_SSID]));
|
||||
|
||||
if (tb[CLIENT_TABLE_NUM_STA]) {
|
||||
ap_entry.station_count = blobmsg_get_u32(tb[CLIENT_TABLE_NUM_STA]);
|
||||
|
@ -905,8 +864,7 @@ void update_tcp_connections(struct uloop_timeout *t) {
|
|||
uloop_timeout_set(&umdns_timer, timeout_config.update_tcp_con * 1000);
|
||||
}
|
||||
|
||||
void start_umdns_update()
|
||||
{
|
||||
void start_umdns_update() {
|
||||
// update connections
|
||||
uloop_timeout_add(&umdns_timer);
|
||||
}
|
||||
|
@ -958,8 +916,7 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr *
|
|||
|
||||
blobmsg_parse(dawn_umdns_table_policy, __DAWN_UMDNS_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (!tb[DAWN_UMDNS_TABLE])
|
||||
{
|
||||
if (!tb[DAWN_UMDNS_TABLE]) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -978,7 +935,7 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr *
|
|||
if (tb_dawn[DAWN_UMDNS_IPV4] && tb_dawn[DAWN_UMDNS_PORT]) {
|
||||
printf("IPV4: %s\n", blobmsg_get_string(tb_dawn[DAWN_UMDNS_IPV4]));
|
||||
printf("Port: %d\n", blobmsg_get_u32(tb_dawn[DAWN_UMDNS_PORT]));
|
||||
}else{
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1018,8 +975,7 @@ int ubus_send_probe_via_network(struct probe_entry_s probe_entry) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int send_set_probe(uint8_t client_addr[])
|
||||
{
|
||||
int send_set_probe(uint8_t client_addr[]) {
|
||||
|
||||
printf("SENDING SET PROBE VIA NETWORK!\n");
|
||||
|
||||
|
@ -1038,7 +994,7 @@ enum {
|
|||
};
|
||||
|
||||
static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = {
|
||||
[MAC_ADDR] = { "addr", BLOBMSG_TYPE_STRING },
|
||||
[MAC_ADDR] = {"addr", BLOBMSG_TYPE_STRING},
|
||||
};
|
||||
|
||||
static const struct ubus_method dawn_methods[] = {
|
||||
|
@ -1060,8 +1016,8 @@ static struct ubus_object dawn_object = {
|
|||
};
|
||||
|
||||
static int add_mac(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
|
||||
struct blob_attr *tb[__ADD_DEL_MAC_MAX];
|
||||
uint8_t addr[ETH_ALEN];
|
||||
|
@ -1074,8 +1030,7 @@ static int add_mac(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr))
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
|
||||
if(insert_to_maclist(addr) == 0)
|
||||
{
|
||||
if (insert_to_maclist(addr) == 0) {
|
||||
write_mac_to_file("/etc/dawn/mac_list", addr);
|
||||
}
|
||||
|
||||
|
@ -1083,8 +1038,8 @@ static int add_mac(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
}
|
||||
|
||||
static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
|
||||
build_hearing_map_sort_client(&b);
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
|
@ -1093,16 +1048,15 @@ static int get_hearing_map(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
|
||||
static int get_network(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
|
||||
build_network_overview(&b);
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ubus_add_oject()
|
||||
{
|
||||
static void ubus_add_oject() {
|
||||
int ret;
|
||||
|
||||
ret = ubus_add_object(ctx, &dawn_object);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#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) {
|
||||
|
||||
int length_1 = strlen((char*)str);
|
||||
int length_2 = strlen((char*)str_2);
|
||||
int length_1 = strlen((char *) str);
|
||||
int length_2 = strlen((char *) str_2);
|
||||
|
||||
int length = length_1 < length_2 ? length_1 : length_2;
|
||||
int length = length_1 < length_2 ? length_1 : length_2;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (str[i] > str_2[i]) {
|
||||
|
@ -62,11 +62,9 @@ int convert_mac(char *in, char *out) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void write_mac_to_file(char* path, uint8_t addr[])
|
||||
{
|
||||
void write_mac_to_file(char *path, uint8_t addr[]) {
|
||||
FILE *f = fopen(path, "a");
|
||||
if (f == NULL)
|
||||
{
|
||||
if (f == NULL) {
|
||||
printf("Error opening file!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue