Search in sources :

Example 1 with LinuxIfconfig

use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.

the class NetworkServiceImpl method getWifiInterfaceAddresses.

private List<WifiInterfaceAddress> getWifiInterfaceAddresses(String interfaceName, boolean isUp) throws KuraException {
    List<WifiInterfaceAddress> wifiInterfaceAddresses = new ArrayList<WifiInterfaceAddress>();
    if (isUp) {
        ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
        WifiInterfaceAddressImpl wifiInterfaceAddress = new WifiInterfaceAddressImpl();
        wifiInterfaceAddresses.add(wifiInterfaceAddress);
        try {
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null) {
                String currentNetmask = ifconfig.getInetMask();
                if (currentNetmask != null) {
                    wifiInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                    wifiInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                    wifiInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
                    wifiInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
                    wifiInterfaceAddress.setGateway(conInfo.getGateway());
                    wifiInterfaceAddress.setDnsServers(conInfo.getDnsServers());
                    WifiMode wifiMode = LinuxNetworkUtil.getWifiMode(interfaceName);
                    wifiInterfaceAddress.setBitrate(LinuxNetworkUtil.getWifiBitrate(interfaceName));
                    wifiInterfaceAddress.setMode(wifiMode);
                    // TODO - should this only be the AP we are connected to in client mode?
                    if (wifiMode == WifiMode.INFRA) {
                        String currentSSID = LinuxNetworkUtil.getSSID(interfaceName);
                        if (currentSSID != null) {
                            s_logger.debug("Adding access point SSID: {}", currentSSID);
                            WifiAccessPointImpl wifiAccessPoint = new WifiAccessPointImpl(currentSSID);
                            // FIXME: fill in other info
                            wifiAccessPoint.setMode(WifiMode.INFRA);
                            List<Long> bitrate = new ArrayList<Long>();
                            bitrate.add(54000000L);
                            wifiAccessPoint.setBitrate(bitrate);
                            wifiAccessPoint.setFrequency(12345);
                            wifiAccessPoint.setHardwareAddress("20AA4B8A6442".getBytes());
                            wifiAccessPoint.setRsnSecurity(EnumSet.allOf(WifiSecurity.class));
                            wifiAccessPoint.setStrength(1234);
                            wifiAccessPoint.setWpaSecurity(EnumSet.allOf(WifiSecurity.class));
                            wifiInterfaceAddress.setWifiAccessPoint(wifiAccessPoint);
                        }
                    }
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } catch (UnknownHostException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
        }
    }
    return wifiInterfaceAddresses;
}
Also used : UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) WifiInterfaceAddressImpl(org.eclipse.kura.core.net.WifiInterfaceAddressImpl) LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig) WifiAccessPointImpl(org.eclipse.kura.core.net.WifiAccessPointImpl) KuraException(org.eclipse.kura.KuraException) WifiMode(org.eclipse.kura.net.wifi.WifiMode) WifiSecurity(org.eclipse.kura.net.wifi.WifiSecurity) WifiInterfaceAddress(org.eclipse.kura.net.wifi.WifiInterfaceAddress) ConnectionInfo(org.eclipse.kura.net.ConnectionInfo)

Example 2 with LinuxIfconfig

use of org.eclipse.kura.linux.net.util.LinuxIfconfig 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;
}
Also used : UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) ModemInterfaceImpl(org.eclipse.kura.core.net.modem.ModemInterfaceImpl) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) ModemInterfaceAddress(org.eclipse.kura.net.modem.ModemInterfaceAddress) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo) WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint) LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig)

Example 3 with LinuxIfconfig

use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.

the class NetworkServiceImpl method getNetInterfaceAddresses.

private List<NetInterfaceAddress> getNetInterfaceAddresses(String interfaceName, NetInterfaceType type, boolean isUp) throws KuraException {
    List<NetInterfaceAddress> netInterfaceAddresses = new ArrayList<NetInterfaceAddress>();
    if (isUp) {
        ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
        NetInterfaceAddressImpl netInterfaceAddress = new NetInterfaceAddressImpl();
        try {
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null) {
                String currentNetmask = ifconfig.getInetMask();
                if (currentNetmask != null) {
                    netInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                    netInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                    netInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
                    netInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
                    netInterfaceAddress.setGateway(conInfo.getGateway());
                    if (type == NetInterfaceType.MODEM) {
                        if (isUp) {
                            netInterfaceAddress.setDnsServers(LinuxDns.getInstance().getPppDnServers());
                        }
                    } else {
                        netInterfaceAddress.setDnsServers(conInfo.getDnsServers());
                    }
                    netInterfaceAddresses.add(netInterfaceAddress);
                }
            }
        } catch (UnknownHostException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
        }
    }
    return netInterfaceAddresses;
}
Also used : UnknownHostException(java.net.UnknownHostException) NetInterfaceAddress(org.eclipse.kura.net.NetInterfaceAddress) KuraException(org.eclipse.kura.KuraException) ArrayList(java.util.ArrayList) ConnectionInfo(org.eclipse.kura.net.ConnectionInfo) NetInterfaceAddressImpl(org.eclipse.kura.core.net.NetInterfaceAddressImpl) LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig)

Example 4 with LinuxIfconfig

use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.

the class Ppp method getIPaddress.

@Override
public String getIPaddress() throws KuraException {
    String ipAddress = null;
    LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(this.m_iface);
    if (ifconfig != null) {
        ipAddress = ifconfig.getInetAddress();
    }
    return ipAddress;
}
Also used : LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig)

Example 5 with LinuxIfconfig

use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.

the class NetworkServiceImpl method getModemInterfaceAddresses.

private List<ModemInterfaceAddress> getModemInterfaceAddresses(String interfaceName, boolean isUp) throws KuraException {
    List<ModemInterfaceAddress> modemInterfaceAddresses = new ArrayList<ModemInterfaceAddress>();
    if (isUp) {
        ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
        ModemInterfaceAddressImpl modemInterfaceAddress = new ModemInterfaceAddressImpl();
        modemInterfaceAddresses.add(modemInterfaceAddress);
        try {
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null) {
                String currentNetmask = ifconfig.getInetMask();
                if (currentNetmask != null) {
                    modemInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                    modemInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                    modemInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
                    modemInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
                    modemInterfaceAddress.setGateway(conInfo.getGateway());
                    modemInterfaceAddress.setDnsServers(conInfo.getDnsServers());
                    ModemConnectionStatus connectionStatus = isUp ? ModemConnectionStatus.CONNECTED : ModemConnectionStatus.DISCONNECTED;
                    modemInterfaceAddress.setConnectionStatus(connectionStatus);
                // TODO - other attributes
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } catch (UnknownHostException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
        }
    }
    return modemInterfaceAddresses;
}
Also used : ModemConnectionStatus(org.eclipse.kura.net.modem.ModemConnectionStatus) UnknownHostException(java.net.UnknownHostException) KuraException(org.eclipse.kura.KuraException) ArrayList(java.util.ArrayList) ConnectionInfo(org.eclipse.kura.net.ConnectionInfo) ModemInterfaceAddress(org.eclipse.kura.net.modem.ModemInterfaceAddress) ModemInterfaceAddressImpl(org.eclipse.kura.core.net.modem.ModemInterfaceAddressImpl) LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig)

Aggregations

LinuxIfconfig (org.eclipse.kura.linux.net.util.LinuxIfconfig)6 UnknownHostException (java.net.UnknownHostException)3 ArrayList (java.util.ArrayList)3 KuraException (org.eclipse.kura.KuraException)3 ConnectionInfo (org.eclipse.kura.net.ConnectionInfo)3 NetInterfaceAddress (org.eclipse.kura.net.NetInterfaceAddress)2 ModemInterfaceAddress (org.eclipse.kura.net.modem.ModemInterfaceAddress)2 SerialModemDevice (org.eclipse.kura.net.modem.SerialModemDevice)2 WifiInterfaceAddress (org.eclipse.kura.net.wifi.WifiInterfaceAddress)2 UsbModemDevice (org.eclipse.kura.usb.UsbModemDevice)2 EthernetInterfaceImpl (org.eclipse.kura.core.net.EthernetInterfaceImpl)1 LoopbackInterfaceImpl (org.eclipse.kura.core.net.LoopbackInterfaceImpl)1 NetInterfaceAddressImpl (org.eclipse.kura.core.net.NetInterfaceAddressImpl)1 WifiAccessPointImpl (org.eclipse.kura.core.net.WifiAccessPointImpl)1 WifiInterfaceAddressImpl (org.eclipse.kura.core.net.WifiInterfaceAddressImpl)1 WifiInterfaceImpl (org.eclipse.kura.core.net.WifiInterfaceImpl)1 ModemInterfaceAddressImpl (org.eclipse.kura.core.net.modem.ModemInterfaceAddressImpl)1 ModemInterfaceImpl (org.eclipse.kura.core.net.modem.ModemInterfaceImpl)1 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)1 SupportedUsbModemInfo (org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)1