diff --git a/wireless/wifictld/src/socket.c b/wireless/wifictld/src/socket.c index 8a670fb..399eba8 100644 --- a/wireless/wifictld/src/socket.c +++ b/wireless/wifictld/src/socket.c @@ -7,6 +7,23 @@ static struct uloop_fd server; struct in6_addr ownaddr; struct sockaddr_in6 client_addr; +int socket_info(struct socket_msg *info) { + int ret = 0; + char msg[REQUEST_MAXLEN]; + + ret = socket_msg_marshal(info, msg); + if (ret) { + log_error("socket_request: could not marshel message: %d\n", ret); + return ret; + } + + ret = sendto(server.fd, msg, REQUEST_MAXLEN, 0, (struct sockaddr *)&client_addr, sizeof(client_addr)); + if (ret < 0) { + log_error("socket_request: could not send message: %d\n", ret); + } + return ret; +} + int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer, struct timeval timeout) { int ret = 0; int sock = 0; @@ -45,7 +62,8 @@ int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer log_error("socket_request: unable to set timeout: %d\n", errno); return ret; } - ret = recv(sock, msg, REQUEST_MAXLEN, 0); + + ret = recv(sock, msg, REQUEST_MAXLEN, MSG_WAITALL); close(sock); if (ret < 0) { if(errno == EWOULDBLOCK) @@ -61,10 +79,10 @@ int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer } log_verbose("socket_request: end %d\n", ret); - if(answer->type & SOCKET_MSG_TYPE_RESPONSE) { - return -1; + if (answer->type & SOCKET_MSG_TYPE_RESPONSE) { + return 0; } - return ret; + return -1; } static void server_cb(struct uloop_fd *fd, unsigned int events) { @@ -129,6 +147,12 @@ int socket_init(char *ifname) { log_error("socket: unable to join multicast group: %d\n", errno); return -1; } + + int loop = 0; + if(setsockopt(server.fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop, sizeof(loop)) < 0) { + log_error("socket_request: unable to disable listen/loop own multicast package: %d\n", errno); + return -1; + } // end listen multicast uloop_fd_add(&server, ULOOP_READ); diff --git a/wireless/wifictld/src/socket.h b/wireless/wifictld/src/socket.h index 898b544..16b0031 100644 --- a/wireless/wifictld/src/socket.h +++ b/wireless/wifictld/src/socket.h @@ -11,6 +11,9 @@ int socket_init(); void socket_close(); +int socket_info(struct socket_msg *info); + + int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer, struct timeval timeout); static inline int socket_request(struct socket_msg *request, struct socket_msg *answer) diff --git a/wireless/wifictld/src/socket_msg.c b/wireless/wifictld/src/socket_msg.c index db4fc48..038d9ef 100644 --- a/wireless/wifictld/src/socket_msg.c +++ b/wireless/wifictld/src/socket_msg.c @@ -7,8 +7,6 @@ int socket_msg_marshal(struct socket_msg *src, char dest[REQUEST_MAXLEN]) { uint16_t ns = 0; int pos = 0; - memset(dest, 0, REQUEST_MAXLEN); - nl = htonl(src->type); memcpy(dest + pos, &nl, sizeof(nl)); pos += sizeof(nl); diff --git a/wireless/wifictld/src/wifi_clients.c b/wireless/wifictld/src/wifi_clients.c index 8a81a5f..baff60e 100644 --- a/wireless/wifictld/src/wifi_clients.c +++ b/wireless/wifictld/src/wifi_clients.c @@ -103,16 +103,21 @@ struct wifi_client *__get_client(struct hostapd_client *hclient){ client->authed = false; client->freq_highest = 0; __client_setvalues(client, hclient); + #ifndef MINI struct socket_msg req = { .type = SOCKET_MSG_TYPE_CLIENT, .client = client, - }, resp; + }, resp = { + .client = malloc(sizeof(*client)), + }; + if(socket_request(&req, &resp) == 0){ log_debug("wifi_clients.__get_client("MACSTR"): get client from neigbour\n", MAC2STR(hclient->address)); return resp.client; } #endif + client->avl.key = client->addr; log_debug("wifi_clients.__get_client("MACSTR"): add client to mem\n", MAC2STR(hclient->address)); avl_insert(&clients_by_addr, &client->avl); @@ -123,10 +128,23 @@ void wifi_clients_learn(struct hostapd_client *hclient) { __get_client(hclient); } + +#ifdef MINI +#define returnINFO_CLIENT return +#else +#define returnINFO_CLIENT if(config_client_force_probe && !hclient->auth) socket_info(&msg); return +#endif + int wifi_clients_try(struct hostapd_client *hclient) { struct wifi_client *client; client = __get_client(hclient); + #ifndef MINI + struct socket_msg msg = { + .type = SOCKET_MSG_TYPE_CLIENT, + .client = client, + }; + #endif if (hclient->auth) { log_info("auth(try=%d mac="MACSTR" freq=%d ssi=%d): ", client->try_auth, MAC2STR(hclient->address), hclient->freq, hclient->ssi_signal); @@ -144,30 +162,30 @@ int wifi_clients_try(struct hostapd_client *hclient) { if(!hclient->auth){ client->try_probe = 0; log_verbose("accept\n"); - return 0; + returnINFO_CLIENT 0; } log_info("accept\n"); client->try_auth = 0; client->connected = 1; - return 0; + returnINFO_CLIENT 0; } if (client->freq_highest > WIFI_CLIENT_FREQ_THREASHOLD) { if (config_client_force || config_client_force_probe && !hclient->auth) { if(!hclient->auth){ log_verbose("reject - force\n"); - return -1; + returnINFO_CLIENT -1; } log_info("reject - force\n"); - return -1; + returnINFO_CLIENT -1; } if (hclient->ssi_signal > config_client_signal_threashold) { if(!hclient->auth){ log_verbose("reject - learned higher freq + ssi is high enough\n"); - return -1; + returnINFO_CLIENT -1; } log_info("reject - learned higher freq + ssi is high enough\n"); - return -1; + returnINFO_CLIENT -1; } } @@ -177,25 +195,35 @@ int wifi_clients_try(struct hostapd_client *hclient) { if(!hclient->auth){ client->try_probe = 0; log_verbose("accept - threashold\n"); - return 0; + returnINFO_CLIENT 0; } log_info("accept - threashold\n"); client->try_auth = 0; client->connected = 1; - return 0; + returnINFO_CLIENT 0; } if(!hclient->auth){ log_verbose("reject\n"); - return client->try_probe; + returnINFO_CLIENT client->try_probe; } log_info("reject\n"); - return client->try_auth; + returnINFO_CLIENT client->try_auth; } + void wifi_clients_disconnect(struct hostapd_client *hclient) { struct wifi_client *client; client = __get_client(hclient); client->connected = 0; + #ifndef MINI + struct socket_msg req = { + .type = SOCKET_MSG_TYPE_CLIENT, + .client = client, + }; + if(socket_info(&req) == 0){ + log_error("error on send info about "MACSTR"\n", MAC2STR(hclient->address)); + } + #endif } void wifi_clients_del(const u8 *address) {