reformat code

This commit is contained in:
PolynomialDivision 2017-12-21 18:47:11 +01:00
parent 7a7519d420
commit dc26e1a03a
7 changed files with 110 additions and 150 deletions

View file

@ -88,28 +88,27 @@
/* aaaack but it's fast and const should make it shared text page. */ /* aaaack but it's fast and const should make it shared text page. */
static const unsigned char pr2six[256] = static const unsigned char pr2six[256] =
{ {
/* ASCII table */ /* ASCII table */
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
}; };
int Base64decode_len(const char *bufcoded) int Base64decode_len(const char *bufcoded) {
{
int nbytesdecoded; int nbytesdecoded;
register const unsigned char *bufin; register const unsigned char *bufin;
register int nprbytes; register int nprbytes;
@ -123,8 +122,7 @@ int Base64decode_len(const char *bufcoded)
return nbytesdecoded + 1; return nbytesdecoded + 1;
} }
int Base64decode(char *bufplain, const char *bufcoded) int Base64decode(char *bufplain, const char *bufcoded) {
{
int nbytesdecoded; int nbytesdecoded;
register const unsigned char *bufin; register const unsigned char *bufin;
register unsigned char *bufout; register unsigned char *bufout;
@ -139,28 +137,28 @@ int Base64decode(char *bufplain, const char *bufcoded)
bufin = (const unsigned char *) bufcoded; bufin = (const unsigned char *) bufcoded;
while (nprbytes > 4) { while (nprbytes > 4) {
*(bufout++) = *(bufout++) =
(unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
*(bufout++) = *(bufout++) =
(unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
*(bufout++) = *(bufout++) =
(unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
bufin += 4; bufin += 4;
nprbytes -= 4; nprbytes -= 4;
} }
/* Note: (nprbytes == 1) would be an error, so just ingore that case */ /* Note: (nprbytes == 1) would be an error, so just ingore that case */
if (nprbytes > 1) { if (nprbytes > 1) {
*(bufout++) = *(bufout++) =
(unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
} }
if (nprbytes > 2) { if (nprbytes > 2) {
*(bufout++) = *(bufout++) =
(unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
} }
if (nprbytes > 3) { if (nprbytes > 3) {
*(bufout++) = *(bufout++) =
(unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
} }
*(bufout++) = '\0'; *(bufout++) = '\0';
@ -169,39 +167,36 @@ int Base64decode(char *bufplain, const char *bufcoded)
} }
static const char basis_64[] = static const char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int Base64encode_len(int len) int Base64encode_len(int len) {
{
return ((len + 2) / 3 * 4) + 1; return ((len + 2) / 3 * 4) + 1;
} }
int Base64encode(char *encoded, const char *string, int len) int Base64encode(char *encoded, const char *string, int len) {
{
int i; int i;
char *p; char *p;
p = encoded; p = encoded;
for (i = 0; i < len - 2; i += 3) { for (i = 0; i < len - 2; i += 3) {
*p++ = basis_64[(string[i] >> 2) & 0x3F]; *p++ = basis_64[(string[i] >> 2) & 0x3F];
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2) |
((int) (string[i + 2] & 0xC0) >> 6)];
*p++ = basis_64[string[i + 2] & 0x3F];
}
if (i < len) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
if (i == (len - 1)) {
*p++ = basis_64[((string[i] & 0x3) << 4)];
*p++ = '=';
}
else {
*p++ = basis_64[((string[i] & 0x3) << 4) | *p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)]; ((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2)]; *p++ = basis_64[((string[i + 1] & 0xF) << 2) |
((int) (string[i + 2] & 0xC0) >> 6)];
*p++ = basis_64[string[i + 2] & 0x3F];
} }
*p++ = '='; if (i < len) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
if (i == (len - 1)) {
*p++ = basis_64[((string[i] & 0x3) << 4)];
*p++ = '=';
} else {
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
}
*p++ = '=';
} }
*p++ = '\0'; *p++ = '\0';

View file

@ -33,7 +33,7 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_
addr->sin_port = htons(_broadcast_port); addr->sin_port = htons(_broadcast_port);
while (bind(sock, (struct sockaddr *) addr, sizeof(*addr)) < while (bind(sock, (struct sockaddr *) addr, sizeof(*addr)) <
0) { 0) {
fprintf(stderr, "Binding socket failed!\n"); fprintf(stderr, "Binding socket failed!\n");
sleep(1); sleep(1);
} }

View file

@ -69,13 +69,12 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_
return sock; return sock;
} }
int remove_multicast_socket(int socket) int remove_multicast_socket(int socket) {
{ if (setsockopt(socket,
if (setsockopt ( socket, IPPROTO_IP,
IPPROTO_IP, IP_DROP_MEMBERSHIP,
IP_DROP_MEMBERSHIP, &command, sizeof(command)) < 0) {
&command, sizeof (command)) < 0 ) { perror("setsockopt:IP_DROP_MEMBERSHIP");
perror ("setsockopt:IP_DROP_MEMBERSHIP");
return -1; return -1;
} }
return 0; return 0;

View file

@ -238,7 +238,7 @@ int send_string_enc(char *msg) {
} }
void close_socket() { void close_socket() {
if(multicast_socket){ if (multicast_socket) {
remove_multicast_socket(sock); remove_multicast_socket(sock);
} }
close(sock); close(sock);

View file

@ -98,10 +98,10 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar
// check if ap entry is available // check if ap entry is available
if (mac_is_equal(ap_entry_own.bssid_addr, bssid_addr_own) if (mac_is_equal(ap_entry_own.bssid_addr, bssid_addr_own)
&& mac_is_equal(ap_entry_to_compre.bssid_addr, bssid_addr_to_compare) && mac_is_equal(ap_entry_to_compre.bssid_addr, bssid_addr_to_compare)
) { ) {
printf("Comparing own %d to %d\n", ap_entry_own.station_count, ap_entry_to_compre.station_count); printf("Comparing own %d to %d\n", ap_entry_own.station_count, ap_entry_to_compre.station_count);
if(automatic_kick){ if (automatic_kick) {
return (ap_entry_own.station_count - 1) > ap_entry_to_compre.station_count; return (ap_entry_own.station_count - 1) > ap_entry_to_compre.station_count;
} else { } else {
return ap_entry_own.station_count > ap_entry_to_compre.station_count; return ap_entry_own.station_count > ap_entry_to_compre.station_count;
@ -148,30 +148,25 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat
for (k = i; k <= probe_entry_last; k++) { for (k = i; k <= probe_entry_last; k++) {
int score_to_compare; int score_to_compare;
if (!mac_is_equal(probe_array[k].client_addr, client_addr)) if (!mac_is_equal(probe_array[k].client_addr, 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)) {
{
printf("Own Score! Skipping!\n"); printf("Own Score! Skipping!\n");
print_probe_entry(probe_array[k]); print_probe_entry(probe_array[k]);
continue; continue;
} }
printf("Calculating score to compare!\n"); printf("Calculating score to compare!\n");
score_to_compare = eval_probe_metric(probe_array[k]); score_to_compare = eval_probe_metric(probe_array[k]);
if(own_score < score_to_compare) if (own_score < score_to_compare) {
{
return 1; return 1;
} }
if (dawn_metric.use_station_count && own_score == score_to_compare) if (dawn_metric.use_station_count && own_score == score_to_compare) {
{
// if ap have same value but station count is different... // if ap have same value but station count is different...
if(compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick)) if (compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick)) {
{
return 1; return 1;
} }
} }
@ -228,12 +223,11 @@ void kick_clients(uint8_t bssid[], uint32_t id) {
printf("Check if client is active receiving!\n"); printf("Check if client is active receiving!\n");
float rx_rate, tx_rate; float rx_rate, tx_rate;
if(get_bandwidth_iwinfo(client_array[j].client_addr, &rx_rate, &tx_rate)) if (get_bandwidth_iwinfo(client_array[j].client_addr, &rx_rate, &tx_rate)) {
{
// only use rx_rate for indicating if transmission is going on // only use rx_rate for indicating if transmission is going on
// <= 6MBits <- probably no transmission // <= 6MBits <- probably no transmission
// tx_rate has always some weird value so don't use ist // tx_rate has always some weird value so don't use ist
if(rx_rate > dawn_metric.bandwith_threshold){ if (rx_rate > dawn_metric.bandwith_threshold) {
printf("Client is probably in active transmisison. Don't kick! RxRate is: %f\n", rx_rate); printf("Client is probably in active transmisison. Don't kick! RxRate is: %f\n", rx_rate);
continue; continue;
} }
@ -633,8 +627,7 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) {
} }
} }
void uloop_add_data_cbs() void uloop_add_data_cbs() {
{
uloop_timeout_add(&probe_timeout); uloop_timeout_add(&probe_timeout);
uloop_timeout_add(&client_timeout); uloop_timeout_add(&client_timeout);
uloop_timeout_add(&ap_timeout); uloop_timeout_add(&ap_timeout);
@ -648,8 +641,7 @@ void remove_probe_array_cb(struct uloop_timeout *t) {
uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000); uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000);
} }
void remove_client_array_cb(struct uloop_timeout *t) void remove_client_array_cb(struct uloop_timeout *t) {
{
pthread_mutex_lock(&client_array_mutex); pthread_mutex_lock(&client_array_mutex);
printf("[Thread] : Removing old client entries!\n"); printf("[Thread] : Removing old client entries!\n");
remove_old_client_entries(time(0), timeout_config.update_client); remove_old_client_entries(time(0), timeout_config.update_client);

View file

@ -17,7 +17,7 @@ int get_rssi(const char *ifname, uint8_t *client_addr);
int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate); int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate);
#define IWINFO_BUFSIZE 24 * 1024 #define IWINFO_BUFSIZE 24 * 1024
int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) { int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) {
@ -33,8 +33,7 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate)
while ((entry = readdir(dirp)) != NULL) { while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_SOCK) { if (entry->d_type == DT_SOCK) {
if(get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) if (get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) {
{
sucess = 1; sucess = 1;
break; break;
} }
@ -44,7 +43,7 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate)
return sucess; return sucess;
} }
int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate){ int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate) {
int i, len; int i, len;
char buf[IWINFO_BUFSIZE]; char buf[IWINFO_BUFSIZE];
@ -53,23 +52,18 @@ int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float
iw = iwinfo_backend(ifname); iw = iwinfo_backend(ifname);
if (iw->assoclist(ifname, buf, &len)) if (iw->assoclist(ifname, buf, &len)) {
{
printf("No information available\n"); printf("No information available\n");
return 0; return 0;
} } else if (len <= 0) {
else if (len <= 0)
{
printf("No station connected\n"); printf("No station connected\n");
return 0; return 0;
} }
for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) {
{
e = (struct iwinfo_assoclist_entry *) &buf[i]; e = (struct iwinfo_assoclist_entry *) &buf[i];
if(mac_is_equal(client_addr, e->mac)) if (mac_is_equal(client_addr, e->mac)) {
{
//struct iwinfo_assoclist_entry * rx_rate = e->rx_rate; //struct iwinfo_assoclist_entry * rx_rate = e->rx_rate;
//struct iwinfo_assoclist_entry * tx_rate = e->tx_rate; //struct iwinfo_assoclist_entry * tx_rate = e->tx_rate;
*rx_rate = e->rx_rate.rate / 1000; *rx_rate = e->rx_rate.rate / 1000;
@ -99,7 +93,7 @@ int get_rssi_iwinfo(__uint8_t *client_addr) {
while ((entry = readdir(dirp)) != NULL) { while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_SOCK) { if (entry->d_type == DT_SOCK) {
rssi = get_rssi(entry->d_name, client_addr); rssi = get_rssi(entry->d_name, client_addr);
if(rssi != INT_MIN) if (rssi != INT_MIN)
break; break;
} }
} }
@ -107,7 +101,7 @@ int get_rssi_iwinfo(__uint8_t *client_addr) {
return rssi; return rssi;
} }
int get_rssi(const char *ifname, uint8_t *client_addr){ int get_rssi(const char *ifname, uint8_t *client_addr) {
int i, len; int i, len;
char buf[IWINFO_BUFSIZE]; char buf[IWINFO_BUFSIZE];
@ -116,23 +110,19 @@ int get_rssi(const char *ifname, uint8_t *client_addr){
iw = iwinfo_backend(ifname); iw = iwinfo_backend(ifname);
if (iw->assoclist(ifname, buf, &len)) if (iw->assoclist(ifname, buf, &len)) {
{
printf("No information available\n"); printf("No information available\n");
return INT_MIN; return INT_MIN;
} } else if (len <= 0) {
else if (len <= 0)
{
printf("No station connected\n"); printf("No station connected\n");
return INT_MIN; return INT_MIN;
} }
for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) {
{
e = (struct iwinfo_assoclist_entry *) &buf[i]; e = (struct iwinfo_assoclist_entry *) &buf[i];
if(mac_is_equal(client_addr, e->mac)) if (mac_is_equal(client_addr, e->mac))
return e->signal; return e->signal;
} }
return INT_MIN; return INT_MIN;

View file

@ -138,20 +138,18 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir);
static int ubus_get_clients(); static int ubus_get_clients();
int hostapd_array_check_id(uint32_t id); int hostapd_array_check_id(uint32_t id);
void hostapd_array_insert(uint32_t id); void hostapd_array_insert(uint32_t id);
void hostapd_array_delete(uint32_t id); void hostapd_array_delete(uint32_t id);
void add_client_update_timer(time_t time) void add_client_update_timer(time_t time) {
{
uloop_timeout_set(&client_timer, time); uloop_timeout_set(&client_timer, time);
} }
int hostapd_array_check_id(uint32_t id) int hostapd_array_check_id(uint32_t id) {
{ for (int i = 0; i <= hostapd_sock_last; i++) {
for(int i = 0; i <= hostapd_sock_last; i++) if (hostapd_sock_arr[i] == id) {
{
if(hostapd_sock_arr[i] == id)
{
return 1; return 1;
} }
} }
@ -159,21 +157,18 @@ int hostapd_array_check_id(uint32_t id)
} }
void hostapd_array_insert(uint32_t id) void hostapd_array_insert(uint32_t id) {
{ if (hostapd_sock_last < MAX_HOSTAPD_SOCKETS) {
if(hostapd_sock_last < MAX_HOSTAPD_SOCKETS) {
hostapd_sock_last++; hostapd_sock_last++;
hostapd_sock_arr[hostapd_sock_last] = id; hostapd_sock_arr[hostapd_sock_last] = id;
} }
for(int i = 0; i <= hostapd_sock_last; i++) for (int i = 0; i <= hostapd_sock_last; i++) {
{ printf("%d: %d\n", i, hostapd_sock_arr[i]);
printf("%d: %d\n",i,hostapd_sock_arr[i]);
} }
} }
void hostapd_array_delete(uint32_t id) void hostapd_array_delete(uint32_t id) {
{
int i = 0; int i = 0;
int found_in_array = 0; int found_in_array = 0;
@ -181,9 +176,8 @@ void hostapd_array_delete(uint32_t id)
return; return;
} }
for(i = 0; i <= hostapd_sock_last; i++) for (i = 0; i <= hostapd_sock_last; i++) {
{ if (hostapd_sock_arr[i] == id) {
if(hostapd_sock_arr[i] == id) {
found_in_array = 1; found_in_array = 1;
break; break;
} }
@ -217,8 +211,7 @@ static int decide_function(probe_entry *prob_req) {
return 0; return 0;
} }
if(better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) if (better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) {
{
return 0; return 0;
} }
@ -309,8 +302,7 @@ static int handle_auth_req(struct blob_attr *msg) {
print_probe_entry(tmp); print_probe_entry(tmp);
// block if entry was not already found in probe database // block if entry was not already found in probe database
if(!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr))) if (!(mac_is_equal(tmp.bssid_addr, auth_req.bssid_addr) && mac_is_equal(tmp.client_addr, auth_req.client_addr))) {
{
printf("DENY AUTH!\n"); printf("DENY AUTH!\n");
return UBUS_STATUS_UNKNOWN_ERROR; return UBUS_STATUS_UNKNOWN_ERROR;
} }
@ -351,8 +343,7 @@ static int handle_probe_req(struct blob_attr *msg) {
// deny access // deny access
if(!dawn_metric.eval_probe_req) if (!dawn_metric.eval_probe_req) {
{
return 0; return 0;
} }
@ -390,8 +381,7 @@ static int add_subscriber(char *name) {
return -1; return -1;
} }
if(hostapd_array_check_id(id)) if (hostapd_array_check_id(id)) {
{
return 0; return 0;
} }
@ -406,8 +396,7 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) {
DIR *dirp; DIR *dirp;
struct dirent *entry; struct dirent *entry;
if(ctx == NULL) if (ctx == NULL) {
{
return 0; return 0;
} }
@ -429,8 +418,7 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) {
static int subscribe_to_hostapd(char *hostapd_dir) { static int subscribe_to_hostapd(char *hostapd_dir) {
if(ctx == NULL) if (ctx == NULL) {
{
return 0; return 0;
} }
@ -583,11 +571,9 @@ int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id) {
ap_entry.vht = blobmsg_get_u8(tb[CLIENT_TABLE_VHT]); ap_entry.vht = blobmsg_get_u8(tb[CLIENT_TABLE_VHT]);
ap_entry.channel_utilization = blobmsg_get_u32(tb[CLIENT_TABLE_CHAN_UTIL]); ap_entry.channel_utilization = blobmsg_get_u32(tb[CLIENT_TABLE_CHAN_UTIL]);
if(tb[CLIENT_TABLE_NUM_STA]) if (tb[CLIENT_TABLE_NUM_STA]) {
{
ap_entry.station_count = blobmsg_get_u32(tb[CLIENT_TABLE_NUM_STA]); ap_entry.station_count = blobmsg_get_u32(tb[CLIENT_TABLE_NUM_STA]);
} else } else {
{
ap_entry.station_count = 0; ap_entry.station_count = 0;
} }
@ -615,8 +601,7 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
} }
static int ubus_get_clients() { static int ubus_get_clients() {
for(int i = 0; i <= hostapd_sock_last; i++) for (int i = 0; i <= hostapd_sock_last; i++) {
{
int timeout = 1; int timeout = 1;
ubus_invoke(ctx_clients, hostapd_sock_arr[i], "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000); ubus_invoke(ctx_clients, hostapd_sock_arr[i], "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000);
} }
@ -651,8 +636,7 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint
blobmsg_add_u8(&b, "deauth", deauth); blobmsg_add_u8(&b, "deauth", deauth);
blobmsg_add_u32(&b, "ban_time", ban_time); blobmsg_add_u32(&b, "ban_time", ban_time);
for(int i = 0; i <= hostapd_sock_last; i++) for (int i = 0; i <= hostapd_sock_last; i++) {
{
int timeout = 1; int timeout = 1;
ubus_invoke(ctx_clients, hostapd_sock_arr[i], "del_client", b.head, NULL, NULL, timeout * 1000); ubus_invoke(ctx_clients, hostapd_sock_arr[i], "del_client", b.head, NULL, NULL, timeout * 1000);
} }