mirror of
https://github.com/thelsing/knx.git
synced 2025-07-21 13:46:17 +02:00
More logging
This commit is contained in:
parent
59a76b7c3f
commit
8c3af52892
@ -40,7 +40,7 @@ uint8_t APDU::length() const
|
|||||||
return _frame.npdu().octetCount();
|
return _frame.npdu().octetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
string APDU::to_string() const
|
string APDU::toString() const
|
||||||
{
|
{
|
||||||
string value = "APDU: " + enum_name(type()) + " ";
|
string value = "APDU: " + enum_name(type()) + " ";
|
||||||
value += byte2hex(_data[0] & 0x3);
|
value += byte2hex(_data[0] & 0x3);
|
||||||
|
@ -37,7 +37,7 @@ class APDU
|
|||||||
/**
|
/**
|
||||||
* Convert APDU to string.
|
* Convert APDU to string.
|
||||||
*/
|
*/
|
||||||
std::string to_string() const;
|
std::string toString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
@ -10,7 +10,10 @@
|
|||||||
#include "util/logger.h"
|
#include "util/logger.h"
|
||||||
#define LOGGER Logger::logger("ApplicationLayer")
|
#define LOGGER Logger::logger("ApplicationLayer")
|
||||||
|
|
||||||
const SecurityControl ApplicationLayer::noSecurity {.toolAccess = false, .dataSecurity = DataSecurity::None};
|
const SecurityControl ApplicationLayer::noSecurity
|
||||||
|
{
|
||||||
|
.toolAccess = false, .dataSecurity = DataSecurity::None
|
||||||
|
};
|
||||||
|
|
||||||
ApplicationLayer::ApplicationLayer(BusAccessUnit& bau) : _bau(bau)
|
ApplicationLayer::ApplicationLayer(BusAccessUnit& bau) : _bau(bau)
|
||||||
{
|
{
|
||||||
@ -35,6 +38,8 @@ void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priori
|
|||||||
|
|
||||||
void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl)
|
void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataGroupIndication %S", apdu.toString());
|
||||||
|
|
||||||
if (_assocTable == nullptr)
|
if (_assocTable == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -86,6 +91,7 @@ void ApplicationLayer::dataGroupConfirm(AckType ack, HopCountType hopType, Prior
|
|||||||
|
|
||||||
void ApplicationLayer::dataGroupConfirm(AckType ack, HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl, bool status)
|
void ApplicationLayer::dataGroupConfirm(AckType ack, HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl, bool status)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataGroupConfirm %S", apdu.toString());
|
||||||
switch (apdu.type())
|
switch (apdu.type())
|
||||||
{
|
{
|
||||||
case GroupValueRead:
|
case GroupValueRead:
|
||||||
@ -122,6 +128,7 @@ void ApplicationLayer::dataBroadcastIndication(HopCountType hopType, Priority pr
|
|||||||
|
|
||||||
void ApplicationLayer::dataBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, APDU& apdu, const SecurityControl& secCtrl)
|
void ApplicationLayer::dataBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, APDU& apdu, const SecurityControl& secCtrl)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataBroadcastIndication %S", apdu.toString());
|
||||||
uint8_t* data = apdu.data();
|
uint8_t* data = apdu.data();
|
||||||
|
|
||||||
switch (apdu.type())
|
switch (apdu.type())
|
||||||
@ -181,6 +188,7 @@ void ApplicationLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, P
|
|||||||
|
|
||||||
void ApplicationLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, Priority priority, APDU& apdu, const SecurityControl& secCtrl, bool status)
|
void ApplicationLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, Priority priority, APDU& apdu, const SecurityControl& secCtrl, bool status)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataBroadcastConfirm %S", apdu.toString());
|
||||||
uint8_t* data = apdu.data();
|
uint8_t* data = apdu.data();
|
||||||
|
|
||||||
switch (apdu.type())
|
switch (apdu.type())
|
||||||
@ -235,6 +243,7 @@ void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Prior
|
|||||||
|
|
||||||
void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, APDU& apdu, const SecurityControl& secCtrl)
|
void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, APDU& apdu, const SecurityControl& secCtrl)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataSystemBroadcastIndication %S", apdu.toString());
|
||||||
const uint8_t* data = apdu.data();
|
const uint8_t* data = apdu.data();
|
||||||
|
|
||||||
switch (apdu.type())
|
switch (apdu.type())
|
||||||
@ -271,8 +280,7 @@ void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Prior
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
print("SystemBroadcast-indication: unhandled APDU-Type: ");
|
LOGGER.warning("SystemBroadcast-indication: unhandled APDU-Type: %d", apdu.type());
|
||||||
println(apdu.type());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,6 +292,7 @@ void ApplicationLayer::dataSystemBroadcastConfirm(HopCountType hopType, Priority
|
|||||||
|
|
||||||
void ApplicationLayer::dataSystemBroadcastConfirm(HopCountType hopType, Priority priority, APDU& apdu, const SecurityControl& secCtrl, bool status)
|
void ApplicationLayer::dataSystemBroadcastConfirm(HopCountType hopType, Priority priority, APDU& apdu, const SecurityControl& secCtrl, bool status)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataSystemBroadcastConfirm %S", apdu.toString());
|
||||||
const uint8_t* data = apdu.data();
|
const uint8_t* data = apdu.data();
|
||||||
|
|
||||||
switch (apdu.type())
|
switch (apdu.type())
|
||||||
@ -1362,7 +1371,7 @@ void ApplicationLayer::individualIndication(HopCountType hopType, Priority prior
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOGGER.warning("Individual-indication: unhandled APDU-Type: %s", apdu.to_string().c_str());
|
LOGGER.warning("Individual-indication: unhandled APDU-Type: %S", apdu.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,9 +400,9 @@ bool CemiFrame::valid() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CemiFrame::to_string() const
|
std::string CemiFrame::toString() const
|
||||||
{
|
{
|
||||||
std::string value = enum_name(frameType()) + " ";
|
std::string value = "DPDU:" + enum_name(frameType()) + " ";
|
||||||
value += enum_name(systemBroadcast()) + " ";
|
value += enum_name(systemBroadcast()) + " ";
|
||||||
value += enum_name(ack()) + " ";
|
value += enum_name(ack()) + " ";
|
||||||
value += enum_name(repetition()) + " ";
|
value += enum_name(repetition()) + " ";
|
||||||
|
@ -72,7 +72,7 @@ class CemiFrame
|
|||||||
uint8_t calcCrcTP(uint8_t* buffer, uint16_t len);
|
uint8_t calcCrcTP(uint8_t* buffer, uint16_t len);
|
||||||
bool valid() const;
|
bool valid() const;
|
||||||
|
|
||||||
std::string to_string() const;
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t buffer[0xff + NPDU_LPDU_DIFF] = {0}; //only valid of add info is zero
|
uint8_t buffer[0xff + NPDU_LPDU_DIFF] = {0}; //only valid of add info is zero
|
||||||
|
@ -161,7 +161,7 @@ void DataLinkLayer::frameReceived(CemiFrame& frame)
|
|||||||
SystemBroadcast systemBroadcast = frame.systemBroadcast();
|
SystemBroadcast systemBroadcast = frame.systemBroadcast();
|
||||||
|
|
||||||
|
|
||||||
LOGGER.info("frameReceived %s", frame.to_string().c_str());
|
LOGGER.info("frameReceived %S", frame.toString());
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_CEMI_SERVER
|
#ifdef USE_CEMI_SERVER
|
||||||
@ -222,7 +222,7 @@ bool DataLinkLayer::sendTelegram(NPDU& npdu, AckType ack, uint16_t destinationAd
|
|||||||
else
|
else
|
||||||
frame.frameType(format);
|
frame.frameType(format);
|
||||||
|
|
||||||
LOGGER.info("sendTelegram %s", frame.to_string().c_str());
|
LOGGER.info("sendTelegram %S", frame.toString());
|
||||||
|
|
||||||
if (!frame.valid())
|
if (!frame.valid())
|
||||||
{
|
{
|
||||||
|
@ -1137,7 +1137,7 @@ bool IpDataLinkLayer::sendMulicast(KnxIpFrame& ipFrame)
|
|||||||
if (!_enabled)
|
if (!_enabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LOGGER.info("sendMulicast %s", ipFrame.to_string().c_str());
|
LOGGER.info("sendMulicast %S", ipFrame.toString());
|
||||||
|
|
||||||
return _platform.sendBytesMultiCast(ipFrame.data(), ipFrame.totalLength());
|
return _platform.sendBytesMultiCast(ipFrame.data(), ipFrame.totalLength());
|
||||||
}
|
}
|
||||||
@ -1147,7 +1147,7 @@ bool IpDataLinkLayer::sendUnicast(uint32_t addr, uint16_t port, KnxIpFrame& ipFr
|
|||||||
if (!_enabled)
|
if (!_enabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LOGGER.info("sendUnicast to %s:%d %s", ipaddr2str(addr).c_str(), port, ipFrame.to_string().c_str());
|
LOGGER.info("sendUnicast to %S:%d %S", ipaddr2str(addr), port, ipFrame.toString());
|
||||||
|
|
||||||
return _platform.sendBytesMultiCast(ipFrame.data(), ipFrame.totalLength());
|
return _platform.sendBytesMultiCast(ipFrame.data(), ipFrame.totalLength());
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ KnxIpFrame::KnxIpFrame(uint16_t length)
|
|||||||
totalLength(length);
|
totalLength(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string KnxIpFrame::to_string() const
|
const std::string KnxIpFrame::toString() const
|
||||||
{
|
{
|
||||||
return enum_name(protocolVersion()) + " " + enum_name(serviceTypeIdentifier());
|
return enum_name(protocolVersion()) + " " + enum_name(serviceTypeIdentifier());
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class KnxIpFrame
|
|||||||
uint16_t totalLength() const;
|
uint16_t totalLength() const;
|
||||||
void totalLength(uint16_t length);
|
void totalLength(uint16_t length);
|
||||||
uint8_t* data();
|
uint8_t* data();
|
||||||
const std::string to_string() const;
|
const std::string toString() const;
|
||||||
protected:
|
protected:
|
||||||
bool _freeData = false;
|
bool _freeData = false;
|
||||||
uint8_t* _data = 0;
|
uint8_t* _data = 0;
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
#include "tpdu.h"
|
#include "tpdu.h"
|
||||||
#include "cemi_frame.h"
|
#include "cemi_frame.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "util/logger.h"
|
||||||
|
|
||||||
|
#define LOGGER Logger::logger("NetworkLayerDevice")
|
||||||
|
|
||||||
NetworkLayerDevice::NetworkLayerDevice(DeviceObject& deviceObj, TransportLayer& layer) :
|
NetworkLayerDevice::NetworkLayerDevice(DeviceObject& deviceObj, TransportLayer& layer) :
|
||||||
NetworkLayer(deviceObj, layer),
|
NetworkLayer(deviceObj, layer),
|
||||||
@ -29,6 +32,7 @@ void NetworkLayerDevice::dataIndividualRequest(AckType ack, uint16_t destination
|
|||||||
// print.print("-> NL ");
|
// print.print("-> NL ");
|
||||||
// tpdu.apdu().printPDU();
|
// tpdu.apdu().printPDU();
|
||||||
//}
|
//}
|
||||||
|
LOGGER.info("dataIndividualRequest %S", npdu.toString());
|
||||||
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, destination, _deviceObj.individualAddress(), priority, IndividualAddress, Broadcast);
|
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, destination, _deviceObj.individualAddress(), priority, IndividualAddress, Broadcast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +45,7 @@ void NetworkLayerDevice::dataGroupRequest(AckType ack, uint16_t destination, Hop
|
|||||||
else
|
else
|
||||||
npdu.hopCount(hopCount());
|
npdu.hopCount(hopCount());
|
||||||
|
|
||||||
|
LOGGER.info("dataGroupRequest %S", npdu.toString());
|
||||||
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, destination, _deviceObj.individualAddress(), priority, GroupAddress, Broadcast);
|
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, destination, _deviceObj.individualAddress(), priority, GroupAddress, Broadcast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +58,7 @@ void NetworkLayerDevice::dataBroadcastRequest(AckType ack, HopCountType hopType,
|
|||||||
else
|
else
|
||||||
npdu.hopCount(hopCount());
|
npdu.hopCount(hopCount());
|
||||||
|
|
||||||
|
LOGGER.info("dataBroadcastRequest %S", npdu.toString());
|
||||||
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, 0, _deviceObj.individualAddress(), priority, GroupAddress, Broadcast);
|
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, 0, _deviceObj.individualAddress(), priority, GroupAddress, Broadcast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,11 +75,13 @@ void NetworkLayerDevice::dataSystemBroadcastRequest(AckType ack, HopCountType ho
|
|||||||
else
|
else
|
||||||
npdu.hopCount(hopCount());
|
npdu.hopCount(hopCount());
|
||||||
|
|
||||||
|
LOGGER.info("dataSystemBroadcastRequest %S", npdu.toString());
|
||||||
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, 0, _deviceObj.individualAddress(), priority, GroupAddress, broadcastType);
|
_netLayerEntities[kInterfaceIndex].sendDataRequest(npdu, ack, 0, _deviceObj.individualAddress(), priority, GroupAddress, broadcastType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLayerDevice::dataIndication(AckType ack, AddressType addrType, uint16_t destination, FrameFormat format, NPDU& npdu, Priority priority, uint16_t source, uint8_t srcIfIdx)
|
void NetworkLayerDevice::dataIndication(AckType ack, AddressType addrType, uint16_t destination, FrameFormat format, NPDU& npdu, Priority priority, uint16_t source, uint8_t srcIfIdx)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataIndication %S", npdu.toString());
|
||||||
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
||||||
|
|
||||||
if (addrType == IndividualAddress)
|
if (addrType == IndividualAddress)
|
||||||
@ -95,6 +103,7 @@ void NetworkLayerDevice::dataIndication(AckType ack, AddressType addrType, uint1
|
|||||||
|
|
||||||
void NetworkLayerDevice::dataConfirm(AckType ack, AddressType addressType, uint16_t destination, FrameFormat format, Priority priority, uint16_t source, NPDU& npdu, bool status, uint8_t srcIfIdx)
|
void NetworkLayerDevice::dataConfirm(AckType ack, AddressType addressType, uint16_t destination, FrameFormat format, Priority priority, uint16_t source, NPDU& npdu, bool status, uint8_t srcIfIdx)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataConfirm %S", npdu.toString());
|
||||||
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
||||||
|
|
||||||
if (addressType == IndividualAddress)
|
if (addressType == IndividualAddress)
|
||||||
@ -113,6 +122,7 @@ void NetworkLayerDevice::dataConfirm(AckType ack, AddressType addressType, uint1
|
|||||||
|
|
||||||
void NetworkLayerDevice::broadcastIndication(AckType ack, FrameFormat format, NPDU& npdu, Priority priority, uint16_t source, uint8_t srcIfIdx)
|
void NetworkLayerDevice::broadcastIndication(AckType ack, FrameFormat format, NPDU& npdu, Priority priority, uint16_t source, uint8_t srcIfIdx)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("broadcastIndication %S", npdu.toString());
|
||||||
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
||||||
DptMedium mediumType = _netLayerEntities[srcIfIdx].mediumType();
|
DptMedium mediumType = _netLayerEntities[srcIfIdx].mediumType();
|
||||||
|
|
||||||
@ -133,18 +143,21 @@ void NetworkLayerDevice::broadcastIndication(AckType ack, FrameFormat format, NP
|
|||||||
|
|
||||||
void NetworkLayerDevice::broadcastConfirm(AckType ack, FrameFormat format, Priority priority, uint16_t source, NPDU& npdu, bool status, uint8_t srcIfIdx)
|
void NetworkLayerDevice::broadcastConfirm(AckType ack, FrameFormat format, Priority priority, uint16_t source, NPDU& npdu, bool status, uint8_t srcIfIdx)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("broadcastConfirm %S", npdu.toString());
|
||||||
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
||||||
_transportLayer.dataBroadcastConfirm(ack, hopType, priority, npdu.tpdu(), status);
|
_transportLayer.dataBroadcastConfirm(ack, hopType, priority, npdu.tpdu(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLayerDevice::systemBroadcastIndication(AckType ack, FrameFormat format, NPDU& npdu, Priority priority, uint16_t source, uint8_t srcIfIdx)
|
void NetworkLayerDevice::systemBroadcastIndication(AckType ack, FrameFormat format, NPDU& npdu, Priority priority, uint16_t source, uint8_t srcIfIdx)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("systemBroadcastIndication %S", npdu.toString());
|
||||||
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
||||||
_transportLayer.dataSystemBroadcastIndication(hopType, priority, source, npdu.tpdu());
|
_transportLayer.dataSystemBroadcastIndication(hopType, priority, source, npdu.tpdu());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLayerDevice::systemBroadcastConfirm(AckType ack, FrameFormat format, Priority priority, uint16_t source, NPDU& npdu, bool status, uint8_t srcIfIdx)
|
void NetworkLayerDevice::systemBroadcastConfirm(AckType ack, FrameFormat format, Priority priority, uint16_t source, NPDU& npdu, bool status, uint8_t srcIfIdx)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("systemBroadcastConfirm %S", npdu.toString());
|
||||||
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
HopCountType hopType = npdu.hopCount() == 7 ? UnlimitedRouting : NetworkLayerParameter;
|
||||||
_transportLayer.dataSystemBroadcastConfirm(ack, hopType, npdu.tpdu(), priority, status);
|
_transportLayer.dataSystemBroadcastConfirm(ack, hopType, npdu.tpdu(), priority, status);
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,8 @@ TPDU& NPDU::tpdu()
|
|||||||
{
|
{
|
||||||
return _frame.tpdu();
|
return _frame.tpdu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string NPDU::toString() const
|
||||||
|
{
|
||||||
|
return std::string("NPDU: Octetcount:") + to_string(octetCount()) + " hopCount " + to_string(hopCount());
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class CemiFrame;
|
class CemiFrame;
|
||||||
class TPDU;
|
class TPDU;
|
||||||
@ -17,6 +18,7 @@ class NPDU
|
|||||||
void hopCount(uint8_t value);
|
void hopCount(uint8_t value);
|
||||||
CemiFrame& frame();
|
CemiFrame& frame();
|
||||||
TPDU& tpdu();
|
TPDU& tpdu();
|
||||||
|
const std::string toString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NPDU(uint8_t* data, CemiFrame& frame);
|
NPDU(uint8_t* data, CemiFrame& frame);
|
||||||
|
@ -660,7 +660,7 @@ void SecureApplicationLayer::sendSyncRequest(uint16_t dstAddr, bool dstAddrIsGro
|
|||||||
|
|
||||||
if (secure(request.data() + APDU_LPDU_DIFF, kSecureSyncRequest, _deviceObj.individualAddress(), dstAddr, dstAddrIsGroupAddr, tpci, asdu, sizeof(asdu), secCtrl, systemBcast))
|
if (secure(request.data() + APDU_LPDU_DIFF, kSecureSyncRequest, _deviceObj.individualAddress(), dstAddr, dstAddrIsGroupAddr, tpci, asdu, sizeof(asdu), secCtrl, systemBcast))
|
||||||
{
|
{
|
||||||
LOGGER.info("SyncRequest: %s", request.apdu().to_string().c_str());
|
LOGGER.info("SyncRequest: %S", request.apdu().toString());
|
||||||
|
|
||||||
if (_syncReqBroadcastOutgoing)
|
if (_syncReqBroadcastOutgoing)
|
||||||
{
|
{
|
||||||
@ -723,7 +723,7 @@ void SecureApplicationLayer::sendSyncResponse(uint16_t dstAddr, bool dstAddrIsGr
|
|||||||
{
|
{
|
||||||
_lastSyncRes = millis();
|
_lastSyncRes = millis();
|
||||||
|
|
||||||
LOGGER.info("SyncResponse: %s", response.apdu().to_string().c_str());
|
LOGGER.info("SyncResponse: %S", response.apdu());
|
||||||
|
|
||||||
if (_syncReqBroadcastIncoming)
|
if (_syncReqBroadcastIncoming)
|
||||||
{
|
{
|
||||||
@ -1063,7 +1063,7 @@ bool SecureApplicationLayer::decrypt(uint8_t* plainApdu, uint16_t plainApduLengt
|
|||||||
bool SecureApplicationLayer::decodeSecureApdu(APDU& secureApdu, APDU& plainApdu, SecurityControl& secCtrl)
|
bool SecureApplicationLayer::decodeSecureApdu(APDU& secureApdu, APDU& plainApdu, SecurityControl& secCtrl)
|
||||||
{
|
{
|
||||||
// Decode secure APDU
|
// Decode secure APDU
|
||||||
LOGGER.info("decodeSecureApdu: Secure APDU: %s", secureApdu.to_string().c_str());
|
LOGGER.info("decodeSecureApdu: Secure APDU: %S", secureApdu.toString());
|
||||||
|
|
||||||
uint16_t srcAddress = secureApdu.frame().sourceAddress();
|
uint16_t srcAddress = secureApdu.frame().sourceAddress();
|
||||||
uint16_t dstAddress = secureApdu.frame().destinationAddress();
|
uint16_t dstAddress = secureApdu.frame().destinationAddress();
|
||||||
@ -1085,7 +1085,7 @@ bool SecureApplicationLayer::decodeSecureApdu(APDU& secureApdu, APDU& plainApdu,
|
|||||||
// We are starting from TPCI octet (including): plainApdu.frame().data()+APDU_LPDU_DIFF
|
// We are starting from TPCI octet (including): plainApdu.frame().data()+APDU_LPDU_DIFF
|
||||||
if (decrypt(plainApdu.frame().data() + APDU_LPDU_DIFF, plainApdu.length() + 1, srcAddress, dstAddress, isDstAddrGroupAddr, tpci, secureApdu.data() + 1, secCtrl, isSystemBroadcast))
|
if (decrypt(plainApdu.frame().data() + APDU_LPDU_DIFF, plainApdu.length() + 1, srcAddress, dstAddress, isDstAddrGroupAddr, tpci, secureApdu.data() + 1, secCtrl, isSystemBroadcast))
|
||||||
{
|
{
|
||||||
LOGGER.info("decodeSecureApdu: Plain APDU: %s", plainApdu.frame().apdu().to_string().c_str());
|
LOGGER.info("decodeSecureApdu: Plain APDU: %S", plainApdu.frame().apdu().toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1260,7 +1260,7 @@ bool SecureApplicationLayer::createSecureApdu(APDU& plainApdu, APDU& secureApdu,
|
|||||||
{
|
{
|
||||||
// Create secure APDU
|
// Create secure APDU
|
||||||
|
|
||||||
LOGGER.info("createSecureApdu: Plain APDU: %s", plainApdu.frame().apdu().to_string().c_str());
|
LOGGER.info("createSecureApdu: Plain APDU: %S", plainApdu.frame().apdu().toString());
|
||||||
|
|
||||||
uint16_t srcAddress = plainApdu.frame().sourceAddress();
|
uint16_t srcAddress = plainApdu.frame().sourceAddress();
|
||||||
uint16_t dstAddress = plainApdu.frame().destinationAddress();
|
uint16_t dstAddress = plainApdu.frame().destinationAddress();
|
||||||
@ -1296,7 +1296,7 @@ bool SecureApplicationLayer::createSecureApdu(APDU& plainApdu, APDU& secureApdu,
|
|||||||
println(nextSequenceNumber(secCtrl.toolAccess), HEX);
|
println(nextSequenceNumber(secCtrl.toolAccess), HEX);
|
||||||
updateSequenceNumber(secCtrl.toolAccess, nextSequenceNumber(secCtrl.toolAccess) + 1);
|
updateSequenceNumber(secCtrl.toolAccess, nextSequenceNumber(secCtrl.toolAccess) + 1);
|
||||||
|
|
||||||
LOGGER.info("createSecureApdu: Secure APDU: %s", secureApdu.frame().apdu().to_string().c_str());
|
LOGGER.info("createSecureApdu: Secure APDU: %S", secureApdu.frame().apdu().toString());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -118,15 +118,15 @@ CemiFrame& TPDU::frame()
|
|||||||
return _frame;
|
return _frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPDU::printPDU()
|
const std::string TPDU::toString() const
|
||||||
{
|
{
|
||||||
/* print.print("TPDU: ");
|
std::string value = std::string("TPDU: ") + enum_name(type()) + " ";
|
||||||
print.print(type(), HEX, 2);
|
|
||||||
print.print(" ");
|
if (control())
|
||||||
for (uint8_t i = 0; i < apdu().length() + 1; ++i)
|
value += "control ";
|
||||||
{
|
|
||||||
if (i) print.print(" ");
|
if (numbered())
|
||||||
print.print(_data[i], HEX, 2);
|
value += "numbered sequence: " + to_string(sequenceNumber());
|
||||||
}
|
|
||||||
print.println()*/;
|
return value;
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "knx_types.h"
|
#include "knx_types.h"
|
||||||
|
#include <string>
|
||||||
class CemiFrame;
|
class CemiFrame;
|
||||||
class APDU;
|
class APDU;
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ class TPDU
|
|||||||
APDU& apdu();
|
APDU& apdu();
|
||||||
|
|
||||||
CemiFrame& frame();
|
CemiFrame& frame();
|
||||||
void printPDU();
|
const std::string toString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TPDU(uint8_t* data, CemiFrame& frame);
|
TPDU(uint8_t* data, CemiFrame& frame);
|
||||||
|
@ -5,8 +5,11 @@
|
|||||||
#include "application_layer.h"
|
#include "application_layer.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "util/logger.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define LOGGER Logger::logger("TransportLayer")
|
||||||
|
|
||||||
TransportLayer::TransportLayer(ApplicationLayer& layer): _savedFrame(0),
|
TransportLayer::TransportLayer(ApplicationLayer& layer): _savedFrame(0),
|
||||||
_savedFrameConnecting(0), _applicationLayer(layer)
|
_savedFrameConnecting(0), _applicationLayer(layer)
|
||||||
{
|
{
|
||||||
@ -25,13 +28,7 @@ void TransportLayer::groupAddressTable(AddressTableObject& addrTable)
|
|||||||
|
|
||||||
void TransportLayer::dataIndividualIndication(uint16_t destination, HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
void TransportLayer::dataIndividualIndication(uint16_t destination, HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
||||||
{
|
{
|
||||||
//if (tpdu.apdu().length() > 0)
|
LOGGER.info("dataIndividualIndication %S", tpdu.toString());
|
||||||
//{
|
|
||||||
// print.print("<- TL ");
|
|
||||||
// tpdu.printPDU();
|
|
||||||
// print.print("<- TL ");
|
|
||||||
// tpdu.apdu().printPDU();
|
|
||||||
//}
|
|
||||||
|
|
||||||
uint8_t sequenceNo = tpdu.sequenceNumber();
|
uint8_t sequenceNo = tpdu.sequenceNumber();
|
||||||
|
|
||||||
@ -334,6 +331,7 @@ void TransportLayer::dataIndividualIndication(uint16_t destination, HopCountType
|
|||||||
|
|
||||||
void TransportLayer::dataIndividualConfirm(AckType ack, uint16_t destination, HopCountType hopType, Priority priority, TPDU& tpdu, bool status)
|
void TransportLayer::dataIndividualConfirm(AckType ack, uint16_t destination, HopCountType hopType, Priority priority, TPDU& tpdu, bool status)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataIndividualConfirm %S", tpdu.toString());
|
||||||
TpduType type = tpdu.type();
|
TpduType type = tpdu.type();
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
@ -407,39 +405,49 @@ void TransportLayer::dataIndividualConfirm(AckType ack, uint16_t destination, Ho
|
|||||||
|
|
||||||
void TransportLayer::dataGroupIndication(uint16_t destination, HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
void TransportLayer::dataGroupIndication(uint16_t destination, HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataGroupIndication %S", tpdu.toString());
|
||||||
|
|
||||||
if (_groupAddressTable == nullptr)
|
if (_groupAddressTable == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint16_t tsap = _groupAddressTable->getTsap(destination);
|
uint16_t tsap = _groupAddressTable->getTsap(destination);
|
||||||
|
|
||||||
if (tsap == 0)
|
if (tsap == 0)
|
||||||
|
{
|
||||||
|
LOGGER.info("dataGroupIndication telegram is not for us");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_applicationLayer.dataGroupIndication(hopType, priority, tsap, tpdu.apdu());
|
_applicationLayer.dataGroupIndication(hopType, priority, tsap, tpdu.apdu());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataGroupConfirm(AckType ack, uint16_t source, uint16_t destination, HopCountType hopType, Priority priority, TPDU& tpdu, bool status)
|
void TransportLayer::dataGroupConfirm(AckType ack, uint16_t source, uint16_t destination, HopCountType hopType, Priority priority, TPDU& tpdu, bool status)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataGroupConfirm %S", tpdu.toString());
|
||||||
_applicationLayer.dataGroupConfirm(ack, hopType, priority, destination, tpdu.apdu(), status);
|
_applicationLayer.dataGroupConfirm(ack, hopType, priority, destination, tpdu.apdu(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
void TransportLayer::dataBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataBroadcastIndication %S", tpdu.toString());
|
||||||
_applicationLayer.dataBroadcastIndication(hopType, priority, source, tpdu.apdu());
|
_applicationLayer.dataBroadcastIndication(hopType, priority, source, tpdu.apdu());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, Priority priority, TPDU& tpdu, bool status)
|
void TransportLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, Priority priority, TPDU& tpdu, bool status)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataBroadcastConfirm %S", tpdu.toString());
|
||||||
_applicationLayer.dataBroadcastConfirm(ack, hopType, priority, tpdu.apdu(), status);
|
_applicationLayer.dataBroadcastConfirm(ack, hopType, priority, tpdu.apdu(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataSystemBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
void TransportLayer::dataSystemBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, TPDU& tpdu)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataSystemBroadcastIndication %S", tpdu.toString());
|
||||||
_applicationLayer.dataSystemBroadcastIndication(hopType, priority, source, tpdu.apdu());
|
_applicationLayer.dataSystemBroadcastIndication(hopType, priority, source, tpdu.apdu());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataSystemBroadcastConfirm(AckType ack, HopCountType hopType, TPDU& tpdu, Priority priority, bool status)
|
void TransportLayer::dataSystemBroadcastConfirm(AckType ack, HopCountType hopType, TPDU& tpdu, Priority priority, bool status)
|
||||||
{
|
{
|
||||||
|
LOGGER.info("dataSystemBroadcastConfirm %S", tpdu.toString());
|
||||||
_applicationLayer.dataSystemBroadcastConfirm(hopType, priority, tpdu.apdu(), status);
|
_applicationLayer.dataSystemBroadcastConfirm(hopType, priority, tpdu.apdu(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,26 +458,28 @@ void TransportLayer::dataGroupRequest(AckType ack, HopCountType hopType, Priorit
|
|||||||
|
|
||||||
uint16_t groupAdress = _groupAddressTable->getGroupAddress(tsap);
|
uint16_t groupAdress = _groupAddressTable->getGroupAddress(tsap);
|
||||||
TPDU& tpdu = apdu.frame().tpdu();
|
TPDU& tpdu = apdu.frame().tpdu();
|
||||||
|
LOGGER.info("dataGroupRequest %S", tpdu.toString());
|
||||||
_networkLayer->dataGroupRequest(ack, groupAdress, hopType, priority, tpdu);
|
_networkLayer->dataGroupRequest(ack, groupAdress, hopType, priority, tpdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataBroadcastRequest(AckType ack, HopCountType hopType, Priority priority, APDU& apdu)
|
void TransportLayer::dataBroadcastRequest(AckType ack, HopCountType hopType, Priority priority, APDU& apdu)
|
||||||
{
|
{
|
||||||
TPDU& tpdu = apdu.frame().tpdu();
|
TPDU& tpdu = apdu.frame().tpdu();
|
||||||
|
LOGGER.info("dataBroadcastRequest %S", tpdu.toString());
|
||||||
_networkLayer->dataBroadcastRequest(ack, hopType, priority, tpdu);
|
_networkLayer->dataBroadcastRequest(ack, hopType, priority, tpdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataSystemBroadcastRequest(AckType ack, HopCountType hopType, Priority priority, APDU& apdu)
|
void TransportLayer::dataSystemBroadcastRequest(AckType ack, HopCountType hopType, Priority priority, APDU& apdu)
|
||||||
{
|
{
|
||||||
TPDU& tpdu = apdu.frame().tpdu();
|
TPDU& tpdu = apdu.frame().tpdu();
|
||||||
|
LOGGER.info("dataSystemBroadcastRequest %S", tpdu.toString());
|
||||||
return _networkLayer->dataSystemBroadcastRequest(ack, hopType, priority, tpdu);
|
return _networkLayer->dataSystemBroadcastRequest(ack, hopType, priority, tpdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportLayer::dataIndividualRequest(AckType ack, HopCountType hopType, Priority priority, uint16_t destination, APDU& apdu)
|
void TransportLayer::dataIndividualRequest(AckType ack, HopCountType hopType, Priority priority, uint16_t destination, APDU& apdu)
|
||||||
{
|
{
|
||||||
//print.print("-> TL ");
|
|
||||||
//apdu.printPDU();
|
|
||||||
TPDU& tpdu = apdu.frame().tpdu();
|
TPDU& tpdu = apdu.frame().tpdu();
|
||||||
|
LOGGER.info("dataIndividualRequest %S", tpdu.toString());
|
||||||
_networkLayer->dataIndividualRequest(ack, destination, hopType, priority, tpdu);
|
_networkLayer->dataIndividualRequest(ack, destination, hopType, priority, tpdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,6 +641,7 @@ void TransportLayer::sendControlTelegram(TpduType pduType, uint8_t seqNo)
|
|||||||
TPDU& tpdu = frame.tpdu();
|
TPDU& tpdu = frame.tpdu();
|
||||||
tpdu.type(pduType);
|
tpdu.type(pduType);
|
||||||
tpdu.sequenceNumber(seqNo);
|
tpdu.sequenceNumber(seqNo);
|
||||||
|
LOGGER.info("sendControlTelegram %S", tpdu.toString());
|
||||||
_networkLayer->dataIndividualRequest(AckRequested, _connectionAddress, NetworkLayerParameter,
|
_networkLayer->dataIndividualRequest(AckRequested, _connectionAddress, NetworkLayerParameter,
|
||||||
SystemPriority, tpdu);
|
SystemPriority, tpdu);
|
||||||
}
|
}
|
||||||
|
@ -65,16 +65,16 @@ class Logger
|
|||||||
return "INFO";
|
return "INFO";
|
||||||
|
|
||||||
case LogType::Warning:
|
case LogType::Warning:
|
||||||
return "WARNING";
|
return "WARN";
|
||||||
|
|
||||||
case LogType::Error:
|
case LogType::Error:
|
||||||
return "ERROR";
|
return "ERR ";
|
||||||
|
|
||||||
case LogType::Critical:
|
case LogType::Critical:
|
||||||
return "CRITICAL";
|
return "CRIT";
|
||||||
|
|
||||||
case LogType::Exception:
|
case LogType::Exception:
|
||||||
return "EXCEPTION";
|
return "EXCE";
|
||||||
}
|
}
|
||||||
return to_string(type);
|
return to_string(type);
|
||||||
}
|
}
|
||||||
@ -84,11 +84,11 @@ class Logger
|
|||||||
{
|
{
|
||||||
#ifndef KNX_NO_PRINT
|
#ifndef KNX_NO_PRINT
|
||||||
print(millis());
|
print(millis());
|
||||||
print("\t");
|
print(" ");
|
||||||
print(_name.c_str());
|
print(_name.c_str());
|
||||||
print("\t");
|
print("\t");
|
||||||
print(enum_name(type).c_str());
|
print(enum_name(type).c_str());
|
||||||
print("\t");
|
print(" ");
|
||||||
|
|
||||||
while (*format)
|
while (*format)
|
||||||
{
|
{
|
||||||
@ -104,6 +104,10 @@ class Logger
|
|||||||
{
|
{
|
||||||
print(va_arg(args, char*));
|
print(va_arg(args, char*));
|
||||||
}
|
}
|
||||||
|
else if (*format == 'S')
|
||||||
|
{
|
||||||
|
print(va_arg(args, std::string).c_str());
|
||||||
|
}
|
||||||
else if (*format == 'f')
|
else if (*format == 'f')
|
||||||
{
|
{
|
||||||
print(va_arg(args, double));
|
print(va_arg(args, double));
|
||||||
|
Loading…
Reference in New Issue
Block a user