diff mbox series

[OpenWrt-Devel,2/3,rpcd] iwinfo: add survey.

Message ID 20190218213507.12204-2-daniel@dd-wrt.com
State Accepted
Headers show
Series [OpenWrt-Devel,1/3,rpcd] iwinfo: show more stats from assoclist. | expand

Commit Message

Daniel Danzberger Feb. 18, 2019, 9:35 p.m. UTC
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
---
 iwinfo.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
diff mbox series

Patch

diff --git a/iwinfo.c b/iwinfo.c
index d476ce3..983001a 100644
--- 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),
 	};