reformat code

This commit is contained in:
PolynomialDivision 2017-10-23 15:45:37 +02:00
parent a2b7faee97
commit 377d0815e9
13 changed files with 116 additions and 124 deletions

View file

@ -20,40 +20,39 @@ dawn.metric.freq
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 uci_context *c;
struct uci_ptr ptr;
c = uci_alloc_context ();
c = uci_alloc_context();
printf("Loading TImes!");
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");
return ret;
}
if(ptr.o->type == UCI_TYPE_STRING)
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) {
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)
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) {
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)
if (ptr.o->type == UCI_TYPE_STRING)
ret.remove_probe = atoi(ptr.o->v.string);
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;
}
struct probe_metric_s uci_get_dawn_metric()
{
struct probe_metric_s uci_get_dawn_metric() {
struct probe_metric_s ret;
struct uci_context *c;
struct uci_ptr ptr;
c = uci_alloc_context ();
c = uci_alloc_context();
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");
return ret;
}
if(ptr.o->type == UCI_TYPE_STRING)
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) {
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)
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) {
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)
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) {
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)
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) {
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)
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) {
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)
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) {
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)
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) {
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)
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) {
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)
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) {
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)
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);

View file

@ -6,11 +6,11 @@
#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 call_iwinfo(char *client_addr);
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];
sprintf(mac_buf, "%x:%x:%x:%x:%x:%x", MAC2STR(client_addr));
char mac_buf_conv[20];
@ -20,8 +20,7 @@ int get_rssi_from_iwinfo(__uint8_t* client_addr)
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
FILE *fp;
@ -30,7 +29,7 @@ int call_iwinfo(char* client_addr)
int rssi = INT_MIN;
int command_length = 68;
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);
memcpy(iwinfo_command, first_command, length_first_command);
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");
if (fp == NULL) {
printf("Failed to run command\n" );
printf("Failed to run command\n");
exit(1);
}
/* 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);
}
@ -54,15 +53,13 @@ int call_iwinfo(char* client_addr)
return rssi;
}
int parse_rssi(char* iwinfo_string)
{
int parse_rssi(char *iwinfo_string) {
char cut_1[] = " ";
char cut_2[] = "dBm";
char *p_1 = strstr(iwinfo_string, cut_1);
char *p_2 = strstr(iwinfo_string, cut_2);
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);
char dest[length + 1];
memcpy(dest, p_1, (int) (p_2 - p_1));

View file

@ -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,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg) {
printf("METHOD new: %s\n",method);
printf("METHOD new: %s\n", method);
// 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) {
} else if (strncmp(method, "auth", 4) == 0) {
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 0;
@ -515,7 +513,7 @@ static int ubus_get_clients() {
}
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);
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);
}
int ubus_call_umdns()
{
int ubus_call_umdns() {
u_int32_t id;
if (ubus_lookup_id(ctx, "umdns", &id)) {
fprintf(stderr, "Failed to look up test object for %s\n", "umdns");
@ -624,8 +621,7 @@ int ubus_call_umdns()
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");
static struct blob_buf b;

View file

@ -25,19 +25,19 @@ int hwaddr_aton(const char *txt, uint8_t *addr) {
return 0;
}
int convert_mac(char* in, char* out) {
int i,j = 0;
int convert_mac(char *in, char *out) {
int i, j = 0;
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) + 1] = toupper(in[j + 1]);
out[(3 * i) + 2] = in[j + 2];
j+= 3;
j += 3;
} else {
out[3 * i] = '0';
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;
}
}