iwinfo: add survey.
authorDaniel Danzberger <daniel@dd-wrt.com>
Mon, 18 Feb 2019 21:35:06 +0000 (22:35 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 5 Mar 2019 18:51:54 +0000 (19:51 +0100)
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
iwinfo.c

index d476ce3fd711dc5b93b9d35f3992576248defc47..983001ab2359ca04e11770e9e8de98bbd71c9eb4 100644 (file)
--- a/iwinfo.c
+++ b/iwinfo.c
@@ -511,6 +511,45 @@ rpc_iwinfo_assoclist(struct ubus_context *ctx, struct ubus_object *obj,
        return UBUS_STATUS_OK;
 }
 
+static int
+rpc_iwinfo_survey(struct ubus_context *ctx, struct ubus_object *obj,
+                    struct ubus_request_data *req, const char *method,
+                    struct blob_attr *msg)
+{
+       char res[IWINFO_BUFSIZE];
+       struct iwinfo_survey_entry *e;
+       void *c, *d;
+       int i, rv, len;
+
+       blob_buf_init(&buf, 0);
+
+       rv = rpc_iwinfo_open(msg);
+
+       c = blobmsg_open_array(&buf, "results");
+
+       if (rv || iw->survey(ifname, res, &len) || len < 0)
+               return UBUS_STATUS_OK;
+
+       for (i = 0; i < len; i += sizeof(struct iwinfo_survey_entry)) {
+               e = (struct iwinfo_survey_entry *)&res[i];
+
+               d = blobmsg_open_table(&buf, NULL);
+               blobmsg_add_u32(&buf, "mhz", e->mhz);
+               blobmsg_add_u32(&buf, "noise", e->noise);
+               blobmsg_add_u64(&buf, "active_time", e->active_time);
+               blobmsg_add_u64(&buf, "busy_time", e->busy_time);
+               blobmsg_add_u64(&buf, "busy_time_ext", e->busy_time_ext);
+               blobmsg_add_u64(&buf, "rx_time", e->rxtime);
+               blobmsg_add_u64(&buf, "tx_time", e->txtime);
+               blobmsg_close_table(&buf, d);
+       }
+
+       blobmsg_close_array(&buf, c);
+       ubus_send_reply(ctx, req, buf.head);
+       rpc_iwinfo_close();
+       return UBUS_STATUS_OK;
+}
+
 static int
 rpc_iwinfo_freqlist(struct ubus_context *ctx, struct ubus_object *obj,
                     struct ubus_request_data *req, const char *method,
@@ -791,6 +830,7 @@ rpc_iwinfo_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx)
                UBUS_METHOD("freqlist",    rpc_iwinfo_freqlist,    rpc_device_policy),
                UBUS_METHOD("txpowerlist", rpc_iwinfo_txpowerlist, rpc_device_policy),
                UBUS_METHOD("countrylist", rpc_iwinfo_countrylist, rpc_device_policy),
+               UBUS_METHOD("survey",      rpc_iwinfo_survey,      rpc_device_policy),
                UBUS_METHOD("phyname",     rpc_iwinfo_phyname,     rpc_uci_policy),
        };