+ FILE *f;
+ unsigned char buf[8192], buf2[8192], wbuf[80], *v, *p, *next, *tmp;
+ int wds = 0, i, restart_wds;
+
+ if (fork())
+ return;
+
+ system("kill $(cat /var/run/wifi.pid) 2>&- >&-");
+ f = fopen("/var/run/wifi.pid", "w");
+ fprintf(f, "%d\n", getpid());
+ fclose(f);
+
+ v = nvram_safe_get(wl_var("wds"));
+ memset(buf2, 0, 8192);
+ p = buf2;
+ foreach(wbuf, v, next) {
+ if (ether_atoe(wbuf, p)) {
+ p += 6;
+ wds++;
+ }
+ }
+ v = nvram_safe_get(wl_var("ssid"));
+
+ for (;;) {
+ sleep(5);
+ if (bcom_ioctl(skfd, ifname, WLC_GET_BSSID, buf, 6) < 0)
+ bcom_ioctl(skfd, ifname, WLC_SET_SSID, v, strlen(v));
+ p = buf2;
+ restart_wds = 0;
+ for (i = 0; i < wds; i++) {
+ memset(buf, 0, 8192);
+ strcpy(buf, "sta_info");
+ memcpy(buf + strlen(buf) + 1, p, 6);
+ if (bcom_ioctl(skfd, ifname, WLC_GET_VAR, buf, 8192) < 0) {
+ } else {
+ sta_info_t *sta = (sta_info_t *) (buf + 4);
+ if (!(sta->flags & 0x40)) {
+ } else {
+ if (sta->idle > 120)
+ restart_wds = 1;
+ }
+ }
+ p += 6;
+ }
+ if (restart_wds)
+ setup_bcom_wds(skfd, ifname);
+ }
+}
+
+static void setup_bcom(int skfd, char *ifname)
+{
+ int val = 0, ap;