Skip to content

Commit

Permalink
fix(nm): AP scan not reports correct Wifi Security (#5491)
Browse files Browse the repository at this point in the history
* Added recognition logic for wireless security

Signed-off-by: pierantoniomerlino <[email protected]>

* Updated network status rest provider

Signed-off-by: pierantoniomerlino <[email protected]>

* Added missing wifi flags

Signed-off-by: pierantoniomerlino <[email protected]>

* Limit wifi security to WEP/WPA/WPA2

Signed-off-by: pierantoniomerlino <[email protected]>

* Added tests for new AP flags enum

Signed-off-by: pierantoniomerlino <[email protected]>

* Fixed versions

Signed-off-by: pierantoniomerlino <[email protected]>

* Adapted Network status rest tests with the new flags prop

Signed-off-by: pierantoniomerlino <[email protected]>

* Fixed no auth hotspots detection

Signed-off-by: pierantoniomerlino <[email protected]>

* Improved log message

Signed-off-by: pierantoniomerlino <[email protected]>

* Updated missing copyright

Signed-off-by: pierantoniomerlino <[email protected]>

---------

Signed-off-by: pierantoniomerlino <[email protected]>
  • Loading branch information
pierantoniomerlino authored Nov 1, 2024
1 parent dac4507 commit 6e4aee8
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 53 deletions.
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 @@ -67,7 +67,7 @@ Export-Package: org.eclipse.kura;version="1.7.0",
org.eclipse.kura.net.status.loopback;version="1.0.0",
org.eclipse.kura.net.status.modem;version="1.1.0",
org.eclipse.kura.net.status.vlan;version="1.0.0",
org.eclipse.kura.net.status.wifi;version="1.0.0",
org.eclipse.kura.net.status.wifi;version="1.1.0",
org.eclipse.kura.net.vlan;version="1.0.0",
org.eclipse.kura.net.wifi;version="2.5.0",
org.eclipse.kura.position;version="1.4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
* Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -37,6 +37,7 @@ public class WifiAccessPoint {
private final int signalStrength;
private final Set<WifiSecurity> wpaSecurity;
private final Set<WifiSecurity> rsnSecurity;
private final Set<WifiFlag> flags;

private WifiAccessPoint(WifiAccessPointBuilder builder) {
this.ssid = builder.ssid;
Expand All @@ -48,6 +49,7 @@ private WifiAccessPoint(WifiAccessPointBuilder builder) {
this.signalStrength = builder.signalStrength;
this.wpaSecurity = builder.wpaSecurity;
this.rsnSecurity = builder.rsnSecurity;
this.flags = builder.flags;
}

/**
Expand Down Expand Up @@ -131,6 +133,17 @@ public Set<WifiSecurity> getRsnSecurity() {
return this.rsnSecurity;
}

/**
* Return the capabilities of the access point.
*
* @return a set of {@link WifiFlag} representing the capabilities
*
* @since 2.8
*/
public Set<WifiFlag> getFlags() {
return this.flags;
}

public static WifiAccessPointBuilder builder() {
return new WifiAccessPointBuilder();
}
Expand All @@ -146,6 +159,7 @@ public static final class WifiAccessPointBuilder {
private int signalStrength;
private Set<WifiSecurity> wpaSecurity = Collections.emptySet();
private Set<WifiSecurity> rsnSecurity = Collections.emptySet();
private Set<WifiFlag> flags = Collections.emptySet();

private WifiAccessPointBuilder() {
}
Expand Down Expand Up @@ -195,6 +209,11 @@ public WifiAccessPointBuilder withRsnSecurity(Set<WifiSecurity> rsnSecurity) {
return this;
}

public WifiAccessPointBuilder withFlags(Set<WifiFlag> flags) {
this.flags = flags;
return this;
}

public WifiAccessPoint build() {
return new WifiAccessPoint(this);
}
Expand All @@ -206,7 +225,7 @@ public int hashCode() {
int result = 1;
result = prime * result + Arrays.hashCode(this.hardwareAddress);
result = prime * result + Objects.hash(this.channel, this.maxBitrate, this.mode, this.rsnSecurity,
this.signalQuality, this.signalStrength, this.ssid, this.wpaSecurity);
this.signalQuality, this.signalStrength, this.ssid, this.wpaSecurity, this.flags);
return result;
}

Expand All @@ -223,7 +242,7 @@ public boolean equals(Object obj) {
&& this.maxBitrate == other.maxBitrate && this.mode == other.mode
&& Objects.equals(this.rsnSecurity, other.rsnSecurity) && this.signalQuality == other.signalQuality
&& Objects.equals(this.ssid, other.ssid) && Objects.equals(this.signalStrength, other.signalStrength)
&& Objects.equals(this.wpaSecurity, other.wpaSecurity);
&& Objects.equals(this.wpaSecurity, other.wpaSecurity) && Objects.equals(this.flags, other.flags);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
******************************************************************************/
package org.eclipse.kura.net.status.wifi;

/**
* Flags describing the capabilities of an Access Point.
*
* @since 2.8
*/
public enum WifiFlag {
/** None */
NONE,
/** Supports authentication and encryption */
PRIVACY,
/** Supports WPS */
WPS,
/** Supports push-button based WPS */
WPS_PBC,
/** Supports PIN based WPS */
WPS_PIN;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.nm.enums;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.freedesktop.dbus.types.UInt32;

public enum NM80211ApFlags {

NM_802_11_AP_FLAGS_NONE(0x00000000),
NM_802_11_AP_FLAGS_PRIVACY(0x00000001),
NM_802_11_AP_FLAGS_WPS(0x00000002),
NM_802_11_AP_FLAGS_WPS_PBC(0x00000004),
NM_802_11_AP_FLAGS_WPS_PIN(0x00000008);

private final int value;

private NM80211ApFlags(int value) {
this.value = value;
}

public static List<NM80211ApFlags> fromUInt32(UInt32 val) {
int intVal = val.intValue();

if (intVal == NM80211ApFlags.NM_802_11_AP_FLAGS_NONE.value) {
return Arrays.asList(NM80211ApFlags.NM_802_11_AP_FLAGS_NONE);
}

List<NM80211ApFlags> flags = new ArrayList<>();

for (NM80211ApFlags flag : NM80211ApFlags.values()) {
if (flag == NM80211ApFlags.NM_802_11_AP_FLAGS_NONE) {
continue;
}

if ((intVal & flag.value) == flag.value) {
flags.add(flag);
}
}

return flags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.eclipse.kura.net.status.wifi.WifiAccessPoint;
import org.eclipse.kura.net.status.wifi.WifiAccessPoint.WifiAccessPointBuilder;
import org.eclipse.kura.net.status.wifi.WifiCapability;
import org.eclipse.kura.net.status.wifi.WifiFlag;
import org.eclipse.kura.net.status.wifi.WifiInterfaceStatus;
import org.eclipse.kura.net.status.wifi.WifiInterfaceStatus.WifiInterfaceStatusBuilder;
import org.eclipse.kura.net.status.wifi.WifiMode;
Expand All @@ -73,6 +74,7 @@
import org.eclipse.kura.nm.enums.MMModemState;
import org.eclipse.kura.nm.enums.MMSimEsimStatus;
import org.eclipse.kura.nm.enums.MMSimType;
import org.eclipse.kura.nm.enums.NM80211ApFlags;
import org.eclipse.kura.nm.enums.NM80211ApSecurityFlags;
import org.eclipse.kura.nm.enums.NM80211Mode;
import org.eclipse.kura.nm.enums.NMDeviceState;
Expand Down Expand Up @@ -420,6 +422,9 @@ private static WifiAccessPoint wifiAccessPointConvert(Properties nmAccessPoint)
.fromUInt32(nmAccessPoint.Get(NM_ACCESSPOINT_BUS_NAME, "RsnFlags"));
builder.withRsnSecurity(wifiSecurityFlagConvert(rsnSecurityFlags));

List<NM80211ApFlags> flags = NM80211ApFlags.fromUInt32(nmAccessPoint.Get(NM_ACCESSPOINT_BUS_NAME, "Flags"));
builder.withFlags(wifiFlagConvert(flags));

return builder.build();
}

Expand Down Expand Up @@ -448,6 +453,9 @@ private static int channelFrequencyConvert(int fMHz) {
private static Set<WifiSecurity> wifiSecurityFlagConvert(List<NM80211ApSecurityFlags> nmSecurityFlags) {
List<WifiSecurity> kuraSecurityFlags = new ArrayList<>();

if (nmSecurityFlags.isEmpty()) {
kuraSecurityFlags.add(WifiSecurity.NONE);
}
for (NM80211ApSecurityFlags nmFlag : nmSecurityFlags) {
kuraSecurityFlags.add(wifiSecurityFlagConvert(nmFlag));
}
Expand Down Expand Up @@ -492,6 +500,36 @@ private static WifiSecurity wifiSecurityFlagConvert(NM80211ApSecurityFlags nmFla
}
}

private static Set<WifiFlag> wifiFlagConvert(List<NM80211ApFlags> nmFlags) {
List<WifiFlag> kuraFlags = new ArrayList<>();

if (nmFlags.isEmpty()) {
kuraFlags.add(WifiFlag.NONE);
}
for (NM80211ApFlags nmFlag : nmFlags) {
kuraFlags.add(wifiFlagConvert(nmFlag));
}

return new HashSet<>(kuraFlags);
}

private static WifiFlag wifiFlagConvert(NM80211ApFlags nmFlag) {
switch (nmFlag) {
case NM_802_11_AP_FLAGS_NONE:
return WifiFlag.NONE;
case NM_802_11_AP_FLAGS_PRIVACY:
return WifiFlag.PRIVACY;
case NM_802_11_AP_FLAGS_WPS:
return WifiFlag.WPS;
case NM_802_11_AP_FLAGS_WPS_PBC:
return WifiFlag.WPS_PBC;
case NM_802_11_AP_FLAGS_WPS_PIN:
return WifiFlag.WPS_PIN;
default:
throw new IllegalArgumentException(String.format("Non convertible NM80211ApFlag \"%s\"", nmFlag));
}
}

private static Set<WifiCapability> wifiCapabilitiesConvert(List<NMDeviceWifiCapabilities> nmCapabilities) {
List<WifiCapability> kuraCapabilities = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Import-Package: javax.annotation.security;version="1.2.0",
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.1,1.2)",
org.eclipse.kura.net.status.wifi;version="[1.0,1.1)",
org.eclipse.kura.net.status.wifi;version="[1.1,1.2)",
org.eclipse.kura.request.handler.jaxrs;version="[1.0,2.0)",
org.eclipse.kura.request.handler.jaxrs.annotation;version="[1.0,2.0)",
org.osgi.service.useradmin;version="1.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
* Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,7 @@
import java.util.Set;

import org.eclipse.kura.net.status.wifi.WifiAccessPoint;
import org.eclipse.kura.net.status.wifi.WifiFlag;
import org.eclipse.kura.net.status.wifi.WifiMode;
import org.eclipse.kura.net.status.wifi.WifiSecurity;

Expand All @@ -30,6 +31,7 @@ public class WifiAccessPointDTO {
private final int signalStrength;
private final Set<WifiSecurity> wpaSecurity;
private final Set<WifiSecurity> rsnSecurity;
private final Set<WifiFlag> flags;

public WifiAccessPointDTO(final WifiAccessPoint accessPoint) {
this.ssid = accessPoint.getSsid();
Expand All @@ -41,5 +43,6 @@ public WifiAccessPointDTO(final WifiAccessPoint accessPoint) {
this.signalStrength = accessPoint.getSignalStrength();
this.wpaSecurity = accessPoint.getWpaSecurity();
this.rsnSecurity = accessPoint.getRsnSecurity();
this.flags = accessPoint.getFlags();
}
}
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.web2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Import-Package: com.eclipsesource.json;version="0.9.5",
org.eclipse.kura.net.status.ethernet;version="[1.0,2.0)",
org.eclipse.kura.net.status.modem;version="[1.1,2.0)",
org.eclipse.kura.net.status.vlan;version="[1.0,2.0)",
org.eclipse.kura.net.status.wifi;version="[1.0,2.0)",
org.eclipse.kura.net.status.wifi;version="[1.1,2.0)",
org.eclipse.kura.net.vlan;version="[1.0,2.0)",
org.eclipse.kura.net.wifi;version="[2.4,3.0)",
org.eclipse.kura.position;version="[1.0,2.0)",
Expand Down
Loading

0 comments on commit 6e4aee8

Please sign in to comment.