Skip to content

Commit

Permalink
Merge branch 'project-chip:master' into Support_Passing_CSRNonce_into…
Browse files Browse the repository at this point in the history
…_Commissioning_flow
  • Loading branch information
ritikananda27 authored and RitikaNanda committed Jun 21, 2021
2 parents 23708a4 + e47b41c commit 1011e99
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 271 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
}

if (chip_with_lwip) {
deps += [ "${chip_root}/src/lwip:all" ]
deps += [ "${chip_root}/src/lwip" ]
}

if (chip_build_tools) {
Expand Down
3 changes: 2 additions & 1 deletion examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ target_sources(app PRIVATE
)

target_include_directories(app PRIVATE
${ZEPHYR_BASE}/subsys // required to get access to `log_output_std.h`
${PIGWEED_ROOT}/pw_sys_io/public
${CHIP_ROOT}/src/lib/support
${CHIP_ROOT}/src/system
Expand All @@ -168,4 +167,6 @@ target_link_libraries(app PRIVATE
pw_rpc.server
)

target_link_libraries(pw_build INTERFACE zephyr_interface)

endif(CONFIG_CHIP_PW_RPC)
3 changes: 2 additions & 1 deletion examples/pigweed-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo)
add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo)

target_include_directories(app PRIVATE main/include
${ZEPHYR_BASE}/subsys // required to get access to `log_output_std.h`
${NRFCONNECT_COMMON}/util/include
${CHIP_ROOT}/src/lib/support
${PIGWEED_ROOT}/pw_sys_io/public
Expand Down Expand Up @@ -78,3 +77,5 @@ target_link_libraries(app PUBLIC
pw_rpc.nanopb.echo_service
pw_rpc.server
)

target_link_libraries(pw_build INTERFACE zephyr_interface)
2 changes: 1 addition & 1 deletion examples/pigweed-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ to read more about flashing on the nRF52840 Dongle.
Run the following command to start an interactive Python shell, where the Echo
RPC commands can be invoked:

python -m pw_hdlc.rpc_console --device /dev/ttyACM0 -b 115200 $CHIP_ROOT/third_party/pigweed/repo/pw_rpc/pw_rpc_protos/echo.proto -o /tmp/pw_rpc.out
python -m pw_hdlc.rpc_console --device /dev/ttyACM0 -b 115200 $CHIP_ROOT/third_party/pigweed/repo/pw_rpc/echo.proto -o /tmp/pw_rpc.out

To send an Echo RPC message, type the following command, where the actual
message is the text in quotation marks after the `msg=` phrase:
Expand Down
22 changes: 4 additions & 18 deletions examples/pigweed-app/nrfconnect/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,13 @@

LOG_MODULE_REGISTER(app);

static LEDWidget sStatusLED;

namespace {
#define RPC_STACK_SIZE (8 * 1024)
#define RPC_PRIORITY 7

K_THREAD_STACK_DEFINE(rpc_stack_area, RPC_STACK_SIZE);
struct k_thread rpc_thread_data;

pw::rpc::EchoService echo_service;
LEDWidget sStatusLED;
pw::rpc::EchoService sEchoService;

void RegisterServices(pw::rpc::Server & server)
{
server.RegisterService(echo_service);
}

void RunRpcService(void *, void *, void *)
{
Start(RegisterServices, &::chip::rpc::logger_mutex);
server.RegisterService(sEchoService);
}

} // namespace
Expand All @@ -72,8 +60,6 @@ int main()
sStatusLED.Init(SYSTEM_STATE_LED);
sStatusLED.Set(true);

k_thread_create(&rpc_thread_data, rpc_stack_area, K_THREAD_STACK_SIZEOF(rpc_stack_area), RunRpcService, NULL, NULL, NULL,
RPC_PRIORITY, 0, K_NO_WAIT);
k_thread_join(&rpc_thread_data, K_FOREVER);
Start(RegisterServices, &::chip::rpc::logger_mutex);
return 0;
}
1 change: 0 additions & 1 deletion examples/platform/nrfconnect/pw_sys_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pw_add_module_library(pw_sys_io.nrfconnect
SOURCES
sys_io_nrfconnect.cc
PRIVATE_DEPS
zephyr_interface
pw_sys_io
suppress_zephyr_warnings
)
233 changes: 233 additions & 0 deletions scripts/tools/linux_ip_namespace_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#!/usr/bin/env bash
#
#
# Copyright (c) 2021 Project CHIP Authors
#
# 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.
#
#
# Description:
# This is a utility script that can be used by developers to do
# simulate a device and controller on the same linux machine. This
# script is not intended to be used in a testing framework as-is
# because it requires root access to set up network namespaces.
#
# To use this script, compile the required device example, and
# run inside the namespace using
# sudo <path>/linux_ip_namespace_setup.sh -r <path_to_app>
#
# The controller can then be started in a new terminal and will
# be able to communicate with the application as if it were on
# a separate network.
#

NAMESPACE="MatterTester"
HOST_SIDE_IF_NAME="heth0"
NAMESPACE_SIDE_IF_NAME="neth0"
BRIDGE_NAME="nbridge"
BRIDGE_ADDR="192.168.4.50"
NAMESPACE_ADDR="192.168.4.45"
HOST_IPV6_ADDR=fc00::1
BRIDGE_IPV6_ADDR=fc00::b
NAMESPACE_IPV6_ADDR=fc00::a

function run_setup() {
# Create namespace.
ip netns add "$NAMESPACE"

# Create two virtual interfaces and link them - one on host side, one on namespace side.
ip link add "$HOST_SIDE_IF_NAME" type veth peer name "$NAMESPACE_SIDE_IF_NAME"

# Give the host a known IPv6 addr and set the host side up
ip -6 addr add "$HOST_IPV6_ADDR"/64 dev "$HOST_SIDE_IF_NAME"
ip link set "$HOST_SIDE_IF_NAME" up

# Associate namespace IF with the namespace
ip link set "$NAMESPACE_SIDE_IF_NAME" netns "$NAMESPACE"

# Give the namespace IF an address (something nothing else is using) and set it up
echo "Adding address for namespace IF"
ip netns exec "$NAMESPACE" ip -6 addr add "$NAMESPACE_IPV6_ADDR"/64 dev "$NAMESPACE_SIDE_IF_NAME"
ip netns exec "$NAMESPACE" ip link set dev "$NAMESPACE_SIDE_IF_NAME" up

# Add a route to the namespace to go through the bridge
echo "Setting routes for namespace"
ip netns exec "$NAMESPACE" ip -6 route add default dev "$NAMESPACE_SIDE_IF_NAME"

echo "Setup complete."
}

function run_add_ipv4() {
# Give the namespace an IPv4 address
ip netns exec "$NAMESPACE" ip addr add "$NAMESPACE_ADDR"/24 dev "$NAMESPACE_SIDE_IF_NAME"

# Add a bridge, give it an address (something nothing else is using)
echo "Setting up bridge"
ip link add name "$BRIDGE_NAME" type bridge
ip -6 addr add "$BRIDGE_IPV6_ADDR"/64 dev "$BRIDGE_NAME"
ip addr add "$BRIDGE_ADDR"/24 brd + dev "$BRIDGE_NAME"

# For ipv6 and ipv4 to work together, need the bridge to ignore the ipv6 packets (DROP here means don't bridge)
ebtables-legacy -t broute -A BROUTING -p ipv6 -j DROP -i "$HOST_SIDE_IF_NAME"
ip link set "$BRIDGE_NAME" up

# Connect the host side to the bridge, so now we have bridge <-> host_side_if <-> namespace_if
echo "Connecting host virtual IF to bridge"
ip link set "$HOST_SIDE_IF_NAME" master "$BRIDGE_NAME"

#ip netns exec ${NAMESPACE} ip route add default via ${BRIDGE_ADDR} dev ${NAMESPACE_SIDE_IF_NAME}
}

function run_cmd() {
# Start the app in the namespace
echo "Running $1 in namespace."
ip netns exec "$NAMESPACE" "$1"
}

function run_cleanup() {
# Deleting the namespace will remove the namespace and peer'd interfaces to
have_ebtables_legacy=$1
ip netns delete "$NAMESPACE"
if ifconfig | grep "$BRIDGE_NAME"; then
if [ "$have_ebtables_legacy" = true ]; then
# Just try to drop the additional rule - it references our interface
# so if it's there, we added it.
ebtables-legacy -t broute -D BROUTING -p ipv6 -j DROP -i "$HOST_SIDE_IF_NAME" >/dev/null
fi
ip link delete dev "$BRIDGE_NAME" type bridge
fi
}

function help() {
echo "Usage: $file_name [ options ... ]"
echo ""

echo "This script is used to set up linux namespaces for Matter device testing"
echo "between a controller and device on the same linux machine."
echo ""
echo "To use this script, run the device code in a namespace using the -r command"
echo "and a controller in a seperate terminal to simulate two devices communicating"
echo "across a network."
echo "Example:"
echo "--------"
echo "Terminal 1:"
echo "sudo <path>/$file_name -r <path>/<application_name>"
echo ""
echo "Terminal 2:"
echo "<path>/chip-device-ctrl"
echo ""
echo "This script requires sudo for setup and requires access to ebtables-legacy"
echo "to set up dual ipv4/ipv6 namespaces. Defaults to ipv6 only."
echo ""

echo "Options:
-h, --help Display this information.
-s, --setup Setup an IP namespace. Will run cleanup if namespace exists.
-4, --ipv4 Add ipv4 support.
-r, --run filename Run file in the namespace. Will setup namespace if required.
-c, --cleanup Delete namespace and routes
"
}

declare setup=false
declare filename=""
declare run=false
declare cleanup=false
declare ipv4=false

file_name=${0##*/}

while (($#)); do
case $1 in
--help | -h)
help
exit 1
;;
--setup | -s)
setup=true
;;
--run | -r)
run=true
filename=$2
shift
;;
--cleanup | -c)
cleanup=true
;;
--ipv4 | -4)
ipv4=true
;;
-*)
help
echo "Unknown Option \"$1\""
exit 1
;;
esac
shift
done

if [[ $EUID -ne 0 ]]; then
echo "You must run this script with superuser privileges."
exit 1
fi

if ifconfig | grep "$HOST_SIDE_IF_NAME"; then
issetup=true
else
issetup=false
fi

if [ "$setup" = false ] && [ "$run" = false ] && [ "$cleanup" = false ]; then
echo "Must specify one or more of -s, -r, -c."
exit 1
fi

if command -v ebtables-legacy >/dev/null; then
have_ebtables_legacy=true
else
have_ebtables_legacy=false
fi

if [ "$ipv4" = true ] && [ "$have_ebtables_legacy" = false ]; then
echo "To set up namespaces with ipv4/ipv6 connectivity, ebtables-legacy"
echo "is required. For example, to install on machines using APT:"
echo "sudo apt-get install ebtables"
exit 1
fi

if [ "$run" = true ]; then
if [ "$issetup" = false ]; then
setup=true
fi
fi

if [ "$setup" = true ]; then
if [ "$issetup" = true ]; then
cleanup=true
fi
fi

if [ "$cleanup" = true ]; then
run_cleanup "$have_ebtables_legacy"
fi

if [ "$setup" = true ]; then
run_setup
if [ "$ipv4" = true ]; then
run_add_ipv4
fi
fi

if [ "$run" = true ]; then
run_cmd "$filename"
fi
8 changes: 4 additions & 4 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ CHIP_ERROR AndroidDeviceControllerWrapper::GenerateNodeOperationalCertificate(co
{
jmethodID method;
CHIP_ERROR err = CHIP_NO_ERROR;
err = FindMethod(GetEnvForCurrentThread(), mJavaObjectRef, "onOpCSRGenerationComplete", "([B)V", &method);
err = FindMethod(JniReferences::GetEnvForCurrentThread(), mJavaObjectRef, "onOpCSRGenerationComplete", "([B)V", &method);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Error invoking onOpCSRGenerationComplete: %d", err);
Expand All @@ -178,9 +178,9 @@ CHIP_ERROR AndroidDeviceControllerWrapper::GenerateNodeOperationalCertificate(co
CHIP_ERROR generateCert = NewNodeOperationalX509Cert(request, chip::CertificateIssuerLevel::kIssuerIsRootCA, pubkey, mIssuer, certBuf, certBufSize,
outCertLen);
jbyteArray argument;
GetEnvForCurrentThread()->ExceptionClear();
N2J_ByteArray(GetEnvForCurrentThread(), csr.data(),csr.size(),argument);
GetEnvForCurrentThread()->CallVoidMethod(mJavaObjectRef, method, argument);
JniReferences::GetEnvForCurrentThread()->ExceptionClear();
N2J_ByteArray(JniReferences::GetEnvForCurrentThread(), csr.data(),csr.size(),argument);
JniReferences::GetEnvForCurrentThread()->CallVoidMethod(mJavaObjectRef, method, argument);
return generateCert;
}

Expand Down
2 changes: 1 addition & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static_library("inet") {
"${nlio_root}:nlio",
]

if (chip_with_lwip) {
if (chip_system_config_use_lwip) {
public_deps += [ "${chip_root}/src/lwip" ]
}

Expand Down
6 changes: 3 additions & 3 deletions src/inet/RawEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
#include <lwip/raw.h>
#include <lwip/tcpip.h>
#if CHIP_HAVE_CONFIG_H
#include <lwip/lwip_buildconfig.h>
#endif // CHIP_HAVE_CONFIG_H
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/lwip_buildconfig.h> // nogncheck
#endif // CHIP_HAVE_CONFIG_H
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
#include <system/SystemSockets.h>
Expand Down
6 changes: 3 additions & 3 deletions src/inet/UDPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
#include <lwip/tcpip.h>
#include <lwip/udp.h>
#if CHIP_HAVE_CONFIG_H
#include <lwip/lwip_buildconfig.h>
#endif // CHIP_HAVE_CONFIG_H
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/lwip_buildconfig.h> // nogncheck
#endif // CHIP_HAVE_CONFIG_H
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
#if HAVE_SYS_SOCKET_H
Expand Down
3 changes: 0 additions & 3 deletions src/lwip/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,4 @@ if (current_os == "zephyr") {
"${chip_root}/src:includes",
]
}
group("all") {
deps = [ ":lwip_all" ]
}
}
Loading

0 comments on commit 1011e99

Please sign in to comment.