Esempio n. 1
0
static void
addchan(struct ieee80211com *ic, int ieee, int flags)
{
	struct ieee80211_channel *c;

	c = &ic->ic_channels[ic->ic_nchans++];
	c->ic_freq = ieee80211_ieee2mhz(ieee, flags);
	c->ic_ieee = ieee;
	c->ic_flags = flags;
	c->ic_extieee = 0;
}
Esempio n. 2
0
static void
addchan(struct ieee80211com *ic, int ieee, int flags)
{
	struct ieee80211_channel *c;

	c = &ic->ic_channels[ic->ic_nchans++];
	c->ic_freq = ieee80211_ieee2mhz(ieee, flags);
	c->ic_ieee = ieee;
	c->ic_flags = flags;
	if (flags & IEEE80211_CHAN_HT40U)
		c->ic_extieee = ieee + 4;
	else if (flags & IEEE80211_CHAN_HT40D)
		c->ic_extieee = ieee - 4;
	else
		c->ic_extieee = 0;
}
Esempio n. 3
0
/*
 * Find the channel information according to the scan entry
 */
int rtt_find_channel_info (void *arg, wlan_scan_entry_t scan_entry)
{
    wmi_channel *wmi_chan;
    u_int32_t chan_mode;
    struct ieee80211com *ic;
    struct ieee80211_channel *se_chan;
    static const u_int modeflags[] = {
        0,                            /* IEEE80211_MODE_AUTO           */
        MODE_11A,         /* IEEE80211_MODE_11A            */
        MODE_11B,         /* IEEE80211_MODE_11B            */
        MODE_11G,         /* IEEE80211_MODE_11G            */
        0,                            /* IEEE80211_MODE_FH             */
        0,                            /* IEEE80211_MODE_TURBO_A        */
        0,                            /* IEEE80211_MODE_TURBO_G        */
        MODE_11NA_HT20,   /* IEEE80211_MODE_11NA_HT20      */
        MODE_11NG_HT20,   /* IEEE80211_MODE_11NG_HT20      */
        MODE_11NA_HT40,   /* IEEE80211_MODE_11NA_HT40PLUS  */
        MODE_11NA_HT40,   /* IEEE80211_MODE_11NA_HT40MINUS */
        MODE_11NG_HT40,   /* IEEE80211_MODE_11NG_HT40PLUS  */
        MODE_11NG_HT40,   /* IEEE80211_MODE_11NG_HT40MINUS */
        MODE_11NG_HT40,   /* IEEE80211_MODE_11NG_HT40      */
        MODE_11NA_HT40,   /* IEEE80211_MODE_11NA_HT40      */
        MODE_11AC_VHT20,  /* IEEE80211_MODE_11AC_VHT20     */
        MODE_11AC_VHT40,  /* IEEE80211_MODE_11AC_VHT40PLUS */
        MODE_11AC_VHT40,  /* IEEE80211_MODE_11AC_VHT40MINUS*/
        MODE_11AC_VHT40,  /* IEEE80211_MODE_11AC_VHT40     */
        MODE_11AC_VHT80,  /* IEEE80211_MODE_11AC_VHT80     */
    };

    adf_os_print("%s:\n", __func__);

    if (!(arg && scan_entry)) {
        return -1; //critical error
    }

    wmi_chan = ((channel_search *)arg)->channel;
    ic = ((channel_search *)arg)->ic;

    if(!(wmi_chan && ic)) {
        return -1; //critical error
    }

    se_chan = wlan_scan_entry_channel(scan_entry);

    if(!se_chan) {
        return -1; //critical error
    }

    wmi_chan->mhz = ieee80211_chan2freq(ic,se_chan);
    chan_mode = ieee80211_chan2mode(se_chan);
    WMI_SET_CHANNEL_MODE(wmi_chan, modeflags[chan_mode]);

    if(chan_mode == IEEE80211_MODE_11AC_VHT80) {
        if (se_chan->ic_ieee < 20) {
            wmi_chan->band_center_freq1 = ieee80211_ieee2mhz(
                                             se_chan->ic_vhtop_ch_freq_seg1,
                                             IEEE80211_CHAN_2GHZ);
        } else {
            wmi_chan->band_center_freq1 = ieee80211_ieee2mhz(
                                            se_chan->ic_vhtop_ch_freq_seg1,
                                            IEEE80211_CHAN_5GHZ);
        }
    } else if((chan_mode == IEEE80211_MODE_11NA_HT40PLUS) ||
              (chan_mode == IEEE80211_MODE_11NG_HT40PLUS) ||
              (chan_mode == IEEE80211_MODE_11AC_VHT40PLUS)) {
        wmi_chan->band_center_freq1 = wmi_chan->mhz + 10;
    } else if((chan_mode == IEEE80211_MODE_11NA_HT40MINUS) ||
              (chan_mode == IEEE80211_MODE_11NG_HT40MINUS) ||
              (chan_mode == IEEE80211_MODE_11AC_VHT40MINUS)) {
        wmi_chan->band_center_freq1 = wmi_chan->mhz - 10;
    } else {
        wmi_chan->band_center_freq1 = wmi_chan->mhz;
    }

    /* we do not support HT80PLUS80 yet */
    wmi_chan->band_center_freq2=0;
    WMI_SET_CHANNEL_MIN_POWER(wmi_chan, se_chan->ic_minpower);
    WMI_SET_CHANNEL_MAX_POWER(wmi_chan, se_chan->ic_maxpower);
    WMI_SET_CHANNEL_REG_POWER(wmi_chan, se_chan->ic_maxregpower);
    WMI_SET_CHANNEL_ANTENNA_MAX(wmi_chan, se_chan->ic_antennamax);
    WMI_SET_CHANNEL_REG_CLASSID(wmi_chan, se_chan->ic_regClassId);

    if (IEEE80211_IS_CHAN_DFS(se_chan))
        WMI_SET_CHANNEL_FLAG(wmi_chan, WMI_CHAN_FLAG_DFS);

    adf_os_print("WMI channel freq=%d, mode=%x band_center_freq1=%d\n", wmi_chan->mhz, 
        WMI_GET_CHANNEL_MODE(wmi_chan), wmi_chan->band_center_freq1);

    return 1; //seccessful!    
}
Esempio n. 4
0
int
an_attach(struct an_softc *sc)
{
	struct ieee80211com *ic = &sc->sc_ic;
	struct ifnet *ifp = &ic->ic_if;
	int i;
	struct an_rid_wepkey *akey;
	int buflen, kid, rid;
	int chan, chan_min, chan_max;

	sc->sc_invalid = 0;

	/* disable interrupts */
	CSR_WRITE_2(sc, AN_INT_EN, 0);
	CSR_WRITE_2(sc, AN_EVENT_ACK, 0xffff);

//	an_wait(sc);
	if (an_reset(sc) != 0) {
		sc->sc_invalid = 1;
		return 1;
	}

	/* Load factory config */
	if (an_cmd(sc, AN_CMD_READCFG, 0) != 0) {
		printf("%s: failed to load config data\n",
		    sc->sc_dev.dv_xname);
		return (EIO);
	}

	/* Read the current configuration */
	buflen = sizeof(sc->sc_config);
	if (an_read_rid(sc, AN_RID_GENCONFIG, &sc->sc_config, &buflen) != 0) {
		printf("%s: read config failed\n", sc->sc_dev.dv_xname);
		return(EIO);
	}

	an_swap16((u_int16_t *)&sc->sc_config.an_macaddr, 3); 

	/* Read the card capabilities */
	buflen = sizeof(sc->sc_caps);
	if (an_read_rid(sc, AN_RID_CAPABILITIES, &sc->sc_caps, &buflen) != 0) {
		printf("%s: read caps failed\n", sc->sc_dev.dv_xname);
		return(EIO);
	}

	an_swap16((u_int16_t *)&sc->sc_caps.an_oemaddr, 3); 
	an_swap16((u_int16_t *)&sc->sc_caps.an_rates, 4);

	/* Read WEP settings from persistent memory */
	akey = &sc->sc_buf.sc_wepkey;
	buflen = sizeof(struct an_rid_wepkey);
	rid = AN_RID_WEP_VOLATILE;	/* first persistent key */
	while (an_read_rid(sc, rid, akey, &buflen) == 0) {
		an_swap16((u_int16_t *)&akey->an_mac_addr, 3); 
		an_swap16((u_int16_t *)&akey->an_key, 8); 
		kid = akey->an_key_index;
		DPRINTF(("an_attach: wep rid=0x%x len=%d(%d) index=0x%04x "
		    "mac[0]=%02x keylen=%d\n",
		    rid, buflen, sizeof(*akey), kid,
		    akey->an_mac_addr[0], akey->an_key_len));
		if (kid == 0xffff) {
			sc->sc_tx_perskey = akey->an_mac_addr[0];
			sc->sc_tx_key = -1;
			break;
		}
		if (kid >= IEEE80211_WEP_NKID)
			break;
		sc->sc_perskeylen[kid] = akey->an_key_len;
		sc->sc_wepkeys[kid].an_wep_keylen = -1;
		rid = AN_RID_WEP_PERSISTENT;	/* for next key */
		buflen = sizeof(struct an_rid_wepkey);
	}

	IEEE80211_ADDR_COPY(ic->ic_myaddr, sc->sc_caps.an_oemaddr);
	bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);

	printf("%s: Firmware %x.%02x.%02x, Radio: ", ifp->if_xname,
	    sc->sc_caps.an_fwrev >> 8,
	    sc->sc_caps.an_fwrev & 0xff,
	    sc->sc_caps.an_fwsubrev);

	if (sc->sc_config.an_radiotype & AN_RADIOTYPE_80211_FH)
		printf("802.11 FH");
	else if (sc->sc_config.an_radiotype & AN_RADIOTYPE_80211_DS)
		printf("802.11 DS");
	else if (sc->sc_config.an_radiotype & AN_RADIOTYPE_LM2000_DS)
		printf("LM2000 DS");
	else
		printf("unknown (%x)", sc->sc_config.an_radiotype);

	printf(", address %s\n", ether_sprintf(ic->ic_myaddr));
	
	ifp->if_softc = sc;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_ioctl = an_ioctl;
	ifp->if_start = an_start;
	ifp->if_watchdog = an_watchdog;

	ic->ic_phytype = IEEE80211_T_DS;
	ic->ic_opmode = IEEE80211_M_STA;
	ic->ic_caps = IEEE80211_C_WEP | IEEE80211_C_PMGT | IEEE80211_C_MONITOR;
#ifndef IEEE80211_STA_ONLY
	ic->ic_caps |= IEEE80211_C_IBSS;
#endif
	ic->ic_state = IEEE80211_S_INIT;
	IEEE80211_ADDR_COPY(ic->ic_myaddr, sc->sc_caps.an_oemaddr);

	switch (sc->sc_caps.an_regdomain) {
	default:
	case AN_REGDOMAIN_USA:
	case AN_REGDOMAIN_CANADA:
		chan_min = 1; chan_max = 11; break;
	case AN_REGDOMAIN_EUROPE:
	case AN_REGDOMAIN_AUSTRALIA:
		chan_min = 1; chan_max = 13; break;
	case AN_REGDOMAIN_JAPAN:
		chan_min = 14; chan_max = 14; break;
	case AN_REGDOMAIN_SPAIN:
		chan_min = 10; chan_max = 11; break;
	case AN_REGDOMAIN_FRANCE:
		chan_min = 10; chan_max = 13; break;
	case AN_REGDOMAIN_JAPANWIDE:
		chan_min = 1; chan_max = 14; break;
	}

	for (chan = chan_min; chan <= chan_max; chan++) {
		ic->ic_channels[chan].ic_freq =
		    ieee80211_ieee2mhz(chan, IEEE80211_CHAN_2GHZ);
		ic->ic_channels[chan].ic_flags = IEEE80211_CHAN_B;
	}
	ic->ic_ibss_chan = &ic->ic_channels[chan_min];

	/* Find supported rate */
	for (i = 0; i < sizeof(sc->sc_caps.an_rates); i++) {
		if (sc->sc_caps.an_rates[i] == 0)
			continue;
		ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[
		    ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates++] =
		    sc->sc_caps.an_rates[i];
	}

	/*
	 * Call MI attach routine.
	 */
	if_attach(ifp);
	ieee80211_ifattach(ifp);

	sc->sc_newstate = ic->ic_newstate;
	ic->ic_newstate = an_newstate;

	ieee80211_media_init(ifp, an_media_change, an_media_status);

#if NBPFILTER > 0
	bzero(&sc->sc_rxtapu, sizeof(sc->sc_rxtapu));
	sc->sc_rxtap.ar_ihdr.it_len = sizeof(sc->sc_rxtapu);
	sc->sc_rxtap.ar_ihdr.it_present = AN_RX_RADIOTAP_PRESENT;

	bzero(&sc->sc_txtapu, sizeof(sc->sc_txtapu));
	sc->sc_txtap.at_ihdr.it_len = sizeof(sc->sc_txtapu);
	sc->sc_txtap.at_ihdr.it_present = AN_TX_RADIOTAP_PRESENT;

	bpfattach(&sc->sc_drvbpf, ifp, DLT_IEEE802_11_RADIO,
	    sizeof(struct ieee80211_frame) + 64);
#endif

	sc->sc_attached = 1;

	return(0);
}
Esempio n. 5
0
int site_survey_main(int argc, char *argv[])
#endif
{
#define DOT11_CAP_ESS				0x0001
#define DOT11_CAP_IBSS				0x0002
#define DOT11_CAP_PRIVACY			0x0010	/* d11 cap. privacy */

	unsigned char b1[32], b2[64], b3[32], b4[32], b5[32], b6[32], b7[32], ext[32];
	int i = 0;

	unlink(SITE_SURVEY_DB);
	int ap = 0, oldap = 0;
	int len;

	memset(site_survey_lists, sizeof(site_survey_lists), 0);
	if (nvram_match("wl0_mode", "ap")
	    || nvram_match("wl0_mode", "apsta")) {
		eval("iwpriv", "ra0", "set", "SiteSurvey=1");	// only in ap mode
		sleep(4);	//wait 4 seconds per spec
	}

	FILE *scan = popen("iwpriv ra0 get_site_survey", "rb");

	skipline(scan);
	skipline(scan);
//      fscanf(scan, "%s %s", b1, b2);  // skip first line
//      fscanf(scan, "%s %s %s %s %s %s %s", b1, b2, b3, b4, b5, b6, b7);       //skip second line
	i = 0;
	int c = 0;
	do {
		if (feof(scan))
			break;
		fread(b1, 4, 1, scan);
		b1[4] = 0;
		b1[strlen(b1)] = 0;
		fread(b2, 33, 1, scan);
		b2[32] = 0;
		b2[strlen(b2)] = 0;
		//kill trailing blanks
		for (c = 0; c < 32; c++) {
			if (b2[31 - c] != 0x20)
				break;
			b2[31 - c] = 0;
		}
		//skip leading blanks
		for (c = 0; c < 32; c++) {
			if (b2[c] != 0x20)
				break;
		}
		if (c && c < 32) {
			for (i = 0; i < 32 - c; i++)
				b2[i] = b2[i + c];
		}
		int ret = fscanf(scan, "%s %s %s %s %s %s", b3, b4, b5, b6, ext, b7);	//skip second line
		if (ret < 5)
			break;
		if (ret == 6)
			skipline(scan);
		else
			strncpy(b7, ext, 31);
		site_survey_lists[i].channel = atoi(b1);	// channel
		site_survey_lists[i].frequency = ieee80211_ieee2mhz(site_survey_lists[i].channel);
		strcpy(site_survey_lists[i].SSID, b2);	//SSID
		strcpy(site_survey_lists[i].BSSID, b3);	//BSSID
		site_survey_lists[i].phy_noise = -95;	// no way
		strcpy(site_survey_lists[i].ENCINFO, b4);
		site_survey_lists[i].RSSI = -atoi(b5);

		if (!strcmp(b6, "11b/g"))
			site_survey_lists[i].rate_count = 12;
		if (!strcmp(b6, "11b"))
			site_survey_lists[i].rate_count = 4;
		if (!strcmp(b6, "11b/g/n"))
			site_survey_lists[i].rate_count = 300;

		if (!strcmp(b7, "In"))
			site_survey_lists[i].capability = DOT11_CAP_ESS;

		if (!strcmp(b7, "Ad"))
			site_survey_lists[i].capability = DOT11_CAP_IBSS;

		if (strcmp(b4, "OPEN"))
			site_survey_lists[i].capability |= DOT11_CAP_PRIVACY;

		i++;
	}
	while (1);
	fclose(scan);
	write_site_survey();
	open_site_survey();
	for (i = 0; i < SITE_SURVEY_NUM && site_survey_lists[i].BSSID[0]
	     && site_survey_lists[i].channel != 0; i++) {

		fprintf(stderr,
			"[%2d] SSID[%20s] BSSID[%s] channel[%2d] frequency[%4d] rssi[%d] noise[%d] beacon[%d] cap[%x] dtim[%d] rate[%d] enc[%s]\n",
			i, site_survey_lists[i].SSID,
			site_survey_lists[i].BSSID,
			site_survey_lists[i].channel,
			site_survey_lists[i].frequency,
			site_survey_lists[i].RSSI,
			site_survey_lists[i].phy_noise,
			site_survey_lists[i].beacon_period, site_survey_lists[i].capability, site_survey_lists[i].dtim_period, site_survey_lists[i].rate_count, site_survey_lists[i].ENCINFO);
	}

	return 0;
}
Esempio n. 6
0
int
an_attach(struct an_softc *sc)
{
	struct ieee80211com *ic = &sc->sc_ic;
	struct ifnet *ifp = &sc->sc_if;
	int i, s;
	struct an_rid_wepkey *akey;
	int buflen, kid, rid;
	int chan, chan_min, chan_max;

	s = splnet();
	sc->sc_invalid = 0;

	an_wait(sc);
	if (an_reset(sc) != 0) {
		sc->sc_invalid = 1;
		splx(s);
		return 1;
	}

	/* Load factory config */
	if (an_cmd(sc, AN_CMD_READCFG, 0) != 0) {
		splx(s);
		aprint_error_dev(sc->sc_dev, "failed to load config data\n");
		return 1;
	}

	/* Read the current configuration */
	buflen = sizeof(sc->sc_config);
	if (an_read_rid(sc, AN_RID_GENCONFIG, &sc->sc_config, &buflen) != 0) {
		splx(s);
		aprint_error_dev(sc->sc_dev, "read config failed\n");
		return 1;
	}

	/* Read the card capabilities */
	buflen = sizeof(sc->sc_caps);
	if (an_read_rid(sc, AN_RID_CAPABILITIES, &sc->sc_caps, &buflen) != 0) {
		splx(s);
		aprint_error_dev(sc->sc_dev, "read caps failed\n");
		return 1;
	}

#ifdef AN_DEBUG
	if (an_debug) {
		static const int dumprid[] = {
		    AN_RID_GENCONFIG, AN_RID_CAPABILITIES, AN_RID_SSIDLIST,
		    AN_RID_APLIST, AN_RID_STATUS, AN_RID_ENCAP
		};

		for (rid = 0; rid < sizeof(dumprid)/sizeof(dumprid[0]); rid++) {
			buflen = sizeof(sc->sc_buf);
			if (an_read_rid(sc, dumprid[rid], &sc->sc_buf, &buflen)
			    != 0)
				continue;
			printf("%04x (%d):\n", dumprid[rid], buflen);
			for (i = 0; i < (buflen + 1) / 2; i++)
				printf(" %04x", sc->sc_buf.sc_val[i]);
			printf("\n");
		}
	}
#endif

	/* Read WEP settings from persistent memory */
	akey = &sc->sc_buf.sc_wepkey;
	buflen = sizeof(struct an_rid_wepkey);
	rid = AN_RID_WEP_VOLATILE;	/* first persistent key */
	while (an_read_rid(sc, rid, akey, &buflen) == 0) {
		kid = le16toh(akey->an_key_index);
		DPRINTF(("an_attach: wep rid=0x%x len=%d(%zu) index=0x%04x "
		    "mac[0]=%02x keylen=%d\n",
		    rid, buflen, sizeof(*akey), kid,
		    akey->an_mac_addr[0], le16toh(akey->an_key_len)));
		if (kid == 0xffff) {
			sc->sc_tx_perskey = akey->an_mac_addr[0];
			sc->sc_tx_key = -1;
			break;
		}
		if (kid >= IEEE80211_WEP_NKID)
			break;
		sc->sc_perskeylen[kid] = le16toh(akey->an_key_len);
		sc->sc_wepkeys[kid].an_wep_keylen = -1;
		rid = AN_RID_WEP_PERSISTENT;	/* for next key */
		buflen = sizeof(struct an_rid_wepkey);
	}

	aprint_normal_dev(sc->sc_dev, "%s %s (firmware %s)\n",
	    sc->sc_caps.an_manufname, sc->sc_caps.an_prodname,
	    sc->sc_caps.an_prodvers);

	memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);

	ifp->if_softc = sc;
	ifp->if_flags = IFF_BROADCAST | IFF_NOTRAILERS | IFF_SIMPLEX |
	    IFF_MULTICAST | IFF_ALLMULTI;
	ifp->if_ioctl = an_ioctl;
	ifp->if_start = an_start;
	ifp->if_init = an_init;
	ifp->if_stop = an_stop;
	ifp->if_watchdog = an_watchdog;
	IFQ_SET_READY(&ifp->if_snd);

	ic->ic_ifp = ifp;
	ic->ic_phytype = IEEE80211_T_DS;
	ic->ic_opmode = IEEE80211_M_STA;
	ic->ic_caps = IEEE80211_C_WEP | IEEE80211_C_PMGT | IEEE80211_C_IBSS |
	    IEEE80211_C_MONITOR;
	ic->ic_state = IEEE80211_S_INIT;
	IEEE80211_ADDR_COPY(ic->ic_myaddr, sc->sc_caps.an_oemaddr);

	switch (le16toh(sc->sc_caps.an_regdomain)) {
	default:
	case AN_REGDOMAIN_USA:
	case AN_REGDOMAIN_CANADA:
		chan_min = 1; chan_max = 11; break;
	case AN_REGDOMAIN_EUROPE:
	case AN_REGDOMAIN_AUSTRALIA:
		chan_min = 1; chan_max = 13; break;
	case AN_REGDOMAIN_JAPAN:
		chan_min = 14; chan_max = 14; break;
	case AN_REGDOMAIN_SPAIN:
		chan_min = 10; chan_max = 11; break;
	case AN_REGDOMAIN_FRANCE:
		chan_min = 10; chan_max = 13; break;
	case AN_REGDOMAIN_JAPANWIDE:
		chan_min = 1; chan_max = 14; break;
	}

	for (chan = chan_min; chan <= chan_max; chan++) {
		ic->ic_channels[chan].ic_freq =
		    ieee80211_ieee2mhz(chan, IEEE80211_CHAN_2GHZ);
		ic->ic_channels[chan].ic_flags = IEEE80211_CHAN_B;
	}
	ic->ic_ibss_chan = &ic->ic_channels[chan_min];

	aprint_normal("%s: 802.11 address: %s, channel: %d-%d\n",
	    ifp->if_xname, ether_sprintf(ic->ic_myaddr), chan_min, chan_max);

	/* Find supported rate */
	for (i = 0; i < sizeof(sc->sc_caps.an_rates); i++) {
		if (sc->sc_caps.an_rates[i] == 0)
			continue;
		ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[
		    ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates++] =
		    sc->sc_caps.an_rates[i];
	}

	/*
	 * Call MI attach routine.
	 */
	if_attach(ifp);
	ieee80211_ifattach(ic);

	sc->sc_newstate = ic->ic_newstate;
	ic->ic_newstate = an_newstate;

	ieee80211_media_init(ic, an_media_change, an_media_status);

	/*
	 * radiotap BPF device
	 */
#if NBPFILTER > 0
	bpfattach2(ifp, DLT_IEEE802_11_RADIO,
	    sizeof(struct ieee80211_frame) + 64, &sc->sc_drvbpf);
#endif

	memset(&sc->sc_rxtapu, 0, sizeof(sc->sc_rxtapu));
	sc->sc_rxtap.ar_ihdr.it_len = htole16(sizeof(sc->sc_rxtapu));
	sc->sc_rxtap.ar_ihdr.it_present = htole32(AN_RX_RADIOTAP_PRESENT);

	memset(&sc->sc_txtapu, 0, sizeof(sc->sc_txtapu));
	sc->sc_txtap.at_ihdr.it_len = htole16(sizeof(sc->sc_txtapu));
	sc->sc_txtap.at_ihdr.it_present = htole32(AN_TX_RADIOTAP_PRESENT);

	sc->sc_attached = 1;
	splx(s);

	ieee80211_announce(ic);
	return 0;
}
Esempio n. 7
0
int site_survey_main(int argc, char *argv[])
{
	char tmp[32];
	sprintf(tmp, "%s_ifname", nvram_safe_get("wifi_display"));
	char *name = nvram_safe_get(tmp);

	unsigned char buf[10000];
	wl_scan_results_t *scan_res = (wl_scan_results_t *) buf;
	wl_bss_info_t *bss_info;
	unsigned char mac[20];
	int i;
	char *dev = name;

	unlink(SITE_SURVEY_DB);
	int ap = 0, oldap = 0;
	wl_scan_params_t params;

	memset(&params, 0, sizeof(params));

	/*
	 * use defaults (same parameters as wl scan) 
	 */

	memset(&params.bssid, 0xff, sizeof(params.bssid));
	if (argc > 1) {
		params.ssid.SSID_len = strlen(argv[1]);
		strcpy(params.ssid.SSID, argv[1]);
	}
	params.bss_type = DOT11_BSSTYPE_ANY;
	params.scan_type = 0;
	params.nprobes = -1;
	params.active_time = -1;
	params.passive_time = -1;
	params.home_time = -1;
	params.channel_num = 0;

	/*
	 * can only scan in STA mode 
	 */
	if (wl_ioctl(dev, WLC_SCAN, &params, 64) < 0) {
		fprintf(stderr, "scan failed\n");
		return -1;
	}
	int count = 10;
	int ret = 0;
	while ((count--) > 0)	//scan for max 5 seconds
	{
		usleep(500 * 1000);

		bzero(buf, sizeof(buf));
		scan_res->buflen = sizeof(buf);
		ret = wl_ioctl(dev, WLC_SCAN_RESULTS, buf, WLC_IOCTL_MAXLEN);
		if (!ret)
			break;
	}
	if (ret < 0) {
		fprintf(stderr, "scan failed with errorcode %d\n", ret);
	}

	fprintf(stderr, "buflen=[%d] version=[%d] count=[%d]\n", scan_res->buflen, scan_res->version, scan_res->count);

	if (scan_res->count == 0) {
		cprintf("Can't find any wireless device\n");
		goto endss;
	}

	bss_info = &scan_res->bss_info[0];
	for (i = 0; i < scan_res->count; i++) {
		strcpy(site_survey_lists[i].SSID, bss_info->SSID);
		strcpy(site_survey_lists[i].BSSID, ether_etoa(bss_info->BSSID.octet, mac));
#ifndef HAVE_RB500
		site_survey_lists[i].channel = bss_info->chanspec & 0xff;
#endif
		site_survey_lists[i].frequency = ieee80211_ieee2mhz(site_survey_lists[i].channel);
#ifdef WL_CHANSPEC_BW_80
		switch (bss_info->chanspec & 0x3800) {
		case WL_CHANSPEC_BW_80:
			site_survey_lists[i].channel |= 0x1000;
			break;
		case WL_CHANSPEC_BW_8080:
			site_survey_lists[i].channel |= 0x1100;
			break;
		case WL_CHANSPEC_BW_160:
			site_survey_lists[i].channel |= 0x1200;
			break;
		}
#endif

		site_survey_lists[i].RSSI = bss_info->RSSI;
		site_survey_lists[i].phy_noise = bss_info->phy_noise;
		site_survey_lists[i].beacon_period = bss_info->beacon_period;
		site_survey_lists[i].capability = bss_info->capability;
		site_survey_lists[i].rate_count = get_mcs_max(bss_info->basic_mcs);
		if (!site_survey_lists[i].rate_count)
			site_survey_lists[i].rate_count = get_legacy(bss_info->rateset.rates, bss_info->rateset.count);

		site_survey_lists[i].dtim_period = bss_info->dtim_period;
		strcpy(site_survey_lists[i].ENCINFO, getEncInfo(bss_info));

		bss_info = (wl_bss_info_t *) ((uint32) bss_info + bss_info->length);
	}
	write_site_survey();
	open_site_survey();
	// modded by ascott and fractal, may 17th, 2012 to show "hidden" SSIDS
	for (i = 0; i < SITE_SURVEY_NUM && site_survey_lists[i].BSSID[0]; i++) {
		if (site_survey_lists[i].SSID[0] == 0) {
			strcpy(site_survey_lists[i].SSID, "hidden");
		}
		fprintf(stderr,
			"[%2d] SSID[%20s] BSSID[%s] channel[%2d] frequency[%4d] rssi[%d] noise[%d] beacon[%d] cap[%x] dtim[%d] rate[%d] enc[%s]\n",
			i, site_survey_lists[i].SSID,
			site_survey_lists[i].BSSID,
			site_survey_lists[i].channel & 0xff,
			site_survey_lists[i].frequency,
			site_survey_lists[i].RSSI,
			site_survey_lists[i].phy_noise,
			site_survey_lists[i].beacon_period, site_survey_lists[i].capability, site_survey_lists[i].dtim_period, site_survey_lists[i].rate_count, site_survey_lists[i].ENCINFO);
	}

endss:

	C_led(0);
	eval("wl", "-i", name, "up");
	return 0;
}