mirror of
https://github.com/thelsing/knx.git
synced 2025-04-23 01:16:29 +02:00
save work
This commit is contained in:
parent
47b582068b
commit
723e630dae
@ -66,6 +66,29 @@ enum cEmiErrorCode
|
|||||||
Value_temp_not_writeable = 0x0A, // The Property exists but can at this moment not be written with a new value (W)
|
Value_temp_not_writeable = 0x0A, // The Property exists but can at this moment not be written with a new value (W)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ReturnCodes
|
||||||
|
{
|
||||||
|
// Generic positive return codes
|
||||||
|
Success = 0x00, // service, function or command executed sucessfully
|
||||||
|
SuccessWithCrc = 0x01, // positive message confirmation, CRC over original data
|
||||||
|
// Generic negative return codes
|
||||||
|
MemoryError = 0xF1, // memory cannot be accessed or only with fault(s)
|
||||||
|
InvalidCommand = 0xF2, // server does not support the requested command. ets: also non-existing or protected resource
|
||||||
|
ImpossibleCommand = 0xF3, // command cannot be executed because a dependency is not fulfilled
|
||||||
|
ExceedsMaxApduLength = 0xF4, // data will not fit into a frame supported by this server
|
||||||
|
DataOverflow = 0xF5, // attempt to write data beyond what is reserved for the addressed resource
|
||||||
|
OutOfMinRange = 0xF6, // write value below minimum supported value
|
||||||
|
OutOfMaxRange = 0xF7, // write value exceeds maximum supported value
|
||||||
|
DataVoid = 0xF8, // request contains invalid data
|
||||||
|
TemporarilyNotAvailable = 0xF9, // data access not possible at this time
|
||||||
|
AccessWriteOnly = 0xFA, // read access to write-only resource
|
||||||
|
AccessReadOnly = 0xFB, // write access to read-only resource
|
||||||
|
AccessDenied = 0xFC, // access to recource is not allowed because of authorization/security
|
||||||
|
AddressVoid = 0xFD, // resource is not present, address does not exist
|
||||||
|
DataTypeConflict = 0xFE, // write access with wrong datatype (datapoint length)
|
||||||
|
GenericError = 0xFF // service, function or command failed
|
||||||
|
};
|
||||||
|
|
||||||
enum Repetition
|
enum Repetition
|
||||||
{
|
{
|
||||||
NoRepitiion = 0,
|
NoRepitiion = 0,
|
||||||
|
@ -37,10 +37,10 @@ SecurityInterfaceObject::SecurityInterfaceObject()
|
|||||||
// Command Callback of PID_SECURITY_MODE
|
// Command Callback of PID_SECURITY_MODE
|
||||||
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
||||||
uint8_t serviceId = data[1] & 0xff;
|
uint8_t serviceId = data[1] & 0xff;
|
||||||
resultLength = 1;
|
|
||||||
if (serviceId != 0)
|
if (serviceId != 0)
|
||||||
{
|
{
|
||||||
resultData[0] = 0xF2; // InvalidCommand
|
resultData[0] = ReturnCodes::InvalidCommand;
|
||||||
|
resultLength = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (length == 3)
|
if (length == 3)
|
||||||
@ -48,29 +48,37 @@ SecurityInterfaceObject::SecurityInterfaceObject()
|
|||||||
uint8_t mode = data[2];
|
uint8_t mode = data[2];
|
||||||
if (mode > 1)
|
if (mode > 1)
|
||||||
{
|
{
|
||||||
resultData[0] = 0xF8; // DataVoid
|
resultData[0] = ReturnCodes::DataVoid;
|
||||||
|
resultLength = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
obj->_secAppLayer->setSecurityMode(mode == 1);
|
obj->_secAppLayer->setSecurityMode(mode == 1);
|
||||||
resultData[0] = serviceId;
|
resultData[0] = ReturnCodes::Success;
|
||||||
|
resultData[1] = serviceId;
|
||||||
|
resultLength = 2;
|
||||||
}
|
}
|
||||||
|
resultData[0] = ReturnCodes::GenericError;
|
||||||
|
resultLength = 1;
|
||||||
},
|
},
|
||||||
// State Callback of PID_SECURITY_MODE
|
// State Callback of PID_SECURITY_MODE
|
||||||
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
||||||
uint8_t serviceId = data[1] & 0xff;
|
uint8_t serviceId = data[1] & 0xff;
|
||||||
resultLength = 2;
|
|
||||||
if (serviceId != 0)
|
if (serviceId != 0)
|
||||||
{
|
{
|
||||||
resultData[0] = 0xF2; // InvalidCommand
|
resultData[0] = ReturnCodes::InvalidCommand;
|
||||||
resultLength = 1;
|
resultLength = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (length == 2)
|
if (length == 2)
|
||||||
{
|
{
|
||||||
resultData[0] = serviceId;
|
resultData[0] = ReturnCodes::Success;
|
||||||
resultData[1] = obj->_secAppLayer->isSecurityModeEnabled() ? 1 : 0;
|
resultData[1] = serviceId;
|
||||||
resultLength = 2;
|
resultData[2] = obj->_secAppLayer->isSecurityModeEnabled() ? 1 : 0;
|
||||||
|
resultLength = 3;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
resultData[0] = ReturnCodes::GenericError;
|
||||||
|
resultLength = 1;
|
||||||
}),
|
}),
|
||||||
new DataProperty( PID_P2P_KEY_TABLE, true, PDT_GENERIC_20, 1, ReadLv3 | WriteLv0 ), // written by ETS
|
new DataProperty( PID_P2P_KEY_TABLE, true, PDT_GENERIC_20, 1, ReadLv3 | WriteLv0 ), // written by ETS
|
||||||
new DataProperty( PID_GRP_KEY_TABLE, true, PDT_GENERIC_18, 1, ReadLv3 | WriteLv0 ), // written by ETS
|
new DataProperty( PID_GRP_KEY_TABLE, true, PDT_GENERIC_18, 1, ReadLv3 | WriteLv0 ), // written by ETS
|
||||||
@ -80,7 +88,7 @@ SecurityInterfaceObject::SecurityInterfaceObject()
|
|||||||
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
||||||
if (length != 3)
|
if (length != 3)
|
||||||
{
|
{
|
||||||
resultData[0] = 0xF8; // DataVoid
|
resultData[0] = ReturnCodes::DataVoid;
|
||||||
resultLength = 1;
|
resultLength = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -89,15 +97,19 @@ SecurityInterfaceObject::SecurityInterfaceObject()
|
|||||||
if (id == 0 && info == 0)
|
if (id == 0 && info == 0)
|
||||||
{
|
{
|
||||||
obj->_secAppLayer->clearFailureLog();
|
obj->_secAppLayer->clearFailureLog();
|
||||||
resultData[0] = id;
|
resultData[0] = ReturnCodes::Success;
|
||||||
resultLength = 1;
|
resultData[1] = id;
|
||||||
|
resultLength = 2;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
resultData[0] = ReturnCodes::GenericError;
|
||||||
|
resultLength = 1;
|
||||||
},
|
},
|
||||||
// State Callback of PID_SECURITY_FAILURES_LOG
|
// State Callback of PID_SECURITY_FAILURES_LOG
|
||||||
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
[](SecurityInterfaceObject* obj, uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength) -> void {
|
||||||
if (length != 3)
|
if (length != 3)
|
||||||
{
|
{
|
||||||
resultData[0] = 0xF8; // DataVoid
|
resultData[0] = ReturnCodes::DataVoid;
|
||||||
resultLength = 1;
|
resultLength = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -107,38 +119,35 @@ SecurityInterfaceObject::SecurityInterfaceObject()
|
|||||||
// failure counters
|
// failure counters
|
||||||
if (id == 0 && info == 0)
|
if (id == 0 && info == 0)
|
||||||
{
|
{
|
||||||
resultData[0] = id;
|
resultData[0] = ReturnCodes::Success;
|
||||||
resultData[1] = info;
|
resultData[1] = id;
|
||||||
obj->_secAppLayer->getFailureCounters(&resultData[2]); // Put 8 bytes in the buffer
|
resultData[2] = info;
|
||||||
resultLength = 2 + 8;
|
obj->_secAppLayer->getFailureCounters(&resultData[3]); // Put 8 bytes in the buffer
|
||||||
|
resultLength = 3 + 8;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// query latest failure by index
|
// query latest failure by index
|
||||||
else if(id == 1)
|
else if(id == 1)
|
||||||
{
|
{
|
||||||
uint8_t maxBufferSize = resultLength;
|
uint8_t maxBufferSize = resultLength; // Remember the maximum buffer size of the buffer that is provided to us
|
||||||
// TODO:
|
|
||||||
//int index = info;
|
|
||||||
//int i = 0;
|
|
||||||
//for (var msgInfo : lastFailures) {
|
|
||||||
// if (i++ == index)
|
|
||||||
// return new ServiceResult(ByteBuffer.allocate(2 + msgInfo.length).put((byte) id)
|
|
||||||
// .put((byte) index).put(msgInfo).array());
|
|
||||||
//}
|
|
||||||
uint8_t index = info;
|
uint8_t index = info;
|
||||||
uint8_t numBytes = obj->_secAppLayer->getFromFailureLogByIndex(index, &resultData[2], maxBufferSize);
|
uint8_t numBytes = obj->_secAppLayer->getFromFailureLogByIndex(index, &resultData[2], maxBufferSize);
|
||||||
if ( numBytes > 0)
|
if ( numBytes > 0)
|
||||||
{
|
{
|
||||||
resultData[0] = id;
|
resultData[0] = ReturnCodes::Success;
|
||||||
resultData[1] = index;
|
resultData[1] = id;
|
||||||
|
resultData[2] = index;
|
||||||
resultLength += numBytes;
|
resultLength += numBytes;
|
||||||
resultLength = 2 + numBytes;
|
resultLength = 3 + numBytes;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resultData[0] = 0xF8; // DataVoid
|
resultData[0] = ReturnCodes::DataVoid;
|
||||||
resultData[1] = id;
|
resultData[1] = id;
|
||||||
resultLength = 2;
|
resultLength = 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
resultData[0] = ReturnCodes::GenericError;
|
||||||
|
resultLength = 1;
|
||||||
}),
|
}),
|
||||||
new DataProperty( PID_TOOL_KEY, true, PDT_GENERIC_16, 1, ReadLv3 | WriteLv0, (uint8_t*) _fdsk ), // default is FDSK
|
new DataProperty( PID_TOOL_KEY, true, PDT_GENERIC_16, 1, ReadLv3 | WriteLv0, (uint8_t*) _fdsk ), // default is FDSK
|
||||||
new DataProperty( PID_SECURITY_REPORT, true, PDT_BITSET8, 1, ReadLv3 | WriteLv0, _secReport ), // Not implemented
|
new DataProperty( PID_SECURITY_REPORT, true, PDT_BITSET8, 1, ReadLv3 | WriteLv0, _secReport ), // Not implemented
|
||||||
@ -158,19 +167,16 @@ void SecurityInterfaceObject::secureApplicationLayer(SecureApplicationLayer& sec
|
|||||||
|
|
||||||
uint8_t* SecurityInterfaceObject::save(uint8_t* buffer)
|
uint8_t* SecurityInterfaceObject::save(uint8_t* buffer)
|
||||||
{
|
{
|
||||||
//buffer = pushWord(_ownAddress, buffer);
|
|
||||||
return InterfaceObject::save(buffer);
|
return InterfaceObject::save(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t* SecurityInterfaceObject::restore(const uint8_t* buffer)
|
const uint8_t* SecurityInterfaceObject::restore(const uint8_t* buffer)
|
||||||
{
|
{
|
||||||
//buffer = popWord(_ownAddress, buffer);
|
|
||||||
return InterfaceObject::restore(buffer);
|
return InterfaceObject::restore(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t SecurityInterfaceObject::saveSize()
|
uint16_t SecurityInterfaceObject::saveSize()
|
||||||
{
|
{
|
||||||
//return 2 + InterfaceObject::saveSize();
|
|
||||||
return InterfaceObject::saveSize();
|
return InterfaceObject::saveSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user