use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.
the class HostapdConfigWriter method writeConfig.
private void writeConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig) throws KuraException {
String interfaceName = netInterfaceConfig.getName();
List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
if (netInterfaceAddressConfigs != null && netInterfaceAddressConfigs.size() > 0) {
for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
if (netInterfaceAddressConfig instanceof WifiInterfaceAddressConfigImpl) {
List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
NetInterfaceStatus netInterfaceStatus = NetInterfaceStatus.netIPv4StatusDisabled;
WifiConfig apConfig = null;
String interfaceDriver = null;
if (netConfigs != null) {
for (NetConfig netConfig : netConfigs) {
try {
if (netConfig instanceof WifiConfig) {
if (((WifiConfig) netConfig).getMode() == WifiMode.MASTER) {
s_logger.debug("Found wifiConfig with mode set to master");
interfaceDriver = ((WifiConfig) netConfig).getDriver();
if (interfaceDriver != null) {
s_logger.debug("Writing wifiConfig: {}", netConfig);
apConfig = (WifiConfig) netConfig;
} else {
s_logger.error("Can't generate hostapd config - no driver specified");
}
}
} else if (netConfig instanceof NetConfigIP4) {
netInterfaceStatus = ((NetConfigIP4) netConfig).getStatus();
}
} catch (Exception e) {
s_logger.error("Failed to configure Hostapd");
throw KuraException.internalError(e);
}
}
if (netInterfaceStatus == NetInterfaceStatus.netIPv4StatusDisabled) {
s_logger.info("Network interface status for {} is disabled - not overwriting hostapd configuration file", interfaceName);
return;
}
if (apConfig != null) {
try {
generateHostapdConf(apConfig, interfaceName, interfaceDriver);
} catch (Exception e) {
s_logger.error("Failed to generate hostapd configuration file for {} interface", interfaceName);
throw KuraException.internalError(e);
}
}
}
}
}
}
}
use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.
the class WpaSupplicantConfigReader method getWifiClientConfig.
private static WifiConfig getWifiClientConfig(String ifaceName, WifiMode wifiMode) throws KuraException {
WifiConfig wifiConfig = new WifiConfig();
String ssid = "";
WifiSecurity wifiSecurity = WifiSecurity.NONE;
String password = "";
int[] channels = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
WifiBgscan bgscan = new WifiBgscan("");
WifiCiphers pairwiseCiphers = null;
WifiCiphers groupCiphers = null;
// Get properties from config file
Properties props = parseConfigFile(ifaceName);
if (props == null) {
s_logger.warn("WPA in client mode is not configured");
} else {
ssid = props.getProperty("ssid");
if (ssid == null) {
s_logger.warn("WPA in client mode is not configured");
} else {
s_logger.debug("curent wpa_supplicant.conf: ssid={}", ssid);
// wifi mode
int currentMode = props.getProperty("mode") != null ? Integer.parseInt(props.getProperty("mode")) : WpaSupplicantUtil.MODE_INFRA;
s_logger.debug("current wpa_supplicant.conf: mode={}", currentMode);
switch(wifiMode) {
case INFRA:
String scan_freq = props.getProperty("scan_freq");
if (scan_freq != null) {
s_logger.debug("current wpa_supplicant.conf: scan_freq={}", scan_freq);
String[] saScanFreq = scan_freq.split(" ");
channels = new int[saScanFreq.length];
for (int i = 0; i < channels.length; i++) {
try {
channels[i] = WpaSupplicantUtil.convFrequencyToChannel(Integer.parseInt(saScanFreq[i]));
} catch (NumberFormatException e) {
}
}
}
break;
/*
* case ADHOC:
* channels = new int [1];
* String frequency = props.getProperty("frequency");
* s_logger.debug("current wpa_supplicant.conf: frequency=" + frequency);
* int freq = 2412;
* if (frequency != null) {
* try {
* freq = Integer.parseInt(frequency);
* } catch (NumberFormatException e) {
* }
* }
* channels[0] = WpaSupplicantUtil.convFrequencyToChannel(freq);
* wifiDriver = KuranetConfig.getProperty(adhocDriverKey.toString());
* if(wifiDriver == null) {
* wifiDriver = KuranetConfig.getProperty(infraDriverKey.toString());
* }
* break;
*/
case MASTER:
throw KuraException.internalError("failed to get wpa_supplicant configuration: MASTER mode is invalid");
default:
throw KuraException.internalError("failed to get wpa_supplicant configuration: invalid mode: " + wifiMode);
}
String proto = props.getProperty("proto");
if (proto != null) {
s_logger.debug("current wpa_supplicant.conf: proto={}", proto);
}
String pairwise = props.getProperty("pairwise");
if (pairwise != null) {
s_logger.debug("current wpa_supplicant.conf: pairwise={}", pairwise);
if (pairwise.contains(WifiCiphers.toString(WifiCiphers.CCMP_TKIP))) {
pairwiseCiphers = WifiCiphers.CCMP_TKIP;
} else if (pairwise.contains(WifiCiphers.toString(WifiCiphers.TKIP))) {
pairwiseCiphers = WifiCiphers.TKIP;
} else if (pairwise.contains(WifiCiphers.toString(WifiCiphers.CCMP))) {
pairwiseCiphers = WifiCiphers.CCMP;
}
}
String group = props.getProperty("group");
if (group != null) {
s_logger.debug("current wpa_supplicant.conf: group={}", group);
if (group.contains(WifiCiphers.toString(WifiCiphers.CCMP_TKIP))) {
groupCiphers = WifiCiphers.CCMP_TKIP;
} else if (group.contains(WifiCiphers.toString(WifiCiphers.TKIP))) {
groupCiphers = WifiCiphers.TKIP;
} else if (group.contains(WifiCiphers.toString(WifiCiphers.CCMP))) {
groupCiphers = WifiCiphers.CCMP;
}
}
// security
String keyMgmt = props.getProperty("key_mgmt");
s_logger.debug("current wpa_supplicant.conf: key_mgmt={}", keyMgmt);
if (keyMgmt != null && keyMgmt.equalsIgnoreCase("WPA-PSK")) {
password = props.getProperty("psk");
if (proto != null) {
if (proto.trim().equals("WPA")) {
wifiSecurity = WifiSecurity.SECURITY_WPA;
} else if (proto.trim().equals("RSN")) {
wifiSecurity = WifiSecurity.SECURITY_WPA2;
} else if (proto.trim().equals("WPA RSN")) {
wifiSecurity = WifiSecurity.SECURITY_WPA_WPA2;
}
} else {
wifiSecurity = WifiSecurity.SECURITY_WPA2;
}
} else {
password = props.getProperty("wep_key0");
if (password != null) {
wifiSecurity = WifiSecurity.SECURITY_WEP;
} else {
wifiSecurity = WifiSecurity.SECURITY_NONE;
}
pairwiseCiphers = null;
groupCiphers = null;
}
if (password == null) {
password = "";
}
String sBgscan = props.getProperty("bgscan");
if (sBgscan != null) {
s_logger.debug("current wpa_supplicant.conf: bgscan={}", sBgscan);
bgscan = new WifiBgscan(sBgscan);
}
}
}
// Populate the config
wifiConfig.setMode(wifiMode);
wifiConfig.setSSID(ssid);
wifiConfig.setSecurity(wifiSecurity);
wifiConfig.setPasskey(password);
wifiConfig.setHardwareMode("");
wifiConfig.setPairwiseCiphers(pairwiseCiphers);
wifiConfig.setGroupCiphers(groupCiphers);
wifiConfig.setChannels(channels);
wifiConfig.setBgscan(bgscan);
// Get self-stored properties
boolean pingAP = false;
StringBuilder key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.wifi.infra.pingAccessPoint");
String statusString = KuranetConfig.getProperty(key.toString());
if (statusString != null && !statusString.isEmpty()) {
pingAP = Boolean.parseBoolean(statusString);
}
wifiConfig.setPingAccessPoint(pingAP);
boolean ignoreSSID = false;
key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.wifi.infra.ignoreSSID");
statusString = KuranetConfig.getProperty(key.toString());
if (statusString != null && !statusString.isEmpty()) {
ignoreSSID = Boolean.parseBoolean(statusString);
}
wifiConfig.setIgnoreSSID(ignoreSSID);
StringBuilder infraDriverKey = new StringBuilder("net.interface.").append(ifaceName).append(".config.wifi.infra.driver");
// StringBuilder adhocDriverKey = new
// StringBuilder("net.interface.").append(ifaceName).append(".config.wifi.adhoc.driver");
String wifiDriver = KuranetConfig.getProperty(infraDriverKey.toString());
if (wifiDriver == null || wifiDriver.isEmpty()) {
wifiDriver = "nl80211";
}
wifiConfig.setDriver(wifiDriver);
return wifiConfig;
}
use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.
the class GwtNetworkServiceImpl method privateFindNetInterfaceConfigurations.
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<GwtNetInterfaceConfig> privateFindNetInterfaceConfigurations() throws GwtKuraException {
s_logger.debug("Starting");
List<GwtNetInterfaceConfig> gwtNetConfigs = new ArrayList<GwtNetInterfaceConfig>();
NetworkAdminService nas = null;
try {
nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
} catch (Throwable t) {
s_logger.warn("Exception", t);
return gwtNetConfigs;
}
ModemManagerService modemManagerService = null;
try {
modemManagerService = ServiceLocator.getInstance().getService(ModemManagerService.class);
} catch (Throwable t) {
s_logger.warn("{ModemManagerService} Exception", t);
}
WifiClientMonitorService wifiClientMonitorService = null;
try {
wifiClientMonitorService = ServiceLocator.getInstance().getService(WifiClientMonitorService.class);
} catch (Throwable t) {
s_logger.warn("{WifiClientMonitorService} Exception", t);
}
try {
GwtNetInterfaceConfig gwtNetConfig = null;
for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netIfConfig : nas.getNetworkInterfaceConfigs()) {
s_logger.debug("Getting config for {} with type {}", netIfConfig.getName(), netIfConfig.getType());
s_logger.debug("Interface State: {}", netIfConfig.getState());
if (netIfConfig.getType() == NetInterfaceType.WIFI) {
gwtNetConfig = new GwtWifiNetInterfaceConfig();
} else if (netIfConfig.getType() == NetInterfaceType.MODEM) {
gwtNetConfig = new GwtModemInterfaceConfig();
((GwtModemInterfaceConfig) gwtNetConfig).setModemId(((ModemInterface) netIfConfig).getModemIdentifier());
((GwtModemInterfaceConfig) gwtNetConfig).setManufacturer(((ModemInterface) netIfConfig).getManufacturer());
((GwtModemInterfaceConfig) gwtNetConfig).setModel(((ModemInterface) netIfConfig).getModel());
List<String> technologyList = new ArrayList<String>();
List<ModemTechnologyType> technologyTypes = ((ModemInterface) netIfConfig).getTechnologyTypes();
if (technologyTypes != null) {
for (ModemTechnologyType techType : technologyTypes) {
technologyList.add(techType.name());
}
}
((GwtModemInterfaceConfig) gwtNetConfig).setNetworkTechnology(technologyList);
} else {
gwtNetConfig = new GwtNetInterfaceConfig();
gwtNetConfig.setHwRssi("N/A");
}
gwtNetConfig.setName(netIfConfig.getName());
gwtNetConfig.setHwName(netIfConfig.getName());
if (netIfConfig.getType() != null) {
gwtNetConfig.setHwType(netIfConfig.getType().name());
}
if (netIfConfig.getState() != null) {
gwtNetConfig.setHwState(netIfConfig.getState().name());
}
s_logger.debug("MAC: {}", NetUtil.hardwareAddressToString(netIfConfig.getHardwareAddress()));
gwtNetConfig.setHwAddress(NetUtil.hardwareAddressToString(netIfConfig.getHardwareAddress()));
gwtNetConfig.setHwDriver(netIfConfig.getDriver());
gwtNetConfig.setHwDriverVersion(netIfConfig.getDriverVersion());
gwtNetConfig.setHwFirmware(netIfConfig.getFirmwareVersion());
gwtNetConfig.setHwMTU(netIfConfig.getMTU());
if (netIfConfig.getUsbDevice() != null) {
gwtNetConfig.setHwUsbDevice(netIfConfig.getUsbDevice().getUsbDevicePath());
} else {
gwtNetConfig.setHwUsbDevice("N/A");
}
List<? extends NetInterfaceAddressConfig> addressConfigs = netIfConfig.getNetInterfaceAddresses();
if (addressConfigs != null && !addressConfigs.isEmpty()) {
for (NetInterfaceAddressConfig addressConfig : addressConfigs) {
// current status - not configuration!
if (addressConfig.getAddress() != null) {
s_logger.debug("current address: {}", addressConfig.getAddress().getHostAddress());
}
if (addressConfig.getNetworkPrefixLength() >= 0 && addressConfig.getNetworkPrefixLength() <= 32) {
s_logger.debug("current prefix length: {}", addressConfig.getNetworkPrefixLength());
}
if (addressConfig.getNetmask() != null) {
s_logger.debug("current netmask: {}", addressConfig.getNetmask().getHostAddress());
}
List<NetConfig> netConfigs = addressConfig.getConfigs();
if (netConfigs != null && !netConfigs.isEmpty()) {
boolean isNatEnabled = false;
boolean isDhcpServerEnabled = false;
for (NetConfig netConfig : netConfigs) {
if (netConfig instanceof NetConfigIP4) {
s_logger.debug("Setting up NetConfigIP4 with status {}", ((NetConfigIP4) netConfig).getStatus().toString());
// we are enabled - for LAN or WAN?
if (((NetConfigIP4) netConfig).getStatus() == NetInterfaceStatus.netIPv4StatusEnabledLAN) {
gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusEnabledLAN.name());
} else if (((NetConfigIP4) netConfig).getStatus() == NetInterfaceStatus.netIPv4StatusEnabledWAN) {
gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusEnabledWAN.name());
} else {
gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusDisabled.name());
}
if (((NetConfigIP4) netConfig).isDhcp()) {
gwtNetConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name());
// since DHCP - populate current data
if (addressConfig.getAddress() != null) {
gwtNetConfig.setIpAddress(addressConfig.getAddress().getHostAddress());
} else {
gwtNetConfig.setIpAddress("");
}
if (addressConfig.getNetworkPrefixLength() >= 0 && addressConfig.getNetworkPrefixLength() <= 32) {
gwtNetConfig.setSubnetMask(NetworkUtil.getNetmaskStringForm(addressConfig.getNetworkPrefixLength()));
} else {
if (addressConfig.getNetmask() != null) {
gwtNetConfig.setSubnetMask(addressConfig.getNetmask().getHostAddress());
} else {
gwtNetConfig.setSubnetMask("");
}
}
if (addressConfig.getGateway() != null) {
gwtNetConfig.setGateway(addressConfig.getGateway().getHostAddress());
} else {
gwtNetConfig.setGateway("");
}
// DHCP supplied DNS servers
StringBuffer sb = new StringBuffer();
List<? extends IPAddress> dnsServers = addressConfig.getDnsServers();
if (dnsServers != null && !dnsServers.isEmpty()) {
String sep = "";
for (IPAddress dnsServer : dnsServers) {
sb.append(sep).append(dnsServer.getHostAddress());
sep = "\n";
}
s_logger.debug("DNS Servers: {}", sb);
gwtNetConfig.setReadOnlyDnsServers(sb.toString());
} else {
s_logger.debug("DNS Servers: [empty String]");
gwtNetConfig.setReadOnlyDnsServers("");
}
} else {
gwtNetConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeManual.name());
// TODO - should we throw an error if current state doesn't match configuration?
if (((NetConfigIP4) netConfig).getAddress() != null) {
gwtNetConfig.setIpAddress(((NetConfigIP4) netConfig).getAddress().getHostAddress());
} else {
gwtNetConfig.setIpAddress("");
}
if (((NetConfigIP4) netConfig).getSubnetMask() != null) {
gwtNetConfig.setSubnetMask(((NetConfigIP4) netConfig).getSubnetMask().getHostAddress());
} else {
gwtNetConfig.setSubnetMask("");
}
if (((NetConfigIP4) netConfig).getGateway() != null) {
s_logger.debug("Gateway for {} is: {}", netIfConfig.getName(), ((NetConfigIP4) netConfig).getGateway().getHostAddress());
gwtNetConfig.setGateway(((NetConfigIP4) netConfig).getGateway().getHostAddress());
} else {
gwtNetConfig.setGateway("");
}
}
// Custom DNS servers
StringBuffer sb = new StringBuffer();
List<IP4Address> dnsServers = ((NetConfigIP4) netConfig).getDnsServers();
if (dnsServers != null && !dnsServers.isEmpty()) {
for (IP4Address dnsServer : dnsServers) {
if (!dnsServer.getHostAddress().equals("127.0.0.1")) {
sb.append(' ').append(dnsServer.getHostAddress());
}
}
s_logger.debug("DNS Servers: {}", sb);
gwtNetConfig.setDnsServers(sb.toString().trim());
} else {
s_logger.debug("DNS Servers: [empty String]");
gwtNetConfig.setDnsServers("");
}
// Search domains
sb = new StringBuffer();
List<IP4Address> winsServers = ((NetConfigIP4) netConfig).getWinsServers();
if (winsServers != null && !winsServers.isEmpty()) {
for (IP4Address winServer : winsServers) {
sb.append(winServer.getHostAddress());
sb.append("\n");
}
s_logger.debug("Search Domains: {}", sb);
gwtNetConfig.setSearchDomains(sb.toString());
} else {
s_logger.debug("Search Domains: [empty String]");
gwtNetConfig.setSearchDomains("");
}
}
// config
if (netConfig instanceof WifiConfig) {
s_logger.debug("Setting up WifiConfigIP4");
WifiConfig wifiConfig = (WifiConfig) netConfig;
GwtWifiConfig gwtWifiConfig = new GwtWifiConfig();
// mode
if (wifiConfig.getMode() == WifiMode.MASTER) {
gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name());
// set as the access point config for this interface
((GwtWifiNetInterfaceConfig) gwtNetConfig).setAccessPointWifiConfig(gwtWifiConfig);
} else if (wifiConfig.getMode() == WifiMode.INFRA) {
gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeStation.name());
// set as the station config for this interface
((GwtWifiNetInterfaceConfig) gwtNetConfig).setStationWifiConfig(gwtWifiConfig);
} else if (wifiConfig.getMode() == WifiMode.ADHOC) {
gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAdHoc.name());
// set as the adhoc config for this interface
((GwtWifiNetInterfaceConfig) gwtNetConfig).setAdhocWifiConfig(gwtWifiConfig);
}
// ssid
gwtWifiConfig.setWirelessSsid(wifiConfig.getSSID());
// driver
gwtWifiConfig.setDriver(wifiConfig.getDriver());
// security
if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA) {
gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA.name());
} else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA2) {
gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA2.name());
} else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA_WPA2) {
gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA_WPA2.name());
} else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WEP) {
gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWEP.name());
} else {
gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityNONE.name());
}
if (wifiConfig.getPairwiseCiphers() == WifiCiphers.CCMP_TKIP) {
gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name());
} else if (wifiConfig.getPairwiseCiphers() == WifiCiphers.TKIP) {
gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_TKIP.name());
} else if (wifiConfig.getPairwiseCiphers() == WifiCiphers.CCMP) {
gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_CCMP.name());
}
if (wifiConfig.getGroupCiphers() == WifiCiphers.CCMP_TKIP) {
gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name());
} else if (wifiConfig.getGroupCiphers() == WifiCiphers.TKIP) {
gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_TKIP.name());
} else if (wifiConfig.getGroupCiphers() == WifiCiphers.CCMP) {
gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_CCMP.name());
}
// bgscan
WifiBgscan wifiBgscan = wifiConfig.getBgscan();
if (wifiBgscan != null) {
if (wifiBgscan.getModule() == WifiBgscanModule.NONE) {
gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_NONE.name());
} else if (wifiBgscan.getModule() == WifiBgscanModule.SIMPLE) {
gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_SIMPLE.name());
} else if (wifiBgscan.getModule() == WifiBgscanModule.LEARN) {
gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_LEARN.name());
}
gwtWifiConfig.setBgscanRssiThreshold(wifiBgscan.getRssiThreshold());
gwtWifiConfig.setBgscanShortInterval(wifiBgscan.getShortInterval());
gwtWifiConfig.setBgscanLongInterval(wifiBgscan.getLongInterval());
}
// ping access point?
gwtWifiConfig.setPingAccessPoint(wifiConfig.pingAccessPoint());
// ignore SSID?
gwtWifiConfig.setIgnoreSSID(wifiConfig.ignoreSSID());
// passkey
Password psswd = wifiConfig.getPasskey();
if (psswd != null) {
String password = new String(psswd.getPassword());
gwtWifiConfig.setPassword(password);
}
// channel
int[] channels = wifiConfig.getChannels();
if (channels != null) {
ArrayList<Integer> alChannels = new ArrayList<Integer>();
for (int channel : channels) {
alChannels.add(new Integer(channel));
}
gwtWifiConfig.setChannels(alChannels);
}
// radio mode
GwtWifiRadioMode gwtWifiRadioMode = null;
if (wifiConfig.getRadioMode() != null) {
switch(wifiConfig.getRadioMode()) {
case RADIO_MODE_80211a:
gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeA;
break;
case RADIO_MODE_80211b:
gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeB;
break;
case RADIO_MODE_80211g:
gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeBG;
break;
case RADIO_MODE_80211nHT20:
case RADIO_MODE_80211nHT40above:
case RADIO_MODE_80211nHT40below:
gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeBGN;
break;
default:
break;
}
}
if (gwtWifiRadioMode != null) {
gwtWifiConfig.setRadioMode(gwtWifiRadioMode.name());
}
// set the currently active mode based on the address config
WifiMode activeWirelessMode = ((WifiInterfaceAddressConfig) addressConfig).getMode();
if (activeWirelessMode == WifiMode.MASTER) {
((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name());
gwtNetConfig.setHwRssi("N/A");
} else if (activeWirelessMode == WifiMode.INFRA) {
((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeStation.name());
if (wifiClientMonitorService != null) {
if (wifiConfig.getMode().equals(WifiMode.INFRA)) {
if (gwtNetConfig.getStatus().equals(GwtNetIfStatus.netIPv4StatusDisabled.name())) {
gwtNetConfig.setHwRssi("N/A");
} else {
try {
int rssi = wifiClientMonitorService.getSignalLevel(netIfConfig.getName(), wifiConfig.getSSID());
s_logger.debug("Setting Received Signal Strength to {}", rssi);
gwtNetConfig.setHwRssi(Integer.toString(rssi));
} catch (KuraException e) {
s_logger.warn("Failed", e);
}
}
}
}
} else if (activeWirelessMode == WifiMode.ADHOC) {
((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAdHoc.name());
gwtNetConfig.setHwRssi("N/A");
} else {
((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeDisabled.name());
gwtNetConfig.setHwRssi("N/A");
}
}
if (netConfig instanceof ModemConfig) {
s_logger.debug("Setting up ModemConfig");
ModemConfig modemConfig = (ModemConfig) netConfig;
GwtModemInterfaceConfig gwtModemConfig = (GwtModemInterfaceConfig) gwtNetConfig;
if (modemManagerService != null) {
UsbDevice usbDevice = netIfConfig.getUsbDevice();
String modemServiceId = null;
if (usbDevice != null) {
modemServiceId = netIfConfig.getUsbDevice().getUsbPort();
} else {
Collection<CellularModem> modemServices = modemManagerService.getAllModemServices();
for (CellularModem modemService : modemServices) {
ModemDevice modemDevice = modemService.getModemDevice();
if (modemDevice instanceof SerialModemDevice) {
modemServiceId = modemDevice.getProductName();
break;
}
}
}
if (modemServiceId != null) {
CellularModem cellModemService = modemManagerService.getModemService(modemServiceId);
if (cellModemService != null) {
try {
String imei = cellModemService.getSerialNumber();
s_logger.debug("Setting IMEI/MEID to {}", imei);
gwtModemConfig.setHwSerial(imei);
} catch (KuraException e) {
s_logger.warn("Failed to get IMEI from modem", e);
}
try {
int rssi = cellModemService.getSignalStrength();
s_logger.debug("Setting Received Signal Strength to {}", rssi);
gwtModemConfig.setHwRssi(Integer.toString(rssi));
} catch (KuraException e) {
s_logger.warn("Failed to get Received Signal Strength from modem", e);
}
try {
String sModel = cellModemService.getModel();
((GwtModemInterfaceConfig) gwtNetConfig).setModel(sModel);
} catch (KuraException e) {
s_logger.warn("Failed to get model information from modem", e);
}
try {
boolean gpsSupported = cellModemService.isGpsSupported();
s_logger.debug("Setting GPS supported to {}", gpsSupported);
((GwtModemInterfaceConfig) gwtNetConfig).setGpsSupported(gpsSupported);
} catch (KuraException e) {
s_logger.warn("Failed to get GPS supported from modem", e);
}
}
}
}
// set as DHCP - populate current address
gwtModemConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name());
if (addressConfig.getAddress() != null) {
gwtModemConfig.setIpAddress(addressConfig.getAddress().getHostAddress());
}
if (addressConfig.getNetmask() != null) {
gwtModemConfig.setSubnetMask(addressConfig.getNetmask().getHostAddress());
}
gwtModemConfig.setDialString(modemConfig.getDialString());
AuthType authType = modemConfig.getAuthType();
if (authType == AuthType.AUTO) {
gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthAUTO);
} else if (authType == AuthType.CHAP) {
gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthCHAP);
} else if (authType == AuthType.PAP) {
gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthPAP);
} else {
gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthNONE);
}
gwtModemConfig.setUsername(modemConfig.getUsername());
gwtModemConfig.setPassword(modemConfig.getPassword());
gwtModemConfig.setPppNum(modemConfig.getPppNumber());
gwtModemConfig.setResetTimeout(modemConfig.getResetTimeout());
gwtModemConfig.setPersist(modemConfig.isPersist());
gwtModemConfig.setMaxFail(modemConfig.getMaxFail());
gwtModemConfig.setIdle(modemConfig.getIdle());
gwtModemConfig.setActiveFilter(modemConfig.getActiveFilter());
gwtModemConfig.setLcpEchoInterval(modemConfig.getLcpEchoInterval());
gwtModemConfig.setLcpEchoFailure(modemConfig.getLcpEchoFailure());
gwtModemConfig.setGpsEnabled(modemConfig.isGpsEnabled());
gwtModemConfig.setProfileID(modemConfig.getProfileID());
PdpType pdpType = modemConfig.getPdpType();
if (pdpType == PdpType.IP) {
gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpIP);
} else if (pdpType == PdpType.PPP) {
gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpPPP);
} else if (pdpType == PdpType.IPv6) {
gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpIPv6);
} else {
gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpUnknown);
}
gwtModemConfig.setApn(modemConfig.getApn());
gwtModemConfig.setDataCompression(modemConfig.getDataCompression());
gwtModemConfig.setHeaderCompression(modemConfig.getHeaderCompression());
ModemConnectionStatus connectionStatus = ((ModemInterfaceAddressConfig) addressConfig).getConnectionStatus();
if (connectionStatus == ModemConnectionStatus.DISCONNECTED) {
gwtModemConfig.setHwState(NetInterfaceState.DISCONNECTED.name());
} else if (connectionStatus == ModemConnectionStatus.CONNECTING) {
gwtModemConfig.setHwState(NetInterfaceState.IP_CONFIG.name());
} else if (connectionStatus == ModemConnectionStatus.CONNECTED) {
gwtModemConfig.setHwState(NetInterfaceState.ACTIVATED.name());
} else {
gwtModemConfig.setHwState(NetInterfaceState.UNKNOWN.name());
}
gwtModemConfig.setConnectionType(((ModemInterfaceAddressConfig) addressConfig).getConnectionType().name());
}
if (netConfig instanceof DhcpServerConfigIP4) {
s_logger.debug("Setting up DhcpServerConfigIP4: {} to {}", ((DhcpServerConfigIP4) netConfig).getRangeStart().getHostAddress(), ((DhcpServerConfigIP4) netConfig).getRangeEnd().getHostAddress());
s_logger.debug("Setting up DhcpServerConfigIP4: {}", ((DhcpServerConfigIP4) netConfig).toString());
isDhcpServerEnabled = ((DhcpServerConfigIP4) netConfig).isEnabled();
gwtNetConfig.setRouterDhcpBeginAddress(((DhcpServerConfigIP4) netConfig).getRangeStart().getHostAddress());
gwtNetConfig.setRouterDhcpEndAddress(((DhcpServerConfigIP4) netConfig).getRangeEnd().getHostAddress());
gwtNetConfig.setRouterDhcpSubnetMask(((DhcpServerConfigIP4) netConfig).getSubnetMask().getHostAddress());
gwtNetConfig.setRouterDhcpDefaultLease(((DhcpServerConfigIP4) netConfig).getDefaultLeaseTime());
gwtNetConfig.setRouterDhcpMaxLease(((DhcpServerConfigIP4) netConfig).getMaximumLeaseTime());
gwtNetConfig.setRouterDnsPass(((DhcpServerConfigIP4) netConfig).isPassDns());
}
if (netConfig instanceof FirewallAutoNatConfig) {
s_logger.debug("Setting up FirewallAutoNatConfig");
isNatEnabled = true;
}
// TODO - only dealing with IPv4 right now
}
// set up the DHCP and NAT config
if (isDhcpServerEnabled && isNatEnabled) {
s_logger.debug("setting router mode to DHCP and NAT");
gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterDchpNat.name());
} else if (isDhcpServerEnabled && !isNatEnabled) {
s_logger.debug("setting router mode to DHCP only");
gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterDchp.name());
} else if (!isDhcpServerEnabled && isNatEnabled) {
s_logger.debug("setting router mode to NAT only");
gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterNat.name());
} else {
s_logger.debug("setting router mode to disabled");
gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterOff.name());
}
}
}
}
gwtNetConfigs.add(gwtNetConfig);
}
} catch (Throwable t) {
KuraExceptionHandler.handle(t);
}
s_logger.debug("Returning");
return gwtNetConfigs;
}
use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.
the class GwtNetworkServiceImpl method verifyWifiCredentials.
@Override
public boolean verifyWifiCredentials(GwtXSRFToken xsrfToken, String interfaceName, GwtWifiConfig gwtWifiConfig) throws GwtKuraException {
checkXSRFToken(xsrfToken);
NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
WifiConfig wifiConfig = getWifiConfig(gwtWifiConfig);
return nas.verifyWifiCredentials(interfaceName, wifiConfig, 60);
}
use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.
the class GwtNetworkServiceImpl method getWifiConfig.
private WifiConfig getWifiConfig(GwtWifiConfig gwtWifiConfig) {
WifiConfig wifiConfig = null;
if (gwtWifiConfig != null) {
wifiConfig = new WifiConfig();
String mode = gwtWifiConfig.getWirelessMode();
if (mode != null && mode.equals(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name())) {
wifiConfig.setMode(WifiMode.MASTER);
} else if (mode != null && mode.equals(GwtWifiWirelessMode.netWifiWirelessModeStation.name())) {
wifiConfig.setMode(WifiMode.INFRA);
} else if (mode != null && mode.equals(GwtWifiWirelessMode.netWifiWirelessModeAdHoc.name())) {
wifiConfig.setMode(WifiMode.ADHOC);
} else {
wifiConfig.setMode(WifiMode.UNKNOWN);
}
// ssid
wifiConfig.setSSID(GwtSafeHtmlUtils.htmlUnescape(gwtWifiConfig.getWirelessSsid()));
// driver
wifiConfig.setDriver(gwtWifiConfig.getDriver());
// radio mode
GwtWifiRadioMode radioMode = gwtWifiConfig.getRadioModeEnum();
if (radioMode == GwtWifiRadioMode.netWifiRadioModeA) {
wifiConfig.setRadioMode(WifiRadioMode.RADIO_MODE_80211a);
wifiConfig.setHardwareMode("a");
} else if (radioMode.equals(GwtWifiRadioMode.netWifiRadioModeB)) {
wifiConfig.setRadioMode(WifiRadioMode.RADIO_MODE_80211b);
wifiConfig.setHardwareMode("b");
} else if (radioMode.equals(GwtWifiRadioMode.netWifiRadioModeBG)) {
wifiConfig.setRadioMode(WifiRadioMode.RADIO_MODE_80211g);
wifiConfig.setHardwareMode("g");
} else if (radioMode.equals(GwtWifiRadioMode.netWifiRadioModeBGN)) {
wifiConfig.setRadioMode(WifiRadioMode.RADIO_MODE_80211nHT20);
wifiConfig.setHardwareMode("n");
}
// channel
ArrayList<Integer> alChannels = gwtWifiConfig.getChannels();
if (alChannels != null) {
int[] channels = new int[alChannels.size()];
for (int i = 0; i < channels.length; i++) {
channels[i] = alChannels.get(i).intValue();
}
wifiConfig.setChannels(channels);
}
// security
wifiConfig.setSecurity(WifiSecurity.SECURITY_NONE);
String security = gwtWifiConfig.getSecurity();
if (security != null) {
if (security.equals(GwtWifiSecurity.netWifiSecurityWPA.name())) {
// wifiConfig.setSecurity(WifiSecurity.KEY_MGMT_PSK);
wifiConfig.setSecurity(WifiSecurity.SECURITY_WPA);
} else if (security.equals(GwtWifiSecurity.netWifiSecurityWPA2.name())) {
// wifiConfig.setSecurity(WifiSecurity.KEY_MGMT_PSK);
wifiConfig.setSecurity(WifiSecurity.SECURITY_WPA2);
} else if (security.equals(GwtWifiSecurity.netWifiSecurityWPA_WPA2.name())) {
// wifiConfig.setSecurity(WifiSecurity.KEY_MGMT_PSK);
wifiConfig.setSecurity(WifiSecurity.SECURITY_WPA_WPA2);
} else if (security.equals(GwtWifiSecurity.netWifiSecurityWEP.name())) {
// wifiConfig.setSecurity(WifiSecurity.PAIR_WEP104);
wifiConfig.setSecurity(WifiSecurity.SECURITY_WEP);
}
}
String pairwiseCiphers = gwtWifiConfig.getPairwiseCiphers();
if (pairwiseCiphers != null) {
if (pairwiseCiphers.equals(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name())) {
wifiConfig.setPairwiseCiphers(WifiCiphers.CCMP_TKIP);
} else if (pairwiseCiphers.equals(GwtWifiCiphers.netWifiCiphers_TKIP.name())) {
wifiConfig.setPairwiseCiphers(WifiCiphers.TKIP);
} else if (pairwiseCiphers.equals(GwtWifiCiphers.netWifiCiphers_CCMP.name())) {
wifiConfig.setPairwiseCiphers(WifiCiphers.CCMP);
}
}
String groupCiphers = gwtWifiConfig.getGroupCiphers();
if (groupCiphers != null) {
if (groupCiphers.equals(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name())) {
wifiConfig.setGroupCiphers(WifiCiphers.CCMP_TKIP);
} else if (groupCiphers.equals(GwtWifiCiphers.netWifiCiphers_TKIP.name())) {
wifiConfig.setGroupCiphers(WifiCiphers.TKIP);
} else if (groupCiphers.equals(GwtWifiCiphers.netWifiCiphers_CCMP.name())) {
wifiConfig.setGroupCiphers(WifiCiphers.CCMP);
}
}
// bgscan
String bgscanModule = gwtWifiConfig.getBgscanModule();
if (bgscanModule != null) {
WifiBgscanModule wifiBgscanModule = null;
if (bgscanModule.equals(GwtWifiBgscanModule.netWifiBgscanMode_NONE.name())) {
wifiBgscanModule = WifiBgscanModule.NONE;
} else if (bgscanModule.equals(GwtWifiBgscanModule.netWifiBgscanMode_SIMPLE.name())) {
wifiBgscanModule = WifiBgscanModule.SIMPLE;
} else if (bgscanModule.equals(GwtWifiBgscanModule.netWifiBgscanMode_LEARN.name())) {
wifiBgscanModule = WifiBgscanModule.LEARN;
}
int bgscanRssiThreshold = gwtWifiConfig.getBgscanRssiThreshold();
int bgscanShortInterval = gwtWifiConfig.getBgscanShortInterval();
int bgscanLongInterval = gwtWifiConfig.getBgscanLongInterval();
WifiBgscan wifiBgscan = new WifiBgscan(wifiBgscanModule, bgscanShortInterval, bgscanRssiThreshold, bgscanLongInterval);
wifiConfig.setBgscan(wifiBgscan);
}
// passkey
wifiConfig.setPasskey(gwtWifiConfig.getPassword());
// ping access point?
wifiConfig.setPingAccessPoint(gwtWifiConfig.pingAccessPoint());
// ignore SSID?
wifiConfig.setIgnoreSSID(gwtWifiConfig.ignoreSSID());
// broadcast SSID
wifiConfig.setBroadcast(!gwtWifiConfig.ignoreSSID());
}
return wifiConfig;
}
Aggregations