Search in sources :

Example 1 with PppPeer

use of org.eclipse.kura.net.admin.modem.PppPeer in project kura by eclipse.

the class TelitHe910ConfigGenerator method getPppPeer.

@Override
public PppPeer getPppPeer(String deviceId, ModemConfig modemConfig, String logFile, String connectScript, String disconnectScript) {
    PppPeer pppPeer = new PppPeer();
    // default values
    pppPeer.setBaudRate(115200);
    pppPeer.setEnableDebug(true);
    pppPeer.setUseModemControlLines(true);
    pppPeer.setUseRtsCtsFlowControl(false);
    pppPeer.setLockSerialDevice(true);
    pppPeer.setPeerMustAuthenticateItself(false);
    pppPeer.setPeerToSupplyLocalIP(true);
    pppPeer.setAddDefaultRoute(true);
    pppPeer.setUsePeerDns(true);
    pppPeer.setAllowProxyArps(false);
    pppPeer.setAllowVanJacobsonTcpIpHdrCompression(false);
    pppPeer.setAllowVanJacobsonConnectionIDCompression(false);
    pppPeer.setAllowBsdCompression(false);
    pppPeer.setAllowDeflateCompression(false);
    pppPeer.setAllowMagic(false);
    pppPeer.setConnect_delay(1000);
    pppPeer.setLcp_echo_interval(0);
    // other config
    pppPeer.setLogfile(logFile);
    pppPeer.setProvider(deviceId);
    pppPeer.setPppUnitNumber(modemConfig.getPppNumber());
    pppPeer.setConnectScript(connectScript);
    pppPeer.setDisconnectScript(disconnectScript);
    pppPeer.setApn(modemConfig.getApn());
    pppPeer.setAuthType(modemConfig.getAuthType());
    pppPeer.setUsername(modemConfig.getUsername());
    pppPeer.setPassword(modemConfig.getPassword());
    pppPeer.setDialString(modemConfig.getDialString());
    pppPeer.setPersist(modemConfig.isPersist());
    pppPeer.setMaxFail(modemConfig.getMaxFail());
    pppPeer.setIdleTime(modemConfig.getIdle());
    pppPeer.setActiveFilter(modemConfig.getActiveFilter());
    pppPeer.setLcp_echo_interval(modemConfig.getLcpEchoInterval());
    pppPeer.setLcp_echo_failure(modemConfig.getLcpEchoFailure());
    return pppPeer;
}
Also used : PppPeer(org.eclipse.kura.net.admin.modem.PppPeer)

Example 2 with PppPeer

use of org.eclipse.kura.net.admin.modem.PppPeer 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);
        }
    }
}
Also used : IP4Address(org.eclipse.kura.net.IP4Address) UsbDevice(org.eclipse.kura.usb.UsbDevice) SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) IOException(java.io.IOException) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) UsbModemFactoryInfo(org.eclipse.kura.net.admin.modem.SupportedUsbModemsFactoryInfo.UsbModemFactoryInfo) ModemConfig(org.eclipse.kura.net.modem.ModemConfig) PppPeer(org.eclipse.kura.net.admin.modem.PppPeer) SerialModemFactoryInfo(org.eclipse.kura.net.admin.modem.SupportedSerialModemsFactoryInfo.SerialModemFactoryInfo) ModemXchangeScript(org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangeScript) KuraException(org.eclipse.kura.KuraException) ModemInterfaceAddressConfig(org.eclipse.kura.net.modem.ModemInterfaceAddressConfig) NetConfig(org.eclipse.kura.net.NetConfig) ModemPppConfigGenerator(org.eclipse.kura.net.admin.modem.ModemPppConfigGenerator) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)

Example 3 with PppPeer

use of org.eclipse.kura.net.admin.modem.PppPeer in project kura by eclipse.

the class SierraMc87xxConfigGenerator method getPppPeer.

@Override
public PppPeer getPppPeer(String deviceId, ModemConfig modemConfig, String logFile, String connectScript, String disconnectScript) {
    PppPeer pppPeer = new PppPeer();
    // default values
    pppPeer.setBaudRate(115200);
    pppPeer.setEnableDebug(true);
    pppPeer.setUseModemControlLines(true);
    pppPeer.setUseRtsCtsFlowControl(false);
    pppPeer.setLockSerialDevice(true);
    pppPeer.setPeerMustAuthenticateItself(false);
    pppPeer.setPeerToSupplyLocalIP(true);
    pppPeer.setAddDefaultRoute(true);
    pppPeer.setUsePeerDns(true);
    pppPeer.setAllowProxyArps(false);
    pppPeer.setAllowVanJacobsonTcpIpHdrCompression(false);
    pppPeer.setAllowVanJacobsonConnectionIDCompression(false);
    pppPeer.setAllowBsdCompression(false);
    pppPeer.setAllowDeflateCompression(false);
    pppPeer.setAllowMagic(false);
    pppPeer.setConnect_delay(1000);
    pppPeer.setLcp_echo_interval(0);
    // other config
    pppPeer.setLogfile(logFile);
    pppPeer.setProvider(deviceId);
    pppPeer.setPppUnitNumber(modemConfig.getPppNumber());
    pppPeer.setConnectScript(connectScript);
    pppPeer.setDisconnectScript(disconnectScript);
    pppPeer.setApn(modemConfig.getApn());
    pppPeer.setAuthType(modemConfig.getAuthType());
    pppPeer.setUsername(modemConfig.getUsername());
    pppPeer.setPassword(modemConfig.getPassword());
    pppPeer.setDialString(modemConfig.getDialString());
    pppPeer.setLcp_echo_interval(modemConfig.getLcpEchoInterval());
    pppPeer.setLcp_echo_failure(modemConfig.getLcpEchoFailure());
    return pppPeer;
}
Also used : PppPeer(org.eclipse.kura.net.admin.modem.PppPeer)

Example 4 with PppPeer

use of org.eclipse.kura.net.admin.modem.PppPeer in project kura by eclipse.

the class HspaModemConfigGenerator method getPppPeer.

@Override
public PppPeer getPppPeer(String deviceId, ModemConfig modemConfig, String logFile, String connectScript, String disconnectScript) {
    PppPeer pppPeer = new PppPeer();
    // default values
    pppPeer.setBaudRate(115200);
    pppPeer.setEnableDebug(true);
    pppPeer.setUseModemControlLines(true);
    pppPeer.setUseRtsCtsFlowControl(false);
    pppPeer.setLockSerialDevice(true);
    pppPeer.setPeerMustAuthenticateItself(false);
    pppPeer.setPeerToSupplyLocalIP(true);
    pppPeer.setAddDefaultRoute(true);
    pppPeer.setUsePeerDns(true);
    pppPeer.setAllowProxyArps(false);
    pppPeer.setAllowVanJacobsonTcpIpHdrCompression(false);
    pppPeer.setAllowVanJacobsonConnectionIDCompression(false);
    pppPeer.setAllowBsdCompression(false);
    pppPeer.setAllowDeflateCompression(false);
    pppPeer.setAllowMagic(false);
    pppPeer.setConnect_delay(1000);
    pppPeer.setLcp_echo_interval(0);
    // other config
    pppPeer.setLogfile(logFile);
    pppPeer.setProvider(deviceId);
    pppPeer.setPppUnitNumber(modemConfig.getPppNumber());
    pppPeer.setConnectScript(connectScript);
    pppPeer.setDisconnectScript(disconnectScript);
    pppPeer.setApn(modemConfig.getApn());
    pppPeer.setAuthType(modemConfig.getAuthType());
    pppPeer.setUsername(modemConfig.getUsername());
    pppPeer.setPassword(modemConfig.getPassword());
    pppPeer.setDialString(modemConfig.getDialString());
    pppPeer.setPersist(modemConfig.isPersist());
    pppPeer.setMaxFail(modemConfig.getMaxFail());
    pppPeer.setIdleTime(modemConfig.getIdle());
    pppPeer.setActiveFilter(modemConfig.getActiveFilter());
    pppPeer.setLcp_echo_interval(modemConfig.getLcpEchoInterval());
    pppPeer.setLcp_echo_failure(modemConfig.getLcpEchoFailure());
    return pppPeer;
}
Also used : PppPeer(org.eclipse.kura.net.admin.modem.PppPeer)

Example 5 with PppPeer

use of org.eclipse.kura.net.admin.modem.PppPeer in project kura by eclipse.

the class TelitDe910ConfigGenerator method getPppPeer.

@Override
public PppPeer getPppPeer(String deviceId, ModemConfig modemConfig, String logFile, String connectScript, String disconnectScript) {
    PppPeer pppPeer = new PppPeer();
    // default values
    pppPeer.setBaudRate(921600);
    pppPeer.setEnableDebug(true);
    pppPeer.setUseRtsCtsFlowControl(true);
    pppPeer.setLockSerialDevice(true);
    pppPeer.setPeerMustAuthenticateItself(false);
    pppPeer.setAddDefaultRoute(true);
    pppPeer.setUsePeerDns(true);
    pppPeer.setAllowProxyArps(true);
    pppPeer.setAllowVanJacobsonTcpIpHdrCompression(true);
    pppPeer.setAllowVanJacobsonConnectionIDCompression(true);
    pppPeer.setAllowBsdCompression(true);
    pppPeer.setAllowDeflateCompression(true);
    pppPeer.setAllowMagic(true);
    pppPeer.setConnect_delay(10000);
    pppPeer.setLcp_echo_failure(4);
    pppPeer.setLcp_echo_interval(65535);
    pppPeer.setLogfile(logFile);
    pppPeer.setProvider(deviceId);
    pppPeer.setPppUnitNumber(modemConfig.getPppNumber());
    pppPeer.setConnectScript(connectScript);
    pppPeer.setDisconnectScript(disconnectScript);
    pppPeer.setDialString(modemConfig.getDialString());
    pppPeer.setPersist(modemConfig.isPersist());
    pppPeer.setMaxFail(modemConfig.getMaxFail());
    pppPeer.setIdleTime(modemConfig.getIdle());
    pppPeer.setActiveFilter(modemConfig.getActiveFilter());
    pppPeer.setLcp_echo_interval(modemConfig.getLcpEchoInterval());
    pppPeer.setLcp_echo_failure(modemConfig.getLcpEchoFailure());
    return pppPeer;
}
Also used : PppPeer(org.eclipse.kura.net.admin.modem.PppPeer)

Aggregations

PppPeer (org.eclipse.kura.net.admin.modem.PppPeer)5 IOException (java.io.IOException)1 KuraException (org.eclipse.kura.KuraException)1 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)1 SupportedUsbModemInfo (org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)1 IP4Address (org.eclipse.kura.net.IP4Address)1 NetConfig (org.eclipse.kura.net.NetConfig)1 NetConfigIP4 (org.eclipse.kura.net.NetConfigIP4)1 ModemPppConfigGenerator (org.eclipse.kura.net.admin.modem.ModemPppConfigGenerator)1 SerialModemFactoryInfo (org.eclipse.kura.net.admin.modem.SupportedSerialModemsFactoryInfo.SerialModemFactoryInfo)1 UsbModemFactoryInfo (org.eclipse.kura.net.admin.modem.SupportedUsbModemsFactoryInfo.UsbModemFactoryInfo)1 ModemXchangeScript (org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangeScript)1 ModemConfig (org.eclipse.kura.net.modem.ModemConfig)1 ModemInterfaceAddressConfig (org.eclipse.kura.net.modem.ModemInterfaceAddressConfig)1 UsbDevice (org.eclipse.kura.usb.UsbDevice)1