diff --git a/src/knx/bau07B0.cpp b/src/knx/bau07B0.cpp index ce4f056..f6cd0ce 100644 --- a/src/knx/bau07B0.cpp +++ b/src/knx/bau07B0.cpp @@ -108,14 +108,20 @@ InterfaceObject* Bau07B0::getInterfaceObject(ObjectType objectType, uint8_t obje } } -DataLinkLayer& Bau07B0::dataLinkLayer() +bool Bau07B0::enabled() { - return _dlLayer; + return _dlLayer.enabled(); +} + +void Bau07B0::enabled(bool value) +{ + _dlLayer.enabled(value); } void Bau07B0::loop() { - ::BauSystemB::loop(); + _dlLayer.loop(); + BauSystemBDevice::loop(); #ifdef USE_CEMI_SERVER _cemiServer.loop(); #endif diff --git a/src/knx/bau07B0.h b/src/knx/bau07B0.h index 3e10955..79c7734 100644 --- a/src/knx/bau07B0.h +++ b/src/knx/bau07B0.h @@ -12,12 +12,13 @@ class Bau07B0 : public BauSystemBDevice { public: Bau07B0(Platform& platform); - void loop(); + virtual void loop() override; + virtual bool enabled() override; + virtual void enabled(bool value) override; protected: InterfaceObject* getInterfaceObject(uint8_t idx); InterfaceObject* getInterfaceObject(ObjectType objectType, uint8_t objectInstance); - DataLinkLayer& dataLinkLayer(); private: TpUartDataLinkLayer _dlLayer; diff --git a/src/knx/bau091A.cpp b/src/knx/bau091A.cpp index c958bc6..8c70f1e 100644 --- a/src/knx/bau091A.cpp +++ b/src/knx/bau091A.cpp @@ -108,14 +108,27 @@ InterfaceObject* Bau091A::getInterfaceObject(ObjectType objectType, uint8_t obje void Bau091A::doMasterReset(EraseCode eraseCode, uint8_t channel) { // Common SystemB objects - BauSystemB::doMasterReset(eraseCode, channel); + BauSystemBCoupler::doMasterReset(eraseCode, channel); _ipParameters.masterReset(eraseCode, channel); } -DataLinkLayer& Bau091A::dataLinkLayer() +bool Bau091A::enabled() { - return _dlLayerSecondary; + return _dlLayerPrimary.enabled() && _dlLayerSecondary.enabled(); +} + +void Bau091A::enabled(bool value) +{ + _dlLayerPrimary.enabled(value); + _dlLayerSecondary.enabled(value); +} + +void Bau091A::loop() +{ + _dlLayerPrimary.loop(); + _dlLayerSecondary.loop(); + BauSystemBCoupler::loop(); } #endif diff --git a/src/knx/bau091A.h b/src/knx/bau091A.h index 0d1c687..846f0a3 100644 --- a/src/knx/bau091A.h +++ b/src/knx/bau091A.h @@ -12,11 +12,13 @@ class Bau091A : public BauSystemBCoupler { public: Bau091A(Platform& platform); + virtual void loop() override; + virtual bool enabled() override; + virtual void enabled(bool value) override; protected: InterfaceObject* getInterfaceObject(uint8_t idx); InterfaceObject* getInterfaceObject(ObjectType objectType, uint8_t objectInstance); - DataLinkLayer& dataLinkLayer(); virtual void doMasterReset(EraseCode eraseCode, uint8_t channel) override; private: diff --git a/src/knx/bau27B0.cpp b/src/knx/bau27B0.cpp index 5def14b..46a76b7 100644 --- a/src/knx/bau27B0.cpp +++ b/src/knx/bau27B0.cpp @@ -128,14 +128,20 @@ void Bau27B0::doMasterReset(EraseCode eraseCode, uint8_t channel) _rfMediumObj.masterReset(eraseCode, channel); } -DataLinkLayer& Bau27B0::dataLinkLayer() +bool Bau27B0::enabled() { - return _dlLayer; + return _dlLayer.enabled(); +} + +void Bau27B0::enabled(bool value) +{ + _dlLayer.enabled(value); } void Bau27B0::loop() { - ::BauSystemB::loop(); + _dlLayer.loop(); + BauSystemBDevice::loop(); #ifdef USE_CEMI_SERVER _cemiServer.loop(); #endif diff --git a/src/knx/bau27B0.h b/src/knx/bau27B0.h index 036d207..80e7cf4 100644 --- a/src/knx/bau27B0.h +++ b/src/knx/bau27B0.h @@ -13,12 +13,13 @@ class Bau27B0 : public BauSystemBDevice { public: Bau27B0(Platform& platform); - void loop(); + virtual void loop() override; + virtual bool enabled() override; + virtual void enabled(bool value) override; protected: InterfaceObject* getInterfaceObject(uint8_t idx); InterfaceObject* getInterfaceObject(ObjectType objectType, uint8_t objectInstance); - DataLinkLayer& dataLinkLayer(); virtual void doMasterReset(EraseCode eraseCode, uint8_t channel) override; private: diff --git a/src/knx/bau57B0.cpp b/src/knx/bau57B0.cpp index eb37ef0..485a23a 100644 --- a/src/knx/bau57B0.cpp +++ b/src/knx/bau57B0.cpp @@ -124,9 +124,23 @@ void Bau57B0::doMasterReset(EraseCode eraseCode, uint8_t channel) _ipParameters.masterReset(eraseCode, channel); } -DataLinkLayer& Bau57B0::dataLinkLayer() +bool Bau57B0::enabled() { - return _dlLayer; + return _dlLayer.enabled(); +} + +void Bau57B0::enabled(bool value) +{ + _dlLayer.enabled(value); +} + +void Bau57B0::loop() +{ + _dlLayer.loop(); + BauSystemBDevice::loop(); +#ifdef USE_CEMI_SERVER + _cemiServer.loop(); +#endif } #endif diff --git a/src/knx/bau57B0.h b/src/knx/bau57B0.h index 1066ab7..685526a 100644 --- a/src/knx/bau57B0.h +++ b/src/knx/bau57B0.h @@ -11,11 +11,13 @@ class Bau57B0 : public BauSystemBDevice { public: Bau57B0(Platform& platform); + virtual void loop() override; + virtual bool enabled() override; + virtual void enabled(bool value) override; protected: InterfaceObject* getInterfaceObject(uint8_t idx); InterfaceObject* getInterfaceObject(ObjectType objectType, uint8_t objectInstance); - DataLinkLayer& dataLinkLayer(); virtual void doMasterReset(EraseCode eraseCode, uint8_t channel) override; private: diff --git a/src/knx/bau_systemB.cpp b/src/knx/bau_systemB.cpp index cedccdc..c3779d0 100644 --- a/src/knx/bau_systemB.cpp +++ b/src/knx/bau_systemB.cpp @@ -21,22 +21,6 @@ BauSystemB::BauSystemB(Platform& platform): _memory(platform, _deviceObj), _memory.addSaveRestore(&_appProgram); } -void BauSystemB::loop() -{ - dataLinkLayer().loop(); - nextRestartState(); -} - -bool BauSystemB::enabled() -{ - return dataLinkLayer().enabled(); -} - -void BauSystemB::enabled(bool value) -{ - dataLinkLayer().enabled(value); -} - void BauSystemB::readMemory() { _memory.readMemory(); @@ -166,6 +150,7 @@ void BauSystemB::memoryExtReadIndication(Priority priority, HopCountType hopType void BauSystemB::doMasterReset(EraseCode eraseCode, uint8_t channel) { + _deviceObj.masterReset(eraseCode, channel); _appProgram.masterReset(eraseCode, channel); } diff --git a/src/knx/bau_systemB.h b/src/knx/bau_systemB.h index 7ae6318..4f63638 100644 --- a/src/knx/bau_systemB.h +++ b/src/knx/bau_systemB.h @@ -16,13 +16,13 @@ class BauSystemB : protected BusAccessUnit { public: BauSystemB(Platform& platform); - virtual void loop(); + virtual void loop() = 0; ApplicationProgramObject& parameters(); DeviceObject& deviceObject(); Memory& memory(); bool configured(); - bool enabled(); - void enabled(bool value); + virtual bool enabled() = 0; + virtual void enabled(bool value) = 0; void readMemory(); void writeMemory(); void addSaveRestore(SaveRestore* obj); @@ -37,7 +37,6 @@ class BauSystemB : protected BusAccessUnit uint8_t* data, uint32_t length) override; protected: - virtual DataLinkLayer& dataLinkLayer() = 0; virtual ApplicationLayer& applicationLayer() = 0; void memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint8_t number, diff --git a/src/knx/bau_systemB_coupler.cpp b/src/knx/bau_systemB_coupler.cpp index 0f7c1b5..ac634c2 100644 --- a/src/knx/bau_systemB_coupler.cpp +++ b/src/knx/bau_systemB_coupler.cpp @@ -13,9 +13,6 @@ BauSystemBCoupler::BauSystemBCoupler(Platform& platform) : #endif _transLayer(_appLayer), _netLayer(_deviceObj, _transLayer) { -#ifdef USE_DATASECURE - _secIfObj.secureApplicationLayer(_appLayer); -#endif _appLayer.transportLayer(_transLayer); _transLayer.networkLayer(_netLayer); _memory.addSaveRestore(&_deviceObj); @@ -33,7 +30,6 @@ ApplicationLayer& BauSystemBCoupler::applicationLayer() void BauSystemBCoupler::loop() { - dataLinkLayer().loop(); _transLayer.loop(); #ifdef USE_DATASECURE _appLayer.loop(); @@ -54,4 +50,5 @@ bool BauSystemBCoupler::configured() void BauSystemBCoupler::doMasterReset(EraseCode eraseCode, uint8_t channel) { + BauSystemB::doMasterReset(eraseCode, channel); } diff --git a/src/knx/bau_systemB_coupler.h b/src/knx/bau_systemB_coupler.h index e7b66dd..4353f3d 100644 --- a/src/knx/bau_systemB_coupler.h +++ b/src/knx/bau_systemB_coupler.h @@ -24,10 +24,9 @@ class BauSystemBCoupler : public BauSystemB bool configured(); protected: - virtual DataLinkLayer& dataLinkLayer() = 0; virtual ApplicationLayer& applicationLayer() override; - virtual void doMasterReset(EraseCode eraseCode, uint8_t channel); + virtual void doMasterReset(EraseCode eraseCode, uint8_t channel) override; enum RestartState { diff --git a/src/knx/bau_systemB_device.cpp b/src/knx/bau_systemB_device.cpp index 8f7a574..49fb8b7 100644 --- a/src/knx/bau_systemB_device.cpp +++ b/src/knx/bau_systemB_device.cpp @@ -14,9 +14,6 @@ BauSystemBDevice::BauSystemBDevice(Platform& platform) : #endif _transLayer(_appLayer), _netLayer(_deviceObj, _transLayer) { -#ifdef USE_DATASECURE - _secIfObj.secureApplicationLayer(_appLayer); -#endif _appLayer.transportLayer(_transLayer); _appLayer.associationTableObject(_assocTable); _appLayer.groupAddressTable(_addrTable); @@ -39,7 +36,6 @@ ApplicationLayer& BauSystemBDevice::applicationLayer() void BauSystemBDevice::loop() { - dataLinkLayer().loop(); _transLayer.loop(); sendNextGroupTelegram(); nextRestartState(); @@ -138,10 +134,11 @@ bool BauSystemBDevice::configured() void BauSystemBDevice::doMasterReset(EraseCode eraseCode, uint8_t channel) { + BauSystemB::doMasterReset(eraseCode, channel); + _addrTable.masterReset(eraseCode, channel); _assocTable.masterReset(eraseCode, channel); _groupObjTable.masterReset(eraseCode, channel); - _appProgram.masterReset(eraseCode, channel); #ifdef USE_DATASECURE // If erase code is FactoryReset or FactoryResetWithoutIA, set FDSK as toolkey again // and disable security mode. diff --git a/src/knx/bau_systemB_device.h b/src/knx/bau_systemB_device.h index 29daac6..08ecbbe 100644 --- a/src/knx/bau_systemB_device.h +++ b/src/knx/bau_systemB_device.h @@ -22,7 +22,6 @@ class BauSystemBDevice : public BauSystemB BauSystemBDevice(Platform& platform); virtual void loop(); GroupObjectTableObject& groupObjectTable(); - Memory& memory(); bool configured(); protected: @@ -40,7 +39,7 @@ class BauSystemBDevice : public BauSystemB void sendNextGroupTelegram(); void updateGroupObject(GroupObject& go, uint8_t* data, uint8_t length); - virtual void doMasterReset(EraseCode eraseCode, uint8_t channel); + virtual void doMasterReset(EraseCode eraseCode, uint8_t channel) override; AddressTableObject _addrTable; AssociationTableObject _assocTable; diff --git a/src/knx/secure_application_layer.cpp b/src/knx/secure_application_layer.cpp index ff4901f..69bad03 100644 --- a/src/knx/secure_application_layer.cpp +++ b/src/knx/secure_application_layer.cpp @@ -1251,24 +1251,6 @@ bool SecureApplicationLayer::createSecureApdu(APDU& plainApdu, APDU& secureApdu, return false; } -void SecureApplicationLayer::clearFailureLog() -{ - println("clearFailureLog()"); -} - -void SecureApplicationLayer::getFailureCounters(uint8_t* data) -{ - memset(data, 0, 8); - println("getFailureCounters()"); -} - -uint8_t SecureApplicationLayer::getFromFailureLogByIndex(uint8_t index, uint8_t* data, uint8_t maxDataLen) -{ - print("getFromFailureLogByIndex(): Index: "); - println(index); - return 0; -} - uint64_t SecureApplicationLayer::getRandomNumber() { return 0x000102030405; // TODO: generate random number diff --git a/src/knx/secure_application_layer.h b/src/knx/secure_application_layer.h index 0df8f2c..39b5fc5 100644 --- a/src/knx/secure_application_layer.h +++ b/src/knx/secure_application_layer.h @@ -32,10 +32,6 @@ class SecureApplicationLayer : public ApplicationLayer void groupAddressTable(AddressTableObject& addrTable); - void clearFailureLog(); - void getFailureCounters(uint8_t* data); - uint8_t getFromFailureLogByIndex(uint8_t index, uint8_t* data, uint8_t maxDataLen); - // from transport layer virtual void dataGroupIndication(HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu) override; virtual void dataGroupConfirm(AckType ack, HopCountType hopType, Priority priority, uint16_t tsap, diff --git a/src/knx/security_interface_object.cpp b/src/knx/security_interface_object.cpp index 92b67c4..7b07a6d 100644 --- a/src/knx/security_interface_object.cpp +++ b/src/knx/security_interface_object.cpp @@ -97,7 +97,7 @@ SecurityInterfaceObject::SecurityInterfaceObject() uint8_t info = data[2]; if (id == 0 && info == 0) { - obj->_secAppLayer->clearFailureLog(); + obj->clearFailureLog(); resultData[0] = ReturnCodes::Success; resultData[1] = id; resultLength = 2; @@ -123,7 +123,7 @@ SecurityInterfaceObject::SecurityInterfaceObject() resultData[0] = ReturnCodes::Success; resultData[1] = id; resultData[2] = info; - obj->_secAppLayer->getFailureCounters(&resultData[3]); // Put 8 bytes in the buffer + obj->getFailureCounters(&resultData[3]); // Put 8 bytes in the buffer resultLength = 3 + 8; return; } @@ -132,7 +132,7 @@ SecurityInterfaceObject::SecurityInterfaceObject() { uint8_t maxBufferSize = resultLength; // Remember the maximum buffer size of the buffer that is provided to us uint8_t index = info; - uint8_t numBytes = obj->_secAppLayer->getFromFailureLogByIndex(index, &resultData[2], maxBufferSize); + uint8_t numBytes = obj->getFromFailureLogByIndex(index, &resultData[2], maxBufferSize); if ( numBytes > 0) { resultData[0] = ReturnCodes::Success; @@ -163,11 +163,6 @@ SecurityInterfaceObject::SecurityInterfaceObject() initializeProperties(sizeof(properties), properties); } -void SecurityInterfaceObject::secureApplicationLayer(SecureApplicationLayer& secAppLayer) -{ - _secAppLayer = &secAppLayer; -} - uint8_t* SecurityInterfaceObject::save(uint8_t* buffer) { buffer = pushByte(_state, buffer); @@ -206,6 +201,24 @@ bool SecurityInterfaceObject::isSecurityModeEnabled() return _securityModeEnabled; } +void SecurityInterfaceObject::clearFailureLog() +{ + println("clearFailureLog()"); +} + +void SecurityInterfaceObject::getFailureCounters(uint8_t* data) +{ + memset(data, 0, 8); + println("getFailureCounters()"); +} + +uint8_t SecurityInterfaceObject::getFromFailureLogByIndex(uint8_t index, uint8_t* data, uint8_t maxDataLen) +{ + print("getFromFailureLogByIndex(): Index: "); + println(index); + return 0; +} + bool SecurityInterfaceObject::isLoaded() { return _state == LS_LOADED; diff --git a/src/knx/security_interface_object.h b/src/knx/security_interface_object.h index 754f2ea..53f5314 100644 --- a/src/knx/security_interface_object.h +++ b/src/knx/security_interface_object.h @@ -6,15 +6,11 @@ #include "interface_object.h" #include "knx_types.h" -class SecureApplicationLayer; - class SecurityInterfaceObject: public InterfaceObject { public: SecurityInterfaceObject(); - void secureApplicationLayer(SecureApplicationLayer& secAppLayer); - virtual void masterReset(EraseCode eraseCode, uint8_t channel) override; bool isSecurityModeEnabled(); @@ -39,10 +35,12 @@ public: uint16_t saveSize() override; private: - SecureApplicationLayer* _secAppLayer = nullptr; - void setSecurityMode(bool enabled); + void clearFailureLog(); + void getFailureCounters(uint8_t* data); + uint8_t getFromFailureLogByIndex(uint8_t index, uint8_t* data, uint8_t maxDataLen); + void errorCode(ErrorCode errorCode); void loadEvent(const uint8_t* data);