Example #1
0
bool phy_init_tx()
{
    if(get_radiostate() != Idle)
    {
#ifdef LOG_PHY_ENABLED
        log_print_stack_string(LOG_PHY, "PHY radio not idle");
#endif

        return false;
    }

    //Set radio state
    state = Transmit;

    //Go to idle and flush the txfifo
    Strobe(RF_SIDLE);
    Strobe(RF_SFTX);

    return true;
}
Example #2
0
static void watchdog(void)
{
	int brand = getRouterBrand();
	int registered = -1;
	int radiostate0 = -1;
	int oldstate0 = -1;
	int radiostate1 = -1;
	int oldstate1 = -1;
	int counter = 0;
	int radioledinitcount = 0;
	int fd = open("/dev/misc/watchdog", O_WRONLY);
	if (fd == -1)
	    fd = open("/dev/watchdog", O_WRONLY);

	if (fd == -1) {
		return;
	}
	
#ifdef HAVE_MADWIFI
	int cnt = getdevicecount();
#else
	int cnt = get_wl_instances();
#endif
	
	
	while (1) {
		write(fd, "\0", 1);
		fsync(fd);

#ifdef HAVE_REGISTER
		if (!nvram_match("flash_active", "1")) {
			if (registered == -1)
				registered = isregistered_real();
			if (!registered)
				isregistered();	//to poll
		}
#endif
		/* 
		 * software wlan led control 
		 */
		if (radioledinitcount < 5) {
			radioledinitcount++;
			oldstate0 = -1;
			oldstate1 = -1;
		}
		 
#ifdef HAVE_MADWIFI
		if (!nvram_match("flash_active", "1")) {
			radiostate0 = get_radiostate("ath0");
			if (cnt == 2)
				radiostate1 = get_radiostate("ath1");
		}
#else
		wl_ioctl(get_wl_instance_name(0), WLC_GET_RADIO, &radiostate0, sizeof(int));
		if (cnt == 2)
			wl_ioctl(get_wl_instance_name(1), WLC_GET_RADIO, &radiostate1, sizeof(int));
#endif

		if (radiostate0 != oldstate0) {
#ifdef HAVE_MADWIFI
			if (radiostate0 == 1)
#else
			if ((radiostate0 & WL_RADIO_SW_DISABLE) == 0)
#endif
				led_control(LED_WLAN0, LED_ON);
			else {
				led_control(LED_WLAN0, LED_OFF);
#ifndef HAVE_MADWIFI
				/* 
				 * Disable wireless will cause diag led blink, so we want to
				 * stop it. 
				 */
				if (brand == ROUTER_WRT54G)
					diag_led(DIAG, STOP_LED);
				/* 
				 * Disable wireless will cause power led off, so we want to
				 * turn it on. 
				 */
				if (brand == ROUTER_WRT54G_V8)
					led_control(LED_POWER, LED_ON);
#endif
			}
			
			oldstate0 = radiostate0;
		}

		if (radiostate1 != oldstate1) {
#ifdef HAVE_MADWIFI
			if (radiostate1 == 1)
#else
			if ((radiostate1 & WL_RADIO_SW_DISABLE) == 0)
#endif
				led_control(LED_WLAN1, LED_ON);
			else {
				led_control(LED_WLAN1, LED_OFF);
			}

			oldstate1 = radiostate1;
		}
		/* 
		 * end software wlan led control 
		 */

		sleep(10);
		if (nvram_match("warn_enabled", "1")) {
			counter++;
			if (!(counter % 60))
				system("notifier&");	// 
		}
	}
}
Example #3
0
int ej_active_wireless_if_11n(webs_t wp, int argc, char_t ** argv, char *ifname, int cnt, int turbo, int macmask)
{

	unsigned char *cp;
	int s, len;
	struct iwreq iwr;
	char nb[32];
	sprintf(nb, "%s_bias", ifname);
	int bias = atoi(nvram_default_get(nb, "0"));
	if (!ifexists(ifname)) {
		printf("IOCTL_STA_INFO ifresolv %s failed!\n", ifname);
		return cnt;
	}
	int state = 0;
	state = get_radiostate(ifname);
	if (state == 0 || state == -1) {
		printf("IOCTL_STA_INFO radio %s not enabled!\n", ifname);
		return cnt;
	}
	s = getsocket();
	if (s < 0) {
		fprintf(stderr, "socket(SOCK_DRAGM)\n");
		return cnt;
	}
	(void)memset(&iwr, 0, sizeof(struct iwreq));
	(void)strncpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name));

	iwr.u.data.pointer = (void *)&madbuf[0];
	iwr.u.data.length = 24 * 1024;
	if (ioctl(s, IEEE80211_IOCTL_STA_INFO, &iwr) < 0) {
		fprintf(stderr, "IOCTL_STA_INFO for %s failed!\n", ifname);
		closesocket();
		return cnt;
	}
	len = iwr.u.data.length;
	if (len < sizeof(struct ieee80211req_sta_info)) {
		// fprintf(stderr,"IOCTL_STA_INFO len<struct %s failed!\n",ifname);
		closesocket();
		return cnt;
	}
	cp = madbuf;
	int bufcount = 0;
	do {
		struct ieee80211req_sta_info *si;
		uint8_t *vp;

		si = (struct ieee80211req_sta_info *)cp;
		vp = (u_int8_t *)(si + 1);

		if (cnt)
			websWrite(wp, ",");
		cnt++;
		char mac[32];

		strncpy(mac, ieee80211_ntoa(si->isi_macaddr), 31);
		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 (si->isi_noise == 0) {
			si->isi_noise = -95;
		}
		int qual = (si->isi_noise + si->isi_rssi) * 124 + 11600;
		qual /= 10;
		int rxrate = si->isi_rxrateKbps / 1000;
		int txrate = si->isi_txrateKbps / 1000;
		if (!rxrate)
			rxrate = si->isi_rates[si->isi_rxrate] & IEEE80211_RATE_VAL;
		if (!txrate)
			txrate = si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL;

		char rx[32];
		char tx[32];
		if (rxrate)
			sprintf(rx, "%3dM", rxrate);
		else
			sprintf(rx, "N/A");
		if (txrate)
			sprintf(tx, "%3dM", txrate);
		else
			sprintf(tx, "N/A");
		websWrite(wp, "'%s','%s','%s','%s','%s','%d','%d','%d','%d'", mac, ifname, UPTIME(si->isi_uptime), tx, rx, si->isi_noise + si->isi_rssi + bias, si->isi_noise + bias, si->isi_rssi, qual);
		bufcount += si->isi_len;
		cp += si->isi_len;
		len -= si->isi_len;
	}
	while (len >= sizeof(struct ieee80211req_sta_info)
	       && bufcount < (sizeof(madbuf) - sizeof(struct ieee80211req_sta_info)));

	closesocket();

	return cnt;
}
Example #4
0
bool phy_rx(phy_rx_cfg_t* cfg)
{
#ifdef LOG_PHY_ENABLED
    log_print_stack_string(LOG_PHY, "phy_rx");
#endif

    RadioState current_state = get_radiostate();
    if(current_state != Idle && current_state != Receive)
    {
#ifdef LOG_PHY_ENABLED
        log_print_stack_string(LOG_PHY, "PHY Cannot RX, PHy not idle");
#endif
        return false;
    }

    //Set radio state
    state = Receive;

    //Flush the txfifo
    Strobe(RF_SIDLE);
    Strobe(RF_SFRX);

    //Set configuration

    if (!phy_translate_and_set_settings(cfg->spectrum_id, cfg->sync_word_class))
        return false;

    set_timeout(cfg->timeout);

//TODO Return error if fec not enabled but requested
#ifdef D7_PHY_USE_FEC
    if (fec) {
        //Disable hardware data whitening
        set_data_whitening(false);

        //Initialize fec encoding
        fec_init_decode(buffer);

        //Configure length settings
        set_length_infinite(true);

        if(cfg->length == 0)
        {
            packetLength = 0;
            remainingBytes = 0;
            WriteSingleReg(PKTLEN, 0xFF);
            WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_61_4);
        } else {
            fec_set_length(cfg->length);
            packetLength = ((cfg->length & 0xFE) + 2) << 1;
            remainingBytes = packetLength;
            WriteSingleReg(PKTLEN, (uint8_t)(packetLength & 0x00FF));
            WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48);
        }
    } else {
#endif
        //Enable hardware data whitening
        set_data_whitening(true);

        //Set buffer position
        bufferPosition = buffer;

        //Configure length settings and txfifo threshold
        set_length_infinite(false);

        if(cfg->length == 0)
        {
            packetLength = 0;
            remainingBytes = 0;
            WriteSingleReg(PKTLEN, 0xFF);
            WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_61_4);
        } else {
            packetLength = cfg->length;
            remainingBytes = packetLength;
            WriteSingleReg(PKTLEN, packetLength);
            WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48);
        }
#ifdef D7_PHY_USE_FEC
    }
#endif

    //TODO: set minimum sync word rss to scan minimum energy
    //Enable interrupts
    phy_set_gdo_values(GDOLine2, GDO_EDGE_RXFilled, GDO_SETTING_RXFilled);
    phy_set_gdo_values(GDOLine0, GDO_EDGE_EndOfPacket, GDO_SETTING_EndOfPacket);
    radioClearInterruptPendingLines();
    radioEnableGDO2Interrupt();
    radioEnableGDO0Interrupt();

    //Start receiving
    Strobe(RF_SRX);

    return true;
}
Example #5
0
		/* 
		 * software wlan led control 
		 */
void softcontrol_wlan_led(void)	// done in watchdog.c for non-micro
					// builds.
{
#if defined(HAVE_MICRO) && !defined(HAVE_ADM5120) && !defined(HAVE_WRK54G)
	int brand;
	int radiostate0 = -1;
	int oldstate0 = -1;
	int radiostate1 = -1;
	int oldstate1 = -1;

#ifdef HAVE_MADWIFI
	int cnt = getdevicecount();
#else
	int cnt = get_wl_instances();
#endif

#ifdef HAVE_MADWIFI
	if (!nvram_match("flash_active", "1")) {
		radiostate0 = get_radiostate("ath0");
		if (cnt == 2)
			radiostate1 = get_radiostate("ath1");
	}
#else
	wl_ioctl(get_wl_instance_name(0), WLC_GET_RADIO, &radiostate0, sizeof(int));
	if (cnt == 2)
		wl_ioctl(get_wl_instance_name(1), WLC_GET_RADIO, &radiostate1, sizeof(int));
#endif

	if (radiostate0 != oldstate0) {
#ifdef HAVE_MADWIFI
		if (radiostate0 == 1)
#else
		if ((radiostate0 & WL_RADIO_SW_DISABLE) == 0)
#endif
			led_control(LED_WLAN0, LED_ON);
		else {
			led_control(LED_WLAN0, LED_OFF);
#ifndef HAVE_MADWIFI
			brand = getRouterBrand();
			/*
			 * Disable wireless will cause diag led blink, so we want to
			 * stop it. 
			 */
			if (brand == ROUTER_WRT54G)
				diag_led(DIAG, STOP_LED);
			/* 
			 * Disable wireless will cause power led off, so we want to
			 * turn it on. 
			 */
			if (brand == ROUTER_WRT54G_V8)
				led_control(LED_POWER, LED_ON);
#endif
		}

		oldstate0 = radiostate0;
	}

	if (radiostate1 != oldstate1) {
#ifdef HAVE_MADWIFI
		if (radiostate1 == 1)
#else
		if ((radiostate1 & WL_RADIO_SW_DISABLE) == 0)
#endif
			led_control(LED_WLAN1, LED_ON);
		else {
			led_control(LED_WLAN1, LED_OFF);
		}

		oldstate1 = radiostate1;
	}
	/* 
	 * end software wlan led control 
	 */
	return;

#endif
}