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