F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
CcsdsSdlsDeframer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title CcsdsSdlsDeframer.cpp
3 // \author mstarch
4 // \brief cpp file for CcsdsSdlsDeframer component implementation class
5 // ======================================================================
6 
8 
9 namespace Svc {
10 
11 namespace Ccsds {
12 
13 // ----------------------------------------------------------------------
14 // Component construction and destruction
15 // ----------------------------------------------------------------------
16 
17 CcsdsSdlsDeframer ::CcsdsSdlsDeframer(const char* const compName) : CcsdsSdlsDeframerComponentBase(compName) {}
18 
20 
21 // ----------------------------------------------------------------------
22 // Handler implementations for typed input ports
23 // ----------------------------------------------------------------------
24 
25 void CcsdsSdlsDeframer ::bufferReturnIn_handler(FwIndexType portNum,
26  Fw::Buffer& data,
27  const ComCfg::FrameContext& context) {
28  // The decryption helper has returned the original frame buffer: send it back upstream
29  this->dataReturnOut_out(0, data, context);
30 }
31 
32 void CcsdsSdlsDeframer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
33  if (data.getSize() < sizeof(U16)) {
34  // The frame is not long enough to contain the security association index, so we cannot process it
35  this->log_WARNING_HI_InsufficientLength();
36  this->dataReturnOut_out(0, data, context); // Drop the frame
37  } else {
38  U16 saIndex = 0;
39  Fw::SerializeStatus deserializeStatus = data.getDeserializer().deserializeTo(saIndex);
40  FW_ASSERT(deserializeStatus == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(deserializeStatus));
41 
42  // Copy context and set the security association index to the value we just deserialized from the frame
43  ComCfg::FrameContext newContext = context;
44  newContext.set_saIndex(saIndex);
45 
46  // Remove the security association index: the decryption helper receives only the iv/data
47  data.advance(static_cast<FwSignedSizeType>(sizeof(U16)));
48 
49  this->decryptOut_out(0, saIndex, data, newContext);
50  }
51 }
52 
53 void CcsdsSdlsDeframer ::dataReturnIn_handler(FwIndexType portNum,
54  Fw::Buffer& data,
55  const ComCfg::FrameContext& context) {
56  // Pass the data back to the decryption subsystem when it is returned from the rest of the chain
57  this->decryptReturnOut_out(0, data, context);
58 }
59 
60 void CcsdsSdlsDeframer ::decryptIn_handler(FwIndexType portNum,
61  const Svc::Ccsds::SdlsStatus& status,
62  Fw::Buffer& data,
63  const ComCfg::FrameContext& context) {
64  if (status != Svc::Ccsds::SdlsStatus::SUCCESS) {
65  this->log_WARNING_HI_DecryptionFailed(status);
66  if (this->isConnected_errorNotify_OutputPort(0)) {
67  this->errorNotify_out(0, Svc::Ccsds::FrameError::SDLS_DECRYPTION_FAILURE);
68  }
69  // Return ownership of the failed buffer to the decryption subsystem
70  this->decryptReturnOut_out(0, data, context);
71  } else {
72  // Once the decryption has finished, we can route the decryption output to the dataOut port for further
73  // processing
74  this->dataOut_out(0, data, context);
75  }
76 }
77 
78 } // namespace Ccsds
79 
80 } // namespace Svc
Serialization/Deserialization operation was successful.
~CcsdsSdlsDeframer()
Destroy CcsdsSdlsDeframer object.
SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG) override
Deserialize an 8-bit unsigned integer value.
void advance(FwSignedSizeType amount)
Definition: Buffer.cpp:106
Status of an SDLS (Space Data Link Security) encryption/decryption request.
SerializeStatus
forward declaration for string
ExternalSerializeBufferWithMemberCopy getDeserializer()
Definition: Buffer.cpp:165
FwSizeType getSize() const
Definition: Buffer.cpp:90
void set_saIndex(U16 saIndex)
Set member saIndex.
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
CcsdsSdlsDeframer(const char *const compName)
Construct CcsdsSdlsDeframer object.
Request completed successfully.
#define FW_ASSERT(...)
Definition: Assert.hpp:14