Search in sources :

Example 1 with IwLinkTool

use of org.eclipse.kura.linux.net.util.IwLinkTool in project kura by eclipse.

the class WifiMonitorServiceImpl method getSignalLevel.

@Override
public int getSignalLevel(String interfaceName, String ssid) throws KuraException {
    int rssi = 0;
    InterfaceState wifiState = this.m_interfaceStatuses.get(interfaceName);
    if (wifiState != null && ssid != null) {
        if (wifiState.isUp()) {
            s_logger.trace("getSignalLevel() :: using 'iw dev wlan0 link' command ...");
            // IwLinkTool iwLinkTool = new IwLinkTool(interfaceName);
            Collection<String> supportedWifiOptions = WifiOptions.getSupportedOptions(interfaceName);
            LinkTool linkTool = null;
            if (supportedWifiOptions != null && supportedWifiOptions.size() > 0) {
                if (supportedWifiOptions.contains(WifiOptions.WIFI_MANAGED_DRIVER_NL80211)) {
                    linkTool = new IwLinkTool(interfaceName);
                } else if (supportedWifiOptions.contains(WifiOptions.WIFI_MANAGED_DRIVER_WEXT)) {
                    linkTool = new iwconfigLinkTool(interfaceName);
                }
            }
            if (linkTool != null && linkTool.get()) {
                if (linkTool.isLinkDetected()) {
                    rssi = linkTool.getSignal();
                    s_logger.debug("getSignalLevel() :: rssi={} (using 'iw dev wlan0 link')", rssi);
                }
            }
        }
        if (rssi == 0) {
            s_logger.trace("getSignalLevel() :: using 'iw dev wlan0 scan' command ...");
            IScanTool scanTool = ScanTool.get(interfaceName);
            if (scanTool != null) {
                List<WifiAccessPoint> wifiAccessPoints = scanTool.scan();
                for (WifiAccessPoint wap : wifiAccessPoints) {
                    if (ssid.equals(wap.getSSID())) {
                        if (wap.getStrength() > 0) {
                            rssi = 0 - wap.getStrength();
                            s_logger.debug("getSignalLevel() :: rssi={} (using 'iw dev wlan0 scan')", rssi);
                        }
                        break;
                    }
                }
            }
        }
    }
    return rssi;
}
Also used : WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint) IScanTool(org.eclipse.kura.linux.net.util.IScanTool) IwLinkTool(org.eclipse.kura.linux.net.util.IwLinkTool) org.eclipse.kura.linux.net.util.iwconfigLinkTool(org.eclipse.kura.linux.net.util.iwconfigLinkTool) IwLinkTool(org.eclipse.kura.linux.net.util.IwLinkTool) org.eclipse.kura.linux.net.util.iwconfigLinkTool(org.eclipse.kura.linux.net.util.iwconfigLinkTool) LinkTool(org.eclipse.kura.linux.net.util.LinkTool) WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint)

Aggregations

IScanTool (org.eclipse.kura.linux.net.util.IScanTool)1 IwLinkTool (org.eclipse.kura.linux.net.util.IwLinkTool)1 LinkTool (org.eclipse.kura.linux.net.util.LinkTool)1 org.eclipse.kura.linux.net.util.iwconfigLinkTool (org.eclipse.kura.linux.net.util.iwconfigLinkTool)1 WifiAccessPoint (org.eclipse.kura.net.wifi.WifiAccessPoint)1