Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[darwin] Update the NetworkFramework UDP implementation #36418

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ void CHIPCommand::ShutdownCommissioner(const CommissionerIdentity & key)
CHIP_ERROR CHIPCommand::InitializeCommissioner(CommissionerIdentity & identity, chip::FabricId fabricId)
{
std::unique_ptr<ChipDeviceCommissioner> commissioner = std::make_unique<ChipDeviceCommissioner>();
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY
VerifyOrReturnError(chip::CanCastTo<uint16_t>(CHIP_UDC_PORT + fabricId), CHIP_ERROR_INVALID_ARGUMENT);
uint16_t udcListenPort = static_cast<uint16_t>(CHIP_UDC_PORT + fabricId);
commissioner->SetUdcListenPort(udcListenPort);
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY
chip::Controller::SetupParams commissionerParams;

ReturnLogErrorOnFailure(mCredIssuerCmds->SetupDeviceAttestation(commissionerParams, sTrustStore, sRevocationDelegate));
Expand Down
14 changes: 10 additions & 4 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ declare_args() {

# Enable automatic leak checks before the application exits
enable_leak_checking = !is_asan && target_os == "mac"

# Use Network.framework instead of POSIX sockets
use_network_framework = false
}

sdk = "macosx"
Expand Down Expand Up @@ -125,6 +128,12 @@ action("build-darwin-framework") {
args += [ "--no-enable-encoding-sentinel-enum-values" ]
}

if (defined(use_network_framework) && use_network_framework) {
args += [ "--use-network-framework" ]
} else {
args += [ "--no-use-network-framework" ]
}

output_name = "Matter.framework"
outputs = [
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/${output_name}",
Expand Down Expand Up @@ -277,10 +286,7 @@ executable("darwin-framework-tool") {
"${root_out_dir}/macos_framework_output/Build/Intermediates.noindex/Matter.build/${output_sdk_type}/Matter.build/out/gen/include",
]

defines = [
"CHIP_HAVE_CONFIG_H=1",
"CHIP_SYSTEM_CONFIG_USE_SOCKETS=1",
]
defines = [ "CHIP_HAVE_CONFIG_H=1" ]

frameworks += [
"CoreFoundation.framework",
Expand Down
5 changes: 4 additions & 1 deletion scripts/build/build_darwin_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def build_darwin_framework(args):
'CHIP_IS_ASAN': args.asan,
'CHIP_IS_BLE': args.ble,
'CHIP_IS_CLANG': args.clang,
'CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES': args.enable_encoding_sentinel_enum_values
'CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES': args.enable_encoding_sentinel_enum_values,
'CHIP_USE_NETWORK_FRAMEWORK': args.use_network_framework
}
for option in options:
command += ["{}={}".format(option, "YES" if options[option] else "NO")]
Expand Down Expand Up @@ -176,6 +177,8 @@ def build_darwin_framework(args):
parser.add_argument('--clang', action=argparse.BooleanOptionalAction)
parser.add_argument('--enable-encoding-sentinel-enum-values', action=argparse.BooleanOptionalAction)
parser.add_argument('--compdb', action=argparse.BooleanOptionalAction)
parser.add_argument('--use-network-framework',
action=argparse.BooleanOptionalAction)

args = parser.parse_args()
build_darwin_framework(args)
6 changes: 6 additions & 0 deletions src/darwin/Framework/chip_xcode_build_connector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ esac
)
}

[[ $CHIP_USE_NETWORK_FRAMEWORK == YES ]] && {
args+=(
'chip_system_config_use_network_framework=true'
)
}

# search current (or $2) and its parent directories until
# a name match is found, which is output on stdout
find_in_ancestors() {
Expand Down
9 changes: 8 additions & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ static_library("inet") {
"EndpointQueueFilter.h",
"UDPEndPoint.cpp",
"UDPEndPoint.h",
"UDPEndPointImpl${chip_system_config_inet}.cpp",
"UDPEndPointImpl${chip_system_config_inet}.h",
"UDPEndPointImpl.h",
]

if (chip_system_config_use_network_framework) {
sources += [ "UDPEndPointImpl${chip_system_config_inet}.mm" ]
} else {
sources += [ "UDPEndPointImpl${chip_system_config_inet}.cpp" ]
}

if (chip_system_config_inet == "Sockets") {
# TODO: dependency on this one is not clear as it is only ever
# enabled through CMakeLists.txt. Added here for completeness
Expand All @@ -187,5 +192,7 @@ static_library("inet") {
cflags = [ "-Wconversion" ]
if (current_os == "nuttx") {
cflags -= [ "-Wconversion" ]
} else if (chip_system_config_use_network_framework) {
cflags += [ "-fobjc-arc" ]
}
}
8 changes: 4 additions & 4 deletions src/inet/IPAddress-StringFuncts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <inet/IPAddress.h>
#include <lib/support/CodeUtils.h>

#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS
#include <arpa/inet.h>
#endif

Expand All @@ -54,7 +54,7 @@ char * IPAddress::ToString(char * buf, uint32_t bufSize) const
ip6_addr_t ip6_addr = ToIPv6();
ip6addr_ntoa_r(&ip6_addr, buf, (int) bufSize);
}
#elif CHIP_SYSTEM_CONFIG_USE_SOCKETS
#elif CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
// socklen_t is sometimes signed, sometimes not, so the only safe way to do
// this is to promote everything to an unsigned type that's known to be big
// enough for everything, then cast back to uint32_t after taking the min.
Expand Down Expand Up @@ -93,7 +93,7 @@ bool IPAddress::FromString(const char * str, IPAddress & output)
ip4_addr_t ipv4Addr;
if (!ip4addr_aton(str, &ipv4Addr))
return false;
#elif CHIP_SYSTEM_CONFIG_USE_SOCKETS
#elif CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
struct in_addr ipv4Addr;
if (inet_pton(AF_INET, str, &ipv4Addr) < 1)
return false;
Expand All @@ -107,7 +107,7 @@ bool IPAddress::FromString(const char * str, IPAddress & output)
ip6_addr_t ipv6Addr;
if (!ip6addr_aton(str, &ipv6Addr))
return false;
#elif CHIP_SYSTEM_CONFIG_USE_SOCKETS
#elif CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
struct in6_addr ipv6Addr;
if (inet_pton(AF_INET6, str, &ipv6Addr) < 1)
return false;
Expand Down
9 changes: 3 additions & 6 deletions src/inet/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@
#include <openthread/ip6.h>
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT

#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS
#include <net/if.h>
#include <netinet/in.h>
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS
#include <sys/socket.h>
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS

Expand Down Expand Up @@ -110,7 +107,7 @@ enum class IPv6MulticastFlag : uint8_t
};
using IPv6MulticastFlags = BitFlags<IPv6MulticastFlag>;

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
#if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
/**
* SockAddr should be used when calling any API that returns (by copying into
* it) a sockaddr, because that will need enough storage that it can hold data
Expand Down Expand Up @@ -139,7 +136,7 @@ union SockAddrWithoutStorage
sockaddr_in in;
sockaddr_in6 in6;
};
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

/**
* @brief Internet protocol address
Expand Down
8 changes: 4 additions & 4 deletions src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <lwip/tcpip.h>
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#if (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
Expand All @@ -50,7 +50,7 @@
#include <ifaddrs.h>
#include <net/if.h>
#include <sys/ioctl.h>
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#endif // (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS

#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF
#include <zephyr/net/net_if.h>
Expand Down Expand Up @@ -434,7 +434,7 @@ CHIP_ERROR InterfaceId::GetLinkLocalAddr(IPAddress * llAddr) const

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#if (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS

CHIP_ERROR InterfaceId::GetInterfaceName(char * nameBuf, size_t nameBufSize) const
{
Expand Down Expand Up @@ -788,7 +788,7 @@ CHIP_ERROR InterfaceId::GetLinkLocalAddr(IPAddress * llAddr) const
return (found) ? CHIP_NO_ERROR : INET_ERROR_ADDRESS_NOT_FOUND;
}

#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#endif // (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS

#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF

Expand Down
2 changes: 1 addition & 1 deletion src/inet/InetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class InterfaceId
static constexpr size_t kMaxIfNameLength = 13; // Names are formatted as %c%c%d
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#if (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
using PlatformType = unsigned int;
static constexpr size_t kMaxIfNameLength = IF_NAMESIZE;
#endif // CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
Expand Down
2 changes: 1 addition & 1 deletion src/inet/InetInterfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <system/SystemConfig.h>

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#if (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#include <net/if.h>

namespace chip {
Expand Down
2 changes: 1 addition & 1 deletion src/inet/InetInterfaceImplDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#include <inet/InetInterfaceImpl.h>

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#if (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
#include <net/if.h>
namespace chip {
namespace Inet {
Expand Down
Loading
Loading