use of org.eclipse.kura.net.modem.CellularModem in project kura by eclipse.
the class ModemMonitorServiceImpl method processNetworkConfigurationChangeEvent.
private void processNetworkConfigurationChangeEvent(NetworkConfiguration newNetworkConfig) {
synchronized (s_lock) {
if (this.m_modems == null || this.m_modems.isEmpty()) {
return;
}
for (Map.Entry<String, CellularModem> modemEntry : this.m_modems.entrySet()) {
String usbPort = modemEntry.getKey();
CellularModem modem = modemEntry.getValue();
try {
String ifaceName = null;
if (this.m_networkService != null) {
ifaceName = this.m_networkService.getModemPppPort(modem.getModemDevice());
}
if (ifaceName != null) {
List<NetConfig> oldNetConfigs = modem.getConfiguration();
NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig = newNetworkConfig.getNetInterfaceConfig(ifaceName);
if (netInterfaceConfig == null) {
netInterfaceConfig = newNetworkConfig.getNetInterfaceConfig(usbPort);
}
List<NetConfig> newNetConfigs = null;
IModemLinkService pppService = null;
int ifaceNo = getInterfaceNumber(oldNetConfigs);
if (ifaceNo >= 0) {
pppService = PppFactory.obtainPppService(ifaceNo, modem.getDataPort());
}
if (netInterfaceConfig != null) {
newNetConfigs = getNetConfigs(netInterfaceConfig);
} else {
if (oldNetConfigs != null && pppService != null) {
if (!ifaceName.equals(pppService.getIfaceName())) {
StringBuilder key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.ip4.status");
String statusString = KuranetConfig.getProperty(key.toString());
NetInterfaceStatus netInterfaceStatus = NetInterfaceStatus.netIPv4StatusDisabled;
if (statusString != null && !statusString.isEmpty()) {
netInterfaceStatus = NetInterfaceStatus.valueOf(statusString);
}
newNetConfigs = oldNetConfigs;
oldNetConfigs = null;
try {
setInterfaceNumber(ifaceName, newNetConfigs);
setNetInterfaceStatus(netInterfaceStatus, newNetConfigs);
} catch (NumberFormatException e) {
s_logger.error("failed to set new interface number - {}", e);
}
}
}
}
if (oldNetConfigs == null || !isConfigsEqual(oldNetConfigs, newNetConfigs)) {
s_logger.info("new configuration for cellular modem on usb port {} netinterface {}", usbPort, ifaceName);
this.m_networkConfig = newNetworkConfig;
if (pppService != null) {
PppState pppState = pppService.getPppState();
if (pppState == PppState.CONNECTED || pppState == PppState.IN_PROGRESS) {
s_logger.info("disconnecting " + pppService.getIfaceName());
pppService.disconnect();
}
PppFactory.releasePppService(pppService.getIfaceName());
}
if (modem.isGpsEnabled()) {
if (!disableModemGps(modem)) {
s_logger.error("processNetworkConfigurationChangeEvent() :: Failed to disable modem GPS");
modem.reset();
this.m_resetTimerStart = System.currentTimeMillis();
}
}
modem.setConfiguration(newNetConfigs);
if (modem instanceof EvdoCellularModem) {
NetInterfaceStatus netIfaceStatus = getNetInterfaceStatus(newNetConfigs);
if (netIfaceStatus == NetInterfaceStatus.netIPv4StatusEnabledWAN) {
if (!((EvdoCellularModem) modem).isProvisioned()) {
s_logger.info("NetworkConfigurationChangeEvent :: The {} is not provisioned, will try to provision it ...", modem.getModel());
if (task != null && !task.isCancelled()) {
s_logger.info("NetworkConfigurationChangeEvent :: Cancelling monitor task");
stopThread.set(true);
monitorNotity();
task.cancel(true);
task = null;
}
((EvdoCellularModem) modem).provision();
if (task == null) {
s_logger.info("NetworkConfigurationChangeEvent :: Restarting monitor task");
stopThread.set(false);
task = this.m_executor.submit(new Runnable() {
@Override
public void run() {
while (!stopThread.get()) {
Thread.currentThread().setName("ModemMonitor");
try {
monitor();
monitorWait();
} catch (InterruptedException interruptedException) {
Thread.interrupted();
s_logger.debug("modem monitor interrupted - {}", interruptedException);
} catch (Throwable t) {
s_logger.error("handleEvent() :: Exception while monitoring cellular connection {}", t);
}
}
}
});
} else {
monitorNotity();
}
} else {
s_logger.info("NetworkConfigurationChangeEvent :: The " + modem.getModel() + " is provisioned");
}
}
if (modem.isGpsSupported()) {
if (isGpsEnabledInConfig(newNetConfigs) && !modem.isGpsEnabled()) {
modem.enableGps();
postModemGpsEvent(modem, true);
}
}
}
}
}
} catch (KuraException e) {
s_logger.error("NetworkConfigurationChangeEvent :: Failed to process - {}", e);
}
}
}
}
use of org.eclipse.kura.net.modem.CellularModem in project kura by eclipse.
the class ModemMonitorServiceImpl method monitor.
private void monitor() {
synchronized (s_lock) {
HashMap<String, InterfaceState> newInterfaceStatuses = new HashMap<String, InterfaceState>();
if (this.m_modems == null || this.m_modems.isEmpty()) {
return;
}
for (Map.Entry<String, CellularModem> modemEntry : this.m_modems.entrySet()) {
CellularModem modem = modemEntry.getValue();
// get signal strength only if somebody needs it
if (this.m_listeners != null && !this.m_listeners.isEmpty()) {
for (ModemMonitorListener listener : this.m_listeners) {
try {
int rssi = modem.getSignalStrength();
listener.setCellularSignalLevel(rssi);
} catch (KuraException e) {
listener.setCellularSignalLevel(0);
s_logger.error("monitor() :: Failed to obtain signal strength - {}", e);
}
}
}
IModemLinkService pppService = null;
PppState pppState = null;
NetInterfaceStatus netInterfaceStatus = getNetInterfaceStatus(modem.getConfiguration());
try {
String ifaceName = this.m_networkService.getModemPppPort(modem.getModemDevice());
if (netInterfaceStatus == NetInterfaceStatus.netIPv4StatusEnabledWAN && ifaceName != null) {
pppService = PppFactory.obtainPppService(ifaceName, modem.getDataPort());
pppState = pppService.getPppState();
if (this.m_pppState != pppState) {
s_logger.info("monitor() :: previous PppState={}", this.m_pppState);
s_logger.info("monitor() :: current PppState={}", pppState);
}
if (pppState == PppState.NOT_CONNECTED) {
boolean checkIfSimCardReady = false;
List<ModemTechnologyType> modemTechnologyTypes = modem.getTechnologyTypes();
for (ModemTechnologyType modemTechnologyType : modemTechnologyTypes) {
if (modemTechnologyType == ModemTechnologyType.GSM_GPRS || modemTechnologyType == ModemTechnologyType.UMTS || modemTechnologyType == ModemTechnologyType.HSDPA || modemTechnologyType == ModemTechnologyType.HSPA) {
checkIfSimCardReady = true;
break;
}
}
if (checkIfSimCardReady) {
if (((HspaCellularModem) modem).isSimCardReady()) {
s_logger.info("monitor() :: !!! SIM CARD IS READY !!! connecting ...");
pppService.connect();
if (this.m_pppState == PppState.NOT_CONNECTED) {
this.m_resetTimerStart = System.currentTimeMillis();
}
} else {
s_logger.warn("monitor() :: ! SIM CARD IS NOT READY !");
}
} else {
s_logger.info("monitor() :: connecting ...");
pppService.connect();
if (this.m_pppState == PppState.NOT_CONNECTED) {
this.m_resetTimerStart = System.currentTimeMillis();
}
}
} else if (pppState == PppState.IN_PROGRESS) {
long modemResetTout = getModemResetTimeoutMsec(ifaceName, modem.getConfiguration());
if (modemResetTout > 0) {
long timeElapsed = System.currentTimeMillis() - this.m_resetTimerStart;
if (timeElapsed > modemResetTout) {
// reset modem
s_logger.info("monitor() :: Modem Reset TIMEOUT !!!");
pppService.disconnect();
if (modem.isGpsEnabled() && !disableModemGps(modem)) {
s_logger.error("monitor() :: Failed to disable modem GPS");
}
modem.reset();
pppState = PppState.NOT_CONNECTED;
this.m_resetTimerStart = System.currentTimeMillis();
} else {
int timeTillReset = (int) (modemResetTout - timeElapsed) / 1000;
s_logger.info("monitor() :: PPP connection in progress. Modem will be reset in {} sec if not connected", timeTillReset);
}
}
} else if (pppState == PppState.CONNECTED) {
this.m_resetTimerStart = System.currentTimeMillis();
}
this.m_pppState = pppState;
ConnectionInfo connInfo = new ConnectionInfoImpl(ifaceName);
InterfaceState interfaceState = new InterfaceState(ifaceName, LinuxNetworkUtil.hasAddress(ifaceName), pppState == PppState.CONNECTED, connInfo.getIpAddress());
newInterfaceStatuses.put(ifaceName, interfaceState);
}
if (modem.isGpsSupported()) {
if (isGpsEnabledInConfig(modem.getConfiguration())) {
if (modem instanceof HspaCellularModem) {
if (!modem.isGpsEnabled()) {
modem.enableGps();
}
}
postModemGpsEvent(modem, true);
}
}
} catch (Exception e) {
s_logger.error("monitor() :: Exception", e);
if (pppService != null && pppState != null) {
try {
s_logger.info("monitor() :: Exception :: PPPD disconnect");
pppService.disconnect();
} catch (KuraException e1) {
s_logger.error("monitor() :: Exception while disconnect", e1);
}
this.m_pppState = pppState;
}
if (modem.isGpsEnabled()) {
try {
if (!disableModemGps(modem)) {
s_logger.error("monitor() :: Failed to disable modem GPS");
}
} catch (KuraException e1) {
s_logger.error("monitor() :: Exception disableModemGps", e1);
}
}
try {
s_logger.info("monitor() :: Exception :: modem reset");
modem.reset();
this.m_resetTimerStart = System.currentTimeMillis();
} catch (KuraException e1) {
s_logger.error("monitor() :: Exception modem.reset", e1);
}
}
}
// post event for any status changes
checkStatusChange(this.m_interfaceStatuses, newInterfaceStatuses);
this.m_interfaceStatuses = newInterfaceStatuses;
}
}
use of org.eclipse.kura.net.modem.CellularModem in project kura by eclipse.
the class ModemMonitorServiceImpl method trackModem.
private void trackModem(ModemDevice modemDevice) {
Class<? extends CellularModemFactory> modemFactoryClass = null;
if (modemDevice instanceof UsbModemDevice) {
SupportedUsbModemInfo supportedUsbModemInfo = SupportedUsbModemsInfo.getModem((UsbModemDevice) modemDevice);
UsbModemFactoryInfo usbModemFactoryInfo = SupportedUsbModemsFactoryInfo.getModem(supportedUsbModemInfo);
modemFactoryClass = usbModemFactoryInfo.getModemFactoryClass();
} else if (modemDevice instanceof SerialModemDevice) {
SupportedSerialModemInfo supportedSerialModemInfo = SupportedSerialModemsInfo.getModem();
SerialModemFactoryInfo serialModemFactoryInfo = SupportedSerialModemsFactoryInfo.getModem(supportedSerialModemInfo);
modemFactoryClass = serialModemFactoryInfo.getModemFactoryClass();
}
if (modemFactoryClass != null) {
CellularModemFactory modemFactoryService = null;
try {
try {
Method getInstanceMethod = modemFactoryClass.getDeclaredMethod("getInstance", (Class<?>[]) null);
getInstanceMethod.setAccessible(true);
modemFactoryService = (CellularModemFactory) getInstanceMethod.invoke(null, (Object[]) null);
} catch (Exception e) {
s_logger.error("Error calling getInstance() method on " + modemFactoryClass.getName() + e);
}
// if unsuccessful in calling getInstance()
if (modemFactoryService == null) {
modemFactoryService = modemFactoryClass.newInstance();
}
String platform = null;
if (this.m_systemService != null) {
platform = this.m_systemService.getPlatform();
}
CellularModem modem = modemFactoryService.obtainCellularModemService(modemDevice, platform);
try {
HashMap<String, String> modemInfoMap = new HashMap<String, String>();
modemInfoMap.put(ModemReadyEvent.IMEI, modem.getSerialNumber());
modemInfoMap.put(ModemReadyEvent.IMSI, modem.getMobileSubscriberIdentity());
modemInfoMap.put(ModemReadyEvent.ICCID, modem.getIntegratedCirquitCardId());
modemInfoMap.put(ModemReadyEvent.RSSI, Integer.toString(modem.getSignalStrength()));
s_logger.info("posting ModemReadyEvent on topic {}", ModemReadyEvent.MODEM_EVENT_READY_TOPIC);
this.m_eventAdmin.postEvent(new ModemReadyEvent(modemInfoMap));
} catch (Exception e) {
s_logger.error("Failed to post the ModemReadyEvent - {}", e);
}
String ifaceName = this.m_networkService.getModemPppPort(modemDevice);
List<NetConfig> netConfigs = null;
if (ifaceName != null) {
NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig = this.m_networkConfig.getNetInterfaceConfig(ifaceName);
if (netInterfaceConfig == null) {
this.m_networkConfig = this.m_netConfigService.getNetworkConfiguration();
netInterfaceConfig = this.m_networkConfig.getNetInterfaceConfig(ifaceName);
}
if (netInterfaceConfig != null) {
netConfigs = getNetConfigs(netInterfaceConfig);
if (netConfigs != null && netConfigs.size() > 0) {
modem.setConfiguration(netConfigs);
}
}
}
if (modemDevice instanceof UsbModemDevice) {
this.m_modems.put(((UsbModemDevice) modemDevice).getUsbPort(), modem);
} else if (modemDevice instanceof SerialModemDevice) {
this.m_modems.put(modemDevice.getProductName(), modem);
}
if (modem instanceof EvdoCellularModem) {
NetInterfaceStatus netIfaceStatus = getNetInterfaceStatus(netConfigs);
if (netIfaceStatus == NetInterfaceStatus.netIPv4StatusEnabledWAN) {
if (modem.isGpsEnabled()) {
if (!disableModemGps(modem)) {
s_logger.error("trackModem() :: Failed to disable modem GPS, resetting modem ...");
modem.reset();
this.m_resetTimerStart = System.currentTimeMillis();
}
}
if (!((EvdoCellularModem) modem).isProvisioned()) {
s_logger.info("trackModem() :: The {} is not provisioned, will try to provision it ...", modem.getModel());
if (task != null && !task.isCancelled()) {
s_logger.info("trackModem() :: Cancelling monitor task");
stopThread.set(true);
monitorNotity();
task.cancel(true);
task = null;
}
((EvdoCellularModem) modem).provision();
if (task == null) {
s_logger.info("trackModem() :: Restarting monitor task");
stopThread.set(false);
task = this.m_executor.submit(new Runnable() {
@Override
public void run() {
while (!stopThread.get()) {
Thread.currentThread().setName("ModemMonitor");
try {
monitor();
monitorWait();
} catch (InterruptedException interruptedException) {
Thread.interrupted();
s_logger.debug("modem monitor interrupted - {}", interruptedException);
} catch (Throwable t) {
s_logger.error("trackModem() :: Exception while monitoring cellular connection {}", t);
}
}
}
});
} else {
monitorNotity();
}
} else {
s_logger.info("trackModem() :: The {} is provisioned", modem.getModel());
}
}
if (modem.isGpsSupported()) {
if (isGpsEnabledInConfig(netConfigs) && !modem.isGpsEnabled()) {
modem.enableGps();
postModemGpsEvent(modem, true);
}
}
}
} catch (Exception e) {
s_logger.error("trackModem() :: {}", e);
}
}
}
use of org.eclipse.kura.net.modem.CellularModem 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.CellularModem in project kura by eclipse.
the class NetworkConfigurationServiceImpl method addPropertiesInModemInterface.
private void addPropertiesInModemInterface(ModemInterfaceImpl<? extends NetInterfaceAddress> modemInterface) throws KuraException {
String interfaceName = modemInterface.getName();
if (this.m_modemManagerService != null) {
String modemPort = this.m_networkService.getModemUsbPort(interfaceName);
if (modemPort == null) {
modemPort = interfaceName;
}
CellularModem modem = this.m_modemManagerService.getModemService(modemPort);
if (modem != null) {
// set modem properties
modemInterface.setSerialNumber(modem.getSerialNumber());
modemInterface.setModel(modem.getModel());
modemInterface.setFirmwareVersion(modem.getRevisionID());
modemInterface.setGpsSupported(modem.isGpsSupported());
// set modem driver
UsbModemDevice usbModemDevice = (UsbModemDevice) modemInterface.getUsbDevice();
if (usbModemDevice != null) {
List<? extends UsbModemDriver> drivers = null;
drivers = SupportedUsbModemsFactoryInfo.getDeviceDrivers(usbModemDevice.getVendorId(), usbModemDevice.getProductId());
if (drivers != null && drivers.size() > 0) {
UsbModemDriver driver = drivers.get(0);
modemInterface.setDriver(driver.getName());
}
}
}
}
}
Aggregations