use of org.eclipse.kura.linux.net.util.IScanTool 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;
}
use of org.eclipse.kura.linux.net.util.IScanTool in project kura by eclipse.
the class WifiMonitorServiceImpl method isAccessPointAvailable.
private boolean isAccessPointAvailable(String interfaceName, String ssid) throws KuraException {
boolean available = false;
if (ssid != null) {
IScanTool scanTool = ScanTool.get(interfaceName);
if (scanTool != null) {
List<WifiAccessPoint> wifiAccessPoints = scanTool.scan();
for (WifiAccessPoint wap : wifiAccessPoints) {
if (ssid.equals(wap.getSSID())) {
s_logger.trace("isAccessPointAvailable() :: SSID={} is available :: strength={}", ssid, wap.getStrength());
available = Math.abs(wap.getStrength()) > 0;
break;
}
}
}
}
return available;
}
use of org.eclipse.kura.linux.net.util.IScanTool in project kura by eclipse.
the class NetworkServiceImpl method getWifiAccessPoints.
@Override
public List<WifiAccessPoint> getWifiAccessPoints(String wifiInterfaceName) throws KuraException {
List<WifiAccessPoint> wifAccessPoints = null;
IScanTool scanTool = ScanTool.get(wifiInterfaceName);
if (scanTool != null) {
wifAccessPoints = scanTool.scan();
}
return wifAccessPoints;
}
use of org.eclipse.kura.linux.net.util.IScanTool in project kura by eclipse.
the class NetworkAdminServiceImpl method getWifiHotspots.
@Override
public Map<String, WifiHotspotInfo> getWifiHotspots(String ifaceName) throws KuraException {
Map<String, WifiHotspotInfo> mWifiHotspotInfo = new HashMap<String, WifiHotspotInfo>();
WifiMode wifiMode = WifiMode.UNKNOWN;
List<? extends NetInterfaceConfig<? extends NetInterfaceAddressConfig>> netInterfaceConfigs = getNetworkInterfaceConfigs();
for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig : netInterfaceConfigs) {
if (netInterfaceConfig.getName().equals(ifaceName)) {
List<? extends NetInterfaceAddressConfig> netInterfaceAddresses = netInterfaceConfig.getNetInterfaceAddresses();
if (netInterfaceAddresses != null) {
for (NetInterfaceAddressConfig netInterfaceAddress : netInterfaceAddresses) {
if (netInterfaceAddress instanceof WifiInterfaceAddressConfig) {
wifiMode = ((WifiInterfaceAddressConfig) netInterfaceAddress).getMode();
}
}
}
break;
}
}
try {
if (wifiMode == WifiMode.MASTER) {
reloadKernelModule(ifaceName, WifiMode.INFRA);
WpaSupplicantConfigWriter wpaSupplicantConfigWriter = WpaSupplicantConfigWriter.getInstance();
wpaSupplicantConfigWriter.generateTempWpaSupplicantConf();
s_logger.debug("getWifiHotspots() :: Starting temporary instance of wpa_supplicant");
StringBuilder key = new StringBuilder("net.interface." + ifaceName + ".config.wifi.infra.driver");
String driver = KuranetConfig.getProperty(key.toString());
WpaSupplicantManager.startTemp(ifaceName, WifiMode.INFRA, driver);
wifiModeWait(ifaceName, WifiMode.INFRA, 10);
}
s_logger.info("getWifiHotspots() :: scanning for available access points ...");
IScanTool scanTool = ScanTool.get(ifaceName);
if (scanTool != null) {
List<WifiAccessPoint> wifiAccessPoints = scanTool.scan();
for (WifiAccessPoint wap : wifiAccessPoints) {
if (wap.getSSID() == null || wap.getSSID().length() == 0) {
s_logger.debug("Skipping hidden SSID");
continue;
}
// if (!wap.getSSID().matches(SSID_REGEXP)){
// s_logger.debug("Skipping undesired SSID");
// continue;
// }
s_logger.trace("getWifiHotspots() :: SSID={}", wap.getSSID());
s_logger.trace("getWifiHotspots() :: Signal={}", wap.getStrength());
s_logger.trace("getWifiHotspots() :: Frequency={}", wap.getFrequency());
byte[] baMacAddress = wap.getHardwareAddress();
StringBuffer sbMacAddress = new StringBuffer();
for (int i = 0; i < baMacAddress.length; i++) {
sbMacAddress.append(String.format("%02x", baMacAddress[i] & 0x0ff).toUpperCase());
if (i < baMacAddress.length - 1) {
sbMacAddress.append(':');
}
}
WifiSecurity wifiSecurity = WifiSecurity.NONE;
EnumSet<WifiSecurity> esWpaSecurity = wap.getWpaSecurity();
if (esWpaSecurity != null && !esWpaSecurity.isEmpty()) {
wifiSecurity = WifiSecurity.SECURITY_WPA;
Iterator<WifiSecurity> itWpaSecurity = esWpaSecurity.iterator();
while (itWpaSecurity.hasNext()) {
s_logger.trace("getWifiHotspots() :: WPA Security={}", itWpaSecurity.next());
}
}
EnumSet<WifiSecurity> esRsnSecurity = wap.getRsnSecurity();
if (esRsnSecurity != null && !esRsnSecurity.isEmpty()) {
if (wifiSecurity == WifiSecurity.SECURITY_WPA) {
wifiSecurity = WifiSecurity.SECURITY_WPA_WPA2;
} else {
wifiSecurity = WifiSecurity.SECURITY_WPA2;
}
Iterator<WifiSecurity> itRsnSecurity = esRsnSecurity.iterator();
while (itRsnSecurity.hasNext()) {
s_logger.trace("getWifiHotspots() :: RSN Security={}", itRsnSecurity.next());
}
}
if (wifiSecurity == WifiSecurity.NONE) {
List<String> capabilities = wap.getCapabilities();
if (capabilities != null && !capabilities.isEmpty()) {
for (String capab : capabilities) {
if (capab.equals("Privacy")) {
wifiSecurity = WifiSecurity.SECURITY_WEP;
break;
}
}
}
}
int frequency = (int) wap.getFrequency();
int channel = frequencyMhz2Channel(frequency);
EnumSet<WifiSecurity> pairCiphers = EnumSet.noneOf(WifiSecurity.class);
EnumSet<WifiSecurity> groupCiphers = EnumSet.noneOf(WifiSecurity.class);
if (wifiSecurity == WifiSecurity.SECURITY_WPA_WPA2) {
Iterator<WifiSecurity> itWpaSecurity = esWpaSecurity.iterator();
while (itWpaSecurity.hasNext()) {
WifiSecurity securityEntry = itWpaSecurity.next();
if (securityEntry == WifiSecurity.PAIR_CCMP || securityEntry == WifiSecurity.PAIR_TKIP) {
pairCiphers.add(securityEntry);
} else if (securityEntry == WifiSecurity.GROUP_CCMP || securityEntry == WifiSecurity.GROUP_TKIP) {
groupCiphers.add(securityEntry);
}
}
Iterator<WifiSecurity> itRsnSecurity = esRsnSecurity.iterator();
while (itRsnSecurity.hasNext()) {
WifiSecurity securityEntry = itRsnSecurity.next();
if (securityEntry == WifiSecurity.PAIR_CCMP || securityEntry == WifiSecurity.PAIR_TKIP) {
if (!pairCiphers.contains(securityEntry)) {
pairCiphers.add(securityEntry);
}
} else if (securityEntry == WifiSecurity.GROUP_CCMP || securityEntry == WifiSecurity.GROUP_TKIP) {
if (!groupCiphers.contains(securityEntry)) {
groupCiphers.add(securityEntry);
}
}
}
} else if (wifiSecurity == WifiSecurity.SECURITY_WPA) {
Iterator<WifiSecurity> itWpaSecurity = esWpaSecurity.iterator();
while (itWpaSecurity.hasNext()) {
WifiSecurity securityEntry = itWpaSecurity.next();
if (securityEntry == WifiSecurity.PAIR_CCMP || securityEntry == WifiSecurity.PAIR_TKIP) {
pairCiphers.add(securityEntry);
} else if (securityEntry == WifiSecurity.GROUP_CCMP || securityEntry == WifiSecurity.GROUP_TKIP) {
groupCiphers.add(securityEntry);
}
}
} else if (wifiSecurity == WifiSecurity.SECURITY_WPA2) {
Iterator<WifiSecurity> itRsnSecurity = esRsnSecurity.iterator();
while (itRsnSecurity.hasNext()) {
WifiSecurity securityEntry = itRsnSecurity.next();
if (securityEntry == WifiSecurity.PAIR_CCMP || securityEntry == WifiSecurity.PAIR_TKIP) {
pairCiphers.add(securityEntry);
} else if (securityEntry == WifiSecurity.GROUP_CCMP || securityEntry == WifiSecurity.GROUP_TKIP) {
groupCiphers.add(securityEntry);
}
}
}
WifiHotspotInfo wifiHotspotInfo = new WifiHotspotInfo(wap.getSSID(), sbMacAddress.toString(), 0 - wap.getStrength(), channel, frequency, wifiSecurity, pairCiphers, groupCiphers);
mWifiHotspotInfo.put(wap.getSSID(), wifiHotspotInfo);
}
}
if (wifiMode == WifiMode.MASTER) {
if (WpaSupplicantManager.isTempRunning()) {
s_logger.debug("getWifiHotspots() :: stoping temporary instance of wpa_supplicant");
WpaSupplicantManager.stop(ifaceName);
}
reloadKernelModule(ifaceName, WifiMode.MASTER);
}
} catch (Throwable t) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, t, "scan operation has failed");
}
return mWifiHotspotInfo;
}
Aggregations