diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index d5fd71ec582038..dc518ccc1a55c8 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -30,6 +30,10 @@ if (chip_system_config_use_lwip) { import("//build_overrides/lwip.gni") } +if (chip_device_platform == "darwin") { + import("${chip_root}/src/platform/Darwin/inet/darwin_sources.gni") +} + declare_args() { # Extra header to include in SystemConfig.h for project. chip_inet_project_config_include = "" @@ -94,7 +98,6 @@ static_library("inet") { # - src/inet/EndPointStateSockets.h sources = [ "EndPointBasis.h", - "EndPointState${chip_system_config_inet}.h", "IANAConstants.h", "IPAddress-StringFuncts.cpp", "IPAddress.cpp", @@ -114,6 +117,10 @@ static_library("inet") { "arpa-inet-compatibility.h", ] + if (!chip_system_config_use_network_framework) { + sources += [ "EndPointState${chip_system_config_inet}.h" ] + } + public_deps = [ ":impl_header", ":inet_config_header", @@ -168,9 +175,7 @@ static_library("inet") { "UDPEndPointImpl.h", ] - if (chip_system_config_use_network_framework) { - sources += [ "UDPEndPointImpl${chip_system_config_inet}.mm" ] - } else { + if (!chip_system_config_use_network_framework) { sources += [ "UDPEndPointImpl${chip_system_config_inet}.cpp" ] } } @@ -197,6 +202,7 @@ static_library("inet") { if (current_os == "nuttx") { cflags -= [ "-Wconversion" ] } else if (chip_system_config_use_network_framework) { + sources += darwin_sources cflags += [ "-fobjc-arc" ] } } diff --git a/src/inet/UDPEndPointImplNetworkFramework.h b/src/inet/UDPEndPointImplNetworkFramework.h index 0e8f7dda68ebcb..faa998d1e012e7 100644 --- a/src/inet/UDPEndPointImplNetworkFramework.h +++ b/src/inet/UDPEndPointImplNetworkFramework.h @@ -1,8 +1,6 @@ /* * - * Copyright (c) 2020-2021 Project CHIP Authors - * Copyright (c) 2018 Google LLC - * Copyright (c) 2013-2017 Nest Labs, Inc. + * Copyright (c) 2025 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. @@ -21,59 +19,4 @@ * This file declares an implementation of Inet::UDPEndPoint using Network Framework. */ -#pragma once - -#include - -namespace chip { -namespace Inet { - -class UDPEndPointImplNetworkFramework : public UDPEndPoint, public EndPointStateNetworkFramework -{ -public: - UDPEndPointImplNetworkFramework(EndPointManager & endPointManager) : UDPEndPoint(endPointManager) {} - - // UDPEndPoint overrides. - CHIP_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) override; - InterfaceId GetBoundInterface() const override; - uint16_t GetBoundPort() const override; - void Free() override; - -private: - // UDPEndPoint overrides. -#if INET_CONFIG_ENABLE_IPV4 - CHIP_ERROR IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override; -#endif // INET_CONFIG_ENABLE_IPV4 - CHIP_ERROR IPv6JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override; - CHIP_ERROR BindImpl(IPAddressType addressType, const IPAddress & address, uint16_t port, InterfaceId interfaceId) override; - CHIP_ERROR BindInterfaceImpl(IPAddressType addressType, InterfaceId interfaceId) override; - CHIP_ERROR ListenImpl() override; - CHIP_ERROR SendMsgImpl(const IPPacketInfo * pktInfo, chip::System::PacketBufferHandle && msg) override; - void CloseImpl() override; - - nw_listener_t mListener; - dispatch_semaphore_t mListenerSemaphore; - dispatch_queue_t mListenerQueue; - nw_connection_t mConnection; - dispatch_semaphore_t mConnectionSemaphore; - dispatch_queue_t mConnectionQueue; - dispatch_semaphore_t mSendSemaphore; - dispatch_queue_t mSystemQueue; - - CHIP_ERROR ConfigureProtocol(IPAddressType aAddressType, const nw_parameters_t & aParameters); - CHIP_ERROR StartListener(); - CHIP_ERROR GetConnection(const IPPacketInfo * aPktInfo); - nw_endpoint_t GetEndPoint(const IPAddressType aAddressType, const IPAddress & aAddress, uint16_t aPort, - InterfaceId interfaceIndex = InterfaceId::Null()); - CHIP_ERROR StartConnection(nw_connection_t aConnection); - void GetPacketInfo(const nw_connection_t & aConnection, IPPacketInfo & aPacketInfo); - void HandleDataReceived(const nw_connection_t & aConnection); - CHIP_ERROR ReleaseListener(); - CHIP_ERROR ReleaseConnection(); - void ReleaseAll(); -}; - -using UDPEndPointImpl = UDPEndPointImplNetworkFramework; - -} // namespace Inet -} // namespace chip +#include diff --git a/src/inet/EndPointStateNetworkFramework.h b/src/platform/Darwin/inet/EndPointStateNetworkFramework.h similarity index 100% rename from src/inet/EndPointStateNetworkFramework.h rename to src/platform/Darwin/inet/EndPointStateNetworkFramework.h diff --git a/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.h b/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.h new file mode 100644 index 00000000000000..0e8f7dda68ebcb --- /dev/null +++ b/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.h @@ -0,0 +1,79 @@ +/* + * + * Copyright (c) 2020-2021 Project CHIP Authors + * Copyright (c) 2018 Google LLC + * Copyright (c) 2013-2017 Nest Labs, Inc. + * + * 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. + */ + +/** + * This file declares an implementation of Inet::UDPEndPoint using Network Framework. + */ + +#pragma once + +#include + +namespace chip { +namespace Inet { + +class UDPEndPointImplNetworkFramework : public UDPEndPoint, public EndPointStateNetworkFramework +{ +public: + UDPEndPointImplNetworkFramework(EndPointManager & endPointManager) : UDPEndPoint(endPointManager) {} + + // UDPEndPoint overrides. + CHIP_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) override; + InterfaceId GetBoundInterface() const override; + uint16_t GetBoundPort() const override; + void Free() override; + +private: + // UDPEndPoint overrides. +#if INET_CONFIG_ENABLE_IPV4 + CHIP_ERROR IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override; +#endif // INET_CONFIG_ENABLE_IPV4 + CHIP_ERROR IPv6JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override; + CHIP_ERROR BindImpl(IPAddressType addressType, const IPAddress & address, uint16_t port, InterfaceId interfaceId) override; + CHIP_ERROR BindInterfaceImpl(IPAddressType addressType, InterfaceId interfaceId) override; + CHIP_ERROR ListenImpl() override; + CHIP_ERROR SendMsgImpl(const IPPacketInfo * pktInfo, chip::System::PacketBufferHandle && msg) override; + void CloseImpl() override; + + nw_listener_t mListener; + dispatch_semaphore_t mListenerSemaphore; + dispatch_queue_t mListenerQueue; + nw_connection_t mConnection; + dispatch_semaphore_t mConnectionSemaphore; + dispatch_queue_t mConnectionQueue; + dispatch_semaphore_t mSendSemaphore; + dispatch_queue_t mSystemQueue; + + CHIP_ERROR ConfigureProtocol(IPAddressType aAddressType, const nw_parameters_t & aParameters); + CHIP_ERROR StartListener(); + CHIP_ERROR GetConnection(const IPPacketInfo * aPktInfo); + nw_endpoint_t GetEndPoint(const IPAddressType aAddressType, const IPAddress & aAddress, uint16_t aPort, + InterfaceId interfaceIndex = InterfaceId::Null()); + CHIP_ERROR StartConnection(nw_connection_t aConnection); + void GetPacketInfo(const nw_connection_t & aConnection, IPPacketInfo & aPacketInfo); + void HandleDataReceived(const nw_connection_t & aConnection); + CHIP_ERROR ReleaseListener(); + CHIP_ERROR ReleaseConnection(); + void ReleaseAll(); +}; + +using UDPEndPointImpl = UDPEndPointImplNetworkFramework; + +} // namespace Inet +} // namespace chip diff --git a/src/inet/UDPEndPointImplNetworkFramework.mm b/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.mm similarity index 100% rename from src/inet/UDPEndPointImplNetworkFramework.mm rename to src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.mm diff --git a/src/platform/Darwin/inet/darwin_sources.gni b/src/platform/Darwin/inet/darwin_sources.gni new file mode 100644 index 00000000000000..29cc672cdb09cc --- /dev/null +++ b/src/platform/Darwin/inet/darwin_sources.gni @@ -0,0 +1,30 @@ +# Copyright (c) 2025 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. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +import("${chip_root}/src/inet/inet.gni") + +# These files are physically located under src/platform/Darwin/inet/, +# but are considered part of the inet logical layer. + +darwin_sources = [] + +if (chip_inet_config_enable_udp_endpoint) { + darwin_sources += [ + "${chip_root}/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.h", + "${chip_root}/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.mm", + ] +}