Skip to content

Commit 862ae2d

Browse files
Revert "Remove ZephyrSocket"
This reverts commit f283940. Also, fix things discussed with Damian-Nordic Signed-off-by: Caldeira, Quentin <QuentinCaldeira@eaton.com>
1 parent 5daca77 commit 862ae2d

9 files changed

+82
-26
lines changed

src/inet/BUILD.gn

+9
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ static_library("inet") {
162162
"UDPEndPointImpl${chip_system_config_inet}.h",
163163
"UDPEndPointImpl.h",
164164
]
165+
<<<<<<< HEAD
166+
=======
167+
168+
if (chip_system_config_inet == "Sockets") {
169+
# TODO: dependency on this one is not clear as it is only ever
170+
# enabled through CMakeLists.txt. Added here for completeness
171+
sources += [ "ZephyrSocket.h" ]
172+
}
173+
>>>>>>> parent of f283940c03 (Remove ZephyrSocket)
165174
}
166175

167176
if (chip_with_nlfaultinjection) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,12 @@ CHIP_ERROR UDPEndPointImplSockets::IPv4JoinLeaveMulticastGroupImpl(InterfaceId a
781781
interfaceAddr.s_addr = htonl(INADDR_ANY);
782782
}
783783

784-
#ifdef SOCKET_ENABLE_MREQN
784+
#if INET_CONFIG_UDP_SOCKET_MREQN
785785
struct ip_mreqn lMulticastRequest;
786786
memset(&lMulticastRequest, 0, sizeof(lMulticastRequest));
787-
lMulticastRequest.imr_ifindex = -1; /* Network interface index */
788-
lMulticastRequest.imr_address = interfaceAddr; /* IP address of local interface */
789-
lMulticastRequest.imr_multiaddr = aAddress.ToIPv4(); /* IP multicast group address*/
787+
lMulticastRequest.imr_ifindex = aInterfaceId.GetPlatformInterface(); /* Network interface index */
788+
lMulticastRequest.imr_address = interfaceAddr; /* IP address of local interface */
789+
lMulticastRequest.imr_multiaddr = aAddress.ToIPv4(); /* IP multicast group address*/
790790

791791
#else
792792

src/inet/ZephyrSocket.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#/*
2+
*
3+
* Copyright (c) 2020 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @file
20+
* This header file defines BSD socket API functions which for various
21+
* reasons have not (yet) been implemented or exposed in Zephyr.
22+
*/
23+
24+
#pragma once
25+
26+
#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS
27+
#include <sys/select.h>
28+
#endif
29+
30+
#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS
31+
#include <zephyr/net/socket.h>
32+
#endif
33+
34+
static inline ssize_t recvmsg(int sock, struct msghdr * msg, int flags)
35+
{
36+
// Zephyr doesn't implement recvmsg at all, but if the message vector size is > 0 we can simply
37+
// translate recvmsg to recvfrom which fills only the first of the provided buffers (although
38+
// we don't get control messages in such a case).
39+
40+
if (msg->msg_iovlen < 1)
41+
{
42+
errno = EMSGSIZE;
43+
return -1;
44+
}
45+
46+
ssize_t ret = recvfrom(sock, msg->msg_iov[0].iov_base, msg->msg_iov[0].iov_len, flags, static_cast<sockaddr *>(msg->msg_name),
47+
&msg->msg_namelen);
48+
49+
if (ret >= 0)
50+
msg->msg_controllen = 0;
51+
52+
return ret;
53+
}

src/platform/Zephyr/BLEManagerImpl.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -802,20 +802,6 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBle
802802
return false;
803803
}
804804

805-
bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
806-
PacketBufferHandle pBuf)
807-
{
808-
ChipLogDetail(DeviceLayer, "BLE central not implemented");
809-
return false;
810-
}
811-
812-
bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext,
813-
const ChipBleUUID * svcId, const ChipBleUUID * charId)
814-
{
815-
ChipLogDetail(DeviceLayer, "BLE central not implemented");
816-
return false;
817-
}
818-
819805
void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId)
820806
{
821807
CloseConnection(conId);

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",

src/platform/Zephyr/CHIPDevicePlatformConfig.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@
104104
#endif // CHIP_DEVICE_CONFIG_SERVER_SHUTDOWN_ACTIONS_SLEEP_MS
105105

106106
#ifndef CHIP_DEVICE_CONFIG_HEAP_STATISTICS_MALLINFO
107-
#if !defined(CONFIG_CHIP_MALLOC_SYS_HEAP) && (defined(CONFIG_NEWLIB_LIBC) || (defined(CONFIG_NEWLIB_LIBC_NANO)))
107+
#if !defined(CONFIG_CHIP_MALLOC_SYS_HEAP) && defined(CONFIG_NEWLIB_LIBC)
108108
/// Use mallinfo() to obtain the heap usage statistics exposed by SoftwareDiagnostics cluster attributes.
109109
#define CHIP_DEVICE_CONFIG_HEAP_STATISTICS_MALLINFO 1
110110
#else
111111
#define CHIP_DEVICE_CONFIG_HEAP_STATISTICS_MALLINFO 0
112-
#endif // !defined(CONFIG_CHIP_MALLOC_SYS_HEAP) && (defined(CONFIG_NEWLIB_LIBC) || (defined(CONFIG_NEWLIB_LIBC_NANO)))
112+
#endif // !defined(CONFIG_CHIP_MALLOC_SYS_HEAP) && defined(CONFIG_NEWLIB_LIBC)
113113
#endif // CHIP_DEVICE_CONFIG_HEAP_STATISTICS_MALLINFO
114114

115115
#ifndef CHIP_DEVICE_BLE_ADVERTISING_PRIORITY

src/platform/Zephyr/CHIPPlatformConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
#ifndef CHIP_CONFIG_MAX_FABRICS
5454
#define CHIP_CONFIG_MAX_FABRICS 5
5555

56-
#define SOCKET_ENABLE_MREQN
56+
#define INET_CONFIG_UDP_SOCKET_MREQN 1
5757

5858
#endif

src/platform/Zephyr/DiagnosticDataProviderImpl.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ BootReasonType DetermineBootReason()
110110

111111
} // namespace
112112

113-
DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
114-
{
115-
return DiagnosticDataProviderImpl::GetDefaultInstance();
116-
}
117-
118113
DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance()
119114
{
120115
static DiagnosticDataProviderImpl sInstance;

0 commit comments

Comments
 (0)