示例#1
0
static
void tb80211_update_freq(void)
{
    static unsigned int tb80211_freq_cnt;
    unsigned int i;
    gchar *str;
    gint32 oldfreq = 0;

    for (i = 0; i < tb80211_freq_cnt; i++) {
        gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(tb80211_freq_list_box), 0);
    }

    oldfreq = tb80211_current_freq;
    tb80211_current_freq = -1;

    if (!tb80211_current_iface)
        return;

    tb80211_freq_cnt = tb80211_current_iface->frequencies->len;
    for (i = 0; i < tb80211_freq_cnt; i++) {
	int freq;
        freq = g_array_index(tb80211_current_iface->frequencies, int, i);
        str = g_strdup_printf("%d MHz (%d)", freq, ws80211_frequency_to_channel(freq));
        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(tb80211_freq_list_box), str);
        g_free(str);

        if (freq == oldfreq) {
            gtk_combo_box_set_active(GTK_COMBO_BOX(tb80211_freq_list_box), i);
            tb80211_current_freq = oldfreq;
        }
    }
}
void WirelessFrame::on_interfaceComboBox_currentIndexChanged(const QString &cur_iface)
{
    ui->channelComboBox->clear();
    ui->channelTypeComboBox->clear();
    if (cur_iface.isEmpty()) {
        updateWidgets();
        return;
    }

    for (guint i = 0; i < interfaces_->len; i++) {
        struct ws80211_interface *iface = g_array_index(interfaces_, struct ws80211_interface *, i);
        if (cur_iface.compare(iface->ifname) == 0) {
            struct ws80211_iface_info iface_info;
            QString units = " GHz";

            ws80211_get_iface_info(iface->ifname, &iface_info);

            for (guint i = 0; i < iface->frequencies->len; i++) {
                guint32 frequency = g_array_index(iface->frequencies, guint32, i);
                double ghz = frequency / 1000.0;
                QString chan_str = QString("%1 " UTF8_MIDDLE_DOT " %2%3")
                        .arg(ws80211_frequency_to_channel(frequency))
                        .arg(ghz, 0, 'f', 3)
                        .arg(units);
                ui->channelComboBox->addItem(chan_str, frequency);
                if ((int)frequency == iface_info.current_freq) {
                    ui->channelComboBox->setCurrentIndex(ui->channelComboBox->count() - 1);
                }
                units = QString();
            }
            // XXX - Do we need to make a distinction between WS80211_CHAN_NO_HT
            // and WS80211_CHAN_HT20? E.g. is there a driver that won't capture
            // HT frames if you use WS80211_CHAN_NO_HT?
            ui->channelTypeComboBox->addItem("20 MHz", WS80211_CHAN_NO_HT);
            if (iface_info.current_chan_type == WS80211_CHAN_NO_HT || iface_info.current_chan_type == WS80211_CHAN_HT20) {
                ui->channelTypeComboBox->setCurrentIndex(0);
            }
            if (iface->channel_types & (1 << WS80211_CHAN_HT40MINUS)) {
                ui->channelTypeComboBox->addItem("HT 40-", WS80211_CHAN_HT40MINUS);
                if (iface_info.current_chan_type == WS80211_CHAN_HT40MINUS) {
                    ui->channelTypeComboBox->setCurrentIndex(ui->channelTypeComboBox->count() - 1);
                }
            }
            if (iface->channel_types & (1 << WS80211_CHAN_HT40PLUS)) {
                ui->channelTypeComboBox->addItem("HT 40+", WS80211_CHAN_HT40PLUS);
                if (iface_info.current_chan_type == WS80211_CHAN_HT40PLUS) {
                    ui->channelTypeComboBox->setCurrentIndex(ui->channelTypeComboBox->count() - 1);
                }
            }

            if (ws80211_has_fcs_filter()) {
                ui->fcsComboBox->setCurrentIndex(iface_info.current_fcs_validation);
            }
        }
    }
    updateWidgets();
}
示例#3
0
/* Called on freq and type combo box change. */
static void
tb80211_set_channel(void)
{
    gchar *info = NULL;
    int err, selected_chan, new_type, new_freq;

    GtkComboBox *freq_combo = GTK_COMBO_BOX(tb80211_freq_list_box);

    GtkComboBox *type_combo = GTK_COMBO_BOX(tb80211_chan_type_box);

    selected_chan = gtk_combo_box_get_active(freq_combo);
    if (selected_chan < 0)
        return;

    new_freq = g_array_index(tb80211_current_iface->frequencies, int, selected_chan);
    new_type = get_selected_channel_type();

    err = tb80211_do_set_channel(tb80211_current_iface->ifname, new_freq, new_type);
    if (err) {
        info = g_strdup_printf("<b>Failed to set channel: %s</b>", g_strerror(abs(err)));
	/* Try to set back to last working chan */
        err = tb80211_do_set_channel(tb80211_current_iface->ifname, tb80211_current_freq, tb80211_current_type);
        if (err) {
            gtk_combo_box_set_active(freq_combo, -1);
            gtk_combo_box_set_active(type_combo, -1);
            tb80211_current_freq = -1;
            tb80211_current_type = -1;
        }
        else {
            tb80211_update_freq_and_type();
        }
    }
    else {
        info = g_strdup_printf("%s Switched to %d MHz (%d)", tb80211_current_iface->ifname, new_freq, ws80211_frequency_to_channel(new_freq));
        tb80211_current_freq = new_freq;
        tb80211_current_type = new_type;
    }
    tb80211_set_info(info);
    g_free(info);
}