reformat code

This commit is contained in:
PolynomialDivision 2018-01-07 21:50:16 +01:00
parent 2352474a36
commit b6cc6470af
10 changed files with 116 additions and 175 deletions

View file

@ -89,9 +89,11 @@ 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);
#ifdef __cplusplus

View file

@ -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[]);

View file

@ -4,20 +4,25 @@
#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 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);
#define ARRAY_NETWORK_LEN 50

View file

@ -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();
@ -128,8 +127,7 @@ int main(int argc, char **argv) {
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;

View file

@ -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;
@ -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);
@ -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]);

View file

@ -22,8 +22,7 @@ int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, floa
#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];
@ -54,16 +53,14 @@ int compare_essid_iwinfo(__uint8_t *bssid_addr, __uint8_t *bssid_addr_to_compare
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;
}

View file

@ -11,8 +11,7 @@ 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 *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,6 +103,7 @@ struct network_config_s uci_get_dawn_network() {
return ret;
}
const char *uci_get_dawn_hostapd_dir() {
struct uci_element *e;
uci_foreach_element(&uci_pkg->sections, e)
@ -119,19 +119,18 @@ const char* uci_get_dawn_hostapd_dir() {
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;

View file

@ -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");
}
@ -501,8 +497,7 @@ static int handle_set_probe(struct blob_attr *msg) {
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;
}
@ -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;
}
@ -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;
}
@ -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");
@ -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);
}
@ -1101,8 +1056,7 @@ static int get_network(struct ubus_context *ctx, struct ubus_object *obj,
return 0;
}
static void ubus_add_oject()
{
static void ubus_add_oject() {
int ret;
ret = ubus_add_object(ctx, &dawn_object);

View file

@ -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);
}