use of org.eclipse.kura.linux.net.util.LinkTool 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;
}
Aggregations