Search in sources :

Example 16 with WifiConfig

use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.

the class WpaSupplicantConfigWriter method writeConfig.

private void writeConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig) throws KuraException {
    String interfaceName = netInterfaceConfig.getName();
    s_logger.debug("Writing wpa_supplicant config for {}", interfaceName);
    List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
    if (netInterfaceAddressConfigs.size() > 0) {
        for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
            if (netInterfaceAddressConfig instanceof WifiInterfaceAddressConfigImpl) {
                List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
                NetInterfaceStatus netInterfaceStatus = NetInterfaceStatus.netIPv4StatusDisabled;
                WifiMode wifiMode = ((WifiInterfaceAddressConfigImpl) netInterfaceAddressConfig).getMode();
                WifiConfig infraConfig = null;
                WifiConfig adhocConfig = null;
                WifiConfig wpaSupplicantConfig = null;
                // Get the wifi configs
                if (netConfigs != null) {
                    for (NetConfig netConfig : netConfigs) {
                        if (netConfig instanceof WifiConfig) {
                            if (((WifiConfig) netConfig).getMode() == WifiMode.ADHOC) {
                                adhocConfig = (WifiConfig) netConfig;
                            } else if (((WifiConfig) netConfig).getMode() == WifiMode.INFRA) {
                                infraConfig = (WifiConfig) netConfig;
                            }
                        } else if (netConfig instanceof NetConfigIP4) {
                            netInterfaceStatus = ((NetConfigIP4) netConfig).getStatus();
                        }
                    }
                }
                if (netInterfaceStatus == NetInterfaceStatus.netIPv4StatusDisabled) {
                    s_logger.info("Network interface status for " + interfaceName + " is disabled - not overwriting wpaconfig file");
                    return;
                }
                // Choose which config to write
                if (wifiMode == WifiMode.INFRA) {
                    if (infraConfig != null) {
                        StringBuilder key = new StringBuilder().append("net.interface.").append(interfaceName).append(".config.wifi.infra.pingAccessPoint");
                        try {
                            KuranetConfig.setProperty(key.toString(), Boolean.toString(infraConfig.pingAccessPoint()));
                        } catch (IOException e) {
                            s_logger.warn("Error setting KuranetConfig property", e);
                        }
                        key = new StringBuilder().append("net.interface.").append(interfaceName).append(".config.wifi.infra.ignoreSSID");
                        try {
                            KuranetConfig.setProperty(key.toString(), Boolean.toString(infraConfig.ignoreSSID()));
                        } catch (IOException e) {
                            s_logger.warn("Error setting KuranetConfig property", e);
                        }
                        wpaSupplicantConfig = infraConfig;
                    } else {
                        s_logger.debug("Not updating wpa_supplicant config - wifi mode is " + wifiMode + " but the infra config is null");
                    }
                } else if (wifiMode == WifiMode.ADHOC) {
                    if (adhocConfig != null) {
                        wpaSupplicantConfig = adhocConfig;
                    } else {
                        s_logger.debug("Not updating wpa_supplicant config - wifi mode is " + wifiMode + " but the adhoc config is null");
                    }
                } else if (wifiMode == WifiMode.MASTER) {
                    if (infraConfig != null && adhocConfig != null) {
                        // Choose the infra config if both are present?
                        wpaSupplicantConfig = infraConfig;
                    } else if (infraConfig != null) {
                        wpaSupplicantConfig = infraConfig;
                    } else if (adhocConfig != null) {
                        wpaSupplicantConfig = adhocConfig;
                    } else {
                        s_logger.debug("Not updating wpa_supplicant config - wifi mode is " + wifiMode + " and the infra and adhoc configs are null");
                    }
                }
                // Write the config
                try {
                    if (wpaSupplicantConfig != null) {
                        s_logger.debug("Writing wifiConfig: {}", wpaSupplicantConfig);
                        generateWpaSupplicantConf(wpaSupplicantConfig, interfaceName, WPA_TMP_CONFIG_FILE);
                        moveWpaSupplicantConf(interfaceName, WPA_TMP_CONFIG_FILE);
                    }
                } catch (Exception e) {
                    s_logger.error("Failed to configure WPA Supplicant");
                    throw KuraException.internalError(e);
                }
            }
        }
    }
}
Also used : NetInterfaceStatus(org.eclipse.kura.net.NetInterfaceStatus) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) IOException(java.io.IOException) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) WifiMode(org.eclipse.kura.net.wifi.WifiMode) NetConfig(org.eclipse.kura.net.NetConfig) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) WifiInterfaceAddressConfigImpl(org.eclipse.kura.core.net.WifiInterfaceAddressConfigImpl)

Example 17 with WifiConfig

use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.

the class NetworkAdminServiceImpl method enableInterface.

@Override
public void enableInterface(String interfaceName, boolean dhcp) throws KuraException {
    try {
        NetInterfaceType type = LinuxNetworkUtil.getType(interfaceName);
        NetInterfaceStatus status = NetInterfaceStatus.netIPv4StatusUnknown;
        WifiMode wifiMode = WifiMode.UNKNOWN;
        WifiConfig wifiConfig = null;
        WifiInterfaceState wifiInterfaceState = null;
        if (type == NetInterfaceType.WIFI) {
            List<NetInterfaceConfig<? extends NetInterfaceAddressConfig>> wifiNetInterfaceConfigs = getWifiInterfaceConfigs();
            List<? extends NetInterfaceAddressConfig> wifiNetInterfaceAddressConfigs = getWifiNetInterfaceAddressConfigs(interfaceName, wifiNetInterfaceConfigs);
            WifiInterfaceAddressConfig wifiInterfaceAddressConfig = getWifiAddressConfig(wifiNetInterfaceAddressConfigs);
            wifiMode = wifiInterfaceAddressConfig.getMode();
            wifiInterfaceState = new WifiInterfaceState(interfaceName, wifiMode);
            for (NetConfig netConfig : wifiInterfaceAddressConfig.getConfigs()) {
                if (netConfig instanceof NetConfigIP4) {
                    status = ((NetConfigIP4) netConfig).getStatus();
                    s_logger.debug("Interface status is set to {}", status);
                } else if (netConfig instanceof WifiConfig && ((WifiConfig) netConfig).getMode() == wifiMode) {
                    wifiConfig = (WifiConfig) netConfig;
                }
            }
        }
        if (!LinuxNetworkUtil.hasAddress(interfaceName) || ((type == NetInterfaceType.WIFI) && (wifiInterfaceState != null) && !wifiInterfaceState.isLinkUp())) {
            s_logger.info("bringing interface {} up", interfaceName);
            if (type == NetInterfaceType.WIFI) {
                enableWifiInterface(interfaceName, status, wifiMode, wifiConfig);
            }
            if (dhcp) {
                renewDhcpLease(interfaceName);
            } else {
                LinuxNetworkUtil.enableInterface(interfaceName);
            }
            // if it isn't up - at least make sure the Ethernet controller is powered on
            if (!LinuxNetworkUtil.hasAddress(interfaceName)) {
                LinuxNetworkUtil.bringUpDeletingAddress(interfaceName);
            }
        } else {
            s_logger.info("not bringing interface {} up because it is already up", interfaceName);
            if (dhcp) {
                renewDhcpLease(interfaceName);
            }
        }
    } catch (Exception e) {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : NetInterfaceConfig(org.eclipse.kura.net.NetInterfaceConfig) NetInterfaceStatus(org.eclipse.kura.net.NetInterfaceStatus) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) WifiInterfaceAddressConfig(org.eclipse.kura.net.wifi.WifiInterfaceAddressConfig) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) KuraException(org.eclipse.kura.KuraException) WifiMode(org.eclipse.kura.net.wifi.WifiMode) NetConfig(org.eclipse.kura.net.NetConfig) WifiInterfaceState(org.eclipse.kura.net.admin.monitor.WifiInterfaceState) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig)

Example 18 with WifiConfig

use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.

the class NetworkConfiguration method getWifiConfig.

private static WifiConfig getWifiConfig(String netIfConfigPrefix, WifiMode mode, Map<String, Object> properties) throws KuraException {
    String key;
    WifiConfig wifiConfig = new WifiConfig();
    StringBuilder prefix = new StringBuilder(netIfConfigPrefix).append("wifi.").append(mode.toString().toLowerCase());
    // mode
    s_logger.trace("mode is {}", mode.toString());
    wifiConfig.setMode(mode);
    // ssid
    key = prefix + ".ssid";
    String ssid = (String) properties.get(key);
    if (ssid == null) {
        ssid = "";
    }
    s_logger.trace("SSID is {}", ssid);
    wifiConfig.setSSID(ssid);
    // driver
    key = prefix + ".driver";
    String driver = (String) properties.get(key);
    if (driver == null) {
        driver = "";
    }
    s_logger.trace("driver is {}", driver);
    wifiConfig.setDriver(driver);
    // security
    key = prefix + ".securityType";
    WifiSecurity wifiSecurity = WifiSecurity.NONE;
    String securityString = (String) properties.get(key);
    s_logger.trace("securityString is {}", securityString);
    if (securityString != null && !securityString.isEmpty()) {
        try {
            wifiSecurity = WifiSecurity.valueOf(securityString);
        } catch (IllegalArgumentException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Could not parse wifi security " + securityString);
        }
    }
    wifiConfig.setSecurity(wifiSecurity);
    // channels
    key = prefix + ".channel";
    String channelsString = (String) properties.get(key);
    s_logger.trace("channelsString is {}", channelsString);
    if (channelsString != null) {
        channelsString = channelsString.trim();
        if (channelsString.length() > 0) {
            StringTokenizer st = new StringTokenizer(channelsString, " ");
            int tokens = st.countTokens();
            if (tokens > 0) {
                int[] channels = new int[tokens];
                for (int i = 0; i < tokens; i++) {
                    String token = st.nextToken();
                    try {
                        channels[i] = Integer.parseInt(token);
                    } catch (Exception e) {
                        s_logger.error("Error parsing channels!", e);
                    }
                }
                wifiConfig.setChannels(channels);
            }
        }
    }
    // passphrase
    key = prefix + ".passphrase";
    Object psswdObj = properties.get(key);
    Password psswd = null;
    if (psswdObj instanceof Password) {
        psswd = (Password) psswdObj;
    } else if (psswdObj instanceof String) {
        char[] tempPsswd = ((String) psswdObj).toCharArray();
        psswd = new Password(tempPsswd);
    }
    String passphrase = new String(psswd.getPassword());
    s_logger.trace("passphrase is {}", passphrase);
    wifiConfig.setPasskey(passphrase);
    // hardware mode
    key = prefix + ".hardwareMode";
    String hwMode = (String) properties.get(key);
    if (hwMode == null) {
        hwMode = "";
    }
    s_logger.trace("hwMode is {}", hwMode);
    wifiConfig.setHardwareMode(hwMode);
    // ignore SSID
    key = prefix + ".ignoreSSID";
    boolean ignoreSSID = false;
    if (properties.get(key) != null) {
        ignoreSSID = (Boolean) properties.get(key);
        s_logger.trace("Ignore SSID is {}", ignoreSSID);
    } else {
        s_logger.trace("Ignore SSID is null");
    }
    wifiConfig.setIgnoreSSID(ignoreSSID);
    key = prefix + ".pairwiseCiphers";
    String pairwiseCiphers = (String) properties.get(key);
    if (pairwiseCiphers != null) {
        wifiConfig.setPairwiseCiphers(WifiCiphers.valueOf(pairwiseCiphers));
    }
    if (mode == WifiMode.INFRA) {
        key = prefix + ".bgscan";
        String bgscan = (String) properties.get(key);
        if (bgscan == null) {
            bgscan = "";
        }
        s_logger.trace("bgscan is {}", bgscan);
        wifiConfig.setBgscan(new WifiBgscan(bgscan));
        /*
             * key = prefix + ".pairwiseCiphers";
             * String pairwiseCiphers = (String)properties.get(key);
             * if (pairwiseCiphers != null) {
             * wifiConfig.setPairwiseCiphers(WifiCiphers.valueOf(pairwiseCiphers));
             * }
             */
        key = prefix + ".groupCiphers";
        String groupCiphers = (String) properties.get(key);
        if (groupCiphers != null) {
            wifiConfig.setGroupCiphers(WifiCiphers.valueOf(groupCiphers));
        }
        // ping access point?
        key = prefix + ".pingAccessPoint";
        boolean pingAccessPoint = false;
        if (properties.get(key) != null) {
            pingAccessPoint = (Boolean) properties.get(key);
            s_logger.trace("Ping Access Point is {}", pingAccessPoint);
        } else {
            s_logger.trace("Ping Access Point is null");
        }
        wifiConfig.setPingAccessPoint(pingAccessPoint);
    }
    // broadcast
    key = prefix + ".broadcast";
    Boolean broadcast = (Boolean) properties.get(key);
    if (broadcast != null) {
        wifiConfig.setBroadcast(broadcast);
    }
    s_logger.trace("hwMode is {}", hwMode);
    // radio mode
    key = prefix + ".radioMode";
    WifiRadioMode radioMode;
    String radioModeString = (String) properties.get(key);
    s_logger.trace("radioModeString is {}", radioModeString);
    if (radioModeString != null && !radioModeString.isEmpty()) {
        try {
            radioMode = WifiRadioMode.valueOf(radioModeString);
            wifiConfig.setRadioMode(radioMode);
        } catch (IllegalArgumentException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Could not parse wifi radio mode " + radioModeString);
        }
    }
    if (!wifiConfig.isValid()) {
        return null;
    } else {
        s_logger.trace("Returning wifiConfig: {}", wifiConfig);
        return wifiConfig;
    }
}
Also used : WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint) KuraException(org.eclipse.kura.KuraException) UnknownHostException(java.net.UnknownHostException) StringTokenizer(java.util.StringTokenizer) WifiRadioMode(org.eclipse.kura.net.wifi.WifiRadioMode) KuraException(org.eclipse.kura.KuraException) WifiSecurity(org.eclipse.kura.net.wifi.WifiSecurity) WifiBgscan(org.eclipse.kura.net.wifi.WifiBgscan) Password(org.eclipse.kura.configuration.Password)

Example 19 with WifiConfig

use of org.eclipse.kura.net.wifi.WifiConfig in project kura by eclipse.

the class NetworkConfiguration method recomputeNetworkProperties.

// ---------------------------------------------------------------
// 
// Private Methods
// 
// ---------------------------------------------------------------
private void recomputeNetworkProperties() {
    Map<String, Object> properties = new HashMap<String, Object>();
    String netIfPrefix = null;
    String netIfReadOnlyPrefix = null;
    String netIfConfigPrefix = null;
    StringBuilder sbPrefix = null;
    StringBuilder sbInterfaces = new StringBuilder();
    if (this.m_modifiedInterfaceNames != null && !this.m_modifiedInterfaceNames.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        String prefix = "";
        for (String interfaceName : this.m_modifiedInterfaceNames) {
            sb.append(prefix);
            prefix = ",";
            sb.append(interfaceName);
        }
        String result = sb.toString();
        s_logger.debug("Set modified interface names: {}", result);
        properties.put("modified.interface.names", result);
    }
    Iterator<String> it = this.m_netInterfaceConfigs.keySet().iterator();
    while (it.hasNext()) {
        NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig = this.m_netInterfaceConfigs.get(it.next());
        // add the interface to the list of interface found in the platform
        if (sbInterfaces.length() != 0) {
            sbInterfaces.append(",");
        }
        sbInterfaces.append(netInterfaceConfig.getName());
        // build the prefixes for all the properties associated with this interface
        sbPrefix = new StringBuilder("net.interface.").append(netInterfaceConfig.getName()).append(".");
        netIfReadOnlyPrefix = sbPrefix.toString();
        netIfPrefix = sbPrefix.append("config.").toString();
        netIfConfigPrefix = sbPrefix.toString();
        // add the properties of the interface
        properties.put(netIfReadOnlyPrefix + "type", netInterfaceConfig.getType().toString());
        properties.put(netIfPrefix + "name", netInterfaceConfig.getName());
        if (netInterfaceConfig.getState() != null) {
            properties.put(netIfPrefix + "state", netInterfaceConfig.getState().toString());
        }
        properties.put(netIfPrefix + "autoconnect", netInterfaceConfig.isAutoConnect());
        properties.put(netIfPrefix + "mtu", netInterfaceConfig.getMTU());
        properties.put(netIfReadOnlyPrefix + "driver", netInterfaceConfig.getDriver());
        properties.put(netIfReadOnlyPrefix + "driver.version", netInterfaceConfig.getDriverVersion());
        properties.put(netIfReadOnlyPrefix + "firmware.version", netInterfaceConfig.getFirmwareVersion());
        properties.put(netIfReadOnlyPrefix + "mac", NetUtil.hardwareAddressToString(netInterfaceConfig.getHardwareAddress()));
        properties.put(netIfReadOnlyPrefix + "loopback", netInterfaceConfig.isLoopback());
        properties.put(netIfReadOnlyPrefix + "ptp", netInterfaceConfig.isPointToPoint());
        properties.put(netIfReadOnlyPrefix + "up", netInterfaceConfig.isUp());
        properties.put(netIfReadOnlyPrefix + "virtual", netInterfaceConfig.isVirtual());
        // usb
        if (netInterfaceConfig.getUsbDevice() != null) {
            UsbDevice usbDev = netInterfaceConfig.getUsbDevice();
            properties.put(netIfReadOnlyPrefix + "usb.vendor.id", usbDev.getVendorId());
            properties.put(netIfReadOnlyPrefix + "usb.vendor.name", usbDev.getManufacturerName());
            properties.put(netIfReadOnlyPrefix + "usb.product.id", usbDev.getProductId());
            properties.put(netIfReadOnlyPrefix + "usb.product.name", usbDev.getProductName());
            properties.put(netIfReadOnlyPrefix + "usb.busNumber", usbDev.getUsbBusNumber());
            properties.put(netIfReadOnlyPrefix + "usb.devicePath", usbDev.getUsbDevicePath());
        }
        // custom readonly props for Ethernet and Wifi
        if (netInterfaceConfig instanceof EthernetInterfaceConfigImpl) {
            properties.put(netIfReadOnlyPrefix + "eth.link.up", ((EthernetInterfaceConfigImpl) netInterfaceConfig).isLinkUp());
        } else if (netInterfaceConfig instanceof WifiInterfaceConfigImpl) {
            EnumSet<Capability> capabilities = ((WifiInterfaceConfigImpl) netInterfaceConfig).getCapabilities();
            if (capabilities != null && !capabilities.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (Capability capability : capabilities) {
                    sb.append(capability.toString());
                    sb.append(",");
                }
                String capabilitiesString = sb.toString();
                capabilitiesString = capabilitiesString.substring(0, capabilitiesString.length() - 1);
                properties.put(netIfReadOnlyPrefix + "wifi.capabilities", capabilitiesString);
            }
        }
        // add wifi properties
        if (netInterfaceConfig.getType() == NetInterfaceType.WIFI) {
            // capabilities
            StringBuilder sbCapabilities = new StringBuilder();
            EnumSet<Capability> capabilities = ((WifiInterface) netInterfaceConfig).getCapabilities();
            if (capabilities != null) {
                Iterator<Capability> it2 = ((WifiInterface) netInterfaceConfig).getCapabilities().iterator();
                while (it2.hasNext()) {
                    sbCapabilities.append(it2.next().name()).append(" ");
                }
                properties.put(netIfReadOnlyPrefix + "wifi.capabilities", sbCapabilities.toString());
            }
        }
        // add modem properties
        if (netInterfaceConfig.getType() == NetInterfaceType.MODEM) {
            String delim;
            // revision
            StringBuffer revisionIdBuf = new StringBuffer();
            String[] revisionId = ((ModemInterface<?>) netInterfaceConfig).getRevisionId();
            if (revisionId != null) {
                delim = null;
                for (String rev : revisionId) {
                    if (delim != null) {
                        revisionIdBuf.append(delim);
                    }
                    revisionIdBuf.append(rev);
                    delim = ",";
                }
            }
            // technology types
            StringBuffer techTypesBuf = new StringBuffer();
            List<ModemTechnologyType> techTypes = ((ModemInterface<?>) netInterfaceConfig).getTechnologyTypes();
            if (techTypes != null) {
                delim = null;
                for (ModemTechnologyType techType : techTypes) {
                    if (delim != null) {
                        techTypesBuf.append(delim);
                    }
                    techTypesBuf.append(techType.toString());
                    delim = ",";
                }
            }
            ModemPowerMode powerMode = ModemPowerMode.UNKNOWN;
            if (((ModemInterface<?>) netInterfaceConfig).getPowerMode() != null) {
                powerMode = ((ModemInterface<?>) netInterfaceConfig).getPowerMode();
            }
            properties.put(netIfReadOnlyPrefix + "manufacturer", ((ModemInterface<?>) netInterfaceConfig).getManufacturer());
            properties.put(netIfReadOnlyPrefix + "model", ((ModemInterface<?>) netInterfaceConfig).getModel());
            properties.put(netIfReadOnlyPrefix + "revisionId", revisionIdBuf.toString());
            properties.put(netIfReadOnlyPrefix + "serialNum", ((ModemInterface<?>) netInterfaceConfig).getSerialNumber());
            properties.put(netIfReadOnlyPrefix + "technologyTypes", techTypesBuf.toString());
            properties.put(netIfConfigPrefix + "identifier", ((ModemInterface<?>) netInterfaceConfig).getModemIdentifier());
            properties.put(netIfConfigPrefix + "powerMode", powerMode.toString());
            properties.put(netIfConfigPrefix + "pppNum", ((ModemInterface<?>) netInterfaceConfig).getPppNum());
            properties.put(netIfConfigPrefix + "poweredOn", ((ModemInterface<?>) netInterfaceConfig).isPoweredOn());
        }
        for (NetInterfaceAddress nia : netInterfaceConfig.getNetInterfaceAddresses()) {
            String typePrefix = "ip4.";
            if (nia != null) {
                if (nia.getAddress() != null) {
                    properties.put(netIfReadOnlyPrefix + typePrefix + "address", nia.getAddress().getHostAddress());
                }
                if (nia.getBroadcast() != null) {
                    properties.put(netIfReadOnlyPrefix + typePrefix + "broadcast", nia.getBroadcast().getHostAddress());
                }
                if (nia.getGateway() != null) {
                    properties.put(netIfReadOnlyPrefix + typePrefix + "gateway", nia.getGateway().getHostAddress());
                }
                if (nia.getNetmask() != null) {
                    properties.put(netIfReadOnlyPrefix + typePrefix + "netmask", nia.getNetmask().getHostAddress());
                }
                if (nia.getNetmask() != null) {
                    properties.put(netIfReadOnlyPrefix + typePrefix + "prefix", Short.valueOf(nia.getNetworkPrefixLength()));
                }
                if (nia.getDnsServers() != null) {
                    StringBuilder dnsServers = new StringBuilder();
                    for (IPAddress dnsServer : nia.getDnsServers()) {
                        if (dnsServers.length() != 0) {
                            dnsServers.append(",");
                        }
                        dnsServers.append(dnsServer);
                    }
                    properties.put(netIfReadOnlyPrefix + typePrefix + "dnsServers", dnsServers.toString());
                }
                // Wifi interface address
                if (nia instanceof WifiInterfaceAddress) {
                    // access point
                    WifiAccessPoint wap = ((WifiInterfaceAddress) nia).getWifiAccessPoint();
                    if (wap != null) {
                    /*
                             * TODO: need fields to reflect current state?
                             * properties.put(sbNetIfPrefix+"wifi.ssid", wap.getSSID());
                             * properties.put(sbNetIfPrefix+"wifi.mode", wap.getMode());
                             */
                    }
                    long bitrate = ((WifiInterfaceAddress) nia).getBitrate();
                    properties.put(netIfReadOnlyPrefix + "wifi.bitrate", Long.valueOf(bitrate));
                    WifiMode wifiMode;
                    if (((WifiInterfaceAddress) nia).getMode() != null) {
                        wifiMode = ((WifiInterfaceAddress) nia).getMode();
                    } else {
                        wifiMode = WifiMode.UNKNOWN;
                    }
                    properties.put(netIfPrefix + "wifi.mode", wifiMode.toString());
                }
                // Modem interface address
                if (nia instanceof ModemInterfaceAddress) {
                    if (((ModemInterfaceAddress) nia).getConnectionType() != null) {
                        properties.put(netIfConfigPrefix + "connection.type", ((ModemInterfaceAddress) nia).getConnectionType().toString());
                    }
                    if (((ModemInterfaceAddress) nia).getConnectionStatus() != null) {
                        properties.put(netIfConfigPrefix + "connection.status", ((ModemInterfaceAddress) nia).getConnectionStatus().toString());
                    }
                }
            }
        }
        // add the properties of the network configurations associated to the interface
        List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
        s_logger.trace("netInterfaceAddressConfigs.size() for {}: {}", netInterfaceConfig.getName(), netInterfaceAddressConfigs.size());
        for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
            List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
            if (netConfigs != null) {
                s_logger.trace("netConfigs.size(): {}", netConfigs.size());
                for (NetConfig netConfig : netConfigs) {
                    if (netConfig instanceof WifiConfig) {
                        s_logger.trace("adding netconfig WifiConfigIP4 for {}", netInterfaceConfig.getName());
                        addWifiConfigIP4Properties((WifiConfig) netConfig, netIfConfigPrefix, properties);
                    } else if (netConfig instanceof ModemConfig) {
                        s_logger.trace("adding netconfig ModemConfig for {}", netInterfaceConfig.getName());
                        addModemConfigProperties((ModemConfig) netConfig, netIfConfigPrefix, properties);
                    } else if (netConfig instanceof NetConfigIP4) {
                        s_logger.trace("adding netconfig NetConfigIP4 for {}", netInterfaceConfig.getName());
                        addNetConfigIP4Properties((NetConfigIP4) netConfig, netIfConfigPrefix, properties);
                    /*
                             * Iterator<String> it2 = properties.keySet().iterator();
                             * while(it2.hasNext()) {
                             * String key = it2.next();
                             * System.out.println("\t\t\t"+key+"="+properties.get(key));
                             * }
                             */
                    } else if (netConfig instanceof NetConfigIP6) {
                        s_logger.trace("adding netconfig NetConfigIP6 for {}", netInterfaceConfig.getName());
                        addNetConfigIP6Properties((NetConfigIP6) netConfig, netIfConfigPrefix, properties);
                    /*
                             * Iterator<String> it = properties.keySet().iterator();
                             * while(it.hasNext()) {
                             * String key = it.next();
                             * System.out.println("\t\t\t"+key+"="+properties.get(key));
                             * }
                             */
                    } else if (netConfig instanceof DhcpServerConfig4) {
                        s_logger.trace("adding netconfig DhcpServerConfig4 for {}", netInterfaceConfig.getName());
                        addDhcpServerConfig4((DhcpServerConfig4) netConfig, netIfConfigPrefix, properties);
                    } else if (netConfig instanceof FirewallAutoNatConfig) {
                        s_logger.trace("adding netconfig FirewallNatConfig for {}", netInterfaceConfig.getName());
                        addFirewallNatConfig((FirewallAutoNatConfig) netConfig, netIfConfigPrefix, properties);
                    }
                }
            }
        }
    }
    properties.put("net.interfaces", sbInterfaces.toString());
    this.m_properties = properties;
}
Also used : FirewallAutoNatConfig(org.eclipse.kura.net.firewall.FirewallAutoNatConfig) HashMap(java.util.HashMap) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) UsbDevice(org.eclipse.kura.usb.UsbDevice) WifiInterface(org.eclipse.kura.net.wifi.WifiInterface) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) NetConfigIP6(org.eclipse.kura.net.NetConfigIP6) WifiMode(org.eclipse.kura.net.wifi.WifiMode) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) ModemInterface(org.eclipse.kura.net.modem.ModemInterface) Capability(org.eclipse.kura.net.wifi.WifiInterface.Capability) EnumSet(java.util.EnumSet) ModemPowerMode(org.eclipse.kura.net.modem.ModemPowerMode) DhcpServerConfig4(org.eclipse.kura.net.dhcp.DhcpServerConfig4) 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) WifiInterfaceAddress(org.eclipse.kura.net.wifi.WifiInterfaceAddress) IPAddress(org.eclipse.kura.net.IPAddress) ModemInterfaceAddress(org.eclipse.kura.net.modem.ModemInterfaceAddress)

Aggregations

WifiConfig (org.eclipse.kura.net.wifi.WifiConfig)19 NetConfig (org.eclipse.kura.net.NetConfig)12 KuraException (org.eclipse.kura.KuraException)11 NetConfigIP4 (org.eclipse.kura.net.NetConfigIP4)11 NetInterfaceAddressConfig (org.eclipse.kura.net.NetInterfaceAddressConfig)9 WifiMode (org.eclipse.kura.net.wifi.WifiMode)8 UnknownHostException (java.net.UnknownHostException)7 ArrayList (java.util.ArrayList)7 FirewallAutoNatConfig (org.eclipse.kura.net.firewall.FirewallAutoNatConfig)6 WifiAccessPoint (org.eclipse.kura.net.wifi.WifiAccessPoint)6 IP4Address (org.eclipse.kura.net.IP4Address)5 IOException (java.io.IOException)4 List (java.util.List)4 WifiInterfaceAddressConfigImpl (org.eclipse.kura.core.net.WifiInterfaceAddressConfigImpl)4 ModemConfig (org.eclipse.kura.net.modem.ModemConfig)4 WifiBgscan (org.eclipse.kura.net.wifi.WifiBgscan)4 WifiInterfaceAddressConfig (org.eclipse.kura.net.wifi.WifiInterfaceAddressConfig)4 GwtWifiConfig (org.eclipse.kura.web.shared.model.GwtWifiConfig)4 HashMap (java.util.HashMap)3 WifiInterfaceConfigImpl (org.eclipse.kura.core.net.WifiInterfaceConfigImpl)3