Search in sources :

Example 1 with WpaSupplicant

use of org.eclipse.kura.linux.net.wifi.WpaSupplicant in project kura by eclipse.

the class NetworkAdminServiceImpl method verifyWifiCredentials.

@Override
public boolean verifyWifiCredentials(String ifaceName, WifiConfig wifiConfig, int tout) {
    boolean ret = false;
    boolean restartSupplicant = false;
    WpaSupplicantConfigWriter wpaSupplicantConfigWriter = WpaSupplicantConfigWriter.getInstance();
    try {
        wpaSupplicantConfigWriter.generateTempWpaSupplicantConf(wifiConfig, ifaceName);
        if (WpaSupplicantManager.isRunning(ifaceName)) {
            s_logger.debug("verifyWifiCredentials() :: stoping wpa_supplicant");
            WpaSupplicantManager.stop(ifaceName);
            restartSupplicant = true;
        }
        s_logger.debug("verifyWifiCredentials() :: Restarting temporary instance of wpa_supplicant");
        WpaSupplicantManager.startTemp(ifaceName, WifiMode.INFRA, wifiConfig.getDriver());
        wifiModeWait(ifaceName, WifiMode.INFRA, 10);
        ret = isWifiConnectionCompleted(ifaceName, tout);
        if (WpaSupplicantManager.isTempRunning()) {
            s_logger.debug("verifyWifiCredentials() :: stopping temporary instance of wpa_supplicant");
            WpaSupplicantManager.stop(ifaceName);
        }
    } catch (KuraException e) {
        s_logger.warn("Exception while managing the temporary instance of the Wpa supplicant.", e);
    }
    if (restartSupplicant) {
        try {
            s_logger.debug("verifyWifiCredentials() :: Restarting wpa_supplicant");
            WpaSupplicant wpaSupplicant = WpaSupplicant.getWpaSupplicant(ifaceName);
            if (wpaSupplicant != null) {
                WpaSupplicantManager.start(ifaceName, wpaSupplicant.getMode(), wpaSupplicant.getDriver());
                if (isWifiConnectionCompleted(ifaceName, tout)) {
                    renewDhcpLease(ifaceName);
                }
            }
        } catch (KuraException e) {
            s_logger.warn("Exception while trying to restart the Wpa supplicant.", e);
        }
    }
    return ret;
}
Also used : WpaSupplicantConfigWriter(org.eclipse.kura.net.admin.visitor.linux.WpaSupplicantConfigWriter) KuraException(org.eclipse.kura.KuraException) WpaSupplicant(org.eclipse.kura.linux.net.wifi.WpaSupplicant)

Example 2 with WpaSupplicant

use of org.eclipse.kura.linux.net.wifi.WpaSupplicant in project kura by eclipse.

the class GenericNetworkInterface method setWifiClientConfig.

/**
 * Populate a WifiConfigIP4 object using the wpa_supplicant config
 *
 * @param ifaceName
 *            - interface name as {@link String}
 * @param wifiConfig
 *            - WiFi configuration as {@link WifiConfig}
 * @param wifiMode
 *            - WiFi mode as {@link wifiMode}
 * @throws KuraException
 */
private static void setWifiClientConfig(String ifaceName, WifiConfig wifiConfig, WifiMode wifiMode) throws KuraException {
    WpaSupplicant supplicant = WpaSupplicant.getWpaSupplicant(ifaceName);
    if (supplicant != null) {
        wifiConfig.setMode(supplicant.getMode());
        wifiConfig.setSSID(supplicant.getSSID());
        wifiConfig.setSecurity(supplicant.getWifiSecurity());
        wifiConfig.setPasskey(supplicant.getPassword());
        wifiConfig.setPairwiseCiphers(supplicant.getPairwiseCiphers());
        wifiConfig.setGroupCiphers(supplicant.getGroupCiphers());
        wifiConfig.setChannels(supplicant.getChannels());
        wifiConfig.setBgscan(supplicant.getBgscan());
    }
}
Also used : WpaSupplicant(org.eclipse.kura.linux.net.wifi.WpaSupplicant)

Aggregations

WpaSupplicant (org.eclipse.kura.linux.net.wifi.WpaSupplicant)2 KuraException (org.eclipse.kura.KuraException)1 WpaSupplicantConfigWriter (org.eclipse.kura.net.admin.visitor.linux.WpaSupplicantConfigWriter)1