예제 #1
0
static int
net_receive_chan_list(unsigned char *buffer, size_t len)
{
	struct net_chan_list *nc;
	int i;

	if (len < sizeof(struct net_chan_list))
		return 0;

	nc = (struct net_chan_list *)buffer;

	if (len < sizeof(struct net_chan_list) + sizeof(struct net_chan_freq)*(nc->num_channels - 1))
		return 0;

	if (nc->num_channels > MAX_CHANNELS) {
		printlog("ERR: server sent too many channels, truncated");
		conf.num_channels = MAX_CHANNELS;
	} else {
		conf.num_channels = nc->num_channels;
	}

	for (i = 0; i < conf.num_channels; i++) {
		channel_set(i, nc->channel[i].chan, le32toh(nc->channel[i].freq));
		DEBUG("NET recv chan %d %d %d\n", i, nc->channel[i].chan, le32toh(nc->channel[i].freq));
	}
	init_spectrum();
	return sizeof(struct net_chan_list) + sizeof(struct net_chan_freq)*(nc->num_channels - 1);
}
예제 #2
0
t_max_err buffer_set(t_HoaConvolve *x, t_object *attr, long argc, t_atom *argv)
{
	t_buffer *b;
	t_symbol *name;
	t_atom channel[1];
	if(argc && argv && atom_gettype(argv) == A_SYM)
	{
		if(argc > x->f_numberOfHarmonics)
		argc = x->f_numberOfHarmonics;

		name = atom_getsym(argv);
		if(x->f_name != name)
		{
			if ((b = (t_buffer *)(name->s_thing)) && ob_sym(b) == gensym("buffer~"))
			{
				if(x->f_name && x->f_buffer != NULL)
				{
					globalsymbol_dereference((t_object*)x, x->f_name->s_name, "buffer~");
				}
				x->f_name = name;
				x->f_buffer = (t_buffer*)globalsymbol_reference((t_object*)x, x->f_name->s_name, "buffer~");
				
			}
			else
			{
				x->f_buffer = NULL;
				x->f_name= gensym("none");
			}
		}
        atom_setlong(channel, x->f_channel);
        channel_set(x, attr, 2, channel);
	}
	return 0;
}
예제 #3
0
static int script_schan_set(char *chan_name, char *setting, char *value)
{
	channel_t *chan = channel_probe(chan_name, 1);

	if (!chan) return(-1);
	return channel_set(chan, value, setting, 0, NULL);
}
예제 #4
0
static int parse_chans_str(char *chans_str, channelset_t *chans) {
	char *s, *str, *ptrs[256] = { NULL };
	int i, j, n, chan1, chan2;

	channel_zero(chans);

	str = strtok_r(chans_str, ",", &s);
	ptrs[0] = str;
	n = 1;
	while (n < ARRAY_SIZE(ptrs)-1) {
		str = strtok_r(NULL, ",", &s);
		if (str == NULL)
			break;
		ptrs[n++] = str;
	}

	i = 0;
	while (ptrs[i] != NULL) {
		if (ptrs[i][0] == '-')
			return -1;
		n = 0;
		for (j = 0; ptrs[i][j] != '\0'; j++) {
			if (ptrs[i][j] == '-') {
				if (ptrs[i][j+1] == '\0')
					return -1;
				n++;
				if (n > 1)
					return -1;
			} else if (ptrs[i][j] < '0' || ptrs[i][j] > '9')
				return -1;
		}

		str = strtok_r(ptrs[i], "-", &s);
		chan1 = atoi(str);
		if (chan1 == 0)
			return -1;

		if (s[0] == '\0')
			chan2 = chan1;
		else
			chan2 = atoi(s);

		if (chan1 >= 256 || chan2 >= 256)
			return -1;

		if (chan1 > chan2)
			return -1;

		for (j = chan1; j <= chan2; j++)
			channel_set(chans, j);
		i++;
	}

	return 0;
}
예제 #5
0
void cNRF24L01::init(HAL *_hal, dir_t dir, uint8_t addr, uint8_t channel, hal_spi_c *_SPI)
{
    hal = _hal;
	address_width_t addr_width = RF24_ADDR_5_BYTES;
	
    this->channel = channel;
	this->addr_size = addr_width + 2;
	this->addr = BASE_ADDR + addr;
	this->payload_size = 10;
	this->dynamic_payload = 1;
	this->dir = dir;

	/*PWR_.init(&hw_conf.pwr);
	IRQ.init(&hw_conf.irq);
	CE.init(&hw_conf.ce);*/
    hal->gpio->init(SPI1_PINS_RCC, SPI1_PINS_PORT, SPI1_PWR, GPIO_Mode_OUT);
    hal->gpio->init(SPI1_CE_PIN_RCC, SPI1_CE_PIN_PORT, SPI1_CE, GPIO_Mode_OUT);        
    hal->gpio->init(SPI1_PINS_RCC, SPI1_PINS_PORT, SPI1_IRQ, GPIO_Mode_IN);
	init_registers(_SPI);

	// Turn on RF24 - defaults, standby-I mode
    hal->gpio->set(SPI1_PINS_PORT, SPI1_PWR, PIN_HIGH);
    hal->gpio->set(SPI1_CE_PIN_PORT, SPI1_CE, PIN_LOW);
	//PWR_.set(PIN_HIGH);
	//CE.set(PIN_LOW);
	// XXX fixme delay(5, msec_1);
	power_mode_set(RF24_PWR_DOWN, RF24_DIR_TX);

//#define RF_DEBUG_INIT
#ifdef RF_DEBUG_INIT
    volatile uint64_t tmp = 0;
#endif
    // Enable CRC
	CRC_len_set(RF24_CRC_16);
#ifdef RF_DEBUG_INIT
	tmp = config.read();// CONFIG = 0x0C
#endif
	// Answer if msg recieved on P0 addr
    auto_ack_enable(RF24_AUTO_ACK_P0);
#ifdef RF_DEBUG_INIT
    tmp = en_aa.read(); // EN_AA = 0x01
#endif
    // Enable P0 addr for RX
    enable_rx_address(RF24_AUTO_ACK_P0);
#ifdef RF_DEBUG_INIT
    tmp = en_rxaddr.read(); //RX_ADDR = 0x01
#endif
    // Addressing width 4 bytes
    address_width_set(addr_width);
#ifdef RF_DEBUG_INIT
    tmp = setup_aw.read(); //SETUP_AW = 0x02 - 4 bytes
#endif
    // Set retries
    retry_mode_set(RF24_RETR_COUNT_5, RF24_RETR_DELAY_500);
#ifdef RF_DEBUG_INIT
    tmp = setup_retr.read(); //SETUP_RETR = 0x2A
#endif
    // Default channel #2, set 1 !!!
    channel_set((rf_channel_t)this->channel);
#ifdef RF_DEBUG_INIT
    tmp = rf_ch.read(); // 0x02
#endif
    rf_setup_set(RF24_1MBPS, RF24_PA_MAX);
#ifdef RF_DEBUG_INIT
    tmp = rf_setup.read(); // RF_SETUP = 0x07
#endif
    tx_addr_set(addr);
#ifdef RF_DEBUG_INIT
    tx_addr.read((uint8_t*)(&tmp), this->addr_size);
#endif
    rx_addr_set(addr, RF24_AUTO_ACK_P0);
#ifdef RF_DEBUG_INIT
    rx_addr_p0.read((uint8_t*)(&tmp), this->addr_size);
#endif
			payload_size_set(this->payload_size);
#ifdef RF_DEBUG_INIT
    tmp = rx_pw_p0.read();
#endif
    if (!this->dynamic_payload)
    {
    	dyn_pd.write(0);
    	feature.write(0);
    }
		else
    {
        feature_setup();
		}
    // Reset current IRQ status
    irq_status_reset();

    // Flush buffers
    config.flush(RX_BUFF);
    config.flush(TX_BUFF);
}
예제 #6
0
int main(int argc, char *argv[]) {
	struct ap_list apl;
	struct ap_info api;
	struct iw_dev dev;
	struct pollfd pfd[2];
	struct deauth_thread_args ta;
	struct timeval tv1, tv2;
	suseconds_t msec;
	pthread_t deauth_thread;
	pthread_mutex_t chan_mutex, list_mutex, cnc_mutex;
	pthread_cond_t chan_cond;
	channelset_t chans;
	int ret, sigfd, c, n, chan;
	char *ifname, *chans_str;
	sigset_t exit_sig;
	time_t tm;

	if (argc < 2) {
		print_usage(stderr);
		return EXIT_FAILURE;
	}

	/* arguments */
	ifname = argv[argc-1];
	chans_str = NULL;

	while((c = getopt(argc, argv, "c:lh")) != -1) {
		switch (c) {
		case 'c':
			chans_str = optarg;
			break;
		case 'l':
			return print_interfaces();
		case 'h':
			print_usage(stdout);
			return EXIT_SUCCESS;
		case '?':
		default:
			return EXIT_FAILURE;
		}
	}

	if (argv[optind] != ifname) {
		print_usage(stderr);
		return EXIT_FAILURE;
	}

	if (getuid()) {
		fprintf(stderr, "Not root?\n");
		return EXIT_FAILURE;
	}

	/* init channel set */
	if (chans_str == NULL) {
		channel_zero(&chans);
		for (n=1; n<=14; n++)
			channel_set(&chans, n);
	} else {
		if (parse_chans_str(chans_str, &chans) == -1) {
			fprintf(stderr, "Can not parse the channels\n");
			return EXIT_FAILURE;
		}
	}

	/* init access point list */
	init_ap_list(&apl);

	/* init signals */
	sigemptyset(&exit_sig);
	sigaddset(&exit_sig, SIGINT);
	sigaddset(&exit_sig, SIGTERM);

	if (sigprocmask(SIG_BLOCK, &exit_sig, NULL) < 0) {
		err_msg("sigprocmask");
		return EXIT_FAILURE;
	}

	sigfd = signalfd(-1, &exit_sig, 0);
	if (sigfd < 0) {
		err_msg("signalfd");
		return EXIT_FAILURE;
	}

	pfd[0].fd = sigfd;
	pfd[0].revents = 0;
	pfd[0].events = POLLIN;

	/* init device */
	iw_init_dev(&dev);
	strncpy(dev.ifname, ifname, sizeof(dev.ifname)-1);

	if (iw_open(&dev) < 0) {
		print_error();
		goto _errout_no_thread;
	}

	pfd[1].fd = dev.fd_in;
	pfd[1].revents = 0;
	pfd[1].events = POLLIN;

	/* set channel */
	n = 0;
	chan = 0;
	do {
		chan = (chan % CHANNEL_MAX) + 1;
		if (channel_isset(&chans, chan))
			ret = iw_set_channel(&dev, chan);
		else
			ret = -1;
		/* if fails try next channel */
	} while(++n < CHANNEL_MAX && ret < 0);
	if (ret < 0) {
		print_error();
		goto _errout_no_thread;
	}

	/* start deauth thread */
	ta.stop = 0;
	ta.apl = &apl;
	ta.dev = &dev;
	pthread_mutex_init(&chan_mutex, NULL);
	ta.chan_mutex = &chan_mutex;
	pthread_cond_init(&chan_cond, NULL);
	ta.chan_cond = &chan_cond;
	pthread_mutex_init(&list_mutex, NULL);
	ta.list_mutex = &list_mutex;
	ta.chan_changed = 1;
	pthread_mutex_init(&cnc_mutex, NULL);
	ta.cnc_mutex = &cnc_mutex;
	ta.chan_need_change = 0;

	if (pthread_create(&deauth_thread, NULL, deauth_thread_func, &ta) < 0) {
		err_msg("pthread_create");
		goto _errout_no_thread;
	}

	clear_scr();
	update_scr(&apl, &dev);
	tm = time(NULL);
	gettimeofday(&tv1, NULL);

	while (!ta.stop) {
		if (poll(pfd, 2, 0) < 0) {
			err_msg("poll");
			goto _errout;
		}

		if (pfd[0].revents & POLLIN) /* got SIGTERM or SIGINT */
			break;

		if (pfd[1].revents & POLLIN) {
			ret = read_ap_info(&dev, &api);
			if (ret < 0 && ret != ERRNODATA) { /* error */
				print_error();
				goto _errout;
			} else if (ret == 0 && channel_isset(&chans, api.chan)) { /* got infos */
				pthread_mutex_lock(&list_mutex);
				if (add_or_update_ap(&apl, &api) < 0) {
					pthread_mutex_unlock(&list_mutex);
					print_error();
					goto _errout;
				}
				pthread_mutex_unlock(&list_mutex);
			}
		}

		gettimeofday(&tv2, NULL);
		if (tv2.tv_usec > tv1.tv_usec)
			msec = tv2.tv_usec - tv1.tv_usec;
		else
			msec = tv1.tv_usec - tv2.tv_usec;

		/* update screen every 0.5 second */
		if (msec >= 500000) {
			pthread_mutex_lock(&list_mutex);
			update_scr(&apl, &dev);
			pthread_mutex_unlock(&list_mutex);
			gettimeofday(&tv1, NULL);
		}

		/* change channel at least every 1 second */
		if (time(NULL) - tm >= 1) {
			if (!ta.chan_changed) {
				pthread_mutex_lock(&cnc_mutex);
				ta.chan_need_change = 0;
				pthread_mutex_unlock(&cnc_mutex);
				pthread_mutex_lock(&chan_mutex);
				n = 0;
				do {
					chan = (chan % CHANNEL_MAX) + 1;
					if (channel_isset(&chans, chan))
						ret = iw_set_channel(&dev, chan);
					else
						ret = -1;
					/* if fails try next channel */
				} while(++n < CHANNEL_MAX && ret < 0);
				/* if all channels failed */
				if (ret < 0) {
					print_error();
					goto _errout;
				}
				tm = time(NULL);
				ta.chan_changed = 1;
				pthread_cond_signal(&chan_cond);
				pthread_mutex_unlock(&chan_mutex);
			} else {
				pthread_mutex_lock(&cnc_mutex);
				ta.chan_need_change = 1;
				pthread_mutex_unlock(&cnc_mutex);
			}
		}
	}

	/* we got an error from deauth thread */
	if (ta.stop == 2)
		goto _errout;

	printf("\nExiting..\n");
	ta.stop = 1;
	pthread_mutex_unlock(&list_mutex);
	pthread_cond_broadcast(&chan_cond);
	pthread_mutex_unlock(&chan_mutex);
	pthread_join(deauth_thread, NULL);
	iw_close(&dev);
	free_ap_list(&apl);
	return EXIT_SUCCESS;
_errout:
	ta.stop = 1;
	pthread_mutex_unlock(&list_mutex);
	pthread_cond_broadcast(&chan_cond);
	pthread_mutex_unlock(&chan_mutex);
	pthread_join(deauth_thread, NULL);
_errout_no_thread:
	iw_close(&dev);
	free_ap_list(&apl);
	return EXIT_FAILURE;
}