Search in sources :

Example 1 with ModemConfig

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

the class NetworkConfiguration method getModemConfig.

private static ModemConfig getModemConfig(String prefix, Map<String, Object> properties) throws KuraException {
    String key;
    ModemConfig modemConfig = new ModemConfig();
    // apn
    key = prefix + "apn";
    String apn = (String) properties.get(key);
    s_logger.trace("APN is {}", apn);
    modemConfig.setApn(apn);
    // auth type
    key = prefix + "authType";
    String authTypeString = (String) properties.get(key);
    AuthType authType = AuthType.NONE;
    s_logger.trace("Auth type is {}", authTypeString);
    if (authTypeString != null && !authTypeString.isEmpty()) {
        try {
            authType = AuthType.valueOf(authTypeString);
        } catch (IllegalArgumentException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Could not parse auth type " + authTypeString);
        }
    } else {
        s_logger.trace("Auth type is null");
    }
    modemConfig.setAuthType(authType);
    // data compression
    key = prefix + "dataCompression";
    if (properties.get(key) != null) {
        int dataCompression = (Integer) properties.get(key);
        s_logger.trace("Data compression is {}", dataCompression);
        modemConfig.setDataCompression(dataCompression);
    } else {
        s_logger.trace("Data compression is null");
    }
    // dial string
    key = prefix + "dialString";
    String dialString = (String) properties.get(key);
    s_logger.trace("Dial string is {}", dialString);
    modemConfig.setDialString(dialString);
    // header compression
    key = prefix + "headerCompression";
    if (properties.get(key) != null) {
        int headerCompression = (Integer) properties.get(key);
        s_logger.trace("Header compression is {}", headerCompression);
        modemConfig.setHeaderCompression(headerCompression);
    } else {
        s_logger.trace("Header compression is null");
    }
    // ip address
    String ipAddressString = (String) properties.get(prefix + "ipAddress");
    IPAddress ipAddress = null;
    s_logger.trace("IP address is {}", ipAddressString);
    if (ipAddressString != null && !ipAddressString.isEmpty()) {
        try {
            IPAddress.parseHostAddress(ipAddressString);
        } catch (UnknownHostException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Could not parse ip address " + ipAddressString);
        }
    } else {
        s_logger.trace("IP address is null");
    }
    modemConfig.setIpAddress(ipAddress);
    // password
    String password = (String) properties.get(prefix + "password");
    s_logger.trace("Password is {}", password);
    modemConfig.setPassword(password);
    // pdp type
    String pdpTypeString = (String) properties.get(prefix + "pdpType");
    PdpType pdpType = PdpType.UNKNOWN;
    if (pdpTypeString != null && !pdpTypeString.isEmpty()) {
        try {
            pdpType = PdpType.valueOf(pdpTypeString);
        } catch (IllegalArgumentException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Could not parse pdp type " + pdpTypeString);
        }
    }
    s_logger.trace("Pdp type is {}", pdpTypeString);
    modemConfig.setPdpType(pdpType);
    // profile id
    key = prefix + "profileId";
    if (properties.get(key) != null) {
        int profileId = (Integer) properties.get(key);
        s_logger.trace("Profile id is {}", profileId);
        modemConfig.setProfileID(profileId);
    } else {
        s_logger.trace("Profile id is null");
    }
    // ppp number
    key = prefix + "pppNum";
    if (properties.get(key) != null) {
        int pppNum = (Integer) properties.get(key);
        s_logger.trace("PPP number is {}", pppNum);
        modemConfig.setPppNumber(pppNum);
    } else {
        s_logger.trace("PPP number is null");
    }
    // persist
    key = prefix + "persist";
    if (properties.get(key) != null) {
        boolean persist = (Boolean) properties.get(key);
        s_logger.trace("persist is {}", persist);
        modemConfig.setPersist(persist);
    } else {
        s_logger.trace("persist is null");
    }
    // max fail
    key = prefix + "maxFail";
    if (properties.get(key) != null) {
        int maxFail = (Integer) properties.get(key);
        s_logger.trace("maxfail is {}", maxFail);
        modemConfig.setMaxFail(maxFail);
    } else {
        s_logger.trace("maxfail is null");
    }
    // resetTimeout
    key = prefix + "resetTimeout";
    if (properties.get(key) != null) {
        int resetTimeout = (Integer) properties.get(key);
        s_logger.trace("resetTimeout is {}", resetTimeout);
        modemConfig.setResetTimeout(resetTimeout);
    } else {
        s_logger.trace("resetTimeout is null");
    }
    // idle
    key = prefix + "idle";
    if (properties.get(key) != null) {
        int idle = (Integer) properties.get(key);
        s_logger.trace("idle is {}", idle);
        modemConfig.setIdle(idle);
    } else {
        s_logger.trace("idle is null");
    }
    // active filter
    key = prefix + "activeFilter";
    if (properties.get(key) != null) {
        String activeFilter = (String) properties.get(key);
        s_logger.trace("activeFilter is {}", activeFilter);
        modemConfig.setActiveFilter(activeFilter);
    } else {
        s_logger.trace("activeFilter is null");
    }
    // LCP echo interval
    key = prefix + "lcpEchoInterval";
    if (properties.get(key) != null) {
        int lcpEchoInterval = (Integer) properties.get(key);
        s_logger.trace("LCP Echo Interval is {}", lcpEchoInterval);
        modemConfig.setLcpEchoInterval(lcpEchoInterval);
    } else {
        s_logger.trace("LCP Echo Interval is null");
    }
    // LCP echo failure
    key = prefix + "lcpEchoFailure";
    if (properties.get(key) != null) {
        int lcpEchoFailure = (Integer) properties.get(key);
        s_logger.trace("LCP Echo Failure is {}", lcpEchoFailure);
        modemConfig.setLcpEchoFailure(lcpEchoFailure);
    } else {
        s_logger.trace("LCP Echo Failure is null");
    }
    // username
    String username = (String) properties.get(prefix + "username");
    s_logger.trace("Username is {}", username);
    modemConfig.setUsername(username);
    // enabled
    key = prefix + "enabled";
    boolean enabled = false;
    if (properties.get(key) != null) {
        enabled = (Boolean) properties.get(key);
        s_logger.trace("Enabled is {}", enabled);
    } else {
        s_logger.trace("Enabled is null");
    }
    modemConfig.setEnabled(enabled);
    // GPS enabled
    key = prefix + "gpsEnabled";
    boolean gpsEnabled = false;
    if (properties.get(key) != null) {
        gpsEnabled = (Boolean) properties.get(key);
        s_logger.trace("GPS Enabled is {}", gpsEnabled);
    } else {
        s_logger.trace("GPS Enabled is null");
    }
    modemConfig.setGpsEnabled(gpsEnabled);
    return modemConfig;
}
Also used : ModemConfig(org.eclipse.kura.net.modem.ModemConfig) UnknownHostException(java.net.UnknownHostException) KuraException(org.eclipse.kura.KuraException) AuthType(org.eclipse.kura.net.modem.ModemConfig.AuthType) IPAddress(org.eclipse.kura.net.IPAddress) WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint) PdpType(org.eclipse.kura.net.modem.ModemConfig.PdpType)

Example 2 with ModemConfig

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

the class NetworkConfiguration method toString.

@Override
public String toString() {
    StringBuffer sb = new StringBuffer();
    Iterator<String> it = this.m_netInterfaceConfigs.keySet().iterator();
    while (it.hasNext()) {
        NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig = this.m_netInterfaceConfigs.get(it.next());
        sb.append("\nname: " + netInterfaceConfig.getName());
        sb.append(" :: Loopback? " + netInterfaceConfig.isLoopback());
        sb.append(" :: Point to Point? " + netInterfaceConfig.isPointToPoint());
        sb.append(" :: Up? " + netInterfaceConfig.isUp());
        sb.append(" :: Virtual? " + netInterfaceConfig.isVirtual());
        sb.append(" :: Driver: " + netInterfaceConfig.getDriver());
        sb.append(" :: Driver Version: " + netInterfaceConfig.getDriverVersion());
        sb.append(" :: Firmware Version: " + netInterfaceConfig.getFirmwareVersion());
        sb.append(" :: MTU: " + netInterfaceConfig.getMTU());
        if (netInterfaceConfig.getHardwareAddress() != null) {
            sb.append(" :: Hardware Address: " + new String(netInterfaceConfig.getHardwareAddress()));
        }
        sb.append(" :: State: " + netInterfaceConfig.getState());
        sb.append(" :: Type: " + netInterfaceConfig.getType());
        sb.append(" :: Usb Device: " + netInterfaceConfig.getUsbDevice());
        List<? extends NetInterfaceAddress> netInterfaceAddresses = netInterfaceConfig.getNetInterfaceAddresses();
        for (NetInterfaceAddress netInterfaceAddress : netInterfaceAddresses) {
            if (netInterfaceAddress.getAddress() != null) {
                sb.append(" :: Address: " + netInterfaceAddress.getAddress().getHostAddress());
            }
            sb.append(" :: Prefix: " + netInterfaceAddress.getNetworkPrefixLength());
            if (netInterfaceAddress.getNetmask() != null) {
                sb.append(" :: Netmask: " + netInterfaceAddress.getNetmask().getHostAddress());
            }
            if (netInterfaceAddress.getBroadcast() != null) {
                sb.append(" :: Broadcast: " + netInterfaceAddress.getBroadcast().getHostAddress());
            }
        }
        List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
        if (netInterfaceAddressConfigs != null) {
            for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
                List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
                if (netConfigs != null) {
                    for (NetConfig netConfig : netConfigs) {
                        if (netConfig instanceof NetConfigIP4) {
                            sb.append("\n\tIPv4 ");
                            if (((NetConfigIP4) netConfig).isDhcp()) {
                                sb.append(" :: is DHCP client");
                                Map<String, Object> dhcp4Map = ((NetConfigIP4) netConfig).getProperties();
                                for (Map.Entry<String, Object> entry : dhcp4Map.entrySet()) {
                                    String dhcpKey = entry.getKey();
                                    sb.append(" :: " + dhcpKey + ": " + entry.getValue());
                                }
                            } else if (((NetConfigIP4) netConfig).getAddress() == null) {
                                sb.append(" :: is not configured for STATIC or DHCP");
                            } else {
                                sb.append(" :: is STATIC client");
                                if (((NetConfigIP4) netConfig).getAddress() != null) {
                                    sb.append(" :: Address: " + ((NetConfigIP4) netConfig).getAddress().getHostAddress());
                                }
                                sb.append(" :: Prefix: " + ((NetConfigIP4) netConfig).getNetworkPrefixLength());
                                if (((NetConfigIP4) netConfig).getGateway() != null) {
                                    sb.append(" :: Gateway: " + ((NetConfigIP4) netConfig).getGateway().getHostAddress());
                                }
                                List<IP4Address> dnsServers = ((NetConfigIP4) netConfig).getDnsServers();
                                List<IP4Address> winsServers = ((NetConfigIP4) netConfig).getWinsServers();
                                List<String> domains = ((NetConfigIP4) netConfig).getDomains();
                                if (dnsServers != null) {
                                    for (IP4Address dnsServer : dnsServers) {
                                        sb.append(" :: DNS : " + dnsServer.getHostAddress());
                                    }
                                }
                                if (winsServers != null) {
                                    for (IP4Address winsServer : winsServers) {
                                        sb.append(" :: WINS Server : " + winsServer.getHostAddress());
                                    }
                                }
                                if (domains != null) {
                                    for (String domain : domains) {
                                        sb.append(" :: Domains : " + domain);
                                    }
                                }
                            }
                        } else if (netConfig instanceof NetConfigIP6) {
                            sb.append("\n\tIPv6 ");
                            if (((NetConfigIP6) netConfig).isDhcp()) {
                                sb.append(" :: is DHCP client");
                                Map<String, Object> dhcp6Map = ((NetConfigIP6) netConfig).getProperties();
                                Iterator<String> it2 = dhcp6Map.keySet().iterator();
                                while (it2.hasNext()) {
                                    String dhcpKey = it2.next();
                                    sb.append(" :: " + dhcpKey + ": " + dhcp6Map.get(dhcpKey));
                                }
                            } else {
                                sb.append(" :: is STATIC client");
                                if (((NetConfigIP6) netConfig).getAddress() != null) {
                                    sb.append(" :: Address: " + ((NetConfigIP6) netConfig).getAddress().getHostAddress());
                                }
                                List<IP6Address> dnsServers = ((NetConfigIP6) netConfig).getDnsServers();
                                List<String> domains = ((NetConfigIP6) netConfig).getDomains();
                                for (IP6Address dnsServer : dnsServers) {
                                    sb.append(" :: DNS : " + dnsServer.getHostAddress());
                                }
                                for (String domain : domains) {
                                    sb.append(" :: Domains : " + domain);
                                }
                            }
                        } else if (netConfig instanceof WifiConfig) {
                            sb.append("\n\tWifiConfig ");
                            sb.append(" :: SSID: " + ((WifiConfig) netConfig).getSSID());
                            sb.append(" :: BgScan: " + ((WifiConfig) netConfig).getBgscan());
                            sb.append(" :: Broadcast: " + ((WifiConfig) netConfig).getBroadcast());
                            int[] channels = ((WifiConfig) netConfig).getChannels();
                            if (channels != null && channels.length > 0) {
                                for (int i = 0; i < channels.length; i++) {
                                    sb.append(channels[i]);
                                    if (i + 1 < channels.length) {
                                        sb.append(",");
                                    }
                                }
                            }
                            sb.append(" :: Group Ciphers: " + ((WifiConfig) netConfig).getGroupCiphers());
                            sb.append(" :: Hardware Mode: " + ((WifiConfig) netConfig).getHardwareMode());
                            sb.append(" :: Mode: " + ((WifiConfig) netConfig).getMode());
                            sb.append(" :: Pairwise Ciphers: " + ((WifiConfig) netConfig).getPairwiseCiphers());
                            sb.append(" :: Passkey: " + ((WifiConfig) netConfig).getPasskey());
                            sb.append(" :: Security: " + ((WifiConfig) netConfig).getSecurity());
                        } else if (netConfig instanceof ModemConfig) {
                            sb.append("\n\tModemConfig ");
                            sb.append(" :: APN: " + ((ModemConfig) netConfig).getApn());
                            sb.append(" :: Data Compression: " + ((ModemConfig) netConfig).getDataCompression());
                            sb.append(" :: Dial String: " + ((ModemConfig) netConfig).getDialString());
                            sb.append(" :: Header Compression: " + ((ModemConfig) netConfig).getHeaderCompression());
                            sb.append(" :: Password: " + ((ModemConfig) netConfig).getPassword());
                            sb.append(" :: PPP number: " + ((ModemConfig) netConfig).getPppNumber());
                            sb.append(" :: Profile ID: " + ((ModemConfig) netConfig).getProfileID());
                            sb.append(" :: Username: " + ((ModemConfig) netConfig).getUsername());
                            sb.append(" :: Auth Type: " + ((ModemConfig) netConfig).getAuthType());
                            sb.append(" :: IP Address: " + ((ModemConfig) netConfig).getIpAddress());
                            sb.append(" :: PDP Type: " + ((ModemConfig) netConfig).getPdpType());
                        } else if (netConfig instanceof DhcpServerConfig) {
                            sb.append("\n\tDhcpServerConfig ");
                        // TODO - finish displaying
                        } else if (netConfig instanceof FirewallAutoNatConfig) {
                            sb.append("\n\tFirewallAutoNatConfig ");
                        // TODO - finish displaying
                        } else {
                            if (netConfig != null && netConfig.getClass() != null) {
                                sb.append("\n\tUNKNOWN CONFIG TYPE???: " + netConfig.getClass().getName());
                            } else {
                                sb.append("\n\tNULL NETCONFIG PRESENT?!?");
                            }
                        }
                    }
                }
            }
        }
    }
    return sb.toString();
}
Also used : FirewallAutoNatConfig(org.eclipse.kura.net.firewall.FirewallAutoNatConfig) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) NetConfigIP6(org.eclipse.kura.net.NetConfigIP6) Iterator(java.util.Iterator) DhcpServerConfig(org.eclipse.kura.net.dhcp.DhcpServerConfig) List(java.util.List) ArrayList(java.util.ArrayList) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) IP4Address(org.eclipse.kura.net.IP4Address) IP6Address(org.eclipse.kura.net.IP6Address) WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint) ModemConfig(org.eclipse.kura.net.modem.ModemConfig) NetInterfaceAddress(org.eclipse.kura.net.NetInterfaceAddress) NetConfig(org.eclipse.kura.net.NetConfig) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ModemConfig

use of org.eclipse.kura.net.modem.ModemConfig 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 ModemConfig

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

the class PppConfigReader method getConfig.

private void getConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig) throws KuraException {
    String interfaceName = netInterfaceConfig.getName();
    s_logger.debug("Getting ppp config for {}", interfaceName);
    if (netInterfaceConfig instanceof ModemInterfaceConfigImpl) {
        StringBuilder key = new StringBuilder("net.interface." + netInterfaceConfig.getName() + ".modem.identifier");
        String modemId = KuranetConfig.getProperty(key.toString());
        s_logger.debug("Getting modem identifier using key " + key + ": " + modemId);
        if (modemId != null) {
            ((ModemInterfaceConfigImpl) netInterfaceConfig).setModemIdentifier(modemId);
        }
    }
    List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
    for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
        if (netInterfaceAddressConfig instanceof ModemInterfaceAddressConfigImpl) {
            List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
            if (netConfigs == null) {
                netConfigs = new ArrayList<NetConfig>();
                ((ModemInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(netConfigs);
            }
            // Create a ModemConfig
            ModemConfig modemConfig = getModemConfig(interfaceName, netInterfaceConfig.getUsbDevice());
            if (modemConfig != null) {
                netConfigs.add(modemConfig);
            }
            // Create a NetConfigIP4
            netConfigs.add(getNetConfigIP4(interfaceName));
            // Populate with DNS provided by PPP (displayed as read-only in Denali)
            if (LinuxNetworkUtil.hasAddress("ppp" + modemConfig.getPppNumber())) {
                List<? extends IPAddress> pppDnsServers = LinuxDns.getInstance().getPppDnServers();
                if (pppDnsServers != null) {
                    ((ModemInterfaceAddressConfigImpl) netInterfaceAddressConfig).setDnsServers(pppDnsServers);
                }
            }
        }
    }
}
Also used : ModemInterfaceAddressConfigImpl(org.eclipse.kura.core.net.modem.ModemInterfaceAddressConfigImpl) ModemConfig(org.eclipse.kura.net.modem.ModemConfig) ModemInterfaceConfigImpl(org.eclipse.kura.core.net.modem.ModemInterfaceConfigImpl) NetConfig(org.eclipse.kura.net.NetConfig) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig)

Example 5 with ModemConfig

use of org.eclipse.kura.net.modem.ModemConfig 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

ModemConfig (org.eclipse.kura.net.modem.ModemConfig)10 NetConfig (org.eclipse.kura.net.NetConfig)7 NetConfigIP4 (org.eclipse.kura.net.NetConfigIP4)7 KuraException (org.eclipse.kura.KuraException)6 NetInterfaceAddressConfig (org.eclipse.kura.net.NetInterfaceAddressConfig)5 UnknownHostException (java.net.UnknownHostException)4 ArrayList (java.util.ArrayList)4 IP4Address (org.eclipse.kura.net.IP4Address)4 WifiConfig (org.eclipse.kura.net.wifi.WifiConfig)4 List (java.util.List)3 IPAddress (org.eclipse.kura.net.IPAddress)3 NetConfigIP6 (org.eclipse.kura.net.NetConfigIP6)3 FirewallAutoNatConfig (org.eclipse.kura.net.firewall.FirewallAutoNatConfig)3 AuthType (org.eclipse.kura.net.modem.ModemConfig.AuthType)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ModemInterfaceAddressConfigImpl (org.eclipse.kura.core.net.modem.ModemInterfaceAddressConfigImpl)2 ModemInterfaceConfigImpl (org.eclipse.kura.core.net.modem.ModemInterfaceConfigImpl)2 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)2 SupportedUsbModemInfo (org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)2