예제 #1
0
int SoftapController::stopSoftap() {

    if (!mHostapdStarted) {
        LOGE("Softap is stopped");
        return 0;
    }

    stopHostapd();
    switchInterface(false);
    release_wake_lock(AP_WAKE_LOCK);
    return 0;
}
void RKStandardComponentWizard::prev () {
	RK_TRACE (PLUGIN);

	if (enslaved) {
		if (stack->havePage (false)) {
			stack->movePage (false);
			updateState ();
		} else {
			cancel ();
		}
	} else {
		if (stack->havePage (false)) {
			stack->movePage (false);
			updateState ();
		} else if (is_switchable) {
			switchInterface ();
		} else {
			RK_ASSERT (false);
		}
	}
}
void RKStandardComponentGUI::createDialog (bool switchable) {
	RK_TRACE (PLUGIN);

	QVBoxLayout *main_vbox = new QVBoxLayout (this);
	main_vbox->setContentsMargins (0, 0, 0, 0);
	QWidget *upper_widget = new QWidget (this);
	
	QHBoxLayout *hbox = new QHBoxLayout (upper_widget);

	// build standard elements
	main_widget = new KVBox (upper_widget);
	hbox->addWidget (main_widget);

	// lines
	QFrame *line = new QFrame (upper_widget);
	line->setFrameShape (QFrame::VLine);
	line->setFrameShadow (QFrame::Plain);	
	hbox->addWidget (line);

	// buttons
	QVBoxLayout* vbox = new QVBoxLayout ();
	hbox->addLayout (vbox);
	vbox->setContentsMargins (0, 0, 0, 0);
	vbox->setSpacing (RKGlobals::spacingHint ());
	ok_button = new QPushButton (i18n ("Submit"), upper_widget);
	connect (ok_button, SIGNAL (clicked ()), this, SLOT (ok ()));
	vbox->addWidget (ok_button);
	if (enslaved) ok_button->hide ();

	cancel_button = new QPushButton (i18n ("Close"), upper_widget);
	connect (cancel_button, SIGNAL (clicked ()), this, SLOT (cancel ()));
	vbox->addWidget (cancel_button);
	auto_close_box = new QCheckBox (i18n ("Auto close"), upper_widget);
	auto_close_box->setChecked (true);
	vbox->addWidget (auto_close_box);
	if (enslaved) auto_close_box->hide ();
	vbox->addStretch (1);
	
	help_button = new QPushButton (i18n ("Help"), upper_widget);
	help_button->setEnabled (component->haveHelp ());
	connect (help_button, SIGNAL (clicked ()), this, SLOT (help ()));
	vbox->addWidget (help_button);
	
	if (switchable && (!enslaved)) {
		switch_button = new QPushButton (i18n ("Use Wizard"), upper_widget);
		connect (switch_button, SIGNAL (clicked ()), this, SLOT (switchInterface ()));
		vbox->addWidget (switch_button);
	}
	vbox->addStretch (2);
	
	toggle_code_button = new QPushButton (i18n ("Code"), upper_widget);
	toggle_code_button->setCheckable (true);
	connect (toggle_code_button, SIGNAL (clicked ()), this, SLOT (toggleCode ()));
	vbox->addWidget (toggle_code_button);
	if (enslaved) toggle_code_button->hide ();
	
	// code display
	code_display = new RKCommandEditorWindow (this, true);
	code_display->setMinimumHeight (RKSettingsModulePlugins::defaultCodeHeight ());
	code_display->hide ();

	main_vbox->addWidget (upper_widget);
	main_vbox->addWidget (code_display);

	if (!enslaved && RKSettingsModulePlugins::showCodeByDefault ()) {
		toggle_code_button->setChecked (true);	// will trigger showing the code along with the dialog
	}
}
예제 #4
0
/*
 * Arguments:
 *      argv[2] - wlan interface
 *      argv[3] - softap interface
 *      argv[4] - SSID
 *	argv[5] - Security
 *	argv[6] - Key
 *	argv[7] - Channel
 *	argv[8] - Preamble
 *	argv[9] - Max SCB
 */
int SoftapController::setSoftap(int argc, char *argv[]) {
    int ret = 0;
    char buf[1024];
    int sta_chan, is_g_mode;


    LOGD("%s - %s - %s - %s - %s - %s",argv[2],argv[3],argv[4],argv[5],argv[6],argv[7]);

    if (argc < 4) {
        LOGE("Softap set - missing arguments");
        return -1;
    }

    FILE* fp = fopen(HOSTAPD_CONF_TEMPLATE_FILE, "r");
    if (!fp) {
       LOGE("Softap set - hostapd template file read failed");
       return -1;
    }

    FILE* fp2 = fopen(HOSTAPD_CONF_FILE, "w");
    if (!fp2) {
       LOGE("Softap set - hostapd.conf file read failed");
       fclose(fp);
       return -1;
    }
    while (fgets(buf, sizeof(buf), fp)) {
        if((strncmp(buf, "ssid=",5) == 0) ||
           (strncmp(buf, "wpa=",4) == 0) ||
           (strncmp(buf, "wpa_passphrase=",15) == 0) ||
           (strncmp(buf, "wpa_key_mgmt=",12) == 0) ||
           (strncmp(buf, "wpa_pairwise=",12) == 0) ||
           (strncmp(buf, "rsn_pairwise=",12) == 0) ||
           (strncmp(buf, "interface=",10) == 0)) {
           continue;
        }
        fputs(buf,fp2);
    }

    // Update interface
    sprintf(buf, "interface=%s\n", AP_INTERFACE);
    fputs(buf, fp2);

    // Update SSID
    sprintf(buf, "ssid=%s\n",argv[4]);
    fputs(buf, fp2);

    // Update security
    if(strncmp(argv[5],"wpa2-psk",8) == 0) {
        sprintf(buf, "wpa=2\nwpa_passphrase=%s\nwpa_key_mgmt=WPA-PSK\n"
                  "wpa_pairwise=CCMP\nrsn_pairwise=CCMP\n", argv[6]);
        fputs(buf, fp2);
    }

    if(strncmp(argv[5],"wpa-psk",7) == 0) {
        sprintf(buf, "wpa=1\nwpa_passphrase=%s\nwpa_key_mgmt=WPA-PSK\n"
                  "wpa_pairwise=TKIP\nrsn_pairwise=TKIP\n", argv[6]);
        fputs(buf, fp2);
    }

    // Choose the correct channel - based on the current channel of the STA
    if (getStaChanAndMode(&sta_chan, &is_g_mode) != 0 || sta_chan == 0) {
        /* default to channel 11 on G */
        sta_chan = 11;
        is_g_mode = 1;
    }

    LOGD("AP starting on channel %d g_mode: %d", sta_chan, is_g_mode);
    sprintf(buf, "hw_mode=%s\nchannel=%d\n", is_g_mode ? "g" : "a", sta_chan);
    fputs(buf, fp2);

    fclose(fp);
    fclose(fp2);

    // we take the wakelock here because the stop/start is lengthy
    acquire_wake_lock(PARTIAL_WAKE_LOCK, AP_WAKE_LOCK);

    // switch interface to wlan1
    ret = switchInterface(true);
    if (ret != 0)
        goto fail_switch;

    // restart hostapd to update configuration
    ret = stopHostapd();
    if (ret != 0)
        goto fail;

    ret = startHostapd();
    if (ret != 0)
        goto fail;

    LOGD("hostapd set - Ok");
    return 0;

fail:
    switchInterface(false);
fail_switch:
    release_wake_lock(AP_WAKE_LOCK);
    LOGD("hostapd set - failed. AP is off.");

    return ret;
}