fix log, skip socket_request, respondd
This commit is contained in:
parent
2349afd777
commit
9285147699
|
@ -6,65 +6,19 @@
|
||||||
|
|
||||||
#define UBUS_SOCKET "/var/run/ubus.sock"
|
#define UBUS_SOCKET "/var/run/ubus.sock"
|
||||||
|
|
||||||
static struct blob_attr *msg_config_store, *msg_client_store;
|
static struct json_object *json_config_store, *json_client_store;
|
||||||
|
|
||||||
static void cb_config(struct ubus_request *req, int type, struct blob_attr *msg)
|
static void cb_config(struct ubus_request *req, int type, struct blob_attr *msg)
|
||||||
{
|
{
|
||||||
if (!msg) return;
|
if (!msg) return;
|
||||||
msg_config_store = msg;
|
struct json_object *wifictld = json_object_new_object();
|
||||||
}
|
|
||||||
|
|
||||||
static void cb_client(struct ubus_request *req, int type, struct blob_attr *msg)
|
|
||||||
{
|
|
||||||
if (!msg) return;
|
|
||||||
msg_client_store = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ubus_fetch(const char *method, ubus_data_handler_t cb) {
|
|
||||||
int ret;
|
|
||||||
uint32_t ubus_id;
|
|
||||||
|
|
||||||
struct ubus_context *ctx = ubus_connect(UBUS_SOCKET);
|
|
||||||
if (!ctx) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ubus_lookup_id(ctx, "wifictld", &ubus_id);
|
|
||||||
if (ret) {
|
|
||||||
ubus_free(ctx);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
ret = ubus_invoke(ctx, ubus_id, method, NULL, cb, NULL, 100);
|
|
||||||
if (ret) {
|
|
||||||
ubus_free(ctx);
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
ubus_free(ctx);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct json_object *respondd_provider_nodeinfo(void) {
|
|
||||||
struct json_object *ret = json_object_new_object(),
|
|
||||||
*wifictld = json_object_new_object();
|
|
||||||
json_object_object_add(ret, "wifictld", wifictld);
|
|
||||||
|
|
||||||
int ubus_ret = ubus_fetch("get_config", cb_config);
|
|
||||||
if (ubus_ret) {
|
|
||||||
json_object_object_add(wifictld, "error", json_object_new_int(ubus_ret));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!msg_config_store) {
|
|
||||||
json_object_object_add(wifictld, "error", json_object_new_string("no data"));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct blob_attr *pos;
|
struct blob_attr *pos;
|
||||||
int rem;
|
int rem;
|
||||||
|
|
||||||
const char *attr_name;
|
const char *attr_name;
|
||||||
|
|
||||||
blobmsg_for_each_attr(pos, blobmsg_data(msg_config_store), rem) {
|
blobmsg_for_each_attr(pos, blobmsg_data(msg), rem) {
|
||||||
attr_name = blobmsg_name(pos);
|
attr_name = blobmsg_name(pos);
|
||||||
switch(blobmsg_type(pos)) {
|
switch(blobmsg_type(pos)) {
|
||||||
case BLOBMSG_TYPE_UNSPEC:
|
case BLOBMSG_TYPE_UNSPEC:
|
||||||
|
@ -97,24 +51,13 @@ struct json_object *respondd_provider_nodeinfo(void) {
|
||||||
json_object_object_add(wifictld, attr_name, json_object_new_string("error"));
|
json_object_object_add(wifictld, attr_name, json_object_new_string("error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
json_config_store = wifictld;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct json_object *respondd_provider_statistics(void) {
|
static void cb_client(struct ubus_request *req, int type, struct blob_attr *msg)
|
||||||
struct json_object *ret = json_object_new_object(),
|
{
|
||||||
*wifictld = json_object_new_object();
|
if (!msg) return;
|
||||||
json_object_object_add(ret, "wifictld", wifictld);
|
struct json_object *wifictld = json_object_new_object();
|
||||||
|
|
||||||
int ubus_ret = ubus_fetch("get_clients", cb_client);
|
|
||||||
if (ubus_ret) {
|
|
||||||
json_object_object_add(wifictld, "error", json_object_new_int(ubus_ret));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!msg_client_store) {
|
|
||||||
json_object_object_add(wifictld, "error", json_object_new_string("no data"));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct blob_attr *client, *pos;
|
struct blob_attr *client, *pos;
|
||||||
int rem, remC;
|
int rem, remC;
|
||||||
|
@ -131,7 +74,7 @@ struct json_object *respondd_provider_statistics(void) {
|
||||||
highest_try_probe = 0,
|
highest_try_probe = 0,
|
||||||
highest_try_auth = 0;
|
highest_try_auth = 0;
|
||||||
|
|
||||||
blobmsg_for_each_attr(client, blobmsg_data(msg_client_store), rem) {
|
blobmsg_for_each_attr(client, blobmsg_data(msg), rem) {
|
||||||
total++;
|
total++;
|
||||||
remC = blobmsg_data_len(client);
|
remC = blobmsg_data_len(client);
|
||||||
blobmsg_for_each_attr(pos, client, remC) {
|
blobmsg_for_each_attr(pos, client, remC) {
|
||||||
|
@ -163,6 +106,70 @@ struct json_object *respondd_provider_statistics(void) {
|
||||||
json_object_object_add(wifictld, "connected", json_object_new_int(connected));
|
json_object_object_add(wifictld, "connected", json_object_new_int(connected));
|
||||||
json_object_object_add(wifictld, "highest_try_probe", json_object_new_int(highest_try_probe));
|
json_object_object_add(wifictld, "highest_try_probe", json_object_new_int(highest_try_probe));
|
||||||
json_object_object_add(wifictld, "highest_try_auth", json_object_new_int(highest_try_auth));
|
json_object_object_add(wifictld, "highest_try_auth", json_object_new_int(highest_try_auth));
|
||||||
|
json_client_store = wifictld;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ubus_fetch(const char *method, ubus_data_handler_t cb) {
|
||||||
|
int ret;
|
||||||
|
uint32_t ubus_id;
|
||||||
|
|
||||||
|
struct ubus_context *ctx = ubus_connect(UBUS_SOCKET);
|
||||||
|
if (!ctx) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ubus_lookup_id(ctx, "wifictld", &ubus_id);
|
||||||
|
if (ret) {
|
||||||
|
ubus_free(ctx);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
ret = ubus_invoke(ctx, ubus_id, method, NULL, cb, NULL, 100);
|
||||||
|
if (ret) {
|
||||||
|
ubus_free(ctx);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
ubus_free(ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct json_object *respondd_provider_nodeinfo(void) {
|
||||||
|
struct json_object *ret = json_object_new_object(),
|
||||||
|
*wifictld = json_object_new_object();
|
||||||
|
|
||||||
|
int ubus_ret = ubus_fetch("get_config", cb_config);
|
||||||
|
if (ubus_ret) {
|
||||||
|
json_object_object_add(wifictld, "error", json_object_new_int(ubus_ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!json_config_store) {
|
||||||
|
json_object_object_add(wifictld, "error", json_object_new_string("no data"));
|
||||||
|
json_object_object_add(ret, "wifictld", wifictld);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object_object_add(ret, "wifictld", json_config_store);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct json_object *respondd_provider_statistics(void) {
|
||||||
|
struct json_object *ret = json_object_new_object(),
|
||||||
|
*wifictld = json_object_new_object();
|
||||||
|
|
||||||
|
|
||||||
|
int ubus_ret = ubus_fetch("get_clients", cb_client);
|
||||||
|
if (ubus_ret) {
|
||||||
|
json_object_object_add(wifictld, "error", json_object_new_int(ubus_ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!json_client_store) {
|
||||||
|
json_object_object_add(wifictld, "error", json_object_new_string("no data"));
|
||||||
|
json_object_object_add(ret, "wifictld", wifictld);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object_object_add(ret, "wifictld", json_client_store);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,10 @@ int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer
|
||||||
ret = recv(sock, msg, REQUEST_MAXLEN, MSG_WAITALL);
|
ret = recv(sock, msg, REQUEST_MAXLEN, MSG_WAITALL);
|
||||||
close(sock);
|
close(sock);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if(errno == EWOULDBLOCK)
|
if(errno == EWOULDBLOCK) {
|
||||||
|
log_verbose("socket_request: could not recv message - timeout: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
log_error("socket_request: could not recv message: %d\n", ret);
|
log_error("socket_request: could not recv message: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,12 +74,12 @@ bool __client_setvalues(struct wifi_client *client, struct hostapd_client *hclie
|
||||||
if (client->freq_highest < hclient->freq) {
|
if (client->freq_highest < hclient->freq) {
|
||||||
client->freq_highest = hclient->freq;
|
client->freq_highest = hclient->freq;
|
||||||
log_debug(" new highest freq");
|
log_debug(" new highest freq");
|
||||||
|
//here to skip socket_request
|
||||||
|
updated = true;
|
||||||
}
|
}
|
||||||
if (hclient->freq > WIFI_CLIENT_FREQ_THREASHOLD) {
|
if (hclient->freq > WIFI_CLIENT_FREQ_THREASHOLD) {
|
||||||
client->signal_highfreq = hclient->ssi_signal;
|
client->signal_highfreq = hclient->ssi_signal;
|
||||||
client->signal_lowfreq = 0;
|
client->signal_lowfreq = 0;
|
||||||
//here to skip socket_request
|
|
||||||
updated = true;
|
|
||||||
}else{
|
}else{
|
||||||
client->signal_highfreq = 0;
|
client->signal_highfreq = 0;
|
||||||
client->signal_lowfreq = hclient->ssi_signal;
|
client->signal_lowfreq = hclient->ssi_signal;
|
||||||
|
@ -119,7 +119,6 @@ struct wifi_client *__get_client(struct hostapd_client *hclient){
|
||||||
client->connected = false;
|
client->connected = false;
|
||||||
client->authed = false;
|
client->authed = false;
|
||||||
client->freq_highest = 0;
|
client->freq_highest = 0;
|
||||||
__client_setvalues(client, hclient);
|
|
||||||
|
|
||||||
#ifdef MINI
|
#ifdef MINI
|
||||||
__client_setvalues(client, hclient);
|
__client_setvalues(client, hclient);
|
||||||
|
|
Loading…
Reference in New Issue