예제 #1
0
파일: channel.c 프로젝트: JiantaoFu/horst
bool
channel_init(void) {
	/* get available channels */
	ifctrl_iwget_freqlist(conf.if_phy, &channels);
	conf.channel_initialized = 1;

	printf("Got %d Bands, %d Channels:\n", channels.num_bands, channels.num_channels);
	for (int i = 0; i < channels.num_channels && i < MAX_CHANNELS; i++)
		printf("%s\n", channel_get_string(i));

	if (conf.channel_set_num > 0) {
		/* configured values */
		int ini_idx = channel_find_index_from_chan(conf.channel_set_num);
		if (!channel_change(ini_idx, conf.channel_set_width, conf.channel_set_ht40plus))
			return false;
	} else {
		conf.channel_idx = channel_find_index_from_freq(conf.if_freq);
		conf.channel_set_num = channel_get_chan(conf.channel_idx);
		if (conf.channel_idx < 0)
			return true; // not failure

		/* try to set max width */
		struct band_info b = channel_get_band_from_idx(conf.channel_idx);
		if (conf.channel_width != b.max_chan_width) {
			printlog("Try to set max channel width %s",
				channel_width_string(b.max_chan_width, -1));
			// try both HT40+ and HT40- if necessary
			if (!channel_change(conf.channel_idx, b.max_chan_width, true) &&
			    !channel_change(conf.channel_idx, b.max_chan_width, false))
				return false;
		}
	}
	return true;
}
예제 #2
0
파일: channel.c 프로젝트: JiantaoFu/horst
bool
channel_auto_change(void)
{
	int new_idx;
	bool ret = true;
	int start_idx;

	if (conf.channel_idx == -1)
		return false; /* The current channel is still unknown for some
			   * reason (mac80211 bug, busy physical interface,
			   * etc.), it will be fixed when the first packet
			   * arrives, see fixup_packet_channel().
			   *
			   * Without this return, horst would busy-loop forever
			   * (making the ui totally unresponsive) in the channel
			   * changing code below because start_idx would be -1
			   * as well. Short-circuit exiting here is quite
			   * logical though: it does not make any sense to scan
			   * channels as long as the channel module is not
			   * initialized properly. */

	if (channel_get_remaining_dwell_time() > 0)
		return false; /* too early */

	if (conf.do_change_channel) {
		start_idx = new_idx = conf.channel_idx;
		do {
			enum chan_width max_width = channel_get_band_from_idx(new_idx).max_chan_width;
			/*
			 * For HT40 we visit the same channel twice, once with HT40+
			 * and once with HT40-. This is necessary to see the HT40+/-
			 * data packets
			 */
			if (max_width == CHAN_WIDTH_40) {
				if (conf.channel_ht40plus)
					new_idx++;
				conf.channel_ht40plus = !conf.channel_ht40plus; // toggle
			} else {
				new_idx++;
			}

			if (new_idx >= channels.num_channels ||
			    new_idx >= MAX_CHANNELS ||
			    (conf.channel_max &&
			     channel_get_chan(new_idx) > conf.channel_max))
				new_idx = 0;

			ret = channel_change(new_idx, max_width, conf.channel_ht40plus);

		/* try setting different channels in case we get errors only
		 * on some channels (e.g. ipw2200 reports channel 14 but cannot
		 * be set to use it). stop if we tried all channels */
		} while (ret != 1 && new_idx != start_idx);
	}

	return ret;
}
예제 #3
0
int
channel_input(WINDOW *win, int c)
{
	char buf[6];
	int x;

	switch (c) {
	case 'a': case 'A':
		conf.do_change_channel = conf.do_change_channel ? 0 : 1;
		break;

	case 'd': case 'D':
		echo();
		curs_set(1);
		mvwgetnstr(win, 3, 25, buf, 6);
		curs_set(0);
		noecho();
		sscanf(buf, "%d", &x);
		conf.channel_time = x*1000;
		break;

	case 'u': case 'U':
		echo();
		curs_set(1);
		mvwgetnstr(win, 4, 26, buf, 6);
		curs_set(0);
		noecho();
		sscanf(buf, "%d", &x);
		conf.channel_max = x;
		break;

	case 'm': case 'M':
		conf.do_change_channel = 0;
		echo();
		curs_set(1);
		mvwgetnstr(win, 6, 30, buf, 2);
		curs_set(0);
		noecho();
		sscanf(buf, "%d", &x);
		x = channel_find_index_from_chan(x);
		if (x >= 0) {
			if (!conf.serveraddr)
				channel_change(x);
			else
				conf.channel_idx = x;
		}
		break;

	default:
		return 0; /* didn't handle input */
	}

	net_send_channel_config();

	update_channel_win(win);
	return 1;
}
예제 #4
0
bool
channel_init(void) {
	/* get available channels */
	ifctrl_iwget_freqlist(conf.if_phy, channels);
	conf.channel_idx = channel_find_index_from_freq(conf.if_freq);

	if (conf.channel_num_initial > 0) {
	    if (!channel_change(channel_find_index_from_chan(conf.channel_num_initial)))
	        return false;
	} else {
	    conf.channel_num_initial = channel_get_chan_from_idx(conf.channel_idx);
	}
	conf.channel_initialized = 1;
	return true;
}
예제 #5
0
bool
channel_auto_change(void)
{
	int new_idx;
	bool ret = true;
	int start_idx;

	if (conf.channel_idx == -1)
		return false; /* The current channel is still unknown for some
			   * reason (mac80211 bug, busy physical interface,
			   * etc.), it will be fixed when the first packet
			   * arrives, see fixup_packet_channel().
			   *
			   * Without this return, horst would busy-loop forever
			   * (making the ui totally unresponsive) in the channel
			   * changing code below because start_idx would be -1
			   * as well. Short-circuit exiting here is quite
			   * logical though: it does not make any sense to scan
			   * channels as long as the channel module is not
			   * initialized properly. */

	if (channel_get_remaining_dwell_time() > 0)
		return false; /* too early */

	if (conf.do_change_channel) {
		start_idx = new_idx = conf.channel_idx;
		do {
			new_idx = new_idx + 1;
			if (new_idx >= conf.num_channels ||
			    new_idx >= MAX_CHANNELS ||
			    (conf.channel_max &&
			     channel_get_chan_from_idx(new_idx) > conf.channel_max))
				new_idx = 0;

			ret = channel_change(new_idx);

		/* try setting different channels in case we get errors only
		 * on some channels (e.g. ipw2200 reports channel 14 but cannot
		 * be set to use it). stop if we tried all channels */
		} while (ret != 1 && new_idx != start_idx);
	}

	return ret;
}
예제 #6
0
파일: network.c 프로젝트: latelee/horst
static int net_receive_conf_chan(unsigned char *buffer, size_t len)
{
	struct net_conf_chan *nc;

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

	nc = (struct net_conf_chan *)buffer;
	conf.do_change_channel = nc->do_change;
	conf.channel_max = nc->upper;
	conf.channel_time = le32toh(nc->dwell_time);

	enum chan_width width = nc->width_ht40p & ~NET_WIDTH_HT40PLUS;
	bool ht40p = !!(nc->width_ht40p & NET_WIDTH_HT40PLUS);

	if (nc->channel != conf.channel_idx ||
	    width != conf.channel_width ||
	    ht40p != conf.channel_ht40plus) { /* something changed */
		if (cli_fd > -1) { /* server */
			if (!channel_change(nc->channel, width, ht40p)) {
				printlog("Net Channel %d %s is not available/allowed",
					channel_get_chan(nc->channel),
					channel_width_string(width, ht40p));
				net_send_channel_config();
			} else {
				/* success: update UI */
				conf.channel_set_num = channel_get_chan(nc->channel);
				conf.channel_set_width = width;
				conf.channel_set_ht40plus = ht40p;
				update_display(NULL);
			}
		} else { /* client */
			conf.channel_idx = nc->channel;
			conf.channel_width = conf.channel_set_width = width;
			conf.channel_ht40plus = conf.channel_set_ht40plus = ht40p;
			conf.channel_set_num = channel_get_chan(nc->channel);
			update_spectrum_durations();
			update_display(NULL);
		}
	}

	return sizeof(struct net_conf_chan);
}
예제 #7
0
파일: network.c 프로젝트: ocakgun/horst
static int
net_receive_conf_chan(unsigned char *buffer, size_t len)
{
	struct net_conf_chan *nc;

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

	nc = (struct net_conf_chan *)buffer;
	conf.do_change_channel = nc->do_change;
	conf.channel_max = nc->upper;
	conf.channel_time = le32toh(nc->dwell_time);

	if (cli_fd > -1 && nc->channel != conf.channel_idx) /* server */
		channel_change(nc->channel);
	else { /* client */
		conf.channel_idx = nc->channel;
		update_spectrum_durations();
	}

	return sizeof(struct net_conf_chan);
}
예제 #8
0
bool
channel_input(WINDOW *win, int c)
{
	char buf[6];
	int x;

	switch (c) {
	case 's': case 'S':
		conf.do_change_channel = conf.do_change_channel ? 0 : 1;
		break;

	case 'd': case 'D':
		echo();
		curs_set(1);
		mvwgetnstr(win, 18, 12, buf, 6);
		curs_set(0);
		noecho();
		sscanf(buf, "%d", &x);
		conf.channel_time = x*1000;
		break;

	case 'u': case 'U':
		echo();
		curs_set(1);
		mvwgetnstr(win, 19, 18, buf, 6);
		curs_set(0);
		noecho();
		sscanf(buf, "%d", &x);
		conf.channel_max = x;
		break;

	case 'm': case 'M':
		echo();
		curs_set(1);
		mvwgetnstr(win, 21, 18, buf, 3);
		curs_set(0);
		noecho();
		sscanf(buf, "%d", &x);
		int i = channel_find_index_from_chan(x);
		if (i >= 0) {
			if (!conf.serveraddr[0] != '\0') {
				if (!channel_change(i, conf.channel_set_width, conf.channel_set_ht40plus))
					printlog("Channel %d %s is not available/allowed", x,
						channel_width_string(conf.channel_set_width,
									 conf.channel_set_ht40plus));
			} else
				conf.channel_idx = i;
		}
		break;

	case '1':
		conf.channel_set_width = CHAN_WIDTH_20_NOHT;
		break;

	case '2':
		conf.channel_set_width = CHAN_WIDTH_20;
		break;

	case '4':
		conf.channel_set_width = CHAN_WIDTH_40;
		conf.channel_set_ht40plus = false;
		break;

	case '5':
		conf.channel_set_width = CHAN_WIDTH_40;
		conf.channel_set_ht40plus = true;
		break;

	case '8':
		conf.channel_set_width = CHAN_WIDTH_80;
		break;

	case '6':
		conf.channel_set_width = CHAN_WIDTH_160;
		break;

	default:
		return false; /* didn't handle input */
	}

	// TODO: net client has not set channel_width and ht40p yet:
	net_send_channel_config();

	update_channel_win(win);
	return true;
}