Skip to content

Commit

Permalink
fix memory leak in DLL when reading propertyData
Browse files Browse the repository at this point in the history
add console msg for new Tunnel conn
  • Loading branch information
Ing-Dom committed Jun 5, 2024
1 parent ea18c2e commit ce80595
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
16 changes: 12 additions & 4 deletions src/knx/data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ bool DataLinkLayer::sendTelegram(NPDU & npdu, AckType ack, uint16_t destinationA
// a) we are the secondary interface (e.g. TP) AND
// b) destination == PA of a Tunnel (TODO)

if(_networkLayerEntity.getEntityIndex() == 1) // don't send to tp if we are the secondary (TP) interface AND the destination is a tunnel
if(_networkLayerEntity.getEntityIndex() == 1 && addrType == AddressType::IndividualAddress) // don't send to tp if we are the secondary (TP) interface AND the destination is a tunnel-PA
{
if(isTunnelingPA(destinationAddr))
sendTheFrame = false;
Expand Down Expand Up @@ -274,21 +274,29 @@ bool DataLinkLayer::isTunnelingPA(uint16_t pa)
{
uint8_t num = KNX_TUNNELING;
uint32_t len = 0;
uint8_t** data = nullptr;
_bau.propertyValueRead(OT_IP_PARAMETER, 0, PID_ADDITIONAL_INDIVIDUAL_ADDRESSES, num, 1, data, len);
uint8_t* data = nullptr;
_bau.propertyValueRead(OT_IP_PARAMETER, 0, PID_ADDITIONAL_INDIVIDUAL_ADDRESSES, num, 1, &data, len);
//printHex("isTunnelingPA, PID_ADDITIONAL_INDIVIDUAL_ADDRESSES: ", *data, len);
if(len != KNX_TUNNELING * 2)
{
println("Tunnel PAs unkwnown");
if(data != nullptr)
delete[] data;
return false;
}
for(uint8_t i = 0; i < KNX_TUNNELING; i++)
{
uint16_t tunnelpa;
popWord(tunnelpa, (*data)+i*2);
popWord(tunnelpa, (data)+i*2);
if(pa == tunnelpa)
{
if(data != nullptr)
delete[] data;
return true;
}
}
if(data != nullptr)
delete[] data;
return false;
}

Expand Down
46 changes: 22 additions & 24 deletions src/knx/ip_data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,41 +803,39 @@ void IpDataLinkLayer::loopHandleConnectRequest(uint8_t* buffer, uint16_t length,
tun->PortData = srcPort;
tun->PortCtrl = connRequest.hpaiCtrl().ipPortNumber()?connRequest.hpaiCtrl().ipPortNumber():srcPort;

#ifdef KNX_LOG_TUNNELING
print(">>> new tunnel[");
print("New Tunnel-Connection[");
print(tunIdx);
print("]: 0x");
print("], Channel: 0x");
print(tun->ChannelId, 16);
print("/");
print(" PA: ");
print(tun->IndividualAddress >> 12);
print(".");
print((tun->IndividualAddress >> 8) & 0xF);
print(".");
println(tun->IndividualAddress & 0xFF);
print(tun->IndividualAddress & 0xFF);

print(">>> Data Endpoint: ");
ip = tun->IpAddress;
print(ip >> 24);
print(" with ");
print(tun->IpAddress >> 24);
print(".");
print((ip >> 16) & 0xFF);
print((tun->IpAddress >> 16) & 0xFF);
print(".");
print((ip >> 8) & 0xFF);
print((tun->IpAddress >> 8) & 0xFF);
print(".");
print(ip & 0xFF);
print(tun->IpAddress & 0xFF);
print(":");
println(tun->PortData);
print(">>> Ctrl Endpoint: ");
ip = tun->IpAddress;
print(ip >> 24);
print(".");
print((ip >> 16) & 0xFF);
print(".");
print((ip >> 8) & 0xFF);
print(".");
print(ip & 0xFF);
print(":");
println(tun->PortCtrl);
#endif
print(tun->PortData);
if(tun->PortData != tun->PortCtrl)
{
print(" (Ctrlport: ");
print(tun->PortCtrl);
print(")");
}
if(tun->IsConfig)
{
print(" (Config-Channel)");
}
println();


KnxIpConnectResponse connRes(_ipParameters, tun->IndividualAddress, 3671, tun->ChannelId, connRequest.cri().type());
_platform.sendBytesUniCast(tun->IpAddress, tun->PortCtrl, connRes.data(), connRes.totalLength());
Expand Down

0 comments on commit ce80595

Please sign in to comment.