Skip to content

Commit ea235fd

Browse files
Zephyr standalone platform update (#34135)
* fix zephyr build (west) * Use different Kconfig In order to let the user choose his own pack of functionality. I guess BLUETOOTH shouldn't be enable by default, because Bluetooth isn't mandatory for a Matter device Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Remove ZephyrSocket Because zephyr has recvmsg now Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Support ip_mreq and ip_mreqn Because Zephyr seems to not have ip_mreq, only ip_mreqn, so add an extra flag in platform config to make the choice. This issue is only meets when doing ipv4 on a Zephyr platform Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Add missing functions to BLE Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Add specific configs and dependencies for Zephyr platform Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Revert "Remove ZephyrSocket" This reverts commit f283940. Also, fix things discussed with Damian-Nordic Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Don't use ZephyrSocket.h Since zephyr implement recvsg now Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Remove git artifact Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Restyled by whitespace * Restyled by clang-format * Re-add ZephyrSocket.h include Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Remove BLE Read declarations As discussed in conversations Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Allow net_if only with Ethernet or Wifi connection Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Check if Ethernet is defined Because all manufactures don't implement it Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> * Restyled by clang-format --------- Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 129081a commit ea235fd

12 files changed

+256
-97
lines changed

config/zephyr/app/enable-gnu-std.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ add_library(gnu17 INTERFACE)
22
target_compile_options(gnu17
33
INTERFACE
44
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17>
5-
-D_SYS__PTHREADTYPES_H_)
6-
target_link_libraries(app PRIVATE gnu17)
5+
-D_DEFAULT_SOURCE)
6+
target_link_libraries(app PRIVATE gnu17)

config/zephyr/chip-module/CMakeLists.txt

+48-20
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,27 @@ endif()
3939
get_filename_component(GN_ROOT_TARGET ${CHIP_ROOT}/config/zephyr/chip-gn REALPATH)
4040
get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake REALPATH)
4141

42-
# Additional configuration
43-
if (CONFIG_CHIP_PW_RPC)
44-
set(CONFIG_CHIP_LIB_PW_RPC YES)
45-
endif()
4642

4743
# Get common Cmake sources
4844
include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake)
4945
include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake)
5046

51-
# Prepare compiler flags
52-
matter_add_flags(-isystem${ZEPHYR_BASE}/../modules/crypto/mbedtls/include/)
53-
5447
if (CONFIG_POSIX_API)
55-
matter_add_flags(-D_SYS__PTHREADTYPES_H_)
48+
matter_add_flags(-D_DEFAULT_SOURCE)
5649
matter_add_flags(-isystem${ZEPHYR_BASE}/include/zephyr/posix)
5750
endif()
5851

52+
if(CONFIG_MBEDTLS)
53+
zephyr_include_directories($<TARGET_PROPERTY:mbedTLS,INTERFACE_INCLUDE_DIRECTORIES>)
54+
zephyr_compile_definitions($<TARGET_PROPERTY:mbedTLS,INTERFACE_COMPILE_DEFINITIONS>)
55+
endif()
56+
5957
zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C)
60-
matter_add_cflags(${ZEPHYR_CFLAGS_C})
58+
matter_add_cflags("${ZEPHYR_CFLAGS_C}")
6159
zephyr_get_compile_flags(ZEPHYR_CFLAGS_CC CXX)
62-
matter_add_cxxflags(${ZEPHYR_CFLAGS_CC})
60+
matter_add_cxxflags("${ZEPHYR_CFLAGS_CC}")
6361
zephyr_get_gnu_cpp_standard(ZEPHYR_GNU_CPP_STD)
64-
matter_add_cxxflags(${ZEPHYR_GNU_CPP_STD})
62+
matter_add_cxxflags("${ZEPHYR_GNU_CPP_STD}")
6563

6664
# Set up custom OpenThread configuration
6765

@@ -81,29 +79,59 @@ matter_common_gn_args(
8179
DEBUG CONFIG_DEBUG
8280
LIB_SHELL CONFIG_CHIP_LIB_SHELL
8381
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
84-
LIB_PW_RPC CONFIG_CHIP_PW_RPC
8582
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
8683
)
87-
matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
88-
matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
89-
matter_add_gn_arg_string("zephyr_cxx" ${CMAKE_CXX_COMPILER})
90-
matter_add_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD)
91-
matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD)
92-
matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4)
93-
matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)
84+
85+
matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
86+
matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
87+
matter_add_gn_arg_string("zephyr_cxx" ${CMAKE_CXX_COMPILER})
88+
matter_add_gn_arg_bool ("chip_logging" CONFIG_LOG)
89+
matter_add_gn_arg_bool ("chip_error_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 1)
90+
matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 3)
91+
matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 4)
92+
matter_add_gn_arg_bool ("chip_automation_logging" FALSE)
93+
matter_add_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD)
94+
matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD)
95+
matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_CHIP_IPV4)
96+
matter_add_gn_arg_bool ("chip_enable_wifi" CONFIG_WIFI)
97+
matter_add_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT)
98+
matter_add_gn_arg_bool ("chip_mdns_minimal" CONFIG_WIFI)
99+
matter_add_gn_arg_bool ("chip_mdns_minimal" CONFIG_NET_L2_ETHERNET)
100+
matter_add_gn_arg_bool ("chip_mdns_platform" CONFIG_NET_L2_OPENTHREAD)
101+
matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)
102+
matter_add_gn_arg_bool ("chip_inet_config_enable_udp_endpoint" CONFIG_NET_UDP)
103+
matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_NET_TCP)
104+
matter_add_gn_arg_bool ("chip_malloc_sys_heap" CONFIG_CHIP_MALLOC_SYS_HEAP)
105+
94106

95107
if (CONFIG_CHIP_ENABLE_DNSSD_SRP)
96108
matter_add_gn_arg_string("chip_mdns" "platform")
97109
endif()
98110

111+
if(CONFIG_WIFI)
112+
matter_add_gn_arg_string("chip_mdns" "minimal")
113+
elseif (CONFIG_NET_L2_ETHERNET)
114+
matter_add_gn_arg_string("chip_mdns" "minimal")
115+
elseif (CONFIG_NET_L2_OPENTHREAD)
116+
matter_add_gn_arg_string("chip_mdns" "platform")
117+
else()
118+
matter_add_gn_arg_string("chip_mdns" "none")
119+
endif()
120+
121+
if (CONFIG_CHIP_PW_RPC)
122+
set(PIGWEED_DIR "//third_party/pigweed/repo")
123+
matter_add_gn_arg_string("pw_assert_BACKEND" ${PIGWEED_DIR}/pw_assert_log:check_backend)
124+
matter_add_gn_arg_string("pw_log_BACKEND" ${PIGWEED_DIR}/pw_log_basic)
125+
matter_add_gn_arg("pw_build_LINK_DEPS" [\"${PIGWEED_DIR}/pw_assert:impl\",\ \"${PIGWEED_DIR}/pw_log:impl\"])
126+
endif()
127+
99128
matter_generate_args_tmp_file()
100129

101130
# ==============================================================================
102131
# Build chip library
103132
# ==============================================================================
104133
matter_build(chip
105134
LIB_SHELL ${CONFIG_CHIP_LIB_SHELL}
106-
LIB_PW_RPC ${CONFIG_CHIP_PW_RPC}
107135
LIB_TESTS ${CONFIG_CHIP_BUILD_TESTS}
108136
GN_DEPENDENCIES kernel
109137
)

config/zephyr/chip-module/Kconfig.bt

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# Copyright (c) 2021 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
# Bluetooth Low Energy configs
18+
config BT
19+
bool
20+
default y
21+
22+
config BT_PERIPHERAL
23+
bool
24+
default y
25+
26+
config BT_PERIPHERAL_PREF_MIN_INT
27+
int
28+
default 36
29+
30+
config BT_PERIPHERAL_PREF_MAX_INT
31+
int
32+
default 36
33+
34+
config BT_GAP_AUTO_UPDATE_CONN_PARAMS
35+
bool
36+
default y
37+
38+
config BT_GATT_DYNAMIC_DB
39+
bool
40+
default y
41+
42+
config BT_DEVICE_NAME_DYNAMIC
43+
bool
44+
default y
45+
46+
config BT_DEVICE_NAME_MAX
47+
int
48+
default 15
49+
50+
config BT_MAX_CONN
51+
int
52+
default 1
53+
54+
config BT_L2CAP_TX_MTU
55+
int
56+
default 247
57+
58+
config BT_BUF_ACL_RX_SIZE
59+
int
60+
default 251
61+
62+
config BT_BUF_ACL_TX_SIZE
63+
int
64+
default 251
65+
66+
config BT_RX_STACK_SIZE
67+
int
68+
default 1200

config/zephyr/chip-module/Kconfig.defaults

-71
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@
2020

2121
if CHIP
2222

23-
config LOG
24-
bool
25-
default y
26-
27-
if LOG
28-
29-
choice LOG_MODE
30-
default LOG_MODE_MINIMAL
31-
endchoice
32-
33-
choice MATTER_LOG_LEVEL_CHOICE
34-
default MATTER_LOG_LEVEL_DBG
35-
endchoice
36-
37-
config LOG_DEFAULT_LEVEL
38-
int
39-
default 2
40-
41-
endif
42-
4323
# disable synchronous printk to avoid blocking IRQs which
4424
# may affect time sensitive components
4525
config PRINTK_SYNC
@@ -119,58 +99,7 @@ config NET_BUF_TX_COUNT
11999
int
120100
default 80
121101

122-
# Bluetooth Low Energy configs
123-
config BT
124-
bool
125-
default y
126-
127-
config BT_PERIPHERAL
128-
bool
129-
default y
130-
131-
config BT_PERIPHERAL_PREF_MIN_INT
132-
int
133-
default 36
134-
135-
config BT_PERIPHERAL_PREF_MAX_INT
136-
int
137-
default 36
138-
139-
config BT_GAP_AUTO_UPDATE_CONN_PARAMS
140-
bool
141-
default y
142-
143-
config BT_GATT_DYNAMIC_DB
144-
bool
145-
default y
146-
147-
config BT_DEVICE_NAME_DYNAMIC
148-
bool
149-
default y
150-
151-
config BT_DEVICE_NAME_MAX
152-
int
153-
default 15
154102

155-
config BT_MAX_CONN
156-
int
157-
default 1
158-
159-
config BT_L2CAP_TX_MTU
160-
int
161-
default 247
162-
163-
config BT_BUF_ACL_RX_SIZE
164-
int
165-
default 251
166-
167-
config BT_BUF_ACL_TX_SIZE
168-
int
169-
default 251
170-
171-
config BT_RX_STACK_SIZE
172-
int
173-
default 1200
174103

175104
config CHIP_OTA_REQUESTOR
176105
bool
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# Copyright (c) 2021 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
if CHIP
18+
19+
config MBEDTLS
20+
default y
21+
22+
config MBEDTLS_ENTROPY_ENABLED
23+
default y
24+
25+
config MBEDTLS_ENTROPY_ENABLED
26+
default y
27+
28+
config MBEDTLS_ZEPHYR_ENTROPY
29+
default y
30+
31+
config MBEDTLS_ENABLE_HEAP
32+
default y
33+
34+
config MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
35+
default y
36+
37+
config MBEDTLS_ECP_ALL_ENABLED
38+
default y
39+
40+
config MBEDTLS_ECP_C
41+
default y
42+
43+
config MBEDTLS_PKCS5_C
44+
default y
45+
46+
config MBEDTLS_HKDF_C
47+
default y
48+
49+
config MBEDTLS_CIPHER_CCM_ENABLED
50+
default y
51+
52+
config MBEDTLS_CTR_DRBG_ENABLED
53+
default y
54+
55+
config MBEDTLS_CIPHER_AES_ENABLED
56+
default y
57+
58+
config MBEDTLS_ECDH_C
59+
default y
60+
61+
config MBEDTLS_ECDSA_C
62+
default y
63+
64+
endif #CHIP

src/inet/InetConfig.h

+12
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,16 @@
283283
#define HAVE_SO_BINDTODEVICE 0
284284
#endif
285285

286+
/**
287+
* @def INET_CONFIG_UDP_SOCKET_MREQN
288+
*
289+
* @brief
290+
* Should be set to 1 if your platform can handle struct ip_mreqn,
291+
* mandatory in UDPEndPointSocket.cpp
292+
*/
293+
294+
#ifndef INET_CONFIG_UDP_SOCKET_MREQN
295+
#define INET_CONFIG_UDP_SOCKET_MREQN 0
296+
#endif
297+
286298
// clang-format on

src/inet/UDPEndPointImplSockets.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -785,11 +785,22 @@ CHIP_ERROR UDPEndPointImplSockets::IPv4JoinLeaveMulticastGroupImpl(InterfaceId a
785785
interfaceAddr.s_addr = htonl(INADDR_ANY);
786786
}
787787

788+
#if INET_CONFIG_UDP_SOCKET_MREQN
789+
struct ip_mreqn lMulticastRequest;
790+
memset(&lMulticastRequest, 0, sizeof(lMulticastRequest));
791+
lMulticastRequest.imr_ifindex = aInterfaceId.GetPlatformInterface(); /* Network interface index */
792+
lMulticastRequest.imr_address = interfaceAddr; /* IP address of local interface */
793+
lMulticastRequest.imr_multiaddr = aAddress.ToIPv4(); /* IP multicast group address*/
794+
795+
#else
796+
788797
struct ip_mreq lMulticastRequest;
789798
memset(&lMulticastRequest, 0, sizeof(lMulticastRequest));
790799
lMulticastRequest.imr_interface = interfaceAddr;
791800
lMulticastRequest.imr_multiaddr = aAddress.ToIPv4();
792801

802+
#endif
803+
793804
const int command = join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
794805
if (setsockopt(mSocket, IPPROTO_IP, command, &lMulticastRequest, sizeof(lMulticastRequest)) != 0)
795806
{

src/platform/Zephyr/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static_library("Zephyr") {
3838
"ConnectivityManagerImpl.h",
3939
"DiagnosticDataProviderImpl.cpp",
4040
"DiagnosticDataProviderImpl.h",
41+
"DiagnosticDataProviderImplGetter.cpp",
4142
"InetPlatformConfig.h",
4243
"KeyValueStoreManagerImpl.cpp",
4344
"KeyValueStoreManagerImpl.h",

0 commit comments

Comments
 (0)