Refactor IP-Tunneling to use IpParameterObject directly instead of via BusAccessUnit

This commit is contained in:
Thomas Kunze 2024-08-10 00:18:50 +02:00
parent e988c431fd
commit fcfeef3334
18 changed files with 74 additions and 56 deletions

View File

@ -125,6 +125,36 @@ set(SOURCES
../../src/knx/transport_layer.h
../../src/knx/usb_tunnel_interface.cpp
../../src/knx/usb_tunnel_interface.h
../../src/knx/knx_ip_tunnel_connection.cpp
../../src/knx/knx_ip_tunnel_connection.h
../../src/knx/knx_ip_tunneling_request.cpp
../../src/knx/knx_ip_tunneling_request.h
../../src/knx/knx_ip_ch.cpp
../../src/knx/knx_ip_ch.h
../../src/knx/knx_ip_cri.cpp
../../src/knx/knx_ip_cri.h
../../src/knx/knx_ip_crd.cpp
../../src/knx/knx_ip_crd.h
../../src/knx/knx_ip_connect_request.cpp
../../src/knx/knx_ip_connect_request.h
../../src/knx/knx_ip_connect_response.cpp
../../src/knx/knx_ip_connect_response.h
../../src/knx/knx_ip_disconnect_request.cpp
../../src/knx/knx_ip_disconnect_request.h
../../src/knx/knx_ip_disconnect_response.cpp
../../src/knx/knx_ip_disconnect_response.h
../../src/knx/knx_ip_state_request.cpp
../../src/knx/knx_ip_state_request.h
../../src/knx/knx_ip_state_response.cpp
../../src/knx/knx_ip_state_response.h
../../src/knx/knx_ip_description_request.cpp
../../src/knx/knx_ip_description_request.h
../../src/knx/knx_ip_description_response.cpp
../../src/knx/knx_ip_description_response.h
../../src/knx/knx_ip_config_request.cpp
../../src/knx/knx_ip_config_request.h
../../src/knx/knx_ip_tunneling_ack.cpp
../../src/knx/knx_ip_tunneling_ack.h
../../src/knx_facade.cpp
../../src/knx_facade.h
../../src/linux_platform.cpp
@ -141,7 +171,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -
add_executable(knx-linux-iptp ${SOURCES})
target_link_libraries(knx-linux-iptp "${LIBRARIES_FROM_REFERENCES}")
set_property(TARGET knx-linux-iptp PROPERTY CXX_STANDARD 11)
target_compile_definitions(knx-linux-iptp PUBLIC -DMASK_VERSION=0x091A)
target_compile_definitions(knx-linux-iptp PUBLIC -DMASK_VERSION=0x091A -DKNX_TUNNELING)
add_executable(knx-linux-tprf ${SOURCES})
target_link_libraries(knx-linux-tprf "${LIBRARIES_FROM_REFERENCES}")

View File

@ -10,7 +10,7 @@ using namespace std;
Bau07B0::Bau07B0(Platform& platform)
: BauSystemBDevice(platform), DataLinkLayerCallbacks(),
_dlLayer(_deviceObj, _netLayer.getInterface(), _platform, *this, (ITpUartCallBacks&) * this, (DataLinkLayerCallbacks*) this)
_dlLayer(_deviceObj, _netLayer.getInterface(), _platform, (ITpUartCallBacks&) * this, (DataLinkLayerCallbacks*) this)
#ifdef USE_CEMI_SERVER
, _cemiServer(*this)
#endif

View File

@ -17,8 +17,8 @@ Bau091A::Bau091A(Platform& platform)
: BauSystemBCoupler(platform), DataLinkLayerCallbacks(),
_routerObj(memory(), 0x200, 0x2000), // the Filtertable of 0x091A IP Routers is fixed at 0x200 and 0x2000 long
_ipParameters(_deviceObj, platform),
_dlLayerPrimary(_deviceObj, _ipParameters, _netLayer.getPrimaryInterface(), _platform, *this, (DataLinkLayerCallbacks*) this),
_dlLayerSecondary(_deviceObj, _netLayer.getSecondaryInterface(), platform, *this, (ITpUartCallBacks&) * this, (DataLinkLayerCallbacks*) this)
_dlLayerPrimary(_deviceObj, _ipParameters, _netLayer.getPrimaryInterface(), _platform, (DataLinkLayerCallbacks*) this),
_dlLayerSecondary(_deviceObj, _netLayer.getSecondaryInterface(), platform, (ITpUartCallBacks&) * this, (DataLinkLayerCallbacks*) this)
#ifdef USE_CEMI_SERVER
, _cemiServer(*this)
#endif

View File

@ -10,7 +10,7 @@ using namespace std;
Bau27B0::Bau27B0(Platform& platform)
: BauSystemBDevice(platform),
_dlLayer(_deviceObj, _rfMediumObj, _netLayer.getInterface(), _platform, *this)
_dlLayer(_deviceObj, _rfMediumObj, _netLayer.getInterface(), _platform)
#ifdef USE_CEMI_SERVER
, _cemiServer(*this)
#endif

View File

@ -14,8 +14,8 @@ Bau2920::Bau2920(Platform& platform)
_rtObjPrimary(memory()),
_rtObjSecondary(memory()),
_rfMediumObject(),
_dlLayerPrimary(_deviceObj, _netLayer.getPrimaryInterface(), _platform, *this, (ITpUartCallBacks&) * this),
_dlLayerSecondary(_deviceObj, _rfMediumObject, _netLayer.getSecondaryInterface(), platform, *this)
_dlLayerPrimary(_deviceObj, _netLayer.getPrimaryInterface(), _platform, (ITpUartCallBacks&) * this),
_dlLayerSecondary(_deviceObj, _rfMediumObject, _netLayer.getSecondaryInterface(), platform)
#ifdef USE_CEMI_SERVER
,
_cemiServer(*this)

View File

@ -11,7 +11,7 @@ using namespace std;
Bau57B0::Bau57B0(Platform& platform)
: BauSystemBDevice(platform), DataLinkLayerCallbacks(),
_ipParameters(_deviceObj, platform),
_dlLayer(_deviceObj, _ipParameters, _netLayer.getInterface(), _platform, *this, (DataLinkLayerCallbacks*) this)
_dlLayer(_deviceObj, _ipParameters, _netLayer.getInterface(), _platform, (DataLinkLayerCallbacks*) this)
#ifdef USE_CEMI_SERVER
, _cemiServer(*this)
#endif

View File

@ -18,8 +18,8 @@ void DataLinkLayerCallbacks::setActivityCallback(ActivityCallback activityCallba
_activityCallback = activityCallback;
}
DataLinkLayer::DataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity, Platform& platform, BusAccessUnit& busAccessUnit) :
_deviceObject(devObj), _networkLayerEntity(netLayerEntity), _platform(platform), _bau(busAccessUnit)
DataLinkLayer::DataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity, Platform& platform) :
_deviceObject(devObj), _networkLayerEntity(netLayerEntity), _platform(platform)
{
#ifdef KNX_ACTIVITYCALLBACK
_netIndex = netLayerEntity.getEntityIndex();
@ -281,39 +281,15 @@ uint8_t* DataLinkLayer::frameData(CemiFrame& frame)
#ifdef KNX_TUNNELING
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 numAddresses = 0;
uint16_t* addresses = _ipParameters->additionalIndivualAddresses(numAddresses);
//printHex("isTunnelingPA, PID_ADDITIONAL_INDIVIDUAL_ADDRESSES: ", *data, len);
if (len != KNX_TUNNELING * 2)
for (uint8_t i = 0; i < numAddresses; i++)
{
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);
if (pa == tunnelpa)
{
if (data != nullptr)
delete[] data;
if (pa == addresses[i])
return true;
}
}
if (data != nullptr)
delete[] data;
return false;
}

View File

@ -6,6 +6,9 @@
#include "device_object.h"
#include "knx_types.h"
#include "network_layer_entity.h"
#ifdef KNX_TUNNELING
#include "ip_parameter_object.h"
#endif
#include "cemi_server.h"
#include "bau.h"
@ -27,7 +30,7 @@ class DataLinkLayer
{
public:
DataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity,
Platform& platform, BusAccessUnit& busAccessUnit);
Platform& platform);
#ifdef USE_CEMI_SERVER
// from tunnel
@ -38,6 +41,7 @@ class DataLinkLayer
virtual void dataConfirmationToTunnel(CemiFrame& frame);
virtual void dataIndicationToTunnel(CemiFrame& frame);
virtual bool isTunnelAddress(uint16_t addr);
void ipParameterObject(IpParameterObject* object);
#endif
#endif
@ -59,7 +63,6 @@ class DataLinkLayer
DeviceObject& _deviceObject;
NetworkLayerEntity& _networkLayerEntity;
Platform& _platform;
BusAccessUnit& _bau;
#ifdef USE_CEMI_SERVER
CemiServer* _cemiServer;
#endif
@ -69,5 +72,6 @@ class DataLinkLayer
#ifdef KNX_TUNNELING
bool isTunnelingPA(uint16_t pa);
bool isRoutedPA(uint16_t pa);
IpParameterObject* _ipParameters;
#endif
};

View File

@ -35,7 +35,7 @@
#define MIN_LEN_CEMI 10
IpDataLinkLayer::IpDataLinkLayer(DeviceObject& devObj, IpParameterObject& ipParam,
NetworkLayerEntity& netLayerEntity, Platform& platform, BusAccessUnit& busAccessUnit, DataLinkLayerCallbacks* dllcb) : DataLinkLayer(devObj, netLayerEntity, platform, busAccessUnit), _ipParameters(ipParam), _dllcb(dllcb)
NetworkLayerEntity& netLayerEntity, Platform& platform, DataLinkLayerCallbacks* dllcb) : DataLinkLayer(devObj, netLayerEntity, platform), _ipParameters(ipParam), _dllcb(dllcb)
{
}
@ -704,8 +704,8 @@ void IpDataLinkLayer::loopHandleConnectRequest(uint8_t* buffer, uint16_t length,
int firstFreeTunnel = -1;
int firstResAndFreeTunnel = -1;
int firstResAndOccTunnel = -1;
bool tunnelResActive[KNX_TUNNELING];
uint8_t tunnelResOptions[KNX_TUNNELING];
bool tunnelResActive[KNX_TUNNELING] = {0};
uint8_t tunnelResOptions[KNX_TUNNELING] = {0};
for (int i = 0; i < KNX_TUNNELING; i++)
{

View File

@ -15,7 +15,7 @@ class IpDataLinkLayer : public DataLinkLayer
public:
IpDataLinkLayer(DeviceObject& devObj, IpParameterObject& ipParam, NetworkLayerEntity& netLayerEntity,
Platform& platform, BusAccessUnit& busAccessUnit, DataLinkLayerCallbacks* dllcb = nullptr);
Platform& platform, DataLinkLayerCallbacks* dllcb = nullptr);
void loop();
void enabled(bool value);
@ -49,7 +49,6 @@ class IpDataLinkLayer : public DataLinkLayer
#endif
bool sendBytes(uint8_t* buffer, uint16_t length);
bool isSendLimitReached();
IpParameterObject& _ipParameters;
DataLinkLayerCallbacks* _dllcb;
#ifdef KNX_TUNNELING

View File

@ -130,4 +130,14 @@ IpParameterObject::IpParameterObject(DeviceObject& deviceObject, Platform& platf
initializeProperties(sizeof(properties), properties);
}
uint16_t* IpParameterObject::additionalIndivualAddresses(uint8_t& numAddresses)
{
#ifdef KNX_TUNNELING
numAddresses = KNX_TUNNELING;
#else
numAddresses = 0;
#endif
return (uint16_t*) propertyData(PID_ADDITIONAL_INDIVIDUAL_ADDRESSES);
}
#endif

View File

@ -12,7 +12,7 @@ class IpParameterObject : public InterfaceObject
{
public:
IpParameterObject(DeviceObject& deviceObject, Platform& platform);
uint16_t* additionalIndivualAddresses(uint8_t& numAddresses);
private:
DeviceObject& _deviceObject;
Platform& _platform;

View File

@ -1,15 +1,15 @@
#include "knx_ip_config_request.h"
#ifdef USE_IP
KnxIpConfigRequest::KnxIpConfigRequest(uint8_t* data, uint16_t length)
: KnxIpFrame(data, length), _ch(data + LEN_KNXIP_HEADER), _frame(data + LEN_KNXIP_HEADER + LEN_CH, length - LEN_KNXIP_HEADER - LEN_CH)
: KnxIpFrame(data, length), _frame(data + LEN_KNXIP_HEADER + LEN_CH, length - LEN_KNXIP_HEADER - LEN_CH), _ch(data + LEN_KNXIP_HEADER)
{
}
CemiFrame& KnxIpConfigRequest::frame()
{
return _frame;
}
KnxIpCH& KnxIpConfigRequest::connectionHeader()
{
return _ch;

View File

@ -3,12 +3,12 @@
#ifdef USE_IP
KnxIpTunnelingRequest::KnxIpTunnelingRequest(uint8_t* data,
uint16_t length) : KnxIpFrame(data, length), _ch(_data + headerLength()), _frame(data + LEN_CH + headerLength(), length - LEN_CH - headerLength())
uint16_t length) : KnxIpFrame(data, length), _frame(data + LEN_CH + headerLength(), length - LEN_CH - headerLength()), _ch(_data + headerLength())
{
}
KnxIpTunnelingRequest::KnxIpTunnelingRequest(CemiFrame frame)
: KnxIpFrame(frame.totalLenght() + LEN_CH + LEN_KNXIP_HEADER), _ch(_data + LEN_KNXIP_HEADER), _frame(_data + LEN_CH + LEN_KNXIP_HEADER, frame.totalLenght())
: KnxIpFrame(frame.totalLenght() + LEN_CH + LEN_KNXIP_HEADER), _frame(_data + LEN_CH + LEN_KNXIP_HEADER, frame.totalLenght()), _ch(_data + LEN_KNXIP_HEADER)
{
serviceTypeIdentifier(TunnelingRequest);
memcpy(_data + LEN_KNXIP_HEADER + LEN_CH, frame.data(), frame.totalLenght());

View File

@ -78,8 +78,8 @@ bool RfDataLinkLayer::sendFrame(CemiFrame& frame)
}
RfDataLinkLayer::RfDataLinkLayer(DeviceObject& devObj, RfMediumObject& rfMediumObj,
NetworkLayerEntity& netLayerEntity, Platform& platform, BusAccessUnit& busAccessUnit)
: DataLinkLayer(devObj, netLayerEntity, platform, busAccessUnit),
NetworkLayerEntity& netLayerEntity, Platform& platform)
: DataLinkLayer(devObj, netLayerEntity, platform),
_rfMediumObj(rfMediumObj),
_rfPhy(*this, platform)
{

View File

@ -22,7 +22,7 @@ class RfDataLinkLayer : public DataLinkLayer
public:
RfDataLinkLayer(DeviceObject& devObj, RfMediumObject& rfMediumObj, NetworkLayerEntity& netLayerEntity,
Platform& platform, BusAccessUnit& busAccessUnit);
Platform& platform);
void loop();
void enabled(bool value);

View File

@ -1039,10 +1039,9 @@ bool TpUartDataLinkLayer::processTxFrameBytes()
TpUartDataLinkLayer::TpUartDataLinkLayer(DeviceObject& devObj,
NetworkLayerEntity& netLayerEntity,
Platform& platform,
BusAccessUnit& busAccessUnit,
ITpUartCallBacks& cb,
DataLinkLayerCallbacks* dllcb)
: DataLinkLayer(devObj, netLayerEntity, platform, busAccessUnit),
: DataLinkLayer(devObj, netLayerEntity, platform),
_cb(cb),
_dllcb(dllcb)
{

View File

@ -39,7 +39,7 @@ class TpUartDataLinkLayer : public DataLinkLayer
public:
TpUartDataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity,
Platform& platform, BusAccessUnit& busAccessUnit, ITpUartCallBacks& cb, DataLinkLayerCallbacks* dllcb = nullptr);
Platform& platform, ITpUartCallBacks& cb, DataLinkLayerCallbacks* dllcb = nullptr);
void loop();
void enabled(bool value);