| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title CcsdsSdlsFramer.cpp | ||
| 3 | // \author devin | ||
| 4 | // \brief cpp file for CcsdsSdlsFramer component implementation class | ||
| 5 | // ====================================================================== | ||
| 6 | |||
| 7 | #include "Svc/Ccsds/CcsdsSdlsFramer/CcsdsSdlsFramer.hpp" | ||
| 8 | |||
| 9 | #include <Fw/Prm/ParamValid.hpp> | ||
| 10 | |||
| 11 | namespace Svc { | ||
| 12 | |||
| 13 | namespace Ccsds { | ||
| 14 | |||
| 15 | // ---------------------------------------------------------------------- | ||
| 16 | // Component construction and destruction | ||
| 17 | // ---------------------------------------------------------------------- | ||
| 18 | |||
| 19 | 7 | CcsdsSdlsFramer ::CcsdsSdlsFramer(const char* const compName) : CcsdsSdlsFramerComponentBase(compName) {} | |
| 20 | |||
| 21 | 14 | CcsdsSdlsFramer ::~CcsdsSdlsFramer() {} | |
| 22 | |||
| 23 | // ---------------------------------------------------------------------- | ||
| 24 | // Handler implementations for typed input ports | ||
| 25 | // ---------------------------------------------------------------------- | ||
| 26 | |||
| 27 | 1244 | void CcsdsSdlsFramer ::bufferReturnIn_handler(FwIndexType portNum, | |
| 28 | Fw::Buffer& data, | ||
| 29 | const ComCfg::FrameContext& context) { | ||
| 30 | // The encryption helper has returned the original data buffer: send it back upstream | ||
| 31 | 1244 | this->dataReturnOut_out(0, data, context); | |
| 32 | 1244 | } | |
| 33 | |||
| 34 | 1204 | void CcsdsSdlsFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) { | |
| 35 |
1/2✓ Branch 5 taken 1204 times.
✗ Branch 6 not taken.
|
1204 | if (this->isConnected_comStatusOut_OutputPort(portNum)) { |
| 36 | 1204 | this->comStatusOut_out(portNum, condition); | |
| 37 | } | ||
| 38 | 1204 | } | |
| 39 | |||
| 40 | 2501 | void CcsdsSdlsFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) { | |
| 41 | // Determine the security association index: use the context's value when set, otherwise the SA_INDEX parameter | ||
| 42 | 2501 | const U16 unsetSaIndex = static_cast<U16>(ComCfg::SaIndexUnset); | |
| 43 | 2501 | U16 saIndex = context.get_saIndex(); | |
| 44 |
2/2✓ Branch 0 taken 1254 times.
✓ Branch 1 taken 1247 times.
|
2501 | if (saIndex == unsetSaIndex) { |
| 45 |
1/1✓ Branch 2 taken 1254 times.
|
1254 | Fw::ParamValid valid = Fw::ParamValid::INVALID; |
| 46 |
1/1✓ Branch 5 taken 1254 times.
|
1254 | saIndex = this->paramGet_SA_INDEX(valid); |
| 47 | 1254 | FW_ASSERT(FW_PARAM_OK(valid), static_cast<FwAssertArgType>(valid.e)); | |
| 48 | 1254 | } | |
| 49 | |||
| 50 | // Copy context and record the security association index used for encryption | ||
| 51 |
1/1✓ Branch 2 taken 2501 times.
|
2501 | ComCfg::FrameContext newContext = context; |
| 52 |
1/1✓ Branch 2 taken 2501 times.
|
2501 | newContext.set_saIndex(saIndex); |
| 53 | |||
| 54 |
1/1✓ Branch 5 taken 2501 times.
|
2501 | this->encryptOut_out(0, saIndex, data, newContext); |
| 55 | 5002 | } | |
| 56 | |||
| 57 | 1251 | void CcsdsSdlsFramer ::dataReturnIn_handler(FwIndexType portNum, | |
| 58 | Fw::Buffer& data, | ||
| 59 | const ComCfg::FrameContext& context) { | ||
| 60 | // dataReturnIn is the allocated frame buffer coming back from the dataOut port | ||
| 61 | 1251 | this->bufferDeallocate_out(0, data); | |
| 62 | 1251 | } | |
| 63 | |||
| 64 | 3808 | void CcsdsSdlsFramer ::encryptIn_handler(FwIndexType portNum, | |
| 65 | const Svc::Ccsds::SdlsStatus& status, | ||
| 66 | Fw::Buffer& data, | ||
| 67 | const ComCfg::FrameContext& context) { | ||
| 68 |
2/2✓ Branch 4 taken 1244 times.
✓ Branch 5 taken 2564 times.
|
3808 | if (status != Svc::Ccsds::SdlsStatus::SUCCESS) { |
| 69 |
1/1✓ Branch 5 taken 1244 times.
|
1244 | this->log_WARNING_HI_EncryptionFailed(status); |
| 70 | // Drop the frame: return ownership of the buffer to the encryption subsystem | ||
| 71 |
1/1✓ Branch 5 taken 1244 times.
|
1244 | this->encryptReturnOut_out(0, data, context); |
| 72 |
1/1✓ Branch 4 taken 1244 times.
|
1244 | this->sendComStatusOnDrop(); |
| 73 | 1244 | return; | |
| 74 | } | ||
| 75 | |||
| 76 | 2564 | FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - sizeof(U16), | |
| 77 | static_cast<FwAssertArgType>(data.getSize())); | ||
| 78 |
1/1✓ Branch 4 taken 2564 times.
|
2564 | const Fw::Buffer::SizeType frameSize = static_cast<Fw::Buffer::SizeType>(data.getSize() + sizeof(U16)); |
| 79 | |||
| 80 | // Allocate the frame buffer used to prepend the security association index to the encrypted data | ||
| 81 |
1/1✓ Branch 3 taken 2564 times.
|
2564 | Fw::Buffer frameBuffer = this->bufferAllocate_out(0, frameSize); |
| 82 |
8/8✓ Branch 2 taken 2564 times.
✓ Branch 4 taken 1893 times.
✓ Branch 5 taken 671 times.
✓ Branch 8 taken 1893 times.
✓ Branch 10 taken 637 times.
✓ Branch 11 taken 1256 times.
✓ Branch 12 taken 1308 times.
✓ Branch 13 taken 1256 times.
|
2564 | if ((!frameBuffer.isValid()) || (frameBuffer.getSize() < frameSize)) { |
| 83 |
1/1✓ Branch 5 taken 1308 times.
|
1308 | this->log_WARNING_HI_BufferAllocationFailed(frameSize); |
| 84 | // Drop the frame: return the undersized allocation (when valid) and the encrypted data buffer | ||
| 85 |
3/3✓ Branch 2 taken 1308 times.
✓ Branch 4 taken 637 times.
✓ Branch 5 taken 671 times.
|
1308 | if (frameBuffer.isValid()) { |
| 86 |
1/1✓ Branch 5 taken 637 times.
|
637 | this->bufferDeallocate_out(0, frameBuffer); |
| 87 | } | ||
| 88 |
1/1✓ Branch 5 taken 1308 times.
|
1308 | this->encryptReturnOut_out(0, data, context); |
| 89 |
1/1✓ Branch 4 taken 1308 times.
|
1308 | this->sendComStatusOnDrop(); |
| 90 | 1308 | return; | |
| 91 | } | ||
| 92 | |||
| 93 |
1/1✓ Branch 2 taken 1256 times.
|
1256 | auto frameSerializer = frameBuffer.getSerializer(); |
| 94 |
1/1✓ Branch 6 taken 1256 times.
|
1256 | Fw::SerializeStatus serializeStatus = frameSerializer.serializeFrom(context.get_saIndex()); |
| 95 | 1256 | FW_ASSERT(serializeStatus == Fw::FW_SERIALIZE_OK, serializeStatus); | |
| 96 |
3/3✓ Branch 5 taken 1256 times.
✓ Branch 11 taken 1256 times.
✓ Branch 14 taken 1256 times.
|
1256 | serializeStatus = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH); |
| 97 | 1256 | FW_ASSERT(serializeStatus == Fw::FW_SERIALIZE_OK, serializeStatus); | |
| 98 | |||
| 99 | // Trim to actual frame size in case the allocator returned a larger buffer | ||
| 100 |
1/1✓ Branch 2 taken 1256 times.
|
1256 | frameBuffer.setSize(frameSize); |
| 101 | |||
| 102 | // Return ownership of the encrypted data buffer to the encryption helper, then send the frame | ||
| 103 |
1/1✓ Branch 5 taken 1256 times.
|
1256 | this->encryptReturnOut_out(0, data, context); |
| 104 |
1/1✓ Branch 5 taken 1256 times.
|
1256 | this->dataOut_out(0, frameBuffer, context); |
| 105 | 2564 | } | |
| 106 | |||
| 107 | // ---------------------------------------------------------------------- | ||
| 108 | // Private helper implementations | ||
| 109 | // ---------------------------------------------------------------------- | ||
| 110 | |||
| 111 | 2552 | void CcsdsSdlsFramer ::sendComStatusOnDrop() { | |
| 112 | // Report ready-for-more on a dropped frame so a ComQueue-driven downlink does not stall | ||
| 113 |
1/2✓ Branch 5 taken 2552 times.
✗ Branch 6 not taken.
|
2552 | if (this->isConnected_comStatusOut_OutputPort(0)) { |
| 114 |
1/1✓ Branch 2 taken 2552 times.
|
2552 | Fw::Success status = Fw::Success::SUCCESS; |
| 115 |
1/1✓ Branch 5 taken 2552 times.
|
2552 | this->comStatusOut_out(0, status); |
| 116 | 2552 | } | |
| 117 | 2552 | } | |
| 118 | |||
| 119 | } // namespace Ccsds | ||
| 120 | |||
| 121 | } // namespace Svc | ||
| 122 |