Exemplo n.º 1
0
static void
list_scan(prop_dictionary_t env)
{
	u_int8_t buf[64*1024 - 1];
	struct ieee80211req ireq;
	char ssid[IEEE80211_NWID_LEN+1];
	const u_int8_t *cp;
	int len, ssidmax;
	const struct ieee80211req_scan_result *sr;

	memset(&ireq, 0, sizeof(ireq));
	ireq.i_type = IEEE80211_IOC_SCAN_RESULTS;
	ireq.i_data = buf;
	ireq.i_len = sizeof(buf);
	if (direct_ioctl(env, SIOCG80211, &ireq) < 0)
		errx(EXIT_FAILURE, "unable to get scan results");
	len = ireq.i_len;
	if (len < (int)sizeof(*sr))
		return;

	ssidmax = calc_len(buf, len);

	printf("%-*.*s  %-17.17s  %4s %4s  %-7s %3s %4s\n"
		, ssidmax, ssidmax, "SSID"
		, "BSSID"
		, "CHAN"
		, "RATE"
		, "S:N"
		, "INT"
		, "CAPS"
	);
	cp = buf;
	while (len >= (int)sizeof(*sr)) {
		const uint8_t *vp;

		sr = (const struct ieee80211req_scan_result *) cp;
		vp = (const u_int8_t *)(sr+1);
		(void)copy_essid(ssid, sizeof(ssid), vp, sr->isr_ssid_len);
		printf("%-*.*s  %s  %3d  %3dM %3d:%-3d  %3d %-4.4s"
			, ssidmax, ssidmax, ssid
			, ether_ntoa((const struct ether_addr *) sr->isr_bssid)
			, ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
			, getmaxrate(sr->isr_rates, sr->isr_nrates)
			, sr->isr_rssi, sr->isr_noise
			, sr->isr_intval
			, getcaps(sr->isr_capinfo)
		);
		printies(vp + sr->isr_ssid_len, sr->isr_ie_len, 24);
		printf("\n");
		cp += sr->isr_len, len -= sr->isr_len;
	}
}
Exemplo n.º 2
0
static void
list_scan(const char *ifname)
{
	uint8_t buf[24 * 1024];
	char ssid[14];
	uint8_t *cp;
	int len;

	len = get80211priv(ifname, IEEE80211_IOCTL_SCAN_RESULTS,
		buf, sizeof(buf));
	if (len == -1)
		errx(1, "unable to get scan results");
	if (len < sizeof(struct ieee80211req_scan_result))
		return;

	printf("%-14.14s  %-17.17s  %4s %4s  %-5s %3s %4s\n",
		"SSID",
		"BSSID",
		"CHAN",
		"RATE",
		"S:N",
		"INT",
		"CAPS");
	cp = buf;
	do {
		struct ieee80211req_scan_result *sr;
		uint8_t *vp;

		sr = (struct ieee80211req_scan_result *) cp;
		vp = (u_int8_t *)(sr+1);
		printf("%-14.*s  %s  %3d  %3dM %2d:%-2d  %3d %-4.4s",
			copy_essid(ssid, sizeof(ssid), vp, sr->isr_ssid_len),
			ssid,
			ieee80211_ntoa(sr->isr_bssid),
			ieee80211_mhz2ieee(sr->isr_freq),
			getmaxrate(sr->isr_rates, sr->isr_nrates),
			(int8_t) sr->isr_rssi, sr->isr_noise,
			sr->isr_intval,
			getcaps(sr->isr_capinfo));
		printies(vp + sr->isr_ssid_len, sr->isr_ie_len, 24);
		printf("\n");
		cp += sr->isr_len, len -= sr->isr_len;
	} while (len >= sizeof(struct ieee80211req_scan_result));
}
Exemplo n.º 3
0
static int
wpa_driver_bsd_get_scan_results(void *priv,
				     struct wpa_scan_result *results,
				     size_t max_size)
{
#define	min(a,b)	((a)>(b)?(b):(a))
	struct wpa_driver_bsd_data *drv = priv;
	uint8_t buf[24*1024];
	const uint8_t *cp, *vp;
	const struct ieee80211req_scan_result *sr;
	struct wpa_scan_result *wsr;
	int len, ielen;

	memset(results, 0, max_size * sizeof(struct wpa_scan_result));

	len = get80211var(drv, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf));
	if (len < 0)
		return -1;
	cp = buf;
	wsr = results;
	while (len >= sizeof(struct ieee80211req_scan_result)) {
		sr = (const struct ieee80211req_scan_result *) cp;
		memcpy(wsr->bssid, sr->isr_bssid, IEEE80211_ADDR_LEN);
		wsr->ssid_len = sr->isr_ssid_len;
		wsr->freq = sr->isr_freq;
		wsr->noise = sr->isr_noise;
		wsr->qual = sr->isr_rssi;
		wsr->level = 0;		/* XXX? */
		wsr->caps = sr->isr_capinfo;
		wsr->maxrate = getmaxrate(sr->isr_rates, sr->isr_nrates);
		vp = ((u_int8_t *)sr) + sr->isr_ie_off;
		memcpy(wsr->ssid, vp, sr->isr_ssid_len);
		if (sr->isr_ie_len > 0) {
			vp += sr->isr_ssid_len;
			ielen = sr->isr_ie_len;
			while (ielen > 0) {
				switch (vp[0]) {
				case IEEE80211_ELEMID_VENDOR:
					if (!iswpaoui(vp))
						break;
					wsr->wpa_ie_len =
					    min(2+vp[1], SSID_MAX_WPA_IE_LEN);
					memcpy(wsr->wpa_ie, vp, wsr->wpa_ie_len);
					break;
				case IEEE80211_ELEMID_RSN:
					wsr->rsn_ie_len =
					    min(2+vp[1], SSID_MAX_WPA_IE_LEN);
					memcpy(wsr->rsn_ie, vp, wsr->rsn_ie_len);
					break;
				}
				ielen -= 2+vp[1];
				vp += 2+vp[1];
			}
		}

		cp += sr->isr_len, len -= sr->isr_len;
		wsr++;
	}
	qsort(results, wsr - results, sizeof(struct wpa_scan_result),
	      wpa_scan_result_compar);

	wpa_printf(MSG_DEBUG, "Received %d bytes of scan results (%d BSSes)",
		   len, wsr - results);

	return wsr - results;
#undef min
}
Exemplo n.º 4
0
static void
list_scan(AP_IW_CHANSCAN_RESULT_T *cfg, const char *ifname)
{
	uint8_t  buf[48*1024];
	uint8_t  *cp = NULL;
	int      len = 0;
    int      count = 0;  //to count results.
    int      iTemp = 0;
    AP_IW_CHANSCAN_RESULT_ENTRY *entry;
    struct ieee80211req_scan_result *sr;
    uint8_t *vp;

	len = get80211priv(ifname, IEEE80211_IOCTL_SCAN_RESULTS,
			    buf, sizeof(buf));
    
	if (len == -1)
	{
		RTN_LOG("IOCTL error,unable to get scan results");
        return;
	}    
    
	if (len < sizeof(struct ieee80211req_scan_result))
	{
        RTN_LOG("get scan results len %d < struct", len);
        return;
	}
    
	cp = buf;
	do {
		sr = (struct ieee80211req_scan_result *) cp;
		vp = (u_int8_t *)(sr+1);

//        RTN_LOG("Get assignchan=%d, match chan=%d", cfg->assignChan, sr->isr_freq);

        if(cfg->assignChan == 0 || cfg->assignChan == sr->isr_freq)
        {                  
            entry = &cfg->scan_entry[count];        

            //set ssid
            iTemp = copy_essid((char *)entry->ssid, 32, vp, sr->isr_ssid_len);
            entry->ssid[iTemp] = '\0';

            //set bssid
            memcpy(entry->bssid, sr->isr_bssid, 6);
            
            //set chan
            entry->chan = sr->isr_freq;
                   
            //set maxrate
            entry->maxrate =  getmaxrate(sr->isr_rates, sr->isr_nrates);
            
            //set rssi
            entry->rssi = sr->isr_rssi;
            
            //set noise
            entry->noise = sr->isr_noise;

            //set intval
            entry->intval = sr->isr_intval;

            //set caps
            getcaps(sr->isr_capinfo, (char *)entry->caps);

            //set ies,max = 96/4-1=23
            getIEs(vp + sr->isr_ssid_len, sr->isr_ie_len, 23, entry->ieinfo);

            count++;

        }       
        
		cp += sr->isr_len, len -= sr->isr_len;               
	} while ((len >= sizeof(struct ieee80211req_scan_result)) && (count < AP_IW_CHANSCAN_MAX_RESULT_NUM));

    cfg->num = count;
}