Extend restart and masterreset for factory reset

This commit is contained in:
Nanosonde 2020-06-27 16:32:39 +02:00
parent 4b52f241ec
commit 604c1d6bdb
9 changed files with 95 additions and 13 deletions

View File

@ -243,6 +243,15 @@ int main(int argc, char **argv)
{
printf("main() start.\n");
if (argc > 1)
{
EraseCode eraseCode = (EraseCode) atoi(argv[2]);
print("Performing factory reset with erase code: ");
println(eraseCode, HEX);
knx.masterReset(eraseCode, 0);
}
uint8_t inPlain[] { 0x00, 0xFA, 0x01, 0x02, 0x03, 0x04, // KNX Serial
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; // Key
uint8_t* outEncoded = NULL;

View File

@ -803,10 +803,19 @@ void ApplicationLayer::individualIndication(HopCountType hopType, Priority prior
_bau.deviceDescriptorReadAppLayerConfirm(priority, hopType, tsap, secCtrl, *data & 0x3f, data + 1);
break;
case Restart:
// TODO: handle erase code for factory reset (setting FDSK again as toolkey, etc.)
if ((*data & 0x3f) == 0)
_bau.restartRequestIndication(priority, hopType, tsap, secCtrl);
{
// handle erase code for factory reset (setting FDSK again as toolkey, etc.)
RestartType restartType = (RestartType) (*data & 0x3f);
EraseCode eraseCode = EraseCode::Void;
uint8_t channel = 0;
if (restartType == RestartType::MasterReset)
{
eraseCode = (EraseCode) (*data + 1);
channel = *data + 2;
}
_bau.restartRequestIndication(priority, hopType, tsap, secCtrl, restartType, eraseCode, channel);
break;
}
case PropertyValueRead:
{
uint16_t startIndex;

View File

@ -94,7 +94,7 @@ void BusAccessUnit::restartRequestLocalConfirm(AckType ack, Priority priority, H
{
}
void BusAccessUnit::restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl)
void BusAccessUnit::restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, RestartType restartType, EraseCode eraseCode, uint8_t channel)
{
}

View File

@ -43,7 +43,7 @@ class BusAccessUnit
virtual void deviceDescriptorReadAppLayerConfirm(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl,
uint8_t descriptortype, uint8_t* deviceDescriptor);
virtual void restartRequestLocalConfirm(AckType ack, Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, bool status);
virtual void restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl);
virtual void restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, RestartType restartType, EraseCode eraseCode, uint8_t channel);
virtual void propertyValueReadLocalConfirm(AckType ack, Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl,
uint8_t objectIndex, uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex, bool status);
virtual void propertyValueReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint8_t objectIndex,

View File

@ -158,6 +158,36 @@ bool BauSystemB::configured()
return _configured;
}
void BauSystemB::masterReset(EraseCode eraseCode, uint8_t channel)
{
switch (eraseCode)
{
case EraseCode::ConfimrmedRestart:
{
println("Confirmed restart requested.");
break;
}
case EraseCode::FactoryReset:
case EraseCode::FactoryResetWithoutIA:
{
#ifdef USE_DATASECURE
print("Factory reset requested. type: ");
println(eraseCode == EraseCode::FactoryReset ? "FactoryReset with IA" : "FactoryReset without IA");
// If erase code is FactoryReset or FactoryResetWithoutIA, set FDSK as toolkey again
// and disable security mode
_secIfObj.factoryReset();
#endif
break;
}
default:
{
print("Unhandled erase code: ");
println(eraseCode, HEX);
break;
}
}
}
void BauSystemB::deviceDescriptorReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint8_t descriptorType)
{
if (descriptorType != 0)
@ -184,12 +214,22 @@ void BauSystemB::memoryReadIndication(Priority priority, HopCountType hopType, u
_memory.toAbsolute(memoryAddress));
}
void BauSystemB::restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl)
void BauSystemB::restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, RestartType restartType, EraseCode eraseCode, uint8_t channel)
{
#ifdef USE_DATASECURE
// If erase code is FactoryReset, set FDSK as toolkey again
//_secIfObj.factoryReset();
#endif
if (restartType == RestartType::BasicRestart)
{
println("Basic restart requested");
}
else if (restartType == RestartType::MasterReset)
{
masterReset(eraseCode, channel);
}
else
{
println("Unhandled restart type");
return;
}
// Flush the EEPROM before resetting
_memory.writeMemory();
_platform.restart();

View File

@ -32,6 +32,7 @@ class BauSystemB : protected BusAccessUnit
void writeMemory();
void addSaveRestore(SaveRestore* obj);
bool restartRequest(uint16_t asap, const SecurityControl &secCtrl);
void masterReset(EraseCode eraseCode, uint8_t channel);
void propertyValueRead(ObjectType objectType, uint8_t objectInstance, uint8_t propertyId,
uint8_t& numberOfElements, uint16_t startIndex,
@ -47,7 +48,7 @@ class BauSystemB : protected BusAccessUnit
void memoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint8_t number,
uint16_t memoryAddress) override;
void deviceDescriptorReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint8_t descriptorType) override;
void restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl) override;
void restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, RestartType restartType, EraseCode eraseCode, uint8_t channel) override;
void authorizeIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint32_t key) override;
void userMemoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint8_t number, uint32_t memoryAddress) override;
void userMemoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl &secCtrl, uint8_t number,

View File

@ -183,7 +183,7 @@ enum ApduType
SecureService = 0x3F1
};
enum class DataSecurity
enum DataSecurity
{
none,
auth,
@ -196,3 +196,20 @@ struct SecurityControl
DataSecurity dataSecurity;
};
enum RestartType
{
BasicRestart = 0x0,
MasterReset = 0x1
};
enum EraseCode
{
Void = 0x00,
ConfimrmedRestart = 0x01,
FactoryReset = 0x02,
ResetIA = 0x03,
ResetAP = 0x04,
ResetParam = 0x05,
ResetLinks = 0x06,
FactoryResetWithoutIA = 0x07
};

View File

@ -188,6 +188,7 @@ bool SecurityInterfaceObject::isLoaded()
void SecurityInterfaceObject::factoryReset()
{
_secAppLayer->setSecurityMode(false);
property(PID_TOOL_KEY)->write(1, 1, _fdsk);
}

View File

@ -93,6 +93,11 @@ template <class P, class B> class KnxFacade : private SaveRestore
return _bau.configured();
}
void masterReset(EraseCode erasecode, uint8_t channel)
{
_bau.masterReset(erasecode, channel);
}
/**
* returns HIGH if led is active on HIGH, LOW otherwise
*/
@ -352,4 +357,4 @@ template <class P, class B> class KnxFacade : private SaveRestore
extern KnxFacade<Stm32Platform, Bau07B0> knx;
#elif __linux__
// no predefined global instance
#endif
#endif