+ memcpy(&buf[strlen(var) + 1], val, len);
+
+ ret = bcom_ioctl(skfd, ifname, WLC_SET_VAR, buf, sizeof(buf));
+
+#ifdef DEBUG
+ if (ret < 0)
+ fprintf(stderr, "SET_VAR %s failed: %d\n", var, ret);
+#endif
+
+ return ret;
+}
+
+static int bcom_get_var(int skfd, char *ifname, char *var, void *buf, int len)
+{
+ int ret;
+
+ if (strlen(var) + 1 > sizeof(buf) || len > sizeof(buf))
+ return -1;
+
+ bzero(buf, sizeof(buf));
+ strcpy(buf, var);
+
+ ret = bcom_ioctl(skfd, ifname, WLC_GET_VAR, buf, sizeof(buf));
+
+#ifdef DEBUG
+ if (ret < 0)
+ fprintf(stderr, "GET_VAR %s failed: %d\n", var, ret);
+#endif
+
+ return ret;
+}
+
+static int bcom_set_bss_var(int skfd, char *ifname, int bss, char *var, void *val, int len)
+{
+ char buf[8192];
+ int i = 0, ret;
+
+ bzero(buf, sizeof(buf));
+ if (strlen(var) + len + 8 > sizeof(buf) || len > sizeof(buf))
+ return -1;
+
+ // "bsscfg:<name>\x00" <bss> <data>
+ i = sprintf(buf, "bsscfg:%s", var);
+ buf[i++] = 0;
+
+ memcpy(buf + i, &bss, sizeof(bss));
+ i += sizeof(bss);
+
+ memcpy(buf + i, val, len);
+ i += len;
+
+ ret = bcom_ioctl(skfd, ifname, WLC_SET_VAR, buf, i);
+
+#ifdef DEBUG
+ if (ret < 0)
+ fprintf(stderr, "SET_BSS_VAR %s failed: %d\n", var, ret);
+#endif
+
+ return ret;
+}
+
+static int bcom_set_int(int skfd, char *ifname, char *var, int val)
+{
+ return bcom_set_var(skfd, ifname, var, &val, sizeof(val));
+}
+
+static int bcom_set_bss_int(int skfd, char *ifname, int bss, char *var, int val)
+{
+ return bcom_set_bss_var(skfd, ifname, bss, var, &val, sizeof(val));
+}
+
+static int is_new_bcom(int skfd, char *ifname)
+{
+ char buf[8192];
+
+ bzero(buf, 8192);
+ bcom_ioctl(skfd, ifname, WLC_DUMP, buf, 8192);
+
+ if (strstr(buf, "3.130"))
+ return 1;
+
+ return 0;
+}
+
+static int bcom_get_wsec(int vif)
+{
+ int val;
+
+ if (nvram_match(vif_var(vif, "crypto"), "tkip"))
+ val = TKIP_ENABLED;
+ else if (nvram_match(vif_var(vif, "crypto"), "aes"))
+ val = AES_ENABLED;
+ else if (nvram_match(vif_var(vif, "crypto"), "tkip+aes") || nvram_match(vif_var(vif, "crypto"), "aes+tkip"))
+ val = TKIP_ENABLED | AES_ENABLED;
+ else
+ val = 0;
+
+ return val;
+}
+
+static int bcom_get_wauth(int vif)
+{
+ char *v, *next, var[80];
+ int res = 0;