use of org.eclipse.kura.net.modem.ModemInterfaceAddressConfig in project kura by eclipse.
the class ModemInterfaceAddressConfigImpl method equals.
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ModemInterfaceAddressConfig)) {
return false;
}
ModemInterfaceAddressConfig other = (ModemInterfaceAddressConfig) obj;
if (!compare(getSignalStrength(), other.getSignalStrength())) {
return false;
}
if (!compare(isRoaming(), other.isRoaming())) {
return false;
}
if (!compare(getConnectionStatus(), other.getConnectionStatus())) {
return false;
}
if (getBytesTransmitted() != other.getBytesTransmitted()) {
return false;
}
if (getBytesReceived() != other.getBytesReceived()) {
return false;
}
if (!compare(getConnectionType(), other.getConnectionType())) {
return false;
}
List<NetConfig> thisNetConfigs = getConfigs();
List<NetConfig> otherNetConfigs = other.getConfigs();
if (thisNetConfigs.size() != otherNetConfigs.size()) {
return false;
}
if (!thisNetConfigs.containsAll(otherNetConfigs)) {
return false;
}
if (!otherNetConfigs.containsAll(thisNetConfigs)) {
return false;
}
return true;
}
use of org.eclipse.kura.net.modem.ModemInterfaceAddressConfig 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.modem.ModemInterfaceAddressConfig in project kura by eclipse.
the class GenericNetworkInterface method getCurrentConfig.
protected static NetInterfaceConfig<?> getCurrentConfig(String interfaceName, NetInterfaceType type, NetInterfaceStatus status, boolean dhcpServerEnabled, boolean passDns, Properties kuraProps) throws KuraException {
try {
NetInterfaceConfig<?> netInterfaceConfig = null;
boolean autoConnect = false;
int mtu = -1;
boolean dhcp = false;
IP4Address address = null;
String ipAddress = null;
String prefixString = null;
String netmask = null;
String gateway = null;
boolean interfaceEnabled = false;
if (kuraProps != null) {
String onBoot = kuraProps.getProperty("ONBOOT");
if ("yes".equals(onBoot)) {
autoConnect = true;
// we are enabled - just not sure if for LAN or WAN
if (status == NetInterfaceStatus.netIPv4StatusUnknown) {
interfaceEnabled = true;
}
} else {
autoConnect = false;
}
// override MTU with what is in config if it is present
String stringMtu = kuraProps.getProperty("MTU");
if (stringMtu == null) {
try {
mtu = LinuxNetworkUtil.getCurrentMtu(interfaceName);
} catch (KuraException e) {
// just assume ???
if (interfaceName.equals("lo")) {
mtu = 16436;
} else {
mtu = 1500;
}
}
} else {
mtu = Short.parseShort(stringMtu);
}
// get the bootproto
String bootproto = kuraProps.getProperty("BOOTPROTO");
if (bootproto == null) {
bootproto = "static";
}
// get the defroute
String defroute = kuraProps.getProperty("DEFROUTE");
if (defroute == null) {
defroute = "no";
}
if (interfaceEnabled) {
if (defroute.equals("yes")) {
status = NetInterfaceStatus.netIPv4StatusEnabledWAN;
} else {
status = NetInterfaceStatus.netIPv4StatusEnabledLAN;
}
}
// check for dhcp or static configuration
try {
ipAddress = kuraProps.getProperty("IPADDR");
prefixString = kuraProps.getProperty("PREFIX");
netmask = kuraProps.getProperty("NETMASK");
kuraProps.getProperty("BROADCAST");
try {
gateway = kuraProps.getProperty("GATEWAY");
s_logger.debug("got gateway for {}: {}", interfaceName, gateway);
} catch (Exception e) {
s_logger.warn("missing gateway stanza for " + interfaceName);
}
if (bootproto.equals("dhcp")) {
s_logger.debug("currently set for DHCP");
dhcp = true;
ipAddress = null;
netmask = null;
} else {
s_logger.debug("currently set for static address");
dhcp = false;
}
} catch (Exception e) {
e.printStackTrace();
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "malformatted config file: " + NET_CONFIGURATION_DIRECTORY + "ifcfg-" + interfaceName);
}
if (ipAddress != null && !ipAddress.isEmpty()) {
address = (IP4Address) IPAddress.parseHostAddress(ipAddress);
}
// make sure at least prefix or netmask is present if static
if (!dhcp && prefixString == null && netmask == null) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "malformatted config file: " + NET_CONFIGURATION_DIRECTORY + "ifcfg-" + interfaceName + " must contain NETMASK and/or PREFIX");
}
}
ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
LinuxDns dnsService = LinuxDns.getInstance();
// note - we only add the fields we need/care about from a configuration standpoint
if (type == NetInterfaceType.LOOPBACK) {
s_logger.debug("Adding a Loopback interface");
netInterfaceConfig = new LoopbackInterfaceConfigImpl(interfaceName);
((LoopbackInterfaceImpl<?>) netInterfaceConfig).setMTU(mtu);
// loopback autoConnect
((LoopbackInterfaceImpl<?>) netInterfaceConfig).setAutoConnect(true);
// should always be true?
((LoopbackInterfaceImpl<?>) netInterfaceConfig).setLoopback(true);
List<NetInterfaceAddressConfig> netInterfaceAddressConfigs = new ArrayList<NetInterfaceAddressConfig>();
List<NetInterfaceAddress> netInterfaceAddresses = new ArrayList<NetInterfaceAddress>();
NetInterfaceAddressConfigImpl netInterfaceAddressConfig = new NetInterfaceAddressConfigImpl();
netInterfaceAddressConfigs.add(netInterfaceAddressConfig);
netInterfaceAddresses.add(netInterfaceAddressConfig);
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null && ifconfig.isUp()) {
netInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
netInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
netInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(ifconfig.getInetMask()));
netInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(ifconfig.getInetMask()));
netInterfaceAddressConfig.setGateway(conInfo.getGateway());
if (dhcp) {
netInterfaceAddressConfig.setDnsServers(dnsService.getDhcpDnsServers(interfaceName, netInterfaceAddressConfig.getAddress()));
} else {
netInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
}
}
((LoopbackInterfaceConfigImpl) netInterfaceConfig).setNetInterfaceAddresses(netInterfaceAddressConfigs);
List<NetConfig> netConfigs = new ArrayList<NetConfig>();
netInterfaceAddressConfig.setNetConfigs(netConfigs);
// FIXME - hardcoded
NetConfig netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusEnabledLAN, true);
((NetConfigIP4) netConfig).setAddress(address);
((NetConfigIP4) netConfig).setDhcp(dhcp);
((NetConfigIP4) netConfig).setDnsServers(null);
((NetConfigIP4) netConfig).setDomains(null);
((NetConfigIP4) netConfig).setGateway(null);
((NetConfigIP4) netConfig).setNetworkPrefixLength((short) 8);
((NetConfigIP4) netConfig).setSubnetMask((IP4Address) IPAddress.parseHostAddress("255.0.0.0"));
((NetConfigIP4) netConfig).setWinsServers(null);
netConfigs.add(netConfig);
} else if (type == NetInterfaceType.ETHERNET) {
s_logger.debug("Adding an Ethernet interface - {}", interfaceName);
netInterfaceConfig = new EthernetInterfaceConfigImpl(interfaceName);
((EthernetInterfaceImpl<?>) netInterfaceConfig).setMTU(mtu);
((EthernetInterfaceImpl<?>) netInterfaceConfig).setAutoConnect(autoConnect);
((EthernetInterfaceImpl<?>) netInterfaceConfig).setLoopback(false);
List<NetInterfaceAddressConfig> netInterfaceAddressConfigs = new ArrayList<NetInterfaceAddressConfig>();
List<NetInterfaceAddress> netInterfaceAddresses = new ArrayList<NetInterfaceAddress>();
NetInterfaceAddressConfigImpl netInterfaceAddressConfig = new NetInterfaceAddressConfigImpl();
netInterfaceAddressConfigs.add(netInterfaceAddressConfig);
netInterfaceAddresses.add(netInterfaceAddressConfig);
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
((EthernetInterfaceImpl<?>) netInterfaceConfig).setHardwareAddress(ifconfig.getMacAddressBytes());
if (ifconfig.isUp()) {
try {
netInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
netInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
netInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(ifconfig.getInetMask()));
netInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(ifconfig.getInetMask()));
netInterfaceAddressConfig.setGateway(conInfo.getGateway());
if (dhcp) {
netInterfaceAddressConfig.setDnsServers(dnsService.getDhcpDnsServers(interfaceName, netInterfaceAddressConfig.getAddress()));
} else {
netInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
}
} catch (KuraException e) {
s_logger.warn("The interface went down " + interfaceName + " not including current state in status because it is not up");
netInterfaceAddressConfig.setAddress(null);
netInterfaceAddressConfig.setBroadcast(null);
netInterfaceAddressConfig.setNetmask(null);
netInterfaceAddressConfig.setNetworkPrefixLength((short) -1);
netInterfaceAddressConfig.setGateway(null);
netInterfaceAddressConfig.setDnsServers(null);
}
}
}
((EthernetInterfaceConfigImpl) netInterfaceConfig).setNetInterfaceAddresses(netInterfaceAddressConfigs);
// add the config
List<NetConfig> netConfigs = new ArrayList<NetConfig>();
netInterfaceAddressConfig.setNetConfigs(netConfigs);
NetConfigIP4 netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusDisabled, autoConnect);
setNetConfigIP4(netConfig, status, autoConnect, dhcp, address, gateway, prefixString, netmask, kuraProps);
netConfigs.add(netConfig);
if (dhcpServerEnabled) {
// add DHCP server configuration to the list
DhcpServerImpl dhcpServer = DhcpServerFactory.getInstance(interfaceName, dhcpServerEnabled, passDns);
DhcpServerConfig4 dhcpServerConfig = dhcpServer.getDhcpServerConfig(dhcpServerEnabled, passDns);
if (dhcpServerConfig != null) {
netConfigs.add(dhcpServerConfig);
}
}
} else if (type == NetInterfaceType.WIFI) {
s_logger.debug("Adding a Wireless interface - {}", interfaceName);
WifiInterfaceConfigImpl wifiInterfaceConfig = new WifiInterfaceConfigImpl(interfaceName);
netInterfaceConfig = wifiInterfaceConfig;
wifiInterfaceConfig.setMTU(mtu);
wifiInterfaceConfig.setAutoConnect(autoConnect);
wifiInterfaceConfig.setLoopback(false);
List<WifiInterfaceAddressConfig> wifiInterfaceAddressConfigs = new ArrayList<WifiInterfaceAddressConfig>();
List<WifiInterfaceAddress> wifiInterfaceAddresses = new ArrayList<WifiInterfaceAddress>();
WifiInterfaceAddressConfigImpl wifiInterfaceAddressConfig = new WifiInterfaceAddressConfigImpl();
wifiInterfaceAddressConfigs.add(wifiInterfaceAddressConfig);
wifiInterfaceAddresses.add(wifiInterfaceAddressConfig);
String currentSSID = LinuxNetworkUtil.getSSID(interfaceName);
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
wifiInterfaceConfig.setHardwareAddress(ifconfig.getMacAddressBytes());
if (ifconfig.isUp()) {
wifiInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
wifiInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
String currentNetmask = ifconfig.getInetMask();
if (currentNetmask != null) {
wifiInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(currentNetmask));
wifiInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
}
wifiInterfaceAddressConfig.setBitrate(LinuxNetworkUtil.getWifiBitrate(interfaceName));
wifiInterfaceAddressConfig.setGateway(conInfo.getGateway());
if (dhcp) {
wifiInterfaceAddressConfig.setDnsServers(dnsService.getDhcpDnsServers(interfaceName, wifiInterfaceAddressConfig.getAddress()));
} else {
wifiInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
}
WifiAccessPointImpl ap = null;
if (currentSSID != null) {
s_logger.debug("Adding access point SSID: {}", currentSSID);
ap = new WifiAccessPointImpl(currentSSID);
// TODO: fill in other info
ap.setMode(WifiMode.INFRA);
List<Long> bitrate = new ArrayList<Long>();
bitrate.add(54000000L);
ap.setBitrate(bitrate);
ap.setFrequency(12345);
ap.setHardwareAddress("20AA4B8A6442".getBytes());
ap.setRsnSecurity(EnumSet.allOf(WifiSecurity.class));
ap.setStrength(1234);
ap.setWpaSecurity(EnumSet.allOf(WifiSecurity.class));
}
wifiInterfaceAddressConfig.setWifiAccessPoint(ap);
}
}
// mode
WifiMode wifiMode = WifiMode.UNKNOWN;
s_logger.debug("Get WifiMode...");
try {
// get from config file
String mode = kuraProps.getProperty("MODE");
if (mode != null) {
s_logger.debug("Getting wifi mode from {}", kuraFile.getAbsolutePath());
if (mode.equalsIgnoreCase("Managed")) {
wifiMode = WifiMode.INFRA;
} else if (mode.equalsIgnoreCase("Master")) {
wifiMode = WifiMode.MASTER;
} else if (mode.equalsIgnoreCase("Ad-Hoc")) {
wifiMode = WifiMode.ADHOC;
} else {
wifiMode = WifiMode.valueOf(mode);
}
} else {
// get current setting using iwconfig
s_logger.debug("Getting wifi mode from iwconfig");
wifiMode = LinuxNetworkUtil.getWifiMode(interfaceName);
}
} catch (Exception e) {
// leave as unknown
}
s_logger.debug("Current WifiMode: {}", wifiMode);
wifiInterfaceAddressConfig.setMode(wifiMode);
wifiInterfaceConfig.setNetInterfaceAddresses(wifiInterfaceAddressConfigs);
// TODO: fix
wifiInterfaceConfig.setCapabilities(EnumSet.allOf(Capability.class));
// add the configs - one for client (managed) mode, one for access point (master) mode
List<NetConfig> netConfigs = new ArrayList<NetConfig>();
wifiInterfaceAddressConfig.setNetConfigs(netConfigs);
// get the NetConfig
NetConfigIP4 netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusDisabled, autoConnect);
setNetConfigIP4(netConfig, status, autoConnect, dhcp, address, gateway, prefixString, netmask, kuraProps);
netConfigs.add(netConfig);
// get the wpa_supplicant configuration
WifiConfig wifiClientConfig = new WifiConfig();
setWifiClientConfig(interfaceName, wifiClientConfig, wifiMode);
// get the hostapd configuration
WifiConfig wifiAPConfig = new WifiConfig();
setWifiAccessPointConfig(wifiAPConfig);
// add WiFi configurations to the list
netConfigs.add(wifiClientConfig);
netConfigs.add(wifiAPConfig);
if (dhcpServerEnabled) {
// add DHCP server configuration to the list
DhcpServerImpl dhcpServer = DhcpServerFactory.getInstance(interfaceName, dhcpServerEnabled, passDns);
DhcpServerConfig4 dhcpServerConfig = dhcpServer.getDhcpServerConfig(dhcpServerEnabled, passDns);
if (dhcpServerConfig != null) {
netConfigs.add(dhcpServerConfig);
}
}
} else if (type == NetInterfaceType.MODEM) {
s_logger.debug("Adding a Modem interface");
netInterfaceConfig = new ModemInterfaceConfigImpl(interfaceName);
((ModemInterfaceConfigImpl) netInterfaceConfig).setMTU(mtu);
((ModemInterfaceConfigImpl) netInterfaceConfig).setAutoConnect(autoConnect);
((ModemInterfaceConfigImpl) netInterfaceConfig).setLoopback(false);
((ModemInterfaceConfigImpl) netInterfaceConfig).setPointToPoint(true);
List<ModemInterfaceAddressConfig> modemInterfaceAddressConfigs = new ArrayList<ModemInterfaceAddressConfig>();
List<ModemInterfaceAddress> netInterfaceAddresses = new ArrayList<ModemInterfaceAddress>();
ModemInterfaceAddressConfigImpl netInterfaceAddressConfig = new ModemInterfaceAddressConfigImpl();
modemInterfaceAddressConfigs.add(netInterfaceAddressConfig);
netInterfaceAddresses.add(netInterfaceAddressConfig);
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
((ModemInterfaceConfigImpl) netInterfaceConfig).setHardwareAddress(ifconfig.getMacAddressBytes());
if (ifconfig.isUp()) {
netInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
netInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
netInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(ifconfig.getInetMask()));
netInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(ifconfig.getInetMask()));
netInterfaceAddressConfig.setGateway(conInfo.getGateway());
netInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
}
}
((ModemInterfaceConfigImpl) netInterfaceConfig).setNetInterfaceAddresses(modemInterfaceAddressConfigs);
// add the config
List<NetConfig> netConfigs = new ArrayList<NetConfig>();
netInterfaceAddressConfig.setNetConfigs(netConfigs);
NetConfigIP4 netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusDisabled, autoConnect);
setNetConfigIP4(netConfig, status, autoConnect, dhcp, address, gateway, prefixString, netmask, kuraProps);
netConfigs.add(netConfig);
} else {
s_logger.warn("Unsupported Type: " + type);
}
return netInterfaceConfig;
} catch (UnknownHostException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
use of org.eclipse.kura.net.modem.ModemInterfaceAddressConfig in project kura by eclipse.
the class PppConfigWriter method writeConfig.
private void writeConfig(ModemInterfaceConfigImpl modemInterfaceConfig) throws KuraException {
String oldInterfaceName = modemInterfaceConfig.getName();
String newInterfaceName = modemInterfaceConfig.getName();
// Get the configs
ModemConfig modemConfig = null;
NetConfigIP4 netConfigIP4 = null;
for (ModemInterfaceAddressConfig modemInterfaceAddressConfig : modemInterfaceConfig.getNetInterfaceAddresses()) {
for (NetConfig netConfig : modemInterfaceAddressConfig.getConfigs()) {
if (netConfig instanceof ModemConfig) {
modemConfig = (ModemConfig) netConfig;
} else if (netConfig instanceof NetConfigIP4) {
netConfigIP4 = (NetConfigIP4) netConfig;
}
}
}
// Use the ppp number for the interface name, if configured
int pppNum = -1;
if (modemConfig != null) {
pppNum = modemConfig.getPppNumber();
if (pppNum >= 0) {
newInterfaceName = "ppp" + pppNum;
modemInterfaceConfig.setName(newInterfaceName);
}
}
// Save the status and priority
IfcfgConfigWriter.writeKuraExtendedConfig(modemInterfaceConfig);
Class<? extends ModemPppConfigGenerator> configClass = null;
UsbDevice usbDevice = modemInterfaceConfig.getUsbDevice();
int baudRate = -1;
if (usbDevice != null) {
SupportedUsbModemInfo modemInfo = SupportedUsbModemsInfo.getModem(usbDevice);
UsbModemFactoryInfo usbFactoryInfo = SupportedUsbModemsFactoryInfo.getModem(modemInfo);
if (usbFactoryInfo != null) {
configClass = usbFactoryInfo.getConfigGeneratorClass();
}
baudRate = 921600;
} else {
SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
SerialModemFactoryInfo serialFactoryInfo = SupportedSerialModemsFactoryInfo.getModem(serialModemInfo);
configClass = serialFactoryInfo.getConfigGeneratorClass();
baudRate = serialModemInfo.getDriver().getComm().getBaudRate();
}
String pppPeerFilename = formPeerFilename(usbDevice);
String pppLogfile = formPppLogFilename(usbDevice);
String chatFilename = formChatFilename(usbDevice);
String disconnectFilename = formDisconnectFilename(usbDevice);
// Cleanup values associated with the old name if the interface name has changed
if (!oldInterfaceName.equals(newInterfaceName)) {
try {
// Remove the old ppp peers symlink
s_logger.debug("Removing old symlinks to {}", pppPeerFilename);
removeSymbolicLinks(pppPeerFilename, OS_PEERS_DIRECTORY);
// Remove the old modem identifier
StringBuilder key = new StringBuilder("net.interface.").append(oldInterfaceName).append(".modem.identifier");
s_logger.debug("Removing modem identifier for {}", oldInterfaceName);
KuranetConfig.deleteProperty(key.toString());
// Remove custom dns servers
key = new StringBuilder("net.interface.").append(oldInterfaceName).append(".config.dnsServers");
s_logger.debug("Removing dns servers for {}", oldInterfaceName);
KuranetConfig.deleteProperty(key.toString());
// Remove gpsEnabled
key = new StringBuilder().append("net.interface.").append(oldInterfaceName).append(".config.gpsEnabled");
s_logger.debug("Removing gpsEnabled for {}", oldInterfaceName);
KuranetConfig.deleteProperty(key.toString());
// Remove status
IfcfgConfigWriter.removeKuraExtendedConfig(oldInterfaceName);
} catch (IOException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
if (configClass != null) {
try {
ModemPppConfigGenerator scriptGenerator = configClass.newInstance();
if (modemConfig != null) {
s_logger.debug("Writing connect scripts for " + modemInterfaceConfig.getName() + " using " + configClass.toString());
s_logger.debug("Writing {}", pppPeerFilename);
PppPeer pppPeer = scriptGenerator.getPppPeer(getDeviceId(usbDevice), modemConfig, pppLogfile, chatFilename, disconnectFilename);
pppPeer.setBaudRate(baudRate);
pppPeer.write(pppPeerFilename);
s_logger.debug("Writing {}", chatFilename);
ModemXchangeScript connectScript = scriptGenerator.getConnectScript(modemConfig);
connectScript.writeScript(chatFilename);
s_logger.debug("Writing {}", disconnectFilename);
ModemXchangeScript disconnectScript = scriptGenerator.getDisconnectScript(modemConfig);
disconnectScript.writeScript(disconnectFilename);
if (pppNum >= 0) {
s_logger.debug("Linking peer file using ppp number: {}", pppNum);
String symlinkFilename = formPeerLinkAbsoluteName(pppNum);
LinuxFileUtil.createSymbolicLink(pppPeerFilename, symlinkFilename);
} else {
s_logger.error("Can't create symbolic link to " + pppPeerFilename + ", invalid ppp number: " + pppNum);
}
String modemIdentifier = modemInterfaceConfig.getModemIdentifier();
if (modemIdentifier != null) {
StringBuilder key = new StringBuilder("net.interface.").append(modemInterfaceConfig.getName()).append(".modem.identifier");
s_logger.debug("Storing modem identifier " + modemIdentifier + " using key: " + key);
KuranetConfig.setProperty(key.toString(), modemIdentifier);
}
// Custom dns servers
if (netConfigIP4 != null) {
StringBuilder key = new StringBuilder("net.interface.").append(modemInterfaceConfig.getName()).append(".config.dnsServers");
List<IP4Address> dnsServers = netConfigIP4.getDnsServers();
if (dnsServers != null && !dnsServers.isEmpty()) {
StringBuilder serversSB = new StringBuilder();
Iterator<IP4Address> it = dnsServers.iterator();
serversSB.append(it.next().getHostAddress());
while (it.hasNext()) {
serversSB.append(DNS_DELIM).append(it.next().getHostAddress());
}
s_logger.debug("Storing DNS servers " + serversSB + " using key: " + key);
KuranetConfig.setProperty(key.toString(), serversSB.toString());
} else {
KuranetConfig.deleteProperty(key.toString());
}
}
StringBuilder key = new StringBuilder().append("net.interface.").append(newInterfaceName).append(".config.gpsEnabled");
s_logger.debug("Setting gpsEnabled for {}", newInterfaceName);
KuranetConfig.setProperty(key.toString(), Boolean.toString(modemConfig.isGpsEnabled()));
key = new StringBuilder().append("net.interface.").append(newInterfaceName).append(".config.resetTimeout");
s_logger.debug("Setting modem resetTimeout for {}", newInterfaceName);
KuranetConfig.setProperty(key.toString(), Integer.toString(modemConfig.getResetTimeout()));
} else {
s_logger.error("Error writing connect scripts - modemConfig is null");
}
} catch (Exception e) {
s_logger.error("Could not write modem config", e);
}
}
}
use of org.eclipse.kura.net.modem.ModemInterfaceAddressConfig in project kura by eclipse.
the class NetworkConfiguration method addInterfaceConfiguration.
private void addInterfaceConfiguration(String interfaceName, NetInterfaceType type, Map<String, Object> props) throws UnknownHostException, KuraException {
if (type == null) {
s_logger.error("Null type for " + interfaceName);
return;
}
switch(type) {
case LOOPBACK:
LoopbackInterfaceConfigImpl loopbackInterfaceConfig = new LoopbackInterfaceConfigImpl(interfaceName);
List<NetInterfaceAddressConfig> loopbackInterfaceAddressConfigs = new ArrayList<NetInterfaceAddressConfig>();
loopbackInterfaceAddressConfigs.add(new NetInterfaceAddressConfigImpl());
loopbackInterfaceConfig.setNetInterfaceAddresses(loopbackInterfaceAddressConfigs);
populateNetInterfaceConfiguration(loopbackInterfaceConfig, props);
this.m_netInterfaceConfigs.put(interfaceName, loopbackInterfaceConfig);
break;
case ETHERNET:
EthernetInterfaceConfigImpl ethernetInterfaceConfig = new EthernetInterfaceConfigImpl(interfaceName);
List<NetInterfaceAddressConfig> ethernetInterfaceAddressConfigs = new ArrayList<NetInterfaceAddressConfig>();
ethernetInterfaceAddressConfigs.add(new NetInterfaceAddressConfigImpl());
ethernetInterfaceConfig.setNetInterfaceAddresses(ethernetInterfaceAddressConfigs);
populateNetInterfaceConfiguration(ethernetInterfaceConfig, props);
this.m_netInterfaceConfigs.put(interfaceName, ethernetInterfaceConfig);
break;
case WIFI:
WifiInterfaceConfigImpl wifiInterfaceConfig = new WifiInterfaceConfigImpl(interfaceName);
List<WifiInterfaceAddressConfig> wifiInterfaceAddressConfigs = new ArrayList<WifiInterfaceAddressConfig>();
wifiInterfaceAddressConfigs.add(new WifiInterfaceAddressConfigImpl());
wifiInterfaceConfig.setNetInterfaceAddresses(wifiInterfaceAddressConfigs);
populateNetInterfaceConfiguration(wifiInterfaceConfig, props);
this.m_netInterfaceConfigs.put(interfaceName, wifiInterfaceConfig);
break;
case MODEM:
ModemInterfaceConfigImpl modemInterfaceConfig = new ModemInterfaceConfigImpl(interfaceName);
List<ModemInterfaceAddressConfig> modemInterfaceAddressConfigs = new ArrayList<ModemInterfaceAddressConfig>();
modemInterfaceAddressConfigs.add(new ModemInterfaceAddressConfigImpl());
modemInterfaceConfig.setNetInterfaceAddresses(modemInterfaceAddressConfigs);
populateNetInterfaceConfiguration(modemInterfaceConfig, props);
this.m_netInterfaceConfigs.put(interfaceName, modemInterfaceConfig);
break;
case UNKNOWN:
s_logger.trace("Found interface of unknown type in current configuration: {}", interfaceName);
break;
/*
* default:
*
* switch (type) {
* case ETHERNET:
* addEthernetConfiguration(interfaceName, props);
* break;
* case WIFI:
* addWifiConfiguration(interfaceName, props);
* break;
*/
default:
s_logger.error("Unsupported type " + type.toString() + " for interface " + interfaceName);
break;
}
}
Aggregations