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

Convert to enum class in src/inet #10504

Merged
merged 10 commits into from
Oct 21, 2021
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/discover/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Resolve : public DiscoverCommand, public chip::Dnssd::ResolverDelegate
chip::Dnssd::Resolver::Instance().SetResolverDelegate(this);
ChipLogProgress(chipTool, "Dnssd: Searching for NodeId: %" PRIx64 " FabricId: %" PRIx64 " ...", remoteId, fabricId);
return chip::Dnssd::Resolver::Instance().ResolveNodeId(chip::PeerId().SetNodeId(remoteId).SetCompressedFabricId(fabricId),
chip::Inet::kIPAddressType_Any);
chip::Inet::IPAddressType::kAny);
}

void OnNodeIdResolved(const chip::Dnssd::ResolvedNodeData & nodeData) override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void DiscoverCommissionablesCommand::OnDiscoveredDevice(const chip::Dnssd::Disco
ChipLogProgress(Discovery, "\tPairing Hint\t\t0x%x", nodeData.pairingHint);
for (int i = 0; i < nodeData.numIPs; i++)
{
char buf[chip::Inet::kMaxIPAddressStringLength];
char buf[chip::Inet::IPAddress::kMaxStringLength];
nodeData.ipAddress[i].ToString(buf);

ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", i, buf);
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void PairingCommand::OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR err)
void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData)
{
const uint16_t port = nodeData.port;
char buf[chip::Inet::kMaxIPAddressStringLength];
char buf[chip::Inet::IPAddress::kMaxStringLength];
nodeData.ipAddress[0].ToString(buf);
ChipLogProgress(chipTool, "Discovered Device: %s:%u", buf, port);

Expand Down
4 changes: 2 additions & 2 deletions examples/minimal-mdns/AllInterfaceListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
{
#if INET_CONFIG_ENABLE_IPV4
*id = INET_NULL_INTERFACEID;
*type = chip::Inet::kIPAddressType_IPv4;
*type = chip::Inet::IPAddressType::kIPv4;
#endif
mState = State::kIpV6;

Expand All @@ -57,7 +57,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
}

*id = mIterator.GetInterfaceId();
*type = chip::Inet::kIPAddressType_IPv6;
*type = chip::Inet::IPAddressType::kIPv6;

for (mIterator.Next(); SkipCurrentInterface(); mIterator.Next())
{
Expand Down
15 changes: 6 additions & 9 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,16 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
SuccessOrExit(err);

// Init transport before operations with secure session mgr.
err = mTransports.Init(UdpListenParameters(&DeviceLayer::InetLayer)
.SetAddressType(IPAddressType::kIPAddressType_IPv6)
.SetListenPort(mSecuredServicePort)
err = mTransports.Init(
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(IPAddressType::kIPv6).SetListenPort(mSecuredServicePort)

#if INET_CONFIG_ENABLE_IPV4
,
UdpListenParameters(&DeviceLayer::InetLayer)
.SetAddressType(IPAddressType::kIPAddressType_IPv4)
.SetListenPort(mSecuredServicePort)
,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(IPAddressType::kIPv4).SetListenPort(mSecuredServicePort)
#endif
#if CONFIG_NETWORK_LAYER_BLE
,
BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer())
,
BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer())
#endif
);

Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ int main(int argc, char * argv[])
InitializeChip();

err = gTransportManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer)
.SetAddressType(chip::Inet::kIPAddressType_IPv6)
.SetAddressType(chip::Inet::IPAddressType::kIPv6)
.SetListenPort(IM_CLIENT_PORT));
SuccessOrExit(err);

Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int main(int argc, char * argv[])
InitializeChip();

err = gTransportManager.Init(
chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv6));
chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::IPAddressType::kIPv6));
SuccessOrExit(err);

err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager);
Expand Down
9 changes: 4 additions & 5 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ CHIP_ERROR DeviceController::UpdateDevice(NodeId deviceId)
{
#if CHIP_DEVICE_CONFIG_ENABLE_DNSSD
return Dnssd::Resolver::Instance().ResolveNodeId(PeerId().SetCompressedFabricId(GetCompressedFabricId()).SetNodeId(deviceId),
chip::Inet::kIPAddressType_Any);
chip::Inet::IPAddressType::kAny);
#else
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
#endif // CHIP_DEVICE_CONFIG_ENABLE_DNSSD
Expand Down Expand Up @@ -631,12 +631,12 @@ CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params)
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable
mUdcTransportMgr = chip::Platform::New<DeviceIPTransportMgr>();
ReturnErrorOnFailure(mUdcTransportMgr->Init(Transport::UdpListenParameters(mSystemState->InetLayer())
.SetAddressType(Inet::kIPAddressType_IPv6)
.SetAddressType(Inet::IPAddressType::kIPv6)
.SetListenPort((uint16_t)(mUdcListenPort))
#if INET_CONFIG_ENABLE_IPV4
,
Transport::UdpListenParameters(mSystemState->InetLayer())
.SetAddressType(Inet::kIPAddressType_IPv4)
.SetAddressType(Inet::IPAddressType::kIPv4)
.SetListenPort((uint16_t)(mUdcListenPort))
#endif // INET_CONFIG_ENABLE_IPV4
));
Expand Down Expand Up @@ -1999,8 +1999,7 @@ void DeviceCommissioner::AdvanceCommissioningStage(CHIP_ERROR err)
#if CHIP_DEVICE_CONFIG_ENABLE_DNSSD
ChipLogProgress(Controller, "Finding node on operational network");
Dnssd::Resolver::Instance().ResolveNodeId(
PeerId().SetCompressedFabricId(GetCompressedFabricId()).SetNodeId(device->GetDeviceId()),
Inet::IPAddressType::kIPAddressType_Any);
PeerId().SetCompressedFabricId(GetCompressedFabricId()).SetNodeId(device->GetDeviceId()), Inet::IPAddressType::kAny);
#endif
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
stateParams.transportMgr = chip::Platform::New<DeviceTransportMgr>();

ReturnErrorOnFailure(stateParams.transportMgr->Init(
Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::kIPAddressType_IPv6).SetListenPort(mListenPort)
Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(mListenPort)
#if INET_CONFIG_ENABLE_IPV4
,
Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::kIPAddressType_IPv4).SetListenPort(mListenPort)
Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(mListenPort)
#endif
#if CONFIG_NETWORK_LAYER_BLE
,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners(
ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp);
for (int j = 0; j < dnsSdInfo->numIPs; ++j)
{
char buf[chip::Inet::kMaxIPAddressStringLength];
char buf[chip::Inet::IPAddress::kMaxStringLength];
dnsSdInfo->ipAddress[j].ToString(buf);
ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", j, buf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void pychip_DeviceController_PrintDiscoveredDevices(chip::Controller::DeviceComm
ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp);
for (int j = 0; j < dnsSdInfo->numIPs; ++j)
{
char buf[chip::Inet::kMaxIPAddressStringLength];
char buf[chip::Inet::IPAddress::kMaxStringLength];
dnsSdInfo->ipAddress[j].ToString(buf);
ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", j, buf);
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/discovery/NodeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extern "C" ChipError::StorageType pychip_discovery_resolve(uint64_t fabricId, ui
Resolver::Instance().SetResolverDelegate(&gPythonResolverDelegate);

result = Resolver::Instance().ResolveNodeId(chip::PeerId().SetCompressedFabricId(fabricId).SetNodeId(nodeId),
chip::Inet::IPAddressType::kIPAddressType_Any);
chip::Inet::IPAddressType::kAny);
});

return result.AsInteger();
Expand Down
11 changes: 5 additions & 6 deletions src/controller/tests/TestDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext

systemLayer.Init();
inetLayer.Init(systemLayer, nullptr);
transportMgr.Init(
UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPAddressType_IPv6).SetListenPort(CHIP_PORT)
transportMgr.Init(UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(CHIP_PORT)
#if INET_CONFIG_ENABLE_IPV4
,
UdpListenParameters(&inetLayer).SetAddressType(Inet::kIPAddressType_IPv4).SetListenPort(CHIP_PORT)
,
UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT)
#endif
#if CONFIG_NETWORK_LAYER_BLE
,
BleListenParameters(&blelayer)
,
BleListenParameters(&blelayer)
#endif
);
sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager);
Expand Down
32 changes: 16 additions & 16 deletions src/inet/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ ip_addr_t IPAddress::ToLwIPAddr(void) const
switch (Type())
{
#if INET_CONFIG_ENABLE_IPV4
case kIPAddressType_IPv4:
case IPAddressType::kIPv4:
IP_SET_TYPE_VAL(ret, IPADDR_TYPE_V4);
*ip_2_ip4(&ret) = IPAddress::ToIPv4();
break;
#endif // INET_CONFIG_ENABLE_IPV4

case kIPAddressType_IPv6:
case IPAddressType::kIPv6:
IP_SET_TYPE_VAL(ret, IPADDR_TYPE_V6);
*ip_2_ip6(&ret) = IPAddress::ToIPv6();
break;
Expand Down Expand Up @@ -132,12 +132,12 @@ lwip_ip_addr_type IPAddress::ToLwIPAddrType(IPAddressType typ)
switch (typ)
{
#if INET_CONFIG_ENABLE_IPV4
case kIPAddressType_IPv4:
case IPAddressType::kIPv4:
ret = IPADDR_TYPE_V4;
break;
#endif // INET_CONFIG_ENABLE_IPV4

case kIPAddressType_IPv6:
case IPAddressType::kIPv6:
ret = IPADDR_TYPE_V6;
break;

Expand Down Expand Up @@ -321,12 +321,12 @@ uint64_t IPAddress::GlobalId() const
IPAddressType IPAddress::Type() const
{
if (Addr[0] == 0 && Addr[1] == 0 && Addr[2] == 0 && Addr[3] == 0)
return kIPAddressType_Any;
return IPAddressType::kAny;
#if INET_CONFIG_ENABLE_IPV4
if (Addr[0] == 0 && Addr[1] == 0 && Addr[2] == htonl(0xFFFF))
return kIPAddressType_IPv4;
return IPAddressType::kIPv4;
#endif // INET_CONFIG_ENABLE_IPV4
return kIPAddressType_IPv6;
return IPAddressType::kIPv6;
}

// Encode IPAddress to buffer in network byte order. Buffer must have at least 128 bits of available space.
Expand Down Expand Up @@ -382,10 +382,11 @@ IPAddress IPAddress::MakeLLA(uint64_t interfaceId)
return addr;
}

IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope,
IPAddress IPAddress::MakeIPv6Multicast(IPv6MulticastFlags aFlags, uint8_t aScope,
const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES])
{
const uint32_t lFlagsAndScope = (((uint32_t(aFlags) & 0xF) << 20) | ((uint32_t(aScope) & 0xF) << 16));
const uint32_t lFlagsAndScope =
(((static_cast<uint32_t>(aFlags.Raw()) & 0xF) << 20) | ((static_cast<uint32_t>(aScope) & 0xF) << 16));
IPAddress addr;

addr.Addr[0] = htonl((0xFF000000U | lFlagsAndScope) | (uint32_t(aGroupId[0]) << 8) | (uint32_t(aGroupId[1]) << 0));
Expand All @@ -399,7 +400,7 @@ IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope,
return addr;
}

IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, uint32_t aGroupId)
IPAddress IPAddress::MakeIPv6Multicast(IPv6MulticastFlags aFlags, uint8_t aScope, uint32_t aGroupId)
{
const uint8_t lGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES] = { 0,
0,
Expand All @@ -421,23 +422,22 @@ IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, uint32_t

IPAddress IPAddress::MakeIPv6WellKnownMulticast(uint8_t aScope, uint32_t aGroupId)
{
const uint8_t lFlags = 0;
constexpr IPv6MulticastFlags lFlags;

return (MakeIPv6Multicast(lFlags, aScope, aGroupId));
}

IPAddress IPAddress::MakeIPv6TransientMulticast(uint8_t aFlags, uint8_t aScope,
IPAddress IPAddress::MakeIPv6TransientMulticast(IPv6MulticastFlags aFlags, uint8_t aScope,
const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES])
{
const uint8_t lFlags = (aFlags | kIPv6MulticastFlag_Transient);

return (MakeIPv6Multicast(lFlags, aScope, aGroupId));
aFlags.Set(IPv6MulticastFlag::kTransient);
return (MakeIPv6Multicast(aFlags, aScope, aGroupId));
}

IPAddress IPAddress::MakeIPv6PrefixMulticast(uint8_t aScope, uint8_t aPrefixLength, const uint64_t & aPrefix, uint32_t aGroupId)
{
const uint8_t lReserved = 0;
const uint8_t lFlags = kIPv6MulticastFlag_Prefix;
const IPv6MulticastFlags lFlags = IPv6MulticastFlag::kPrefix;
const uint8_t lGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES] = { lReserved,
aPrefixLength,
static_cast<uint8_t>((aPrefix & 0xFF00000000000000ULL) >> 56),
Expand Down
Loading