use of org.eclipse.kura.net.admin.modem.SupportedUsbModemsFactoryInfo.UsbModemFactoryInfo 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.admin.modem.SupportedUsbModemsFactoryInfo.UsbModemFactoryInfo 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);
}
}
}
Aggregations