Signed-off-by: Roman Yeryomin <ro...@advem.lv>
---
 iwinfo.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/iwinfo.c b/iwinfo.c
index 325c07a..6e34ea1 100644
--- a/iwinfo.c
+++ b/iwinfo.c
@@ -317,6 +317,41 @@ rpc_iwinfo_info(struct ubus_context *ctx, struct 
ubus_object *obj,
        return UBUS_STATUS_OK;
 }
 
+static void
+rpc_iwinfo_add_ve(const char *name, struct iwinfo_scanlist_entry *e)
+{
+       void *c, *d;
+       char oui[7];
+       char *data = NULL;
+       int datalen, i, di;
+
+       d = blobmsg_open_array(&buf, name);
+       for (i = 0; i < IWINFO_VE_MAX; i++) {
+               if (e->ve[i].len < 1)
+                       break;
+               c = blobmsg_open_table(&buf, NULL);
+
+               snprintf(oui, sizeof(oui), "%02x%02x%02x", e->ve[i].oui[0],
+                                                          e->ve[i].oui[1],
+                                                          e->ve[i].oui[2]);
+               blobmsg_add_string(&buf, "oui", oui);
+
+               datalen = e->ve[i].len * 2;
+               data = (char *)malloc(datalen + 1);
+               if (!data) {
+                       blobmsg_close_table(&buf, c);
+                       break;
+               }
+               for (di = 0; di < e->ve[i].len - sizeof(e->ve[i].oui); di++)
+                       snprintf(data + di * 2, 3, "%02x", e->ve[i].data[di]);
+               blobmsg_add_string(&buf, "data", data);
+               free(data);
+
+               blobmsg_close_table(&buf, c);
+       }
+       blobmsg_close_array(&buf, d);
+}
+
 static int
 rpc_iwinfo_scan(struct ubus_context *ctx, struct ubus_object *obj,
                 struct ubus_request_data *req, const char *method,
@@ -325,7 +360,7 @@ rpc_iwinfo_scan(struct ubus_context *ctx, struct 
ubus_object *obj,
        int i, rv, len;
        void *c, *d;
        char mac[18];
-       char res[IWINFO_BUFSIZE];
+       char res[IWINFO_MAX_APS * sizeof(struct iwinfo_scanlist_entry)];
        struct iwinfo_scanlist_entry *e;
 
        rv = rpc_iwinfo_open(msg);
@@ -363,6 +398,10 @@ rpc_iwinfo_scan(struct ubus_context *ctx, struct 
ubus_object *obj,
 
                        rpc_iwinfo_add_encryption("encryption", &e->crypto);
 
+                       /* add vendor elements if exist */
+                       if (e->ve[0].len)
+                               rpc_iwinfo_add_ve("vendor_elements", e);
+
                        blobmsg_close_table(&buf, d);
                }
        }
-- 
2.1.4
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to