From 8dc9032be02df695ace69b5c83337db9489e1f73 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:17:28 +0100 Subject: [PATCH] fix: wireless tab and cellular tab will show up when only ipv6 is enabled [backport release-5.4.0] (#5001) fix: wireless tab and cellular tab will show up when only ipv6 is enabled (#4999) * fix: added boolean for ipv6 * Update TabIp6Ui.java * fix: management of ipv6 and modes with wireless Signed-off-by: MMaiero * fix: condition to detect status change Signed-off-by: Marcello Martina --------- Signed-off-by: MMaiero Signed-off-by: Marcello Martina Co-authored-by: MMaiero Co-authored-by: Marcello Martina (cherry picked from commit 423a7a4938f438c15d540957d17425617105e7e5) Co-authored-by: G_Ivo --- .../web/client/ui/network/NetworkTabsUi.java | 44 ++++++------ .../kura/web/client/ui/network/TabIp6Ui.java | 15 ++-- .../web/client/ui/network/TabWirelessUi.java | 69 ++++++++++++------- .../kura/web/shared/model/GwtNetIfStatus.java | 7 +- 4 files changed, 80 insertions(+), 55 deletions(-) diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java index 7744f794d90..708a095b2ee 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright (c) 2011, 2023 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 *******************************************************************************/ @@ -24,8 +24,6 @@ import org.eclipse.kura.web.shared.model.GwtSession; import org.eclipse.kura.web.shared.model.GwtWifiNetInterfaceConfig; import org.eclipse.kura.web.shared.model.GwtWifiWirelessMode; -import org.eclipse.kura.web.shared.service.GwtNetworkService; -import org.eclipse.kura.web.shared.service.GwtNetworkServiceAsync; import org.gwtbootstrap3.client.ui.AnchorListItem; import org.gwtbootstrap3.client.ui.NavbarNav; import org.gwtbootstrap3.client.ui.PanelBody; @@ -45,13 +43,14 @@ public class NetworkTabsUi extends Composite { .get(GwtNetIfStatus.netIPv4StatusUnmanaged.name()); private static final String IPV4_STATUS_ENABLED_LAN_MESSAGE = MessageUtils .get(GwtNetIfStatus.netIPv4StatusEnabledLAN.name()); + private static final String IPV6_STATUS_DISABLED_MESSAGE = MessageUtils + .get(GwtNetIfStatus.netIPv6StatusDisabled.name()); private static NetworkTabsUiUiBinder uiBinder = GWT.create(NetworkTabsUiUiBinder.class); interface NetworkTabsUiUiBinder extends UiBinder { } - private final GwtNetworkServiceAsync gwtNetworkService = GWT.create(GwtNetworkService.class); private static final Messages MSGS = GWT.create(Messages.class); private boolean isNet2 = false; @@ -146,8 +145,8 @@ private void initIp6Tab() { private void initWirelessTab(final boolean isNet2) { this.wirelessTabAnchorItem = new AnchorListItem(MSGS.netWifiWireless()); - this.wirelessTab = new TabWirelessUi(this.session, this.ip4Tab, this.set8021xTab, this.net8021xTabAnchorItem, - this, isNet2); + this.wirelessTab = new TabWirelessUi(this.session, this.ip4Tab, this.ip6Tab, this.set8021xTab, + this.net8021xTabAnchorItem, this, isNet2); this.wirelessTabAnchorItem.addClickHandler(event -> { setSelected(NetworkTabsUi.this.wirelessTabAnchorItem); @@ -287,6 +286,7 @@ private void removeAllTabs() { private void arrangeOptionalTabs() { boolean isIpv4EnabledLAN = this.ip4Tab.getStatus().equals(IPV4_STATUS_ENABLED_LAN_MESSAGE); boolean isIpv4Disabled = this.ip4Tab.getStatus().equals(IPV4_STATUS_DISABLED_MESSAGE); + boolean isIpv6Disabled = this.ip6Tab.getStatus().equals(IPV6_STATUS_DISABLED_MESSAGE); boolean isWirelessAP = this.wirelessTab.getWirelessMode() != null && this.wirelessTab.getWirelessMode().name().equals(WIFI_ACCESS_POINT); boolean isDhcp = this.ip4Tab.isDhcp(); @@ -296,14 +296,14 @@ private void arrangeOptionalTabs() { InterfaceConfigWrapper wrapper = new InterfaceConfigWrapper(this.netIfConfig); if (wrapper.isWireless()) { - showWirelessTabs(isIpv4Disabled || isUnmanagedSelected()); + showWirelessTabs(isIPInterfacesDisabled(isIpv4Disabled, isIpv6Disabled) || isUnmanagedSelected()); if (!isWirelessAP) { includeDhcpNat = false; } } else if (wrapper.isModem()) { includeDhcpNat = false; this.modemGpsTabAnchorItem.setEnabled(wrapper.isGpsSupported() && !isUnmanagedSelected()); - showModemTabs(isIpv4Disabled || isUnmanagedSelected()); + showModemTabs(isIPInterfacesDisabled(isIpv4Disabled, isIpv6Disabled) || isUnmanagedSelected()); } else { showEthernetTabs(); if (wrapper.isLoopback()) { @@ -316,11 +316,15 @@ private void arrangeOptionalTabs() { this.dhcp4NatTabAnchorItem.setEnabled(includeDhcpNat); this.ip6TabAnchorItem.setEnabled(!isUnmanagedSelected()); - if (isIpv4Disabled || isUnmanagedSelected()) { + if (isIPInterfacesDisabled(isIpv4Disabled, isIpv6Disabled) || isUnmanagedSelected()) { removeOptionalTabs(); } } + private boolean isIPInterfacesDisabled(boolean isIpv4Disabled, boolean isIpv6Disabled) { + return isIpv4Disabled && isIpv6Disabled; + } + private void showWirelessTabs(boolean interfaceNotEnabled) { removeTab(this.modemTabAnchorItem); removeTab(this.modemGpsTabAnchorItem); @@ -412,11 +416,7 @@ private void refreshAllVisibleTabs() { */ public boolean isDirty() { - if (this.visibleTabs.contains(this.ip4TabAnchorItem) && this.ip4Tab.isDirty()) { - return true; - } - - if (this.visibleTabs.contains(this.ip6TabAnchorItem) && this.ip6Tab.isDirty()) { + if ((this.visibleTabs.contains(this.ip4TabAnchorItem) && this.ip4Tab.isDirty()) || (this.visibleTabs.contains(this.ip6TabAnchorItem) && this.ip6Tab.isDirty())) { return true; } @@ -540,11 +540,7 @@ public boolean isValid() { return false; } - if (this.visibleTabs.contains(this.wirelessTabAnchorItem) && !this.wirelessTab.isValid()) { - return false; - } - - if (this.visibleTabs.contains(this.modemTabAnchorItem) && !this.modemTab.isValid()) { + if ((this.visibleTabs.contains(this.wirelessTabAnchorItem) && !this.wirelessTab.isValid()) || (this.visibleTabs.contains(this.modemTabAnchorItem) && !this.modemTab.isValid())) { return false; } @@ -604,18 +600,18 @@ private void setSelected(AnchorListItem item) { class InterfaceConfigWrapper { - private GwtNetInterfaceConfig config; + private final GwtNetInterfaceConfig config; public InterfaceConfigWrapper(GwtNetInterfaceConfig config) { this.config = config; } public boolean isWireless() { - return (this.config instanceof GwtWifiNetInterfaceConfig); + return this.config instanceof GwtWifiNetInterfaceConfig; } public boolean isModem() { - return (this.config instanceof GwtModemInterfaceConfig); + return this.config instanceof GwtModemInterfaceConfig; } public boolean isGpsSupported() { diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp6Ui.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp6Ui.java index 3202f9037ea..69d39b2be21 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp6Ui.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp6Ui.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2023 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/ @@ -190,6 +190,10 @@ public TabIp6Ui(GwtSession currentSession, NetworkTabsUi netTabs) { initListBoxes(); initTextBoxes(); } + + public String getStatus() { + return this.status.getSelectedItemText(); + } private void initLabels() { this.labelStatus.setText(MSGS.netIPv6Status()); @@ -225,6 +229,7 @@ private void initListBoxes() { } private void initStatusField() { + this.status.clear(); this.status.addItem(MessageUtils.get(STATUS_DISABLED), STATUS_DISABLED); this.status.addItem(MessageUtils.get(STATUS_LAN), STATUS_LAN); this.status.addItem(MessageUtils.get(STATUS_WAN), STATUS_WAN); @@ -355,7 +360,7 @@ private void initPriorityField() { } }); } - + private void initMtuField() { this.mtu.addMouseOverHandler(event -> { if (this.mtu.isEnabled()) { @@ -685,7 +690,7 @@ private void updateConfigWithSelectedValues(GwtNetInterfaceConfig updatedNetIf) } updatedNetIf.setIpv6Privacy(this.privacy.getSelectedValue()); - + if (this.mtu.getValue() != null) { updatedNetIf.setIpv6Mtu(this.mtu.getValue()); } @@ -802,7 +807,7 @@ private void fillFormWithCachedConfig() { break; } } - + this.mtu.setValue(this.selectedNetIfConfig.get().getIpv6Mtu()); this.tabs.updateTabs(); @@ -814,4 +819,4 @@ public void clear() { // Not needed } -} \ No newline at end of file +} diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java index 372bf24e801..aada0946ea4 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java @@ -144,7 +144,8 @@ interface TabWirelessUiUiBinder extends UiBinder { private static final int MAX_SSID_LENGTH = 32; private final GwtSession session; - private final TabIp4Ui tcpTab; + private final TabIp4Ui tcp4Tab; + private final TabIp6Ui tcp6Tab; private final NetworkTabsUi netTabs; private final Tab8021xUi wireless8021x; private final ListDataProvider ssidDataProvider = new ListDataProvider<>(); @@ -156,7 +157,8 @@ interface TabWirelessUiUiBinder extends UiBinder { private boolean ssidInit; private boolean isNet2; private GwtWifiNetInterfaceConfig selectedNetIfConfig; - private String tcpStatus; + private String tcp4Status; + private String tcp6Status; GwtWifiConfig activeConfig; GwtWifiChannelModel previousSelection; @@ -344,12 +346,13 @@ interface TabWirelessUiUiBinder extends UiBinder { @UiField Text unavailableChannelErrorText; - public TabWirelessUi(GwtSession currentSession, TabIp4Ui tcp, Tab8021xUi wireless8021x, + public TabWirelessUi(GwtSession currentSession, TabIp4Ui tcp4, TabIp6Ui tcp6, Tab8021xUi wireless8021x, AnchorListItem wireless8021xTabAnchorItem, NetworkTabsUi tabs, final boolean isNet2) { this.ssidInit = false; initWidget(uiBinder.createAndBindUi(this)); this.session = currentSession; - this.tcpTab = tcp; + this.tcp4Tab = tcp4; + this.tcp6Tab = tcp6; this.netTabs = tabs; this.wireless8021x = wireless8021x; this.wireless8021xTabAnchorItem = wireless8021xTabAnchorItem; @@ -362,21 +365,14 @@ public TabWirelessUi(GwtSession currentSession, TabIp4Ui tcp, Tab8021xUi wireles initRegDomErrorModal(); setPasswordValidation(); - this.tcpTab.status.addChangeHandler(event -> { - if (TabWirelessUi.this.selectedNetIfConfig != null) { - // set the default values for wireless mode if tcp/ip status was changed - String tcpIpStatus = TabWirelessUi.this.tcpTab.getStatus(); - if (!tcpIpStatus.equals(TabWirelessUi.this.tcpStatus)) { - if (tcpIpStatus.equals(MessageUtils.get(GwtNetIfStatus.netIPv4StatusEnabledWAN.name()))) { - TabWirelessUi.this.activeConfig = TabWirelessUi.this.selectedNetIfConfig.getStationWifiConfig(); - } else { - TabWirelessUi.this.activeConfig = TabWirelessUi.this.selectedNetIfConfig.getActiveWifiConfig(); - } + this.tcp4Tab.status.addChangeHandler(event -> { + evalActiveConfig(); - TabWirelessUi.this.tcpStatus = tcpIpStatus; - TabWirelessUi.this.netTabs.updateTabs(); - } - } + update(); + }); + + this.tcp6Tab.status.addChangeHandler(event -> { + evalActiveConfig(); update(); }); @@ -384,6 +380,28 @@ public TabWirelessUi(GwtSession currentSession, TabIp4Ui tcp, Tab8021xUi wireles logger.info("Constructor done."); } + private void evalActiveConfig() { + if (TabWirelessUi.this.selectedNetIfConfig != null) { + // set the default values for wireless mode if tcp/ip status was changed + String tcpIp4Status = TabWirelessUi.this.tcp4Tab.getStatus(); + String tcpIp6Status = TabWirelessUi.this.tcp6Tab.getStatus(); + boolean isStatusChanged = !tcpIp4Status.equals(TabWirelessUi.this.tcp4Status) + || !tcpIp6Status.equals(TabWirelessUi.this.tcp6Status); + + if (isStatusChanged) { + if (tcpIp4Status.equals(MessageUtils.get(GwtNetIfStatus.netIPv4StatusEnabledWAN.name())) || tcpIp6Status.equals(MessageUtils.get(GwtNetIfStatus.netIPv4StatusEnabledWAN.name()))) { + TabWirelessUi.this.activeConfig = TabWirelessUi.this.selectedNetIfConfig.getStationWifiConfig(); + } else { + TabWirelessUi.this.activeConfig = TabWirelessUi.this.selectedNetIfConfig.getActiveWifiConfig(); + } + + TabWirelessUi.this.tcp4Status = tcpIp4Status; + TabWirelessUi.this.tcp6Status = tcpIp6Status; + TabWirelessUi.this.netTabs.updateTabs(); + } + } + } + @UiHandler(value = { "wireless", "ssid", "radio", "security", "password", "verify", "pairwise", "group", "bgscan", "longI", "shortI", "radio1", "radio2", "radio3", "radio4", "rssi", "channelList", "countryCode" }) public void onChange(ChangeEvent e) { @@ -436,8 +454,9 @@ public boolean isValid() { @Override public void setNetInterface(GwtNetInterfaceConfig config) { setDirty(true); - if (this.tcpStatus == null || this.selectedNetIfConfig != config) { - this.tcpStatus = this.tcpTab.getStatus(); + if (this.tcp4Status == null || this.tcp6Status == null || this.selectedNetIfConfig != config) { + this.tcp4Status = this.tcp4Tab.getStatus(); + this.tcp6Status = this.tcp6Tab.getStatus(); } if (config instanceof GwtWifiNetInterfaceConfig) { this.selectedNetIfConfig = (GwtWifiNetInterfaceConfig) config; @@ -523,6 +542,7 @@ private void changeRadioModeToBand(boolean isNet2) { private void update() { setValues(); + this.netTabs.updateTabs(); refreshForm(); setPasswordValidation(); } @@ -644,10 +664,11 @@ private void setBandFromRadioMode(String radioModeValue) { private void refreshForm() { logger.info("Start refreshForm"); - String tcpipStatus = this.tcpTab.getStatus(); + String tcpip4Status = this.tcp4Tab.getStatus(); + String tcpip6Status = this.tcp6Tab.getStatus(); // Tcp/IP disabled - if (tcpipStatus.equals(GwtNetIfStatus.netIPv4StatusDisabled.name())) { + if (tcpip4Status.equals(GwtNetIfStatus.netIPv4StatusDisabled.name()) && tcpip6Status.equals(GwtNetIfStatus.netIPv4StatusDisabled.name())) { setForm(false); } else { setForm(true); @@ -656,7 +677,7 @@ private void refreshForm() { add8021xFromSecurityDropdown(); - if (tcpipStatus.equals(IPV4_STATUS_WAN_MESSAGE)) { + if (tcpip4Status.equals(IPV4_STATUS_WAN_MESSAGE) || tcpip6Status.equals(IPV4_STATUS_WAN_MESSAGE)) { this.wireless.setEnabled(false); } this.groupVerify.setVisible(false); @@ -667,7 +688,7 @@ private void refreshForm() { remove8021xFromSecurityDropdown(); // disable access point when TCP/IP is set to WAN - if (tcpipStatus.equals(IPV4_STATUS_WAN_MESSAGE)) { + if (tcpip4Status.equals(IPV4_STATUS_WAN_MESSAGE) || tcpip6Status.equals(IPV4_STATUS_WAN_MESSAGE)) { setForm(false); } diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtNetIfStatus.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtNetIfStatus.java index d9db14e39d1..df3b417611f 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtNetIfStatus.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/shared/model/GwtNetIfStatus.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others + * Copyright (c) 2011, 2023 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 @@ -21,7 +21,10 @@ public enum GwtNetIfStatus implements Serializable, IsSerializable { netIPv4StatusUnmanaged("Unmanaged"), netIPv4StatusL2Only("L2Only"), netIPv4StatusEnabledLAN("LAN"), - netIPv4StatusEnabledWAN("WAN"); + netIPv4StatusEnabledWAN("WAN"), + netIPv6StatusDisabled("Disabled"), + netIPv6StatusEnabledLAN("LAN"), + netIPv6StatusEnabledWAN("WAN"); private String status;