Search in sources :

Example 1 with WifiInterfaceAddressImpl

use of org.eclipse.kura.core.net.WifiInterfaceAddressImpl in project kura by eclipse.

the class NetworkServiceImpl method getWifiInterfaceAddresses.

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

Aggregations

UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 KuraException (org.eclipse.kura.KuraException)1 WifiAccessPointImpl (org.eclipse.kura.core.net.WifiAccessPointImpl)1 WifiInterfaceAddressImpl (org.eclipse.kura.core.net.WifiInterfaceAddressImpl)1 LinuxIfconfig (org.eclipse.kura.linux.net.util.LinuxIfconfig)1 ConnectionInfo (org.eclipse.kura.net.ConnectionInfo)1 WifiInterfaceAddress (org.eclipse.kura.net.wifi.WifiInterfaceAddress)1 WifiMode (org.eclipse.kura.net.wifi.WifiMode)1 WifiSecurity (org.eclipse.kura.net.wifi.WifiSecurity)1