Search in sources :

Example 1 with ModemTechnologyType

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

the class NetworkConfiguration method populateNetInterfaceConfiguration.

private void populateNetInterfaceConfiguration(AbstractNetInterface<? extends NetInterfaceAddressConfig> netInterfaceConfig, Map<String, Object> props) throws UnknownHostException, KuraException {
    String interfaceName = netInterfaceConfig.getName();
    StringBuffer keyBuffer = new StringBuffer();
    keyBuffer.append("net.interface.").append(interfaceName).append(".type");
    NetInterfaceType interfaceType = NetInterfaceType.valueOf((String) props.get(keyBuffer.toString()));
    s_logger.trace("Populating interface: {} of type {}", interfaceName, interfaceType);
    // build the prefixes for all the properties associated with this interface
    StringBuilder sbPrefix = new StringBuilder();
    sbPrefix.append("net.interface.").append(interfaceName).append(".");
    String netIfReadOnlyPrefix = sbPrefix.toString();
    String netIfPrefix = sbPrefix.append("config.").toString();
    String netIfConfigPrefix = sbPrefix.toString();
    // [RO] State
    String stateConfig = netIfReadOnlyPrefix + "state";
    if (props.containsKey(stateConfig)) {
        try {
            NetInterfaceState state = (NetInterfaceState) props.get(stateConfig);
            s_logger.trace("got state: {}", state);
            netInterfaceConfig.setState(state);
        } catch (Exception e) {
            s_logger.error("Could not process State configuration. Retaining current value.", e);
        }
    }
    // Auto connect
    boolean autoConnect = false;
    String autoConnectKey = netIfPrefix + "autoconnect";
    if (props.containsKey(autoConnectKey)) {
        autoConnect = (Boolean) props.get(autoConnectKey);
        s_logger.trace("got autoConnect: {}", autoConnect);
        netInterfaceConfig.setAutoConnect(autoConnect);
    }
    // MTU
    String mtuConfig = netIfPrefix + "mtu";
    if (props.containsKey(mtuConfig)) {
        int mtu = (Integer) props.get(mtuConfig);
        s_logger.trace("got MTU: {}", mtu);
        netInterfaceConfig.setMTU(mtu);
    }
    // Driver
    String driverKey = netIfReadOnlyPrefix + "driver";
    if (props.containsKey(driverKey)) {
        String driver = (String) props.get(driverKey);
        s_logger.trace("got Driver: {}", driver);
        netInterfaceConfig.setDriver(driver);
    }
    // Driver Version
    String driverVersionKey = netIfReadOnlyPrefix + "driver.version";
    if (props.containsKey(driverVersionKey)) {
        String driverVersion = (String) props.get(driverVersionKey);
        s_logger.trace("got Driver Version: {}", driverVersion);
        netInterfaceConfig.setDriverVersion(driverVersion);
    }
    // Firmware Version
    String firmwardVersionKey = netIfReadOnlyPrefix + "firmware.version";
    if (props.containsKey(firmwardVersionKey)) {
        String firmwareVersion = (String) props.get(firmwardVersionKey);
        s_logger.trace("got Firmware Version: {}", firmwareVersion);
        netInterfaceConfig.setFirmwareVersion(firmwareVersion);
    }
    // Mac Address
    String macAddressKey = netIfReadOnlyPrefix + "mac";
    if (props.containsKey(macAddressKey)) {
        String macAddress = (String) props.get(macAddressKey);
        s_logger.trace("got Mac Address: {}", macAddress);
        netInterfaceConfig.setHardwareAddress(NetUtil.hardwareAddressToBytes(macAddress));
    }
    // Is Loopback
    String loopbackKey = netIfReadOnlyPrefix + "loopback";
    if (props.containsKey(loopbackKey)) {
        Boolean isLoopback = (Boolean) props.get(loopbackKey);
        s_logger.trace("got Is Loopback: {}", isLoopback);
        netInterfaceConfig.setLoopback(isLoopback);
    }
    // Is Point to Point
    String ptpKey = netIfReadOnlyPrefix + "ptp";
    if (props.containsKey(ptpKey)) {
        Boolean isPtp = (Boolean) props.get(ptpKey);
        s_logger.trace("got Is PtP: {}", isPtp);
        netInterfaceConfig.setPointToPoint(isPtp);
    }
    // Is Up
    String upKey = netIfReadOnlyPrefix + "up";
    if (props.containsKey(upKey)) {
        Boolean isUp = (Boolean) props.get(upKey);
        s_logger.trace("got Is Up: {}", isUp);
        netInterfaceConfig.setUp(isUp);
        if (isUp) {
            netInterfaceConfig.setState(NetInterfaceState.ACTIVATED);
        } else {
            netInterfaceConfig.setState(NetInterfaceState.DISCONNECTED);
        }
    } else {
        s_logger.trace("Setting state to");
        netInterfaceConfig.setState(NetInterfaceState.DISCONNECTED);
    }
    // Is Virtual
    String virtualKey = netIfReadOnlyPrefix + "virtual";
    if (props.containsKey(virtualKey)) {
        Boolean isVirtual = (Boolean) props.get(virtualKey);
        s_logger.trace("got Is Virtual: {}", isVirtual);
        netInterfaceConfig.setVirtual(isVirtual);
    }
    // USB
    String vendorId = (String) props.get(netIfReadOnlyPrefix + "usb.vendor.id");
    String vendorName = (String) props.get(netIfReadOnlyPrefix + "usb.vendor.name");
    String productId = (String) props.get(netIfReadOnlyPrefix + "usb.product.id");
    String productName = (String) props.get(netIfReadOnlyPrefix + "usb.product.name");
    String usbBusNumber = (String) props.get(netIfReadOnlyPrefix + "usb.busNumber");
    String usbDevicePath = (String) props.get(netIfReadOnlyPrefix + "usb.devicePath");
    if (vendorId != null && productId != null) {
        UsbDevice usbDevice = new UsbNetDevice(vendorId, productId, vendorName, productName, usbBusNumber, usbDevicePath, interfaceName);
        s_logger.trace("adding usbDevice: {}, port: {}", usbDevice, usbDevice.getUsbPort());
        netInterfaceConfig.setUsbDevice(usbDevice);
    }
    if (netInterfaceConfig instanceof EthernetInterfaceConfigImpl) {
        // Is Up
        String linkUpKey = netIfReadOnlyPrefix + "eth.link.up";
        if (props.containsKey(linkUpKey)) {
            Boolean linkUp = (Boolean) props.get(linkUpKey);
            s_logger.trace("got Is Link Up: {}", linkUp);
            ((EthernetInterfaceConfigImpl) netInterfaceConfig).setLinkUp(linkUp);
        }
    } else if (netInterfaceConfig instanceof WifiInterfaceConfigImpl) {
        // Wifi Capabilities
        String capabilitiesKey = netIfReadOnlyPrefix + "wifi.capabilities";
        if (props.containsKey(capabilitiesKey)) {
            String capabilitiesString = (String) props.get(capabilitiesKey);
            if (capabilitiesString != null) {
                String[] capabilities = capabilitiesString.split(" ");
                if (capabilities != null && capabilities.length > 0) {
                    EnumSet<Capability> capabilitiesEnum = EnumSet.noneOf(Capability.class);
                    for (String capability : capabilities) {
                        if (capability != null && !capability.isEmpty()) {
                            capabilitiesEnum.add(Capability.valueOf(capability));
                        }
                    }
                    ((WifiInterfaceConfigImpl) netInterfaceConfig).setCapabilities(capabilitiesEnum);
                }
            }
        }
    } else if (netInterfaceConfig instanceof ModemInterfaceConfigImpl) {
        ModemInterfaceConfigImpl modemInterfaceConfig = (ModemInterfaceConfigImpl) netInterfaceConfig;
        String key;
        // manufacturer
        key = netIfReadOnlyPrefix + "manufacturer";
        if (props.containsKey(key)) {
            modemInterfaceConfig.setManufacturer((String) props.get(key));
        }
        // manufacturer
        key = netIfReadOnlyPrefix + "model";
        if (props.containsKey(key)) {
            modemInterfaceConfig.setModel((String) props.get(key));
        }
        // revision id
        key = netIfReadOnlyPrefix + "revisionId";
        if (props.containsKey(key)) {
            String revisionIdString = (String) props.get(key);
            modemInterfaceConfig.setRevisionId(revisionIdString.split(","));
        }
        // serial number
        key = netIfReadOnlyPrefix + "serialNum";
        if (props.containsKey(key)) {
            modemInterfaceConfig.setSerialNumber((String) props.get(key));
        }
        // technology types
        key = netIfReadOnlyPrefix + "technologyTypes";
        if (props.containsKey(key)) {
            ArrayList<ModemTechnologyType> technologyTypes = new ArrayList<ModemTechnologyType>();
            String techTypesString = (String) props.get(netIfReadOnlyPrefix + "technologyTypes");
            if (techTypesString != null && !techTypesString.isEmpty()) {
                for (String techTypeString : techTypesString.split(",")) {
                    if (techTypeString != null && !techTypeString.isEmpty()) {
                        try {
                            ModemTechnologyType modemTechType = ModemTechnologyType.valueOf(techTypeString);
                            technologyTypes.add(modemTechType);
                        } catch (IllegalArgumentException e) {
                            s_logger.error("Could not parse type " + techTypeString);
                        }
                    }
                }
                modemInterfaceConfig.setTechnologyTypes(technologyTypes);
            }
        }
        // modem identifier
        key = netIfConfigPrefix + "identifier";
        if (props.containsKey(key)) {
            modemInterfaceConfig.setModemIdentifier((String) props.get(key));
        }
        // power mode
        key = netIfConfigPrefix + "powerMode";
        if (props.containsKey(key)) {
            ModemPowerMode powerMode = ModemPowerMode.UNKNOWN;
            String modemPowerModeString = (String) props.get(netIfConfigPrefix + "powerMode");
            if (modemPowerModeString != null) {
                powerMode = ModemPowerMode.valueOf(modemPowerModeString);
                modemInterfaceConfig.setPowerMode(powerMode);
            }
        }
        // ppp number
        key = netIfConfigPrefix + "pppNum";
        if (props.containsKey(key)) {
            if (props.get(key) != null) {
                modemInterfaceConfig.setPppNum((Integer) props.get(key));
            }
        }
        // powered on
        key = netIfConfigPrefix + "poweredOn";
        if (props.containsKey(key)) {
            if (props.get(key) != null) {
                modemInterfaceConfig.setPoweredOn((Boolean) props.get(key));
            }
        }
    }
    // Status
    String configStatus4 = null;
    String configStatus4Key = "net.interface." + interfaceName + ".config.ip4.status";
    if (props.containsKey(configStatus4Key)) {
        configStatus4 = (String) props.get(configStatus4Key);
    }
    if (configStatus4 == null) {
        configStatus4 = NetInterfaceStatus.netIPv4StatusDisabled.name();
    }
    s_logger.trace("Status Ipv4? {}", configStatus4);
    String configStatus6 = null;
    String configStatus6Key = "net.interface." + interfaceName + ".config.ip6.status";
    if (props.containsKey(configStatus6Key)) {
        configStatus6 = (String) props.get(configStatus6Key);
    }
    if (configStatus6 == null) {
        configStatus6 = NetInterfaceStatus.netIPv6StatusDisabled.name();
    }
    // POPULATE NetInterfaceAddresses
    for (NetInterfaceAddressConfig netInterfaceAddress : netInterfaceConfig.getNetInterfaceAddresses()) {
        List<NetConfig> netConfigs = new ArrayList<NetConfig>();
        if (netInterfaceAddress instanceof NetInterfaceAddressConfigImpl) {
            ((NetInterfaceAddressConfigImpl) netInterfaceAddress).setNetConfigs(netConfigs);
        } else if (netInterfaceAddress instanceof WifiInterfaceAddressConfigImpl) {
            ((WifiInterfaceAddressConfigImpl) netInterfaceAddress).setNetConfigs(netConfigs);
        } else if (netInterfaceAddress instanceof ModemInterfaceAddressConfigImpl) {
            ((ModemInterfaceAddressConfigImpl) netInterfaceAddress).setNetConfigs(netConfigs);
        }
        // Common NetInterfaceAddress
        if (netInterfaceAddress instanceof NetInterfaceAddressImpl) {
            s_logger.trace("netInterfaceAddress is instanceof NetInterfaceAddressImpl");
            NetInterfaceAddressImpl netInterfaceAddressImpl = (NetInterfaceAddressImpl) netInterfaceAddress;
            // TODO: determine dynamically
            String addressType = ".ip4";
            // populate current address status
            String key = "net.interface." + interfaceName + addressType + ".address";
            if (props.containsKey(key)) {
                IPAddress address = IPAddress.parseHostAddress((String) props.get(key));
                s_logger.trace("got {}: {}", key, address);
                netInterfaceAddressImpl.setAddress(address);
            }
            key = "net.interface." + interfaceName + addressType + ".broadcast";
            if (props.containsKey(key)) {
                IPAddress broadcast = IPAddress.parseHostAddress((String) props.get(key));
                s_logger.trace("got {}: {}", key, broadcast);
                netInterfaceAddressImpl.setBroadcast(broadcast);
            }
            key = "net.interface." + interfaceName + addressType + ".dnsServers";
            if (props.containsKey(key)) {
                List<IPAddress> dnsServers = new ArrayList<IPAddress>();
                String dnsServersString = (String) props.get(key);
                s_logger.trace("got {}: {}", key, dnsServersString);
                for (String dnsServer : dnsServersString.split(",")) {
                    dnsServers.add(IPAddress.parseHostAddress(dnsServer));
                }
                netInterfaceAddressImpl.setDnsServers(dnsServers);
            }
            key = "net.interface." + interfaceName + addressType + ".gateway";
            if (props.containsKey(key)) {
                if (props.get(key) != null && !((String) props.get(key)).trim().equals("")) {
                    IPAddress gateway = IPAddress.parseHostAddress((String) props.get(key));
                    s_logger.trace("got {}: {}", key, gateway);
                    netInterfaceAddressImpl.setGateway(gateway);
                } else {
                    s_logger.trace("got {}: null", key);
                    netInterfaceAddressImpl.setGateway(null);
                }
            }
            key = "net.interface." + interfaceName + addressType + ".netmask";
            if (props.containsKey(key)) {
                IPAddress netmask = IPAddress.parseHostAddress((String) props.get(key));
                s_logger.trace("got {}: {}", key, netmask);
                netInterfaceAddressImpl.setBroadcast(netmask);
            }
            key = "net.interface." + interfaceName + addressType + ".prefix";
            if (props.containsKey(key)) {
                Short prefix = (Short) props.get(key);
                s_logger.trace("got {}: {}", key, prefix);
                netInterfaceAddressImpl.setNetworkPrefixLength(prefix);
            }
        }
        // WifiInterfaceAddress
        if (netInterfaceAddress instanceof WifiInterfaceAddressImpl) {
            s_logger.trace("netInterfaceAddress is instanceof WifiInterfaceAddressImpl");
            WifiInterfaceAddressImpl wifiInterfaceAddressImpl = (WifiInterfaceAddressImpl) netInterfaceAddress;
            // wifi mode
            String configWifiMode = netIfPrefix + "wifi.mode";
            if (props.containsKey(configWifiMode)) {
                // FIXME: INFRA for now while debugging - probably want this as
                WifiMode mode = WifiMode.INFRA;
                // UNKNOWN
                if (props.get(configWifiMode) != null) {
                    mode = WifiMode.valueOf((String) props.get(configWifiMode));
                }
                s_logger.trace("Adding wifiMode: {}", mode);
                wifiInterfaceAddressImpl.setMode(mode);
            }
        }
        // ModemInterfaceAddress
        if (netInterfaceAddress instanceof ModemInterfaceAddressConfigImpl) {
            s_logger.trace("netInterfaceAddress is instanceof ModemInterfaceAddressConfigImpl");
            ModemInterfaceAddressConfigImpl modemInterfaceAddressImpl = (ModemInterfaceAddressConfigImpl) netInterfaceAddress;
            // connection type
            String configConnType = netIfPrefix + "connection.type";
            if (props.containsKey(configConnType)) {
                ModemConnectionType connType = ModemConnectionType.PPP;
                String connTypeStr = (String) props.get(configConnType);
                if (connTypeStr != null && !connTypeStr.isEmpty()) {
                    connType = ModemConnectionType.valueOf(connTypeStr);
                }
                s_logger.trace("Adding modem connection type: {}", connType);
                modemInterfaceAddressImpl.setConnectionType(connType);
            }
            // connection type
            String configConnStatus = netIfPrefix + "connection.status";
            if (props.containsKey(configConnStatus)) {
                ModemConnectionStatus connStatus = ModemConnectionStatus.UNKNOWN;
                String connStatusStr = (String) props.get(configConnStatus);
                if (connStatusStr != null && !connStatusStr.isEmpty()) {
                    connStatus = ModemConnectionStatus.valueOf(connStatusStr);
                }
                s_logger.trace("Adding modem connection status: {}", connStatus);
                modemInterfaceAddressImpl.setConnectionStatus(connStatus);
            }
        }
        // POPULATE NetConfigs
        // dhcp4
        String configDhcp4 = "net.interface." + interfaceName + ".config.dhcpClient4.enabled";
        NetConfigIP4 netConfigIP4 = null;
        boolean dhcpEnabled = false;
        if (props.containsKey(configDhcp4)) {
            dhcpEnabled = (Boolean) props.get(configDhcp4);
            s_logger.trace("DHCP 4 enabled? {}", dhcpEnabled);
        }
        netConfigIP4 = new NetConfigIP4(NetInterfaceStatus.valueOf(configStatus4), autoConnect, dhcpEnabled);
        netConfigs.add(netConfigIP4);
        if (!dhcpEnabled) {
            // NetConfigIP4
            String configIp4 = "net.interface." + interfaceName + ".config.ip4.address";
            if (props.containsKey(configIp4)) {
                s_logger.trace("got {}: {}", configIp4, props.get(configIp4));
                // address
                String addressIp4 = (String) props.get(configIp4);
                s_logger.trace("IPv4 address: {}", addressIp4);
                if (addressIp4 != null && !addressIp4.isEmpty()) {
                    IP4Address ip4Address = (IP4Address) IPAddress.parseHostAddress(addressIp4);
                    netConfigIP4.setAddress(ip4Address);
                }
                // prefix
                String configIp4Prefix = "net.interface." + interfaceName + ".config.ip4.prefix";
                short networkPrefixLength = -1;
                if (props.containsKey(configIp4Prefix)) {
                    if (props.get(configIp4Prefix) instanceof Short) {
                        networkPrefixLength = (Short) props.get(configIp4Prefix);
                    } else if (props.get(configIp4Prefix) instanceof String) {
                        networkPrefixLength = Short.parseShort((String) props.get(configIp4Prefix));
                    }
                    try {
                        netConfigIP4.setNetworkPrefixLength(networkPrefixLength);
                    } catch (KuraException e) {
                        s_logger.error("Exception while setting Network Prefix length!", e);
                    }
                /*
                         * s_logger.trace("IPv4 prefix: " + networkPrefixLength);
                         * netInterfaceAddress.setNetworkPrefixLength(networkPrefixLength);
                         * //FIXME - hack for now
                         * netInterfaceAddress.setBroadcast((IP4Address) IPAddress.parseHostAddress("192.168.1.255"));
                         * ip4Config.setNetworkPrefixLength(networkPrefixLength);
                         */
                }
                // gateway
                String configIp4Gateway = "net.interface." + interfaceName + ".config.ip4.gateway";
                if (props.containsKey(configIp4Gateway)) {
                    String gatewayIp4 = (String) props.get(configIp4Gateway);
                    s_logger.trace("IPv4 gateway: {}", gatewayIp4);
                    if (gatewayIp4 != null && !gatewayIp4.isEmpty()) {
                        IP4Address ip4Gateway = (IP4Address) IPAddress.parseHostAddress(gatewayIp4);
                        netConfigIP4.setGateway(ip4Gateway);
                    }
                }
            }
        }
        // dns servers
        String configDNSs = "net.interface." + interfaceName + ".config.ip4.dnsServers";
        if (props.containsKey(configDNSs)) {
            List<IP4Address> dnsIPs = new ArrayList<IP4Address>();
            String dnsAll = (String) props.get(configDNSs);
            String[] dnss = dnsAll.split(",");
            for (String dns : dnss) {
                if (dns != null && dns.length() > 0) {
                    s_logger.trace("IPv4 DNS: {}", dns);
                    IP4Address dnsIp4 = (IP4Address) IPAddress.parseHostAddress(dns);
                    dnsIPs.add(dnsIp4);
                }
            }
            netConfigIP4.setDnsServers(dnsIPs);
        }
        // win servers
        String configWINSs = "net.interface." + interfaceName + ".config.ip4.winsServers";
        if (props.containsKey(configWINSs)) {
            List<IP4Address> winsIPs = new ArrayList<IP4Address>();
            String winsAll = (String) props.get(configWINSs);
            String[] winss = winsAll.split(",");
            for (String wins : winss) {
                s_logger.trace("WINS: {}", wins);
                IP4Address winsIp4 = (IP4Address) IPAddress.parseHostAddress(wins);
                winsIPs.add(winsIp4);
            }
            netConfigIP4.setWinsServers(winsIPs);
        }
        // domains
        String configDomains = "net.interface." + interfaceName + ".config.ip4.domains";
        if (props.containsKey(configDomains)) {
            List<String> domainNames = new ArrayList<String>();
            String domainsAll = (String) props.get(configDomains);
            String[] domains = domainsAll.split(",");
            for (String domain : domains) {
                s_logger.trace("IPv4 Domain: {}", domain);
                domainNames.add(domain);
            }
            netConfigIP4.setDomains(domainNames);
        }
        // FirewallNatConfig - see if NAT is enabled
        String configNatEnabled = "net.interface." + interfaceName + ".config.nat.enabled";
        if (props.containsKey(configNatEnabled)) {
            boolean natEnabled = (Boolean) props.get(configNatEnabled);
            s_logger.trace("NAT enabled? {}", natEnabled);
            if (natEnabled) {
                FirewallAutoNatConfig natConfig = new FirewallAutoNatConfig(interfaceName, "unknown", true);
                netConfigs.add(natConfig);
            }
        }
        // DhcpServerConfigIP4 - see if there is a DHCP 4 Server
        String configDhcpServerEnabled = "net.interface." + interfaceName + ".config.dhcpServer4.enabled";
        if (props.containsKey(configDhcpServerEnabled)) {
            boolean dhcpServerEnabled = (Boolean) props.get(configDhcpServerEnabled);
            s_logger.trace("DHCP Server 4 enabled? {}", dhcpServerEnabled);
            IP4Address subnet = null;
            IP4Address routerAddress = dhcpEnabled ? (IP4Address) netInterfaceAddress.getAddress() : netConfigIP4.getAddress();
            IP4Address subnetMask = null;
            int defaultLeaseTime = -1;
            int maximumLeaseTime = -1;
            short prefix = -1;
            IP4Address rangeStart = null;
            IP4Address rangeEnd = null;
            boolean passDns = false;
            List<IP4Address> dnServers = new ArrayList<IP4Address>();
            // prefix
            String configDhcpServerPrefix = "net.interface." + interfaceName + ".config.dhcpServer4.prefix";
            if (props.containsKey(configDhcpServerPrefix)) {
                if (props.get(configDhcpServerPrefix) instanceof Short) {
                    prefix = (Short) props.get(configDhcpServerPrefix);
                } else if (props.get(configDhcpServerPrefix) instanceof String) {
                    prefix = Short.parseShort((String) props.get(configDhcpServerPrefix));
                }
                s_logger.trace("DHCP Server prefix: {}", prefix);
            }
            // rangeStart
            String configDhcpServerRangeStart = "net.interface." + interfaceName + ".config.dhcpServer4.rangeStart";
            if (props.containsKey(configDhcpServerRangeStart)) {
                String dhcpServerRangeStart = (String) props.get(configDhcpServerRangeStart);
                s_logger.trace("DHCP Server Range Start: {}", dhcpServerRangeStart);
                if (dhcpServerRangeStart != null && !dhcpServerRangeStart.isEmpty()) {
                    rangeStart = (IP4Address) IPAddress.parseHostAddress(dhcpServerRangeStart);
                }
            }
            // rangeEnd
            String configDhcpServerRangeEnd = "net.interface." + interfaceName + ".config.dhcpServer4.rangeEnd";
            if (props.containsKey(configDhcpServerRangeEnd)) {
                String dhcpServerRangeEnd = (String) props.get(configDhcpServerRangeEnd);
                s_logger.trace("DHCP Server Range End: {}", dhcpServerRangeEnd);
                if (dhcpServerRangeEnd != null && !dhcpServerRangeEnd.isEmpty()) {
                    rangeEnd = (IP4Address) IPAddress.parseHostAddress(dhcpServerRangeEnd);
                }
            }
            // default lease time
            String configDhcpServerDefaultLeaseTime = "net.interface." + interfaceName + ".config.dhcpServer4.defaultLeaseTime";
            if (props.containsKey(configDhcpServerDefaultLeaseTime)) {
                if (props.get(configDhcpServerDefaultLeaseTime) instanceof Integer) {
                    defaultLeaseTime = (Integer) props.get(configDhcpServerDefaultLeaseTime);
                } else if (props.get(configDhcpServerDefaultLeaseTime) instanceof String) {
                    defaultLeaseTime = Integer.parseInt((String) props.get(configDhcpServerDefaultLeaseTime));
                }
                s_logger.trace("DHCP Server Default Lease Time: {}", defaultLeaseTime);
            }
            // max lease time
            String configDhcpServerMaxLeaseTime = "net.interface." + interfaceName + ".config.dhcpServer4.maxLeaseTime";
            if (props.containsKey(configDhcpServerMaxLeaseTime)) {
                if (props.get(configDhcpServerMaxLeaseTime) instanceof Integer) {
                    maximumLeaseTime = (Integer) props.get(configDhcpServerMaxLeaseTime);
                } else if (props.get(configDhcpServerMaxLeaseTime) instanceof String) {
                    maximumLeaseTime = Integer.parseInt((String) props.get(configDhcpServerMaxLeaseTime));
                }
                s_logger.trace("DHCP Server Maximum Lease Time: {}", maximumLeaseTime);
            }
            // passDns
            String configDhcpServerPassDns = "net.interface." + interfaceName + ".config.dhcpServer4.passDns";
            if (props.containsKey(configDhcpServerPassDns)) {
                if (props.get(configDhcpServerPassDns) instanceof Boolean) {
                    passDns = (Boolean) props.get(configDhcpServerPassDns);
                } else if (props.get(configDhcpServerPassDns) instanceof String) {
                    passDns = Boolean.parseBoolean((String) props.get(configDhcpServerPassDns));
                }
                s_logger.trace("DHCP Server Pass DNS?: {}", passDns);
            }
            if (routerAddress != null && rangeStart != null && rangeEnd != null) {
                // get the netmask and subnet
                int prefixInt = prefix;
                int mask = ~((1 << 32 - prefixInt) - 1);
                String subnetMaskString = NetworkUtil.dottedQuad(mask);
                String subnetString = NetworkUtil.calculateNetwork(routerAddress.getHostAddress(), subnetMaskString);
                subnet = (IP4Address) IPAddress.parseHostAddress(subnetString);
                subnetMask = (IP4Address) IPAddress.parseHostAddress(subnetMaskString);
                dnServers.add(routerAddress);
                DhcpServerConfigIP4 dhcpServerConfig = new DhcpServerConfigIP4(interfaceName, dhcpServerEnabled, subnet, routerAddress, subnetMask, defaultLeaseTime, maximumLeaseTime, prefix, rangeStart, rangeEnd, passDns, dnServers);
                netConfigs.add(dhcpServerConfig);
            } else {
                s_logger.trace("Not including DhcpServerConfig - router: " + routerAddress + ", range start: " + rangeStart + ", range end: " + rangeEnd);
            }
        }
        // dhcp6
        String configDhcp6 = "net.interface." + interfaceName + ".config.dhcpClient6.enabled";
        NetConfigIP6 netConfigIP6 = null;
        boolean dhcp6Enabled = false;
        if (props.containsKey(configDhcp6)) {
            dhcp6Enabled = (Boolean) props.get(configDhcp6);
            s_logger.trace("DHCP 6 enabled? {}", dhcp6Enabled);
        }
        if (!dhcp6Enabled) {
            // ip6
            String configIp6 = "net.interface." + interfaceName + ".config.ip6.address";
            if (props.containsKey(configIp6)) {
                // address
                String addressIp6 = (String) props.get(configIp6);
                s_logger.trace("IPv6 address: {}", addressIp6);
                if (addressIp6 != null && !addressIp6.isEmpty()) {
                    IP6Address ip6Address = (IP6Address) IPAddress.parseHostAddress(addressIp6);
                    netConfigIP6.setAddress(ip6Address);
                }
                // dns servers
                String configDNSs6 = "net.interface." + interfaceName + ".config.ip6.dnsServers";
                if (props.containsKey(configDNSs6)) {
                    List<IP6Address> dnsIPs = new ArrayList<IP6Address>();
                    String dnsAll = (String) props.get(configDNSs6);
                    String[] dnss = dnsAll.split(",");
                    for (String dns : dnss) {
                        s_logger.trace("IPv6 DNS: {}", dns);
                        IP6Address dnsIp6 = (IP6Address) IPAddress.parseHostAddress(dns);
                        dnsIPs.add(dnsIp6);
                    }
                    netConfigIP6.setDnsServers(dnsIPs);
                }
                // domains
                String configDomains6 = "net.interface." + interfaceName + ".config.ip6.domains";
                if (props.containsKey(configDomains6)) {
                    List<String> domainNames = new ArrayList<String>();
                    String domainsAll = (String) props.get(configDomains6);
                    String[] domains = domainsAll.split(",");
                    for (String domain : domains) {
                        s_logger.trace("IPv6 Domain: {}", domain);
                        domainNames.add(domain);
                    }
                    netConfigIP6.setDomains(domainNames);
                }
            }
        }
        if (interfaceType == NetInterfaceType.WIFI) {
            s_logger.trace("Adding wifi netconfig");
            // Wifi access point config
            WifiConfig apConfig = getWifiConfig(netIfConfigPrefix, WifiMode.MASTER, props);
            if (apConfig != null) {
                s_logger.trace("Adding AP wifi config");
                netConfigs.add(apConfig);
            } else {
                s_logger.warn("no AP wifi config specified");
            }
            // Wifi client/adhoc config
            // WifiConfig adhocConfig = getWifiConfig(netIfConfigPrefix, WifiMode.ADHOC, props);
            WifiConfig infraConfig = getWifiConfig(netIfConfigPrefix, WifiMode.INFRA, props);
            /*
                 * if(adhocConfig != null && infraConfig != null) {
                 * s_logger.warn("Two conflicting client wifi configs specified");
                 * }
                 */
            if (infraConfig != null) {
                s_logger.trace("Adding client INFRA wifi config");
                netConfigs.add(infraConfig);
            } else {
                s_logger.warn("no INFRA wifi config specified");
            }
        /*
                 * if(adhocConfig != null){
                 * s_logger.trace("Adding client ADHOC wifi config");
                 * netConfigs.add(adhocConfig);
                 * }
                 */
        }
        if (interfaceType == NetInterfaceType.MODEM) {
            s_logger.trace("Adding modem netconfig");
            netConfigs.add(getModemConfig(netIfConfigPrefix, props));
        }
    }
}
Also used : ModemInterfaceAddressConfigImpl(org.eclipse.kura.core.net.modem.ModemInterfaceAddressConfigImpl) FirewallAutoNatConfig(org.eclipse.kura.net.firewall.FirewallAutoNatConfig) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) UsbDevice(org.eclipse.kura.usb.UsbDevice) ArrayList(java.util.ArrayList) KuraException(org.eclipse.kura.KuraException) WifiMode(org.eclipse.kura.net.wifi.WifiMode) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) Capability(org.eclipse.kura.net.wifi.WifiInterface.Capability) IP4Address(org.eclipse.kura.net.IP4Address) IP6Address(org.eclipse.kura.net.IP6Address) ModemConnectionStatus(org.eclipse.kura.net.modem.ModemConnectionStatus) ModemConnectionType(org.eclipse.kura.net.modem.ModemConnectionType) NetConfig(org.eclipse.kura.net.NetConfig) DhcpServerConfigIP4(org.eclipse.kura.net.dhcp.DhcpServerConfigIP4) NetInterfaceState(org.eclipse.kura.net.NetInterfaceState) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) NetConfigIP6(org.eclipse.kura.net.NetConfigIP6) UsbNetDevice(org.eclipse.kura.usb.UsbNetDevice) EnumSet(java.util.EnumSet) ModemPowerMode(org.eclipse.kura.net.modem.ModemPowerMode) KuraException(org.eclipse.kura.KuraException) UnknownHostException(java.net.UnknownHostException) WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) ModemInterfaceConfigImpl(org.eclipse.kura.core.net.modem.ModemInterfaceConfigImpl) IPAddress(org.eclipse.kura.net.IPAddress)

Example 2 with ModemTechnologyType

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

the class ModemMonitorServiceImpl method monitor.

private void monitor() {
    synchronized (s_lock) {
        HashMap<String, InterfaceState> newInterfaceStatuses = new HashMap<String, InterfaceState>();
        if (this.m_modems == null || this.m_modems.isEmpty()) {
            return;
        }
        for (Map.Entry<String, CellularModem> modemEntry : this.m_modems.entrySet()) {
            CellularModem modem = modemEntry.getValue();
            // get signal strength only if somebody needs it
            if (this.m_listeners != null && !this.m_listeners.isEmpty()) {
                for (ModemMonitorListener listener : this.m_listeners) {
                    try {
                        int rssi = modem.getSignalStrength();
                        listener.setCellularSignalLevel(rssi);
                    } catch (KuraException e) {
                        listener.setCellularSignalLevel(0);
                        s_logger.error("monitor() :: Failed to obtain signal strength - {}", e);
                    }
                }
            }
            IModemLinkService pppService = null;
            PppState pppState = null;
            NetInterfaceStatus netInterfaceStatus = getNetInterfaceStatus(modem.getConfiguration());
            try {
                String ifaceName = this.m_networkService.getModemPppPort(modem.getModemDevice());
                if (netInterfaceStatus == NetInterfaceStatus.netIPv4StatusEnabledWAN && ifaceName != null) {
                    pppService = PppFactory.obtainPppService(ifaceName, modem.getDataPort());
                    pppState = pppService.getPppState();
                    if (this.m_pppState != pppState) {
                        s_logger.info("monitor() :: previous PppState={}", this.m_pppState);
                        s_logger.info("monitor() :: current PppState={}", pppState);
                    }
                    if (pppState == PppState.NOT_CONNECTED) {
                        boolean checkIfSimCardReady = false;
                        List<ModemTechnologyType> modemTechnologyTypes = modem.getTechnologyTypes();
                        for (ModemTechnologyType modemTechnologyType : modemTechnologyTypes) {
                            if (modemTechnologyType == ModemTechnologyType.GSM_GPRS || modemTechnologyType == ModemTechnologyType.UMTS || modemTechnologyType == ModemTechnologyType.HSDPA || modemTechnologyType == ModemTechnologyType.HSPA) {
                                checkIfSimCardReady = true;
                                break;
                            }
                        }
                        if (checkIfSimCardReady) {
                            if (((HspaCellularModem) modem).isSimCardReady()) {
                                s_logger.info("monitor() :: !!! SIM CARD IS READY !!! connecting ...");
                                pppService.connect();
                                if (this.m_pppState == PppState.NOT_CONNECTED) {
                                    this.m_resetTimerStart = System.currentTimeMillis();
                                }
                            } else {
                                s_logger.warn("monitor() :: ! SIM CARD IS NOT READY !");
                            }
                        } else {
                            s_logger.info("monitor() :: connecting ...");
                            pppService.connect();
                            if (this.m_pppState == PppState.NOT_CONNECTED) {
                                this.m_resetTimerStart = System.currentTimeMillis();
                            }
                        }
                    } else if (pppState == PppState.IN_PROGRESS) {
                        long modemResetTout = getModemResetTimeoutMsec(ifaceName, modem.getConfiguration());
                        if (modemResetTout > 0) {
                            long timeElapsed = System.currentTimeMillis() - this.m_resetTimerStart;
                            if (timeElapsed > modemResetTout) {
                                // reset modem
                                s_logger.info("monitor() :: Modem Reset TIMEOUT !!!");
                                pppService.disconnect();
                                if (modem.isGpsEnabled() && !disableModemGps(modem)) {
                                    s_logger.error("monitor() :: Failed to disable modem GPS");
                                }
                                modem.reset();
                                pppState = PppState.NOT_CONNECTED;
                                this.m_resetTimerStart = System.currentTimeMillis();
                            } else {
                                int timeTillReset = (int) (modemResetTout - timeElapsed) / 1000;
                                s_logger.info("monitor() :: PPP connection in progress. Modem will be reset in {} sec if not connected", timeTillReset);
                            }
                        }
                    } else if (pppState == PppState.CONNECTED) {
                        this.m_resetTimerStart = System.currentTimeMillis();
                    }
                    this.m_pppState = pppState;
                    ConnectionInfo connInfo = new ConnectionInfoImpl(ifaceName);
                    InterfaceState interfaceState = new InterfaceState(ifaceName, LinuxNetworkUtil.hasAddress(ifaceName), pppState == PppState.CONNECTED, connInfo.getIpAddress());
                    newInterfaceStatuses.put(ifaceName, interfaceState);
                }
                if (modem.isGpsSupported()) {
                    if (isGpsEnabledInConfig(modem.getConfiguration())) {
                        if (modem instanceof HspaCellularModem) {
                            if (!modem.isGpsEnabled()) {
                                modem.enableGps();
                            }
                        }
                        postModemGpsEvent(modem, true);
                    }
                }
            } catch (Exception e) {
                s_logger.error("monitor() :: Exception", e);
                if (pppService != null && pppState != null) {
                    try {
                        s_logger.info("monitor() :: Exception :: PPPD disconnect");
                        pppService.disconnect();
                    } catch (KuraException e1) {
                        s_logger.error("monitor() :: Exception while disconnect", e1);
                    }
                    this.m_pppState = pppState;
                }
                if (modem.isGpsEnabled()) {
                    try {
                        if (!disableModemGps(modem)) {
                            s_logger.error("monitor() :: Failed to disable modem GPS");
                        }
                    } catch (KuraException e1) {
                        s_logger.error("monitor() :: Exception disableModemGps", e1);
                    }
                }
                try {
                    s_logger.info("monitor() :: Exception :: modem reset");
                    modem.reset();
                    this.m_resetTimerStart = System.currentTimeMillis();
                } catch (KuraException e1) {
                    s_logger.error("monitor() :: Exception modem.reset", e1);
                }
            }
        }
        // post event for any status changes
        checkStatusChange(this.m_interfaceStatuses, newInterfaceStatuses);
        this.m_interfaceStatuses = newInterfaceStatuses;
    }
}
Also used : ModemMonitorListener(org.eclipse.kura.net.modem.ModemMonitorListener) HashMap(java.util.HashMap) NetInterfaceStatus(org.eclipse.kura.net.NetInterfaceStatus) IModemLinkService(org.eclipse.kura.net.admin.modem.IModemLinkService) HspaCellularModem(org.eclipse.kura.net.admin.modem.HspaCellularModem) KuraException(org.eclipse.kura.KuraException) HspaCellularModem(org.eclipse.kura.net.admin.modem.HspaCellularModem) CellularModem(org.eclipse.kura.net.modem.CellularModem) EvdoCellularModem(org.eclipse.kura.net.admin.modem.EvdoCellularModem) KuraException(org.eclipse.kura.KuraException) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) ConnectionInfo(org.eclipse.kura.net.ConnectionInfo) Map(java.util.Map) HashMap(java.util.HashMap) PppState(org.eclipse.kura.net.admin.modem.PppState) ConnectionInfoImpl(org.eclipse.kura.linux.net.ConnectionInfoImpl)

Example 3 with ModemTechnologyType

use of org.eclipse.kura.net.modem.ModemTechnologyType 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;
}
Also used : SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ModemConfig(org.eclipse.kura.net.modem.ModemConfig) ModemXchangeScript(org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangeScript) KuraException(org.eclipse.kura.KuraException) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) AuthType(org.eclipse.kura.net.modem.ModemConfig.AuthType) ModemXchangePair(org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangePair) File(java.io.File) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)

Example 4 with ModemTechnologyType

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

the class TelitHe910 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 5 with ModemTechnologyType

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

the class GwtNetworkServiceImpl method privateFindNetInterfaceConfigurations.

@SuppressWarnings({ "unchecked", "rawtypes" })
private List<GwtNetInterfaceConfig> privateFindNetInterfaceConfigurations() throws GwtKuraException {
    s_logger.debug("Starting");
    List<GwtNetInterfaceConfig> gwtNetConfigs = new ArrayList<GwtNetInterfaceConfig>();
    NetworkAdminService nas = null;
    try {
        nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    } catch (Throwable t) {
        s_logger.warn("Exception", t);
        return gwtNetConfigs;
    }
    ModemManagerService modemManagerService = null;
    try {
        modemManagerService = ServiceLocator.getInstance().getService(ModemManagerService.class);
    } catch (Throwable t) {
        s_logger.warn("{ModemManagerService} Exception", t);
    }
    WifiClientMonitorService wifiClientMonitorService = null;
    try {
        wifiClientMonitorService = ServiceLocator.getInstance().getService(WifiClientMonitorService.class);
    } catch (Throwable t) {
        s_logger.warn("{WifiClientMonitorService} Exception", t);
    }
    try {
        GwtNetInterfaceConfig gwtNetConfig = null;
        for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netIfConfig : nas.getNetworkInterfaceConfigs()) {
            s_logger.debug("Getting config for {} with type {}", netIfConfig.getName(), netIfConfig.getType());
            s_logger.debug("Interface State: {}", netIfConfig.getState());
            if (netIfConfig.getType() == NetInterfaceType.WIFI) {
                gwtNetConfig = new GwtWifiNetInterfaceConfig();
            } else if (netIfConfig.getType() == NetInterfaceType.MODEM) {
                gwtNetConfig = new GwtModemInterfaceConfig();
                ((GwtModemInterfaceConfig) gwtNetConfig).setModemId(((ModemInterface) netIfConfig).getModemIdentifier());
                ((GwtModemInterfaceConfig) gwtNetConfig).setManufacturer(((ModemInterface) netIfConfig).getManufacturer());
                ((GwtModemInterfaceConfig) gwtNetConfig).setModel(((ModemInterface) netIfConfig).getModel());
                List<String> technologyList = new ArrayList<String>();
                List<ModemTechnologyType> technologyTypes = ((ModemInterface) netIfConfig).getTechnologyTypes();
                if (technologyTypes != null) {
                    for (ModemTechnologyType techType : technologyTypes) {
                        technologyList.add(techType.name());
                    }
                }
                ((GwtModemInterfaceConfig) gwtNetConfig).setNetworkTechnology(technologyList);
            } else {
                gwtNetConfig = new GwtNetInterfaceConfig();
                gwtNetConfig.setHwRssi("N/A");
            }
            gwtNetConfig.setName(netIfConfig.getName());
            gwtNetConfig.setHwName(netIfConfig.getName());
            if (netIfConfig.getType() != null) {
                gwtNetConfig.setHwType(netIfConfig.getType().name());
            }
            if (netIfConfig.getState() != null) {
                gwtNetConfig.setHwState(netIfConfig.getState().name());
            }
            s_logger.debug("MAC: {}", NetUtil.hardwareAddressToString(netIfConfig.getHardwareAddress()));
            gwtNetConfig.setHwAddress(NetUtil.hardwareAddressToString(netIfConfig.getHardwareAddress()));
            gwtNetConfig.setHwDriver(netIfConfig.getDriver());
            gwtNetConfig.setHwDriverVersion(netIfConfig.getDriverVersion());
            gwtNetConfig.setHwFirmware(netIfConfig.getFirmwareVersion());
            gwtNetConfig.setHwMTU(netIfConfig.getMTU());
            if (netIfConfig.getUsbDevice() != null) {
                gwtNetConfig.setHwUsbDevice(netIfConfig.getUsbDevice().getUsbDevicePath());
            } else {
                gwtNetConfig.setHwUsbDevice("N/A");
            }
            List<? extends NetInterfaceAddressConfig> addressConfigs = netIfConfig.getNetInterfaceAddresses();
            if (addressConfigs != null && !addressConfigs.isEmpty()) {
                for (NetInterfaceAddressConfig addressConfig : addressConfigs) {
                    // current status - not configuration!
                    if (addressConfig.getAddress() != null) {
                        s_logger.debug("current address: {}", addressConfig.getAddress().getHostAddress());
                    }
                    if (addressConfig.getNetworkPrefixLength() >= 0 && addressConfig.getNetworkPrefixLength() <= 32) {
                        s_logger.debug("current prefix length: {}", addressConfig.getNetworkPrefixLength());
                    }
                    if (addressConfig.getNetmask() != null) {
                        s_logger.debug("current netmask: {}", addressConfig.getNetmask().getHostAddress());
                    }
                    List<NetConfig> netConfigs = addressConfig.getConfigs();
                    if (netConfigs != null && !netConfigs.isEmpty()) {
                        boolean isNatEnabled = false;
                        boolean isDhcpServerEnabled = false;
                        for (NetConfig netConfig : netConfigs) {
                            if (netConfig instanceof NetConfigIP4) {
                                s_logger.debug("Setting up NetConfigIP4 with status {}", ((NetConfigIP4) netConfig).getStatus().toString());
                                // we are enabled - for LAN or WAN?
                                if (((NetConfigIP4) netConfig).getStatus() == NetInterfaceStatus.netIPv4StatusEnabledLAN) {
                                    gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusEnabledLAN.name());
                                } else if (((NetConfigIP4) netConfig).getStatus() == NetInterfaceStatus.netIPv4StatusEnabledWAN) {
                                    gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusEnabledWAN.name());
                                } else {
                                    gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusDisabled.name());
                                }
                                if (((NetConfigIP4) netConfig).isDhcp()) {
                                    gwtNetConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name());
                                    // since DHCP - populate current data
                                    if (addressConfig.getAddress() != null) {
                                        gwtNetConfig.setIpAddress(addressConfig.getAddress().getHostAddress());
                                    } else {
                                        gwtNetConfig.setIpAddress("");
                                    }
                                    if (addressConfig.getNetworkPrefixLength() >= 0 && addressConfig.getNetworkPrefixLength() <= 32) {
                                        gwtNetConfig.setSubnetMask(NetworkUtil.getNetmaskStringForm(addressConfig.getNetworkPrefixLength()));
                                    } else {
                                        if (addressConfig.getNetmask() != null) {
                                            gwtNetConfig.setSubnetMask(addressConfig.getNetmask().getHostAddress());
                                        } else {
                                            gwtNetConfig.setSubnetMask("");
                                        }
                                    }
                                    if (addressConfig.getGateway() != null) {
                                        gwtNetConfig.setGateway(addressConfig.getGateway().getHostAddress());
                                    } else {
                                        gwtNetConfig.setGateway("");
                                    }
                                    // DHCP supplied DNS servers
                                    StringBuffer sb = new StringBuffer();
                                    List<? extends IPAddress> dnsServers = addressConfig.getDnsServers();
                                    if (dnsServers != null && !dnsServers.isEmpty()) {
                                        String sep = "";
                                        for (IPAddress dnsServer : dnsServers) {
                                            sb.append(sep).append(dnsServer.getHostAddress());
                                            sep = "\n";
                                        }
                                        s_logger.debug("DNS Servers: {}", sb);
                                        gwtNetConfig.setReadOnlyDnsServers(sb.toString());
                                    } else {
                                        s_logger.debug("DNS Servers: [empty String]");
                                        gwtNetConfig.setReadOnlyDnsServers("");
                                    }
                                } else {
                                    gwtNetConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeManual.name());
                                    // TODO - should we throw an error if current state doesn't match configuration?
                                    if (((NetConfigIP4) netConfig).getAddress() != null) {
                                        gwtNetConfig.setIpAddress(((NetConfigIP4) netConfig).getAddress().getHostAddress());
                                    } else {
                                        gwtNetConfig.setIpAddress("");
                                    }
                                    if (((NetConfigIP4) netConfig).getSubnetMask() != null) {
                                        gwtNetConfig.setSubnetMask(((NetConfigIP4) netConfig).getSubnetMask().getHostAddress());
                                    } else {
                                        gwtNetConfig.setSubnetMask("");
                                    }
                                    if (((NetConfigIP4) netConfig).getGateway() != null) {
                                        s_logger.debug("Gateway for {} is: {}", netIfConfig.getName(), ((NetConfigIP4) netConfig).getGateway().getHostAddress());
                                        gwtNetConfig.setGateway(((NetConfigIP4) netConfig).getGateway().getHostAddress());
                                    } else {
                                        gwtNetConfig.setGateway("");
                                    }
                                }
                                // Custom DNS servers
                                StringBuffer sb = new StringBuffer();
                                List<IP4Address> dnsServers = ((NetConfigIP4) netConfig).getDnsServers();
                                if (dnsServers != null && !dnsServers.isEmpty()) {
                                    for (IP4Address dnsServer : dnsServers) {
                                        if (!dnsServer.getHostAddress().equals("127.0.0.1")) {
                                            sb.append(' ').append(dnsServer.getHostAddress());
                                        }
                                    }
                                    s_logger.debug("DNS Servers: {}", sb);
                                    gwtNetConfig.setDnsServers(sb.toString().trim());
                                } else {
                                    s_logger.debug("DNS Servers: [empty String]");
                                    gwtNetConfig.setDnsServers("");
                                }
                                // Search domains
                                sb = new StringBuffer();
                                List<IP4Address> winsServers = ((NetConfigIP4) netConfig).getWinsServers();
                                if (winsServers != null && !winsServers.isEmpty()) {
                                    for (IP4Address winServer : winsServers) {
                                        sb.append(winServer.getHostAddress());
                                        sb.append("\n");
                                    }
                                    s_logger.debug("Search Domains: {}", sb);
                                    gwtNetConfig.setSearchDomains(sb.toString());
                                } else {
                                    s_logger.debug("Search Domains: [empty String]");
                                    gwtNetConfig.setSearchDomains("");
                                }
                            }
                            // config
                            if (netConfig instanceof WifiConfig) {
                                s_logger.debug("Setting up WifiConfigIP4");
                                WifiConfig wifiConfig = (WifiConfig) netConfig;
                                GwtWifiConfig gwtWifiConfig = new GwtWifiConfig();
                                // mode
                                if (wifiConfig.getMode() == WifiMode.MASTER) {
                                    gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name());
                                    // set as the access point config for this interface
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setAccessPointWifiConfig(gwtWifiConfig);
                                } else if (wifiConfig.getMode() == WifiMode.INFRA) {
                                    gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeStation.name());
                                    // set as the station config for this interface
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setStationWifiConfig(gwtWifiConfig);
                                } else if (wifiConfig.getMode() == WifiMode.ADHOC) {
                                    gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAdHoc.name());
                                    // set as the adhoc config for this interface
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setAdhocWifiConfig(gwtWifiConfig);
                                }
                                // ssid
                                gwtWifiConfig.setWirelessSsid(wifiConfig.getSSID());
                                // driver
                                gwtWifiConfig.setDriver(wifiConfig.getDriver());
                                // security
                                if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA.name());
                                } else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA2) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA2.name());
                                } else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA_WPA2) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA_WPA2.name());
                                } else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WEP) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWEP.name());
                                } else {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityNONE.name());
                                }
                                if (wifiConfig.getPairwiseCiphers() == WifiCiphers.CCMP_TKIP) {
                                    gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name());
                                } else if (wifiConfig.getPairwiseCiphers() == WifiCiphers.TKIP) {
                                    gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_TKIP.name());
                                } else if (wifiConfig.getPairwiseCiphers() == WifiCiphers.CCMP) {
                                    gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_CCMP.name());
                                }
                                if (wifiConfig.getGroupCiphers() == WifiCiphers.CCMP_TKIP) {
                                    gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name());
                                } else if (wifiConfig.getGroupCiphers() == WifiCiphers.TKIP) {
                                    gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_TKIP.name());
                                } else if (wifiConfig.getGroupCiphers() == WifiCiphers.CCMP) {
                                    gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_CCMP.name());
                                }
                                // bgscan
                                WifiBgscan wifiBgscan = wifiConfig.getBgscan();
                                if (wifiBgscan != null) {
                                    if (wifiBgscan.getModule() == WifiBgscanModule.NONE) {
                                        gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_NONE.name());
                                    } else if (wifiBgscan.getModule() == WifiBgscanModule.SIMPLE) {
                                        gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_SIMPLE.name());
                                    } else if (wifiBgscan.getModule() == WifiBgscanModule.LEARN) {
                                        gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_LEARN.name());
                                    }
                                    gwtWifiConfig.setBgscanRssiThreshold(wifiBgscan.getRssiThreshold());
                                    gwtWifiConfig.setBgscanShortInterval(wifiBgscan.getShortInterval());
                                    gwtWifiConfig.setBgscanLongInterval(wifiBgscan.getLongInterval());
                                }
                                // ping access point?
                                gwtWifiConfig.setPingAccessPoint(wifiConfig.pingAccessPoint());
                                // ignore SSID?
                                gwtWifiConfig.setIgnoreSSID(wifiConfig.ignoreSSID());
                                // passkey
                                Password psswd = wifiConfig.getPasskey();
                                if (psswd != null) {
                                    String password = new String(psswd.getPassword());
                                    gwtWifiConfig.setPassword(password);
                                }
                                // channel
                                int[] channels = wifiConfig.getChannels();
                                if (channels != null) {
                                    ArrayList<Integer> alChannels = new ArrayList<Integer>();
                                    for (int channel : channels) {
                                        alChannels.add(new Integer(channel));
                                    }
                                    gwtWifiConfig.setChannels(alChannels);
                                }
                                // radio mode
                                GwtWifiRadioMode gwtWifiRadioMode = null;
                                if (wifiConfig.getRadioMode() != null) {
                                    switch(wifiConfig.getRadioMode()) {
                                        case RADIO_MODE_80211a:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeA;
                                            break;
                                        case RADIO_MODE_80211b:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeB;
                                            break;
                                        case RADIO_MODE_80211g:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeBG;
                                            break;
                                        case RADIO_MODE_80211nHT20:
                                        case RADIO_MODE_80211nHT40above:
                                        case RADIO_MODE_80211nHT40below:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeBGN;
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                if (gwtWifiRadioMode != null) {
                                    gwtWifiConfig.setRadioMode(gwtWifiRadioMode.name());
                                }
                                // set the currently active mode based on the address config
                                WifiMode activeWirelessMode = ((WifiInterfaceAddressConfig) addressConfig).getMode();
                                if (activeWirelessMode == WifiMode.MASTER) {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name());
                                    gwtNetConfig.setHwRssi("N/A");
                                } else if (activeWirelessMode == WifiMode.INFRA) {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeStation.name());
                                    if (wifiClientMonitorService != null) {
                                        if (wifiConfig.getMode().equals(WifiMode.INFRA)) {
                                            if (gwtNetConfig.getStatus().equals(GwtNetIfStatus.netIPv4StatusDisabled.name())) {
                                                gwtNetConfig.setHwRssi("N/A");
                                            } else {
                                                try {
                                                    int rssi = wifiClientMonitorService.getSignalLevel(netIfConfig.getName(), wifiConfig.getSSID());
                                                    s_logger.debug("Setting Received Signal Strength to {}", rssi);
                                                    gwtNetConfig.setHwRssi(Integer.toString(rssi));
                                                } catch (KuraException e) {
                                                    s_logger.warn("Failed", e);
                                                }
                                            }
                                        }
                                    }
                                } else if (activeWirelessMode == WifiMode.ADHOC) {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAdHoc.name());
                                    gwtNetConfig.setHwRssi("N/A");
                                } else {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeDisabled.name());
                                    gwtNetConfig.setHwRssi("N/A");
                                }
                            }
                            if (netConfig instanceof ModemConfig) {
                                s_logger.debug("Setting up ModemConfig");
                                ModemConfig modemConfig = (ModemConfig) netConfig;
                                GwtModemInterfaceConfig gwtModemConfig = (GwtModemInterfaceConfig) gwtNetConfig;
                                if (modemManagerService != null) {
                                    UsbDevice usbDevice = netIfConfig.getUsbDevice();
                                    String modemServiceId = null;
                                    if (usbDevice != null) {
                                        modemServiceId = netIfConfig.getUsbDevice().getUsbPort();
                                    } else {
                                        Collection<CellularModem> modemServices = modemManagerService.getAllModemServices();
                                        for (CellularModem modemService : modemServices) {
                                            ModemDevice modemDevice = modemService.getModemDevice();
                                            if (modemDevice instanceof SerialModemDevice) {
                                                modemServiceId = modemDevice.getProductName();
                                                break;
                                            }
                                        }
                                    }
                                    if (modemServiceId != null) {
                                        CellularModem cellModemService = modemManagerService.getModemService(modemServiceId);
                                        if (cellModemService != null) {
                                            try {
                                                String imei = cellModemService.getSerialNumber();
                                                s_logger.debug("Setting IMEI/MEID to {}", imei);
                                                gwtModemConfig.setHwSerial(imei);
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get IMEI from modem", e);
                                            }
                                            try {
                                                int rssi = cellModemService.getSignalStrength();
                                                s_logger.debug("Setting Received Signal Strength to {}", rssi);
                                                gwtModemConfig.setHwRssi(Integer.toString(rssi));
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get Received Signal Strength from modem", e);
                                            }
                                            try {
                                                String sModel = cellModemService.getModel();
                                                ((GwtModemInterfaceConfig) gwtNetConfig).setModel(sModel);
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get model information from modem", e);
                                            }
                                            try {
                                                boolean gpsSupported = cellModemService.isGpsSupported();
                                                s_logger.debug("Setting GPS supported to {}", gpsSupported);
                                                ((GwtModemInterfaceConfig) gwtNetConfig).setGpsSupported(gpsSupported);
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get GPS supported from modem", e);
                                            }
                                        }
                                    }
                                }
                                // set as DHCP - populate current address
                                gwtModemConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name());
                                if (addressConfig.getAddress() != null) {
                                    gwtModemConfig.setIpAddress(addressConfig.getAddress().getHostAddress());
                                }
                                if (addressConfig.getNetmask() != null) {
                                    gwtModemConfig.setSubnetMask(addressConfig.getNetmask().getHostAddress());
                                }
                                gwtModemConfig.setDialString(modemConfig.getDialString());
                                AuthType authType = modemConfig.getAuthType();
                                if (authType == AuthType.AUTO) {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthAUTO);
                                } else if (authType == AuthType.CHAP) {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthCHAP);
                                } else if (authType == AuthType.PAP) {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthPAP);
                                } else {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthNONE);
                                }
                                gwtModemConfig.setUsername(modemConfig.getUsername());
                                gwtModemConfig.setPassword(modemConfig.getPassword());
                                gwtModemConfig.setPppNum(modemConfig.getPppNumber());
                                gwtModemConfig.setResetTimeout(modemConfig.getResetTimeout());
                                gwtModemConfig.setPersist(modemConfig.isPersist());
                                gwtModemConfig.setMaxFail(modemConfig.getMaxFail());
                                gwtModemConfig.setIdle(modemConfig.getIdle());
                                gwtModemConfig.setActiveFilter(modemConfig.getActiveFilter());
                                gwtModemConfig.setLcpEchoInterval(modemConfig.getLcpEchoInterval());
                                gwtModemConfig.setLcpEchoFailure(modemConfig.getLcpEchoFailure());
                                gwtModemConfig.setGpsEnabled(modemConfig.isGpsEnabled());
                                gwtModemConfig.setProfileID(modemConfig.getProfileID());
                                PdpType pdpType = modemConfig.getPdpType();
                                if (pdpType == PdpType.IP) {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpIP);
                                } else if (pdpType == PdpType.PPP) {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpPPP);
                                } else if (pdpType == PdpType.IPv6) {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpIPv6);
                                } else {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpUnknown);
                                }
                                gwtModemConfig.setApn(modemConfig.getApn());
                                gwtModemConfig.setDataCompression(modemConfig.getDataCompression());
                                gwtModemConfig.setHeaderCompression(modemConfig.getHeaderCompression());
                                ModemConnectionStatus connectionStatus = ((ModemInterfaceAddressConfig) addressConfig).getConnectionStatus();
                                if (connectionStatus == ModemConnectionStatus.DISCONNECTED) {
                                    gwtModemConfig.setHwState(NetInterfaceState.DISCONNECTED.name());
                                } else if (connectionStatus == ModemConnectionStatus.CONNECTING) {
                                    gwtModemConfig.setHwState(NetInterfaceState.IP_CONFIG.name());
                                } else if (connectionStatus == ModemConnectionStatus.CONNECTED) {
                                    gwtModemConfig.setHwState(NetInterfaceState.ACTIVATED.name());
                                } else {
                                    gwtModemConfig.setHwState(NetInterfaceState.UNKNOWN.name());
                                }
                                gwtModemConfig.setConnectionType(((ModemInterfaceAddressConfig) addressConfig).getConnectionType().name());
                            }
                            if (netConfig instanceof DhcpServerConfigIP4) {
                                s_logger.debug("Setting up DhcpServerConfigIP4: {} to {}", ((DhcpServerConfigIP4) netConfig).getRangeStart().getHostAddress(), ((DhcpServerConfigIP4) netConfig).getRangeEnd().getHostAddress());
                                s_logger.debug("Setting up DhcpServerConfigIP4: {}", ((DhcpServerConfigIP4) netConfig).toString());
                                isDhcpServerEnabled = ((DhcpServerConfigIP4) netConfig).isEnabled();
                                gwtNetConfig.setRouterDhcpBeginAddress(((DhcpServerConfigIP4) netConfig).getRangeStart().getHostAddress());
                                gwtNetConfig.setRouterDhcpEndAddress(((DhcpServerConfigIP4) netConfig).getRangeEnd().getHostAddress());
                                gwtNetConfig.setRouterDhcpSubnetMask(((DhcpServerConfigIP4) netConfig).getSubnetMask().getHostAddress());
                                gwtNetConfig.setRouterDhcpDefaultLease(((DhcpServerConfigIP4) netConfig).getDefaultLeaseTime());
                                gwtNetConfig.setRouterDhcpMaxLease(((DhcpServerConfigIP4) netConfig).getMaximumLeaseTime());
                                gwtNetConfig.setRouterDnsPass(((DhcpServerConfigIP4) netConfig).isPassDns());
                            }
                            if (netConfig instanceof FirewallAutoNatConfig) {
                                s_logger.debug("Setting up FirewallAutoNatConfig");
                                isNatEnabled = true;
                            }
                        // TODO - only dealing with IPv4 right now
                        }
                        // set up the DHCP and NAT config
                        if (isDhcpServerEnabled && isNatEnabled) {
                            s_logger.debug("setting router mode to DHCP and NAT");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterDchpNat.name());
                        } else if (isDhcpServerEnabled && !isNatEnabled) {
                            s_logger.debug("setting router mode to DHCP only");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterDchp.name());
                        } else if (!isDhcpServerEnabled && isNatEnabled) {
                            s_logger.debug("setting router mode to NAT only");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterNat.name());
                        } else {
                            s_logger.debug("setting router mode to disabled");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterOff.name());
                        }
                    }
                }
            }
            gwtNetConfigs.add(gwtNetConfig);
        }
    } catch (Throwable t) {
        KuraExceptionHandler.handle(t);
    }
    s_logger.debug("Returning");
    return gwtNetConfigs;
}
Also used : SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) FirewallAutoNatConfig(org.eclipse.kura.net.firewall.FirewallAutoNatConfig) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) GwtWifiConfig(org.eclipse.kura.web.shared.model.GwtWifiConfig) ArrayList(java.util.ArrayList) ModemManagerService(org.eclipse.kura.net.modem.ModemManagerService) UsbDevice(org.eclipse.kura.usb.UsbDevice) WifiClientMonitorService(org.eclipse.kura.net.wifi.WifiClientMonitorService) WifiInterfaceAddressConfig(org.eclipse.kura.net.wifi.WifiInterfaceAddressConfig) GwtWifiRadioMode(org.eclipse.kura.web.shared.model.GwtWifiRadioMode) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) CellularModem(org.eclipse.kura.net.modem.CellularModem) KuraException(org.eclipse.kura.KuraException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) WifiMode(org.eclipse.kura.net.wifi.WifiMode) ModemInterfaceAddressConfig(org.eclipse.kura.net.modem.ModemInterfaceAddressConfig) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) List(java.util.List) ArrayList(java.util.ArrayList) GwtModemInterfaceConfig(org.eclipse.kura.web.shared.model.GwtModemInterfaceConfig) AuthType(org.eclipse.kura.net.modem.ModemConfig.AuthType) GwtModemAuthType(org.eclipse.kura.web.shared.model.GwtModemAuthType) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) ModemInterface(org.eclipse.kura.net.modem.ModemInterface) IP4Address(org.eclipse.kura.net.IP4Address) ModemConnectionStatus(org.eclipse.kura.net.modem.ModemConnectionStatus) ModemConfig(org.eclipse.kura.net.modem.ModemConfig) NetConfig(org.eclipse.kura.net.NetConfig) DhcpServerConfigIP4(org.eclipse.kura.net.dhcp.DhcpServerConfigIP4) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) GwtNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig) Password(org.eclipse.kura.configuration.Password) PdpType(org.eclipse.kura.net.modem.ModemConfig.PdpType) GwtModemPdpType(org.eclipse.kura.web.shared.model.GwtModemPdpType) GwtWifiConfig(org.eclipse.kura.web.shared.model.GwtWifiConfig) GwtWifiNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtWifiNetInterfaceConfig) WifiBgscan(org.eclipse.kura.net.wifi.WifiBgscan) NetworkAdminService(org.eclipse.kura.net.NetworkAdminService) IPAddress(org.eclipse.kura.net.IPAddress)

Aggregations

ModemTechnologyType (org.eclipse.kura.net.modem.ModemTechnologyType)11 KuraException (org.eclipse.kura.KuraException)10 SupportedUsbModemInfo (org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)7 ModemDevice (org.eclipse.kura.net.modem.ModemDevice)7 UsbModemDevice (org.eclipse.kura.usb.UsbModemDevice)6 SerialModemDevice (org.eclipse.kura.net.modem.SerialModemDevice)4 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)3 IPAddress (org.eclipse.kura.net.IPAddress)3 NetConfig (org.eclipse.kura.net.NetConfig)3 NetConfigIP4 (org.eclipse.kura.net.NetConfigIP4)3 NetInterfaceAddressConfig (org.eclipse.kura.net.NetInterfaceAddressConfig)3 FirewallAutoNatConfig (org.eclipse.kura.net.firewall.FirewallAutoNatConfig)3 ModemConfig (org.eclipse.kura.net.modem.ModemConfig)3 WifiConfig (org.eclipse.kura.net.wifi.WifiConfig)3 WifiMode (org.eclipse.kura.net.wifi.WifiMode)3 UsbDevice (org.eclipse.kura.usb.UsbDevice)3 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2