+ 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;
+
+ if (!(v = nvram_get(vif_var(vif, "akm"))))
+ v = nvram_safe_get(vif_var(vif, "auth_mode"));
+
+ foreach(var, v, next) {
+ if (strcmp(var, "psk") == 0)
+ res |= WPA_AUTH_PSK;
+ else if (strcmp(var, "psk2") == 0)
+ res |= WPA2_AUTH_PSK;
+ else if (strcmp(var, "wpa") == 0)
+ res |= WPA_AUTH_UNSPECIFIED;
+ else if (strcmp(var, "wpa2") == 0)
+ res |= WPA2_AUTH_UNSPECIFIED;
+ }