use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.
the class NetworkServiceImpl method getWifiInterfaceAddresses.
private List<WifiInterfaceAddress> getWifiInterfaceAddresses(String interfaceName, boolean isUp) throws KuraException {
List<WifiInterfaceAddress> wifiInterfaceAddresses = new ArrayList<WifiInterfaceAddress>();
if (isUp) {
ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
WifiInterfaceAddressImpl wifiInterfaceAddress = new WifiInterfaceAddressImpl();
wifiInterfaceAddresses.add(wifiInterfaceAddress);
try {
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
String currentNetmask = ifconfig.getInetMask();
if (currentNetmask != null) {
wifiInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
wifiInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
wifiInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
wifiInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
wifiInterfaceAddress.setGateway(conInfo.getGateway());
wifiInterfaceAddress.setDnsServers(conInfo.getDnsServers());
WifiMode wifiMode = LinuxNetworkUtil.getWifiMode(interfaceName);
wifiInterfaceAddress.setBitrate(LinuxNetworkUtil.getWifiBitrate(interfaceName));
wifiInterfaceAddress.setMode(wifiMode);
// TODO - should this only be the AP we are connected to in client mode?
if (wifiMode == WifiMode.INFRA) {
String currentSSID = LinuxNetworkUtil.getSSID(interfaceName);
if (currentSSID != null) {
s_logger.debug("Adding access point SSID: {}", currentSSID);
WifiAccessPointImpl wifiAccessPoint = new WifiAccessPointImpl(currentSSID);
// FIXME: fill in other info
wifiAccessPoint.setMode(WifiMode.INFRA);
List<Long> bitrate = new ArrayList<Long>();
bitrate.add(54000000L);
wifiAccessPoint.setBitrate(bitrate);
wifiAccessPoint.setFrequency(12345);
wifiAccessPoint.setHardwareAddress("20AA4B8A6442".getBytes());
wifiAccessPoint.setRsnSecurity(EnumSet.allOf(WifiSecurity.class));
wifiAccessPoint.setStrength(1234);
wifiAccessPoint.setWpaSecurity(EnumSet.allOf(WifiSecurity.class));
wifiInterfaceAddress.setWifiAccessPoint(wifiAccessPoint);
}
}
} else {
return null;
}
} else {
return null;
}
} catch (UnknownHostException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
return wifiInterfaceAddresses;
}
use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.
the class NetworkServiceImpl method getModemInterface.
private ModemInterface<ModemInterfaceAddress> getModemInterface(String interfaceName, boolean isUp, ModemDevice modemDevice) throws KuraException {
ModemInterfaceImpl<ModemInterfaceAddress> modemInterface = new ModemInterfaceImpl<ModemInterfaceAddress>(interfaceName);
modemInterface.setModemDevice(modemDevice);
if (modemDevice instanceof UsbModemDevice) {
UsbModemDevice usbModemDevice = (UsbModemDevice) modemDevice;
SupportedUsbModemInfo supportedUsbModemInfo = null;
supportedUsbModemInfo = SupportedUsbModemsInfo.getModem(usbModemDevice.getVendorId(), usbModemDevice.getProductId(), usbModemDevice.getProductName());
modemInterface.setTechnologyTypes(supportedUsbModemInfo.getTechnologyTypes());
modemInterface.setUsbDevice((UsbModemDevice) modemDevice);
} else if (modemDevice instanceof SerialModemDevice) {
SupportedSerialModemInfo supportedSerialModemInfo = null;
supportedSerialModemInfo = SupportedSerialModemsInfo.getModem();
modemInterface.setTechnologyTypes(supportedSerialModemInfo.getTechnologyTypes());
}
int pppNum = 0;
if (interfaceName.startsWith("ppp")) {
pppNum = Integer.parseInt(interfaceName.substring(3));
}
modemInterface.setPppNum(pppNum);
modemInterface.setManufacturer(modemDevice.getManufacturerName());
modemInterface.setModel(modemDevice.getProductName());
modemInterface.setModemIdentifier(modemDevice.getProductName());
// these properties required net.admin packages
modemInterface.setDriver(getDriver());
modemInterface.setDriverVersion(getDriverVersion());
modemInterface.setFirmwareVersion(getFirmwareVersion());
modemInterface.setSerialNumber("unknown");
modemInterface.setLoopback(false);
modemInterface.setPointToPoint(true);
modemInterface.setState(getState(interfaceName, isUp));
modemInterface.setHardwareAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
modemInterface.setMTU(ifconfig.getMtu());
modemInterface.setSupportsMulticast(ifconfig.isMulticast());
}
modemInterface.setUp(isUp);
modemInterface.setVirtual(isVirtual());
modemInterface.setNetInterfaceAddresses(getModemInterfaceAddresses(interfaceName, isUp));
return modemInterface;
}
use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.
the class NetworkServiceImpl method getNetInterfaceAddresses.
private List<NetInterfaceAddress> getNetInterfaceAddresses(String interfaceName, NetInterfaceType type, boolean isUp) throws KuraException {
List<NetInterfaceAddress> netInterfaceAddresses = new ArrayList<NetInterfaceAddress>();
if (isUp) {
ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
NetInterfaceAddressImpl netInterfaceAddress = new NetInterfaceAddressImpl();
try {
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
String currentNetmask = ifconfig.getInetMask();
if (currentNetmask != null) {
netInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
netInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
netInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
netInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
netInterfaceAddress.setGateway(conInfo.getGateway());
if (type == NetInterfaceType.MODEM) {
if (isUp) {
netInterfaceAddress.setDnsServers(LinuxDns.getInstance().getPppDnServers());
}
} else {
netInterfaceAddress.setDnsServers(conInfo.getDnsServers());
}
netInterfaceAddresses.add(netInterfaceAddress);
}
}
} catch (UnknownHostException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
return netInterfaceAddresses;
}
use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.
the class Ppp method getIPaddress.
@Override
public String getIPaddress() throws KuraException {
String ipAddress = null;
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(this.m_iface);
if (ifconfig != null) {
ipAddress = ifconfig.getInetAddress();
}
return ipAddress;
}
use of org.eclipse.kura.linux.net.util.LinuxIfconfig in project kura by eclipse.
the class NetworkServiceImpl method getModemInterfaceAddresses.
private List<ModemInterfaceAddress> getModemInterfaceAddresses(String interfaceName, boolean isUp) throws KuraException {
List<ModemInterfaceAddress> modemInterfaceAddresses = new ArrayList<ModemInterfaceAddress>();
if (isUp) {
ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
ModemInterfaceAddressImpl modemInterfaceAddress = new ModemInterfaceAddressImpl();
modemInterfaceAddresses.add(modemInterfaceAddress);
try {
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
String currentNetmask = ifconfig.getInetMask();
if (currentNetmask != null) {
modemInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
modemInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
modemInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
modemInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
modemInterfaceAddress.setGateway(conInfo.getGateway());
modemInterfaceAddress.setDnsServers(conInfo.getDnsServers());
ModemConnectionStatus connectionStatus = isUp ? ModemConnectionStatus.CONNECTED : ModemConnectionStatus.DISCONNECTED;
modemInterfaceAddress.setConnectionStatus(connectionStatus);
// TODO - other attributes
} else {
return null;
}
} else {
return null;
}
} catch (UnknownHostException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
return modemInterfaceAddresses;
}
Aggregations