diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt index 7f96d1ad292b89..ce37951915e283 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt @@ -28,7 +28,7 @@ import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment -import chip.devicecontroller.NetworkCredentials +import com.google.chip.chiptool.NetworkCredentialsParcelable import chip.setuppayload.SetupPayload import chip.setuppayload.SetupPayloadParser import chip.setuppayload.SetupPayloadParser.UnrecognizedQrCodeException @@ -133,7 +133,7 @@ class CHIPToolActivity : showFragment(AddressCommissioningFragment.newInstance(), false) } - override fun onNetworkCredentialsEntered(networkCredentials: NetworkCredentials) { + override fun onNetworkCredentialsEntered(networkCredentials: NetworkCredentialsParcelable) { showFragment(DeviceProvisioningFragment.newInstance(deviceInfo!!, networkCredentials)) } diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/NetworkCredentialsParcelable.java b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/NetworkCredentialsParcelable.java new file mode 100644 index 00000000000000..2194155f4f660b --- /dev/null +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/NetworkCredentialsParcelable.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2020-2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.google.chip.chiptool; + +import android.os.Parcel; +import android.os.Parcelable; +import androidx.annotation.Nullable; + +/** Class for holding WiFi or Thread credentials, but not both. */ +public class NetworkCredentialsParcelable implements Parcelable { + @Nullable private WiFiCredentials wifiCredentials; + @Nullable private ThreadCredentials threadCredentials; + + private NetworkCredentialsParcelable( + @Nullable WiFiCredentials wifiCredentials, @Nullable ThreadCredentials threadCredentials) { + this.wifiCredentials = wifiCredentials; + this.threadCredentials = threadCredentials; + } + + /** + * Return a NetworkCredentialsParcelable object with the given WiFiCredentials and null + * ThreadCredentials. + */ + public static NetworkCredentialsParcelable forWiFi(WiFiCredentials wifiCredentials) { + return new NetworkCredentialsParcelable(wifiCredentials, null); + } + + /** + * Return a NetworkCredentialsParcelable object with the given ThreadCredentials and null + * WiFiCredentials. + */ + public static NetworkCredentialsParcelable forThread(ThreadCredentials threadCredentials) { + return new NetworkCredentialsParcelable(null, threadCredentials); + } + + public WiFiCredentials getWiFiCredentials() { + return wifiCredentials; + } + + public ThreadCredentials getThreadCredentials() { + return threadCredentials; + } + + // Begin Parcelable implementation + + private NetworkCredentialsParcelable(Parcel in) { + wifiCredentials = in.readParcelable(WiFiCredentials.class.getClassLoader()); + threadCredentials = in.readParcelable(ThreadCredentials.class.getClassLoader()); + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(wifiCredentials, 0); + out.writeParcelable(threadCredentials, 0); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public NetworkCredentialsParcelable createFromParcel(Parcel in) { + return new NetworkCredentialsParcelable(in); + } + + public NetworkCredentialsParcelable[] newArray(int size) { + return new NetworkCredentialsParcelable[size]; + } + }; + + public static class WiFiCredentials implements Parcelable { + private final String ssid; + private final String password; + + public WiFiCredentials(String ssid, String password) { + this.ssid = ssid; + this.password = password; + } + + public String getSsid() { + return ssid; + } + + public String getPassword() { + return password; + } + + // Begin Parcelable implementation + + private WiFiCredentials(Parcel in) { + ssid = in.readString(); + password = in.readString(); + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel out, int flags) { + out.writeString(ssid); + out.writeString(password); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public WiFiCredentials createFromParcel(Parcel in) { + return new WiFiCredentials(in); + } + + public WiFiCredentials[] newArray(int size) { + return new WiFiCredentials[size]; + } + }; + } + + public static class ThreadCredentials implements Parcelable { + private final byte[] operationalDataset; + + public ThreadCredentials(byte[] operationalDataset) { + this.operationalDataset = operationalDataset; + } + + public byte[] getOperationalDataset() { + return operationalDataset; + } + + // Begin Parcelable implementation + + private ThreadCredentials(Parcel in) { + operationalDataset = new byte[in.readInt()]; + in.readByteArray(operationalDataset); + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel out, int flags) { + out.writeInt(operationalDataset.length); + out.writeByteArray(operationalDataset); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public ThreadCredentials createFromParcel(Parcel in) { + return new ThreadCredentials(in); + } + + public ThreadCredentials[] newArray(int size) { + return new ThreadCredentials[size]; + } + }; + } +} diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt index f97647ce4ab18a..f816fabce45ead 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt @@ -28,6 +28,7 @@ import android.widget.Toast import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import chip.devicecontroller.NetworkCredentials +import com.google.chip.chiptool.NetworkCredentialsParcelable import com.google.chip.chiptool.ChipClient import com.google.chip.chiptool.GenericChipDeviceListener import com.google.chip.chiptool.R @@ -46,7 +47,7 @@ class DeviceProvisioningFragment : Fragment() { private var gatt: BluetoothGatt? = null - private val networkCredentials: NetworkCredentials? + private val networkCredentialsParcelable: NetworkCredentialsParcelable? get() = arguments?.getParcelable(ARG_NETWORK_CREDENTIALS) private lateinit var scope: CoroutineScope @@ -120,7 +121,22 @@ class DeviceProvisioningFragment : Fragment() { val deviceId = DeviceIdUtil.getNextAvailableId(requireContext()) val connId = bluetoothManager.connectionId - deviceController.pairDevice(gatt, connId, deviceId, deviceInfo.setupPinCode, networkCredentials) + val network = NetworkCredentials() + var networkParcelable = checkNotNull(networkCredentialsParcelable) + + val wifi = networkParcelable.getWiFiCredentials() + if (wifi != null) + { + network.setWiFiCredentials(wifi.getSsid(), wifi.getPassword()) + } + + val thread = networkParcelable.getThreadCredentials() + if (thread != null) + { + network.setThreadCredentials(thread.getOperationalDataset()) + } + + deviceController.pairDevice(gatt, connId, deviceId, deviceInfo.setupPinCode, network) DeviceIdUtil.setNextAvailableId(requireContext(), deviceId + 1) } } @@ -191,17 +207,17 @@ class DeviceProvisioningFragment : Fragment() { private const val STATUS_PAIRING_SUCCESS = 0 /** - * Return a new instance of [DeviceProvisioningFragment]. [networkCredentials] can be null for + * Return a new instance of [DeviceProvisioningFragment]. [networkCredentialsParcelable] can be null for * IP commissioning. */ fun newInstance( deviceInfo: CHIPDeviceInfo, - networkCredentials: NetworkCredentials?, + networkCredentialsParcelable: NetworkCredentialsParcelable?, ): DeviceProvisioningFragment { return DeviceProvisioningFragment().apply { arguments = Bundle(2).apply { putParcelable(ARG_DEVICE_INFO, deviceInfo) - putParcelable(ARG_NETWORK_CREDENTIALS, networkCredentials) + putParcelable(ARG_NETWORK_CREDENTIALS, networkCredentialsParcelable) } } } diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt index 9153b02c7fa266..5f0d024ee694a4 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt @@ -23,9 +23,9 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.Fragment -import chip.devicecontroller.NetworkCredentials import com.google.chip.chiptool.R import com.google.chip.chiptool.util.FragmentUtil +import com.google.chip.chiptool.NetworkCredentialsParcelable import kotlinx.android.synthetic.main.enter_thread_network_fragment.channelEd import kotlinx.android.synthetic.main.enter_thread_network_fragment.masterKeyEd import kotlinx.android.synthetic.main.enter_thread_network_fragment.panIdEd @@ -44,7 +44,7 @@ class EnterNetworkFragment : Fragment() { ) interface Callback { - fun onNetworkCredentialsEntered(networkCredentials: NetworkCredentials) + fun onNetworkCredentialsEntered(networkCredentials: NetworkCredentialsParcelable) } override fun onCreateView( @@ -79,8 +79,8 @@ class EnterNetworkFragment : Fragment() { return } - val networkCredentials = NetworkCredentials.forWiFi( - NetworkCredentials.WiFiCredentials(ssid.toString(), pwd.toString()) + val networkCredentials = NetworkCredentialsParcelable.forWiFi( + NetworkCredentialsParcelable.WiFiCredentials(ssid.toString(), pwd.toString()) ) FragmentUtil.getHost(this, Callback::class.java) ?.onNetworkCredentialsEntered(networkCredentials) @@ -130,7 +130,7 @@ class EnterNetworkFragment : Fragment() { ) val networkCredentials = - NetworkCredentials.forThread(NetworkCredentials.ThreadCredentials(operationalDataset)) + NetworkCredentialsParcelable.forThread(NetworkCredentialsParcelable.ThreadCredentials(operationalDataset)) FragmentUtil.getHost(this, Callback::class.java) ?.onNetworkCredentialsEntered(networkCredentials) } diff --git a/examples/android/CHIPTool/chip-library/build.gradle b/examples/android/CHIPTool/chip-library/build.gradle index b6679efc9da1b4..429577ee6060aa 100644 --- a/examples/android/CHIPTool/chip-library/build.gradle +++ b/examples/android/CHIPTool/chip-library/build.gradle @@ -33,7 +33,8 @@ android { '../../../setup_payload/java/src', '../../../controller/java/zap-generated', '../../../controller/java/src', - '../../../platform/android/java' + '../../../platform/android/java', + '../app/src/main/java/com/google/chip/chiptool' ] } } diff --git a/examples/light-switch-app/efr32/BUILD.gn b/examples/light-switch-app/efr32/BUILD.gn index 8849f790d06bd8..7d71569cd0ff76 100644 --- a/examples/light-switch-app/efr32/BUILD.gn +++ b/examples/light-switch-app/efr32/BUILD.gn @@ -79,6 +79,7 @@ assert(!(use_wf200 && chip_enable_openthread)) if (chip_enable_wifi) { assert(use_rs911x || use_wf200) enable_openthread_cli = false + import("${chip_root}/src/platform/EFR32/wifi_args.gni") } # ThunderBoards, Explorer Kit and MGM240L do not support LCD (No LCD) @@ -92,14 +93,28 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || if (chip_enable_wifi) { wifi_sdk_dir = "${chip_root}/src/platform/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] - efr32_lwip_defs += [ - "LWIP_IPV4=1", - "LWIP_ARP=1", - "LWIP_ICMP=1", - "LWIP_DHCP=1", - "LWIP_IPV6_ND=1", - "LWIP_IGMP=1", - ] + if (lwip_ipv4) { + efr32_lwip_defs += [ + "LWIP_IPV4=1", + + # adds following options to provide + # them to .cpp source files + # flags ported from lwipopts file + # TODO: move lwipopts to one location + "LWIP_ARP=1", + "LWIP_ICMP=1", + "LWIP_IGMP=1", + "LWIP_DHCP=1", + "LWIP_DNS=0", + ] + } else { + efr32_lwip_defs += [ "LWIP_IPV4=0" ] + } + if (lwip_ipv6) { + efr32_lwip_defs += [ "LWIP_IPV6=1" ] + } else { + efr32_lwip_defs += [ "LWIP_IPV6=0" ] + } if (use_rs911x) { wiseconnect_sdk_root = diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 0c36e3bba57314..1ca1b41e2ce62b 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -79,6 +79,7 @@ assert(!(use_wf200 && chip_enable_openthread)) if (chip_enable_wifi) { assert(use_rs911x || use_wf200) enable_openthread_cli = false + import("${chip_root}/src/platform/EFR32/wifi_args.gni") } # ThunderBoards, Explorer Kit and MGM240L do not support LCD (No LCD) @@ -97,14 +98,28 @@ if (chip_enable_wifi) { } wifi_sdk_dir = "${chip_root}/src/platform/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] - efr32_lwip_defs += [ - "LWIP_IPV4=1", - "LWIP_ARP=1", - "LWIP_ICMP=1", - "LWIP_DHCP=1", - "LWIP_IPV6_ND=1", - "LWIP_IGMP=1", - ] + if (lwip_ipv4) { + efr32_lwip_defs += [ + "LWIP_IPV4=1", + + # adds following options to provide + # them to .cpp source files + # flags ported from lwipopts file + # TODO: move lwipopts to one location + "LWIP_ARP=1", + "LWIP_ICMP=1", + "LWIP_IGMP=1", + "LWIP_DHCP=1", + "LWIP_DNS=0", + ] + } else { + efr32_lwip_defs += [ "LWIP_IPV4=0" ] + } + if (lwip_ipv6) { + efr32_lwip_defs += [ "LWIP_IPV6=1" ] + } else { + efr32_lwip_defs += [ "LWIP_IPV6=0" ] + } if (use_rs911x) { wiseconnect_sdk_root = diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 996cb0f086a67d..fdd3f9f9984b8d 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -79,6 +79,7 @@ assert(!(use_wf200 && chip_enable_openthread)) if (chip_enable_wifi) { assert(use_rs911x || use_wf200) enable_openthread_cli = false + import("${chip_root}/src/platform/EFR32/wifi_args.gni") } # ThunderBoards, Explorer Kit and MGM240L do not support LCD (No LCD) @@ -92,14 +93,28 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || if (chip_enable_wifi) { wifi_sdk_dir = "${chip_root}/src/platform/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] - efr32_lwip_defs += [ - "LWIP_IPV4=1", - "LWIP_ARP=1", - "LWIP_ICMP=1", - "LWIP_DHCP=1", - "LWIP_IPV6_ND=1", - "LWIP_IGMP=1", - ] + if (lwip_ipv4) { + efr32_lwip_defs += [ + "LWIP_IPV4=1", + + # adds following options to provide + # them to .cpp source files + # flags ported from lwipopts file + # TODO: move lwipopts to one location + "LWIP_ARP=1", + "LWIP_ICMP=1", + "LWIP_IGMP=1", + "LWIP_DHCP=1", + "LWIP_DNS=0", + ] + } else { + efr32_lwip_defs += [ "LWIP_IPV4=0" ] + } + if (lwip_ipv6) { + efr32_lwip_defs += [ "LWIP_IPV6=1" ] + } else { + efr32_lwip_defs += [ "LWIP_IPV6=0" ] + } if (use_rs911x) { wiseconnect_sdk_root = diff --git a/examples/lock-app/efr32/src/ZclCallbacks.cpp b/examples/lock-app/efr32/src/ZclCallbacks.cpp index 650aba7d2d73de..9c1812a90c0a04 100644 --- a/examples/lock-app/efr32/src/ZclCallbacks.cpp +++ b/examples/lock-app/efr32/src/ZclCallbacks.cpp @@ -41,7 +41,9 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & if (clusterId == DoorLock::Id && attributeId == DoorLock::Attributes::LockState::Id) { - ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); + DoorLock::DlLockState lockState = *(reinterpret_cast(value)); + ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI " state %d", ChipLogValueMEI(clusterId), + to_underlying(lockState)); } } @@ -146,3 +148,9 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t h { return LockMgr().SetHolidaySchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode); } + +void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) +{ + // Apply the relock state in the application control + LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION); +} diff --git a/examples/platform/efr32/EFR32DeviceAttestationCreds.cpp b/examples/platform/efr32/EFR32DeviceAttestationCreds.cpp index 942505bd82e81c..f68f0b892be1d6 100644 --- a/examples/platform/efr32/EFR32DeviceAttestationCreds.cpp +++ b/examples/platform/efr32/EFR32DeviceAttestationCreds.cpp @@ -23,7 +23,7 @@ #include "efr32_creds.h" #include "psa/crypto.h" -extern uint32_t __attestation_credentials_base; +extern uint8_t __attestation_credentials_base[]; namespace chip { namespace Credentials { @@ -37,7 +37,7 @@ class DeviceAttestationCredsEFR32 : public DeviceAttestationCredentialsProvider public: CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & out_buffer) override { - ByteSpan cd_span(((uint8_t *) &__attestation_credentials_base) + EFR32_CREDENTIALS_CD_OFFSET, EFR32_CREDENTIALS_CD_SIZE); + ByteSpan cd_span(((uint8_t *) __attestation_credentials_base) + EFR32_CREDENTIALS_CD_OFFSET, EFR32_CREDENTIALS_CD_SIZE); return CopySpanToMutableSpan(cd_span, out_buffer); } @@ -50,15 +50,13 @@ class DeviceAttestationCredsEFR32 : public DeviceAttestationCredentialsProvider CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & out_buffer) override { - ByteSpan cert_span(((uint8_t *) &__attestation_credentials_base) + EFR32_CREDENTIALS_DAC_OFFSET, - EFR32_CREDENTIALS_DAC_SIZE); + ByteSpan cert_span(((uint8_t *) __attestation_credentials_base) + EFR32_CREDENTIALS_DAC_OFFSET, EFR32_CREDENTIALS_DAC_SIZE); return CopySpanToMutableSpan(cert_span, out_buffer); } CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & out_pai_buffer) override { - ByteSpan cert_span(((uint8_t *) &__attestation_credentials_base) + EFR32_CREDENTIALS_PAI_OFFSET, - EFR32_CREDENTIALS_PAI_SIZE); + ByteSpan cert_span(((uint8_t *) __attestation_credentials_base) + EFR32_CREDENTIALS_PAI_OFFSET, EFR32_CREDENTIALS_PAI_SIZE); return CopySpanToMutableSpan(cert_span, out_pai_buffer); } diff --git a/examples/platform/efr32/rs911x/rsi_if.c b/examples/platform/efr32/rs911x/rsi_if.c index 872d82c411269b..ad72f6361c055c 100644 --- a/examples/platform/efr32/rs911x/rsi_if.c +++ b/examples/platform/efr32/rs911x/rsi_if.c @@ -738,6 +738,7 @@ void wfx_rsi_task(void * arg) } } +#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 /******************************************************************************************** * @fn void wfx_dhcp_got_ipv4(uint32_t ip) * @brief @@ -761,6 +762,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) wfx_ip_changed_notify(IP_STATUS_SUCCESS); wfx_rsi.dev_state |= WFX_RSI_ST_STA_READY; } +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ /* * WARNING - Taken from RSI and broken up diff --git a/examples/platform/efr32/rs911x/wfx_rsi.h b/examples/platform/efr32/rs911x/wfx_rsi.h index 5899a0c45bc31e..380fc8f29e1693 100644 --- a/examples/platform/efr32/rs911x/wfx_rsi.h +++ b/examples/platform/efr32/rs911x/wfx_rsi.h @@ -82,7 +82,9 @@ extern "C" { void wfx_rsidev_init(void); void wfx_rsi_task(void * arg); void efr32Log(const char * aFormat, ...); +#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 void wfx_ip_changed_notify(int got_ip); +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap); int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info); int32_t wfx_rsi_reset_count(); diff --git a/examples/platform/efr32/rs911x/wfx_rsi_host.c b/examples/platform/efr32/rs911x/wfx_rsi_host.c index 2a502356e6ae66..a55e0aeb5cab2e 100644 --- a/examples/platform/efr32/rs911x/wfx_rsi_host.c +++ b/examples/platform/efr32/rs911x/wfx_rsi_host.c @@ -294,7 +294,7 @@ sl_status_t wfx_sta_discon(void) WFX_RSI_LOG("%s: completed.", __func__); return status; } - +#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 /********************************************************************* * @fn bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) * @brief @@ -317,6 +317,7 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) WFX_RSI_LOG("%s: status: %d", __func__, status); return status; } +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ /********************************************************************* * @fn bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) diff --git a/examples/platform/efr32/wf200/host_if.cpp b/examples/platform/efr32/wf200/host_if.cpp index 8015a0cb7a1caa..d6f90419613f22 100644 --- a/examples/platform/efr32/wf200/host_if.cpp +++ b/examples/platform/efr32/wf200/host_if.cpp @@ -1132,6 +1132,7 @@ static void sl_wfx_ap_client_rejected_callback(uint32_t status, uint8_t * mac) ******************************************************************************/ bool wfx_hw_ready(void) { return (wifiContext.state & SL_WFX_STARTED) ? true : false; } +#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 /***************************************************************************** * @fn void wfx_dhcp_got_ipv4(uint32_t ip) * @brief @@ -1146,6 +1147,7 @@ static void sl_wfx_ap_client_rejected_callback(uint32_t status, uint8_t * mac) sta_ip = ip; wfx_ip_changed_notify(IP_STATUS_SUCCESS); } +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ /***************************************************************************** * @fn wfx_enable_sta_mode(void) diff --git a/examples/thermostat/efr32/BUILD.gn b/examples/thermostat/efr32/BUILD.gn index 9c74f3224df18f..da732a26122b1d 100644 --- a/examples/thermostat/efr32/BUILD.gn +++ b/examples/thermostat/efr32/BUILD.gn @@ -76,6 +76,7 @@ assert(!(use_wf200 && chip_enable_openthread)) if (chip_enable_wifi) { assert(use_rs911x || use_wf200) enable_openthread_cli = false + import("${chip_root}/src/platform/EFR32/wifi_args.gni") } # ThunderBoards, Explorer Kit and MGM240L do not support LCD (No LCD) @@ -89,14 +90,28 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || if (chip_enable_wifi) { wifi_sdk_dir = "${chip_root}/src/platform/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] - efr32_lwip_defs += [ - "LWIP_IPV4=1", - "LWIP_ARP=1", - "LWIP_ICMP=1", - "LWIP_DHCP=1", - "LWIP_IPV6_ND=1", - "LWIP_IGMP=1", - ] + if (lwip_ipv4) { + efr32_lwip_defs += [ + "LWIP_IPV4=1", + + # adds following options to provide + # them to .cpp source files + # flags ported from lwipopts file + # TODO: move lwipopts to one location + "LWIP_ARP=1", + "LWIP_ICMP=1", + "LWIP_IGMP=1", + "LWIP_DHCP=1", + "LWIP_DNS=0", + ] + } else { + efr32_lwip_defs += [ "LWIP_IPV4=0" ] + } + if (lwip_ipv6) { + efr32_lwip_defs += [ "LWIP_IPV6=1" ] + } else { + efr32_lwip_defs += [ "LWIP_IPV6=0" ] + } if (use_rs911x) { wiseconnect_sdk_root = diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java index d2a4327685b832..85812285fe581e 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java @@ -53,7 +53,7 @@ public void handleCommissioningButtonClicked(DiscoveredNodeData commissioner) { @Override public void handleCommissioningComplete() { - showFragment(SelectClusterFragment.newInstance()); + showFragment(SelectClusterFragment.newInstance(tvCastingApp)); } @Override @@ -66,6 +66,11 @@ public void handleMediaPlaybackSelected() { showFragment(MediaPlaybackFragment.newInstance(tvCastingApp)); } + @Override + public void handleDisconnect() { + showFragment(CommissionerDiscoveryFragment.newInstance(tvCastingApp)); + } + /** * The order is important, must first new TvCastingApp to load dynamic library, then * AndroidChipPlatform to prepare platform, then start ChipAppServer, then call init on diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java index ad0df7878dc63c..7e9070665b74b4 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java @@ -24,6 +24,8 @@ public class MediaPlaybackFragment extends Fragment { private View.OnClickListener subscribeToCurrentStateButtonClickListener; + private View.OnClickListener shutdownALlSubscriptionsButtonClickListener; + private static final ContentApp kContentApp = new ContentApp((short) 4, null); public MediaPlaybackFragment(TvCastingApp tvCastingApp) { @@ -123,6 +125,15 @@ public void run() { } }; + this.shutdownALlSubscriptionsButtonClickListener = + new View.OnClickListener() { + @Override + public void onClick(View v) { + Log.d(TAG, "Shutting down all subscriptions"); + tvCastingApp.shutdownAllSubscriptions(); + } + }; + return inflater.inflate(R.layout.fragment_media_playback, container, false); } @@ -133,5 +144,9 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { getView() .findViewById(R.id.subscribeToCurrentStateButton) .setOnClickListener(subscribeToCurrentStateButtonClickListener); + + getView() + .findViewById(R.id.shutdownAllSubscriptionsButton) + .setOnClickListener(shutdownALlSubscriptionsButtonClickListener); } } diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java index 67de30838b296d..f80f286ea3df22 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java @@ -7,22 +7,31 @@ import android.view.ViewGroup; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import com.chip.casting.TvCastingApp; /** An interstitial {@link Fragment} to select one of the supported media actions to perform */ public class SelectClusterFragment extends Fragment { private static final String TAG = SelectClusterFragment.class.getSimpleName(); + private final TvCastingApp tvCastingApp; + private View.OnClickListener selectContentLauncherButtonClickListener; private View.OnClickListener selectMediaPlaybackButtonClickListener; + private View.OnClickListener disconnectButtonClickListener; + + public SelectClusterFragment(TvCastingApp tvCastingApp) { + this.tvCastingApp = tvCastingApp; + } /** * Use this factory method to create a new instance of this fragment using the provided * parameters. * + * @param tvCastingApp TV Casting App (JNI) * @return A new instance of fragment SelectActionFragment. */ - public static SelectClusterFragment newInstance() { - return new SelectClusterFragment(); + public static SelectClusterFragment newInstance(TvCastingApp tvCastingApp) { + return new SelectClusterFragment(tvCastingApp); } @Override @@ -52,6 +61,16 @@ public void onClick(View v) { } }; + this.disconnectButtonClickListener = + new View.OnClickListener() { + @Override + public void onClick(View v) { + Log.d(TAG, "Disconnecting from current video player"); + tvCastingApp.disconnect(); + callback.handleDisconnect(); + } + }; + return inflater.inflate(R.layout.fragment_select_cluster, container, false); } @@ -65,6 +84,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { getView() .findViewById(R.id.selectMediaPlaybackButton) .setOnClickListener(selectMediaPlaybackButtonClickListener); + getView().findViewById(R.id.disconnectButton).setOnClickListener(disconnectButtonClickListener); } /** Interface for notifying the host. */ @@ -74,5 +94,8 @@ public interface Callback { /** Notifies listener to trigger transition on selection of Media Playback cluster */ void handleMediaPlaybackSelected(); + + /** Notifies listener to trigger transition on click of the Disconnect button */ + void handleDisconnect(); } } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java index 20235ae21b38e2..65cd2cbcec1902 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java @@ -95,6 +95,10 @@ public native boolean verifyOrEstablishConnection( FailureCallback onConnectionFailure, SuccessCallback onNewOrUpdatedEndpointCallback); + public native void shutdownAllSubscriptions(); + + public native void disconnect(); + public native List getActiveTargetVideoPlayers(); /* @@ -328,7 +332,7 @@ public native boolean applicationBasic_readVendorName( public native boolean applicationBasic_readVendorID( ContentApp contentApp, - SuccessCallback readSuccessHandler, + SuccessCallback readSuccessHandler, FailureCallback readFailureHandler); public native boolean applicationBasic_readApplicationName( @@ -338,7 +342,7 @@ public native boolean applicationBasic_readApplicationName( public native boolean applicationBasic_readProductID( ContentApp contentApp, - SuccessCallback readSuccessHandler, + SuccessCallback readSuccessHandler, FailureCallback readFailureHandler); public native boolean applicationBasic_readApplicationVersion( diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp index 862334ae1ee4cb..2d78fe461a6c2e 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp @@ -34,7 +34,7 @@ CHIP_ERROR CallbackBaseJNI::SetUp(JNIEnv * env, jobject inHandler) mMethod = env->GetMethodID(mClazz, "handle", mMethodSignature); if (mMethod == nullptr) { - ChipLogError(AppServer, "Failed to access 'handle' method"); + ChipLogError(AppServer, "Failed to access 'handle' method with signature %s", mMethodSignature); env->ExceptionClear(); } @@ -50,7 +50,7 @@ CHIP_ERROR CallbackBaseJNI::SetUp(JNIEnv * env, jobject inHandler) void FailureHandlerJNI::Handle(CHIP_ERROR callbackErr) { - ChipLogProgress(AppServer, "FailureHandlerJNI::Handle called"); + ChipLogProgress(AppServer, "Handle(CHIP_ERROR) called"); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); UtfString jniCallbackErrString(env, callbackErr.AsString()); @@ -63,7 +63,7 @@ void FailureHandlerJNI::Handle(CHIP_ERROR callbackErr) exit: if (err != CHIP_NO_ERROR) { - ChipLogError(AppServer, "FailureHandlerJNI::Handle status error: %s", err.AsString()); + ChipLogError(AppServer, "Handle(CHIP_ERROR) status error: %s", err.AsString()); } } @@ -332,9 +332,10 @@ jobject TargetListSuccessHandlerJNI::ConvertToJObject( return nullptr; } - jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(Ljava/lang/Integer;java/lang/String;)V"); + jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(Ljava/lang/Integer;Ljava/lang/String;)V"); chip::UtfString targetInfoName(env, targetInfo.name); - jobject jTargetInfo = env->NewObject(responseTypeClass, constructor, targetInfo.identifier, targetInfoName.jniValue()); + jobject jTargetInfo = env->NewObject(responseTypeClass, constructor, ConvertToIntegerJObject(targetInfo.identifier), + targetInfoName.jniValue()); chip::JniReferences::GetInstance().AddToList(jArrayList, jTargetInfo); } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp index 33d7c753bf9042..04c1196fcd57fe 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp @@ -204,6 +204,21 @@ JNI_METHOD(jboolean, verifyOrEstablishConnection) return true; } +JNI_METHOD(void, shutdownAllSubscriptions)(JNIEnv * env, jobject) +{ + chip::DeviceLayer::StackLock lock; + ChipLogProgress(AppServer, "JNI_METHOD shutdownAllSubscriptions called"); + + CastingServer::GetInstance()->ShutdownAllSubscriptions(); +} + +JNI_METHOD(void, disconnect)(JNIEnv * env, jobject) +{ + chip::DeviceLayer::StackLock lock; + ChipLogProgress(AppServer, "JNI_METHOD disconnect called"); + CastingServer::GetInstance()->Disconnect(); +} + JNI_METHOD(jobject, getActiveTargetVideoPlayers)(JNIEnv * env, jobject) { chip::DeviceLayer::StackLock lock; diff --git a/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_media_playback.xml b/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_media_playback.xml index fac656c8c447a5..4aea6b35967ed5 100644 --- a/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_media_playback.xml +++ b/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_media_playback.xml @@ -102,5 +102,19 @@ android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.AppCompat.Large" /> + + +