F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
CcsdsSdlsFramer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title CcsdsSdlsFramer.cpp
3 // \author devin
4 // \brief cpp file for CcsdsSdlsFramer component implementation class
5 // ======================================================================
6 
8 
9 namespace Svc {
10 
11 namespace Ccsds {
12 
13 // ----------------------------------------------------------------------
14 // Component construction and destruction
15 // ----------------------------------------------------------------------
16 
17 CcsdsSdlsFramer ::CcsdsSdlsFramer(const char* const compName) : CcsdsSdlsFramerComponentBase(compName) {}
18 
20 
21 // ----------------------------------------------------------------------
22 // Handler implementations for typed input ports
23 // ----------------------------------------------------------------------
24 
25 void CcsdsSdlsFramer ::bufferReturnIn_handler(FwIndexType portNum,
26  Fw::Buffer& data,
27  const ComCfg::FrameContext& context) {
28  // The encryption helper has returned the original data buffer: send it back upstream
29  this->dataReturnOut_out(0, data, context);
30 }
31 
32 void CcsdsSdlsFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
33  if (this->isConnected_comStatusOut_OutputPort(portNum)) {
34  this->comStatusOut_out(portNum, condition);
35  }
36 }
37 
38 void CcsdsSdlsFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
39  // Determine the security association index: use the context's value when set, otherwise the SA_INDEX parameter
40  const U16 unsetSaIndex = static_cast<U16>(ComCfg::SaIndexUnset);
41  U16 saIndex = context.get_saIndex();
42  if (saIndex == unsetSaIndex) {
44  saIndex = this->paramGet_SA_INDEX(valid);
46  static_cast<FwAssertArgType>(valid.e));
47  }
48 
49  // Copy context and record the security association index used for encryption
50  ComCfg::FrameContext newContext = context;
51  newContext.set_saIndex(saIndex);
52 
53  this->encryptOut_out(0, saIndex, data, newContext);
54 }
55 
56 void CcsdsSdlsFramer ::dataReturnIn_handler(FwIndexType portNum,
57  Fw::Buffer& data,
58  const ComCfg::FrameContext& context) {
59  // dataReturnIn is the allocated frame buffer coming back from the dataOut port
60  this->bufferDeallocate_out(0, data);
61 }
62 
63 void CcsdsSdlsFramer ::encryptIn_handler(FwIndexType portNum,
64  const Svc::Ccsds::SdlsStatus& status,
65  Fw::Buffer& data,
66  const ComCfg::FrameContext& context) {
67  if (status != Svc::Ccsds::SdlsStatus::SUCCESS) {
68  this->log_WARNING_HI_EncryptionFailed(status);
69  // Drop the frame: return ownership of the buffer to the encryption subsystem
70  this->encryptReturnOut_out(0, data, context);
71  this->sendComStatusOnDrop();
72  return;
73  }
74 
75  FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - sizeof(U16),
76  static_cast<FwAssertArgType>(data.getSize()));
77  const Fw::Buffer::SizeType frameSize = static_cast<Fw::Buffer::SizeType>(data.getSize() + sizeof(U16));
78 
79  // Allocate the frame buffer used to prepend the security association index to the encrypted data
80  Fw::Buffer frameBuffer = this->bufferAllocate_out(0, frameSize);
81  if ((!frameBuffer.isValid()) || (frameBuffer.getSize() < frameSize)) {
82  this->log_WARNING_HI_BufferAllocationFailed(frameSize);
83  // Drop the frame: return the undersized allocation (when valid) and the encrypted data buffer
84  if (frameBuffer.isValid()) {
85  this->bufferDeallocate_out(0, frameBuffer);
86  }
87  this->encryptReturnOut_out(0, data, context);
88  this->sendComStatusOnDrop();
89  return;
90  }
91 
92  auto frameSerializer = frameBuffer.getSerializer();
93  Fw::SerializeStatus serializeStatus = frameSerializer.serializeFrom(context.get_saIndex());
94  FW_ASSERT(serializeStatus == Fw::FW_SERIALIZE_OK, serializeStatus);
95  serializeStatus = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
96  FW_ASSERT(serializeStatus == Fw::FW_SERIALIZE_OK, serializeStatus);
97 
98  // Trim to actual frame size in case the allocator returned a larger buffer
99  frameBuffer.setSize(frameSize);
100 
101  // Return ownership of the encrypted data buffer to the encryption helper, then send the frame
102  this->encryptReturnOut_out(0, data, context);
103  this->dataOut_out(0, frameBuffer, context);
104 }
105 
106 // ----------------------------------------------------------------------
107 // Private helper implementations
108 // ----------------------------------------------------------------------
109 
110 void CcsdsSdlsFramer ::sendComStatusOnDrop() {
111  // Report ready-for-more on a dropped frame so a ComQueue-driven downlink does not stall
112  if (this->isConnected_comStatusOut_OutputPort(0)) {
114  this->comStatusOut_out(0, status);
115  }
116 }
117 
118 } // namespace Ccsds
119 
120 } // namespace Svc
Serialization/Deserialization operation was successful.
Representing success.
CcsdsSdlsFramer(const char *const compName)
Construct CcsdsSdlsFramer object.
void setSize(FwSizeType size)
Definition: Buffer.cpp:131
U8 * getData() const
Definition: Buffer.cpp:82
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
Status of an SDLS (Space Data Link Security) encryption/decryption request.
SerializeStatus
forward declaration for string
Omit length from serialization.
bool isValid() const
Definition: Buffer.cpp:78
enum T e
The raw enum value.
FwSizeType getSize() const
Definition: Buffer.cpp:90
U16 get_saIndex() const
Get member saIndex.
void set_saIndex(U16 saIndex)
Set member saIndex.
PlatformIndexType FwIndexType
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
Definition: Buffer.hpp:67
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
Enum representing parameter validity.
Request completed successfully.
ExternalSerializeBufferWithMemberCopy getSerializer()
Definition: Buffer.cpp:155
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.
~CcsdsSdlsFramer()
Destroy CcsdsSdlsFramer object.