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;
}
}
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");
}
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;
}
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;
}
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;
}
Aggregations