示例#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
文件: 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);
}
示例#4
0
void
update_channel_win(WINDOW *win)
{
	int l = 2;

	box(win, 0 , 0);
	print_centered(win, 0, 39, " Channel Settings ");

	wattron(win, WHITE);
	for (int b = 0; b < channel_get_num_bands(); b++) {
		const struct band_info* bp = channel_get_band(b);
		int c = channel_get_idx_from_band_idx(b, 0);
		int col = channel_get_chan(c) > 14 ? COL_BAND2 : 2;
		wattron(win, A_BOLD);
		mvwprintw(win, 2, col, "%s: %s",
			col == 2 ? "2.4GHz" : "5GHz",
			channel_width_string(bp->max_chan_width, -1));

		if (bp->streams_rx || bp->streams_tx)
			wprintw(win, " %dx%d", bp->streams_rx, bp->streams_tx);
		wattroff(win, A_BOLD);
		l = 3;
		for (int i = 0; (c = channel_get_idx_from_band_idx(b, i)) != -1; i++) {
			if (c == conf.channel_idx)
				wattron(win, CYAN);
			else
				wattron(win, WHITE);
			mvwprintw(win, l++,
				col,
				"%s", channel_get_string(c));
		}
	}
	wattroff(win, WHITE);

	l = 17;
	wattron(win, A_BOLD);
	mvwprintw(win, l++, 2, "s: [%c] Scan",
		  CHECKED(conf.do_change_channel));
	wattroff(win, A_BOLD);
	mvwprintw(win, l++, 2, "d: Dwell: %d ms   ",
		  conf.channel_time/1000);
	mvwprintw(win, l++, 2, "u: Upper limit: %d  ", conf.channel_max);

	l++;
	wattron(win, A_BOLD);
	mvwprintw(win, l++, 2, "m: Set channel: %d  ",
		channel_get_chan(conf.channel_idx));
	wattroff(win, A_BOLD);
	mvwprintw(win, l++, 2, "1: [%c] 20 (no HT)",
		CHECKED(conf.channel_set_width == CHAN_WIDTH_20_NOHT));
	mvwprintw(win, l++, 2, "2: [%c] HT20",
		CHECKED(conf.channel_set_width == CHAN_WIDTH_20));
	mvwprintw(win, l++, 2, "4: [%c] HT40-",
		CHECKED(conf.channel_set_width == CHAN_WIDTH_40 && !conf.channel_set_ht40plus));
	mvwprintw(win, l++, 2, "5: [%c] HT40+",
		CHECKED(conf.channel_set_width == CHAN_WIDTH_40 && conf.channel_set_ht40plus));
	mvwprintw(win, l++, 2, "8: [%c] VHT80",
		CHECKED(conf.channel_set_width == CHAN_WIDTH_80));
	mvwprintw(win, l++, 2, "6: [%c] VHT160",
		CHECKED(conf.channel_set_width == CHAN_WIDTH_160));

	print_centered(win, CHANNEL_WIN_HEIGHT-1, CHANNEL_WIN_WIDTH,
		       "[ Press key or ENTER ]");
	wrefresh(win);
}