Search in sources :

Example 6 with ModemDevice

use of org.eclipse.kura.net.modem.ModemDevice in project kura by eclipse.

the class NetworkServiceImpl method getNetworkInterface.

public NetInterface<? extends NetInterfaceAddress> getNetworkInterface(String interfaceName) throws KuraException {
    // ignore redpine vlan interface
    if (interfaceName.startsWith("rpine")) {
        s_logger.debug("Ignoring redpine vlan interface.");
        return null;
    }
    // ignore usb0 for beaglebone
    if (interfaceName.startsWith("usb0") && "beaglebone".equals(System.getProperty("target.device"))) {
        s_logger.debug("Ignoring usb0 for beaglebone.");
        return null;
    }
    LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
    if (ifconfig == null) {
        s_logger.debug("Ignoring {} interface.", interfaceName);
        return null;
    }
    NetInterfaceType type = ifconfig.getType();
    boolean isUp = ifconfig.isUp();
    if (type == NetInterfaceType.UNKNOWN) {
        if (interfaceName.matches(UNCONFIGURED_MODEM_REGEX)) {
            // If the interface name is in a form such as "1-3.4", assume it is a modem
            type = NetInterfaceType.MODEM;
        } else if (this.m_serialModem != null && interfaceName.equals(this.m_serialModem.getProductName())) {
            type = NetInterfaceType.MODEM;
        }
    }
    if (type == NetInterfaceType.ETHERNET) {
        EthernetInterfaceImpl<NetInterfaceAddress> netInterface = new EthernetInterfaceImpl<NetInterfaceAddress>(interfaceName);
        Map<String, String> driver = LinuxNetworkUtil.getEthernetDriver(interfaceName);
        netInterface.setDriver(driver.get("name"));
        netInterface.setDriverVersion(driver.get("version"));
        netInterface.setFirmwareVersion(driver.get("firmware"));
        netInterface.setAutoConnect(LinuxNetworkUtil.isAutoConnect(interfaceName));
        netInterface.setHardwareAddress(ifconfig.getMacAddressBytes());
        netInterface.setMTU(ifconfig.getMtu());
        netInterface.setSupportsMulticast(ifconfig.isMulticast());
        netInterface.setLinkUp(LinuxNetworkUtil.isLinkUp(type, interfaceName));
        netInterface.setLoopback(false);
        netInterface.setPointToPoint(false);
        netInterface.setUp(isUp);
        netInterface.setVirtual(isVirtual());
        netInterface.setUsbDevice(getUsbDevice(interfaceName));
        netInterface.setState(getState(interfaceName, isUp));
        netInterface.setNetInterfaceAddresses(getNetInterfaceAddresses(interfaceName, type, isUp));
        return netInterface;
    } else if (type == NetInterfaceType.LOOPBACK) {
        LoopbackInterfaceImpl<NetInterfaceAddress> netInterface = new LoopbackInterfaceImpl<NetInterfaceAddress>(interfaceName);
        netInterface.setDriver(getDriver());
        netInterface.setDriverVersion(getDriverVersion());
        netInterface.setFirmwareVersion(getFirmwareVersion());
        netInterface.setAutoConnect(LinuxNetworkUtil.isAutoConnect(interfaceName));
        netInterface.setHardwareAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
        netInterface.setLoopback(true);
        netInterface.setMTU(ifconfig.getMtu());
        netInterface.setSupportsMulticast(ifconfig.isMulticast());
        netInterface.setPointToPoint(false);
        netInterface.setUp(isUp);
        netInterface.setVirtual(false);
        netInterface.setUsbDevice(null);
        netInterface.setState(getState(interfaceName, isUp));
        netInterface.setNetInterfaceAddresses(getNetInterfaceAddresses(interfaceName, type, isUp));
        return netInterface;
    } else if (type == NetInterfaceType.WIFI) {
        WifiInterfaceImpl<WifiInterfaceAddress> wifiInterface = new WifiInterfaceImpl<WifiInterfaceAddress>(interfaceName);
        Map<String, String> driver = LinuxNetworkUtil.getEthernetDriver(interfaceName);
        wifiInterface.setDriver(driver.get("name"));
        wifiInterface.setDriverVersion(driver.get("version"));
        wifiInterface.setFirmwareVersion(driver.get("firmware"));
        wifiInterface.setAutoConnect(LinuxNetworkUtil.isAutoConnect(interfaceName));
        wifiInterface.setHardwareAddress(ifconfig.getMacAddressBytes());
        wifiInterface.setMTU(ifconfig.getMtu());
        wifiInterface.setSupportsMulticast(ifconfig.isMulticast());
        // FIXME:MS Add linkUp in the AbstractNetInterface and populate accordingly
        // wifiInterface.setLinkUp(LinuxNetworkUtil.isLinkUp(type, interfaceName));
        wifiInterface.setLoopback(false);
        wifiInterface.setPointToPoint(false);
        wifiInterface.setUp(isUp);
        wifiInterface.setVirtual(isVirtual());
        wifiInterface.setUsbDevice(getUsbDevice(interfaceName));
        wifiInterface.setState(getState(interfaceName, isUp));
        wifiInterface.setNetInterfaceAddresses(getWifiInterfaceAddresses(interfaceName, isUp));
        wifiInterface.setCapabilities(LinuxNetworkUtil.getWifiCapabilities(interfaceName));
        return wifiInterface;
    } else if (type == NetInterfaceType.MODEM) {
        ModemDevice modemDevice = null;
        if (interfaceName.startsWith("ppp")) {
            // already connected - find the corresponding usb device
            modemDevice = this.m_usbModems.get(getModemUsbPort(interfaceName));
            if (modemDevice == null && this.m_serialModem != null) {
                modemDevice = this.m_serialModem;
            }
        } else if (interfaceName.matches(UNCONFIGURED_MODEM_REGEX)) {
            // the interface name is in the form of a usb port i.e. "1-3.4"
            modemDevice = this.m_usbModems.get(interfaceName);
        } else if (this.m_serialModem != null && interfaceName.equals(this.m_serialModem.getProductName())) {
            modemDevice = this.m_serialModem;
        }
        return modemDevice != null ? getModemInterface(interfaceName, isUp, modemDevice) : null;
    } else {
        if (interfaceName.startsWith("can")) {
            s_logger.trace("Ignoring CAN interface: {}", interfaceName);
        } else if (interfaceName.startsWith("ppp")) {
            s_logger.debug("Ignoring unconfigured ppp interface: {}", interfaceName);
        } else {
            s_logger.debug("Unsupported network type - not adding to network devices: {} of type: ", interfaceName, type.toString());
        }
        return null;
    }
}
Also used : WifiInterfaceImpl(org.eclipse.kura.core.net.WifiInterfaceImpl) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig) EthernetInterfaceImpl(org.eclipse.kura.core.net.EthernetInterfaceImpl) LoopbackInterfaceImpl(org.eclipse.kura.core.net.LoopbackInterfaceImpl) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) NetInterfaceAddress(org.eclipse.kura.net.NetInterfaceAddress) WifiInterfaceAddress(org.eclipse.kura.net.wifi.WifiInterfaceAddress)

Example 7 with ModemDevice

use of org.eclipse.kura.net.modem.ModemDevice in project kura by eclipse.

the class ModemMonitorServiceImpl method activate.

protected void activate(ComponentContext componentContext) {
    // save the bundle context
    this.m_ctx = componentContext;
    this.m_pppState = PppState.NOT_CONNECTED;
    this.m_resetTimerStart = 0L;
    Dictionary<String, String[]> d = new Hashtable<String, String[]>();
    d.put(EventConstants.EVENT_TOPIC, EVENT_TOPICS);
    this.m_ctx.getBundleContext().registerService(EventHandler.class.getName(), this, d);
    this.m_modems = new HashMap<String, CellularModem>();
    this.m_interfaceStatuses = new HashMap<String, InterfaceState>();
    this.m_listeners = new ArrayList<ModemMonitorListener>();
    stopThread = new AtomicBoolean();
    // track currently installed modems
    try {
        this.m_networkConfig = this.m_netConfigService.getNetworkConfiguration();
        for (NetInterface<? extends NetInterfaceAddress> netInterface : this.m_networkService.getNetworkInterfaces()) {
            if (netInterface instanceof ModemInterface) {
                ModemDevice modemDevice = ((ModemInterface<?>) netInterface).getModemDevice();
                trackModem(modemDevice);
            }
        }
    } catch (Exception e) {
        s_logger.error("Error getting installed modems", e);
    }
    stopThread.set(false);
    this.m_executor = Executors.newSingleThreadExecutor();
    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("activate() :: Exception while monitoring cellular connection {}", t);
                }
            }
        }
    });
    this.m_serviceActivated = true;
    s_logger.debug("ModemMonitor activated and ready to receive events");
}
Also used : ModemMonitorListener(org.eclipse.kura.net.modem.ModemMonitorListener) Hashtable(java.util.Hashtable) EventHandler(org.osgi.service.event.EventHandler) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) KuraException(org.eclipse.kura.KuraException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HspaCellularModem(org.eclipse.kura.net.admin.modem.HspaCellularModem) CellularModem(org.eclipse.kura.net.modem.CellularModem) EvdoCellularModem(org.eclipse.kura.net.admin.modem.EvdoCellularModem) ModemInterface(org.eclipse.kura.net.modem.ModemInterface)

Example 8 with ModemDevice

use of org.eclipse.kura.net.modem.ModemDevice in project kura by eclipse.

the class HspaModem method getTechnologyTypes.

@Override
public List<ModemTechnologyType> getTechnologyTypes() throws KuraException {
    List<ModemTechnologyType> modemTechnologyTypes = null;
    ModemDevice device = getModemDevice();
    if (device == null) {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No modem device");
    }
    if (device instanceof UsbModemDevice) {
        SupportedUsbModemInfo usbModemInfo = SupportedUsbModemsInfo.getModem((UsbModemDevice) device);
        if (usbModemInfo != null) {
            modemTechnologyTypes = usbModemInfo.getTechnologyTypes();
        } else {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No usbModemInfo available");
        }
    } else if (device instanceof SerialModemDevice) {
        SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
        if (serialModemInfo != null) {
            modemTechnologyTypes = serialModemInfo.getTechnologyTypes();
        } else {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No serialModemInfo available");
        }
    } else {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Unsupported modem device");
    }
    return modemTechnologyTypes;
}
Also used : UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) KuraException(org.eclipse.kura.KuraException) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)

Example 9 with ModemDevice

use of org.eclipse.kura.net.modem.ModemDevice in project kura by eclipse.

the class SierraMc87xx method getTechnologyTypes.

@Override
public List<ModemTechnologyType> getTechnologyTypes() throws KuraException {
    List<ModemTechnologyType> modemTechnologyTypes = null;
    ModemDevice device = getModemDevice();
    if (device == null) {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No modem device");
    }
    if (device instanceof UsbModemDevice) {
        SupportedUsbModemInfo usbModemInfo = SupportedUsbModemsInfo.getModem((UsbModemDevice) device);
        if (usbModemInfo != null) {
            modemTechnologyTypes = usbModemInfo.getTechnologyTypes();
        } else {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No usbModemInfo available");
        }
    } else {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Unsupported modem device");
    }
    return modemTechnologyTypes;
}
Also used : UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) KuraException(org.eclipse.kura.KuraException) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)

Example 10 with ModemDevice

use of org.eclipse.kura.net.modem.ModemDevice in project kura by eclipse.

the class TelitDe910 method getTechnologyTypes.

@Override
public List<ModemTechnologyType> getTechnologyTypes() throws KuraException {
    List<ModemTechnologyType> modemTechnologyTypes = null;
    ModemDevice device = getModemDevice();
    if (device == null) {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No modem device");
    }
    if (device instanceof UsbModemDevice) {
        SupportedUsbModemInfo usbModemInfo = SupportedUsbModemsInfo.getModem((UsbModemDevice) device);
        if (usbModemInfo != null) {
            modemTechnologyTypes = usbModemInfo.getTechnologyTypes();
        } else {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No usbModemInfo available");
        }
    } else {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Unsupported modem device");
    }
    return modemTechnologyTypes;
}
Also used : UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) KuraException(org.eclipse.kura.KuraException) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)

Aggregations

ModemDevice (org.eclipse.kura.net.modem.ModemDevice)10 KuraException (org.eclipse.kura.KuraException)9 UsbModemDevice (org.eclipse.kura.usb.UsbModemDevice)9 ModemTechnologyType (org.eclipse.kura.net.modem.ModemTechnologyType)7 SerialModemDevice (org.eclipse.kura.net.modem.SerialModemDevice)7 SupportedUsbModemInfo (org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)6 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)2 CellularModem (org.eclipse.kura.net.modem.CellularModem)2 ModemInterface (org.eclipse.kura.net.modem.ModemInterface)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Password (org.eclipse.kura.configuration.Password)1 EthernetInterfaceImpl (org.eclipse.kura.core.net.EthernetInterfaceImpl)1 LoopbackInterfaceImpl (org.eclipse.kura.core.net.LoopbackInterfaceImpl)1 NetworkConfiguration (org.eclipse.kura.core.net.NetworkConfiguration)1 WifiInterfaceImpl (org.eclipse.kura.core.net.WifiInterfaceImpl)1