Skip to content

Commit

Permalink
Merge branch 'master' into ncs_211_usage
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 authored Oct 27, 2022
2 parents 55f8843 + d65a207 commit 7b2fb51
Show file tree
Hide file tree
Showing 78 changed files with 9,801 additions and 5,920 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<NetworkCredentialsParcelable> CREATOR =
new Parcelable.Creator<NetworkCredentialsParcelable>() {
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<WiFiCredentials> CREATOR =
new Parcelable.Creator<WiFiCredentials>() {
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<ThreadCredentials> CREATOR =
new Parcelable.Creator<ThreadCredentials>() {
public ThreadCredentials createFromParcel(Parcel in) {
return new ThreadCredentials(in);
}

public ThreadCredentials[] newArray(int size) {
return new ThreadCredentials[size];
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,7 +44,7 @@ class EnterNetworkFragment : Fragment() {
)

interface Callback {
fun onNetworkCredentialsEntered(networkCredentials: NetworkCredentials)
fun onNetworkCredentialsEntered(networkCredentials: NetworkCredentialsParcelable)
}

override fun onCreateView(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/android/CHIPTool/chip-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}
}
Expand Down
31 changes: 23 additions & 8 deletions examples/light-switch-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 =
Expand Down
31 changes: 23 additions & 8 deletions examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 =
Expand Down
Loading

0 comments on commit 7b2fb51

Please sign in to comment.