added PLOC sequence count. Not tested yet

This commit is contained in:
2021-04-27 12:18:04 +02:00
3 changed files with 62 additions and 20 deletions

View File

@ -92,11 +92,16 @@ ReturnValue_t PlocHandler::scanForReply(const uint8_t *start,
default: {
sif::debug << "PlocHandler::scanForReply: Reply has invalid apid" << std::endl;
*foundLen = remainingSize;
result = INVALID_APID;
break;
return INVALID_APID;
}
}
/**
* This should normally never fail. However, this function is also responsible for incrementing
* the packet sequence count why it is called here.
*/
result = checkPacketSequenceCount(start);
return result;
}
@ -151,7 +156,7 @@ ReturnValue_t PlocHandler::prepareTcMemWriteCommand(const uint8_t * commandData,
| *(commandData + 2) << 8 | *(commandData + 3);
const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16
| *(commandData + 6) << 8 | *(commandData + 7);
PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData);
PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData, packetSequenceCount);
if (tcMemWrite.getFullSize() > PLOC::MAX_COMMAND_SIZE) {
sif::debug << "PlocHandler::prepareTcMemWriteCommand: Command too big" << std::endl;
return RETURN_FAILED;
@ -167,7 +172,7 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData,
size_t commandDataLen) {
const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16
| *(commandData + 2) << 8 | *(commandData + 3);
PLOC::TcMemRead tcMemRead(memoryAddress);
PLOC::TcMemRead tcMemRead(memoryAddress, packetSequenceCount);
if (tcMemRead.getFullSize() > PLOC::MAX_COMMAND_SIZE) {
sif::debug << "PlocHandler::prepareTcMemReadCommand: Command too big" << std::endl;
return RETURN_FAILED;
@ -176,6 +181,7 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData,
rawPacket = commandBuffer;
rawPacketLen = tcMemRead.getFullSize();
nextReplyId = PLOC::ACK_REPORT;
return RETURN_OK;
}
@ -183,7 +189,7 @@ ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1);
uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2, 0);
uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2);
if (receivedCrc != recalculatedCrc) {
return CRC_FAILURE;
@ -474,3 +480,16 @@ void PlocHandler::disableExeReportReply() {
/* Expected replies is set to one here. The value will set to 0 in replyToReply() */
info->command->second.expectedReplies = 0;
}
ReturnValue_t PlocHandler::checkPacketSequenceCount(const uint8_t* data) {
uint16_t receivedSequenceCount = *(data + 2) << 8 | *(data + 3) & PACKET_SEQUENCE_COUNT_MASK;
if (receivedSequenceCount != ((packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK)) {
sif::debug << "PlocHandler::checkPacketSequenceCount: Packet sequence count mismatch"
<< std::endl;
/** The packet sequence count is corrected here to match the sequence count of the PLOC */
packetSequenceCount = (receivedSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
return SUBSEQUENCE_COUNT_FAILURE;
}
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
return RETURN_OK;
}