use of org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo in project kura by eclipse.
the class NetworkServiceImpl method handleEvent.
@Override
public void handleEvent(Event event) {
s_logger.debug("handleEvent() :: topic: {}", event.getTopic());
String topic = event.getTopic();
if (topic.equals(UsbDeviceAddedEvent.USB_EVENT_DEVICE_ADDED_TOPIC)) {
// validate mandatory properties
if (event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY) == null) {
return;
}
if (event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY) == null) {
return;
}
if (event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY) == null) {
return;
}
if (event.getProperty(UsbDeviceEvent.USB_EVENT_RESOURCE_PROPERTY) == null) {
return;
}
// do we care?
final SupportedUsbModemInfo modemInfo = SupportedUsbModemsInfo.getModem((String) event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
if (modemInfo != null) {
// Found one - see if we have some info for it.
// Also check if we are getting more devices than expected.
// This can happen if all the modem resources cannot be removed from the OS or from Kura.
// In this case we did not receive an UsbDeviceRemovedEvent and we did not post
// an ModemRemovedEvent. Should we do it here?
List<? extends UsbModemDriver> drivers = modemInfo.getDeviceDrivers();
for (UsbModemDriver driver : drivers) {
try {
driver.install();
} catch (Exception e) {
s_logger.error("handleEvent() :: Failed to install modem device driver {} - {}", driver.getName(), e);
}
}
UsbModemDevice usbModem = this.m_usbModems.get(event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY));
boolean createNewUsbModemDevice = false;
if (usbModem == null) {
createNewUsbModemDevice = true;
} else if (modemInfo.getNumTtyDevs() > 0 && modemInfo.getNumBlockDevs() > 0) {
if (usbModem.getTtyDevs().size() >= modemInfo.getNumTtyDevs() && usbModem.getBlockDevs().size() >= modemInfo.getNumBlockDevs()) {
createNewUsbModemDevice = true;
}
} else if (modemInfo.getNumTtyDevs() > 0 && usbModem.getTtyDevs().size() >= modemInfo.getNumTtyDevs() || modemInfo.getNumBlockDevs() > 0 && usbModem.getBlockDevs().size() >= modemInfo.getNumBlockDevs()) {
createNewUsbModemDevice = true;
}
if (createNewUsbModemDevice) {
if (usbModem == null) {
s_logger.debug("handleEvent() :: Modem not found. Create one");
} else {
s_logger.debug("handleEvent() :: Found modem with too many resources: {}. Create a new one", usbModem);
}
usbModem = new UsbModemDevice((String) event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_BUS_NUMBER_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_DEVICE_PATH_PROPERTY));
}
String resource = (String) event.getProperty(UsbDeviceEvent.USB_EVENT_RESOURCE_PROPERTY);
s_logger.debug("handleEvent() :: Adding resource: {} for: {}", resource, usbModem.getUsbPort());
if (resource.contains("tty")) {
usbModem.addTtyDev(resource);
} else {
usbModem.addBlockDev(resource);
}
this.m_usbModems.put(usbModem.getUsbPort(), usbModem);
// At this point, we should have some modems - display them
s_logger.info("handleEvent() :: Modified modem (Added resource): {}", usbModem);
s_logger.debug("handleEvent() :: usbModem.getTtyDevs().size()={}, modemInfo.getNumTtyDevs()={}", usbModem.getTtyDevs().size(), modemInfo.getNumTtyDevs());
s_logger.debug("handleEvent() :: usbModem.getBlockDevs().size()={}, modemInfo.getNumBlockDevs()={}", usbModem.getBlockDevs().size(), modemInfo.getNumBlockDevs());
// Check for correct number of resources
if (usbModem.getTtyDevs().size() == modemInfo.getNumTtyDevs() && usbModem.getBlockDevs().size() == modemInfo.getNumBlockDevs()) {
s_logger.info("handleEvent() :: posting ModemAddedEvent -- USB_EVENT_DEVICE_ADDED_TOPIC: {}", usbModem);
this.m_eventAdmin.postEvent(new ModemAddedEvent(usbModem));
this.m_addedModems.add(usbModem.getUsbPort());
if (OS_VERSION != null && TARGET_NAME != null && OS_VERSION.equals(KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Mini_Gateway.getTargetName()) || OS_VERSION.equals(KuraConstants.Reliagate_10_11.getImageName() + "_" + KuraConstants.Reliagate_10_11.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Reliagate_10_11.getTargetName())) {
if (this.m_serialModem != null) {
if (SupportedUsbModemInfo.Telit_HE910_D.getVendorId().equals(usbModem.getVendorId()) && SupportedUsbModemInfo.Telit_HE910_D.getProductId().equals(usbModem.getProductId())) {
s_logger.info("handleEvent() :: Removing {} from addedModems", this.m_serialModem.getProductName());
this.m_addedModems.remove(this.m_serialModem.getProductName());
}
}
}
}
}
/*
* System.out.println("ADDED Device: " + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_VENDOR_ID_PROPERTY)
* + ":" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_ID_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_RESOURCE_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_USB_PORT_PROPERTY));
*/
} else if (topic.equals(UsbDeviceRemovedEvent.USB_EVENT_DEVICE_REMOVED_TOPIC)) {
// validate mandatory properties
if (event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY) == null) {
return;
}
if (event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY) == null) {
return;
}
if (event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY) == null) {
return;
}
// do we care?
SupportedUsbModemInfo modemInfo = SupportedUsbModemsInfo.getModem((String) event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
if (modemInfo != null) {
// found one - remove if it exists
UsbModemDevice usbModem = this.m_usbModems.remove(event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY));
if (usbModem != null) {
s_logger.info("handleEvent() :: Removing modem: {}", usbModem);
this.m_addedModems.remove(usbModem.getUsbPort());
Map<String, String> properties = new HashMap<String, String>();
properties.put(UsbDeviceEvent.USB_EVENT_BUS_NUMBER_PROPERTY, usbModem.getUsbBusNumber());
properties.put(UsbDeviceEvent.USB_EVENT_DEVICE_PATH_PROPERTY, usbModem.getUsbDevicePath());
properties.put(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY, usbModem.getUsbPort());
properties.put(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY, usbModem.getVendorId());
properties.put(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY, usbModem.getProductId());
properties.put(UsbDeviceEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY, usbModem.getManufacturerName());
properties.put(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY, usbModem.getProductName());
this.m_eventAdmin.postEvent(new ModemRemovedEvent(properties));
}
}
/*
* System.out.println("REMOVED Device: " +
* event.getProperty(UsbDeviceAddedEvent.USB_EVENT_VENDOR_ID_PROPERTY) + ":" +
* event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_ID_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_RESOURCE_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
* System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_USB_PORT_PROPERTY));
*/
} else if (topic.equals(SerialModemAddedEvent.SERIAL_MODEM_EVENT_ADDED_TOPIC)) {
SerialModemAddedEvent serialModemAddedEvent = (SerialModemAddedEvent) event;
SupportedSerialModemInfo serialModemInfo = serialModemAddedEvent.getSupportedSerialModemInfo();
if (serialModemInfo != null) {
if (OS_VERSION != null && TARGET_NAME != null && OS_VERSION.equals(KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Mini_Gateway.getTargetName()) || OS_VERSION.equals(KuraConstants.Reliagate_10_11.getImageName() + "_" + KuraConstants.Reliagate_10_11.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Reliagate_10_11.getTargetName())) {
if (this.m_usbModems.isEmpty()) {
this.m_serialModem = new SerialModemDevice(serialModemInfo.getModemName(), serialModemInfo.getManufacturerName(), serialModemInfo.getDriver().getComm().getSerialPorts());
if (this.m_serialModem != null) {
s_logger.debug("handleEvent() :: posting ModemAddedEvent for serial modem: {}", this.m_serialModem.getProductName());
this.m_eventAdmin.postEvent(new ModemAddedEvent(this.m_serialModem));
this.m_addedModems.add(this.m_serialModem.getProductName());
}
} else {
s_logger.info("handleEvent() :: Ignoring {} modem since it has already been detected as a USB device", serialModemInfo.getModemName());
}
} else {
this.m_serialModem = new SerialModemDevice(serialModemInfo.getModemName(), serialModemInfo.getManufacturerName(), serialModemInfo.getDriver().getComm().getSerialPorts());
if (this.m_serialModem != null) {
s_logger.debug("handleEvent() :: posting ModemAddedEvent for serial modem: {}", this.m_serialModem.getProductName());
this.m_eventAdmin.postEvent(new ModemAddedEvent(this.m_serialModem));
this.m_addedModems.add(this.m_serialModem.getProductName());
}
}
}
} else {
s_logger.error("handleEvent() :: Unexpected event topic: {}", topic);
}
}
use of org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo in project kura by eclipse.
the class NetworkServiceImpl method getModemPppPort.
/**
* Given a usb port address, look up the associated ppp interface name
*
* @throws KuraException
*/
@Override
public String getModemPppPort(ModemDevice modemDevice) throws KuraException {
String deviceName = null;
String modemId = null;
if (modemDevice instanceof UsbModemDevice) {
UsbModemDevice usbModem = (UsbModemDevice) modemDevice;
SupportedUsbModemInfo modemInfo = SupportedUsbModemsInfo.getModem(usbModem.getVendorId(), usbModem.getProductId(), usbModem.getProductName());
deviceName = modemInfo.getDeviceName();
modemId = usbModem.getUsbPort();
} else if (modemDevice instanceof SerialModemDevice) {
SerialModemDevice serialModem = (SerialModemDevice) modemDevice;
deviceName = serialModem.getProductName();
modemId = serialModem.getProductName();
}
// find a matching config file in the ppp peers directory
File peersDir = new File(PPP_PEERS_DIR);
if (peersDir.isDirectory()) {
File[] peerFiles = peersDir.listFiles();
for (File peerFile : peerFiles) {
String peerFilename = peerFile.getName();
if (peerFilename.startsWith(deviceName) && peerFilename.endsWith(/* usbPort */
modemId)) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(peerFile));
String line = null;
StringBuilder sbIfaceName = null;
while ((line = br.readLine()) != null) {
if (line.startsWith("unit")) {
sbIfaceName = new StringBuilder("ppp");
sbIfaceName.append(line.substring("unit".length()).trim());
break;
}
}
return sbIfaceName.toString();
} catch (Exception e) {
s_logger.error("failed to parse peers file - {}", e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
s_logger.error("failed to close buffered reader - {}", e);
}
}
}
break;
}
}
}
return null;
}
use of org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo in project kura by eclipse.
the class NetworkServiceImpl method getModemInterface.
private ModemInterface<ModemInterfaceAddress> getModemInterface(String interfaceName, boolean isUp, ModemDevice modemDevice) throws KuraException {
ModemInterfaceImpl<ModemInterfaceAddress> modemInterface = new ModemInterfaceImpl<ModemInterfaceAddress>(interfaceName);
modemInterface.setModemDevice(modemDevice);
if (modemDevice instanceof UsbModemDevice) {
UsbModemDevice usbModemDevice = (UsbModemDevice) modemDevice;
SupportedUsbModemInfo supportedUsbModemInfo = null;
supportedUsbModemInfo = SupportedUsbModemsInfo.getModem(usbModemDevice.getVendorId(), usbModemDevice.getProductId(), usbModemDevice.getProductName());
modemInterface.setTechnologyTypes(supportedUsbModemInfo.getTechnologyTypes());
modemInterface.setUsbDevice((UsbModemDevice) modemDevice);
} else if (modemDevice instanceof SerialModemDevice) {
SupportedSerialModemInfo supportedSerialModemInfo = null;
supportedSerialModemInfo = SupportedSerialModemsInfo.getModem();
modemInterface.setTechnologyTypes(supportedSerialModemInfo.getTechnologyTypes());
}
int pppNum = 0;
if (interfaceName.startsWith("ppp")) {
pppNum = Integer.parseInt(interfaceName.substring(3));
}
modemInterface.setPppNum(pppNum);
modemInterface.setManufacturer(modemDevice.getManufacturerName());
modemInterface.setModel(modemDevice.getProductName());
modemInterface.setModemIdentifier(modemDevice.getProductName());
// these properties required net.admin packages
modemInterface.setDriver(getDriver());
modemInterface.setDriverVersion(getDriverVersion());
modemInterface.setFirmwareVersion(getFirmwareVersion());
modemInterface.setSerialNumber("unknown");
modemInterface.setLoopback(false);
modemInterface.setPointToPoint(true);
modemInterface.setState(getState(interfaceName, isUp));
modemInterface.setHardwareAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
modemInterface.setMTU(ifconfig.getMtu());
modemInterface.setSupportsMulticast(ifconfig.isMulticast());
}
modemInterface.setUp(isUp);
modemInterface.setVirtual(isVirtual());
modemInterface.setNetInterfaceAddresses(getModemInterfaceAddresses(interfaceName, isUp));
return modemInterface;
}
use of org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo 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.linux.net.modem.SupportedUsbModemInfo in project kura by eclipse.
the class PppConfigReader method getModemConfig.
private static ModemConfig getModemConfig(String ifaceName, UsbDevice usbDevice) throws KuraException {
s_logger.debug("parsePppPeerConfig()");
boolean isGsmGprsUmtsHspa = false;
List<ModemTechnologyType> technologyTypes = null;
if (usbDevice != null) {
SupportedUsbModemInfo usbModemInfo = SupportedUsbModemsInfo.getModem(usbDevice);
if (usbModemInfo != null) {
technologyTypes = usbModemInfo.getTechnologyTypes();
}
} else {
SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
if (serialModemInfo != null) {
technologyTypes = serialModemInfo.getTechnologyTypes();
}
}
if (technologyTypes != null) {
for (ModemTechnologyType technologyType : technologyTypes) {
if (technologyType == ModemTechnologyType.GSM_GPRS || technologyType == ModemTechnologyType.UMTS || technologyType == ModemTechnologyType.HSDPA || technologyType == ModemTechnologyType.HSPA) {
isGsmGprsUmtsHspa = true;
break;
}
}
}
boolean enabled = true;
int unitNum = getUnitNum(ifaceName);
String apn = "";
String pdpType = "UNKNOWN";
String dialString = "";
String username = "";
String password = "";
String model = "";
AuthType authType = AuthType.NONE;
boolean persist = false;
int maxFail = 0;
int idle = 0;
String activeFilter = "";
int lcpEchoInterval = 0;
int lcpEchoFailure = 0;
String peerFilename = getPeerFilename(ifaceName, usbDevice);
File peerFile = new File(peerFilename);
if (!peerFile.exists()) {
persist = true;
maxFail = 5;
idle = 95;
activeFilter = "inbound";
s_logger.warn("getModemConfig() :: PPPD peer file does not exist - {}", peerFilename);
} else {
s_logger.debug("getModemConfig() :: PPPD peer file exists - {}", peerFilename);
// Check if peer file is a symlink. If so, get information from the linked filename.
try {
if (!peerFile.getCanonicalPath().equals(peerFile.getAbsolutePath())) {
Map<String, String> fileInfo = PppUtil.parsePeerFilename(peerFile.getCanonicalFile().getName());
fileInfo.get("technology");
model = fileInfo.get("model");
fileInfo.get("serialNum");
fileInfo.get("modemId");
}
} catch (IOException e) {
s_logger.error("Error checking for symlink", e);
}
Properties props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(peerFilename);
props.load(fis);
} catch (Exception e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Error getting modem config", e);
} finally {
if (null != fis) {
try {
fis.close();
} catch (IOException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Error getting modem config", e);
}
}
}
s_logger.debug("peer properties: {}", props);
if (props.getProperty("unit") != null) {
unitNum = Integer.parseInt(props.getProperty("unit"));
}
if (props.getProperty("user") != null) {
username = removeQuotes(props.getProperty("user"));
}
if (props.getProperty("persist") != null) {
persist = true;
}
if (props.getProperty("maxfail") != null) {
maxFail = Integer.parseInt(props.getProperty("maxfail"));
}
if (props.getProperty("idle") != null) {
idle = Integer.parseInt(props.getProperty("idle"));
}
if (props.getProperty("active-filter") != null) {
activeFilter = removeQuotes(props.getProperty("active-filter"));
}
if (props.getProperty("lcp-echo-interval") != null) {
lcpEchoInterval = Integer.parseInt(props.getProperty("lcp-echo-interval"));
}
if (props.getProperty("lcp-echo-failure") != null) {
lcpEchoFailure = Integer.parseInt(props.getProperty("lcp-echo-failure"));
}
String chatFilename = "";
String connectProperty = removeQuotes(props.getProperty("connect"));
String[] args = connectProperty.split("\\s+");
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-f") && args.length > i + 1) {
chatFilename = args[i + 1];
break;
}
}
// String disconnectFilename = "";
// String disconnectProperty = removeQuotes(props.getProperty("disconnect"));
// args = disconnectProperty.split("\\s+");
// for(int i=0; i<args.length; i++) {
// if(args[i].equals("-f") && args.length > i+1) {
// disconnectFilename = args[i+1];
// break;
// }
// }
// Parse the connect script
ModemXchangeScript connectScript = null;
try {
connectScript = ModemXchangeScript.parseFile(chatFilename);
} catch (Exception e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Error parsing " + chatFilename, e);
}
if (connectScript != null) {
ModemXchangePair modemXchangePair = connectScript.getFirstModemXchangePair();
ModemXchangePair prevXchangePair = null;
String expectedStr, sendStr;
while (modemXchangePair != null) {
expectedStr = modemXchangePair.getExpectString();
sendStr = removeQuotes(modemXchangePair.getSendString());
if (expectedStr.equals("OK")) {
// apn
if (sendStr.contains(",")) {
String[] sendArgs = sendStr.split(",");
if (sendArgs.length == 3 && isGsmGprsUmtsHspa) {
pdpType = removeQuotes(sendArgs[1]);
apn = removeQuotes(sendArgs[2]);
}
}
// } else if(expectedStr.equals("\"\"")) {
} else if (expectedStr.equals("CONNECT")) {
// dial string
if (prevXchangePair != null) {
dialString = removeQuotes(prevXchangePair.getSendString());
}
}
prevXchangePair = modemXchangePair;
modemXchangePair = connectScript.getNextModemXchangePair();
}
}
s_logger.debug("* Enabled: {}", enabled);
s_logger.debug("* CHAT file: {}", chatFilename);
s_logger.debug("* UnitNum: {}", unitNum);
s_logger.debug("* dial string: {}", dialString);
s_logger.debug("* persist: {}", persist);
s_logger.debug("* maxfail: {}", maxFail);
s_logger.debug("* idle: {}", idle);
s_logger.debug("* active-filter: {}", activeFilter);
s_logger.debug("* LCP Echo Interval: {}", lcpEchoInterval);
s_logger.debug("* LCP Echo Failure: {}", lcpEchoFailure);
// Get the auth type and credentials
// pppd will use CHAP if available, else PAP
password = "";
if (isGsmGprsUmtsHspa) {
String chapSecret = ChapLinux.getInstance().getSecret(model, username, "*", "*");
String papSecret = PapLinux.getInstance().getSecret(model, username, "*", "*");
if (chapSecret != null && papSecret != null && chapSecret.equals(papSecret)) {
authType = AuthType.AUTO;
password = chapSecret;
} else if (chapSecret != null) {
authType = AuthType.CHAP;
password = chapSecret;
} else if (papSecret != null) {
authType = AuthType.PAP;
password = papSecret;
}
s_logger.debug("* APN: {}", apn);
s_logger.debug("* auth: {}", authType);
s_logger.debug("* username: {}", username);
s_logger.debug("* password: {}", password);
}
}
boolean gpsEnabled = false;
StringBuilder key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.gpsEnabled");
String statusString = KuranetConfig.getProperty(key.toString());
if (statusString != null && !statusString.isEmpty()) {
gpsEnabled = Boolean.parseBoolean(statusString);
}
int resetTout = 5;
key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.resetTimeout");
statusString = KuranetConfig.getProperty(key.toString());
if (statusString != null && !statusString.isEmpty()) {
resetTout = Integer.parseInt(statusString);
}
// Populate the modem config
ModemConfig modemConfig = new ModemConfig();
modemConfig.setPppNumber(unitNum);
modemConfig.setPersist(persist);
modemConfig.setMaxFail(maxFail);
modemConfig.setIdle(idle);
modemConfig.setActiveFilter(activeFilter);
modemConfig.setLcpEchoInterval(lcpEchoInterval);
modemConfig.setLcpEchoFailure(lcpEchoFailure);
// TODO - from self configuring properties
modemConfig.setEnabled(enabled);
// FIXME
modemConfig.setDataCompression(0);
modemConfig.setDialString(dialString);
// FIXME
modemConfig.setHeaderCompression(0);
modemConfig.setGpsEnabled(gpsEnabled);
modemConfig.setResetTimeout(resetTout);
if (isGsmGprsUmtsHspa) {
modemConfig.setApn(apn);
modemConfig.setAuthType(authType);
modemConfig.setPassword(password);
modemConfig.setPdpType(PdpType.valueOf(pdpType.toUpperCase()));
modemConfig.setUsername(username);
}
return modemConfig;
}
Aggregations