use of org.eclipse.kura.core.net.WifiInterfaceAddressImpl in project kura by eclipse.
the class NetworkServiceImpl method getWifiInterfaceAddresses.
private List<WifiInterfaceAddress> getWifiInterfaceAddresses(String interfaceName, boolean isUp) throws KuraException {
List<WifiInterfaceAddress> wifiInterfaceAddresses = new ArrayList<WifiInterfaceAddress>();
if (isUp) {
ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
WifiInterfaceAddressImpl wifiInterfaceAddress = new WifiInterfaceAddressImpl();
wifiInterfaceAddresses.add(wifiInterfaceAddress);
try {
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
String currentNetmask = ifconfig.getInetMask();
if (currentNetmask != null) {
wifiInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
wifiInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
wifiInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
wifiInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
wifiInterfaceAddress.setGateway(conInfo.getGateway());
wifiInterfaceAddress.setDnsServers(conInfo.getDnsServers());
WifiMode wifiMode = LinuxNetworkUtil.getWifiMode(interfaceName);
wifiInterfaceAddress.setBitrate(LinuxNetworkUtil.getWifiBitrate(interfaceName));
wifiInterfaceAddress.setMode(wifiMode);
// TODO - should this only be the AP we are connected to in client mode?
if (wifiMode == WifiMode.INFRA) {
String currentSSID = LinuxNetworkUtil.getSSID(interfaceName);
if (currentSSID != null) {
s_logger.debug("Adding access point SSID: {}", currentSSID);
WifiAccessPointImpl wifiAccessPoint = new WifiAccessPointImpl(currentSSID);
// FIXME: fill in other info
wifiAccessPoint.setMode(WifiMode.INFRA);
List<Long> bitrate = new ArrayList<Long>();
bitrate.add(54000000L);
wifiAccessPoint.setBitrate(bitrate);
wifiAccessPoint.setFrequency(12345);
wifiAccessPoint.setHardwareAddress("20AA4B8A6442".getBytes());
wifiAccessPoint.setRsnSecurity(EnumSet.allOf(WifiSecurity.class));
wifiAccessPoint.setStrength(1234);
wifiAccessPoint.setWpaSecurity(EnumSet.allOf(WifiSecurity.class));
wifiInterfaceAddress.setWifiAccessPoint(wifiAccessPoint);
}
}
} else {
return null;
}
} else {
return null;
}
} catch (UnknownHostException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
return wifiInterfaceAddresses;
}
Aggregations