Пример #1
0
int ledtracking_main(int argc, char **argv)
{
	int toggle = 0;
	int testsnr = 0;
	int rssi, noise, snr_min, snr_max, polarity, delay, snr, gpio;
	unsigned char assoclist[1024];

	if (argc <= 4) {
		fprintf(stderr, "%s <interfacex> <gpio> <polarity> <snr-max>\n", argv[0]);
		exit(1);
	}
	gpio = atoi(argv[2]);
	polarity = atoi(argv[3]);
	snr_max = atoi(argv[4]);
	snr_min = snr_max / 6;
	if (argc == 6) {
		testsnr = atoi(argv[5]);
		fprintf(stderr, "use testsnr %d\n", testsnr);
	}

	while (1) {
		if (testsnr) {
			snr = testsnr;
		} else {
			int cnt = getassoclist(argv[1], assoclist);

			if (cnt == -1) {
				cnt = 0;
			}
			if (!cnt) {
				fprintf(stderr, "not associated, wait 5 seconds\n");
				sleep(5);
				continue;
			}
			unsigned char *pos = assoclist;

			pos += 4;
			rssi = getRssi(argv[1], pos);
			noise = getNoise(argv[1], pos);
			snr = rssi - noise;
		}

		if (snr < 0) {
			fprintf(stderr, "snr is %d, invalid\n", snr);
			continue;
		}

		snr -= snr_min;
		if (snr < 0)
			snr = 0;

		if (snr >= snr_max - snr_min) {
			fprintf(stderr, "snr >= snr_max - snr_min\n", gpio, toggle);
			toggle = polarity;
			delay = 100;
		} else {
			fprintf(stderr, "else\n", gpio, toggle);
			toggle = !toggle;
			delay = 1000 - snr * (1000 - 125) / (snr_max - snr_min);
		}

		usleep(1000 * delay / 2);
		set_gpio(gpio, 0 + toggle);
		fprintf(stderr, "%d,%d\n", gpio, toggle);
	}
}
Пример #2
0
int ej_active_wireless_if(webs_t wp, int argc, char_t ** argv, char *iface, char *visible, int cnt)
{
	int rssi = 0, noise = 0;
	FILE *fp2;
	char *mode;
	char mac[30];
	char line[80];
	int macmask;
	macmask = atoi(argv[0]);
	if (!ifexists(iface))
		return cnt;
	unlink(RSSI_TMP);
	char wlmode[32];

	sprintf(wlmode, "%s_mode", visible);
	mode = nvram_safe_get(wlmode);
	unsigned char buf[WLC_IOCTL_MAXLEN];

	memset(buf, 0, WLC_IOCTL_MAXLEN);	// get_wdev
	int r = getassoclist(iface, buf);

	if (r < 0)
		return cnt;
	struct maclist *maclist = (struct maclist *)buf;
	int i;

	for (i = 0; i < maclist->count; i++) {
		ether_etoa((uint8 *) & maclist->ea[i], mac);

		rssi = 0;
		noise = 0;
		// get rssi value
		if (strcmp(mode, "ap") && strcmp(mode, "apsta")
		    && strcmp(mode, "apstawet"))
			sysprintf("wl -i %s rssi > %s", iface, RSSI_TMP);
		else
			sysprintf("wl -i %s rssi \"%s\" > %s", iface, mac, RSSI_TMP);

		// get noise value if not ap mode
		// if (strcmp (mode, "ap"))
		// snprintf (cmd, sizeof (cmd), "wl -i %s noise >> %s", iface,
		// RSSI_TMP);
		// system2 (cmd); // get RSSI value for mac

		fp2 = fopen(RSSI_TMP, "r");
		if (fgets(line, sizeof(line), fp2) != NULL) {

			// get rssi
			if (sscanf(line, "%d", &rssi) != 1)
				continue;
			noise = getNoise(iface, NULL);
			/*
			 * if (strcmp (mode, "ap") && fgets (line, sizeof (line), fp2) != 
			 * NULL && sscanf (line, "%d", &noise) != 1) continue;
			 */
			// get noise for client/wet mode

			fclose(fp2);
		}
		if (nvram_match("maskmac", "1") && macmask) {
			mac[0] = 'x';
			mac[1] = 'x';
			mac[3] = 'x';
			mac[4] = 'x';
			mac[6] = 'x';
			mac[7] = 'x';
			mac[9] = 'x';
			mac[10] = 'x';
		}
		if (cnt)
			websWrite(wp, ",");
		cnt++;
		int rxrate[32];
		int txrate[32];
		int time[32];
		strcpy(rxrate, "N/A");
		strcpy(txrate, "N/A");
		strcpy(time, "N/A");
#ifndef WL_STA_SCBSTATS
#define WL_STA_SCBSTATS		0x4000	/* Per STA debug stats */
#endif
		sta_info_compat_t *sta;
		sta_info_compat_old_t *staold;
		char *param;
		int buflen;
		char buf[WLC_IOCTL_MEDLEN];
		strcpy(buf, "sta_info");
		buflen = strlen(buf) + 1;
		param = (char *)(buf + buflen);
		memcpy(param, (char *)&maclist->ea[i], ETHER_ADDR_LEN);
		if (!wl_ioctl(iface, WLC_GET_VAR, &buf[0], WLC_IOCTL_MEDLEN)) {
			/* display the sta info */
			sta = (sta_info_compat_t *) buf;
			if (sta->ver == 2) {
				staold = (sta_info_compat_old_t *) buf;
				if (staold->flags & WL_STA_SCBSTATS) {
					int tx = staold->tx_rate;
					int rx = staold->rx_rate;
					if (tx > 0)
						sprintf(txrate, "%dM", tx / 1000);

					if (rx > 0)
						sprintf(rxrate, "%dM", rx / 1000);
					strcpy(time, UPTIME(staold->in));
				}
			} else {	// sta->ver == 3
				if (sta->flags & WL_STA_SCBSTATS) {
					int tx = sta->tx_rate;
					int rx = sta->rx_rate;
					if (tx > 0)
						sprintf(txrate, "%dM", tx / 1000);

					if (rx > 0)
						sprintf(rxrate, "%dM", rx / 1000);
					strcpy(time, UPTIME(sta->in));
				}
			}
		}

		/*
		 * if (!strcmp (mode, "ap")) { noise = getNoise(iface,NULL); // null
		 * only for broadcom }
		 */
		int qual = rssi * 124 + 11600;
		qual /= 10;
		websWrite(wp, "'%s','%s','%s','%s','%s','%d','%d','%d','%d'", mac, iface, time, txrate, rxrate, rssi, noise, rssi - noise, qual);
	}
	unlink(RSSI_TMP);

	return cnt;
}
Пример #3
0
void readWL(wiviz_cfg * cfg)
{
	int ap, i;
	wiviz_host *host, *sta;
	uchar mac[6];
	wlc_ssid_t ssid;
	channel_info_t channel;
	maclist_t *macs;
	sta_rssi_t starssi;
	char buf[32];

	get_mac(wl_dev, mac);
	printf("AP mac: ");
#ifdef NEED_PRINTF
	print_mac(mac, "\n");
#endif
	if (!nonzeromac(mac))
		return;
#ifdef HAVE_RT2880
	if (nvram_match("ap", "wl0_oldmode"))
		ap = 1;
#else
	if (nvram_nmatch("ap", "%s_mode", wl_dev))
		ap = 1;
	if (nvram_nmatch("wdsap", "%s_mode", wl_dev))
		ap = 1;
#endif
//      wl_ioctl(wl_dev, WLC_GET_AP, &ap, 4);
	if (ap) {
		host = gotHost(cfg, mac, typeAP);
		host->isSelf = 1;
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
#ifdef HAVE_RT2880
		strcpy(host->apInfo->ssid, nvram_safe_get("wl0_ssid"));
		host->apInfo->ssidlen = strlen(host->apInfo->ssid);
		ether_atoe(nvram_safe_get("wl0_hwaddr"), buf);
		memcpy(host->apInfo->bssid, buf, 6);
#else
		strcpy(host->apInfo->ssid, nvram_nget("%s_ssid", wl_dev));
		host->apInfo->ssidlen = strlen(host->apInfo->ssid);
		ether_atoe(nvram_nget("%s_hwaddr", wl_dev), buf);
		memcpy(host->apInfo->bssid, buf, 6);
#endif
#else
		wl_ioctl(wl_dev, WLC_GET_BSSID, host->apInfo->bssid, 6);
		wl_ioctl(wl_dev, WLC_GET_SSID, &ssid, sizeof(wlc_ssid_t));
		memcpy(host->apInfo->ssid, ssid.SSID, 32);
		host->apInfo->ssidlen = ssid.SSID_len;
#endif
		host->RSSI = 0;
#ifdef HAVE_MADWIFI
		host->apInfo->channel = wifi_getchannel(wl_dev);
#elif HAVE_RT2880
		host->apInfo->channel = atoi(nvram_safe_get("wl0_channel"));
#else
		wl_ioctl(wl_dev, WLC_GET_CHANNEL, &channel, sizeof(channel_info_t));
		host->apInfo->channel = channel.hw_channel;
#endif

		macs = (maclist_t *) malloc(4 + MAX_STA_COUNT * sizeof(ether_addr_t));
		macs->count = MAX_STA_COUNT;
		int code = getassoclist(wl_dev, macs);
		printf("code :%d\n", code);
		if (code > 0) {
			for (i = 0; i < macs->count; i++) {
				sta = gotHost(cfg, (char *)&macs->ea[i], typeSta);
#ifdef HAVE_MADWIFI
				sta->RSSI = -getRssi(wl_dev, macs->ea) * 100;
#elif HAVE_RT2880
				sta->RSSI = -getRssi(wl_dev, macs->ea) * 100;	// needs to be solved                            
#else
				memcpy(starssi.mac, &macs->ea[i], 6);
				starssi.RSSI = 3000;
				starssi.zero_ex_forty_one = 0x41;
				if (wl_ioctl(wl_dev, WLC_GET_RSSI, &starssi, 12) < 0)
					printf("rssifail\n");
				sta->RSSI = -starssi.RSSI * 100;
#endif
				sta->staInfo->state = ssAssociated;
				memcpy(sta->staInfo->connectedBSSID, host->apInfo->bssid, 6);
			}
		}
	} else {
		host = gotHost(cfg, mac, typeSta);
		host->isSelf = 1;
		host->RSSI = 0;
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
		if (getassoclist(wl_dev, macs) > -1) {
			if (macs->count > 0) {
				host->staInfo->state = ssUnassociated;
			} else {
				host->staInfo->state = ssAssociated;
			}
		} else {
			host->staInfo->state = ssUnassociated;

		}

#else
		if (wl_ioctl(wl_dev, WLC_GET_BSSID, &host->staInfo->connectedBSSID, 6) < 0) {
			host->staInfo->state = ssUnassociated;
		} else {
			host->staInfo->state = ssAssociated;
		}
#endif
	}
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
	cfg->curChannel = wifi_getchannel(wl_dev);

#else
	if (wl_ioctl(wl_dev, WLC_GET_CHANNEL, &channel, sizeof(channel_info_t)) >= 0) {
		cfg->curChannel = channel.hw_channel;
		printf("Current channel is %i\n", cfg->curChannel);
	}
#endif
}