int wl_probe(char *name) { int ret, val; if (isListed("probe_blacklist", name)) return -1; #if 0 //defined(linux) char buf[DEV_TYPE_LEN]; if ((ret = wl_get_dev_type(name, buf, DEV_TYPE_LEN)) < 0) { // fprintf(stderr,"dev type=%s fail\n",name); addList("probe_blacklist", name); return ret; } /* * Check interface */ // fprintf(stderr,"dev type=%s\n",buf); if (strncmp(buf, "wl", 2)) { addList("probe_blacklist", name); return -1; } #else /* * Check interface */ if ((ret = wl_ioctl(name, WLC_GET_MAGIC, &val, sizeof(val)))) { // fprintf(stderr,"magic fail\n"); addList("probe_blacklist", name); return ret; } #endif if ((ret = wl_ioctl(name, WLC_GET_VERSION, &val, sizeof(val)))) { // fprintf(stderr,"version fail\n"); addList("probe_blacklist", name); return ret; } if (val > WLC_IOCTL_VERSION) { // fprintf(stderr,"version fail %d\n",val); addList("probe_blacklist", name); return -1; } return ret; }
static int wl_find(struct ifreq *ifr) { char proc_net_dev[] = "/proc/net/dev"; FILE *fp; char buf[1000], *c, *name; char dev_type[DEV_TYPE_LEN]; int status; ifr->ifr_name[0] = '\0'; if (!(fp = fopen(proc_net_dev, "r"))) return BCME_ERROR; /* eat first two lines */ if (!fgets(buf, sizeof(buf), fp) || !fgets(buf, sizeof(buf), fp)) { fclose(fp); return BCME_ERROR; } while (fgets(buf, sizeof(buf), fp)) { c = buf; while (isspace(*c)) c++; if (!(name = strsep(&c, ":"))) continue; strncpy(ifr->ifr_name, name, IFNAMSIZ); if (wl_get_dev_type(name, dev_type, DEV_TYPE_LEN) >= 0 && !strncmp(dev_type, "wl", 2)) if (wl_check((void *) ifr) == 0) break; ifr->ifr_name[0] = '\0'; } if (ifr->ifr_name[0] == '\0') status = BCME_ERROR; else status = BCME_OK; fclose(fp); return status; }
static void wl_get_interface_name(struct ifreq *ifr) { char proc_net_dev[] = "/proc/net/dev"; FILE *fp; char buf[1000], *c, *name; char dev_type[DEV_TYPE_LEN]; int ret = -1; ifr->ifr_name[0] = '\0'; if (!(fp = fopen(proc_net_dev, "r"))) return; /* eat first two lines */ if (!fgets(buf, sizeof(buf), fp) || !fgets(buf, sizeof(buf), fp)) { fclose(fp); return; } while (fgets(buf, sizeof(buf), fp)) { c = buf; while (isspace(*c)) c++; if (!(name = strsep(&c, ":"))) continue; strncpy(ifr->ifr_name, name, IFNAMSIZ); if (wl_get_dev_type(name, dev_type, DEV_TYPE_LEN) >= 0 && (!strncmp(dev_type, "wl", 2) || !strncmp(dev_type, "dhd", 3))) { ret = 0; break; } ifr->ifr_name[0] = '\0'; } fclose(fp); }
int wl_probe(char *name) { int ret, val; #if defined(linux) char buf[DEV_TYPE_LEN]; if ((ret = wl_get_dev_type(name, buf, DEV_TYPE_LEN)) < 0) return ret; /* Check interface */ if (strncmp(buf, "wl", 2)) return -1; #else /* Check interface */ if ((ret = wl_ioctl(name, WLC_GET_MAGIC, &val, sizeof(val)))) return ret; #endif if ((ret = wl_ioctl(name, WLC_GET_VERSION, &val, sizeof(val)))) return ret; if (val > WLC_IOCTL_VERSION) return -1; return ret; }