Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added trigger scan button #4791

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion kura/distrib/src/main/resources/common/manage_kura_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ ResultInactive=no
ResultActive=no
ResultAny=yes" >/etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modemmanager.pkla
fi
if [ ! -f /etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla ]; then
echo "[No password prompt for kurad user when using Wpa Supplicant]
Identity=unix-user:kurad
Action=fi.w1.wpa_supplicant1.*
ResultInactive=no
ResultActive=no
ResultAny=yes" >/etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla
fi
fi
else
if [[ $NN == "NO" ]]; then
Expand All @@ -81,7 +89,8 @@ ResultAny=yes" >/etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modem
if [ ! -f /usr/share/polkit-1/rules.d/kura-nm.rules ]; then
echo "polkit.addRule(function(action, subject) {
if ((action.id.indexOf(\"org.freedesktop.NetworkManager.\") == 0 ||
action.id.indexOf(\"org.freedesktop.ModemManager1.\") == 0) &&
action.id.indexOf(\"org.freedesktop.ModemManager1.\") == 0 ||
action.id.indexOf(\"fi.w1.wpa_supplicant1.\") == 0) &&
subject.user == \"kurad\") {
return polkit.Result.YES;
}
Expand Down Expand Up @@ -130,6 +139,21 @@ if (action.id == \"org.freedesktop.systemd1.manage-unit-files\" &&
done = 1
} 1' /etc/dbus-1/system.d/bluetooth.conf >tempfile && mv tempfile /etc/dbus-1/system.d/bluetooth.conf
fi

# grant kurad user the privileges to manage wpa supplicant via dbus
grep -lR kurad /etc/dbus-1/system.d/wpa_supplicant.conf
if [ $?!= 0 ]; then
cp /etc/dbus-1/system.d/wpa_supplicant.conf /etc/dbus-1/system.d/wpa_supplicant.conf.save
awk 'done != 1 && /^<\/busconfig>/ {
print " <policy user=\"kurad\">"
print " <allow own=\"fi.w1.wpa_supplicant1\"/>"
print " <allow send_destination=\"fi.w1.wpa_supplicant1\"/>"
print " <allow send_interface=\"fi.w1.wpa_supplicant1\"/>"
print " <allow receive_sender=\"fi.w1.wpa_supplicant1\" receive_type=\"signal\"/>"
print " </policy>\n"
done = 1
} 1' /etc/dbus-1/system.d/wpa_supplicant.conf >tempfile && mv tempfile /etc/dbus-1/system.d/wpa_supplicant.conf
fi

# Change kura folder ownership and permission
chown -R kurad:kurad /opt/eclipse
Expand Down Expand Up @@ -161,6 +185,9 @@ function delete_users {
if [ -f /etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modemmanager.pkla ]; then
rm -f /etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modemmanager.pkla
fi
if [ -f /etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla ]; then
rm -f /etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla
fi

# recover pam policy
if [ -f /etc/pam.d/su ]; then
Expand All @@ -170,6 +197,7 @@ function delete_users {

# recover old dbus config
mv /etc/dbus-1/system.d/bluetooth.conf.save /etc/dbus-1/system.d/bluetooth.conf
mv /etc/dbus-1/system.d/wpa_supplicant.conf.save /etc/dbus-1/system.d/wpa_supplicant.conf
}

INSTALL=YES
Expand Down
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Export-Package: org.eclipse.kura;version="1.7.0",
org.eclipse.kura.net.firewall;version="2.0.0",
org.eclipse.kura.net.modem;version="2.4.0",
org.eclipse.kura.net.route;version="1.0.2",
org.eclipse.kura.net.status;version="1.0.0",
org.eclipse.kura.net.status;version="1.1.0",
org.eclipse.kura.net.status.ethernet;version="1.0.0",
org.eclipse.kura.net.status.loopback;version="1.0.0",
org.eclipse.kura.net.status.modem;version="1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,36 @@ public interface NetworkStatusService {
* it is the usb or pci path.
* If the interface doesn't exist, an Empty value is returned.
*
* @param id
* @param interfaceId
* the identifier of the network interface
* @return the {@link NetworkInterfaceStatus}
* @throws KuraException
* when an error occurs while retrieving the status of the
* given interface
*/
public Optional<NetworkInterfaceStatus> getNetworkStatus(String interfaceName) throws KuraException;
public Optional<NetworkInterfaceStatus> getNetworkStatus(String interfaceId) throws KuraException;

/**
* Return an optional {@link NetworkInterfaceStatus} of the given network
* interface selected by its name.For Ethernet and WiFi interfaces, the
* identifier is typically the interface name. For the modems, instead,
salvatore-coppola marked this conversation as resolved.
Show resolved Hide resolved
* it is the usb or pci path.
* If the interface doesn't exist, an Empty value is returned.
*
salvatore-coppola marked this conversation as resolved.
Show resolved Hide resolved
* @param interfaceId
* the identifier of the network interface
* @param recompute
* If set to true, the NetworkStatusService will perform some additional expansive operations (like AP
* scanning) to ensure the status returned by the method is up to date. If set to false, it will return
* the status as returned by the network configuration provider.
* @return the {@link NetworkInterfaceStatus}
* @throws KuraException
* when an error occurs while retrieving the status of the
* given interface
*/

public Optional<NetworkInterfaceStatus> getNetworkStatus(String interfaceId, boolean recompute)
throws KuraException;

/**
* Return the identifiers of the network interfaces detected in the
Expand Down
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.nm/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Import-Package: org.apache.commons.io;version="2.4.0",
org.eclipse.kura.net.dhcp;version="[1.2,2.0)",
org.eclipse.kura.net.dns;version="[1.0,2.0)",
org.eclipse.kura.net.modem;version="[2.4,3.0)",
org.eclipse.kura.net.status;version="[1.0,1.1)",
org.eclipse.kura.net.status;version="[1.1,1.2)",
org.eclipse.kura.net.status.ethernet;version="[1.0,2.0)",
org.eclipse.kura.net.status.loopback;version="[1.0,2.0)",
org.eclipse.kura.net.status.modem;version="[1.0,2.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ModemManagerDbusWrapper {
private static final String MM_MODEM_PROPERTY_STATE = "State";
private static final String MM_LOCATION_BUS_NAME = "org.freedesktop.ModemManager1.Modem.Location";

private DBusConnection dbusConnection;
private final DBusConnection dbusConnection;

private final Map<String, NMModemResetHandler> modemHandlers = new HashMap<>();

Expand Down Expand Up @@ -140,7 +140,7 @@ protected List<SimProperties> getModemSimProperties(Properties modemProperties)

Properties simProp = this.dbusConnection.getRemoteObject(MM_BUS_NAME, dbusPath, Properties.class);
boolean isActive = simProp.Get(MM_SIM_NAME, "Active");
boolean isPrimary = index == (primarySimSlot.intValue() - 1);
boolean isPrimary = index == primarySimSlot.intValue() - 1;

simProperties.add(new SimProperties(simProp, isActive, isPrimary));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ public class NMDbusConnector {
NMDeviceType.NM_DEVICE_TYPE_MODEM, NMDeviceType.NM_DEVICE_TYPE_ETHERNET, NMDeviceType.NM_DEVICE_TYPE_WIFI,
NMDeviceType.NM_DEVICE_TYPE_LOOPBACK);

private static final long MAX_SCAN_TIME_SECONDS = 30L;

private static NMDbusConnector instance;
private final DBusConnection dbusConnection;
private final NetworkManagerDbusWrapper networkManager;
private final ModemManagerDbusWrapper modemManager;
private final WpaSupplicantDbusWrapper wpaSupplicant;

private Map<String, Object> cachedConfiguration = null;

Expand All @@ -90,6 +93,7 @@ private NMDbusConnector(DBusConnection dbusConnection) throws DBusException {
this.dbusConnection = Objects.requireNonNull(dbusConnection);
this.networkManager = new NetworkManagerDbusWrapper(this.dbusConnection);
this.modemManager = new ModemManagerDbusWrapper(this.dbusConnection);
this.wpaSupplicant = new WpaSupplicantDbusWrapper(this.dbusConnection);
}

public static synchronized NMDbusConnector getInstance() throws DBusException {
Expand Down Expand Up @@ -188,9 +192,10 @@ public String getInterfaceIdByDBusPath(String dbusPath) throws DBusException {
}
}

public synchronized NetworkInterfaceStatus getInterfaceStatus(String interfaceId,
public synchronized NetworkInterfaceStatus getInterfaceStatus(String interfaceId, boolean recompute,
CommandExecutorService commandExecutorService) throws DBusException, KuraException {
NetworkInterfaceStatus networkInterfaceStatus = null;

Optional<Device> device = getNetworkManagerDeviceByInterfaceId(interfaceId);
if (device.isPresent()) {
NMDeviceType deviceType = this.networkManager.getDeviceType(device.get().getObjectPath());
Expand Down Expand Up @@ -231,6 +236,10 @@ public synchronized NetworkInterfaceStatus getInterfaceStatus(String interfaceId
ip4configProperties);
break;
case NM_DEVICE_TYPE_WIFI:
if (recompute) {
wpaSupplicant.syncScan(interfaceId, MAX_SCAN_TIME_SECONDS);
}

networkInterfaceStatus = createWirelessStatus(interfaceId, commandExecutorService, device.get(),
deviceProperties, ip4configProperties);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class NetworkManagerDbusWrapper {
private static final String NM_SETTING_CONNECTION_KEY = "connection";
private static final String NM_DEVICE_GENERIC_PROPERTY_TYPEDESCRIPTION = "TypeDescription";

private DBusConnection dbusConnection;
private NetworkManager networkManager;
private final DBusConnection dbusConnection;
private final NetworkManager networkManager;

protected NetworkManagerDbusWrapper(DBusConnection dbusConnection) throws DBusException {
this.dbusConnection = dbusConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class WpaSupplicantDbusWrapper {
private static final long DEFAULT_SCAN_TIMEOUT_SECONDS = 30;

private final DBusConnection dbusConnection;
private Wpa_supplicant1 wpaSupplicant;
private final Wpa_supplicant1 wpaSupplicant;

public WpaSupplicantDbusWrapper(DBusConnection dbusConnection) throws DBusException {
this.dbusConnection = dbusConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ private String getInterfaceName(Map<String, Object> properties, String interface
NetInterfaceType type = NetInterfaceType
.valueOf((String) properties.get(String.format(PREFIX + "%s.type", interfaceId)));
if (NetInterfaceType.MODEM.equals(type)) {
Integer pppNum = (Integer) properties
.get(String.format(PREFIX + "%s.config.pppNum", interfaceId));
Integer pppNum = (Integer) properties.get(String.format(PREFIX + "%s.config.pppNum", interfaceId));
interfaceName = "ppp" + pppNum;
} else {
interfaceName = interfaceId;
Expand Down Expand Up @@ -430,11 +429,7 @@ private boolean isDhcpServerValid(String interfaceName) {
final NetInterfaceStatus status = getNetInterfaceStatus(interfaceName)
.orElse(NetInterfaceStatus.netIPv4StatusUnknown);

if (type != NetInterfaceType.ETHERNET && type != NetInterfaceType.WIFI) {
return false;
}

if (!isDhcpServerEnabled) {
if ((type != NetInterfaceType.ETHERNET && type != NetInterfaceType.WIFI) || !isDhcpServerEnabled) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class DnsServerMonitor {
private final CommandExecutorService executorService;
private NetworkProperties networkProperties;

private LinuxNetworkUtil linuxNetworkUtil;
private final LinuxNetworkUtil linuxNetworkUtil;

public DnsServerMonitor(DnsServerService dnsServerService, CommandExecutorService executorService) {

Expand Down Expand Up @@ -158,7 +158,8 @@ private Set<NetworkPair<IP4Address>> getAllowedNetworks() {

}

private void addToAllowedNetworksIfPassDnsEnabled(Set<NetworkPair<IP4Address>> allowedNetworks, NetConfig netConfig) {
private void addToAllowedNetworksIfPassDnsEnabled(Set<NetworkPair<IP4Address>> allowedNetworks,
NetConfig netConfig) {
if (isPassDnsEnabled(netConfig)) {

DhcpServerConfig dhcpServerConfig = (DhcpServerConfig) netConfig;
Expand Down Expand Up @@ -190,7 +191,7 @@ private boolean isEnabledForLan(NetInterfaceConfig<? extends NetInterfaceAddress
}

public boolean isPassDnsEnabled(NetConfig netConfig) {
return (netConfig instanceof DhcpServerConfig && ((DhcpServerConfig) netConfig).isPassDns());
return netConfig instanceof DhcpServerConfig && ((DhcpServerConfig) netConfig).isPassDns();
}

private Set<IP4Address> getForwarders(Set<IPAddress> dnsServers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,12 @@ private void writeConfigFile(String configFileName, String ifaceName, DhcpServer
addDNSServersOption(dhcpServerConfig, pw);
} else if (dhcpServerTool == DhcpServerTool.DNSMASQ) {
pw.println("interface=" + dhcpServerConfig.getInterfaceName());

StringBuilder dhcpRangeProp = new StringBuilder("dhcp-range=")
.append(this.interfaceName)
.append(",")
.append(dhcpServerConfig.getRangeStart())
.append(",")
.append(dhcpServerConfig.getRangeEnd())
.append(",")
.append(dhcpServerConfig.getDefaultLeaseTime()).append("s");

StringBuilder dhcpRangeProp = new StringBuilder("dhcp-range=").append(this.interfaceName).append(",")
.append(dhcpServerConfig.getRangeStart()).append(",").append(dhcpServerConfig.getRangeEnd())
.append(",").append(dhcpServerConfig.getDefaultLeaseTime()).append("s");
pw.println(dhcpRangeProp.toString());

pw.println(DHCP_OPTION_KEY + this.interfaceName + ",1,"
+ NetworkUtil.getNetmaskStringForm(dhcpServerConfig.getPrefix()));
// router property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public class FirewallNatConfigWriter {
private static final Logger logger = LoggerFactory.getLogger(FirewallNatConfigWriter.class);

private final CommandExecutorService executorService;
private LinuxFirewall firewall;
private final LinuxFirewall firewall;
private final List<String> wanInterfaceNames;
private final List<String> natInterfaceNames;

public FirewallNatConfigWriter(CommandExecutorService executorService, List<String> wanInterfaceNames, List<String> natInterfaceNames) {
public FirewallNatConfigWriter(CommandExecutorService executorService, List<String> wanInterfaceNames,
List<String> natInterfaceNames) {
this.executorService = executorService;
this.wanInterfaceNames = wanInterfaceNames;
this.natInterfaceNames = natInterfaceNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static Set<MMModemLocationSource> toMMModemLocationSourceFromBitMask(UInt
public static UInt32 toBitMaskFromMMModemLocationSource(Set<MMModemLocationSource> desiredLocationSources) {
long bitmask = 0x00000000;
for (MMModemLocationSource source : desiredLocationSources) {
bitmask = (bitmask | source.value);
bitmask = bitmask | source.value;
}

return new UInt32(bitmask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ private static NetworkInterfaceState deviceStateConvert(NMDeviceState state) {
* https://github.com/torvalds/linux/blob/c9c3395d5e3dcc6daee66c6908354d47bf98cb0c/drivers/net/wireless/intel/ipw2x00/ipw2200.c#L4305
* and
* https://github.com/torvalds/linux/blob/c9c3395d5e3dcc6daee66c6908354d47bf98cb0c/drivers/net/wireless/intel/ipw2x00/ipw2200.c#L11664
*
*
* signalQuality = (100 * DeltaRSSI^2 - (RSSIMax - RSSI)*(15*DeltaRSSI + 62*DeltaRSSI))/DeltaRSSI^2
*/
protected static int convertToWifiSignalStrength(int signalQuality) {
Expand All @@ -791,7 +791,7 @@ protected static int convertToWifiSignalStrength(int signalQuality) {
* the command at+csq (https://m2msupport.net/m2msupport/atcsq-signal-quality/),
* the following method converts the signalQuality to the csq value and finally
* convert this to the signal strength [dBm]:
*
*
* signalQuality = 100/30 * csq
* signalStrength = -113 + 2 * csq
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,9 @@ public void deactivate() {
}

@Override
public Optional<NetworkInterfaceStatus> getNetworkStatus(String id) throws KuraException {
Optional<NetworkInterfaceStatus> networkInterfaceStatus = Optional.empty();
try {
NetworkInterfaceStatus status = this.nmDbusConnector.getInterfaceStatus(id, this.commandExecutorService);
if (Objects.nonNull(status)) {
networkInterfaceStatus = Optional.of(status);
}
} catch (UnknownMethod e) {
throw new KuraIOException(e, "Could not retrieve status for " + id
+ " interface from NM because the DBus object path references got invalidated.");
} catch (DBusException e) {
throw new KuraIOException(e, "Could not retrieve status for " + id + " interface from NM.");
}
public Optional<NetworkInterfaceStatus> getNetworkStatus(String interfaceId) throws KuraException {

return networkInterfaceStatus;
return getNetworkStatus(interfaceId, false);
}

@Override
Expand All @@ -98,4 +86,25 @@ public List<String> getInterfaceIds() throws KuraException {
return interfaces;
}

@Override
public Optional<NetworkInterfaceStatus> getNetworkStatus(String interfaceId, boolean recompute)
throws KuraException {

Optional<NetworkInterfaceStatus> networkInterfaceStatus = Optional.empty();
try {
NetworkInterfaceStatus status = this.nmDbusConnector.getInterfaceStatus(interfaceId, recompute,
this.commandExecutorService);
if (Objects.nonNull(status)) {
networkInterfaceStatus = Optional.of(status);
}
} catch (UnknownMethod e) {
throw new KuraIOException(e, "Could not retrieve status for " + interfaceId
+ " interface from NM because the DBus object path references got invalidated.");
} catch (DBusException e) {
throw new KuraIOException(e, "Could not retrieve status for " + interfaceId + " interface from NM.");
}

return networkInterfaceStatus;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Import-Package: javax.annotation.security;version="1.2.0",
org.eclipse.kura.cloudconnection.request;version="[1.0,2.0)",
org.eclipse.kura.net;version="[2.4,3.0)",
org.eclipse.kura.net.modem;version="[2.4,3.0)",
org.eclipse.kura.net.status;version="[1.0,1.1)",
org.eclipse.kura.net.status;version="[1.1,1.2)",
org.eclipse.kura.net.status.ethernet;version="[1.0,1.1)",
org.eclipse.kura.net.status.modem;version="[1.0,1.1)",
org.eclipse.kura.net.status.wifi;version="[1.0,1.1)",
Expand Down
Loading