Exemple #1
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;
}
Exemple #2
0
int
// sys_upgrade(char *url, FILE *stream, int *total)
sys_upgrade(char *url, webs_t stream, int *total, int type)	// jimmy,
								// https,
								// 8/6/2003
{

#ifndef ANTI_FLASH
	char upload_fifo[] = "/tmp/uploadXXXXXX";
	FILE *fifo = NULL;
	char *write_argv[4];
	pid_t pid;
	char *buf = NULL;
	int count, ret = 0;
	long flags = -1;
	int size = BUFSIZ;
	int i = 0;

	{
		write_argv[0] = "write";
		write_argv[1] = upload_fifo;
		write_argv[2] = "linux";
		write_argv[3] = NULL;
	}

	// diag_led(DIAG, START_LED); // blink the diag led
	C_led(1);
#ifdef HAVE_HTTPS
	if (do_ssl)
		ACTION("ACT_WEBS_UPGRADE");
	else
#endif
		ACTION("ACT_WEB_UPGRADE");

	/*
	 * Feed write from a temporary FIFO 
	 */
	if (!mktemp(upload_fifo) || !(fifo = fopen(upload_fifo, "w"))) {
		if (!ret)
			ret = errno;
		goto err;
	}

	/*
	 * Set nonblock on the socket so we can timeout 
	 */

	/*
	 ** The buffer must be at least as big as what the stream file is
	 ** using so that it can read all the data that has been buffered
	 ** in the stream file. Otherwise it would be out of sync with fn
	 ** select specially at the end of the data stream in which case
	 ** the select tells there is no more data available but there in
	 ** fact is data buffered in the stream file's buffer. Since no
	 ** one has changed the default stream file's buffer size, let's
	 ** use the constant BUFSIZ until someone changes it.
	 **/

	if (size < MIN_BUF_SIZE)
		size = MIN_BUF_SIZE;
	if ((buf = safe_malloc(size)) == NULL) {
		ret = ENOMEM;
		goto err;
	}

	/*
	 * Pipe the rest to the FIFO 
	 */
	cprintf("Upgrading\n");
	// while (total && *total)
	{
		wfread(&buf[0], 1, 5, stream);
		*total -= 5;
		if (buf[0] != 'R' || buf[1] != 'B' || buf[2] != '5' || buf[3] != '0' || buf[4] != '0') {
			ret = -1;
			goto err;
		}
		int linuxsize;
		int fssize;

		wfread(&linuxsize, 1, 4, stream);
		wfread(&fssize, 1, 4, stream);
		*total -= 8;
		safe_fwrite(&linuxsize, 1, 4, fifo);
		safe_fwrite(&fssize, 1, 4, fifo);
		linuxsize += fssize;
		for (i = 0; i < linuxsize / MIN_BUF_SIZE; i++) {
			wfread(&buf[0], 1, MIN_BUF_SIZE, stream);
			fwrite(&buf[0], 1, MIN_BUF_SIZE, fifo);
		}

		wfread(&buf[0], 1, linuxsize % MIN_BUF_SIZE, stream);
		fwrite(&buf[0], 1, linuxsize % MIN_BUF_SIZE, fifo);
		*total -= linuxsize;

	}
	fclose(fifo);
	fifo = NULL;
	fifo = fopen(upload_fifo, "rb");
	unsigned long linuxsize;
	unsigned long fssize;

	linuxsize = 0;
	linuxsize += getc(fifo);
	linuxsize += getc(fifo) * 256;
	linuxsize += getc(fifo) * 256 * 256;
	linuxsize += getc(fifo) * 256 * 256 * 256;
	fssize = 0;
	fssize += getc(fifo);
	fssize += getc(fifo) * 256;
	fssize += getc(fifo) * 256 * 256;
	fssize += getc(fifo) * 256 * 256 * 256;
	fprintf(stderr, "Write Linux %d\n", linuxsize);
	FILE *out = fopen("/dev/cf/card0/part1", "wb");

	for (i = 0; i < linuxsize; i++)
		putc(getc(fifo), out);
	fclose(out);
	fprintf(stderr, "Write FileSys %d\n", fssize);
	out = fopen("/dev/cf/card0/part2", "wb");
	for (i = 0; i < fssize; i++)
		putc(getc(fifo), out);
	fclose(out);

	/*
	 * Wait for write to terminate 
	 */
	// waitpid (pid, &ret, 0);
	cprintf("done\n");
	ret = 0;
err:
	if (buf)
		free(buf);
	if (fifo)
		fclose(fifo);
	unlink(upload_fifo);

	// diag_led(DIAG, STOP_LED);
	// C_led (0);
	fprintf(stderr, "Idle\n");
	ACTION("ACT_IDLE");

	return ret;
#else
	return 0;
#endif
}