diff --git a/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF index e8c99060444..a2e73678689 100644 --- a/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF @@ -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", diff --git a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/net/status/wifi/WifiAccessPoint.java b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/net/status/wifi/WifiAccessPoint.java index 693c463f3e2..8426e6c907a 100644 --- a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/net/status/wifi/WifiAccessPoint.java +++ b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/net/status/wifi/WifiAccessPoint.java @@ -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 @@ -37,6 +37,7 @@ public class WifiAccessPoint { private final int signalStrength; private final Set wpaSecurity; private final Set rsnSecurity; + private final Set flags; private WifiAccessPoint(WifiAccessPointBuilder builder) { this.ssid = builder.ssid; @@ -48,6 +49,7 @@ private WifiAccessPoint(WifiAccessPointBuilder builder) { this.signalStrength = builder.signalStrength; this.wpaSecurity = builder.wpaSecurity; this.rsnSecurity = builder.rsnSecurity; + this.flags = builder.flags; } /** @@ -131,6 +133,17 @@ public Set 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 getFlags() { + return this.flags; + } + public static WifiAccessPointBuilder builder() { return new WifiAccessPointBuilder(); } @@ -146,6 +159,7 @@ public static final class WifiAccessPointBuilder { private int signalStrength; private Set wpaSecurity = Collections.emptySet(); private Set rsnSecurity = Collections.emptySet(); + private Set flags = Collections.emptySet(); private WifiAccessPointBuilder() { } @@ -195,6 +209,11 @@ public WifiAccessPointBuilder withRsnSecurity(Set rsnSecurity) { return this; } + public WifiAccessPointBuilder withFlags(Set flags) { + this.flags = flags; + return this; + } + public WifiAccessPoint build() { return new WifiAccessPoint(this); } @@ -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; } @@ -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); } } diff --git a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/net/status/wifi/WifiFlag.java b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/net/status/wifi/WifiFlag.java new file mode 100644 index 00000000000..2739f45f65c --- /dev/null +++ b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/net/status/wifi/WifiFlag.java @@ -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; + +} diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NM80211ApFlags.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NM80211ApFlags.java new file mode 100644 index 00000000000..b06bbf9457a --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NM80211ApFlags.java @@ -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 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 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; + } +} \ No newline at end of file diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/status/NMStatusConverter.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/status/NMStatusConverter.java index 7c53f518160..bd57501915f 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/status/NMStatusConverter.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/status/NMStatusConverter.java @@ -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; @@ -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; @@ -420,6 +422,9 @@ private static WifiAccessPoint wifiAccessPointConvert(Properties nmAccessPoint) .fromUInt32(nmAccessPoint.Get(NM_ACCESSPOINT_BUS_NAME, "RsnFlags")); builder.withRsnSecurity(wifiSecurityFlagConvert(rsnSecurityFlags)); + List flags = NM80211ApFlags.fromUInt32(nmAccessPoint.Get(NM_ACCESSPOINT_BUS_NAME, "Flags")); + builder.withFlags(wifiFlagConvert(flags)); + return builder.build(); } @@ -448,6 +453,9 @@ private static int channelFrequencyConvert(int fMHz) { private static Set wifiSecurityFlagConvert(List nmSecurityFlags) { List kuraSecurityFlags = new ArrayList<>(); + if (nmSecurityFlags.isEmpty()) { + kuraSecurityFlags.add(WifiSecurity.NONE); + } for (NM80211ApSecurityFlags nmFlag : nmSecurityFlags) { kuraSecurityFlags.add(wifiSecurityFlagConvert(nmFlag)); } @@ -492,6 +500,36 @@ private static WifiSecurity wifiSecurityFlagConvert(NM80211ApSecurityFlags nmFla } } + private static Set wifiFlagConvert(List nmFlags) { + List 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 wifiCapabilitiesConvert(List nmCapabilities) { List kuraCapabilities = new ArrayList<>(); diff --git a/kura/org.eclipse.kura.rest.network.status.provider/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.rest.network.status.provider/META-INF/MANIFEST.MF index a7deb4313a5..3f96746e46e 100644 --- a/kura/org.eclipse.kura.rest.network.status.provider/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.rest.network.status.provider/META-INF/MANIFEST.MF @@ -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", diff --git a/kura/org.eclipse.kura.rest.network.status.provider/src/main/java/org/eclipse/kura/network/status/provider/api/WifiAccessPointDTO.java b/kura/org.eclipse.kura.rest.network.status.provider/src/main/java/org/eclipse/kura/network/status/provider/api/WifiAccessPointDTO.java index ffce0f7f9c5..c532408d0a4 100644 --- a/kura/org.eclipse.kura.rest.network.status.provider/src/main/java/org/eclipse/kura/network/status/provider/api/WifiAccessPointDTO.java +++ b/kura/org.eclipse.kura.rest.network.status.provider/src/main/java/org/eclipse/kura/network/status/provider/api/WifiAccessPointDTO.java @@ -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 @@ -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; @@ -30,6 +31,7 @@ public class WifiAccessPointDTO { private final int signalStrength; private final Set wpaSecurity; private final Set rsnSecurity; + private final Set flags; public WifiAccessPointDTO(final WifiAccessPoint accessPoint) { this.ssid = accessPoint.getSsid(); @@ -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(); } } diff --git a/kura/org.eclipse.kura.web2/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.web2/META-INF/MANIFEST.MF index 8eaa98a713e..9ed008fff65 100644 --- a/kura/org.eclipse.kura.web2/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.web2/META-INF/MANIFEST.MF @@ -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)", diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/status/NetworkStatusServiceAdapter.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/status/NetworkStatusServiceAdapter.java index 344f8c59cb0..dafeed8ae16 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/status/NetworkStatusServiceAdapter.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/status/NetworkStatusServiceAdapter.java @@ -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 @@ -35,6 +35,7 @@ import org.eclipse.kura.net.status.modem.Sim; import org.eclipse.kura.net.status.wifi.WifiAccessPoint; import org.eclipse.kura.net.status.wifi.WifiChannel; +import org.eclipse.kura.net.status.wifi.WifiFlag; import org.eclipse.kura.net.status.wifi.WifiInterfaceStatus; import org.eclipse.kura.net.status.wifi.WifiMode; import org.eclipse.kura.net.status.wifi.WifiSecurity; @@ -159,21 +160,21 @@ public List findWifiHotspots(String interfaceName, boolean for (WifiAccessPoint ap : wifiStatus.getAvailableWifiAccessPoints()) { GwtWifiHotspotEntry entry = new GwtWifiHotspotEntry(); + entry.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_NONE.name()); + entry.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_NONE.name()); + entry.setSecurity(GwtWifiSecurity.netWifiSecurityNONE.name()); + try { + parseAndSetWifiSecurity(entry, ap); + } catch (IllegalArgumentException e) { + logger.warn("Access point security not recognized or supported."); + continue; + } entry.setChannel(ap.getChannel().getChannel()); entry.setFrequency(ap.getChannel().getFrequency()); entry.setMacAddress(NetworkUtil.macToString(ap.getHardwareAddress())); entry.setSSID(ap.getSsid()); entry.setsignalStrength(ap.getSignalStrength()); - // because of GwtWifiHotspotEntry interface does not discriminate RSN/WPA, - // order here is important: - // we assume that WPA security has priority over RSN one - entry.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_NONE.name()); - entry.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_NONE.name()); - entry.setSecurity(GwtWifiSecurity.netWifiSecurityNONE.name()); - parseAndSetWifiSecurity(entry, ap.getRsnSecurity()); - parseAndSetWifiSecurity(entry, ap.getWpaSecurity()); - result.add(entry); } } @@ -380,11 +381,60 @@ private void setWifiSpecificStateProperties(WifiMode wifiMode, GwtWifiNetInterfa gwtConfig.setChannels(channelsBuilder.getChannelsIntegers()); } - private void parseAndSetWifiSecurity(GwtWifiHotspotEntry entryToModify, Set supportedSecurity) { - boolean isGroupCCMP = supportedSecurity.contains(WifiSecurity.GROUP_CCMP); - boolean isGroupTKIP = supportedSecurity.contains(WifiSecurity.GROUP_TKIP); - boolean isPairCCMP = supportedSecurity.contains(WifiSecurity.PAIR_CCMP); - boolean isPairTKIP = supportedSecurity.contains(WifiSecurity.PAIR_TKIP); + private void parseAndSetWifiSecurity(GwtWifiHotspotEntry entryToModify, WifiAccessPoint wifiAccessPoint) { + Set rsnSecurity = wifiAccessPoint.getRsnSecurity(); + Set wpaSecurity = wifiAccessPoint.getWpaSecurity(); + Set flags = wifiAccessPoint.getFlags(); + + if (isSecurityNone(rsnSecurity, wpaSecurity, flags)) { + entryToModify.setSecurity(GwtWifiSecurity.netWifiSecurityNONE.value()); + } else if (isSecurityWEP(rsnSecurity, wpaSecurity, flags)) { + entryToModify.setSecurity(GwtWifiSecurity.netWifiSecurityWEP.value()); + } else if (isSecurityWPA(rsnSecurity, wpaSecurity, flags) && isSecurityWPA2(rsnSecurity, wpaSecurity, flags)) { + entryToModify.setSecurity(GwtWifiSecurity.netWifiSecurityWPA_WPA2.value()); + setCiphers(entryToModify, rsnSecurity); + } else if (isSecurityWPA(rsnSecurity, wpaSecurity, flags)) { + entryToModify.setSecurity(GwtWifiSecurity.netWifiSecurityWPA.value()); + setCiphers(entryToModify, wpaSecurity); + } else if (isSecurityWPA2(rsnSecurity, wpaSecurity, flags)) { + entryToModify.setSecurity(GwtWifiSecurity.netWifiSecurityWPA2.value()); + setCiphers(entryToModify, rsnSecurity); + } else if (isSecurityWPA2WPA3Enterprise(rsnSecurity, wpaSecurity, flags)) { + entryToModify.setSecurity(GwtWifiSecurity.netWifiSecurityWPA2WPA3Enterprise.value()); + setCiphers(entryToModify, rsnSecurity); + } else { + throw new IllegalArgumentException("Security flags not recognized or supported"); + } + } + + private boolean isSecurityNone(Set rsnSecurity, Set wpaSecurity, Set flags) { + return !flags.contains(WifiFlag.PRIVACY) && rsnSecurity.contains(WifiSecurity.NONE) + && wpaSecurity.contains(WifiSecurity.NONE); + } + + private boolean isSecurityWEP(Set rsnSecurity, Set wpaSecurity, Set flags) { + return flags.contains(WifiFlag.PRIVACY) && rsnSecurity.contains(WifiSecurity.NONE) + && wpaSecurity.contains(WifiSecurity.NONE); + } + + private boolean isSecurityWPA(Set rsnSecurity, Set wpaSecurity, Set flags) { + return flags.contains(WifiFlag.PRIVACY) && wpaSecurity.contains(WifiSecurity.KEY_MGMT_PSK); + } + + private boolean isSecurityWPA2(Set rsnSecurity, Set wpaSecurity, Set flags) { + return flags.contains(WifiFlag.PRIVACY) && rsnSecurity.contains(WifiSecurity.KEY_MGMT_PSK); + } + + private boolean isSecurityWPA2WPA3Enterprise(Set rsnSecurity, Set wpaSecurity, + Set flags) { + return flags.contains(WifiFlag.PRIVACY) && (rsnSecurity.contains(WifiSecurity.KEY_MGMT_802_1X)); + } + + private void setCiphers(GwtWifiHotspotEntry entryToModify, Set wifiSecurity) { + boolean isGroupCCMP = wifiSecurity.contains(WifiSecurity.GROUP_CCMP); + boolean isGroupTKIP = wifiSecurity.contains(WifiSecurity.GROUP_TKIP); + boolean isPairCCMP = wifiSecurity.contains(WifiSecurity.PAIR_CCMP); + boolean isPairTKIP = wifiSecurity.contains(WifiSecurity.PAIR_TKIP); if (isGroupCCMP && isGroupTKIP) { entryToModify.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()); @@ -401,27 +451,6 @@ private void parseAndSetWifiSecurity(GwtWifiHotspotEntry entryToModify, Set wifiSecurities) { - StringBuilder prettyPrint = new StringBuilder(); - - for (WifiSecurity wifiSecurity : wifiSecurities) { - String secString = wifiSecurity.name(); - if (secString.contains("KEY_MGMT")) { - prettyPrint.append(secString.replace("KEY_MGMT_", "")); - prettyPrint.append(", "); - } - } - - if (prettyPrint.length() > 2) { - prettyPrint.deleteCharAt(prettyPrint.length() - 1); - prettyPrint.deleteCharAt(prettyPrint.length() - 1); - } - - return prettyPrint.toString(); } private class ChannelsBuilder { diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtWifiSecurity.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtWifiSecurity.java index d2957da58fe..d9273b4b611 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtWifiSecurity.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtWifiSecurity.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2020, 2023 Eurotech and/or its affiliates and others + * Copyright (c) 2011, 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 @@ -13,10 +13,21 @@ package org.eclipse.kura.web.shared.model; public enum GwtWifiSecurity { - netWifiSecurityNONE, - netWifiSecurityWEP, - netWifiSecurityWPA, - netWifiSecurityWPA2, - netWifiSecurityWPA2WPA3Enterprise, - netWifiSecurityWPA_WPA2 + + netWifiSecurityNONE("NONE"), + netWifiSecurityWEP("WEP"), + netWifiSecurityWPA("WPA"), + netWifiSecurityWPA2("WPA2"), + netWifiSecurityWPA2WPA3Enterprise("WPA2/WPA3-Enterprise"), + netWifiSecurityWPA_WPA2("WPA/WPA2"); + + String value; + + private GwtWifiSecurity(String value) { + this.value = value; + } + + public String value() { + return value; + } } diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/enums/NM80211ApFlagsTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/enums/NM80211ApFlagsTest.java new file mode 100644 index 00000000000..f5b0be1c40a --- /dev/null +++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/enums/NM80211ApFlagsTest.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.freedesktop.dbus.types.UInt32; +import org.junit.Test; + +public class NM80211ApFlagsTest { + + UInt32 value; + List flags; + + @Test + public void fromUInt32WorksWithNone() { + givenValue(0x00000000); + + whenFromUInt32IsCalledWith(this.value); + + thenFlagsSizeIs(1); + thenFlagsContains(NM80211ApFlags.NM_802_11_AP_FLAGS_NONE); + } + + @Test + public void fromUInt32WorksWithPrivacy() { + givenValue(0x00000001); + + whenFromUInt32IsCalledWith(this.value); + + thenFlagsSizeIs(1); + thenFlagsContains(NM80211ApFlags.NM_802_11_AP_FLAGS_PRIVACY); + } + + @Test + public void fromUInt32WorksWithWPS() { + givenValue(0x00000002); + + whenFromUInt32IsCalledWith(this.value); + + thenFlagsSizeIs(1); + thenFlagsContains(NM80211ApFlags.NM_802_11_AP_FLAGS_WPS); + } + + @Test + public void fromUInt32WorksWithWPSPBC() { + givenValue(0x00000004); + + whenFromUInt32IsCalledWith(this.value); + + thenFlagsSizeIs(1); + thenFlagsContains(NM80211ApFlags.NM_802_11_AP_FLAGS_WPS_PBC); + } + + @Test + public void fromUInt32WorksWithWPSPin() { + givenValue(0x00000008); + + whenFromUInt32IsCalledWith(this.value); + + thenFlagsSizeIs(1); + thenFlagsContains(NM80211ApFlags.NM_802_11_AP_FLAGS_WPS_PIN); + } + + @Test + public void fromUInt32WorksWithMultipleFlags() { + givenValue(0x00000003); + + whenFromUInt32IsCalledWith(this.value); + + thenFlagsSizeIs(2); + thenFlagsContains(NM80211ApFlags.NM_802_11_AP_FLAGS_PRIVACY); + thenFlagsContains(NM80211ApFlags.NM_802_11_AP_FLAGS_WPS); + } + + private void givenValue(int intValue) { + this.value = new UInt32(intValue); + } + + private void whenFromUInt32IsCalledWith(UInt32 intValue) { + this.flags = NM80211ApFlags.fromUInt32(intValue); + } + + private void thenFlagsSizeIs(int size) { + assertEquals(size, this.flags.size()); + } + + private void thenFlagsContains(NM80211ApFlags nmWifiFlag) { + assertTrue(this.flags.contains(nmWifiFlag)); + } +} \ No newline at end of file diff --git a/kura/test/org.eclipse.kura.rest.network.status.provider.test/src/main/java/org/eclipse/kura/rest/network/status/provider/test/NetworkStatusRestServiceImplTest.java b/kura/test/org.eclipse.kura.rest.network.status.provider.test/src/main/java/org/eclipse/kura/rest/network/status/provider/test/NetworkStatusRestServiceImplTest.java index f161c7ba014..ff0c66d008b 100644 --- a/kura/test/org.eclipse.kura.rest.network.status.provider.test/src/main/java/org/eclipse/kura/rest/network/status/provider/test/NetworkStatusRestServiceImplTest.java +++ b/kura/test/org.eclipse.kura.rest.network.status.provider.test/src/main/java/org/eclipse/kura/rest/network/status/provider/test/NetworkStatusRestServiceImplTest.java @@ -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 @@ -63,6 +63,7 @@ import org.eclipse.kura.net.status.wifi.WifiAccessPoint; import org.eclipse.kura.net.status.wifi.WifiCapability; import org.eclipse.kura.net.status.wifi.WifiChannel; +import org.eclipse.kura.net.status.wifi.WifiFlag; import org.eclipse.kura.net.status.wifi.WifiInterfaceStatus; import org.eclipse.kura.net.status.wifi.WifiMode; import org.eclipse.kura.net.status.wifi.WifiSecurity; @@ -648,6 +649,7 @@ public void shouldEncodeActiveWifiAccessPoint() { .withSignalStrength(-94) // .withWpaSecurity(EnumSet.of(WifiSecurity.GROUP_CCMP, WifiSecurity.KEY_MGMT_SAE)) // .withRsnSecurity(EnumSet.of(WifiSecurity.KEY_MGMT_EAP_SUITE_B_192)) // + .withFlags(EnumSet.of(WifiFlag.PRIVACY)) // .build())) // ); @@ -667,7 +669,8 @@ public void shouldEncodeActiveWifiAccessPoint() { + "\"signalQuality\":12," // + "\"signalStrength\":-94," // + "\"wpaSecurity\":[\"GROUP_CCMP\",\"KEY_MGMT_SAE\"]," // - + "\"rsnSecurity\":[\"KEY_MGMT_EAP_SUITE_B_192\"]}," // + + "\"rsnSecurity\":[\"KEY_MGMT_EAP_SUITE_B_192\"]," // + + "\"flags\":[\"PRIVACY\"]}," // + "\"availableWifiAccessPoints\":[]," // + "\"id\":\"N/A\"," // + "\"interfaceName\":\"N/A\"," // @@ -697,6 +700,7 @@ public void shouldEncodeWifiAccessPointInAvailableAccessPointList() { .withSignalStrength(-94) // .withWpaSecurity(EnumSet.of(WifiSecurity.GROUP_CCMP, WifiSecurity.KEY_MGMT_SAE)) // .withRsnSecurity(EnumSet.of(WifiSecurity.KEY_MGMT_EAP_SUITE_B_192)) // + .withFlags(EnumSet.of(WifiFlag.PRIVACY, WifiFlag.WPS)) // .build()))); whenRequestIsPerformed(new MethodSpec("GET"), NETWORK_STATUS_PATH); @@ -715,7 +719,8 @@ public void shouldEncodeWifiAccessPointInAvailableAccessPointList() { + "\"signalQuality\":12," // + "\"signalStrength\":-94," // + "\"wpaSecurity\":[\"GROUP_CCMP\",\"KEY_MGMT_SAE\"]," // - + "\"rsnSecurity\":[\"KEY_MGMT_EAP_SUITE_B_192\"]}]," // + + "\"rsnSecurity\":[\"KEY_MGMT_EAP_SUITE_B_192\"]," // + + "\"flags\":[\"PRIVACY\",\"WPS\"]}]," // + "\"id\":\"N/A\"," // + "\"interfaceName\":\"N/A\"," // + "\"hardwareAddress\":\"00:00:00:00:00:00\"," //